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

  • Home
  • SEARCH
  • 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 8810915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:14:05+00:00 2026-06-14T03:14:05+00:00

I can not insert a new row to the database. What am I doing

  • 0

I can not insert a new row to the database. What am I doing wrong?

-(void)InsertRecords{
    fileMgr = [NSFileManager defaultManager];
    sqlite3_stmt *stmt;
    sqlite3 *cruddb;

    const char *sql = "Insert into AllDictionary(id, DeleteFlag, TitleBD, Description, PathToDB, ImageURL) VALUES('565','asasf2','asfas2ff','fggaga2hah','b2bb','aa2aa')";
    NSString *cruddatabase = [self.GetDocumentDirectory stringByAppendingPathComponent:@"MainDb.sqlite"];

    if(!(sqlite3_open([cruddatabase UTF8String], &cruddb)==SQLITE_OK))
    {
        NSLog(@"An error has occured: %s",sqlite3_errmsg(cruddb));
    }
    if (sqlite3_prepare(cruddb, sql, -1, &stmt, NULL)!=SQLITE_OK) {
        NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(cruddb));
    } else {
        sqlite3_step(stmt);
    }
    sqlite3_finalize(stmt);
    sqlite3_close(cruddb);
}
  • 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-06-14T03:14:07+00:00Added an answer on June 14, 2026 at 3:14 am

    Your Id type is int.
    So the problem is with the query,

    const char *sql = "Insert into AllDictionary(id, DeleteFlag, TitleBD, Description, PathToDB, ImageURL) VALUES('565','asasf2','asfas2ff','fggaga2hah','b2bb','aa2aa')";
    

    Don’t use quotes for integer values it’s for string values.
    change the query to:

    const char *sql = "Insert into AllDictionary(id, DeleteFlag, TitleBD, Description, PathToDB, ImageURL) VALUES(565,'asasf2','asfas2ff','fggaga2hah','b2bb','aa2aa')";
    

    And there are alot of mistakes in your method, like the prepare statement will always executed if the db is not opened. Finalize statement will work always with or without executing the prepare statement.
    so re-write it like:

    -(void)InsertRecords
    {
        fileMgr = [NSFileManager defaultManager];
        NSString *cruddatabase = [self.GetDocumentDirectory stringByAppendingPathComponent:@"MainDb.sqlite"];
        sqlite3_stmt *stmt;
        sqlite3 *cruddb;
    
        const char *sql = "Insert into AllDictionary(id, DeleteFlag, TitleBD, Description, PathToDB, ImageURL) VALUES(565,'asasf2','asfas2ff','fggaga2hah','b2bb','aa2aa')";
    
        if((sqlite3_open([cruddatabase UTF8String], &cruddb)==SQLITE_OK))
        {
            if (sqlite3_prepare(cruddb, sql, -1, &stmt, NULL) ==SQLITE_OK)
            {
                sqlite3_step(stmt);
                sqlite3_finalize(stmt);
            }
            else 
            {
                NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(cruddb));
            }
            sqlite3_close(cruddb);
        }
        else
        {
           NSLog(@"An error has occured: %s",sqlite3_errmsg(cruddb));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED: Using sed, how can I insert (NOT SUBSTITUTE) a new line on only
I am using the Informix.NET driver (C#) to insert a row into a database
My plan is to update/insert existing/new records into a database from an external, i
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
Can not parse json using this var res = eval('(' + response + ')');
I can not directly user $('commentbody') because there are many comments and selection needs
I can not use content://sms? Works on all Android devices? I'm using SmsManager but
I have a two same tables.Database mysql. How can I compare two tables? Table1,Table2
I am using Hibernate. And i want to persistently store a new row with
i want to insert rows IF a row containing the specific values exists, and

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.