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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:21:17+00:00 2026-06-18T02:21:17+00:00

I want to insert 40000 records that i get from a web service into

  • 0

I want to insert 40000 records that i get from a web service into a sqlite database in my iPad app.

I wrote the following code, but it takes around 20 minutes, is there a faster way?

- (NSArray *)insertPriceSQLWithPrice:(Price *) price
{

SQLiteManager *dbInfo = [SQLiteManager sharedSQLiteManagerWithDataBaseName:@"codefuel_catalogo.sqlite"];


sqlite3 *database;

NSString *querySQL=[self formatStringQueryInsertWithTable:@"prices_list" andObject:price];


if(sqlite3_open([dbInfo.dataBasePath UTF8String], &database) == SQLITE_OK)
{
    sqlite3_stmt * compiledStatement;


    const char *query_stmt = [querySQL UTF8String];

    int result = sqlite3_prepare_v2(database, query_stmt, -1, &compiledStatement, NULL);

    if (result == SQLITE_OK)
    {
        int success = sqlite3_step(compiledStatement);

        NSLog(@"el numero de success es -> %i",success);
        if (success == SQLITE_ERROR)
            NSLog(@"Error al insertar en la base de datps");

    }
    else
        NSLog(@"Error %@ ERROR!!!!",querySQL);

    sqlite3_finalize(compiledStatement);
}

sqlite3_close(database);
return nil;
}
  • 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-18T02:21:18+00:00Added an answer on June 18, 2026 at 2:21 am

    There are three things that you need to do in order to speed up the insertions:

    • Move the call of sqlite3_open outside the loop. Currently, the loop is not shown, so I assume it is outside your code snippet
    • Add BEGIN TRANSACTION and COMMIT TRANSACTION calls – you need to begin transaction before the insertion loop and end it right after the loop is over.
    • Make formatStringQueryInsertWithTable truly parameterized – Currently it appears that you are not using prepared statements to their fullest, because despite using sqlite3_prepare_v2, you have no calls of sqlite3_bind_XYZ in your code.

    Here is a nice post that shows you how to do all of the above. It is plain C, but it will work fine as part of an Objective C program.

    char* errorMessage;
    sqlite3_exec(mDb, "BEGIN TRANSACTION", NULL, NULL, &errorMessage);
    char buffer[] = "INSERT INTO example VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)";
    sqlite3_stmt* stmt;
    sqlite3_prepare_v2(mDb, buffer, strlen(buffer), &stmt, NULL);
    for (unsigned i = 0; i < mVal; i++) {
        std::string id = getID();
        sqlite3_bind_text(stmt, 1, id.c_str(), id.size(), SQLITE_STATIC);
        sqlite3_bind_double(stmt, 2, getDouble());
        sqlite3_bind_double(stmt, 3, getDouble());
        sqlite3_bind_double(stmt, 4, getDouble());
        sqlite3_bind_int(stmt, 5, getInt());
        sqlite3_bind_int(stmt, 6, getInt());
        sqlite3_bind_int(stmt, 7, getInt());
        if (sqlite3_step(stmt) != SQLITE_DONE) {
            printf("Commit Failed!\n");
        }
        sqlite3_reset(stmt);
    }
    sqlite3_exec(mDb, "COMMIT TRANSACTION", NULL, NULL, &errorMessage);
    sqlite3_finalize(stmt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert a record into a MySQL database table from a formulaire.
I want insert in the row from database, array of values as that each
I want to insert some value from first and second foreach into database, but
I want insert a custom snippet into an XML file from code within an
i want to insert all processes that running into listbox, and also how to
I have 40000 records in my DataTable. I want to insert all the records
I exported some data from my database table into sql file as insert statements.
I want to insert a date record to an Access database. Here is my
I want to insert the following include tag into my webpage using JavaScript. <!--#include
I want to insert widgets into my ItemsControl and make them resizeable. How do

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.