private static void setVersion(SVNSqlJetDb sDb, int version) throws SVNException {
   try {
     sDb.getDb().pragma("pragma user_version = " + version);
   } catch (SqlJetException e) {
     SVNSqlJetDb.createSqlJetError(e);
   }
 }
    public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException {
      /*-- STMT_UPGRADE_TO_26
       * DROP VIEW IF EXISTS NODES_BASE;
       * CREATE VIEW NODES_BASE AS
       * SELECT * FROM nodes
       *  WHERE op_depth = 0;
       */

      try {
        if (sDb.getDb().getSchema().getViewNames().contains("NODES_BASE")) {
          sDb.getDb().dropView("NODES_BASE");
        }
        sDb.getDb().createView("CREATE VIEW NODES_BASE AS SELECT * FROM nodes WHERE op_depth = 0;");
      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }

      setVersion(sDb, (int) 26);
    }
    public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException {
      /*-- STMT_UPGRADE_TO_25
      //DROP VIEW IF EXISTS NODES_CURRENT;
      CREATE VIEW NODES_CURRENT AS
        SELECT * FROM nodes JOIN (SELECT wc_id, local_relpath, MAX(op_depth) AS op_depth FROM nodes GROUP BY wc_id, local_relpath) AS filter
          ON nodes.wc_id = filter.wc_id AND nodes.local_relpath = filter.local_relpath AND nodes.op_depth = filter.op_depth;
      */

      try {
        sDb.getDb()
            .createView(
                "CREATE VIEW NODES_CURRENT AS "
                    + "SELECT * FROM nodes JOIN (SELECT wc_id, local_relpath, MAX(op_depth) AS op_depth FROM nodes GROUP BY wc_id, local_relpath) AS filter "
                    + "ON nodes.wc_id = filter.wc_id AND nodes.local_relpath = filter.local_relpath AND nodes.op_depth = filter.op_depth;");
      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }

      setVersion(sDb, (int) 25);
    }
    public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException {
      /* Rename all pristine files, adding a ".svn-base" suffix. */
      File pristineDirAbsPath =
          SVNWCUtils.admChild(wcRootAbsPath, ISVNWCDb.PRISTINE_STORAGE_RELPATH);
      for (File dir : SVNFileListUtil.listFiles(pristineDirAbsPath)) {
        for (File file : SVNFileListUtil.listFiles(dir)) {
          /* If FINFO indicates that ABSPATH names a file, rename it to '<ABSPATH>.svn-base'.
           *
           * Ignore any file whose name is not the expected length, in order to make life easier for any developer
           * who runs this code twice or has some non-standard files in the pristine directory.
           */
          if (SVNFileType.getType(file) == SVNFileType.FILE
              && SVNFileUtil.getFileName(file).length() == PRISTINE_BASENAME_OLD_LEN) {
            File newAbsPath =
                SVNFileUtil.createFilePath(SVNFileUtil.getFilePath(file) + PRISTINE_STORAGE_EXT);
            SVNFileUtil.rename(file, newAbsPath);
          }
        }
      }

      /* Externals */
      try {
        sDb.getDb()
            .createTable(
                "CREATE TABLE EXTERNALS ( "
                    + "  wc_id  INTEGER NOT NULL REFERENCES WCROOT (id), "
                    + "  local_relpath  TEXT NOT NULL, "
                    + "  parent_relpath  TEXT NOT NULL, "
                    + "  repos_id  INTEGER NOT NULL REFERENCES REPOSITORY (id), "
                    + "  presence  TEXT NOT NULL, "
                    + "  kind  TEXT NOT NULL, "
                    + "  def_local_relpath         TEXT NOT NULL, "
                    + "  def_repos_relpath         TEXT NOT NULL, "
                    + "  def_operational_revision  TEXT, "
                    + "  def_revision              TEXT, "
                    + "  PRIMARY KEY (wc_id, local_relpath) "
                    + "); ");
        sDb.getDb()
            .createIndex("CREATE INDEX I_EXTERNALS_PARENT ON EXTERNALS (wc_id, parent_relpath);");
        sDb.getDb()
            .createIndex(
                "CREATE UNIQUE INDEX I_EXTERNALS_DEFINED ON EXTERNALS (wc_id, def_local_relpath, local_relpath);");
      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }

      upgradeExternals(sDb, wcRootAbsPath);

      /* Format 29 introduces the EXTERNALS table (See STMT_CREATE_TRIGGERS) and optimizes a few trigger definitions. ... */
      // -- STMT_UPGRADE_TO_29
      try {
        if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_update_checksum_trigger")) {
          sDb.getDb().dropTrigger("nodes_update_checksum_trigger");
        }
        if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_insert_trigger")) {
          sDb.getDb().dropTrigger("nodes_insert_trigger");
        }
        if (sDb.getDb().getSchema().getTriggerNames().contains("nodes_delete_trigger")) {
          sDb.getDb().dropTrigger("nodes_delete_trigger");
        }
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_update_checksum_trigger AFTER UPDATE OF checksum ON nodes WHEN NEW.checksum IS NOT OLD.checksum BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;");
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_insert_trigger AFTER INSERT ON nodes WHEN NEW.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; END;");
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_delete_trigger AFTER DELETE ON nodes WHEN OLD.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;");
      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }

      setVersion(sDb, (int) 29);
    }
    public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException {
      /*-- STMT_UPGRADE_TO_25
      UPDATE pristine SET refcount = (SELECT COUNT(*) FROM nodes WHERE checksum = pristine.checksum /*OR checksum = pristine.md5_checksum/);
      */
      SVNSqlJetUpdateStatement stmt =
          new SVNSqlJetUpdateStatement(sDb, SVNWCDbSchema.PRISTINE) {
            private SVNSqlJetSelectFieldsStatement<SVNWCDbSchema.NODES__Fields> select =
                new SVNSqlJetSelectFieldsStatement<SVNWCDbSchema.NODES__Fields>(
                    sDb, SVNWCDbSchema.NODES) {
                  protected boolean isFilterPassed() throws SVNException {
                    return ((String) getBind(1))
                        .equals(getColumnString(SVNWCDbSchema.NODES__Fields.checksum));
                  }

                  protected void defineFields() {
                    fields.add(SVNWCDbSchema.NODES__Fields.wc_id);
                  }

                  protected Object[] getWhere() throws SVNException {
                    return new Object[] {};
                  }
                };

            public Map<String, Object> getUpdateValues() throws SVNException {
              Map<String, Object> rowValues = getRowValues();

              select.bindString(
                  1, (String) rowValues.get(SVNWCDbSchema.PRISTINE__Fields.checksum.toString()));
              long rowCount = 0;
              try {
                while (select.next()) rowCount++;
              } finally {
                select.reset();
              }
              rowValues.put(SVNWCDbSchema.PRISTINE__Fields.refcount.toString(), rowCount);
              return rowValues;
            }
          };

      try {
        stmt.exec();
      } finally {
        stmt.reset();
      }

      setVersion(sDb, (int) 24);

      try {
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_insert_trigger AFTER INSERT ON nodes WHEN NEW.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; END;");
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_delete_trigger AFTER DELETE ON nodes WHEN OLD.checksum IS NOT NULL BEGIN UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;");
        sDb.getDb()
            .createTrigger(
                "CREATE TRIGGER nodes_update_checksum_trigger AFTER UPDATE OF checksum ON nodes WHEN NEW.checksum IS NOT OLD.checksum BEGIN UPDATE pristine SET refcount = refcount + 1 WHERE checksum = NEW.checksum; UPDATE pristine SET refcount = refcount - 1 WHERE checksum = OLD.checksum; END;");
      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }
    }
    public void bumpTo(SVNSqlJetDb sDb, File wcRootAbsPath) throws SVNException {
      try {
        sDb.getDb()
            .createTable(
                "CREATE TABLE NODES ( wc_id  INTEGER NOT NULL REFERENCES WCROOT (id), local_relpath  TEXT NOT NULL, op_depth INTEGER NOT NULL, "
                    + "  parent_relpath  TEXT, repos_id  INTEGER REFERENCES REPOSITORY (id), repos_path  TEXT, revision  INTEGER, presence  TEXT NOT NULL, "
                    + "  moved_here  INTEGER, moved_to  TEXT, kind  TEXT NOT NULL, properties  BLOB, depth  TEXT, checksum  TEXT REFERENCES PRISTINE (checksum), symlink_target  TEXT, "
                    + "  changed_revision  INTEGER, changed_date INTEGER, changed_author TEXT, translated_size  INTEGER, last_mod_time  INTEGER, "
                    + "  dav_cache  BLOB, file_external  TEXT, PRIMARY KEY (wc_id, local_relpath, op_depth) ); ");
        sDb.getDb()
            .createIndex(
                "CREATE INDEX I_NODES_PARENT ON NODES (wc_id, parent_relpath, op_depth); ");

        /*
         		UPDATE BASE_NODE SET checksum=(SELECT checksum FROM pristine WHERE md5_checksum=BASE_NODE.checksum)
        WHERE EXISTS(SELECT 1 FROM pristine WHERE md5_checksum=BASE_NODE.checksum);
         		 */
        UpdateChecksum uc = new UpdateChecksum(sDb, SVNWCDbSchema.BASE_NODE);
        uc.run();

        /*
         		UPDATE WORKING_NODE SET checksum=(SELECT checksum FROM pristine WHERE md5_checksum=WORKING_NODE.checksum)
        WHERE EXISTS(SELECT 1 FROM pristine WHERE md5_checksum=WORKING_NODE.checksum);
          	 */
        uc = new UpdateChecksum(sDb, SVNWCDbSchema.WORKING_NODE);
        uc.run();

        /*
        INSERT INTO NODES (
        	wc_id, local_relpath, op_depth, parent_relpath,
        	repos_id, repos_path, revision,
        	presence, depth, moved_here, moved_to, kind,
        	changed_revision, changed_date, changed_author,
        	checksum, properties, translated_size, last_mod_time,
        	dav_cache, symlink_target, file_external )
        	SELECT wc_id, local_relpath, 0 /*op_depth/, parent_relpath,
        	repos_id, repos_relpath, revnum,
        	presence, depth, NULL /*moved_here/, NULL /*moved_to/, kind,
        	changed_rev, changed_date, changed_author,
        	checksum, properties, translated_size, last_mod_time,
        	dav_cache, symlink_target, file_external
        FROM BASE_NODE;
        */
        SVNSqlJetInsertStatement stmt =
            new SVNSqlJetInsertStatement(sDb, SVNWCDbSchema.NODES) {
              private SVNSqlJetSelectStatement select =
                  new SVNSqlJetSelectStatement(sDb.getTemporaryDb(), SVNWCDbSchema.BASE_NODE) {};

              public long exec() throws SVNException {
                try {
                  int n = 0;
                  while (select.next()) {
                    try {
                      table.insertByFieldNamesOr(null, getInsertValues());
                      n++;
                    } catch (SqlJetException e) {
                      SVNSqlJetDb.createSqlJetError(e);
                      return -1;
                    }
                  }
                  return n;
                } finally {
                  select.reset();
                }
              }

              protected Map<String, Object> getInsertValues() throws SVNException {
                Map<String, Object> selectedRow = select.getRowValues();
                Map<String, Object> insertValues = new HashMap<String, Object>();
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.wc_id.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.wc_id.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.local_relpath.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.local_relpath.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.op_depth.toString(), 0);
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.parent_relpath.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.parent_relpath.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.repos_id.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.repos_id.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.repos_path.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.repos_path.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.revision.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.revnum.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.presence.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.presence.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.depth.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.depth.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.moved_here.toString(), null);
                insertValues.put(SVNWCDbSchema.NODES__Fields.moved_to.toString(), null);
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.kind.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.kind.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_revision.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.changed_rev.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_date.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.changed_date.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_author.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.changed_author.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.checksum.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.checksum.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.properties.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.properties.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.translated_size.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.translated_size.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.last_mod_time.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.last_mod_time.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.dav_cache.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.dav_cache.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.symlink_target.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.symlink_target.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.file_external.toString(),
                    selectedRow.get(SVNWCDbSchema.BASE_NODE__Fields.file_external.toString()));
                return insertValues;
              }
            };

        try {
          stmt.exec();
        } finally {
          stmt.reset();
        }
        /*INSERT INTO NODES (
        	wc_id, local_relpath, op_depth, parent_relpath,
        	repos_id, repos_path, revision,
        	presence, depth, moved_here, moved_to, kind,
        	changed_revision, changed_date, changed_author,
        	checksum, properties, translated_size, last_mod_time,
        	dav_cache, symlink_target, file_external )
        SELECT wc_id, local_relpath, 2 /*op_depth/, parent_relpath,
        	copyfrom_repos_id, copyfrom_repos_path, copyfrom_revnum,
        	presence, depth, NULL /*moved_here/, NULL /*moved_to/, kind,
        	changed_rev, changed_date, changed_author,
        	checksum, properties, translated_size, last_mod_time,
        	NULL /*dav_cache/, symlink_target, NULL /*file_external/
        FROM WORKING_NODE;
         */
        stmt =
            new SVNSqlJetInsertStatement(sDb, SVNWCDbSchema.NODES) {
              private SVNSqlJetSelectStatement select =
                  new SVNSqlJetSelectStatement(sDb.getTemporaryDb(), SVNWCDbSchema.BASE_NODE) {};

              public long exec() throws SVNException {
                try {
                  int n = 0;
                  while (select.next()) {
                    try {
                      table.insertByFieldNamesOr(null, getInsertValues());
                      n++;
                    } catch (SqlJetException e) {
                      SVNSqlJetDb.createSqlJetError(e);
                      return -1;
                    }
                  }
                  return n;
                } finally {
                  select.reset();
                }
              }

              protected Map<String, Object> getInsertValues() throws SVNException {
                Map<String, Object> selectedRow = select.getRowValues();
                Map<String, Object> insertValues = new HashMap<String, Object>();
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.wc_id.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.wc_id.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.local_relpath.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.local_relpath.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.op_depth.toString(), 2);
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.parent_relpath.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.parent_relpath.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.repos_id.toString(),
                    selectedRow.get(
                        SVNWCDbSchema.WORKING_NODE__Fields.copyfrom_repos_id.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.repos_path.toString(),
                    selectedRow.get(
                        SVNWCDbSchema.WORKING_NODE__Fields.copyfrom_repos_path.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.revision.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.copyfrom_revnum.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.presence.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.presence.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.depth.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.depth.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.moved_here.toString(), null);
                insertValues.put(SVNWCDbSchema.NODES__Fields.moved_to.toString(), null);
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.kind.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.kind.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_revision.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.changed_rev.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_date.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.changed_date.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.changed_author.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.changed_author.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.checksum.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.checksum.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.properties.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.properties.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.translated_size.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.translated_size.toString()));
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.last_mod_time.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.last_mod_time.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.dav_cache.toString(), null);
                insertValues.put(
                    SVNWCDbSchema.NODES__Fields.symlink_target.toString(),
                    selectedRow.get(SVNWCDbSchema.WORKING_NODE__Fields.symlink_target.toString()));
                insertValues.put(SVNWCDbSchema.NODES__Fields.file_external.toString(), null);
                return insertValues;
              }
            };

        try {
          stmt.exec();
        } finally {
          stmt.reset();
        }

        sDb.getDb().dropTable("BASE_NODE");
        sDb.getDb().dropTable("WORKING_NODE");

      } catch (SqlJetException e) {
        SVNSqlJetDb.createSqlJetError(e);
      }

      setVersion(sDb, (int) 21);
    }
 public SVNWCDbReplaceWithBaseDeleted(SVNSqlJetDb sDb) throws SqlJetException {
   super(sDb);
   table = sDb.getDb().getTable(SVNWCDbSchema.LOCK.toString());
 }