要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];
}
请注意,我只是将 fmdbmain.m
文件中的一些代码粘贴到applicationDidFinishLaunching
.