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 7683503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:48:36+00:00 2026-05-31T18:48:36+00:00

I have a problem when pushing data to my sqlite database in iphone application.

  • 0

I have a problem when pushing data to my sqlite database in iphone application.
here’s how I create database:

-(IBAction)createButtonPressed:(id)sender
{
    NSLog(@"createButtonPressed: called");
    status.text=[status.text stringByAppendingString:@"create button pressed.\n"];
    NSString *docsDir;
    NSArray *dirPaths;

    // Get the documents directory
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    docsDir = [dirPaths objectAtIndex:0];

    // Build the path to the database file
    self.databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"database.sqlite"]];

    NSFileManager *filemgr = [NSFileManager defaultManager];

    if ([filemgr fileExistsAtPath: databasePath ] == NO)
    {
        status.text=[status.text stringByAppendingString:@"creating database... "];
        status.text=[status.text stringByAppendingFormat:@"path: %@\n\n", databasePath];

    const char *dbpath = [databasePath UTF8String];

        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            status.text=[status.text stringByAppendingString:@"database opened successfully\n"];

            char *errMsg;
            const char *sql_stmt;
            NSString *sqlStatement=[[NSString alloc] init];

            /*
             CREATING JOB TABLE
             */
            sqlStatement=@"";
            [sqlStatement stringByAppendingString:@"CREATE TABLE IF NOT EXISTS JOB "];
            [sqlStatement stringByAppendingString:@"(ID INTEGER PRIMARY KEY AUTOINCREMENT, "];
            [sqlStatement stringByAppendingString:@"NUMBER TEXT, "];
            [sqlStatement stringByAppendingString:@"DATE_LOADING INTEGER, "];
            [sqlStatement stringByAppendingString:@"DATE_DEPARTURE INTEGER, "];
            [sqlStatement stringByAppendingString:@"DATE_UNLOADING INTEGER, "];
            [sqlStatement stringByAppendingString:@"ORIGIN INTEGER, "];
            [sqlStatement stringByAppendingString:@"DESTINATION INTEGER, "];
            [sqlStatement stringByAppendingString:@"SUPPLIER INTEGER, "];
            [sqlStatement stringByAppendingString:@"RAILROAD INTEGER, "];
            [sqlStatement stringByAppendingString:@"FOREMAN INTEGER, "];
            [sqlStatement stringByAppendingString:@"WEATHER INTEGER, "];
            [sqlStatement stringByAppendingString:@"COMMENT TEXT, "];
            [sqlStatement stringByAppendingString:@"MODIFY_STATUS INTEGER)"];

            sql_stmt = [sqlStatement UTF8String];

            if (sqlite3_exec(database, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
            {
                status.text=[status.text stringByAppendingString:@"failed to create JOB table\n"];
            }
            else
            {
                status.text=[status.text stringByAppendingString:@"JOB table created\n"];
            };


        status.text=[status.text stringByAppendingString:@"closing database...\n"];
        sqlite3_close(database);

    }
    else
    {
        status.text=[status.text stringByAppendingString:@"failed to open/create database\n"];
    };
}
else
{
    status.text=[status.text stringByAppendingString:@"database exists "];
    status.text=[status.text stringByAppendingFormat:@"path: %@\n\n", databasePath];
};

[status scrollRangeToVisible:NSMakeRange([status.text length], 0)];

}

everything is with creating is OK. BUT!
when I try to push data to my table I get an error: “no such table JOB”
pushing data code:

NSLog(@"populateButtonPressed: called");
status.text=[status.text stringByAppendingString:@"populate button pressed.\n"];

NSFileManager *filemgr = [NSFileManager defaultManager];

if ([filemgr fileExistsAtPath: databasePath ] == YES)
{
    const char *dbpath = [databasePath UTF8String];

    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {
        status.text=[status.text stringByAppendingString:@"database opened successfully\n"];

        char *errMsg;
        const char *sql_stmt;
        NSString *sqlStatement=[[NSString alloc] init];

        /*
         POPULATING JOB TABLE
         */
        sqlStatement=@"INSERT INTO JOB (NUMBER, DATE_LOADING, DATE_DEPARTURE, DATE_UNLOADING, ORIGIN, DESTINATION, SUPPLIER, RAILROAD, FOREMAN, WEATHER, COMMENT, MODIFY_STATUS) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        sql_stmt = [sqlStatement UTF8String];
        sqlite3_stmt *stmt;
        sqlite3_prepare_v2(database, sql_stmt, -1, &stmt, nil);
        sqlite3_bind_text(stmt, 1, "number", -1, SQLITE_STATIC); //number
        sqlite3_bind_int(stmt, 2, 100); //date_loading
        sqlite3_bind_int(stmt, 3, 101); //date_departure
        sqlite3_bind_int(stmt, 4, 102); //date_unloading
        sqlite3_bind_int(stmt, 5, 103); //origin
        sqlite3_bind_int(stmt, 6, 104); //destination
        sqlite3_bind_int(stmt, 7, 105); //supplier
        sqlite3_bind_int(stmt, 8, 106); //railroad
        sqlite3_bind_int(stmt, 9, 107); //foreman
        sqlite3_bind_int(stmt, 10, 108); //weather
        sqlite3_bind_text(stmt, 11, "commentstring", -1, SQLITE_STATIC); //comment
        sqlite3_bind_int(stmt, 12, 1);

        if (sqlite3_step(stmt)!=SQLITE_DONE)
        {
            status.text=[status.text stringByAppendingString:@"WARNING!!! Could not step (execute) stmt\n"];
            status.text=[status.text stringByAppendingFormat:@"error: %@\n", [NSString stringWithUTF8String:sqlite3_errmsg(database)]];
        }
        else
        {
            status.text=[status.text stringByAppendingString:@"it seems like stmt step (execute) was successfull"];
        };

        if(sqlite3_finalize(stmt)==SQLITE_DONE)
        {
            status.text=[status.text stringByAppendingString:@"finalizing stmt was successfull\n"];
        }
        else
        {
            status.text=[status.text stringByAppendingString:@"WARNING!!! failed finalizing stmt\n"];
        };


        status.text=[status.text stringByAppendingString:@"closing database...\n"];
        sqlite3_close(database);

    }
    else
    {
        status.text=[status.text stringByAppendingString:@"failed to open database\n"];
    };
}
else
{
    status.text=[status.text stringByAppendingString:@"database does not exist. you need to create it.\n"];
};

[status scrollRangeToVisible:NSMakeRange([status.text length], 0)];

the database exists at path and opens successfully.
iOS5 ipad application, uses ARC and libsqlite3.dylib, I’m running my application in simulator.

  • 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-31T18:48:37+00:00Added an answer on May 31, 2026 at 6:48 pm

    is your db path is correct? why do not you check in your terminal first?

    > sqlite3 <your_db_path>
    
    > show tables;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem. My LINQ to SQL queries are pushing data to the
I have a problem with saving data from Ext.data.DirectStore to server Here is my
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem when I try insert some data to Informix TEXT column via
i have problem with autorotate on iphone i set up in all classes -
Here's a recurrent problem that I have and I think maybe CDI events can
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for

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.