cosmopolitan/tool/net/demo/sql-backup.lua
Paul Kulchenko bcae817215
Update SQLite deserialize to allow resizing restored DB (#701)
Using either option (FREEONCLOSE or RESIZEABLE) requires using
sqlite3_malloc. Ref. #436
2022-11-28 12:53:20 -08:00

18 lines
503 B
Lua

if GetAssetSize("backup.sqlite3") == nil then
Write("no backup exists. call <a href='sql-backupstore.lua'>sql-backupstore.lua</a> first.")
return
end
backup = sqlite3.open_memory()
buffer = LoadAsset("backup.sqlite3")
backup:deserialize(buffer)
-- insert more values
for i = 1, 250 do
backup:exec("INSERT INTO test (content) VALUES ('Hello more')")
end
-- See .init.lua for CREATE TABLE setup.
for row in backup:nrows("SELECT * FROM test") do
Write(row.id.." "..row.content.."<br>")
end