-
Notifications
You must be signed in to change notification settings - Fork 27
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
Error when inserting certain strings with brackets #150
Comments
This happens because some sql functions are passed as is. I guess the parser function should have had a list of known sqlite function and escape, quote unrecognized ones. I doubt I will fix this soon, but feel free to look into how statements are parsed |
Ok, thanks! I totally understand, I will probably just implement some escaping in my plugin. I'll have a look at the parser if I get to it and maybe submit a PR if I can think of anything. |
Pretty much hit the same: nvim-telescope/telescope-smart-history.nvim#7 Hacky workaround... but it works. :) |
Thanks a lot @steliyan, this will be very useful for my plugin as I haven't implemented a fix yet 😅 |
@kkharji I looked into it and fixed it by providing an additional argument to treat everything as "raw" strings - meaning, whatever string you pass, it's written as-is in SQLite, nothing gets treated as a function. The good thing is - it's backwards compatible, but I don't really like the usage. I've added I was thinking a better approach would be to have something like: sqlite.fn = {
count = function(...) end,
date = function(...) end,
-- the rest of the funcs
} Use like: local db = sqlite.new('my.sqlite')
local table = db:tbl("history", {
id = true,
content = "text",
picker = "text",
cwd = "text",
date = "date"
})
table:insert { content = escape(line), picker = title, cwd = cwd, date = sqlite.fn.now() } This would simplify the parser, the upside (and downside maybe?) is the complexity would be pushed down to the consumer, but if the consumers are APIs and doesn't really rely on executing random statement, this would be an overall win. Any thoughts? |
@steliyan Thanks for looking into it. Yes, insertRaw would be out of place. How about we just relay on field type definition and just auto escape anything of text or string type? I feel this is way cleaner then introducing an escape function to end users. Most cases like 99% would like the text to be skipped. Maybe for those 1% how still want to use the high-level apis with inline sqlite function can have a function e.g. What do you think? |
Sorry for misleading you, table:insert { content = line, picker = title, cwd = cwd, date = sqlite.fn.now() } If I would expect this exact behavior, however, this would be a breaking change, not sure if you are OK with that. Current stateFrom what I got from the codebase, I see 2 entry points:
|
Oh so this would auto-escape.
🤔 Yes, but this would break some programs. Put it is what we all expect 99% of the time and having to worry about what we insert is unnecessary. However, given that we do provide
Could you an give an example?. Not sure if this a suggestion or affirmation 😄
Hmmm here, db:eval is considered low level api and nothing should be done to it. Whatever sqlite accept it should too. No extra handling or magic should be introduced here.
🤔 idk how I feel about that. Maybe seperate module called @steliyan you can go ahead implement what we discuss, it easier to review code. Good luck |
Here is a sample implementation, a couple of open questions, but do you agree with the general direction? |
I've come across a bug when running the following code:
Gives:
It only happens when
I'm guessing something isn't being escaped properly.
The text was updated successfully, but these errors were encountered: