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 Unified Diffs Ignore Whitespace Patch

Changes to test/tests-sqlite3.lua.

1124
1125
1126
1127
1128
1129
1130
1131
1132



















































1133
1134
    assert_equal (#row.val, 3)
  end
  for row in db:nrows("SELECT name as val FROM test WHERE id = 3") do
    assert_equal (row.val, 'Hello SQLite')
    assert_equal (#row.val, 12)
  end

end




















































lunit.main(arg)










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
    assert_equal (#row.val, 3)
  end
  for row in db:nrows("SELECT name as val FROM test WHERE id = 3") do
    assert_equal (row.val, 'Hello SQLite')
    assert_equal (#row.val, 12)
  end

end

local db_bu_gc = lunit_TestCase("Online Backup API GC")

function db_bu_gc.setup()
  db_bu_gc.db_src = assert( sqlite3.open_memory() )
  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("CREATE TABLE test (id, name text)") )
  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (1, 'Hello World')") )
  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (2, 'Hello Lua')") )
  assert_equal( sqlite3.OK, db_bu_gc.db_src:exec("INSERT INTO test VALUES (3, 'Hello SQLite')") )
  db_bu_gc.filename = "/tmp/__lua-sqlite3-20161103120909." .. os.time()
  db_bu_gc.db_tgt = assert_userdata( sqlite3.open(db_bu_gc.filename) )
end

function db_bu_gc.teardown()
  os.remove(db_bu_gc.filename)
end

function db_bu_gc.test()

  local bu = assert_userdata( sqlite3.backup_init(db_bu_gc.db_tgt, 'main', db_bu_gc.db_src, 'main') )

  db_bu_gc.db_src = nil
  db_bu_gc.db_tgt = nil

  collectgarbage()
  collectgarbage() -- should not close dbs even though db_bu_gc refs nil'd since they are referenced by bu

  assert_equal( sqlite3.DONE, bu:step(-1) )
  assert_equal( sqlite3.OK, bu:finish() )
  bu = nil

  collectgarbage()
  collectgarbage() -- should now close dbs

  local db = assert_userdata( sqlite3.open(db_bu_gc.filename) )

  for row in db:nrows("SELECT id as val FROM test WHERE name='Hello World'") do
    assert_equal (row.val, 1)
  end
  for row in db:nrows("SELECT substr(name,7,3) as val FROM test WHERE id = 2") do
    assert_equal (row.val,'Lua')
    assert_equal (#row.val, 3)
  end
  for row in db:nrows("SELECT name as val FROM test WHERE id = 3") do
    assert_equal (row.val, 'Hello SQLite')
    assert_equal (#row.val, 12)
  end

  assert( db:close() )

end

lunit.main(arg)