我正在运行本教程中的代码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.
如何删除此错误?
答案 0 :(得分:1)
查看突出显示的文件夹。将其复制到您的项目中。你的代码似乎没问题。并确保db.sql在那里。