i`ve done it, and i think i understand it :)
thank you..
few more question to be sure that i`m not missing something important..
if i use prepared statements only (dont use exec function in program at all)
i dont need callback function, do i?
somehow after i replaced exec (i.e. select_statement function) and i dont
need select_statement function, neither callback function, evetything seems
much more simple (which is why i`m bit suspicious if i`ve done everything
correct)..
are there any cases when it is better to use exec ?
does using prepared statement slow down my program since prepare function is
used every time when i want to execute some command ? here is how my
function looks like now:
bool create2 (char * command)
{
sqlite3_stmt * statement2;
if ( sqlite3_prepare (db, command, -1, &statement2, 0) != SQLITE_OK )
{
int err = sqlite3_prepare (db, command, -1, &statement2, 0);
const char * pErr = sqlite3_errmsg (db);
printf ("\nError %d occured! \n %s", err, pErr );
return false;
}
int iCol = sqlite3_column_count (statement2);
int smth, i;
//int rows=1;
smth=sqlite3_step(statement2);
while (smth == SQLITE_ROW)
{
printf ("\n");
//printf ("\n Row %d:\t", rows); // doesnt give right number of column
for other select statements except select all
for (i=0; i<iCol; i++)
{
const char *txt = (const char*)sqlite3_column_text(statement2,
i); // save
it into dynamical multidimensional array
printf (" %s = %s \t", sqlite3_column_name (statement2,i), txt
);
}
printf ("\n");
//rows++;
smth=sqlite3_step (statement2);
}
sqlite3_reset (statement2);
sqlite3_finalize (statement2);
return true;
}
main:
create2 ("CREATE TABLE two (ID INTEGER PRIMARY KEY ASC, a,b,c)");
create2 ("INSERT INTO two (a,b) VALUES (3, 4)");
create2 ("INSERT INTO two (a,b,c) VALUES (2, 8, 9)");
create2 ("INSERT INTO two (a,c) VALUES (4, 1)");
create2 ("INSERT INTO two (a,b,c) VALUES (1, 4, 9)");
create2 ("INSERT INTO two (a,b,c) VALUES (1, 2, 8)");
create2 ("SELECT * FROM two");
create2 ("SELECT * FROM two WHERE b=4");
if you have some advices or suggestions please let me know..
--
View this message in context:
http://old.nabble.com/execute-or-prepare%2Bstep%2Bfinalize-tp26299247p26302994.html
Sent from the SQLite mailing list archive at Nabble.com.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users