** This is a different callback routine used for dumping the database. ** Each row received by this callback consists of a table name, ** the table type ("index" or "table") and SQL to create the table. ** This routine should print text sufficient to recreate the table. */
| 19501 | ** This routine should print text sufficient to recreate the table. |
| 19502 | */ |
| 19503 | static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ |
| 19504 | int rc; |
| 19505 | const char *zTable; |
| 19506 | const char *zType; |
| 19507 | const char *zSql; |
| 19508 | ShellState *p = (ShellState *)pArg; |
| 19509 | int dataOnly; |
| 19510 | int noSys; |
| 19511 | |
| 19512 | UNUSED_PARAMETER(azNotUsed); |
| 19513 | if( nArg!=3 || azArg==0 ) return 0; |
| 19514 | zTable = azArg[0]; |
| 19515 | zType = azArg[1]; |
| 19516 | zSql = azArg[2]; |
| 19517 | if( zTable==0 ) return 0; |
| 19518 | if( zType==0 ) return 0; |
| 19519 | dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0; |
| 19520 | noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0; |
| 19521 | |
| 19522 | if( cli_strcmp(zTable, "sqlite_sequence")==0 && !noSys ){ |
| 19523 | if( !dataOnly ) raw_printf(p->out, "DELETE FROM sqlite_sequence;\n"); |
| 19524 | }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){ |
| 19525 | if( !dataOnly ) raw_printf(p->out, "ANALYZE sqlite_schema;\n"); |
| 19526 | }else if( cli_strncmp(zTable, "sqlite_", 7)==0 ){ |
| 19527 | return 0; |
| 19528 | }else if( dataOnly ){ |
| 19529 | /* no-op */ |
| 19530 | }else if( cli_strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ |
| 19531 | char *zIns; |
| 19532 | if( !p->writableSchema ){ |
| 19533 | raw_printf(p->out, "PRAGMA writable_schema=ON;\n"); |
| 19534 | p->writableSchema = 1; |
| 19535 | } |
| 19536 | zIns = sqlite3_mprintf( |
| 19537 | "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)" |
| 19538 | "VALUES('table','%q','%q',0,'%q');", |
| 19539 | zTable, zTable, zSql); |
| 19540 | shell_check_oom(zIns); |
| 19541 | utf8_printf(p->out, "%s\n", zIns); |
| 19542 | sqlite3_free(zIns); |
| 19543 | return 0; |
| 19544 | }else{ |
| 19545 | printSchemaLine(p->out, zSql, ";\n"); |
| 19546 | } |
| 19547 | |
| 19548 | if( cli_strcmp(zType, "table")==0 ){ |
| 19549 | ShellText sSelect; |
| 19550 | ShellText sTable; |
| 19551 | char **azCol; |
| 19552 | int i; |
| 19553 | char *savedDestTable; |
| 19554 | int savedMode; |
| 19555 | |
| 19556 | azCol = tableColumnList(p, zTable); |
| 19557 | if( azCol==0 ){ |
| 19558 | p->nErr++; |
| 19559 | return 0; |
| 19560 | } |
nothing calls this directly
no test coverage detected