Search in sources :

Example 56 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class Table method checkColumnsMatch.

/**
     * Match two valid, equal length, columns arrays for type of columns
     *
     * @param col column array from this Table
     * @param other the other Table object
     * @param othercol column array from the other Table
     */
void checkColumnsMatch(int[] col, Table other, int[] othercol) {
    for (int i = 0; i < col.length; i++) {
        Type type = colTypes[col[i]];
        Type otherType = other.colTypes[othercol[i]];
        if (type.typeComparisonGroup != otherType.typeComparisonGroup) {
            throw Error.error(ErrorCode.X_42562);
        }
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type)

Example 57 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class Table method enforceRowConstraints.

/**
     *  Enforce max field sizes according to SQL column definition.
     *  SQL92 13.8
     */
void enforceRowConstraints(Session session, Object[] data) {
    for (int i = 0; i < defaultColumnMap.length; i++) {
        Type type = colTypes[i];
        data[i] = type.convertToTypeLimits(session, data[i]);
        if (type.isDomainType()) {
            Constraint[] constraints = type.userTypeModifier.getConstraints();
            for (int j = 0; j < constraints.length; j++) {
                constraints[j].checkCheckConstraint(session, this, data[i]);
            }
        }
        if (data[i] == null) {
            if (colNotNull[i]) {
                Constraint c = getNotNullConstraintForColumn(i);
                if (c == null) {
                    if (getColumn(i).isPrimaryKey()) {
                        c = this.getPrimaryConstraint();
                    }
                }
                String[] info = new String[] { c.getName().name, tableName.name };
                throw Error.error(ErrorCode.X_23503, ErrorCode.CONSTRAINT, info);
            }
        }
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type)

Example 58 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class Session method executeResultUpdate.

/**
     * Retrieves the result of inserting, updating or deleting a row
     * from an updatable result.
     *
     * @return the result of executing the statement
     */
private Result executeResultUpdate(Result cmd) {
    long id = cmd.getResultId();
    int actionType = cmd.getActionType();
    Result result = sessionData.getDataResult(id);
    if (result == null) {
        return Result.newErrorResult(Error.error(ErrorCode.X_24501));
    }
    Object[] pvals = cmd.getParameterData();
    Type[] types = cmd.metaData.columnTypes;
    StatementQuery statement = (StatementQuery) result.getStatement();
    QueryExpression qe = statement.queryExpression;
    Table baseTable = qe.getBaseTable();
    int[] columnMap = qe.getBaseTableColumnMap();
    sessionContext.rowUpdateStatement.setRowActionProperties(actionType, baseTable, types, columnMap);
    Result resultOut = executeCompiledStatement(sessionContext.rowUpdateStatement, pvals);
    return resultOut;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Result(org.hsqldb_voltpatches.result.Result)

Example 59 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class StatementInsert method getInsertSelectNavigator.

RowSetNavigator getInsertSelectNavigator(Session session) {
    Type[] colTypes = baseTable.getColumnTypes();
    int[] columnMap = insertColumnMap;
    //
    Result result = queryExpression.getResult(session, 0);
    RowSetNavigator nav = result.initialiseNavigator();
    Type[] sourceTypes = result.metaData.columnTypes;
    RowSetNavigatorClient newData = new RowSetNavigatorClient(2);
    while (nav.hasNext()) {
        Object[] data = baseTable.getNewRowData(session);
        Object[] sourceData = (Object[]) nav.getNext();
        for (int i = 0; i < columnMap.length; i++) {
            int j = columnMap[i];
            Type sourceType = sourceTypes[i];
            data[j] = colTypes[j].convertToType(session, sourceData[i], sourceType);
        }
        newData.add(data);
    }
    return newData;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) RowSetNavigator(org.hsqldb_voltpatches.navigator.RowSetNavigator) RowSetNavigatorClient(org.hsqldb_voltpatches.navigator.RowSetNavigatorClient) Result(org.hsqldb_voltpatches.result.Result)

Example 60 with Type

use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.

the class Routine method getMethod.

static Method getMethod(String name, Type[] types, Type returnType, boolean[] nullability, boolean[] hasConnection) {
    int i = name.indexOf(':');
    if (i != -1) {
        if (!name.substring(0, i).equals(SqlInvariants.CLASSPATH_NAME)) {
            throw Error.error(ErrorCode.X_46102, name);
        }
        name = name.substring(i + 1);
    }
    Method method = null;
    Method[] methods = getMethods(name);
    for (i = 0; i < methods.length; i++) {
        int offset = 0;
        Class[] params = methods[i].getParameterTypes();
        if (params.length > 0 && params[0].equals(java.sql.Connection.class)) {
            offset = 1;
            hasConnection[0] = true;
        }
        if (params.length - offset != types.length) {
            continue;
        }
        Type methodReturnType = Type.getDefaultType(Types.getParameterSQLTypeNumber(methods[i].getReturnType()));
        if (methodReturnType == null) {
            continue;
        }
        if (methodReturnType.typeCode != returnType.typeCode) {
            continue;
        }
        method = methods[i];
        for (int j = 0; j < types.length; j++) {
            Class param = params[j + offset];
            Type methodParamType = Type.getDefaultType(Types.getParameterSQLTypeNumber(param));
            if (methodParamType == null) {
                break;
            }
            nullability[j] = !param.isPrimitive();
            if (types[j].typeCode != methodParamType.typeCode) {
                method = null;
                break;
            }
        }
        if (method != null) {
            break;
        }
    }
    return method;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) Method(java.lang.reflect.Method)

Aggregations

Type (org.hsqldb_voltpatches.types.Type)72 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)20 CharacterType (org.hsqldb_voltpatches.types.CharacterType)20 NumberType (org.hsqldb_voltpatches.types.NumberType)14 SchemaObject (org.hsqldb_voltpatches.SchemaObject)11 Table (org.hsqldb_voltpatches.Table)9 Iterator (org.hsqldb_voltpatches.lib.Iterator)9 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)9 IntervalType (org.hsqldb_voltpatches.types.IntervalType)9 Constraint (org.hsqldb_voltpatches.Constraint)8 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)8 HsqlException (org.hsqldb_voltpatches.HsqlException)7 TextTable (org.hsqldb_voltpatches.TextTable)6 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)6 DTIType (org.hsqldb_voltpatches.types.DTIType)6 ColumnSchema (org.hsqldb_voltpatches.ColumnSchema)4 DateTimeType (org.hsqldb_voltpatches.types.DateTimeType)4 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)3 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2