ios - 数据库执行查询错误 : SQL logic error or missing database xcode

标签 ios objective-c sqlite

我正在运行本教程中的代码 sqlite database iOS app tutorial .查询函数为:

- (IBAction)saveInfo:(id)sender
{
    //  Prepare the query string.
    //  If the recordIDToEdit property has value other than -1, then create an update query. Otherwise create an insert query.
    NSString *query;

    if (self.recordIDToEdit == -1)
    {
        query = [NSString stringWithFormat:@"insert into peopleInfo values(null, '%@', '%@', '%@')", self.txtFirstname.text, self.txtLastname.text, self.txtAge.text ];
    }
    else
    {
        query = [NSString stringWithFormat:@"update peopleInfo set firstname='%@', lastname='%@', age='%@' where peopleInfoID=%d", self.txtFirstname.text, self.txtLastname.text, self.txtAge.text, self.recordIDToEdit];
    }



    NSLog(@"The query is: %@",query);

    //  Execute the query.
    [self.dbManager executeQuery:query];

    //  If the query was succesfully executed then pop the view controller.
    if (self.dbManager.affectedRows != 0) {
        NSLog(@"Query was executed successfully. Affacted rows = %d", self.dbManager.affectedRows);

        //  Inform the delegate that editing was finished.
        [self.delegate editingInfoWasFinished];

        //  Pop the view controller.
        [self.navigationController popViewControllerAnimated:YES];
    }
    else
    {
        NSLog(@"Could not execute the query");
    }
}

程序在插入记录时出现sql错误

The query is: insert into peopleInfo values(null, 'Project 1', 'Test 1', '2014-12-15 05:00:20 +0000')
DB Execute Query Error: SQL logic error or missing database
Could not execute the query.

如何消除这个错误?

最佳答案

enter image description here

查看突出显示的文件夹。将其复制到您的项目中。您的代码似乎没问题。并确保 db.sql 在那里。

关于ios - 数据库执行查询错误 : SQL logic error or missing database xcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27497997/

相关文章:

ios - 动画 UILabel 从中心调整大小?

html - 没有带有 SWIFT 3 的 html 标签的单元格不显示更新的 JSON

python - 选择 N 条随机记录

iphone - 在类之间传递NSString

ios - 在 Objective-C 中锁定一个实例变量

java - SQLException : No suitable driver found for org. sqlite.JDBC

java - SQLite 数据库使我的应用程序崩溃

ios - 将带有图像的工具栏添加到项目中

ios - removeObjectFromSuperView 不使用 if 语句

objective-c - 字符串解析,用逗号分隔,除非用撇号括起来