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

unrecognized token: "$" on db:select #158

Open
yyy33 opened this issue Jan 13, 2023 · 1 comment
Open

unrecognized token: "$" on db:select #158

yyy33 opened this issue Jan 13, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@yyy33
Copy link

yyy33 commented Jan 13, 2023

  1. create file /tmp/test.db
local _, sqlite = pcall(require, 'sqlite.db')
local  context = [[
The command is always executed with 'magic' not set.  The only special
characters in a search pattern are "^" (begin-of-line) and "$" (<EOL>).
See |pattern|.  Note that you must put a backslash before each backslash in
the search text.  This is for backwards compatibility with Vi.
]]

local db = sqlite.new('/tmp/test.db'):open()
local ok = db:create("sentence", {
    id = { type = "integer", required = true, primary = true },
    context = { type = "text", required = true },
    ensure = true,
})

local ok, data_id = db:insert('sentence', {
    context = context,
})

if ok then
    local sentence_table = db:select('sentence', {
        where = {
            context = context,
        }
    })
end
  1. execute luafile /tmp/test.db
  2. i get error
E5113: Error while calling lua chunk: ...ig/nvim/pack/packer/start/sqlite.lua/lua/sqlite/stmt.lua
:35: sqlite.lua: sql statement parse, , stmt: `select * from sentence where context = "The comman
d is always executed with 'magic' not set.  The only special
characters in a search pattern are "" (begin-of-line) and "$" (<EOL>).
See |pattern|.  Note that you must put a backslash before each backslash in
the search text.  This is for backwards compatibility with Vi.
"`, err: `(`unrecognized token: "$"`)`
stack traceback:
        [C]: in function 'assert'
        ...ig/nvim/pack/packer/start/sqlite.lua/lua/sqlite/stmt.lua:35: in function 'parse'
        ...nfig/nvim/pack/packer/start/sqlite.lua/lua/sqlite/db.lua:604: in function 'fn'
        ...ig/nvim/pack/packer/start/sqlite.lua/lua/sqlite/defs.lua:663: in function 'select'
        /tmp/t.lua:21: in main chunk
@yyy33 yyy33 changed the title error when select [bug]error when select Jan 13, 2023
@kkharji
Copy link
Owner

kkharji commented Jan 13, 2023

This known issue #150

In this case I tried @steliyan escape and unescape function:

local escape = function(content)
  return string.format("__ESCAPED__'%s'", content)
end

local unescape = function(content)
  return content:gsub("^__ESCAPED__'(.*)'$", "%1")
end

The insert works without escaping, however the where function fails with escaping insert and selected.

The error result from libsqlite itself. hmmm seems something you have to adhere to in sqlite itself. However it would be nice if this can be supported here.

@kkharji kkharji added the bug Something isn't working label Jan 13, 2023
@kkharji kkharji changed the title [bug]error when select unrecognized token: "$" on db:select Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants