Skip to content

sqlite function in insert break other values #87

@kkharji

Description

@kkharji

Apparently the following parsed statement is not good enough to pass:

insert into timestamps (fid, date) values(:fid, julianday('now'))"

it does insert the date, but sadly ignore fid.

🤔 not sure how this would be solved 😭

function DB:insert(tbl_name, rows)
  --- ...
  clib.wrap_stmts(self.conn, function()
    for _, v in ipairs(items) do
      local s = stmt:parse(self.conn, P.insert(tbl_name, { values = v }))
      --> P.insert(....) => "insert into timestamps (fid, date) values(:fid, julianday('now'))"
      --> stmt:parse(..) => "insert into timestamps (fid, date) values(NULL, julianday('now'))"
      s:bind(v)
      s:step()
      s:bind_clear()
      table.insert(ret_vals, s:finalize())
    end
  end)
end

On the parser side, instead of binding to :date it uses the value in place.

local pvalues = function(defs, kv)
  --- ....
  local keys = {}
  for k, v in u.opairs(defs) do
    if type(v) == "string" and v:match "%a+%(.+%)" then
      tinsert(keys, v)
    else
      tinsert(keys, ":" .. k)
    end
  end

  return ("values(%s)"):format(tconcat(keys, ", "))
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions