Iphone FMDatabase:执行以下操作:插入、更新、选择、删除
我正在使用开发iPhone应用程序。我决定使用。使用fmdb,我如何执行以下操作:-插入、更新、选择、删除 因为我不能使用FMDatabase开发应用程序。我下载了包含以下文件的FMDatabase文件,即=>Iphone FMDatabase:执行以下操作:插入、更新、选择、删除,iphone,sqlite,fmdb,Iphone,Sqlite,Fmdb,我正在使用开发iPhone应用程序。我决定使用。使用fmdb,我如何执行以下操作:-插入、更新、选择、删除 因为我不能使用FMDatabase开发应用程序。我下载了包含以下文件的FMDatabase文件,即=> FMDatabase.h FMDatabase.m FMResultSet.h FMResultSet.m FMDatabaseAdditions.h FMDatabaseAdditions.m fmdb.m 但是文件fmdb.m也包含main函数。因此,它与我的应用程序主功能冲突。fm
但是文件
fmdb.m
也包含main
函数。因此,它与我的应用程序主功能冲突。fmdb.m是一个包含fmdb示例代码的文件。您不应该在Xcode项目中包含此文件。但是您应该查看它,看看如何使用FMDB。它包含许多注释良好的示例。fmdb.m是一个包含fmdb示例代码的文件。您不应该在Xcode项目中包含此文件。但是您应该查看它,看看如何使用FMDB。它包含了许多注释良好的示例。要在代码中使用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];
}
-(无效)应用程序设计完成启动:(NSNotification*)通知{
//在此处插入代码以初始化应用程序
FMDatabase*db=[FMDatabase databaseWithPath:@”/tmp/tmp.db];
如果(![db打开]){
NSLog(@“无法打开数据库”);
}
[db executeUpdate:@“创建表测试(a文本、b文本、c整数、d双精度、e双精度)”;
NSLog(@“%@,[db databasePath]);
[db beginTransaction];
int i=0;
而(i++<20){
[db executeUpdate:@“插入测试(a、b、c、d、e)值(?,,,,,,?)”,
@“嗨,”//看!我放了一个,我不会逃脱的!
[NSString stringWithFormat:@“编号%d”,i],
[NSNumber NUMBER WITHIN:i],
[日期],
[NSNumber numberWithFloat:2.2f]];
}
[db提交];
[db close];
}
请注意,我只是将fmdb
main.m
文件中的一些代码粘贴到ApplicationIDFinishLaunching
要在代码中使用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];
}
-(无效)应用程序设计完成启动:(NSNotification*)通知{
//在此处插入代码以初始化应用程序
FMDatabase*db=[FMDatabase databaseWithPath:@”/tmp/tmp.db];
如果(![db打开]){
NSLog(@“无法打开数据库”);
}
[db executeUpdate:@“创建表测试(a文本、b文本、c整数、d双精度、e双精度)”;
NSLog(@“%@,[db databasePath]);
[db beginTransaction];
int i=0;
而(i++<20){
[db executeUpdate:@“插入测试(a、b、c、d、e)值(?,,,,,,?)”,
@“嗨,”//看!我放了一个,我不会逃脱的!
[NSString stringWithFormat:@“编号%d”,i],
[NSNumber NUMBER WITHIN:i],
[日期],
[NSNumber numberWithFloat:2.2f]];
}
[db提交];
[db close];
}
注意,我只是将一些代码从fmdb
main.m
文件粘贴到applicationdFinishLaunching
谢谢Cesar。你是在说我项目的“main.m”吗?如果是,程序是否将在没有主功能的情况下运行?我指的是fmdb
的main.m
,请欣赏。-谢谢回复。我的申请已经完成了,但仍然不起作用。没有错误或警告。怎么办?你能查一下我的密码吗?这里是代码的链接。将代码发布到github并请求审阅比发布zip文件更容易。谢谢Cesar。你是在说我项目的“main.m”吗?如果是,程序是否将在没有主功能的情况下运行?我指的是fmdb
的main.m
,请欣赏。-谢谢回复。我的申请已经完成了,但仍然不起作用。没有错误或警告。怎么办?你能查一下我的密码吗?这是代码的链接。将代码发布到github并请求审阅比发布zip文件更容易。好的,我会检查它。谢谢你的回复,好的,我会检查的。谢谢你的回复