Ios 数据库执行查询错误:SQL逻辑错误或缺少数据库xcode
我正在运行本教程中的代码。查询函数为:Ios 数据库执行查询错误:SQL逻辑错误或缺少数据库xcode,ios,objective-c,sqlite,Ios,Objective C,Sqlite,我正在运行本教程中的代码。查询函数为: - (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.
- (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.
如何获取和删除此错误?
请参见突出显示的文件夹。将其复制到您的项目中。您的代码似乎很好。并确保db.sql在其中。插入查询中的null是什么意思。该列是标识还是仅为整数?检查该列是否不为空。是否使用更新查询?是否已将数据库文件文件夹(与您引用的代码一起提供)导入到项目中?你可能应该错过它。因为错误显示缺少数据库。您是否在应用程序中指定了数据库路径?如何指定?我已经使用以下命令完成了:self.dbManager=[[dbManager alloc]initWithDatabaseFileName:@“db.sql”];在viewdid中load@frincit:是的,这是正确的,之后您必须将文件复制到文档目录确定尝试重置模拟器。重置内容和设置。然后重新运行应用程序。您正在运行示例文件本身吗?或者你自己也修改过吗?因为我已经下载了代码,它在这里运行得非常好。示例文件在这里运行得很好。没有进一步的线索。我们被困在这里,哈哈。你是在运行示例代码本身还是在某个地方对代码进行了调整?