我无法在XCode上的sqlite3文件中插入数据 [英] I can not insert data into sqlite3 file on XCode

查看:155
本文介绍了我无法在XCode上的sqlite3文件中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到满足我的答案,我可以将数据插入到数据库中,我也可以在模拟器上从中进行选择,但是当我关闭模拟器并再次打开它时,我看不到任何数据。我也在终端上打开它,我没有看到任何数据。
我错过了任何一行还是有任何逻辑错误?

I did not find answer that satisfy me, I can insert data into database and I can also select from it on simulator, but when I close the simulator and open it again, I can't see any data. Also I opened it on the terminal and I did not see any data in it. Did I miss any line or is there any logic error?

你尝试了什么?对我有什么建议?

What did you try? any suggest for me?

我在我的代码中插入数据是这样的:

I inserted data into my code is like this:

databasePath = [[NSBundle mainBundle] pathForResource:@"persons" ofType:@"sqlite3"];
        const char *dbpath = [databasePath UTF8String];
        sqlite3_stmt    *statement;

        if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
        {
            NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO person (id, name, address, photograph, telephone, fax, district) VALUES (\"%i\",\"%@\", \"%@\", \"%@\",\"%@\",\"%@\",\"%@\")", i, Name,Addresses, Image, Telephone,Fax,District];

            const char *query_stmt = [insertSQL UTF8String];

            sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL);

            if (sqlite3_step(statement) == SQLITE_DONE)
            {
                //  NSLog(@"OK");

            } else {
                //  NSLog(@"Problem!!!");

            }
            sqlite3_finalize(statement);
            sqlite3_close(contactDB); 
        }


推荐答案

我在寻找同样的东西回答是因为我也陷入困境,我认为其他人的帖子这里给出了一个很好的例子。

I was searching for the same answer because I was stuck as well, and I think someone else's post here gives a pretty good example.

以下是Inafziger给出的链接信息:

Here is the information on the link that Inafziger gave:

iOS数据存储指南
iCloud包括备份,它每天通过Wi-Fi自动备份用户的iOS设备。除了应用程序包本身,caches目录和临时目录之外,备份应用程序主目录中的所有内容。还备份购买的音乐,应用程序,书籍,相机胶卷,设备设置,主屏幕和应用程序组织,消息和铃声。由于备份是通过无线方式完成的并存储在iCloud中,因此最好尽量减少为应用程序存储的数据量。大文件会延长执行备份所需的时间并消耗更多用户可用的iCloud存储空间。

iOS Data Storage Guidelines iCloud includes Backup, which automatically backs up a user’s iOS device daily over Wi-Fi. Everything in your app’s home directory is backed up, with the exception of the application bundle itself, the caches directory, and temp directory. Purchased music, apps, books, the Camera Roll, device settings, home screen and app organization, messages, and ringtones are backed up as well. Because backups are done wirelessly and stored in iCloud for each user, it’s best to minimize the amount of data that’s stored for your app. Large files will lengthen the time it takes to perform a backup and consume more of a user’s available iCloud storage.

为确保备份尽可能高效,请务必使用根据以下指南存储您的应用程序数据:

To ensure that backups are as efficient as possible, be sure to store your app’s data according to the following guidelines:


  1. 仅用户生成的文档和其他数据,或者无法通过其他方式重新创建的文档和其他数据您的应用程序应存储在/ Documents目录中,并由iCloud自动备份。

  2. 可以再次下载或重新生成的数据应存储在/ Library / Caches目录中。您应该放在Caches目录中的文件示例包括数据库缓存文件和可下载内容,例如杂志,报纸和地图应用程序使用的文件。

  3. 暂时使用的数据应该是存储在/ tmp目录中。虽然这些文件没有备份到iCloud,但请记住在完成这些文件后删除这些文件,这样他们就不会继续占用用户设备上的空间。

  4. 使用do不备份用于指定应保留在设备上的文件的属性,即使在低存储情况下也是如此。将此属性与可以重新创建的数据一起使用,但即使在低存储情况下也需要保留,以使应用程序正常运行,或者因为客户希望在脱机使用期间可以使用该数据。此属性适用于标记文件,无论它们位于何种目录中,包括Documents目录。这些文件不会被清除,也不会包含在用户的iCloud或iTunes备份中。由于这些文件确实使用设备上的存储空间,因此您的应用程序负责定期监视和清除这些文件。

  1. Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.
  2. Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.
  3. Data that is used only temporarily should be stored in the /tmp directory. Although these files are not backed up to iCloud, remember to delete those files when you are done with them so that they do not continue to consume space on the user’s device.
  4. Use the "do not back up" attribute for specifying files that should remain on device, even in low storage situations. Use this attribute with data that can be recreated but needs to persist even in low storage situations for proper functioning of your app or because customers expect it to be available during offline use. This attribute works on marked files regardless of what directory they are in, including the Documents directory. These files will not be purged and will not be included in the user's iCloud or iTunes backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.

这篇关于我无法在XCode上的sqlite3文件中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