sqlite3_exec statement count including create/drop?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

sqlite3_exec statement count including create/drop?

petern
Is there a C API way to get a total count or notification as each statement
is prepared by sqlite_prepare_v2 within sqlite3_exec?  The sqlite3_exec
callback interface is silent with respect to CREATE and DROP statements.

Presumably I could copy and paste the entire body of sqlite3_exec into my
program and add a counter update in the right spot but I'd rather not if
the API can tell me the running or total statement count somehow.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_exec statement count including create/drop?

Clemens Ladisch
petern wrote:
> Is there a C API way to get a total count or notification as each statement
> is prepared by sqlite_prepare_v2 within sqlite3_exec?

sqlite3_trace_v2() with SQLITE_TRACE_PROFILE is called at the end of each
statement.


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_exec statement count including create/drop?

petern
Clemens.  I'm trying you suggestion but...

linker says -> "undefined reference to `sqlite3_trace_v2'"

[I am linking to libsqlite3.so.  Version by sqlite_version() is 3.19.3.]

Is sqlite3_trace_v2() defined by a SQLite compile time option and if so
what is it?

Help page has only negative SQLITE_OMIT_TRACE:
https://sqlite.org/compile.html

I don't see anything called TRACE in bld/Makefile.




On Mon, Jun 19, 2017 at 1:05 AM, Clemens Ladisch <[hidden email]> wrote:

> petern wrote:
> > Is there a C API way to get a total count or notification as each
> statement
> > is prepared by sqlite_prepare_v2 within sqlite3_exec?
>
> sqlite3_trace_v2() with SQLITE_TRACE_PROFILE is called at the end of each
> statement.
>
>
> Regards,
> Clemens
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_exec statement count including create/drop?

Clemens Ladisch
petern wrote:
> linker says -> "undefined reference to `sqlite3_trace_v2'"

Then your distribution's package appears to be compiled with
SQLITE_OMIT_TRACE.

Just add sqlite3.c to your project.


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_exec statement count including create/drop?

petern
Hi Clemens.

Found the problem.  My IDE is picking up other installed libsqlite3.so.  It
was wrong to think that uninstalling the distro's SQLite package would
purge it from /usr/lib.  Other copies still exist.  I'm sure glad the
project is now linking the correct library file!

Regarding sqlite3_trace_v2(db, SQLITE_TRACE_PROFILE,...).  Calls to
sqlite3_sql() on the third trace callback parameter (cast to sqlite_stmt*)
do retrieve the correct part of the the original sqlite3_exec input SQL
string except for ill formed SQL.  Apparently the SQLITE_TRACE_PROFILE
event is not generated for the failed statement.

It would have been helpful to see the event and the parse point of the
failed statement.

At the same time, I found that setting PRAGMA empty_result_callbacks=1 also
has the desired effect of causing sqlite3_exec callbacks on every statement
including create/drop.  However, there is no way of accessing the statement
sql at all that way.

Thanks for your help so far.  This was worth it just to straighten out my
linker issues!

Do you have further thoughts on getting the parse point of the failed
statement from sqlite3_exec on a multiple statement SQL string?

Peter





On Mon, Jun 19, 2017 at 1:30 PM, Clemens Ladisch <[hidden email]> wrote:

> petern wrote:
> > linker says -> "undefined reference to `sqlite3_trace_v2'"
>
> Then your distribution's package appears to be compiled with
> SQLITE_OMIT_TRACE.
>
> Just add sqlite3.c to your project.
>
>
> Regards,
> Clemens
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_exec statement count including create/drop?

Clemens Ladisch
petern wrote:
> Regarding sqlite3_trace_v2(db, SQLITE_TRACE_PROFILE,...).  Calls to
> sqlite3_sql() on the third trace callback parameter (cast to sqlite_stmt*)
> do retrieve the correct part of the the original sqlite3_exec input SQL
> string except for ill formed SQL.  Apparently the SQLITE_TRACE_PROFILE
> event is not generated for the failed statement.

I don't think there is any callback that is called before the statement
is prepared.

> Do you have further thoughts on getting the parse point of the failed
> statement from sqlite3_exec on a multiple statement SQL string?

Even if you copy the sqlite3_exec implemention, the error message will
mention nothing more than a wrong token.


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...