** This is the callback routine that the shell ** invokes for each row of a query result. */
| 22479 | ** invokes for each row of a query result. |
| 22480 | */ |
| 22481 | static int shell_callback( |
| 22482 | void *pArg, |
| 22483 | int nArg, /* Number of result columns */ |
| 22484 | char **azArg, /* Text of each result column */ |
| 22485 | char **azCol, /* Column names */ |
| 22486 | int *aiType /* Column types. Might be NULL */ |
| 22487 | ){ |
| 22488 | int i; |
| 22489 | ShellState *p = (ShellState*)pArg; |
| 22490 | |
| 22491 | if( azArg==0 ) return 0; |
| 22492 | switch( p->cMode ){ |
| 22493 | case MODE_Count: |
| 22494 | case MODE_Off: { |
| 22495 | break; |
| 22496 | } |
| 22497 | case MODE_Line: { |
| 22498 | int w = 5; |
| 22499 | if( azArg==0 ) break; |
| 22500 | for(i=0; i<nArg; i++){ |
| 22501 | int len = strlen30(azCol[i] ? azCol[i] : ""); |
| 22502 | if( len>w ) w = len; |
| 22503 | } |
| 22504 | if( p->cnt++>0 ) sqlite3_fputs(p->rowSeparator, p->out); |
| 22505 | for(i=0; i<nArg; i++){ |
| 22506 | sqlite3_fprintf(p->out, "%*s = %s%s", w, azCol[i], |
| 22507 | azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); |
| 22508 | } |
| 22509 | break; |
| 22510 | } |
| 22511 | case MODE_ScanExp: |
| 22512 | case MODE_Explain: { |
| 22513 | static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13}; |
| 22514 | static const int aExplainMap[] = {0, 1, 2, 3, 4, 5, 6, 7 }; |
| 22515 | static const int aScanExpWidth[] = {4, 15, 6, 13, 4, 4, 4, 13, 2, 13}; |
| 22516 | static const int aScanExpMap[] = {0, 9, 8, 1, 2, 3, 4, 5, 6, 7 }; |
| 22517 | |
| 22518 | const int *aWidth = aExplainWidth; |
| 22519 | const int *aMap = aExplainMap; |
| 22520 | int nWidth = ArraySize(aExplainWidth); |
| 22521 | int iIndent = 1; |
| 22522 | |
| 22523 | if( p->cMode==MODE_ScanExp ){ |
| 22524 | aWidth = aScanExpWidth; |
| 22525 | aMap = aScanExpMap; |
| 22526 | nWidth = ArraySize(aScanExpWidth); |
| 22527 | iIndent = 3; |
| 22528 | } |
| 22529 | if( nArg>nWidth ) nArg = nWidth; |
| 22530 | |
| 22531 | /* If this is the first row seen, print out the headers */ |
| 22532 | if( p->cnt++==0 ){ |
| 22533 | for(i=0; i<nArg; i++){ |
| 22534 | utf8_width_print(p->out, aWidth[i], azCol[ aMap[i] ]); |
| 22535 | sqlite3_fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 22536 | } |
| 22537 | for(i=0; i<nArg; i++){ |
| 22538 | print_dashes(p->out, aWidth[i]); |
no test coverage detected