コード例 #1
0
  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);
      }
    }
  }
コード例 #2
0
  /**
   * Initializes this jdbcResultSetMetaData object from the specified Result and HsqlProperties
   * objects.
   *
   * @param r the Result object from which to initialize this jdbcResultSetMetaData object
   * @param props the HsqlProperties object from which to initialize this jdbcResultSetMetaData
   *     object
   * @throws SQLException if a database access error occurs
   */
  void init(Result r, HsqlProperties props) throws SQLException {

    jdbcColumnMetaData cmd;
    int type;
    Result.ResultMetaData rmd;

    if (r == null) {
      throw Util.sqlException(Trace.GENERAL_ERROR, Trace.JDBC_NO_RESULT_SET, null);
    }

    if (r.mode != ResultConstants.DATA) {

      // implied: columnCount = 0;
      return;
    }

    columnCount = r.getColumnCount();

    // fredt -  props is null for internal connections, so always use the default behaviour in this
    // case
    useColumnName = props == null ? true : props.isPropertyTrue("get_column_name");
    columnMetaData = new jdbcColumnMetaData[columnCount];
    rmd = r.metaData;

    for (int i = 0; i < columnCount; i++) {
      cmd = new jdbcColumnMetaData();
      columnMetaData[i] = cmd;

      // Typically, these null checks are not needed, but as
      // above, it is not _guaranteed_ that these values
      // will be non-null.   So, it is better to do the work
      // here than have to perform checks and conversions later.
      cmd.catalogName = rmd.catalogNames[i] == null ? "" : rmd.catalogNames[i];
      cmd.schemaName = rmd.schemaNames[i] == null ? "" : rmd.schemaNames[i];
      cmd.tableName = rmd.tableNames[i] == null ? "" : rmd.tableNames[i];
      cmd.columnName = rmd.colNames[i] == null ? "" : rmd.colNames[i];
      cmd.columnLabel = rmd.colLabels[i] == null ? "" : rmd.colLabels[i];
      cmd.columnType = rmd.colTypes[i];
      cmd.columnTypeName = Types.getTypeString(cmd.columnType);
      cmd.isWritable = rmd.isWritable[i];
      cmd.isReadOnly = !cmd.isWritable;

      // default: cmd.isDefinitelyWritable = false;
      cmd.isAutoIncrement = rmd.isIdentity[i];
      cmd.isNullable = rmd.colNullable[i];
      type = cmd.columnType;
      cmd.columnClassName = rmd.classNames[i];

      if (cmd.columnClassName == null || cmd.columnClassName.length() == 0) {
        cmd.columnClassName = Types.getColStClsName(type);
      }

      // Some tools, such as PowerBuilder, require that (for char and
      // varchar types, at any rate) getMaxDisplaySize returns a value
      // _at least_ as large as the length of the longest value in this
      // column of the result set, or else an internal error will occur
      // at retrieve time the instant a longer value is fetched.
      //
      // org.hsqldb.Types has been patched to retrieve, by default, either
      // a large-but-reasonable value or a value defined through system
      // properties that is expected to be unlikely to cause problems in
      // the majority of cases.
      if (Types.acceptsPrecisionCreateParam(type)) {
        if (rmd.colSizes[i] == 0) {
          cmd.columnDisplaySize = Types.getMaxDisplaySize(type);
        } else {
          cmd.columnDisplaySize = rmd.colSizes[i];

          if (Types.acceptsScaleCreateParam(type)) {
            if (rmd.colScales[i] != 0) {
              cmd.columnDisplaySize += (1 + rmd.colScales[i]);
            }
          }
        }
      } else {
        cmd.columnDisplaySize = Types.getMaxDisplaySize(type);
      }

      if (Types.isNumberType(type) && Types.acceptsPrecisionCreateParam(type)) {
        cmd.precision = rmd.colSizes[i];

        if (cmd.precision == 0) {
          cmd.precision = Types.getPrecision(type);
        }
      } else {
        cmd.precision = Types.getPrecision(type);
      }

      // Without a non-zero scale value, some (legacy only?) tools will
      // simply truncate digits to the right of the decimal point when
      // retrieving values from the result set. The measure below can
      // help, but currently only as long as one is connected to an
      // embedded instance at design time, not via a network connection.
      if (Types.acceptsScaleCreateParam(type)) {
        cmd.scale = rmd.colScales[i];
      }

      Boolean iua = Types.isUnsignedAttribute(type);

      cmd.isSigned = iua != null && !iua.booleanValue();

      Boolean ics = Types.isCaseSensitive(type);

      cmd.isCaseSensitive = ics != null && ics.booleanValue();
      cmd.isSearchable = Types.isSearchable(type);
    }
  }
コード例 #3
0
  /**
   * 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);
    }
  }