sqlite.lua
sqlite.lua copied to clipboard
Error when inserting certain strings with brackets
I've come across a bug when running the following code:
local tbl = require("sqlite.tbl") --- for constructing sql tables
local db = require("sqlite.db") --- for constructing sql databases
-- the data table
local tbl_data = tbl("data", {
id = true,
test = { "text", required = true, unique = true },
})
local tbls = {
uri = "~/test.sqlite3",
data = tbl_data,
}
local data = db(tbls)
data.data:remove() -- to ensure tbl is empty
data.data:insert({ test = "tes(t)" })
Gives:
E5113: Error while calling lua chunk: ...im/site/pack/packer/start/sqlite.lua/lua/sqlite/stmt.lua:35
: sqlite.lua: sql statement parse, , stmt: `insert into data (test) values(tes(t))`, err: `(`no such
column: t`)`
It only happens when
- both opening and closing brackets are in the string
- the closing bracket is the last char of the string
I'm guessing something isn't being escaped properly.
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.