Search in sources :

Example 41 with Type

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

the class JDBCResultSetMetaData method isCurrency.

/**
     * <!-- start generic documentation -->
     * Indicates whether the designated column is a cash value.
     * <!-- end generic documentation -->
     *
     * <!-- start Release-specific documentation -->
     * <div class="ReleaseSpecificDocumentation">
     * <h3>HSQLDB-Specific Information:</h3> <p>
     *
     * HSQLDB 1.9.0 fully supports this feature and returns true for
     * NUMERIC and DECIMAL columns. <p>
     *
     * </div>
     * <!-- end release-specific documentation -->
     *
     * @param column the first column is 1, the second is 2, ...
     * @return <code>true</code> if so; <code>false</code> otherwise
     * @exception SQLException if a database access error occurs
     */
public boolean isCurrency(int column) throws SQLException {
    checkColumn(column);
    Type type = resultMetaData.columnTypes[--column];
    return (type.typeCode == Types.SQL_DECIMAL || type.typeCode == Types.SQL_NUMERIC) && type.scale > 0;
}
Also used : CharacterType(org.hsqldb_voltpatches.types.CharacterType) Type(org.hsqldb_voltpatches.types.Type)

Example 42 with Type

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

the class JDBCResultSetMetaData method getColumnTypeName.

/**
     * <!-- start generic documentation -->
     * Retrieves the designated column's database-specific type name.
     * <!-- end generic documentation -->
     *
     * @param column the first column is 1, the second is 2, ...
     * @return type name used by the database. If the column type is
     * a user-defined type, then a fully-qualified type name is returned.
     * @exception SQLException if a database access error occurs
     */
public String getColumnTypeName(int column) throws SQLException {
    checkColumn(column);
    Type type = resultMetaData.columnTypes[--column];
    return type.getNameString();
}
Also used : CharacterType(org.hsqldb_voltpatches.types.CharacterType) Type(org.hsqldb_voltpatches.types.Type)

Example 43 with Type

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

the class ParserDDL method compileAlterColumn.

Statement compileAlterColumn(Table table, ColumnSchema column, int columnIndex) {
    int position = getPosition();
    switch(token.tokenType) {
        case Tokens.RENAME:
            {
                read();
                readThis(Tokens.TO);
                return compileAlterColumnRename(table, column);
            }
        case Tokens.DROP:
            {
                read();
                if (token.tokenType == Tokens.DEFAULT) {
                    read();
                    return compileAlterColumnDropDefault(table, column, columnIndex);
                } else if (token.tokenType == Tokens.GENERATED) {
                    read();
                    return compileAlterColumnDropGenerated(table, column, columnIndex);
                } else {
                    throw unexpectedToken();
                }
            }
        case Tokens.SET:
            {
                read();
                switch(token.tokenType) {
                    case Tokens.DATA:
                        {
                            read();
                            readThis(Tokens.TYPE);
                            return compileAlterColumnDataType(table, column);
                        }
                    case Tokens.DEFAULT:
                        {
                            read();
                            //ALTER TABLE .. ALTER COLUMN .. SET DEFAULT
                            Type type = column.getDataType();
                            Expression expr = this.readDefaultClause(type);
                            return compileAlterColumnSetDefault(table, column, expr);
                        }
                    case Tokens.NOT:
                        {
                            //ALTER TABLE .. ALTER COLUMN .. SET NOT NULL
                            read();
                            readThis(Tokens.NULL);
                            return compileAlterColumnSetNullability(table, column, false);
                        }
                    case Tokens.NULL:
                        {
                            read();
                            return compileAlterColumnSetNullability(table, column, true);
                        }
                    default:
                        rewind(position);
                        read();
                        break;
                }
            }
        // $FALL-THROUGH$
        default:
    }
    if (token.tokenType == Tokens.SET || token.tokenType == Tokens.RESTART) {
        if (!column.isIdentity()) {
            throw Error.error(ErrorCode.X_42535);
        }
        return compileAlterColumnSequenceOptions(column);
    } else {
        return compileAlterColumnType(table, column);
    }
}
Also used : Type(org.hsqldb_voltpatches.types.Type)

Example 44 with Type

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

the class ParserDDL method compileAlterDomain.

