- (UserInfo*)getCurrentUserInfo:(NSString*)userName
{
UserInfo *userInfo = [[UserInfo alloc]init];
sqlite3 *database;
sqlite3_stmt *selectstmt;
NSLog(@"userName:%@",userName);
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
NSString *sqlString = [NSString stringWithFormat:@"SELECT USER_LEVEL FROM USER_INFO WHERE USER_NAME = '%@'" , userName];
NSLog(@"getCurrentUserInfo:%@",sqlString);
const char *SqlCommand = [sqlString UTF8String];
if (sqlite3_prepare_v2(database, SqlCommand, -1, &selectstmt, NULL) == SQLITE_OK) {
NSLog(@"success!");
while (sqlite3_step(selectstmt) == SQLITE_ROW) {
NSString *userInfoStr = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
NSLog(@"select result:%@",userInfoStr);
}
}
sqlite3_finalize(selectstmt);
}
sqlite3_close (database);
return userInfo;
}
下面是我的日誌輸出:sqlite的,選擇查詢不起作用
2012-03-06 17:50:11.556 MagicWords[508:f803] userName:Tan
2012-03-06 17:50:11.557 MagicWords[508:f803] getCurrentUserInfo:SELECT USER_LEVEL FROM USER_INFO WHERE USER_NAME = 'Tan'
它不打印「成功」,所以sqlite3_prepare_v2不返回yes.but我的數據庫是確定:
我找不到問題?
讓我看看你的數據庫路徑 – Hector 2012-03-06 10:38:17