我是 iphone 开发的新手。我有一个 sql 查询“从测试中选择 pubdate,其中 rowid 在(从测试中选择 max(rowid))”。当我执行这个查询时,我没有得到适当的结果。源代码:
NSString *query=[NSString stringWithFormat:@"select pubdate from %@ where rowid in(select max(rowid) from %@)",tableName,tableName];
const char * sql = [query UTF8String];
sqlite3_stmt *lastInsVal_statement = nil;
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString * docsDir = [paths objectAtIndex:0];
NSString * thePath = [docsDir stringByAppendingPathComponent:
@"Training_Project2.sqlite"];
sqlite3_open([thePath UTF8String], &database);
sqlite3_prepare_v2(database, sql, -1, &lastInsVal_statement, NULL);
NSString* pubdate;
while(sqlite3_step(lastInsVal_statement)==SQLITE_ROW){
const char* str = (const char*)sqlite3_column_text(lastInsVal_statement, 2);
pubdate = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];
}
sqlite3_finalize(lastInsVal_statement);
sqlite3_close(database);
return pubdate;