Hi, guys.

Dennis Cote wrote:
Stephen,

You should look into using the newer prepare/step API functions instead of the callback mechanism. It will make your code clearer, and will probably execute faster as well.

I don't think so. Prepare/step mechanism can invoke productivity of "INSERT" or "UPDATE", or something like this, when you have much rows to insert/update. But when you need to do "SELECT" sqlite3_exec - the best way in my opinion. Look at the code that you represent - this is the answer on all questions. Want you or don't, but you must allocate memory for result and call function in C/C++ is very cheaply operation. You sad: "It will make your code clearer". I don't agree. Look...

char * sql = sqlite3_mprintf( "SELECT * FROM %s", table_name );
int ret = sqlite3_exec( db, sql, callback, NULL, NULL );
sqlite3_free( sql );

What can be clearer than it???

But when you store many information in DB than transactions/prepare/step are more preferable for productivity. But it does not make code clearer, inside out...


The new API is used to implement the current version of sqlite3_exec that uses the callback mechanism so you can look at that code to see how the new API is used. The following excerpt is from the file legacy.c in the sqlite source. It shows how sqlite uses the new API functions to build the arrays of strings it passes to the callback function.

By using the new API functions directly you can avoid the overhead of converting all the database fields into string and building these arrays, only to have your callback function iterate over the string arrays and convert the values back into other types (for non string fields anyway) and then stuff them into vectors. You can extract the fields and store them directly into the vectors you want.

And here I see this magic word "callback" :)

--
Regards,
Igor Mironchick,
Intervale ©
#ICQ 492-597-570


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to