** This is the callback routine that the shell ** invokes for each row of a query result. */
| 12138 | ** invokes for each row of a query result. |
| 12139 | */ |
| 12140 | static int shell_callback( |
| 12141 | void *pArg, |
| 12142 | int nArg, /* Number of result columns */ |
| 12143 | char **azArg, /* Text of each result column */ |
| 12144 | char **azCol, /* Column names */ |
| 12145 | int *aiType /* Column types. Might be NULL */ |
| 12146 | ){ |
| 12147 | int i; |
| 12148 | ShellState *p = (ShellState*)pArg; |
| 12149 | |
| 12150 | if( azArg==0 ) return 0; |
| 12151 | switch( p->cMode ){ |
| 12152 | case MODE_Line: { |
| 12153 | int w = 5; |
| 12154 | if( azArg==0 ) break; |
| 12155 | for(i=0; i<nArg; i++){ |
| 12156 | int len = strlen30(azCol[i] ? azCol[i] : ""); |
| 12157 | if( len>w ) w = len; |
| 12158 | } |
| 12159 | if( p->cnt++>0 ) utf8_printf(p->out, "%s", p->rowSeparator); |
| 12160 | for(i=0; i<nArg; i++){ |
| 12161 | utf8_printf(p->out,"%*s = %s%s", w, azCol[i], |
| 12162 | azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); |
| 12163 | } |
| 12164 | break; |
| 12165 | } |
| 12166 | case MODE_Explain: { |
| 12167 | static const int aExplainWidth[] = {4, 13, 4, 4, 4, 13, 2, 13}; |
| 12168 | if( nArg>ArraySize(aExplainWidth) ){ |
| 12169 | nArg = ArraySize(aExplainWidth); |
| 12170 | } |
| 12171 | if( p->cnt++==0 ){ |
| 12172 | for(i=0; i<nArg; i++){ |
| 12173 | int w = aExplainWidth[i]; |
| 12174 | utf8_width_print(p->out, w, azCol[i]); |
| 12175 | fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 12176 | } |
| 12177 | for(i=0; i<nArg; i++){ |
| 12178 | int w = aExplainWidth[i]; |
| 12179 | print_dashes(p->out, w); |
| 12180 | fputs(i==nArg-1 ? "\n" : " ", p->out); |
| 12181 | } |
| 12182 | } |
| 12183 | if( azArg==0 ) break; |
| 12184 | for(i=0; i<nArg; i++){ |
| 12185 | int w = aExplainWidth[i]; |
| 12186 | if( i==nArg-1 ) w = 0; |
| 12187 | if( azArg[i] && strlenChar(azArg[i])>w ){ |
| 12188 | w = strlenChar(azArg[i]); |
| 12189 | } |
| 12190 | if( i==1 && p->aiIndent && p->pStmt ){ |
| 12191 | if( p->iIndent<p->nIndent ){ |
| 12192 | utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); |
| 12193 | } |
| 12194 | p->iIndent++; |
| 12195 | } |
| 12196 | utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue); |
| 12197 | fputs(i==nArg-1 ? "\n" : " ", p->out); |
no test coverage detected