MCPcopy Create free account
hub / github.com/altairwei/WizNotePlus / dump_callback

Function dump_callback

src/database/cppsqlite3.cpp:1066–1157  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

1064** This routine should print text sufficient to recreate the table.
1065*/
1066static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
1067 int rc;
1068 const char *zTable;
1069 const char *zType;
1070 const char *zSql;
1071 const char *zPrepStmt = 0;
1072 struct callback_data *p = (struct callback_data *)pArg;
1073 //
1074 Q_UNUSED(azCol);
1075
1076 //UNUSED_PARAMETER(azCol);
1077 if( nArg!=3 ) return 1;
1078 zTable = azArg[0];
1079 zType = azArg[1];
1080 zSql = azArg[2];
1081
1082 if( strcmp(zTable, "sqlite_sequence")==0 ){
1083 zPrepStmt = "DELETE FROM sqlite_sequence;\n";
1084 }else if( strcmp(zTable, "sqlite_stat1")==0 ){
1085 fprintf(p->out, "ANALYZE sqlite_master;\n");
1086 }else if( strncmp(zTable, "sqlite_", 7)==0 ){
1087 return 0;
1088 }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
1089 char *zIns;
1090 if( !p->writableSchema ){
1091 fprintf(p->out, "PRAGMA writable_schema=ON;\n");
1092 p->writableSchema = 1;
1093 }
1094 zIns = sqlite3_mprintf(
1095 "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
1096 "VALUES('table','%q','%q',0,'%q');",
1097 zTable, zTable, zSql);
1098 fprintf(p->out, "%s\n", zIns);
1099 sqlite3_free(zIns);
1100 return 0;
1101 }else{
1102 fprintf(p->out, "%s;\n", zSql);
1103 }
1104
1105 if( strcmp(zType, "table")==0 ){
1106 sqlite3_stmt *pTableInfo = 0;
1107 char *zSelect = 0;
1108 char *zTableInfo = 0;
1109 char *zTmp = 0;
1110 int nRow = 0;
1111
1112 zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0);
1113 zTableInfo = appendText(zTableInfo, zTable, '"');
1114 zTableInfo = appendText(zTableInfo, ");", 0);
1115
1116 rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0);
1117 free(zTableInfo);
1118 if( rc!=SQLITE_OK || !pTableInfo ){
1119 return 1;
1120 }
1121
1122 zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
1123 zTmp = appendText(zTmp, zTable, '"');

Callers

nothing calls this directly

Calls 2

appendTextFunction · 0.85
run_table_dump_queryFunction · 0.85

Tested by

no test coverage detected