static void checkColumnsResolved(HsqlList set) {

    if (set != null && !set.isEmpty()) {
      StringBuffer sb = new StringBuffer();
      Expression e = (Expression) set.get(0);

      if (e instanceof ExpressionColumn) {
        ExpressionColumn c = (ExpressionColumn) e;

        if (c.schema != null) {
          sb.append(c.schema + '.');
        }

        if (c.tableName != null) {
          sb.append(c.tableName + '.');
        }

        throw Error.error(ErrorCode.X_42501, sb.toString() + c.getColumnName());
      } else {
        OrderedHashSet newSet = new OrderedHashSet();

        e.collectAllExpressions(
            newSet, Expression.columnExpressionSet, Expression.emptyExpressionSet);

        // throw with column name
        checkColumnsResolved(newSet);

        // throw anyway if not found
        throw Error.error(ErrorCode.X_42501);
      }
    }
  }
Example #2
0
 private void processScript() {
   Object localObject = null;
   try {
     Crypto localCrypto = this.database.logger.getCrypto();
     if (localCrypto == null) {
       boolean bool = this.database.logger.propScriptFormat == 3;
       localObject = new ScriptReaderText(this.database, this.scriptFileName, bool);
     } else {
       localObject =
           new ScriptReaderDecode(this.database, this.scriptFileName, localCrypto, false);
     }
     Session localSession = this.database.sessionManager.getSysSessionForScript(this.database);
     ((ScriptReaderBase) localObject).readAll(localSession);
     ((ScriptReaderBase) localObject).close();
   } catch (Throwable localThrowable) {
     if (localObject != null) {
       ((ScriptReaderBase) localObject).close();
       if (this.cache != null) this.cache.close(false);
       this.database.logger.closeAllTextCaches(false);
     }
     this.database.logger.logWarningEvent("Script processing failure", localThrowable);
     if ((localThrowable instanceof HsqlException)) throw ((HsqlException) localThrowable);
     if ((localThrowable instanceof IOException)) throw Error.error(452, localThrowable);
     if ((localThrowable instanceof OutOfMemoryError)) throw Error.error(460);
     throw Error.error(458, localThrowable);
   }
 }
  protected String getField(String sep, int sepLen, boolean isEnd) throws IOException {

    String s = null;

    try {
      int start = next;

      field++;

      if (isEnd) {
        if ((next >= textLen) && (sepLen > 0)) {
          throw Error.error(ErrorCode.TEXT_SOURCE_NO_END_SEPARATOR);
        } else if (text.endsWith(sep)) {
          next = textLen - sepLen;
        } else {
          throw Error.error(ErrorCode.TEXT_SOURCE_NO_END_SEPARATOR);
        }
      } else {
        next = text.indexOf(sep, start);

        if (next == -1) {
          next = textLen;
        }
      }

      if (start > next) {
        start = next;
      }

      s = text.substring(start, next);
      next += sepLen;

      int trimLength = s.trim().length();

      if (trimLength == 0) {
        s = null;
      } else if (trimLength < s.length()) {
        trimLength = s.length() - 1;

        while (s.charAt(trimLength) < ' ') {
          trimLength--;
        }

        s = s.substring(0, trimLength + 1);
      }
    } catch (Exception e) {
      Object[] messages = new Object[] {new Integer(field), e.toString()};

      throw new IOException(Error.getMessage(ErrorCode.M_TEXT_SOURCE_FIELD_ERROR, 0, messages));
    }

    return s;
  }
  public void resolveRangeTable(
      Session session,
      RangeVariable[] rangeVariables,
      int rangeCount,
      RangeVariable[] outerRanges) {

    Table table = rangeTable;
    SubQuery subQuery = table.getSubQuery();

    if (subQuery != null && !subQuery.isResolved()) {
      if (subQuery.dataExpression != null) {
        HsqlList unresolved =
            subQuery.dataExpression.resolveColumnReferences(
                session, RangeVariable.emptyArray, null);

        if (unresolved != null) {
          unresolved =
              subQuery.dataExpression.resolveColumnReferences(
                  session, rangeVariables, rangeCount, null, true);
        }

        if (unresolved != null) {
          unresolved = subQuery.dataExpression.resolveColumnReferences(session, outerRanges, null);
        }

        if (unresolved != null) {
          throw Error.error(ErrorCode.X_42501, ((Expression) unresolved.get(0)).getSQL());
        }

        subQuery.dataExpression.resolveTypes(session, null);
        setRangeTableVariables();
      }

      if (subQuery.queryExpression != null) {
        subQuery.queryExpression.resolveReferences(session, outerRanges);

        HsqlList list = subQuery.queryExpression.getUnresolvedExpressions();

        // todo resolve against i ranges
        HsqlList unresolved =
            Expression.resolveColumnSet(session, rangeVariables, rangeCount, list, null);

        if (unresolved != null) {
          throw Error.error(ErrorCode.X_42501, ((Expression) unresolved.get(0)).getSQL());
        }

        subQuery.queryExpression.resolveTypes(session);
        subQuery.prepareTable(session);
        subQuery.setCorrelated();
        setRangeTableVariables();
      }
    }
  }
  /** throws if database is not a normal read / write file database */
  public void checkDatabaseIsFiles() {

    if (!getType().equals(DatabaseURL.S_FILE)) {
      throw Error.error(ErrorCode.DATABASE_IS_NON_FILE);
    }

    if (isFilesReadOnly()) {
      throw Error.error(ErrorCode.DATABASE_IS_READONLY);
    }

    if (logger.isStoredFileAccess()) {
      throw Error.error(ErrorCode.DATABASE_IS_NON_FILE);
    }
  }
