Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Please find question1 as you read along the code:

C++
function()
{
if(sqlite3_open(ch, &database) == SQLITE_OK)
{
    const char *pSQL[6];
    pSQL[3] = "select * from TagValues";
    sqlite3_stmt *statement, *statement4;
    char* errorMessage;
    CString csValue, queryStr, Tag;
    if ( sqlite3_prepare(database, pSQL[3], -1, &statement, 0 ) == SQLITE_OK )
    {
        int ctotal = sqlite3_column_count(statement);
        int res = 0;
        sqlite3_exec(database, "BEGIN TRANSACTION", NULL, NULL, &errorMessage);
        while ( 1 )
	{
	    res = sqlite3_step(statement);
            if ( res == SQLITE_ROW ) 
	    {
		for ( int i = 0; i < 1; i++ ) 
		{
		    Tag = (char*)sqlite3_column_text(statement, i);
                    queryStr.Format(L"update TagValues set Value='%s' where Tag='%s'", csValue, Tag);
		    pSQL[4] = T2A(queryStr);
                    sqlite3_prepare(database, pSQL[4], -1, &statement4, 0 );//Question 1: is this really executing in a bulk??? or is it executing right away?
                }
            }
            if ( res == SQLITE_DONE)    
	    {
		sqlite3_exec(database, "END TRANSACTION", NULL, NULL, &errorMessage);
            }
        }
    } 
}
}


Its taking 2 seconds to update 400 entries of pSQL[4]. Please suggest me. If i remove both end and begin transactions, the time is still the same.
Posted
Updated 2-Aug-12 9:53am
v2

1 solution

A transaction does not make things faster. It can actually slow it down, the point of a transaction is for the update to happen all at once, that is, for you to decide half way through to abandon the process and restore the state of your DB to what it was when the transaction started.
 
Share this answer
 
Comments
amarasat 3-Aug-12 10:50am    
can you suggest me which way to proceed to reduce the time when updating a sqlite database with c++. Or point me to a good example so that i can proceed myself.

Thanks a lot!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900