[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luapsql issues
- From: Marc Balmer <marc@...>
- Date: Wed, 31 Oct 2012 09:08:03 +0100
> So luapsql also has the build issue I posted about earlier, and also
> fails without giving any error message!
>
>
> #!/usr/bin/env lua5.1
> local sql = require('psql')
>
> if not arg[1] then
> print("Usage: " .. arg[0] .. " database-name")
> os.exit(1)
> end
>
> local name = arg[1]
> os.execute("createdb '" .. name .. "'")
> local db = assert(sql.connect(("host=localhost dbname='%s'"):
> format(name, name)))
>
> local function exec(query, ...)
> return assert(db:exec(query, ...))
> end
>
> exec [[
> CREATE TABLE channels (
> id INTEGER PRIMARY KEY,
> path VARCHAR(16384) NOT NULL
> ); ]]
>
>
> lua5.1: ./create-database.lua:26: assertion failed!
> stack traceback:
> [C]: in function 'assert'
> ./create-database.lua:26: in function 'exec'
> ./create-database.lua:33: in main chunk
> [C]: ?
>
> sure enough db:exec() returns absolutely nothing. Oi.
The connectdb() function always returns a connection object, unless there is no more memory. You have to check the connection status using the status() method:
local conn = pgsql.connectdb('')
if conn:status ~= pgsql.CONNECTION_OK then
print('no connection made')
os.exit(1)
end