Make statistics available in case we use db_query instead of db_execute in scripts

This commit is contained in:
Vadim Tkachenko
2011-04-27 09:30:11 -07:00
parent 9a11bb64d6
commit d2788a00c6
2 changed files with 11 additions and 1 deletions

View File

@ -454,6 +454,12 @@ db_result_set_t *db_query(db_conn_t *con, const char *query)
rs->connection = con;
con->db_errno = con->driver->ops.query(con, query, rs);
if (con->db_errno == SB_DB_ERROR_DEADLOCK)
thread_stats[con->thread_id].deadlocks++;
db_update_thread_stats(con->thread_id, db_get_query_type(query));
if (con->db_errno != SB_DB_ERROR_NONE)
return NULL;

View File

@ -611,7 +611,11 @@ int sb_lua_db_query(lua_State *L)
query = luaL_checkstring(L, 1);
rs = db_query(ctxt->con, query);
if (rs == NULL)
luaL_error(L, "Database query failed");
{
if (ctxt->con->db_errno == SB_DB_ERROR_DEADLOCK)
lua_pushnumber(L, SB_DB_RESTART_TRANSACTION);
lua_error(L);
}
db_store_results(rs);
db_free_results(rs);