MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / shell_exec

Function shell_exec

modules/dasSQLITE/sqlite/shell.c:19213–19362  ·  view source on GitHub ↗

** Execute a statement or set of statements. Print ** any result rows/columns depending on the current mode ** set via the supplied callback. ** ** This is very similar to SQLite's built-in sqlite3_exec() ** function except it takes a slightly different callback ** and callback data argument. */

Source from the content-addressed store, hash-verified

19211** and callback data argument.
19212*/
19213static int shell_exec(
19214 ShellState *pArg, /* Pointer to ShellState */
19215 const char *zSql, /* SQL to be evaluated */
19216 char **pzErrMsg /* Error msg written here */
19217){
19218 sqlite3_stmt *pStmt = NULL; /* Statement to execute. */
19219 int rc = SQLITE_OK; /* Return Code */
19220 int rc2;
19221 const char *zLeftover; /* Tail of unprocessed SQL */
19222 sqlite3 *db = pArg->db;
19223
19224 if( pzErrMsg ){
19225 *pzErrMsg = NULL;
19226 }
19227
19228#ifndef SQLITE_OMIT_VIRTUALTABLE
19229 if( pArg->expert.pExpert ){
19230 rc = expertHandleSQL(pArg, zSql, pzErrMsg);
19231 return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
19232 }
19233#endif
19234
19235 while( zSql[0] && (SQLITE_OK == rc) ){
19236 static const char *zStmtSql;
19237 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
19238 if( SQLITE_OK != rc ){
19239 if( pzErrMsg ){
19240 *pzErrMsg = save_err_msg(db, "in prepare", rc, zSql);
19241 }
19242 }else{
19243 if( !pStmt ){
19244 /* this happens for a comment or white-space */
19245 zSql = zLeftover;
19246 while( IsSpace(zSql[0]) ) zSql++;
19247 continue;
19248 }
19249 zStmtSql = sqlite3_sql(pStmt);
19250 if( zStmtSql==0 ) zStmtSql = "";
19251 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
19252
19253 /* save off the prepared statment handle and reset row count */
19254 if( pArg ){
19255 pArg->pStmt = pStmt;
19256 pArg->cnt = 0;
19257 }
19258
19259 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
19260 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
19261 sqlite3_stmt *pExplain;
19262 char *zEQP;
19263 int triggerEQP = 0;
19264 disable_debug_trace_modes();
19265 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
19266 if( pArg->autoEQP>=AUTOEQP_trigger ){
19267 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
19268 }
19269 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
19270 shell_check_oom(zEQP);

Callers 4

dump_callbackFunction · 0.85
do_meta_commandFunction · 0.85
runOneSqlLineFunction · 0.85
wmainFunction · 0.85

Calls 15

expertHandleSQLFunction · 0.85
expertFinishFunction · 0.85
save_err_msgFunction · 0.85
IsSpaceFunction · 0.85
shell_check_oomFunction · 0.85
eqp_renderFunction · 0.85
eqp_appendFunction · 0.85
explain_data_prepareFunction · 0.85
exec_prepared_stmtFunction · 0.85
explain_data_deleteFunction · 0.85

Tested by

no test coverage detected