/** Method declaration */
  public void run() {

    Channel c = init();

    if (c != null) {
      try {
        while (true) {
          String sql = mInput.readUTF();

          mServer.trace(mThread + ":" + sql);

          if (sql == null) {
            break;
          }

          write(mDatabase.execute(sql, c).getBytes());
        }
      } catch (Exception e) {
      }
    }

    try {
      mSocket.close();
    } catch (IOException e) {
    }

    if (mDatabase.isShutdown()) {
      System.out.println("The database is shutdown");
      System.exit(0);
    }
  }
  /**
   * Method declaration
   *
   * @throws SQLException
   */
  private void runScript() throws SQLException {

    if (Trace.TRACE) {
      Trace.trace();
    }

    if (!(new File(sFileScript)).exists()) {
      return;
    }

    bRestoring = true;

    dDatabase.setReferentialIntegrity(false);

    HsqlArrayList session = new HsqlArrayList();

    session.add(sysSession);

    Session current = sysSession;

    try {
      long time = 0;

      if (Trace.TRACE) {
        time = System.currentTimeMillis();
      }

      LineNumberReader r = new LineNumberReader(new FileReader(sFileScript));

      while (true) {
        String s = readLine(r);

        if (s == null) {
          break;
        }

        if (s.startsWith("/*C")) {
          int id = Integer.parseInt(s.substring(3, s.indexOf('*', 4)));

          if (id >= session.size()) {
            session.setSize(id + 1);
          }

          current = (Session) session.get(id);

          if (current == null) {
            current = new Session(sysSession, id);

            session.set(id, current);
            dDatabase.registerSession(current);
          }

          s = s.substring(s.indexOf('/', 1) + 1);
        }

        if (s.length() != 0) {
          Result result = dDatabase.execute(s, current);

          if ((result != null) && (result.iMode == Result.ERROR)) {
            throw (Trace.getError(result.errorCode, result.sError));
          }
        }

        if (s.equals("DISCONNECT")) {
          int id = current.getId();

          current = new Session(sysSession, id);

          session.set(id, current);
        }
      }

      r.close();

      for (int i = 0; i < session.size(); i++) {
        current = (Session) session.get(i);

        if (current != null) {
          current.rollback();
        }
      }

      if (Trace.TRACE) {
        Trace.trace(time - System.currentTimeMillis());
      }
    } catch (IOException e) {
      throw Trace.error(Trace.FILE_IO_ERROR, sFileScript + " " + e);
    }

    dDatabase.setReferentialIntegrity(true);

    bRestoring = false;
  }