LuaSQLite3

Check-in [1c355fc530]
Login

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

Overview
Comment:Add GC test for Online Backup API.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1c355fc53033f925f162c3b77701e197a67c2beb
User & Date: e 2016-11-03 16:13:58
Context
2016-11-03
21:20
Update wiki doc for new Online Backup API support. check-in: 80be7a8591 user: e tags: trunk
16:13
Add GC test for Online Backup API. check-in: 1c355fc530 user: e tags: trunk
04:32
Add Online Backup API. check-in: be6de29e8f user: e tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/tests-sqlite3.lua.

  1124   1124       assert_equal (#row.val, 3)
  1125   1125     end
  1126   1126     for row in db:nrows("SELECT name as val FROM test WHERE id = 3") do
  1127   1127       assert_equal (row.val, 'Hello SQLite')
  1128   1128       assert_equal (#row.val, 12)
  1129   1129     end
  1130   1130   
         1131  +end
         1132  +
         1133  +local db_bu_gc = lunit_TestCase("Online Backup API GC")
         1134  +
         1135  +function db_bu_gc.setup()
         1136  +  db_bu_gc.db_src = assert( sqlite3.open_memory() )
         1137  +  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("CREATE TABLE test (id, name text)") )
         1138  +  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (1, 'Hello World')") )
         1139  +  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (2, 'Hello Lua')") )
         1140  +  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (3, 'Hello SQLite')") )
         1141  +  db_bu_gc.filename = "/tmp/__lua-sqlite3-20161103120909." .. os.time()
         1142  +  db_bu_gc.db_tgt = assert_userdata( sqlite3.open(db_bu_gc.filename) )
         1143  +end
         1144  +
         1145  +function db_bu_gc.teardown()
         1146  +  os.remove(db_bu_gc.filename)
         1147  +end
         1148  +
         1149  +function db_bu_gc.test()
         1150  +
         1151  +  local bu = assert_userdata( sqlite3.backup_init(db_bu_gc.db_tgt, 'main', db_bu_gc.db_src, 'main') )
         1152  +
         1153  +  db_bu_gc.db_src = nil
         1154  +  db_bu_gc.db_tgt = nil
         1155  +
         1156  +  collectgarbage()
         1157  +  collectgarbage() -- should not close dbs even though db_bu_gc refs nil'd since they are referenced by bu
         1158  +
         1159  +  assert_equal( sqlite3.DONE, bu:step(-1) )
         1160  +  assert_equal( sqlite3.OK, bu:finish() )
         1161  +  bu = nil
         1162  +
         1163  +  collectgarbage()
         1164  +  collectgarbage() -- should now close dbs
         1165  +
         1166  +  local db = assert_userdata( sqlite3.open(db_bu_gc.filename) )
         1167  +
         1168  +  for row in db:nrows("SELECT id as val FROM test WHERE name='Hello World'") do
         1169  +    assert_equal (row.val, 1)
         1170  +  end
         1171  +  for row in db:nrows("SELECT substr(name,7,3) as val FROM test WHERE id = 2") do
         1172  +    assert_equal (row.val,'Lua')
         1173  +    assert_equal (#row.val, 3)
         1174  +  end
         1175  +  for row in db:nrows("SELECT name as val FROM test WHERE id = 3") do
         1176  +    assert_equal (row.val, 'Hello SQLite')
         1177  +    assert_equal (#row.val, 12)
         1178  +  end
         1179  +
         1180  +  assert( db:close() )
         1181  +
  1131   1182   end
  1132   1183   
  1133   1184   lunit.main(arg)
  1134   1185