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

Function exec_prepared_stmt

modules/dasSQLITE/sqlite/shell.c:18992–19069  ·  view source on GitHub ↗

** Run a prepared statement */

Source from the content-addressed store, hash-verified

18990** Run a prepared statement
18991*/
18992static void exec_prepared_stmt(
18993 ShellState *pArg, /* Pointer to ShellState */
18994 sqlite3_stmt *pStmt /* Statment to run */
18995){
18996 int rc;
18997 sqlite3_uint64 nRow = 0;
18998
18999 if( pArg->cMode==MODE_Column
19000 || pArg->cMode==MODE_Table
19001 || pArg->cMode==MODE_Box
19002 || pArg->cMode==MODE_Markdown
19003 ){
19004 exec_prepared_stmt_columnar(pArg, pStmt);
19005 return;
19006 }
19007
19008 /* perform the first step. this will tell us if we
19009 ** have a result set or not and how wide it is.
19010 */
19011 rc = sqlite3_step(pStmt);
19012 /* if we have a result set... */
19013 if( SQLITE_ROW == rc ){
19014 /* allocate space for col name ptr, value ptr, and type */
19015 int nCol = sqlite3_column_count(pStmt);
19016 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
19017 if( !pData ){
19018 shell_out_of_memory();
19019 }else{
19020 char **azCols = (char **)pData; /* Names of result columns */
19021 char **azVals = &azCols[nCol]; /* Results */
19022 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
19023 int i, x;
19024 assert(sizeof(int) <= sizeof(char *));
19025 /* save off ptrs to column names */
19026 for(i=0; i<nCol; i++){
19027 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
19028 }
19029 do{
19030 nRow++;
19031 /* extract the data and data types */
19032 for(i=0; i<nCol; i++){
19033 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
19034 if( x==SQLITE_BLOB
19035 && pArg
19036 && (pArg->cMode==MODE_Insert || pArg->cMode==MODE_Quote)
19037 ){
19038 azVals[i] = "";
19039 }else{
19040 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
19041 }
19042 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
19043 rc = SQLITE_NOMEM;
19044 break; /* from for */
19045 }
19046 } /* end for */
19047
19048 /* if data and types extracted successfully... */
19049 if( SQLITE_ROW == rc ){

Callers 1

shell_execFunction · 0.85

Calls 5

shell_out_of_memoryFunction · 0.85
assertFunction · 0.85
shell_callbackFunction · 0.85
printfFunction · 0.85

Tested by

no test coverage detected