[sqlite] What is the right order of the main SQLite functions?
Thanks, all working beautifully now. RBS On Fri, Mar 20, 2015 at 1:27 AM, Simon Slavin wrote: > > On 19 Mar 2015, at 11:48pm, Bart Smissaert > wrote: > > > Is this all how it should be? > > Apart from the following, nothing I see looks like it will cause > problems. You should be checking the result codes of all the calls you do > to make sure you are getting SQLITE_OK (==0) returned from them and not an > error. > > > Where/when should I call sqlite3_close? > > Once you know you don't need access to the database any more. Before your > application quits. As above, check to see that you are getting SQLITE_OK > back to indicate that your connection to the database was still working > correctly when you closed it. > > > Does Clearbindings come indeed before finalize? > > You do not need to clear bindings before _finalize(), since _finalize() > releases all the bindings for you as part of releasing all resources used > by the statement. > > You might want to clear bindings before or after a _reset(), since it can > help you to find errors when you start binding for the next use of the > statement. > > Simon. > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >
[sqlite] What is the right order of the main SQLite functions?
On 19 Mar 2015, at 11:48pm, Bart Smissaert wrote: > Is this all how it should be? Apart from the following, nothing I see looks like it will cause problems. You should be checking the result codes of all the calls you do to make sure you are getting SQLITE_OK (==0) returned from them and not an error. > Where/when should I call sqlite3_close? Once you know you don't need access to the database any more. Before your application quits. As above, check to see that you are getting SQLITE_OK back to indicate that your connection to the database was still working correctly when you closed it. > Does Clearbindings come indeed before finalize? You do not need to clear bindings before _finalize(), since _finalize() releases all the bindings for you as part of releasing all resources used by the statement. You might want to clear bindings before or after a _reset(), since it can help you to find errors when you start binding for the next use of the statement. Simon.
[sqlite] What is the right order of the main SQLite functions?
Thanks, that is very useful. Maybe this should be more clearly (and simple) in the documentation somewhere. RBS On Fri, Mar 20, 2015 at 12:23 AM, Igor Tandetnik wrote: > On 3/19/2015 7:48 PM, Bart Smissaert wrote: > >> I know this is basic and should be in the documentation, but it is not >> quite clear to me. >> Basically I have 3 type of procedures: >> >> 1. Getting values from a table. For this I have the following steps: >> >> (Open) >> Prepare >> >> Then in a loop: >> >> Step >> ColumnInt, ColumnDouble, ColumnText >> >> After the loop: >> >> Finalize >> > > Looks good to me. > > 2. Putting values in a table: >> >> (Open) >> Start Transaction >> Prepare >> > > These two could be in any order > > Then in a loop: >> Bind >> Step >> Reset >> >> After the loop: >> >> Clearbindings >> Finalize >> Commit Transaction >> > > It's pointless to clear bindings right before finalize. And commit could > happen either before or after. > > 3. Non looped procedures, eg, delete and update: >> >> (Open) >> Prepare >> Step >> Reset >> Finalize >> > > You don't need reset before finalize. > > Is this all how it should be? >> > > It'll work. There are a few redundancies, but they are harmless. > > Where/when should I call sqlite3_close? >> > > When you no longer need the connection, of course. > > Does Clearbindings come indeed before finalize? >> > > I have yet to find a reason to call sqlite3_clear_bindings. It's needed > very rarely, if ever. It's absolutely pointless right before finalize. > -- > Igor Tandetnik > > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users >
[sqlite] What is the right order of the main SQLite functions?
I know this is basic and should be in the documentation, but it is not quite clear to me. Basically I have 3 type of procedures: 1. Getting values from a table. For this I have the following steps: (Open) Prepare Then in a loop: Step ColumnInt, ColumnDouble, ColumnText After the loop: Finalize 2. Putting values in a table: (Open) Start Transaction Prepare Then in a loop: Bind Step Reset After the loop: Clearbindings Finalize Commit Transaction 3. Non looped procedures, eg, delete and update: (Open) Prepare Step Reset Finalize Is this all how it should be? Where/when should I call sqlite3_close? Does Clearbindings come indeed before finalize? Thanks for any clarification. RBS
[sqlite] What is the right order of the main SQLite functions?
On 3/19/2015 7:48 PM, Bart Smissaert wrote: > I know this is basic and should be in the documentation, but it is not > quite clear to me. > Basically I have 3 type of procedures: > > 1. Getting values from a table. For this I have the following steps: > > (Open) > Prepare > > Then in a loop: > > Step > ColumnInt, ColumnDouble, ColumnText > > After the loop: > > Finalize Looks good to me. > 2. Putting values in a table: > > (Open) > Start Transaction > Prepare These two could be in any order > Then in a loop: > Bind > Step > Reset > > After the loop: > > Clearbindings > Finalize > Commit Transaction It's pointless to clear bindings right before finalize. And commit could happen either before or after. > 3. Non looped procedures, eg, delete and update: > > (Open) > Prepare > Step > Reset > Finalize You don't need reset before finalize. > Is this all how it should be? It'll work. There are a few redundancies, but they are harmless. > Where/when should I call sqlite3_close? When you no longer need the connection, of course. > Does Clearbindings come indeed before finalize? I have yet to find a reason to call sqlite3_clear_bindings. It's needed very rarely, if ever. It's absolutely pointless right before finalize. -- Igor Tandetnik