MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / tryToCloneSchema

Function tryToCloneSchema

modules/dasSQLITE/sqlite/shell.c:21130–21205  ·  view source on GitHub ↗

** Try to transfer all rows of the schema that match zWhere. For ** each row, invoke xForEach() on the object defined by that row. ** If an error is encountered while moving forward through the ** sqlite_schema table, try again moving backwards. */

Source from the content-addressed store, hash-verified

21128** sqlite_schema table, try again moving backwards.
21129*/
21130static void tryToCloneSchema(
21131 ShellState *p,
21132 sqlite3 *newDb,
21133 const char *zWhere,
21134 void (*xForEach)(ShellState*,sqlite3*,const char*)
21135){
21136 sqlite3_stmt *pQuery = 0;
21137 char *zQuery = 0;
21138 int rc;
21139 const unsigned char *zName;
21140 const unsigned char *zSql;
21141 char *zErrMsg = 0;
21142
21143 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
21144 " WHERE %s ORDER BY rowid ASC", zWhere);
21145 shell_check_oom(zQuery);
21146 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
21147 if( rc ){
21148 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
21149 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
21150 zQuery);
21151 goto end_schema_xfer;
21152 }
21153 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
21154 zName = sqlite3_column_text(pQuery, 0);
21155 zSql = sqlite3_column_text(pQuery, 1);
21156 if( zName==0 || zSql==0 ) continue;
21157 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){
21158 printf("%s... ", zName); fflush(stdout);
21159 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
21160 if( zErrMsg ){
21161 utf8_printf(stderr, "Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
21162 sqlite3_free(zErrMsg);
21163 zErrMsg = 0;
21164 }
21165 }
21166 if( xForEach ){
21167 xForEach(p, newDb, (const char*)zName);
21168 }
21169 printf("done\n");
21170 }
21171 if( rc!=SQLITE_DONE ){
21172 sqlite3_finalize(pQuery);
21173 sqlite3_free(zQuery);
21174 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
21175 " WHERE %s ORDER BY rowid DESC", zWhere);
21176 shell_check_oom(zQuery);
21177 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
21178 if( rc ){
21179 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
21180 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
21181 zQuery);
21182 goto end_schema_xfer;
21183 }
21184 while( sqlite3_step(pQuery)==SQLITE_ROW ){
21185 zName = sqlite3_column_text(pQuery, 0);
21186 zSql = sqlite3_column_text(pQuery, 1);
21187 if( zName==0 || zSql==0 ) continue;

Callers 1

tryToCloneFunction · 0.85

Calls 4

shell_check_oomFunction · 0.85
utf8_printfFunction · 0.85
printfFunction · 0.85
sqlite3_execFunction · 0.85

Tested by

no test coverage detected