【发布时间】:2012-06-25 14:49:08
【问题描述】:
我没有找到让我满意的答案,我可以将数据插入数据库,我也可以在模拟器上从中选择,但是当我关闭模拟器并再次打开它时,我看不到任何数据。我也在终端上打开它,我没有看到任何数据。 是我漏了哪一行还是有什么逻辑错误?
你尝试了什么?有什么建议吗?
我在代码中插入数据是这样的:
databasePath = [[NSBundle mainBundle] pathForResource:@"persons" ofType:@"sqlite3"];
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO person (id, name, address, photograph, telephone, fax, district) VALUES (\"%i\",\"%@\", \"%@\", \"%@\",\"%@\",\"%@\",\"%@\")", i, Name,Addresses, Image, Telephone,Fax,District];
const char *query_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
// NSLog(@"OK");
} else {
// NSLog(@"Problem!!!");
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
【问题讨论】:
标签: database ios5 sqlite xcode4.2