-
Notifications
You must be signed in to change notification settings - Fork 619
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
Cannot properly escape PRAGMA command parameters #579
Comments
There is already support for a synthetic pragma called
|
The summary here is that SQLite supports pragmas, pragmas can have parameters for them. If the parameter is boolean, you can give it is a parameter and bind it properly, but if it is string, you cannot give it as a parameter, instead you need to give the full SQL directly, meaning there is the possibility to forget to escape the parameter properly. Maybe doubling quotes is enough to escape, I am not 100 % sure about that, but do not have any counter examples ready. Also I am not sure if the problem is even solvable here, maybe it would need to be solved in SQLite directly. |
And why not just use the pragma when connecting? For my special case it happened when trying to "rekey" a database, so it was not possible to do it via the config options. |
That might be the first thing to check on your side, ie confirm if it's a SQLite problem, or this driver's problem.
Not sure to understand this.
If you can also give it a try, that would be good. I will leave this as 'waiting for feedback' until you can provide some more details on the points above. |
Closing this as no feedback was received. |
SQLite has SQL extension called PRAGMA. It mostly takes enum and boolean parameters and these cases do not need prepared statements and arbitrary parameter escaping.
But some pragmas take string parameters. One example https://www.sqlite.org/pragma.html#pragma_temp_store_directory
This one is deprecated and maybe not relevant to be handled properly anymore.
But when using encrypted databases the encryption key is set with
PRAGMA key='your-secret-key';
Now, if this key contains
'
characters the command fails. See test testSetPragmaNotEscaped. Escaping the key input with the method from org.sqlite.core.CoreDatabaseMetaData#escape makes it work. The method is just not available. I guess to not encourage people to use that but use prepared statements properly. See testSetPragmaEscaped.As testSetPragmaParameter shows, using prepared statements to escape the contents is not supported. We get
So my question is:
The text was updated successfully, but these errors were encountered: