sqlite3_prepare_v2 正在获取 SQLITE_ERROR [英] sqlite3_prepare_v2 is getting SQLITE_ERROR
问题描述
我已经在这工作了几个小时,必须让它发挥作用!它阻碍了 iPhone 应用程序的发布......我第一次使用 SQLite.我遵循了所有建议,但我的 sqlite3_prepare_v2 调用每次都会收到 SQLITE_ERROR (1)!
I have been at this for hours and MUST get this working! It is holding up an iPhone app release... My first time using SQLite. I have followed all the advice and yet my sqlite3_prepare_v2 call gets a SQLITE_ERROR (1) every time!
这是我的控制器中的代码:
Here is my code from my controller:
NSString *query = @"SELECT * FROM QandA ORDER BY random() LIMIT 1";
// const char *sqlStatement = "SELECT * FROM QandA ORDER BY random() LIMIT 1";
sqlite3_stmt *compiledStatement;
// sqlite3_stmt *statement;
int prepareStatus = sqlite3_prepare_v2(database, [query UTF8String],
-1, &compiledStatement, NULL);
if (prepareStatus == SQLITE_OK) {...
您会注意到我尝试过使用char *"也无济于事(在其他尝试中).我的数据库打开正常:
You'll note that I've tried using a "char *" also to no avail (among other attempts). My database opens fine with:
databaseName = @"Facts.sqlite";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
NSLog(@"databasePath = %@", databasePath);
int dbOpenStatus = sqlite3_open_v2([databasePath UTF8String], &database, SQLITE_OPEN_READWRITE, NULL);
从我的控制器界面:
NSString *databaseName;
NSString *databasePath;
我已经检查了调试器,一切看起来都很好,但是准备语句失败了.我不知道如何记录它试图编译的语句......我假设/希望这正是我的 SELECT 所说的.
I've checked in the debugger and everything looks good, but the prepare statement fails. I don't know how to log the statement it is trying to compile... I assume/hope it is just what my SELECT says.
有人可以帮忙吗?我很绝望.标记
Can anyone help? I'm desperate. Mark
推荐答案
找到答案 此处.我不得不使用它来代替 DB 文件的路径:
Found the answer here. I had to use this instead for the path to the DB file:
[[NSBundle mainBundle]pathForResource:@"Facts"extension:@"sqlite"];
这给出了一个稍微不同的路径(一个额外的目录) - 一旦我使用它就可以了!希望这对其他人有帮助...我花了很多时间在这上面.
This gave a slightly different path (one extra directory) - once I used that it worked! Hope this helps someone else... I spent many hours on this.
这篇关于sqlite3_prepare_v2 正在获取 SQLITE_ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!