MCPcopy Create free account
hub / github.com/Kitware/VTK / tryToCloneSchema

Function tryToCloneSchema

ThirdParty/sqlite/vtksqlite/shell.c:26223–26297  ·  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

26221** sqlite_schema table, try again moving backwards.
26222*/
26223static void tryToCloneSchema(
26224 ShellState *p,
26225 sqlite3 *newDb,
26226 const char *zWhere,
26227 void (*xForEach)(ShellState*,sqlite3*,const char*)
26228){
26229 sqlite3_stmt *pQuery = 0;
26230 char *zQuery = 0;
26231 int rc;
26232 const unsigned char *zName;
26233 const unsigned char *zSql;
26234 char *zErrMsg = 0;
26235
26236 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
26237 " WHERE %s ORDER BY rowid ASC", zWhere);
26238 shell_check_oom(zQuery);
26239 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26240 if( rc ){
26241 sqlite3_fprintf(stderr,
26242 "Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db),
26243 sqlite3_errmsg(p->db), zQuery);
26244 goto end_schema_xfer;
26245 }
26246 while( (rc = sqlite3_step(pQuery))==SQLITE_ROW ){
26247 zName = sqlite3_column_text(pQuery, 0);
26248 zSql = sqlite3_column_text(pQuery, 1);
26249 if( zName==0 || zSql==0 ) continue;
26250 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){
26251 sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout);
26252 sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg);
26253 if( zErrMsg ){
26254 sqlite3_fprintf(stderr,"Error: %s\nSQL: [%s]\n", zErrMsg, zSql);
26255 sqlite3_free(zErrMsg);
26256 zErrMsg = 0;
26257 }
26258 }
26259 if( xForEach ){
26260 xForEach(p, newDb, (const char*)zName);
26261 }
26262 sputz(stdout, "done\n");
26263 }
26264 if( rc!=SQLITE_DONE ){
26265 sqlite3_finalize(pQuery);
26266 sqlite3_free(zQuery);
26267 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
26268 " WHERE %s ORDER BY rowid DESC", zWhere);
26269 shell_check_oom(zQuery);
26270 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
26271 if( rc ){
26272 sqlite3_fprintf(stderr,"Error: (%d) %s on [%s]\n",
26273 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery);
26274 goto end_schema_xfer;
26275 }
26276 while( sqlite3_step(pQuery)==SQLITE_ROW ){
26277 zName = sqlite3_column_text(pQuery, 0);
26278 zSql = sqlite3_column_text(pQuery, 1);
26279 if( zName==0 || zSql==0 ) continue;
26280 if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue;

Callers 1

tryToCloneFunction · 0.85

Calls 2

shell_check_oomFunction · 0.85
sqlite3_fprintfFunction · 0.85

Tested by

no test coverage detected