iOS中的SQLite包装器? [英] SQLite wrapper in iOS?

查看:106
本文介绍了iOS中的SQLite包装器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,可以将信息存储到SQLite数据库中。它和我的兄弟在手机上都很棒。东西被写入,它可以从中读取。但是,当在其他人的手机上运行时,它只会崩溃。为什么?

I have an iPhone app that stores information to a SQLite database. It works splendid on my phone as well as my brothers. Stuff get's written to it and it can read from it. However, when running it on other people's phone's, it just crashes. Why?

我正在使用Matteo Bertozzi的SQLite包装器(将文件放在classes文件夹中并在我的.h中链接到它们,如下所示: #import Sqlite.h

I am using Matteo Bertozzi's SQLite wrapper (put files in the classes folder and linked to them in my .h like this: #import "Sqlite.h")

我还导入 libsqlite3.dylib 到我的项目。

在我的.h中也声明了我的SQLite数据库: Sqlite * database;

Declared my SQLite database like this in my .h as well: Sqlite *database;

像这样设置我的数据库:

Set up my database like this:

if (database == nil) {
// Set up database connection
NSString *myDBTwo = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"flashpics.db"];
database = [[Sqlite alloc] init];
[database open:myDBTwo];
}

并调用这样的查询(我的变量都不是零):

And call a query like this (none of my variables are nil) :

[database executeNonQuery:@"INSERT INTO images (id, thumbnail, album, caption) VALUES (?, ?, ?, ?)", photoID, thumbnailLocation, photoAlbumID, photoCaption];

然而,它在我朋友的手机上崩溃并返回 EXC_BAD_ACCESS 尝试阅读时...当你试图写信时没有任何反应。

However it crashes on my friend's phone and returns EXC_BAD_ACCESS when trying to read it.. Nothing happens when you try to write to it.

请帮忙!
谢谢

Please help! Thanks

PS:这是包装器的链接: http://th30z.blogspot.com/2008/11/objective-c-sqlite-wrapper_8445.html

PS: Here's the link to the wrapper: http://th30z.blogspot.com/2008/11/objective-c-sqlite-wrapper_8445.html

编辑#1:以下是我在加载应用时遇到的一些错误。也许这是造成它的?或者它没有链接到正确的库?

Edit #1: Here's some of the errors I get when loading the app. Maybe this is causing it? Or it's not linking to the correct library?

warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/usr/lib/info/dns.so (file not found).

这就是我在做出让它崩溃的动作时得到的结果。

And here's what I get when I do the action that makes it crash.

Program received signal:  "EXC_BAD_ACCESS".
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2.1 (8C148)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).


推荐答案

问题在于你正试图写信给您的应用程序包中的资源文件夹,只在非越狱系统上读取,出于安全/安全原因,您必须在文档文件夹中创建数据库,因此您将代码更改为此...

The problem is that you are trying to write to the resources folder in your app bundle, which is read only on a non-jailbroken system, due to safety/security reasons, you have to create the database in the documents folder, so you change your code to this...

编辑:抱歉我粘贴了错误代码,这是固定版本。

SORRY I pasted the WRONG code, here is the fixed version.

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *myDBTwo = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"flashpics.db"];

这篇关于iOS中的SQLite包装器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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