2009/11/11 TTTTT <erlichk...@gmail.com>: > > 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?
No > 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 ? <shrug> perhaps simpler/quicker to code for sql that returns no data (INSERT etc) </shrug> > > > does using prepared statement slow down my program since prepare function is > used every time when i want to execute some command ? No - sqlite3_exec() is a wrapper around sqlite3_prepare()/sqlite3_step() > 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); no need to call prepare a second time - assign to err in your if statement, or use sqlite3_errcode() > 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); Use sqlite3_reset if you are going to bind new values to your prepared statement and restep. If you are finalizing there is no need to reset. > 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.. > Regards, Simon _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users