Simon, On Mon, Apr 29, 2013 at 12:18 PM, Simon Slavin <[email protected]> wrote:
> > On 29 Apr 2013, at 7:55pm, Igor Korot <[email protected]> wrote: > > > Problem is sqlite3_prepare_v2() wastes time by compiling SQL statements > and > > I'd like to avoid it by making this call only once and just > > bind the appropriate parameters on each loop iteration. > > > > Would it be possible if I make local function variable "static > sqlite3_stmt > > *stmt;" instead of class member variable? > > Problem is in this case I will need 2 of them for each query, right? > > Just define and prepare the statement outside of your loop. I wish. ;-) This class (CDb) is nicely encapsulating the database communication. All it's doing is inserting/retrieving data from the db. It does not know anything about outside world. Now on the outside I have a GUI application, which on exit ask the user if (s)he wanst to save data. If the answer is yes, then I start transaction and in the loop saving all changes. I would very much like to keep those 2 pieces independent - GUI and DB there are. > You can reuse a prepared statement by resetting it. After you've reset > it you can leave the existing bindings alone or rebind any variables to new > values. See section 3.0 of > > <http://www.sqlite.org/cintro.html> > > You can have any number of statements defined and prepared at once. > Yes, I read this link. But I don't understand how it applies here. Can you make some pseudo code, please? > > By the way, there is no need to ROLLBACK a statement that fails. A > statement that fails, fails. It just does nothing. You might be rolling > back other statements in the same transaction but that doesn't seem to be > in the code you showed. > Yes, I'm rolling back some previous statements. Thank you. > > Simon. > _______________________________________________ > sqlite-users mailing list > [email protected] > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

