MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / lua_prepare_sql_int

Function lua_prepare_sql_int

lua/sp.c:2214–2257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2212}
2213
2214static int lua_prepare_sql_int(SP sp, const char *sql, sqlite3_stmt **stmt,
2215 struct sql_state *rec, int flags)
2216{
2217 Lua L = sp->lua;
2218 int maxRetries = ATOMIC_LOAD32(gbl_lua_prepare_max_retries);
2219 int nRetry = 0;
2220 struct errstat err;
2221 struct sql_state rec_lcl = {0};
2222 struct sql_state *rec_ptr = rec ? rec : &rec_lcl;
2223 rec_ptr->sql = sql;
2224
2225 /* Reset logger. This clears table names (see reqlog_add_table) and
2226 print events (see reqlog_logv_int) in the logger. */
2227 reqlog_reset_logger(sp->thd->logger);
2228
2229retry:
2230 memset(&err, 0, sizeof(struct errstat));
2231 if (sp->initial) {
2232 sp->rc = get_prepared_stmt_try_lock(sp->thd, sp->clnt, rec_ptr, &err, flags | PREPARE_RECREATE);
2233 } else if (flags & PREPARE_ALLOW_TEMP_DDL) {
2234 sp->rc = get_prepared_stmt_no_lock(sp->thd, sp->clnt, rec_ptr, &err, flags);
2235 assert(sp->rc != SQLITE_PERM);
2236 } else {
2237 /* NOTE: Only this call can return SQLITE_PERM. */
2238 sp->rc = get_prepared_stmt_try_lock(sp->thd, sp->clnt, rec_ptr, &err, flags & ~PREPARE_RECREATE);
2239 }
2240 sp->initial = 0;
2241 if ((sp->rc == SQLITE_PERM) && (maxRetries != 0) &&
2242 ((maxRetries == -1) || (nRetry++ < maxRetries))) {
2243 int sleepms = ATOMIC_LOAD32(gbl_lua_prepare_retry_sleep);
2244 if (sleepms >= 0) poll(NULL, 0, sleepms);
2245 goto retry;
2246 }
2247 if (sp->rc == SQLITE_PERM) sp->rc = SQLITE_SCHEMA; /* R7 compat */
2248 if (sp->rc == 0) {
2249 *stmt = rec_ptr->stmt;
2250 rec_ptr->sql = sqlite3_sql(*stmt);
2251 } else if (sp->rc == SQLITE_SCHEMA) {
2252 return luaL_error(L, sqlite3ErrStr(sp->rc));
2253 } else {
2254 luabb_error(L, sp, "%s in stmt: %s", err.errstr, sql);
2255 }
2256 return sp->rc;
2257}
2258
2259static void lua_begin_step(struct sqlclntstate *clnt, SP sp,
2260 sqlite3_stmt *pStmt)

Callers 3

lua_prepare_sqlFunction · 0.85
db_prepareFunction · 0.85

Calls 7

reqlog_reset_loggerFunction · 0.85
sqlite3_sqlFunction · 0.85
luaL_errorFunction · 0.85
sqlite3ErrStrFunction · 0.85
luabb_errorFunction · 0.85

Tested by

no test coverage detected