lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Oct 31, 2012 at 4:08 AM, Marc Balmer <marc@msys.ch> wrote:
>
>
>> 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
>
>
>

I'm not sure where connectdb comes from... my example was using the
connect() method. I'm also really not understanding why connect() or
connectdb() would return anything other than nil and an error message
if connecting fails, or why the resulting object would then throw
useless errors instead of giving some hint as to the problem...

-- 
Sent from my Game Boy.