Example #6
0
  public void resolveTypes(Session session, Expression parent) {

    for (int i = 0; i < nodes.length; i++) {
      if (nodes[i] != null) {
        nodes[i].resolveTypes(session, this);
      }
    }

    if (nodes.length == 1) {
      if (nodes[LEFT].dataType.isRowType()) {
        if (ordinality) {
          throw Error.error(ErrorCode.X_42581, Tokens.T_ORDINALITY);
        }

        nodeDataTypes = ((RowType) nodes[LEFT].dataType).getTypesArray();

        subQuery.prepareTable(session);

        subQuery.getTable().columnList =
            ((FunctionSQLInvoked) nodes[LEFT]).routine.getTable().columnList;
        isTable = true;

        return;
      }
    }

    for (int i = 0; i < nodes.length; i++) {
      if (!nodes[i].dataType.isArrayType()) {
        throw Error.error(ErrorCode.X_42563, Tokens.T_UNNEST);
      }
    }

    int columnCount = ordinality ? nodes.length + 1 : nodes.length;

    nodeDataTypes = new Type[columnCount];

    for (int i = 0; i < nodes.length; i++) {
      nodeDataTypes[i] = nodes[i].dataType.collectionBaseType();

      if (nodeDataTypes[i] == null || nodeDataTypes[i] == Type.SQL_ALL_TYPES) {
        throw Error.error(ErrorCode.X_42567, Tokens.T_UNNEST);
      }
    }

    if (ordinality) {
      nodeDataTypes[nodes.length] = Type.SQL_INTEGER;
    }

    subQuery.prepareTable(session);
  }
  public Result execute(Session session) {

    Result result;

    if (targetTable != null && session.isReadOnly() && !targetTable.isTemp()) {
      HsqlException e = Error.error(ErrorCode.X_25006);

      return Result.newErrorResult(e);
    }

    if (isExplain) {
      return getExplainResult(session);
    }

    try {
      if (subqueries.length > 0) {
        materializeSubQueries(session);
      }

      result = getResult(session);
    } catch (Throwable t) {
      result = Result.newErrorResult(t, null);

      result.getException().setStatementType(group, type);
    }

    session.sessionContext.clearStructures(this);

    return result;
  }
  public void readLobResults(
      SessionInterface session, DataInputStream inputStream, RowInputBinary in)
      throws IOException, HsqlException {

    Result currentResult = this;
    boolean hasLob = false;

    setSession(session);

    while (true) {
      int addedResultMode = inputStream.readByte();

      if (addedResultMode == ResultConstants.LARGE_OBJECT_OP) {
        ResultLob resultLob = ResultLob.newLob(inputStream, false);

        if (session instanceof Session) {
          ((Session) session).allocateResultLob(resultLob, inputStream);
        } else {
          currentResult.addLobResult(resultLob);
        }

        hasLob = true;

        continue;
      } else if (addedResultMode == ResultConstants.NONE) {
        break;
      } else {
        throw Error.runtimeError(ErrorCode.U_S0500, "Result");
      }
    }

    if (hasLob) {
      ((Session) session).registerResultLobs(currentResult);
    }
  }
  /**
   * Opens this database. The database should be opened after construction. or reopened by the
   * close(int closemode) method during a "shutdown compact". Closes the log if there is an error.
   */
  void reopen() {

    boolean isNew = false;

    setState(DATABASE_OPENING);

    try {
      nameManager = new HsqlNameManager(this);
      granteeManager = new GranteeManager(this);
      userManager = new UserManager(this);
      schemaManager = new SchemaManager(this);
      persistentStoreCollection = new PersistentStoreCollectionDatabase(this);
      isReferentialIntegrity = true;
      sessionManager = new SessionManager(this);
      collation = collation.newDatabaseInstance();
      dbInfo = DatabaseInformation.newDatabaseInformation(this);
      txManager = new TransactionManager2PL(this);

      lobManager.createSchema();
      sessionManager.getSysLobSession().setSchema(SqlInvariants.LOBS_SCHEMA);
      schemaManager.setSchemaChangeTimestamp();
      schemaManager.createSystemTables();

      // completed metadata
      logger.open();

      isNew = logger.isNewDatabase;

      if (isNew) {
        String username = urlProperties.getProperty("user", "SA");
        String password = urlProperties.getProperty("password", "");

        userManager.createFirstUser(username, password);
        schemaManager.createPublicSchema();
        logger.checkpoint(false);
      }

      lobManager.open();
      dbInfo.setWithContent(true);

      checkpointRunner = new CheckpointRunner();
      timeoutRunner = new TimeoutRunner();
    } catch (Throwable e) {
      logger.close(Database.CLOSEMODE_IMMEDIATELY);
      logger.releaseLock();
      setState(DATABASE_SHUTDOWN);
      clearStructures();
      DatabaseManager.removeDatabase(this);

      if (!(e instanceof HsqlException)) {
        e = Error.error(ErrorCode.GENERAL_ERROR, e);
      }

      logger.logSevereEvent("could not reopen database", e);

      throw (HsqlException) e;
    }

    setState(DATABASE_ONLINE);
  }
    public void rename(String name, boolean isquoted) {

      if (manager.sqlRegularNames && name.length() > 128) {
        throw Error.error(ErrorCode.X_42501, name);
      }

      // get rid of the excess
      this.name = new String(name);
      this.statementName = this.name;
      this.isNameQuoted = isquoted;

      if (isNameQuoted) {
        statementName = StringConverter.toQuotedString(name, '"', true);
      }

      if (name.startsWith("SYS_")) {
        int length = name.lastIndexOf('_') + 1;

        try {
          int temp = Integer.parseInt(name.substring(length));

          if (temp > manager.sysNumber) {
            manager.sysNumber = temp;
          }
        } catch (NumberFormatException e) {
        }
      }
    }
