要在您的代码中使用fmdb
,只需将列出的文件添加到您的项目中,但main.m
文件除外。这是一个使用它的例子,当应用程序完成启动时,将创建一个SQLite数据库。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
if (![db open]) {
NSLog(@"Could not open db.");
}
[db executeUpdate:@"create table test (a text, b text, c integer, d double, e double)"];
NSLog(@"%@",[db databasePath]);
[db beginTransaction];
int i = 0;
while (i++ < 20) {
[db executeUpdate:@"insert into test (a, b, c, d, e) values (?, ?, ?, ?, ?)" ,
@"hi'", // look! I put in a ', and I'm not escaping it!
[NSString stringWithFormat:@"number %d", i],
[NSNumber numberWithInt:i],
[NSDate date],
[NSNumber numberWithFloat:2.2f]];
}
[db commit];
[db close];
}
注意,我只是贴一些代码FMDB main.m
文件,到applicationDidFinishLaunching
。
好吧,我会检查它。感谢您的回复Ole – iOSAppDev 2011-02-26 16:55:18