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

Function setup_first_sqlite_step

lua/sp.c:3372–3407  ·  view source on GitHub ↗

** NOTE: The "profile" (logical boolean) argument is used here to indicate ** whether or not the caller has its own BEGIN / ANOTHER / END loop ** (i.e. using the lua_*_step() functions). When zero, it means the ** caller does have its own SQL statement stepping loop and this ** function must not call lua_begin_step() on the callers behalf when ** performing first-tim

Source from the content-addressed store, hash-verified

3370** setup for the result set.
3371*/
3372static inline void setup_first_sqlite_step(SP sp, dbstmt_t *dbstmt, int profile)
3373{
3374 if (dbstmt->fetched) {
3375 // tbls already locked by previous step()
3376 return;
3377 }
3378 run_stmt_setup(sp->clnt, dbstmt->stmt);
3379 if (profile) lua_begin_step(sp->clnt, sp, dbstmt->stmt);
3380 dbstmt->fetched = 1;
3381 if (dbstmt->rec == NULL) {
3382 // Not a prepared-stmt.
3383 // tbls locked by get_prepared_stmt_try_lock()
3384 return;
3385 }
3386 if (dbstmt->initial) {
3387 // Initial run of prepared-stmt.
3388 // tbls locked by get_prepared_stmt_try_lock()
3389 dbstmt->initial = 0;
3390 return;
3391 }
3392 // Need to lock tbls. We may be holding some other tbl locks and locking
3393 // schema can cause deadlock; trylock instead.
3394 if (tryrdlock_schema_lk() != 0) {
3395 luaL_error(sp->lua, sqlite3ErrStr(SQLITE_SCHEMA));
3396 return;
3397 }
3398 int rc = sqlengine_prepare_engine(sp->thd, sp->clnt, 0);
3399 if (rc == 0) {
3400 sqlite3LockStmtTables(dbstmt->stmt);
3401 unlock_schema_lk();
3402 } else {
3403 unlock_schema_lk();
3404 luaL_error(sp->lua, sqlite3ErrStr(rc));
3405 return;
3406 }
3407}
3408
3409static int dbstmt_exec(Lua lua)
3410{

Callers 4

dbstmt_execFunction · 0.85
dbstmt_fetchFunction · 0.85
dbstmt_emitFunction · 0.85
db_execFunction · 0.85

Calls 6

run_stmt_setupFunction · 0.85
lua_begin_stepFunction · 0.85
luaL_errorFunction · 0.85
sqlite3ErrStrFunction · 0.85
sqlengine_prepare_engineFunction · 0.85
sqlite3LockStmtTablesFunction · 0.85

Tested by

no test coverage detected