user4277177
user4277177

Reputation:

DB Execute Query Error: SQL logic error or missing database xcode

I am running code from this tutorial sqlite database iOS app tutorial .The query function is :

- (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");
    }
}

Program is giving sql error on inserting record

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.

How to get remove this error ?

Upvotes: 1

Views: 1406

Answers (1)

Prajeet Shrestha
Prajeet Shrestha

Reputation: 8108

enter image description here

See the highlighted folder. Copy that into your project. Your code seems to be fine. And make sure db.sql is in there.

Upvotes: 1

Related Questions