Giter Site home page Giter Site logo

lsqlite3-ffi's People

Contributors

colonelthirtytwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lsqlite3-ffi's Issues

get_values() bug

Hi,

In case of the BLOB type get_value() returns two values

return sqlite3.sqlite3_column_blob(stmt,n), sqlite3.sqlite3_column_bytes(stmt,n)

Which is later in get_values() function lost, so only pointer to blob is kept, the size is discarded by assignment.

function sqlite_stmt:get_values()
        local tbl = {}
        for i=0,sqlite3.sqlite3_column_count(self.stmt)-1 do
                tbl[i+1] = self:get_value(i)
--                         ^^^^ here is the problem
        end
        return tbl
end

Text field returns one less character

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
 }

Which license is used?

I would like to make use of the sqlite3 ffi bindings in an APGLv3 project. Since no license is defined this is impossible.

new_stmt_ptr never freed

Des this code helps ?

function sqlite_db:prepare(sql)
    local stmtptr = new_stmt_ptr()
    self:check(sqlite3.sqlite3_prepare_v2(self.db, sql, #sql+1, stmtptr, nil))

-- Following line is appropriate cleanup ?
    ffi.gc(stmtptr, sqlite3.sqlite3_finalize)

    local stmt = setmetatable(
    {
        stmt=stmtptr[0],
        db=self,
        trace=lsqlite3.DEBUG and debug.traceback() or nil
    },sqlite_stmt)
    self.stmts[stmt] = stmt
    return stmt
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.