1
我有一個數據庫有一個'單詞'表(存儲單詞)的視圖,我想檢索並將數據發送到另一個ViewController,而不是接收實際的詞,我得到id
。ViewController接收ID而不是SQLite查詢中的數據
這裏是我的代碼:
(void)getListData {
//tableData = [[NSMutableArray alloc]init];
sqlite3_stmt *statement;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dexternotedb.sqlite"];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
WordListViewController *temp = APP_DELEGATE.wordListViewController;
NSLog(@"word id %ld",(long)[temp.wordId integerValue]);
NSString *sql=[NSString stringWithFormat:@"SELECT * FROM words WHERE word_id=\"%@\"",APP_DELEGATE.wordListViewController.wordId];
const char *read_stmt = [sql UTF8String];
NSLog(@"select query%@",sql);
if(sqlite3_prepare_v2(database, read_stmt, -1, &statement, NULL) == SQLITE_OK){
sqlite3_bind_int(statement, 1, [temp.wordId integerValue]);
while(sqlite3_step(statement) == SQLITE_ROW) {
NSString *word1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[word addObject:word1];
NSString *meaning1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[meaning addObject:meaning1];
NSString *sentence1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[Sentence addObject:sentence1];
}
sqlite3_finalize(statement);
} else {
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}
我有詞義和句子中的wordID字表...所以u能告訴我如何,如果你說的列名正確地寫它 – Asheesh
選擇查詢,在這裏:選擇wordid,單詞,含義,句子FROM words WHERE word_id = \「%@ \ –
檢查更新,重要的是將正確的索引添加到sqlite3_column_text函數中。還要檢查查詢中的列名 –