Statement compileAlterDomain() {
    HsqlName schema = session.getSchemaHsqlName(token.namePrefix);
    Type domain = database.schemaManager.getDomain(token.tokenString, schema.name, true);
    read();
    switch(token.tokenType) {
        case Tokens.RENAME:
            {
                read();
                readThis(Tokens.TO);
                return compileRenameObject(domain.getName(), SchemaObject.DOMAIN);
            }
        case Tokens.DROP:
            {
                read();
                if (token.tokenType == Tokens.DEFAULT) {
                    read();
                    return compileAlterDomainDropDefault(domain);
                } else if (token.tokenType == Tokens.CONSTRAINT) {
                    read();
                    checkIsSchemaObjectName();
                    HsqlName name = database.schemaManager.getSchemaObjectName(domain.getSchemaName(), token.tokenString, SchemaObject.CONSTRAINT, true);
                    read();
                    return compileAlterDomainDropConstraint(domain, name);
                } else {
                    throw unexpectedToken();
                }
            }
        case Tokens.SET:
            {
                read();
                readThis(Tokens.DEFAULT);
                Expression e = readDefaultClause(domain);
                return compileAlterDomainSetDefault(domain, e);
            }
        case Tokens.ADD:
            {
                read();
                if (token.tokenType == Tokens.CONSTRAINT || token.tokenType == Tokens.CHECK) {
                    HsqlArrayList tempConstraints = new HsqlArrayList();
                    readConstraint(domain, tempConstraints);
                    Constraint c = (Constraint) tempConstraints.get(0);
                    return compileAlterDomainAddConstraint(domain, c);
                }
            }
    }
    throw unexpectedToken();
}
Also used : Type(org.hsqldb_voltpatches.types.Type) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 45 with Type

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

the class ParserDDL method readColumnDefinitionOrNull.

/**
     * Responsible for handling the creation of table columns during the process
     * of executing CREATE TABLE or ADD COLUMN etc. statements.
     *
     * @param table this table
     * @param hsqlName column name
     * @param constraintList list of constraints
     * @return a Column object with indicated attributes
     */
ColumnSchema readColumnDefinitionOrNull(Table table, HsqlName hsqlName, HsqlArrayList constraintList) {
    boolean isIdentity = false;
    boolean isPKIdentity = false;
    boolean identityAlways = false;
    Expression generateExpr = null;
    boolean isNullable = true;
    Expression defaultExpr = null;
    Type typeObject;
    NumberSequence sequence = null;
    if (token.tokenType == Tokens.IDENTITY) {
        read();
        isIdentity = true;
        isPKIdentity = true;
        typeObject = Type.SQL_INTEGER;
        sequence = new NumberSequence(null, 0, 1, typeObject);
    } else if (token.tokenType == Tokens.COMMA) {
        ;
        return null;
    } else {
        typeObject = readTypeDefinition(true);
    }
    if (isIdentity) {
    } else if (token.tokenType == Tokens.DEFAULT) {
        read();
        defaultExpr = readDefaultClause(typeObject);
    } else if (token.tokenType == Tokens.GENERATED && !isIdentity) {
        read();
        if (token.tokenType == Tokens.BY) {
            read();
            readThis(Tokens.DEFAULT);
        } else {
            readThis(Tokens.ALWAYS);
            identityAlways = true;
        }
        readThis(Tokens.AS);
        if (token.tokenType == Tokens.IDENTITY) {
            read();
            sequence = new NumberSequence(null, typeObject);
            sequence.setAlways(identityAlways);
            if (token.tokenType == Tokens.OPENBRACKET) {
                read();
                readSequenceOptions(sequence, false, false);
                readThis(Tokens.CLOSEBRACKET);
            }
            isIdentity = true;
        } else if (token.tokenType == Tokens.OPENBRACKET) {
            read();
            generateExpr = XreadValueExpression();
            readThis(Tokens.CLOSEBRACKET);
        }
    }
    ColumnSchema column = new ColumnSchema(hsqlName, typeObject, isNullable, false, defaultExpr);
    readColumnConstraints(table, column, constraintList);
    if (token.tokenType == Tokens.IDENTITY && !isIdentity) {
        read();
        isIdentity = true;
        isPKIdentity = true;
        sequence = new NumberSequence(null, 0, 1, typeObject);
    }
    if (isIdentity) {
        column.setIdentity(sequence);
    }
    if (isPKIdentity && !column.isPrimaryKey()) {
        OrderedHashSet set = new OrderedHashSet();
        set.add(column.getName().name);
        HsqlName constName = database.nameManager.newAutoName("PK", table.getSchemaName(), table.getName(), SchemaObject.CONSTRAINT);
        Constraint c = new Constraint(constName, true, set, Constraint.PRIMARY_KEY);
        constraintList.set(0, c);
        column.setPrimaryKey(true);
    }
    return column;
}
Also used : Type(org.hsqldb_voltpatches.types.Type) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

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