Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access to sql statement #85

Closed
mtissington opened this issue Feb 13, 2017 · 8 comments
Closed

access to sql statement #85

mtissington opened this issue Feb 13, 2017 · 8 comments

Comments

@mtissington
Copy link

Certainly for debugging and logging it would be very helpful to have access to the last sql statement either thru the database object or thru the exception handler ... like get_code() ... get_sql().

Is this possible?

@zauguin
Copy link
Collaborator

zauguin commented Feb 13, 2017

It might be helpful, but I do not think it is worth storing it if we only use it for debugging.
If we so not store it it is AFAICT only possible to get the SQL code of a prepared statement.
This might be useful, because we can get the expanded SQL, meaning the SQL with bound parameters inserted.

@mtissington
Copy link
Author

mtissington commented Feb 13, 2017

I'm also using a sqlite swift lib for ios development too. It has the ability to access the sql and in my app I produce a log file. On numerous occasions having the sql has helped to track down errors.

fyi GRDB

@zauguin
Copy link
Collaborator

zauguin commented Feb 13, 2017

I think I do not really understand your usage. Do you use dynamically generated SQL queries? Do you use prepared statements?

@mtissington
Copy link
Author

I'm using prepared statements.

@zauguin
Copy link
Collaborator

zauguin commented Feb 13, 2017

So could your problem be solved if the SQL could be extracted from the prepared statements?

@mtissington
Copy link
Author

Not sure I understand your comment, first choice would be to have the expanded SQL available with parameters inserted as you say.

@zauguin
Copy link
Collaborator

zauguin commented Feb 13, 2017

I see three possible positions to expose the SQL code:

  1. I understand your request in a way that you want a method of the database object to return he last executed command. I don't think this is possible without manual caching. If you want this, you may be able to inherit from sqlite::database and overload operator<< to cache the command, but I do not think this kind of caching should be done by default.
  2. If you already have the object of a prepared statement and only want to get the code used to construct it (+bound parameters), that can be done. This information is provided by SQLite.
  3. Additionally we can integrate the code of the statement into the sqlite_exception.

@mtissington
Copy link
Author

2 and 3 sound great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants