** This is the callback routine that the shell ** invokes for each row of a query result. */
| 17428 | ** invokes for each row of a query result. |
| 17429 | */ |
| 17430 | static int shell_callback( |
| 17431 | void *pArg, |
| 17432 | int nArg, /* Number of result columns */ |
| 17433 | char **azArg, /* Text of each result column */ |
| 17434 | char **azCol, /* Column names */ |
| 17435 | int *aiType /* Column types. Might be NULL */ |
| 17436 | ){ |
| 17437 | int i; |
| 17438 | ShellState *p = (ShellState*)pArg; |
| 17439 | |
| 17440 | if( azArg==0 ) return 0; |
| 17441 | switch( p->cMode ){ |
| 17442 | case MODE_Count: |
| 17443 | case MODE_Off: { |
| 17444 | break; |
| 17445 | } |
| 17446 | case MODE_Line: { |
| 17447 | int w = 5; |
| 17448 | if( azArg==0 ) break; |
| 17449 | for(i=0; i<nArg; i++){ |
| 17450 | int len = strlen30(azCol[i] ? azCol[i] : ""); |
| 17451 | if( len>w ) w = len; |
| 17452 | } |
| 17453 | if( p->cnt++>0 ) utf8_printf(p->out, "%s", p->rowSeparator); |
| 17454 | for(i=0; i<nArg; i++){ |
| 17455 | utf8_printf(p->out,"%*s = %s%s", w, azCol[i], |
| 17456 | azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); |
| 17457 | } |
| 17458 | break; |
| 17459 | } |
| 17460 | case MODE_Explain: { |
| 17461 | static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13}; |
| 17462 | if( nArg>ArraySize(aExplainWidth) ){ |
| 17463 | nArg = ArraySize(aExplainWidth); |
| 17464 | } |
| 17465 | if( p->cnt++==0 ){ |
| 17466 | for(i=0; i<nArg; i++){ |
| 17467 | int w = aExplainWidth[i]; |
| 17468 | utf8_width_print(p->out, w, azCol[i]); |
| 17469 | fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 17470 | } |
| 17471 | for(i=0; i<nArg; i++){ |
| 17472 | int w = aExplainWidth[i]; |
| 17473 | print_dashes(p->out, w); |
| 17474 | fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 17475 | } |
| 17476 | } |
| 17477 | if( azArg==0 ) break; |
| 17478 | for(i=0; i<nArg; i++){ |
| 17479 | int w = aExplainWidth[i]; |
| 17480 | if( i==nArg-1 ) w = 0; |
| 17481 | if( azArg[i] && strlenChar(azArg[i])>w ){ |
| 17482 | w = strlenChar(azArg[i]); |
| 17483 | } |
| 17484 | if( i==1 && p->aiIndent && p->pStmt ){ |
| 17485 | if( p->iIndent<p->nIndent ){ |
| 17486 | utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); |
| 17487 | } |
no test coverage detected