** Run a prepared statement */
| 13356 | ** Run a prepared statement |
| 13357 | */ |
| 13358 | static void exec_prepared_stmt( |
| 13359 | ShellState *pArg, /* Pointer to ShellState */ |
| 13360 | sqlite3_stmt *pStmt /* Statment to run */ |
| 13361 | ){ |
| 13362 | int rc; |
| 13363 | |
| 13364 | if( pArg->cMode==MODE_Column |
| 13365 | || pArg->cMode==MODE_Table |
| 13366 | || pArg->cMode==MODE_Box |
| 13367 | || pArg->cMode==MODE_Markdown |
| 13368 | ){ |
| 13369 | exec_prepared_stmt_columnar(pArg, pStmt); |
| 13370 | return; |
| 13371 | } |
| 13372 | |
| 13373 | /* perform the first step. this will tell us if we |
| 13374 | ** have a result set or not and how wide it is. |
| 13375 | */ |
| 13376 | rc = sqlite3_step(pStmt); |
| 13377 | /* if we have a result set... */ |
| 13378 | if( SQLITE_ROW == rc ){ |
| 13379 | /* allocate space for col name ptr, value ptr, and type */ |
| 13380 | int nCol = sqlite3_column_count(pStmt); |
| 13381 | void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1); |
| 13382 | if( !pData ){ |
| 13383 | rc = SQLITE_NOMEM; |
| 13384 | }else{ |
| 13385 | char **azCols = (char **)pData; /* Names of result columns */ |
| 13386 | char **azVals = &azCols[nCol]; /* Results */ |
| 13387 | int *aiTypes = (int *)&azVals[nCol]; /* Result types */ |
| 13388 | int i, x; |
| 13389 | assert(sizeof(int) <= sizeof(char *)); |
| 13390 | /* save off ptrs to column names */ |
| 13391 | for(i=0; i<nCol; i++){ |
| 13392 | azCols[i] = (char *)sqlite3_column_name(pStmt, i); |
| 13393 | } |
| 13394 | do{ |
| 13395 | /* extract the data and data types */ |
| 13396 | for(i=0; i<nCol; i++){ |
| 13397 | aiTypes[i] = x = sqlite3_column_type(pStmt, i); |
| 13398 | if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){ |
| 13399 | azVals[i] = ""; |
| 13400 | }else{ |
| 13401 | azVals[i] = (char*)sqlite3_column_text(pStmt, i); |
| 13402 | } |
| 13403 | if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){ |
| 13404 | rc = SQLITE_NOMEM; |
| 13405 | break; /* from for */ |
| 13406 | } |
| 13407 | } /* end for */ |
| 13408 | |
| 13409 | /* if data and types extracted successfully... */ |
| 13410 | if( SQLITE_ROW == rc ){ |
| 13411 | /* call the supplied callback with the result row data */ |
| 13412 | if( shell_callback(pArg, nCol, azVals, azCols, aiTypes) ){ |
| 13413 | rc = SQLITE_ABORT; |
| 13414 | }else{ |
| 13415 | rc = sqlite3_step(pStmt); |
no test coverage detected