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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:52:41+00:00 2026-06-17T09:52:41+00:00

my application uses SQLite database to store certain data of contacts.. like (record_ID, timestamp

  • 0

my application uses SQLite database to store certain data of contacts.. like (record_ID, timestamp etc.) I am trying to update SQLITE Records with certain values using this method.

After initializing the database, i used to call this method. Only 1 record is updated,. even if i call this method everytime to update.

- (void) updateRecord:(int)recordID:(NSString *)sapCustId:(NSString *)sapContactId: (NSString *)timestamp {


static sqlite3_stmt *updateStmt = nil;

    if(updateStmt == nil) {
        NSString *sql = [NSString stringWithFormat:@"update contactList set sapCustId = \"%@\", sapContactId = \"%@\", timestamp = \"%@\" Where record_ID = \"%d\"", sapCustId, sapContactId, timestamp, recordID];

        const char *sql_stmt = [sql UTF8String];

        if(sqlite3_prepare_v2(databaseHandle, sql_stmt, -1, &updateStmt, NULL) != SQLITE_OK)
            NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(databaseHandle));
    }

//        sqlite3_bind_text(updateStmt, 0, [sapCustId UTF8String], -1, SQLITE_TRANSIENT);
//        sqlite3_bind_text(updateStmt, 1, [sapContactId UTF8String], -1, SQLITE_TRANSIENT);
//        sqlite3_bind_int(updateStmt, 2, recordID);
//        sqlite3_bind_text(updateStmt, 3, [timestamp UTF8String], -1, SQLITE_TRANSIENT);

    if(SQLITE_DONE != sqlite3_step(updateStmt))
        NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(databaseHandle));

sqlite3_reset(updateStmt);
sqlite3_close(databaseHandle);

//Reclaim all memory here.
[sapContactId release];
[sapCustId release];

}

Let me know., how to solve it?

  • 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-17T09:52:42+00:00Added an answer on June 17, 2026 at 9:52 am

    The critical issue is that you code is building updateStmt only once, because that’s a static and you’re checking to see if it’s not nil. Thus, the first SQL statement is getting built, but none of the rest are. The simplest fix it to just get rid of the static qualifier as well as the if(updateStmt == nil) ... logic, and you should be off to the races. Also, make sure to replace the sqlite3_reset with sqlite3_finalize.

    The static pattern that this code clearly used to do (reusing the sqlite3_stmt, binding ? placeholders in the SQL with new values via sqlite3_bind_xxx each iteration, performing sqlite3_reset before each subsequent iteration) makes sense if you’re using precisely the same SQL statement but are just binding new values each iteration. But it looks like you’ve commented out that portion of the code and have removed the ? placeholders from the SQL, and are instead building the SQL using stringWithFormat.

    The simplest solution is to just retire the static pattern (get rid of the static keyword, eliminate the check to see if it’s nil, and use sqlite3_finalize in lieu of sqlite3_reset) and you should be ok.


    Additional thoughts:

    1. It looks like you’re closing the database every time you update a single row. If you’re updating a bunch of records, you might want to contemplate keeping the database open. And even if you decide to open and close the database, it probably makes sense to do those at the same logical level in the code (either both inside the updateRecord method, or both outside the updateRecord method). It just makes for more intuitive code.

    2. Assuming you decide that you don’t want to bother with reusing a previously prepared SQL statement in order to perform multiple UPDATE statements, which would require the use of the SQLite bind function calls, that does not mean that you shouldn’t contemplate using those bind function calls anyway. While it might look a lot more convenient to just build the SQL via stringWithFormat, it generally is better to use sqlite3_bind_xxx calls because (a) that protects you against injection attacks; and (b) you don’t have to worry about escaping parameter values that, for example, have quotation marks in them, etc.

      Don’t get in the habit of building SQL with stringWithFormat because, as a general rule, it’s fragile and in some cases, it’s dangerous.

    3. In your SQL, you generally would not use quotation marks around numeric field values.

    4. If you ever decided to try to make the static sqlite3_stmt/sqlite3_reset logic work, two minor observations:

      • I would not use the same sqlite3_stmt across data sessions (i.e. don’t close the database and then reopen it). Maybe it works, but given that the database is a parameter to sqlite3_prepare_v2, I wouldn’t make any such assumptions.

      • When you do, finally, close your database, you really should call sqlite3_finalize on the sqlite3_stmt and set it back to nil again.

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

Sidebar

Related Questions

My iPhone application uses Core Data and a SQLite database; versions are being tracked
my application uses SQLite database for it's data storage. Idelly, this database should reside
I have an application that uses SQLite(version 3.7.2) to store data. I have a
I'm creating a small c# winforms application. It uses a sqlite database to store
I am working on an iOS application that uses a SQLite database. In the
I'm writing an Android application for RC Cars. It uses a SQLite database, and
I have a desktop .NET WPF application witch uses an embedded database (SQLite). Where
My OSX Cocoa application uses SQLite to manage data. When initializing, I need to
I have created a application which uses Sqlite database. Now i wanted to deploy
I have c# application which writes files to an sqlite database. It uses entity

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.