Example #11
0
 public HsqlException getException(Object[] paramArrayOfObject) {
   Object localObject1;
   Object localObject2;
   switch (this.constType) {
     case 3:
       localObject1 = new String[] {this.name.statementName};
       return Error.error(null, 157, 2, (Object[]) localObject1);
     case 0:
       localObject1 = new StringBuffer();
       for (int i = 0; i < this.core.refCols.length; i++) {
         localObject2 = paramArrayOfObject[this.core.refCols[i]];
         ((StringBuffer) localObject1)
             .append(
                 this.core.refTable.getColumnTypes()[this.core.refCols[i]].convertToString(
                     localObject2));
         ((StringBuffer) localObject1).append(',');
       }
       String[] arrayOfString = {
         this.name.statementName,
         this.core.refTable.getName().statementName,
         ((StringBuffer) localObject1).toString()
       };
       return Error.error(null, 177, 2, arrayOfString);
     case 2:
     case 4:
       localObject1 = new StringBuffer();
       for (int j = 0; j < this.core.mainCols.length; j++) {
         localObject2 = paramArrayOfObject[this.core.mainCols[j]];
         ((StringBuffer) localObject1)
             .append(
                 this.core.mainTable.colTypes[this.core.mainCols[j]].convertToString(
                     localObject2));
         ((StringBuffer) localObject1).append(',');
       }
       return Error.error(
           null,
           104,
           2,
           new String[] {
             this.name.statementName,
             this.core.mainTable.getName().statementName,
             ((StringBuffer) localObject1).toString()
           });
     case 1:
   }
   throw Error.runtimeError(201, "Constraint");
 }
  public final RowIterator rowIterator() {

    if (indexList.length == 0 || indexList[0] == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "RowStoreAVL");
    }

    return indexList[0].firstRow(this, false);
  }
