Re: [sqlite] How can I query a sqlite3_stmt to find outif ithas been run through the sqlite3_prepare_v2 function?
Yes. At times I get so wound up in the details of various parts of the code that I miss the obvious of setting the stmt pointer to null before using it. Thank you to Jay for reminding me of this. Your collective replies, answers and advice are very much appreciated, however the "how stupid are you" attitude of some of the posts are really quite ridiculous. Splitting hairs about my phrasing lacking the specifics of the levels of indirection to the statement doesn't change the fundamentals of the question, which was basically "how do I know if the stmt is initalized". Again thank you Jay for getting me out of the details so that the obvious became clear again. I'll try to be more clear in future questions. > From: paiva...@gmail.com > Date: Tue, 9 Mar 2010 13:21:18 -0500 > To: sqlite-users@sqlite.org > Subject: Re: [sqlite] How can I query a sqlite3_stmt to find outif ithas been > run through the sqlite3_prepare_v2 function? > > > int sqlite3_prepare(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt > > **ppStmt, const char **pzTail); > > > > Please tell me what the 4th parameter is then if it not a statement so that > > I may ask you in the words you are looking for. > > It's not a statement. Speaking in Igor's words it's a _pointer_ to > statement. Speaking in Jay's words it's a _pointer_ to _pointer_ to > statement structure. > Usually when people say they have "function that is being passed an > sqlite3_stmt object" they mean this prototype: > > void f(sqlite3_stmt* stmt); > > If you will check for NULL inside this function (as Jay suggested) and > prepare statement if it's NULL then you will never have a non-NULL > value there and memory will leak from you significantly. > > > Pavel > > On Tue, Mar 9, 2010 at 1:07 PM, Ed Curren wrote: > > > > According to the documentation the function prototype for > > sqlite3_prepare_v2 is the following: > > > > > > > > int sqlite3_prepare(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt > > **ppStmt, const char **pzTail); > > > > > > > > Please tell me what the 4th parameter is then if it not a statement so that > > I may ask you in the words you are looking for. > > > >> To: sqlite-users@sqlite.org > >> From: itandet...@mvps.org > >> Date: Tue, 9 Mar 2010 13:03:00 -0500 > >> Subject: Re: [sqlite] How can I query a sqlite3_stmt to find outif ithas > >> been run through the sqlite3_prepare_v2 function? > >> > >> Ed Curren wrote: > >> > Okay, let's try asking the question this way then. How do I know if > >> > I need to call prepare based on the condition or value or whatever of > >> > a statement that may or may not have already been passed to perpare > >> > as a parameter? > >> > >> You _cannot_ pass a statement to prepare as a parameter. > >> > >> Igor Tandetnik > >> > >> ___ > >> sqlite-users mailing list > >> sqlite-users@sqlite.org > >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > > ___ > > sqlite-users mailing list > > sqlite-users@sqlite.org > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How can I query a sqlite3_stmt to find out if it has been run through the sqlite3_prepare_v2 function?
Thank you for a straight answer Jay. > Date: Tue, 9 Mar 2010 12:10:17 -0600 > From: j...@kreibi.ch > To: sqlite-users@sqlite.org > Subject: Re: [sqlite] How can I query a sqlite3_stmt to find out if it has > been run through the sqlite3_prepare_v2 function? > > On Tue, Mar 09, 2010 at 11:47:39AM -0500, Ed Curren scratched on the wall: > > > > Hello all, > > > > I have a function that is being passed an sqlite3_stmt object. > > I assume you mean a sqlite3_stmt pointer. You should never > instance an actual sqlite3_stmt structure yourself. > > > Within this function I need to determine if the statement has been > > prepared. > > How can I accomplish this? > > Ummm... it's a pointer. Set it to NULL when you initialize whatever > data-structure it is in. When you prepare the statement, it will be > non-NULL. If you have reason to call sqlite3_finalize(), set the > pointer back to NULL. > > Test for NULL. > > -j > > -- > Jay A. Kreibich < J A Y @ K R E I B I.C H > > > "Our opponent is an alien starship packed with atomic bombs. We have > a protractor." "I'll go home and see if I can scrounge up a ruler > and a piece of string." --from Anathem by Neal Stephenson > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How can I query a sqlite3_stmt to find outif ithas been run through the sqlite3_prepare_v2 function?
According to the documentation the function prototype for sqlite3_prepare_v2 is the following: int sqlite3_prepare(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail); Please tell me what the 4th parameter is then if it not a statement so that I may ask you in the words you are looking for. > To: sqlite-users@sqlite.org > From: itandet...@mvps.org > Date: Tue, 9 Mar 2010 13:03:00 -0500 > Subject: Re: [sqlite] How can I query a sqlite3_stmt to find outif ithas been > run through the sqlite3_prepare_v2 function? > > Ed Curren wrote: > > Okay, let's try asking the question this way then. How do I know if > > I need to call prepare based on the condition or value or whatever of > > a statement that may or may not have already been passed to perpare > > as a parameter? > > You _cannot_ pass a statement to prepare as a parameter. > > Igor Tandetnik > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How can I query a sqlite3_stmt to find out if ithas been run through the sqlite3_prepare_v2 function?
Okay, let's try asking the question this way then. How do I know if I need to call prepare based on the condition or value or whatever of a statement that may or may not have already been passed to perpare as a parameter? > To: sqlite-users@sqlite.org > From: itandet...@mvps.org > Date: Tue, 9 Mar 2010 12:47:42 -0500 > Subject: Re: [sqlite] How can I query a sqlite3_stmt to find out if ithas > been run through the sqlite3_prepare_v2 function? > > Ed Curren wrote: > > This function will be called several times. The first time through > > the statment won't be prepared > > What do you mean, won't be prepared? How can one obtain a statement handle > without calling prepare? > > > so in that case the function will > > call sqlite3_preapre_v2 to prepare the statement. > > Note that sqlite3_preapre_v2 doesn't take a statement as a parameter. It > takes a database connection and a SQL string, and _produces_ the statement > from them. > > Imagine one saying "I have a FILE* handle and I need to call fopen on it", or > "I have a void* pointer and I need to call malloc on it". Well, your question > makes about as much sense. > > Igor Tandetnik > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How can I query a sqlite3_stmt to find out if it has been run through the sqlite3_prepare_v2 function?
Hi Igor, This function will be called several times. The first time through the statment won't be prepared, so in that case the function will call sqlite3_preapre_v2 to prepare the statement. Subsequent calls to the function will have the statment that is already prepared, so I do not want to attempt to call sqlite3_prepare_v2 again on a statment that is already prepared. Thanks very much for your help. > To: sqlite-users@sqlite.org > From: itandet...@mvps.org > Date: Tue, 9 Mar 2010 12:04:15 -0500 > Subject: Re: [sqlite] How can I query a sqlite3_stmt to find out if it has > been run through the sqlite3_prepare_v2 function? > > Ed Curren wrote: > > I have a function that is being passed an sqlite3_stmt object. > > Within this function I need to determine if the statement has been > > prepared. How can I accomplish this? > > Where else would a statement handle come from, if not from > sqlite3_prepare[_v2] ? What precisely is the other possibility you are trying > to defend against? > > Igor Tandetnik > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How can I query a sqlite3_stmt to find out if it has been run through the sqlite3_prepare_v2 function?
Hello all, I have a function that is being passed an sqlite3_stmt object. Within this function I need to determine if the statement has been prepared. How can I accomplish this? Thanks very much. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users