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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:43:29+00:00 2026-06-18T08:43:29+00:00

I am trying to save more than 500 records at once in sqlite, code

  • 0

I am trying to save more than 500 records at once in sqlite, code that I have wrote so far is given below

The method name closeDatabase closes any open connection of the database the variable ContactID is nothing but an Array which is populated with ContactID of people present in my address book.

 sqlite3_exec(databaseRefObj, "BEGIN TRANSACTION", 0, 0, 0);

                for (NSString *contactIDstr in contactID)
                {
                    const char *insertintoGropsMember = "My insert query here";
                    NSString *groupIDstr = [NSString stringWithFormat:@"%d",grpID];

                    [self closeDatabase];

                    if(sqlite3_prepare_v2(databaseRefObj, insertintoGropsMember, -1, &sqlstatement, NULL)==SQLITE_OK)
                    {
                        sqlite3_bind_text(sqlstatement, 1, [groupIDstr UTF8String], -1, SQLITE_TRANSIENT);
                        sqlite3_bind_text(sqlstatement, 2, [contactIDstr UTF8String], -1, SQLITE_TRANSIENT);
                        sqlite3_step(sqlstatement);
                    }
                    else
                    {
                        successFlag = NO;
                    }


                    sqlite3_finalize(sqlstatement);
                    sqlite3_close(databaseRefObj);
                }

                sqlite3_exec(databaseRefObj, "END TRANSACTION", 0, 0, 0);

The process of data insertion is quite slow here and I would like to know where am I going wrong or what steps should I follow to optimize my sqlite performance.

Please note that I am not using any kind of index on the column on which I want to perform the insert.

  • 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-18T08:43:31+00:00Added an answer on June 18, 2026 at 8:43 am

    I can see several issues with your code:

    • You appear to be closing the database during processing.
    • You aren’t taking advantage of the statement prepare/multiple binding capability.
    • You are binding the integers as text, when sqlite3 will happily bind integer values

    Try this code:

    BOOL ok = YES;
    sqlite3_exec(databaseRefObj, "BEGIN TRANSACTION", 0, 0, 0);
    const char *insertintoGropsMember = "My insert query here";
    if (sqlite3_prepare_v2(databaseRefObj, insertintoGropsMember, -1, &sqlstatement, NULL) == SQLITE_OK)
    {
        for (NSString *contactIDstr in contactID)
        {
            sqlite3_bind_int(sqlstatement, 1, grpID);
            sqlite3_bind_text(sqlstatement, 2, [contactIDstr UTF8String], -1, 0);
            if (sqlite3_step(sqlstatement) != SQLITE_DONE)
            {
                NSLog(@"Error inserting row: %s", sqlite3_errmsg(databaseRefObj));
                ok = NO;
                break;
            }
            sqlite3_reset(sqlstatement);
        }
        sqlite3_finalize(sqlstatement);
    
        sqlite3_exec(databaseRefObj, ok ? "COMMIT" : "ROLLBACK", 0, 0, 0);
    }
    else
    {
        NSLog(@"Error preparing statement: %s", sqlite3_errmsg(databaseRefObj));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a LocatorPane with more than one Locator using LocatorAutoCreate
have been away from Android for more than a year, trying to pick up
I have a WPF billing solution that is deployed using ClickOnce for more than
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to save my Photo class that has a byte[] File field. When
I am trying to save multiple image using this code. But instead its saving
Is it possible to have more than one custom uitableviewCell within the same xib?
I'm trying to send more than one image file from a client to the
I am trying to process a text file of more than 1GB and saving
(ruby 1.9.2, rails 3.1) Following Michael Hartl's tutorial. Spent more than a day trying

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.