Example #13
0
  public final OrderedHashSet getComponents() {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    return userTypeModifier.getComponents();
  }
Example #14
0
  // interface specific methods
  public final int getType() {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    return userTypeModifier.getType();
  }
Example #15
0
  /**
   * Convert type for JDBC reads. Same as convertToType, but supports non-standard SQL conversions
   * supported by JDBC
   */
  public Object convertToTypeJDBC(SessionInterface session, Object a, Type otherType) {

    if (otherType.isLobType()) {
      throw Error.error(ErrorCode.X_42561);
    }

    return convertToType(session, a, otherType);
  }
Example #16
0
  public final HsqlName getCatalogName() {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    return userTypeModifier.getSchemaName().schema;
  }
Example #17
0
  public Type duplicate() {

    try {
      return (Type) super.clone();
    } catch (CloneNotSupportedException e) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }
  }
Example #18
0
  public void addSpecificRoutine(Database database, Routine routine) {

    int signature = routine.getParameterSignature();
    Type[] types = routine.getParameterTypes();

    for (int i = 0; i < this.routines.length; i++) {
      if (routines[i].parameterTypes.length == types.length) {
        if (routineType == SchemaObject.PROCEDURE) {
          throw Error.error(ErrorCode.X_42605);
        }

        if (routines[i].isAggregate() != routine.isAggregate()) {
          throw Error.error(ErrorCode.X_42605);
        }

        boolean match = true;

        for (int j = 0; j < types.length; j++) {
          if (!routines[i].parameterTypes[j].equals(types[j])) {
            match = false;

            break;
          }
        }

        if (match) {
          throw Error.error(ErrorCode.X_42605);
        }
      }
    }

    if (routine.getSpecificName() == null) {
      HsqlName specificName = database.nameManager.newSpecificRoutineName(name);

      routine.setSpecificName(specificName);
    } else {
      routine.getSpecificName().parent = name;
      routine.getSpecificName().schema = name.schema;
    }

    routine.setName(name);

    routine.routineSchema = this;
    routines = (Routine[]) ArrayUtil.resizeArray(routines, routines.length + 1);
    routines[routines.length - 1] = routine;
  }
Example #19
0
  public final void compile(Session session, SchemaObject parentObject) {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    userTypeModifier.compile(session);
  }
Example #20
0
  public final Grantee getOwner() {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    return userTypeModifier.getOwner();
  }
Example #21
0
  /**
   * Retrieves the SQL character sequence required to (re)create the trigger, as a StringBuffer
   *
   * @return the SQL character sequence required to (re)create the trigger
   */
  public String getSQL() {

    if (userTypeModifier == null) {
      throw Error.runtimeError(ErrorCode.U_S0500, "Type");
    }

    return userTypeModifier.getSQL();
  }
