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

Function run_table_dump_query

modules/dasSQLITE/sqlite/shell.c:17963–18005  ·  view source on GitHub ↗

** Execute a query statement that will generate SQL output. Print ** the result columns, comma-separated, on a line and then add a ** semicolon terminator to the end of that line. ** ** If the number of columns is 1 and that column contains text "--" ** then write the semicolon on a separate line. That way, if a ** "--" comment occurs at the end of the statement, the comment ** won't consume the

Source from the content-addressed store, hash-verified

17961** won't consume the semicolon terminator.
17962*/
17963static int run_table_dump_query(
17964 ShellState *p, /* Query context */
17965 const char *zSelect /* SELECT statement to extract content */
17966){
17967 sqlite3_stmt *pSelect;
17968 int rc;
17969 int nResult;
17970 int i;
17971 const char *z;
17972 rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
17973 if( rc!=SQLITE_OK || !pSelect ){
17974 char *zContext = shell_error_context(zSelect, p->db);
17975 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n%s", rc,
17976 sqlite3_errmsg(p->db), zContext);
17977 sqlite3_free(zContext);
17978 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
17979 return rc;
17980 }
17981 rc = sqlite3_step(pSelect);
17982 nResult = sqlite3_column_count(pSelect);
17983 while( rc==SQLITE_ROW ){
17984 z = (const char*)sqlite3_column_text(pSelect, 0);
17985 utf8_printf(p->out, "%s", z);
17986 for(i=1; i<nResult; i++){
17987 utf8_printf(p->out, ",%s", sqlite3_column_text(pSelect, i));
17988 }
17989 if( z==0 ) z = "";
17990 while( z[0] && (z[0]!='-' || z[1]!='-') ) z++;
17991 if( z[0] ){
17992 raw_printf(p->out, "\n;\n");
17993 }else{
17994 raw_printf(p->out, ";\n");
17995 }
17996 rc = sqlite3_step(pSelect);
17997 }
17998 rc = sqlite3_finalize(pSelect);
17999 if( rc!=SQLITE_OK ){
18000 utf8_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc,
18001 sqlite3_errmsg(p->db));
18002 if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
18003 }
18004 return rc;
18005}
18006
18007/*
18008** Allocate space and save off string indicating current error.

Callers 1

do_meta_commandFunction · 0.85

Calls 2

shell_error_contextFunction · 0.85
utf8_printfFunction · 0.85

Tested by

no test coverage detected