Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Text field returns one less character #4

Open
ghost opened this issue Mar 23, 2017 · 0 comments
Open

Text field returns one less character #4

ghost opened this issue Mar 23, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Mar 23, 2017

Test case:

Database:

CREATE TABLE test(v1 VARCHAR(20), v2 BLOB);
INSERT INTO test VALUES('abcd',X'ABCD');

Lua:

local sqlite = require 'lsqlite3'
local conn = sqlite.open('testdb.sqlite', "read")
local stmt = conn:prepare 'select v1,hex(v2) from test'

while stmt:step() do
  print(stmt:get_value(0), stmt:get_value(1))
end

stmt:finalize()
conn:close()

Actual output:

abc	ABC

Expected output:

abcd	ABCD

Fix:

--- lsqlite3.lua.bad	2017-03-23 20:34:53.000000000 +0100
+++ lsqlite3.lua.good	2017-03-23 20:45:58.000000000 +0100
@@ -995,7 +995,7 @@
 local value_handlers = {
 	[sqlite3.SQLITE_INTEGER] = function(stmt, n) return sqlite3.sqlite3_column_int(stmt, n) end,
 	[sqlite3.SQLITE_FLOAT] = function(stmt, n) return sqlite3.sqlite3_column_double(stmt, n) end,
-	[sqlite3.SQLITE_TEXT] = function(stmt, n) return ffi.string(sqlite3.sqlite3_column_text(stmt,n), sqlite3.sqlite3_column_bytes(stmt,n)-1) end,
+	[sqlite3.SQLITE_TEXT] = function(stmt, n) return ffi.string(sqlite3.sqlite3_column_text(stmt,n), sqlite3.sqlite3_column_bytes(stmt,n)) end,
 	[sqlite3.SQLITE_BLOB] = function(stmt, n) return sqlite3.sqlite3_column_blob(stmt,n), sqlite3.sqlite3_column_bytes(stmt,n) end,
 	[sqlite3.SQLITE_NULL] = function() return nil end
 }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants