Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:55:13+00:00 2026-05-27T19:55:13+00:00

I am currently trying to simply insert a new row into my SQLite3 database

  • 0

I am currently trying to simply insert a new row into my SQLite3 database on my iPad. I have done it multiple times before in other apps and just copied the code. The copied SELECT queries work fine, but if I try to INSERT, it fails at == SQLITE_DONE

This is how I try to insert into the database:

NSString *databaseName = @"Waypoints.sql";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
sqlite3 *database;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
    NSString *statement = [NSString stringWithFormat:
                           @"INSERT INTO Waypoints (id, name, alt, ias, temp, tas, wd, ws, gs, mt, mh, dist, time, fuel, fuelrate) VALUES (%d,'New...','','','','','','','','','','','','','');", [self numberOfWaypoints]];
    NSLog(@"Statement: %@", statement);
    const char *sqlStatement = [statement cStringUsingEncoding:NSASCIIStringEncoding];
    sqlite3_stmt *compiledStatement;
    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
    {
        if(sqlite3_step(compiledStatement) == SQLITE_DONE)
            NSLog(@"DATABASE: Adding: Success");
        else
            NSLog(@"DATABASE: Adding: Failed");
    }
    else
        NSLog(@"Error. Could not add Waypoint.");
    sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);

If I run this code on the press of a button, it outputs DATABASE: Adding: Failed in the console.

The NSLogged statement looks like this:

INSERT INTO Waypoints (id, name, alt, ias, temp, tas, wd, ws, gs, mt, mh, dist, time, fuel, fuelrate) VALUES (2,’New…’,”,”,”,”,”,”,”,”,”,”,”,”,”);

Which works perfectly fine if I paste it in the terminal (connected to same database file).

This brings me to the conclusion: what could be causing this problem?
I thought of maybe write permissions to the file. Could be it, but it’s not in the bundle but already copied to the documents folder on the device.

Please help to how I can get this to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:55:14+00:00Added an answer on May 27, 2026 at 7:55 pm

    Try using NSUTF8StringEncoding for your cStringUsingEncoding or printing

    NSLog(@"%@", [NSString stringWithUTF8String:(char*)sqlite3_errmsg(database)]);
    

    Glad to see you could find your error with this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run a simple insert query to a database. I have it
I have been trying to get more in to TDD. Currently keeping it simple
I'm currently trying to get into the Java EE development with the Spring framework.
I'm currently learning the HDF5 API and I'm trying to insert a set of
Currently looking to extract data from 2 tables and insert into another. Tables as
I'm developing an IE8+ BHO plugin. For now I'm simply trying to insert a
Starting off I have UTFS. Trying to insert a variable in the middle of
I'm attempting to use AJAX to insert data into a database, but am unable
I am currently trying to insert some simple true/false radio buttons in Rails 3,
I'm currently trying to build a simple component which should monitor, if the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.