Reputation: 2783
I am developing iPhone application using SQLite. I decided to use fmdb. Using fmdb, how do I perform the following operation:-Insert, Update, Select, Delete?
As I can't develop application using FMDatabase. I downloaded FMDatabase files which contain following files namely =>
But the file fmdb.m
also contains the main
function. So it is conflicting with my applications MAIN function.
Upvotes: 1
Views: 3204
Reputation: 1355
to use fmdb
in your code, just add the files you list to your project, except the main.m
file. Here is an example of using it, when the app finish launching, a SQLite database will be created.
- (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];
}
Notice, I'm just pasting some code from fmdb main.m
file, into applicationDidFinishLaunching
.
Upvotes: 3
Reputation: 135548
fmdb.m is a file that contains FMDB sample code. You should not include this file in your Xcode project. But you should review it to see how to work with FMDB. It contains a lot of well-commented examples.
Upvotes: 3