protected void readDDL(Session session) throws IOException, HsqlException {

    Result r = Result.read(rowIn, dataStreamIn);
    Iterator it = r.iterator();

    while (it.hasNext()) {
      Object[] data = (Object[]) it.next();
      String s = (String) data[0];
      Result result = session.sqlExecuteDirectNoPreChecks(s);

      if (result.mode == ResultConstants.ERROR) {
        db.logger.appLog.logContext(result.getException());

        /** @todo fredt - trap if unavaialble external functions are to be ignored */
        throw Trace.error(result);
      }
    }
  }
  /**
   * This is used to read the *.log file and manage any necessary transaction rollback.
   *
   * @throws HsqlException
   */
  public static void runScript(Database database, String logFilename, int logType)
      throws HsqlException {

    IntKeyHashMap sessionMap = new IntKeyHashMap();
    Session sysSession = database.getSessionManager().getSysSession(null, false);
    Session current = sysSession;
    int currentId = 0;

    database.setReferentialIntegrity(false);

    ScriptReaderBase scr = null;

    try {
      StopWatch sw = new StopWatch();

      scr =
          ScriptReaderBase.newScriptReader(database, logFilename, ScriptWriterBase.SCRIPT_TEXT_170);

      while (scr.readLoggedStatement(current)) {
        int sessionId = scr.getSessionNumber();

        if (currentId != sessionId) {
          currentId = sessionId;
          current = (Session) sessionMap.get(currentId);

          if (current == null) {
            current =
                database
                    .getSessionManager()
                    .newSession(database, sysSession.getUser(), false, true);

            sessionMap.put(currentId, current);
          }
        }

        if (current.isClosed()) {
          sessionMap.remove(currentId);

          continue;
        }

        String schema = current.currentSchema.name;
        Result result = null;

        switch (scr.getStatementType()) {
          case ScriptReaderBase.ANY_STATEMENT:
            result = current.sqlExecuteDirectNoPreChecks(scr.getLoggedStatement());

            if (result != null && result.mode == ResultConstants.ERROR) {
              if (result.getException() != null) {
                throw result.getException();
              }

              throw Trace.error(result);
            }
            break;

          case ScriptReaderBase.SEQUENCE_STATEMENT:
            scr.getCurrentSequence().reset(scr.getSequenceValue());
            break;

          case ScriptReaderBase.COMMIT_STATEMENT:
            current.commit();
            break;

          case ScriptReaderBase.INSERT_STATEMENT:
            {
              Object[] data = scr.getData();

              scr.getCurrentTable().insertNoCheckFromLog(current, data);

              break;
            }
          case ScriptReaderBase.DELETE_STATEMENT:
            {
              Object[] data = scr.getData();

              scr.getCurrentTable().deleteNoCheckFromLog(current, data);

              break;
            }
          case ScriptReaderBase.SCHEMA_STATEMENT:
            {
              current.setSchema(scr.getCurrentSchema());
            }
        }

        if (current.isClosed()) {
          sessionMap.remove(currentId);
        }
      }
    } catch (Throwable e) {
      String message;

      // catch out-of-memory errors and terminate
      if (e instanceof OutOfMemoryError) {
        message = "out of memory processing " + logFilename + " line: " + scr.getLineNumber();

        database.logger.appLog.logContext(message);

        throw Trace.error(Trace.OUT_OF_MEMORY);
      }

      // stop processing on bad log line
      message = logFilename + " line: " + scr.getLineNumber() + " " + e.getMessage();

      database.logger.appLog.logContext(message);
      Trace.printSystemOut(message);
    } finally {
      if (scr != null) {
        scr.close();
      }

      database.getSessionManager().closeAllSessions();
      database.setReferentialIntegrity(true);
    }
  }