** This function is called either to silently clean up the object ** created by the ".expert" command (if bCancel==1), or to generate a ** report from it and then clean it up (if bCancel==0). ** ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error ** code. In this case, (*pzErr) may be set to point to a buffer containing ** an English language error message. It is the responsibilit
| 13456 | ** caller to eventually free this buffer using sqlite3_free(). |
| 13457 | */ |
| 13458 | static int expertFinish( |
| 13459 | ShellState *pState, |
| 13460 | int bCancel, |
| 13461 | char **pzErr |
| 13462 | ){ |
| 13463 | int rc = SQLITE_OK; |
| 13464 | sqlite3expert *p = pState->expert.pExpert; |
| 13465 | assert( p ); |
| 13466 | assert( bCancel || pzErr==0 || *pzErr==0 ); |
| 13467 | if( bCancel==0 ){ |
| 13468 | FILE *out = pState->out; |
| 13469 | int bVerbose = pState->expert.bVerbose; |
| 13470 | |
| 13471 | rc = sqlite3_expert_analyze(p, pzErr); |
| 13472 | if( rc==SQLITE_OK ){ |
| 13473 | int nQuery = sqlite3_expert_count(p); |
| 13474 | int i; |
| 13475 | |
| 13476 | if( bVerbose ){ |
| 13477 | const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES); |
| 13478 | raw_printf(out, "-- Candidates -----------------------------\n"); |
| 13479 | raw_printf(out, "%s\n", zCand); |
| 13480 | } |
| 13481 | for(i=0; i<nQuery; i++){ |
| 13482 | const char *zSql = sqlite3_expert_report(p, i, EXPERT_REPORT_SQL); |
| 13483 | const char *zIdx = sqlite3_expert_report(p, i, EXPERT_REPORT_INDEXES); |
| 13484 | const char *zEQP = sqlite3_expert_report(p, i, EXPERT_REPORT_PLAN); |
| 13485 | if( zIdx==0 ) zIdx = "(no new indexes)\n"; |
| 13486 | if( bVerbose ){ |
| 13487 | raw_printf(out, "-- Query %d --------------------------------\n",i+1); |
| 13488 | raw_printf(out, "%s\n\n", zSql); |
| 13489 | } |
| 13490 | raw_printf(out, "%s\n", zIdx); |
| 13491 | raw_printf(out, "%s\n", zEQP); |
| 13492 | } |
| 13493 | } |
| 13494 | } |
| 13495 | sqlite3_expert_destroy(p); |
| 13496 | pState->expert.pExpert = 0; |
| 13497 | return rc; |
| 13498 | } |
| 13499 | |
| 13500 | /* |
| 13501 | ** Implementation of ".expert" dot command. |
no test coverage detected