【发布时间】:2014-11-05 15:38:43
【问题描述】:
请帮我找出问题所在。
插入语句不起作用,当我检查保存在 /Users/jppangilinan/Library/Application Support/iPhone Simulator/ 4.3/Applications/61BBA03F-C240-414D-9A64-6CE3B34DF9C2/Documents/person.sqlite3 似乎保存在该位置的数据库没有任何表,这就是插入语句不起作用的原因。为什么它没有在我的项目的资源文件夹中复制我的 sqlite db? TIA
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"person.sqlite3"];
FMDatabase *database = [FMDatabase databaseWithPath:path];
[database open];
[database beginTransaction];
NSString *query = [NSString stringWithFormat:@"insert into person(rowid,fname,lname,address) values (null, '%@','%@','%@')",fname.text,lname.text,address.text];
NSLog(@" %@",path);
NSLog(@" %@",query);
BOOL y= [database executeUpdate:query];
if (!y)
{
NSLog(@"insert failed!!");
}
NSLog(@"Error %d: %@", [database lastErrorCode], [database lastErrorMessage]);
[database commit];
[database close];
}
【问题讨论】:
-
你找到解决这个问题的方法了吗?