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

Function runOneSqlLine

modules/dasSQLITE/sqlite/shell.c:26439–26484  ·  view source on GitHub ↗

** Run a single line of SQL. Return the number of errors. */

Source from the content-addressed store, hash-verified

26437** Run a single line of SQL. Return the number of errors.
26438*/
26439static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
26440 int rc;
26441 char *zErrMsg = 0;
26442
26443 open_db(p, 0);
26444 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
26445 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
26446 BEGIN_TIMER;
26447 rc = shell_exec(p, zSql, &zErrMsg);
26448 END_TIMER;
26449 if( rc || zErrMsg ){
26450 char zPrefix[100];
26451 const char *zErrorTail;
26452 const char *zErrorType;
26453 if( zErrMsg==0 ){
26454 zErrorType = "Error";
26455 zErrorTail = sqlite3_errmsg(p->db);
26456 }else if( cli_strncmp(zErrMsg, "in prepare, ",12)==0 ){
26457 zErrorType = "Parse error";
26458 zErrorTail = &zErrMsg[12];
26459 }else if( cli_strncmp(zErrMsg, "stepping, ", 10)==0 ){
26460 zErrorType = "Runtime error";
26461 zErrorTail = &zErrMsg[10];
26462 }else{
26463 zErrorType = "Error";
26464 zErrorTail = zErrMsg;
26465 }
26466 if( in!=0 || !stdin_is_interactive ){
26467 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
26468 "%s near line %d:", zErrorType, startline);
26469 }else{
26470 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
26471 }
26472 utf8_printf(stderr, "%s %s\n", zPrefix, zErrorTail);
26473 sqlite3_free(zErrMsg);
26474 zErrMsg = 0;
26475 return 1;
26476 }else if( ShellHasFlag(p, SHFLG_CountChanges) ){
26477 char zLineBuf[2000];
26478 sqlite3_snprintf(sizeof(zLineBuf), zLineBuf,
26479 "changes: %lld total_changes: %lld",
26480 sqlite3_changes64(p->db), sqlite3_total_changes64(p->db));
26481 raw_printf(p->out, "%s\n", zLineBuf);
26482 }
26483 return 0;
26484}
26485
26486static void echo_group_input(ShellState *p, const char *zDo){
26487 if( ShellHasFlag(p, SHFLG_Echo) ) utf8_printf(p->out, "%s\n", zDo);

Callers 1

process_inputFunction · 0.85

Calls 5

open_dbFunction · 0.85
resolve_backslashesFunction · 0.85
shell_execFunction · 0.85
cli_strncmpFunction · 0.85
utf8_printfFunction · 0.85

Tested by

no test coverage detected