--- a/dbd/mysql/connection.c Sun Nov 23 04:12:04 2008 +0000 +++ b/dbd/mysql/connection.c Wed Nov 26 10:01:03 2008 +0000 @@ -3,7 +3,7 @@ int dbd_mysql_statement_create(lua_State *L, connection_t *conn, const char *sql_query); /* - * connection = DBD.MySQl.New(dbname, user, password, host, port) + * connection,err = DBD.MySQl.New(dbname, user, password, host, port) */ static int connection_new(lua_State *L) { int n = lua_gettop(L); @@ -42,14 +42,15 @@ conn->mysql = mysql_init(NULL); - if (mysql_real_connect(conn->mysql, host, user, password, db, port, unix_socket, client_flag)) { - luaL_getmetatable(L, DBD_MYSQL_CONNECTION); - lua_setmetatable(L, -2); - } else { - luaL_error(L, "Failed to connect to database: %s", mysql_error(conn->mysql)); + if (!mysql_real_connect(conn->mysql, host, user, password, db, port, unix_socket, client_flag)) { lua_pushnil(L); + lua_pushfstring(L, "Failed to connect to database: %s", mysql_error(conn->mysql)); + return 2; } + luaL_getmetatable(L, DBD_MYSQL_CONNECTION); + lua_setmetatable(L, -2); + return 1; } @@ -63,6 +64,7 @@ if (conn->mysql) { mysql_close(conn->mysql); disconnect = 1; + conn->mysql = NULL; } lua_pushboolean(L, disconnect); @@ -85,7 +87,7 @@ } /* - * statement = connection:prepare(sql_string) + * statement,err = connection:prepare(sql_string) */ static int connection_prepare(lua_State *L) { connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_MYSQL_CONNECTION); @@ -95,7 +97,9 @@ } lua_pushnil(L); - return 1; + lua_pushstring(L, "Database not available"); + + return 2; } /*