Closed JorjBauer closed 5 years ago
Working on a replacement. The constants for connection-time are exported after the connection is created, so my test script is actually passing in 'nil' as the flags. So there are at least three problems:
The abstraction as-is doesn't provide any connectivity between DBI and the submodules until it calls New(), right after loading, in Connect(). So some new abstraction is necessary.
I clearly don't understand what the test script is doing, since it's passing a nil as the second argument (the error that Jenkins flagged).
Apparently my local sqlite3 is creating a temporary database somewhere rather than creating one in-memory, and my own test for in-memory and read-only opens isn't sufficient :)
Problems sorted. Functioning test script, which forces a read-only file into the filesystem to prove it's not creating a new temporary database on disk. Obviously 5.3 (I'm using bitwise or here) but could just use '+' with 5.1/5.2 since they're bit flags.
require 'std.strict' local DBI = require "DBI" local s = require "dbd.sqlite3"
os.execute("touch memorytest") os.execute("chmod a-w memorytest") local db,_ = DBI.Connect("SQLite3", "memorytest", s.SQLITE_OPEN_MEMORY|s.SQLITE_OPEN_CREATE|s.SQLITE_OPENREADWRITE) assert(db,) os.execute("rm -f memorytest")
assert(DBI.Do(db, [[ CREATE TABLE foo (bar integer, baz varchar(25)) ]] ))
local sth,err = db:prepare( [[ INSERT INTO foo (bar, baz) VALUES (?,?) ]] ) assert(sth,err) assert(sth:execute(1, "The Loneliest")) assert(sth:execute(42, "The Answer"))
sth,err = db:prepare( [[ SELECT * FROM foo ]] ) assert(sth,err) assert(sth:execute())
for row in sth:rows(true) do print ("Fetched row: " .. row['bar'] .. " == " .. row['baz']) end
Looks great to me!
Adds optional support for SQLite3's open flags, supporting features like in-memory databases.
!/usr/bin/env lua
local DBI = require "DBI" local s = require "dbd.sqlite3"
local db = DBI.Connect("SQLite3", "memory", SQLITE_OPEN_MEMORY) assert(db)
assert(DBI.Do(db, [[ CREATE TABLE foo (bar integer, baz varchar(25)) ]] ))
local sth,err = db:prepare( [[ INSERT INTO foo (bar, baz) VALUES (?,?) ]] ) assert(sth,err) assert(sth:execute(1, "The Loneliest")) assert(sth:execute(42, "The Answer"))
sth,err = db:prepare( [[ SELECT * FROM foo ]] ) assert(sth,err) assert(sth:execute())
for row in sth:rows(true) do print ("Fetched row: " .. row['bar'] .. " == " .. row['baz']) end