【发布时间】:2012-02-03 11:49:05
【问题描述】:
我正在使用 XCode 4.2 创建和 iphone 应用程序。我正在为应用程序使用 sqlite3 数据库。当我遇到 XCode 4.2 问题时,我在 iPhone 3GS 和 XCode 3.2.5 上成功创建并运行了该应用程序。 db文件无法打开,这里是打开表的示例代码代码。当我使用 SQlite 管理器打开同一个 db 文件时,我可以看到该表。我不明白错误是什么。
static sqlite3 *database = nil;
static sqlite3_stmt *selectStmt = nil;
+ (void) getInitialDataToDisplay:(NSString *)dbPath {
NSLog(@"Path: %@",dbPath);
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
NSString *sqlStr = @"select * from Space";
const char *sql = [sqlStr UTF8String];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
NSInteger primaryKey = sqlite3_column_int(selectstmt, 0);
SpaceClass *spaceObj = [[SpaceClass alloc] initWithPrimaryKey:primaryKey];
spaceObj.spacePK = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
spaceObj.spName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)];
spaceObj.spDescrptn = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)];
[appDelegate.spaceArray addObject:spaceObj];
[spaceObj release];
}
}else
NSLog(@"not ok");
}
else
sqlite3_close(database); //Even though the open call failed, close the database connection to release all the memory.
}
请帮忙,谢谢
【问题讨论】:
-
你能检查一下
NSLog(@"Error=%s",sqlite3_errmsg(&db))给了什么吗?