要在您的代碼中使用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