On Tue, Jan 12, 2010 at 10:22 AM, zhangzhenggui <zhangzheng...@126.com>wrote:

> Dear friend,
>    When I execute a SQL with C/C++ API, I want to know which table is
> operated by this SQL. Is there any way to do this except parse the SQL?
>
>
Every approach is not perfect, here is another one.

add EXPLAIN to the query you examine, iterate through the results while
collecting p2 field where opcode field is "OpenRead" or "OpenWrite" (you
have to iterate since you can not use Explain prefixed query as a subquery).
Concatenate the values as a comma-separated string like "3, 4, 7". These are
the root pages of the tables used.

After that use query

SELECT tbl_name FROM sqlite_master WHERE type="table" and rootpage in (%s)

(replace %s with your comma-seprated list). Now you have the list of tables
used as a query result.
I have not high level of certainty this will always work as expected, but
compare this with other "undocumented", "subject to change" variants and
choose the best )

Max
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to