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); } }
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); } } }
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(); } } }
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 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); }
/** 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); } }
/** * 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 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 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) { } } }
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"); }
/** * 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); }
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; }
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(); }
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); }
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(); }
/** 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 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); }
void checkCheckConstraint(Session paramSession, Table paramTable, Object[] paramArrayOfObject) { RangeVariable.RangeIteratorBase localRangeIteratorBase = paramSession.sessionContext.getCheckIterator(this.rangeVariable); localRangeIteratorBase.currentData = paramArrayOfObject; boolean bool = Boolean.FALSE.equals(this.check.getValue(paramSession)); localRangeIteratorBase.currentData = null; if (bool) { String[] arrayOfString = {this.name.name, paramTable.getName().name}; throw Error.error(null, 157, 2, arrayOfString); } }
public void setRangeTableVariables() { if (columnAliasNames != null && rangeTable.getColumnCount() != columnAliasNames.length) { throw Error.error(ErrorCode.X_42593); } emptyData = rangeTable.getEmptyRowData(); columnsInGroupBy = rangeTable.getNewColumnCheckList(); usedColumns = rangeTable.getNewColumnCheckList(); joinConditions[0].rangeIndex = rangeTable.getPrimaryIndex(); }
/** * 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); } }
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); }
public static long getDateSeconds(String s) { try { synchronized (sdfd) { java.util.Date d = sdfd.parse(s); return d.getTime() / 1000; } } catch (Exception e) { throw Error.error(ErrorCode.X_22007); } }
public Constraint( HsqlNameManager.HsqlName paramHsqlName, Table paramTable, Index paramIndex, int paramInt) { this.name = paramHsqlName; this.constType = paramInt; this.core = new ConstraintCore(); this.core.mainTable = paramTable; this.core.mainIndex = paramIndex; this.core.mainCols = paramIndex.getColumns(); for (int i = 0; i < this.core.mainCols.length; i++) { Type localType = paramTable.getColumn(this.core.mainCols[i]).getDataType(); if (localType.isLobType()) throw Error.error(5534); } }
/** @todo 1.9.0 fredt - move the messages to Error.java */ public static Result newErrorResult(Throwable t, String statement) { Result result = newResult(ResultConstants.ERROR); if (t instanceof HsqlException) { result.exception = (HsqlException) t; result.mainString = result.exception.getMessage(); result.subString = result.exception.getSQLState(); if (statement != null) { result.mainString += " in statement [" + statement + "]"; } result.errorCode = result.exception.getErrorCode(); } else if (t instanceof OutOfMemoryError) { // gc() at this point may clear the memory allocated so far /** @todo 1.9.0 - review if it's better to gc higher up the stack */ System.gc(); result.exception = Error.error(ErrorCode.OUT_OF_MEMORY, t); result.mainString = result.exception.getMessage(); result.subString = result.exception.getSQLState(); result.errorCode = result.exception.getErrorCode(); } else { result.exception = Error.error(ErrorCode.GENERAL_ERROR, t); result.mainString = result.exception.getMessage() + " " + t.toString(); result.subString = result.exception.getSQLState(); result.errorCode = result.exception.getErrorCode(); if (statement != null) { result.mainString += " in statement [" + statement + "]"; } } return result; }
void openLog() { if (this.filesReadOnly) return; Crypto localCrypto = this.database.logger.getCrypto(); try { if (localCrypto == null) this.dbLogWriter = new ScriptWriterText(this.database, this.logFileName, false, false, false); else this.dbLogWriter = new ScriptWriterEncode(this.database, this.logFileName, localCrypto); this.dbLogWriter.setWriteDelay(this.writeDelay); this.dbLogWriter.start(); } catch (Throwable localThrowable) { throw Error.error(452, this.logFileName); } }
/** * 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(); isReferentialIntegrity = true; sessionManager = new SessionManager(this); collation = collation.getDefaultInstance(); dbInfo = DatabaseInformation.newDatabaseInformation(this); txManager = new TransactionManager2PL(this); lobManager.createSchema(); logger.openPersistence(); isNew = logger.isNewDatabase; if (isNew) { userManager.createSAUser(); schemaManager.createPublicSchema(); lobManager.initialiseLobSpace(); logger.checkpoint(false); } lobManager.open(); dbInfo.setWithContent(true); } catch (Throwable e) { logger.closePersistence(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); }
void checkCheckConstraint( Session paramSession, Table paramTable, ColumnSchema paramColumnSchema, Object paramObject) { paramSession.sessionData.currentValue = paramObject; boolean bool = Boolean.FALSE.equals(this.check.getValue(paramSession)); paramSession.sessionData.currentValue = null; if (bool) { String[] arrayOfString = { this.name.statementName, paramTable == null ? "" : paramTable.getName().statementName, paramColumnSchema == null ? "" : paramColumnSchema.getName().statementName }; throw Error.error(null, 157, 3, arrayOfString); } }
public static Result newResult(Session session, int mode, DataInput dataInput, RowInputBinary in) throws IOException, HsqlException { try { if (mode == ResultConstants.LARGE_OBJECT_OP) { return ResultLob.newLob(dataInput, false); } Result result = newResult(session, dataInput, in, mode); return result; } catch (IOException e) { throw Error.error(ErrorCode.X_08000); } }
public void addSessionVariable(ColumnSchema variable) { int index = sessionVariables.size(); if (!sessionVariables.add(variable.getName().name, variable)) { throw Error.error(ErrorCode.X_42504); } Object[] vars = new Object[sessionVariables.size()]; ArrayUtil.copyArray(routineVariables, vars, routineVariables.length); routineVariables = vars; routineVariables[index] = variable.getDefaultValue(session); }
void setColumnsIndexes(Table paramTable) { int i; Type localType; if (this.constType == 0) { if (this.mainColSet == null) { this.core.mainCols = this.core.mainTable.getPrimaryKey(); if (this.core.mainCols == null) throw Error.error(5581); } else if (this.core.mainCols == null) { this.core.mainCols = this.core.mainTable.getColumnIndexes(this.mainColSet); } if (this.core.refCols == null) this.core.refCols = paramTable.getColumnIndexes(this.refColSet); for (i = 0; i < this.core.refCols.length; i++) { localType = paramTable.getColumn(this.core.refCols[i]).getDataType(); if (localType.isLobType()) throw Error.error(5534); } } else if (this.mainColSet != null) { this.core.mainCols = paramTable.getColumnIndexes(this.mainColSet); for (i = 0; i < this.core.mainCols.length; i++) { localType = paramTable.getColumn(this.core.mainCols[i]).getDataType(); if (localType.isLobType()) throw Error.error(5534); } } }