Example #22
0
 void writeDeleteStatement(Session paramSession, Table paramTable, Object[] paramArrayOfObject) {
   try {
     this.dbLogWriter.writeDeleteStatement(paramSession, paramTable, paramArrayOfObject);
   } catch (IOException localIOException) {
     throw Error.error(452, this.logFileName);
   }
   if ((this.maxLogSize > 0L) && (this.dbLogWriter.size() > this.maxLogSize))
     this.database.logger.setCheckpointRequired();
 }
Example #23
0
 void writeCommitStatement(Session paramSession) {
   try {
     this.dbLogWriter.writeCommitStatement(paramSession);
   } catch (IOException localIOException) {
     throw Error.error(452, this.logFileName);
   }
   if ((this.maxLogSize > 0L) && (this.dbLogWriter.size() > this.maxLogSize))
     this.database.logger.setCheckpointRequired();
 }
Example #24
0
  public void setPassword(Session session, User user, String password, boolean isDigest) {

    if (!isDigest && !checkComplexity(session, password)) {
      throw Error.error(ErrorCode.PASSWORD_COMPLEXITY);
    }

    // requires: UserManager.createSAUser(), UserManager.createPublicUser()
    user.setPassword(password, isDigest);
  }
Example #25
0
  public Routine getSpecificRoutine(int paramCount) {

    for (int i = 0; i < this.routines.length; i++) {
      if (routines[i].parameterTypes.length == paramCount) {
        return routines[i];
      }
    }

    throw Error.error(ErrorCode.X_42501);
  }
Example #26
0
  /** Returns the User object identified by the name argument. */
  public User get(String name) {

    User user = (User) userList.get(name);

    if (user == null) {
      throw Error.error(ErrorCode.X_28501, name);
    }

    return user;
  }
  public CachedObject getAccessor(Index key) {

    int position = key.getPosition();

    if (position >= accessorList.length) {
      throw Error.runtimeError(ErrorCode.U_S0500, "RowStoreAVL");
    }

    return accessorList[position];
  }
  public void resolveTypes(Session session, Expression parent) {

    for (int i = 0; i < nodes.length; i++) {
      if (nodes[i] != null) {
        nodes[i].resolveTypes(session, this);
      }
    }

    if (nodes[LEFT].isParam) {
      throw Error.error(ErrorCode.X_42567);
    }

    if (isDistinctAggregate) {
      if (nodes[LEFT].dataType.isLobType()) {
        throw Error.error(ErrorCode.X_42534);
      }
    }

    dataType = SetFunction.getType(opType, nodes[LEFT].dataType);
  }
Example #29
0
  /**
   * Attempts to drop a User object with the specified name from this object's set.
   *
   * <p>A successful drop action consists of:
   *
   * <p>
   *
   * <UL>
   *   <LI>removing the User object with the specified name from the set.
   *   <LI>revoking all rights from the removed User<br>
   *       (this ensures that in case there are still references to the just dropped User object,
   *       those references cannot be used to erronously access database objects).
   * </UL>
   *
   * <p>
   */
  public void dropUser(String name) {

    boolean reservedUser = GranteeManager.isReserved(name);

    if (reservedUser) {
      throw Error.error(ErrorCode.X_28502, name);
    }

    boolean result = granteeManager.removeGrantee(name);

    if (!result) {
      throw Error.error(ErrorCode.X_28501, name);
    }

    User user = (User) userList.remove(name);

    if (user == null) {
      throw Error.error(ErrorCode.X_28501, name);
    }
  }
Example #30
0
  public Object[] getRowValue(Session session) {

    switch (opType) {
      case OpTypes.TABLE:
        {
          return subQuery.queryExpression.getValues(session);
        }
      default:
        throw Error.runtimeError(ErrorCode.U_S0500, "Expression");
    }
  }