Do not create duplicate connections in sb_lua_db_connect().

This commit is contained in:
Alexey Kopytov
2017-01-30 11:31:50 +03:00
parent 5d36164b98
commit dbce3039a7

View File

@ -832,10 +832,14 @@ int sb_lua_db_connect(lua_State *L)
sb_lua_ctxt_t * const ctxt = &tls_lua_ctxt;
ctxt->driver = db_create(NULL);
if (ctxt->driver == NULL)
if (ctxt->driver == NULL) {
luaL_error(L, "DB initialization failed");
lua_pushstring(L, ctxt->driver->sname);
lua_setglobal(L, "db_driver");
lua_pushstring(L, ctxt->driver->sname);
lua_setglobal(L, "db_driver");
}
if (ctxt->con != NULL)
return 0;
ctxt->con = db_connection_create(ctxt->driver);
if (ctxt->con == NULL)
@ -889,8 +893,13 @@ int sb_lua_db_query(lua_State *L)
query = luaL_checklstring(L, 1, &len);
rs = db_query(con, query, len);
if (rs == NULL && con->error == DB_ERROR_IGNORABLE)
throw_restart_event(L);
if (rs == NULL)
{
if (con->error == DB_ERROR_IGNORABLE)
throw_restart_event(L);
else if (con->error == DB_ERROR_FATAL)
luaL_error(L, "db_query() failed");
}
if (rs != NULL)
db_free_results(rs);