FMDatabase:执行操作:插入、更新、选择、删除

发布于 2024-10-19 11:51:01 字数 544 浏览 6 评论 0原文

我正在使用 SQLite 开发 iPhone 应用程序。我决定使用 fmdb。使用fmdb,如何执行以下操作:-插入、更新、选择、删除?

因为我无法使用 FMDatabase 开发应用程序。我下载了 FMDatabase 文件,其中包含以下文件 =>

  1. FMDatabase.h
  2. FMDatabase.m
  3. FMResultSet.h
  4. FMResultSet.m
  5. FMDatabaseAdditions.h
  6. FMDatabaseAdditions.m
  7. fmdb.m

但是文件 fmdb.m 还包含 main 函数。所以它与我的应用程序的 MAIN 功能冲突。

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 =>

  1. FMDatabase.h
  2. FMDatabase.m
  3. FMResultSet.h
  4. FMResultSet.m
  5. FMDatabaseAdditions.h
  6. FMDatabaseAdditions.m
  7. fmdb.m

But the file fmdb.m also contains the main function. So it is conflicting with my applications MAIN function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如痴如狂 2024-10-26 11:51:01

fmdb.m 是包含 FMDB 示例代码的文件。您不应将此文件包含在您的 Xcode 项目中。但您应该查看它以了解如何使用 FMDB。它包含许多评论良好的示例。

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.

权谋诡计 2024-10-26 11:51:01

要在代码中使用 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 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文