** 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. */
| 13855 | ** This routine should print text sufficient to recreate the table. |
| 13856 | */ |
| 13857 | static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ |
| 13858 | int rc; |
| 13859 | const char *zTable; |
| 13860 | const char *zType; |
| 13861 | const char *zSql; |
| 13862 | ShellState *p = (ShellState *)pArg; |
| 13863 | int dataOnly; |
| 13864 | int noSys; |
| 13865 | |
| 13866 | UNUSED_PARAMETER(azNotUsed); |
| 13867 | if( nArg!=3 || azArg==0 ) return 0; |
| 13868 | zTable = azArg[0]; |
| 13869 | zType = azArg[1]; |
| 13870 | zSql = azArg[2]; |
| 13871 | dataOnly = (p->shellFlgs & SHFLG_DumpDataOnly)!=0; |
| 13872 | noSys = (p->shellFlgs & SHFLG_DumpNoSys)!=0; |
| 13873 | |
| 13874 | if( strcmp(zTable, "sqlite_sequence")==0 && !noSys ){ |
| 13875 | if( !dataOnly ) raw_printf(p->out, "DELETE FROM sqlite_sequence;\n"); |
| 13876 | }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){ |
| 13877 | if( !dataOnly ) raw_printf(p->out, "ANALYZE sqlite_schema;\n"); |
| 13878 | }else if( strncmp(zTable, "sqlite_", 7)==0 ){ |
| 13879 | return 0; |
| 13880 | }else if( dataOnly ){ |
| 13881 | /* no-op */ |
| 13882 | }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ |
| 13883 | char *zIns; |
| 13884 | if( !p->writableSchema ){ |
| 13885 | raw_printf(p->out, "PRAGMA writable_schema=ON;\n"); |
| 13886 | p->writableSchema = 1; |
| 13887 | } |
| 13888 | zIns = sqlite3_mprintf( |
| 13889 | "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)" |
| 13890 | "VALUES('table','%q','%q',0,'%q');", |
| 13891 | zTable, zTable, zSql); |
| 13892 | utf8_printf(p->out, "%s\n", zIns); |
| 13893 | sqlite3_free(zIns); |
| 13894 | return 0; |
| 13895 | }else{ |
| 13896 | printSchemaLine(p->out, zSql, ";\n"); |
| 13897 | } |
| 13898 | |
| 13899 | if( strcmp(zType, "table")==0 ){ |
| 13900 | ShellText sSelect; |
| 13901 | ShellText sTable; |
| 13902 | char **azCol; |
| 13903 | int i; |
| 13904 | char *savedDestTable; |
| 13905 | int savedMode; |
| 13906 | |
| 13907 | azCol = tableColumnList(p, zTable); |
| 13908 | if( azCol==0 ){ |
| 13909 | p->nErr++; |
| 13910 | return 0; |
| 13911 | } |
| 13912 | |
| 13913 | /* Always quote the table name, even if it appears to be pure ascii, |
| 13914 | ** in case it is a keyword. Ex: INSERT INTO "table" ... */ |
nothing calls this directly
no test coverage detected