LuaSQLite3

Check-in [7c4cdefcb9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Hack test file so it parses in Lua < 5.3
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fsl_9w | trunk
Files: files | file ages | folders
SHA1: 7c4cdefcb992da6aa00e1ec909549d99d91bbc45
User & Date: e 2015-01-07 02:12:41
Context
2016-11-02
15:17
Add unit tests to confirm proper NUL handling when fetching column. check-in: 4e931d1ae0 user: e tags: trunk
2015-01-07
02:12
Hack test file so it parses in Lua < 5.3 check-in: 7c4cdefcb9 user: e tags: fsl_9w, trunk
2015-01-06
22:46
Update README and version info for 0.9.3 release check-in: 4991508bc8 user: e tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/tests-sqlite3.lua.

869
870
871
872
873
874
875




876
877
878
879
880
881
882
...
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
function gco.teardown()
  assert_true( (gco.db == nil) or (gco.db:close() == sqlite3.OK) )
end


if _VERSION >= 'Lua 5.3' then





l53 = lunit_TestCase("Lua 5.3 integers")

function l53.setup()
  l53.db = assert( sqlite3.open_memory() )
  assert_equal( sqlite3.OK, l53.db:exec("CREATE TABLE test (id, val)") )
  assert_equal( sqlite3.OK, l53.db:exec("INSERT INTO test VALUES (1, 0x12345678abcdef09)") )
  assert_equal( sqlite3.OK, l53.db:exec("INSERT INTO test VALUES (2, 5.1234567890123456)") )
................................................................................
end

-- l53.db:close()
function l53.test_intfloat()
    local db = l53.db
    for row in db:nrows("SELECT val FROM test WHERE id = 1") do
      assert_equal (row.val, 0x12345678abcdef09)
      assert_equal (row.val & 0xffffffff, 0xabcdef09)
      assert_equal (row.val >> 32, 0x12345678)
    end
    for row in db:nrows("SELECT val FROM test WHERE id = 2") do
      assert_equal (row.val, 5.1234567890123456)
    end
    for row in db:nrows("SELECT val FROM test WHERE id = 3") do
      assert_equal (row.val, 42)
    end







>
>
>
>







 







|
|







869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
...
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
function gco.teardown()
  assert_true( (gco.db == nil) or (gco.db:close() == sqlite3.OK) )
end


if _VERSION >= 'Lua 5.3' then

-- this hack is avoid syntax errors in Lua < 5.3
local bitand = (load "return function (x, y) return x & y end")()
local bitshr = (load "return function (x, y) return x >> y end")()

l53 = lunit_TestCase("Lua 5.3 integers")

function l53.setup()
  l53.db = assert( sqlite3.open_memory() )
  assert_equal( sqlite3.OK, l53.db:exec("CREATE TABLE test (id, val)") )
  assert_equal( sqlite3.OK, l53.db:exec("INSERT INTO test VALUES (1, 0x12345678abcdef09)") )
  assert_equal( sqlite3.OK, l53.db:exec("INSERT INTO test VALUES (2, 5.1234567890123456)") )
................................................................................
end

-- l53.db:close()
function l53.test_intfloat()
    local db = l53.db
    for row in db:nrows("SELECT val FROM test WHERE id = 1") do
      assert_equal (row.val, 0x12345678abcdef09)
      assert_equal (bitand(row.val, 0xffffffff), 0xabcdef09)
      assert_equal (bitshr(row.val, 32), 0x12345678)
    end
    for row in db:nrows("SELECT val FROM test WHERE id = 2") do
      assert_equal (row.val, 5.1234567890123456)
    end
    for row in db:nrows("SELECT val FROM test WHERE id = 3") do
      assert_equal (row.val, 42)
    end