** Run zQuery. Use dump_callback() as the callback routine so that ** the contents of the query are output as SQL statements. ** ** If we get a SQLITE_CORRUPT error, rerun the query after appending ** "ORDER BY rowid DESC" to the end. */
| 19622 | ** "ORDER BY rowid DESC" to the end. |
| 19623 | */ |
| 19624 | static int run_schema_dump_query( |
| 19625 | ShellState *p, |
| 19626 | const char *zQuery |
| 19627 | ){ |
| 19628 | int rc; |
| 19629 | char *zErr = 0; |
| 19630 | rc = sqlite3_exec(p->db, zQuery, dump_callback, p, &zErr); |
| 19631 | if( rc==SQLITE_CORRUPT ){ |
| 19632 | char *zQ2; |
| 19633 | int len = strlen30(zQuery); |
| 19634 | raw_printf(p->out, "/****** CORRUPTION ERROR *******/\n"); |
| 19635 | if( zErr ){ |
| 19636 | utf8_printf(p->out, "/****** %s ******/\n", zErr); |
| 19637 | sqlite3_free(zErr); |
| 19638 | zErr = 0; |
| 19639 | } |
| 19640 | zQ2 = malloc( len+100 ); |
| 19641 | if( zQ2==0 ) return rc; |
| 19642 | sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery); |
| 19643 | rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr); |
| 19644 | if( rc ){ |
| 19645 | utf8_printf(p->out, "/****** ERROR: %s ******/\n", zErr); |
| 19646 | }else{ |
| 19647 | rc = SQLITE_CORRUPT; |
| 19648 | } |
| 19649 | sqlite3_free(zErr); |
| 19650 | free(zQ2); |
| 19651 | } |
| 19652 | return rc; |
| 19653 | } |
| 19654 | |
| 19655 | /* |
| 19656 | ** Text of help messages. |
no test coverage detected