Search in sources :

Example 1 with Charset

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

the class DatabaseInformationFull method CHARACTER_SETS.

Table CHARACTER_SETS() {
    Table t = sysTables[CHARACTER_SETS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[CHARACTER_SETS]);
        addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
        addColumn(t, "CHARACTER_REPERTOIRE", SQL_IDENTIFIER);
        addColumn(t, "FORM_OF_USE", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_SCHEMA", SQL_IDENTIFIER);
        addColumn(t, "DEFAULT_COLLATE_NAME", SQL_IDENTIFIER);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[CHARACTER_SETS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0, 1, 2 }, false);
        return t;
    }
    final int character_set_catalog = 0;
    final int character_set_schema = 1;
    final int character_set_name = 2;
    final int character_repertoire = 3;
    final int form_of_use = 4;
    final int default_collate_catalog = 5;
    final int default_collate_schema = 6;
    final int default_collate_name = 7;
    //
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.CHARSET);
    while (it.hasNext()) {
        Charset charset = (Charset) it.next();
        if (!session.getGrantee().isAccessible(charset)) {
            continue;
        }
        Object[] data = t.getEmptyRowData();
        data[character_set_catalog] = database.getCatalogName().name;
        data[character_set_schema] = charset.getSchemaName().name;
        data[character_set_name] = charset.getName().name;
        data[character_repertoire] = "UCS";
        data[form_of_use] = "UTF16";
        data[default_collate_catalog] = data[character_set_catalog];
        if (charset.base == null) {
            data[default_collate_schema] = data[character_set_schema];
            data[default_collate_name] = data[character_set_name];
        } else {
            data[default_collate_schema] = charset.base.schema.name;
            data[default_collate_name] = charset.base.name;
        }
        t.insertSys(store, data);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) TextTable(org.hsqldb_voltpatches.TextTable) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Charset(org.hsqldb_voltpatches.types.Charset) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 2 with Charset

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

the class ParserDQL method readTypeDefinition.

Type readTypeDefinition(boolean includeUserTypes) {
    int typeNumber = Integer.MIN_VALUE;
    checkIsIdentifier();
    if (token.namePrefix == null) {
        typeNumber = Type.getTypeNr(token.tokenString);
    }
    if (typeNumber == Integer.MIN_VALUE) {
        if (includeUserTypes) {
            checkIsSchemaObjectName();
            String schemaName = session.getSchemaName(token.namePrefix);
            Type type = database.schemaManager.getDomain(token.tokenString, schemaName, false);
            if (type != null) {
                read();
                return type;
            }
        }
        throw Error.error(ErrorCode.X_42509, token.tokenString);
    }
    read();
    switch(typeNumber) {
        case Types.SQL_CHAR:
            if (token.tokenType == Tokens.VARYING) {
                read();
                typeNumber = Types.SQL_VARCHAR;
            } else if (token.tokenType == Tokens.LARGE) {
                readThis(Tokens.OBJECT);
                read();
                typeNumber = Types.SQL_CLOB;
            }
            break;
        case Types.SQL_DOUBLE:
            if (token.tokenType == Tokens.PRECISION) {
                read();
            }
            break;
        case Types.SQL_BINARY:
            if (token.tokenType == Tokens.VARYING) {
                read();
                typeNumber = Types.SQL_VARBINARY;
            } else if (token.tokenType == Tokens.LARGE) {
                readThis(Tokens.OBJECT);
                read();
                typeNumber = Types.SQL_BLOB;
            }
            break;
        case Types.SQL_BIT:
            if (token.tokenType == Tokens.VARYING) {
                read();
                typeNumber = Types.SQL_BIT_VARYING;
            }
            break;
        case Types.SQL_INTERVAL:
            return readIntervalType();
        default:
    }
    long length = typeNumber == Types.SQL_TIMESTAMP ? DTIType.defaultTimestampFractionPrecision : 0;
    int scale = 0;
    if (Types.requiresPrecision(typeNumber) && token.tokenType != Tokens.OPENBRACKET && database.sqlEnforceStrictSize) {
        throw unexpectedTokenRequire(Tokens.T_OPENBRACKET);
    }
    // A VoltDB extension to support the character in bytes.
    boolean inBytes = false;
    // End of VoltDB extension
    if (Types.acceptsPrecision(typeNumber)) {
        if (token.tokenType == Tokens.OPENBRACKET) {
            int multiplier = 1;
            read();
            switch(token.tokenType) {
                case Tokens.X_VALUE:
                    if (token.dataType.typeCode != Types.SQL_INTEGER && token.dataType.typeCode != Types.SQL_BIGINT) {
                        throw unexpectedToken();
                    }
                    break;
                case Tokens.X_LOB_SIZE:
                    if (typeNumber == Types.SQL_BLOB || typeNumber == Types.SQL_CLOB) {
                        switch(token.lobMultiplierType) {
                            case Tokens.K:
                                multiplier = 1024;
                                break;
                            case Tokens.M:
                                multiplier = 1024 * 1024;
                                break;
                            case Tokens.G:
                                multiplier = 1024 * 1024 * 1024;
                                break;
                            case Tokens.P:
                            case Tokens.T:
                            default:
                                throw unexpectedToken();
                        }
                        break;
                    } else {
                        throw unexpectedToken(token.getFullString());
                    }
                default:
                    throw unexpectedToken();
            }
            length = ((Number) token.tokenValue).longValue();
            if (length < 0 || (length == 0 && !Types.acceptsZeroPrecision(typeNumber))) {
                throw Error.error(ErrorCode.X_42592);
            }
            length *= multiplier;
            read();
            if (typeNumber == Types.SQL_CHAR || typeNumber == Types.SQL_VARCHAR || typeNumber == Types.SQL_CLOB) {
                if (token.tokenType == Tokens.CHARACTERS) {
                    read();
                } else if (token.tokenType == Tokens.OCTETS) {
                    read();
                    length /= 2;
                }
            }
            if (Types.acceptsScaleCreateParam(typeNumber) && token.tokenType == Tokens.COMMA) {
                read();
                scale = readInteger();
                if (scale < 0) {
                    throw Error.error(ErrorCode.X_42592);
                }
            }
            // A VoltDB extension to support the character in bytes.
            if (typeNumber == Types.SQL_VARCHAR) {
                inBytes = readIfThis(Tokens.BYTES);
            }
            // End of VoltDB extension
            readThis(Tokens.CLOSEBRACKET);
        } else if (typeNumber == Types.SQL_BIT) {
            length = 1;
        } else if (typeNumber == Types.SQL_BLOB || typeNumber == Types.SQL_CLOB) {
            length = BlobType.defaultBlobSize;
        } else if (database.sqlEnforceStrictSize) {
            // BIT is always BIT(1), regardless of sqlEnforceStringSize
            if (typeNumber == Types.SQL_CHAR || typeNumber == Types.SQL_BINARY) {
                length = 1;
            }
        }
        if (typeNumber == Types.SQL_TIMESTAMP || typeNumber == Types.SQL_TIME) {
            if (length > DTIType.maxFractionPrecision) {
                throw Error.error(ErrorCode.X_42592);
            }
            scale = (int) length;
            length = 0;
            if (token.tokenType == Tokens.WITH) {
                read();
                readThis(Tokens.TIME);
                readThis(Tokens.ZONE);
                if (typeNumber == Types.SQL_TIMESTAMP) {
                    typeNumber = Types.SQL_TIMESTAMP_WITH_TIME_ZONE;
                } else {
                    typeNumber = Types.SQL_TIME_WITH_TIME_ZONE;
                }
            } else if (token.tokenType == Tokens.WITHOUT) {
                read();
                readThis(Tokens.TIME);
                readThis(Tokens.ZONE);
            }
        }
    }
    Type typeObject = Type.getType(typeNumber, 0, length, scale);
    if (typeObject.isCharacterType()) {
        // A VoltDB extension to support the character in bytes.
        if (inBytes) {
            ((CharacterType) typeObject).inBytes = true;
        }
        // End of VoltDB extension
        if (token.tokenType == Tokens.CHARACTER) {
            read();
            readThis(Tokens.SET);
            checkIsSchemaObjectName();
            String schemaName = session.getSchemaName(token.namePrefix);
            Charset charset = (Charset) database.schemaManager.getSchemaObject(token.tokenString, schemaName, SchemaObject.CHARSET);
            read();
        }
    }
    return typeObject;
}
Also used : IntervalType(org.hsqldb_voltpatches.types.IntervalType) DTIType(org.hsqldb_voltpatches.types.DTIType) Type(org.hsqldb_voltpatches.types.Type) CharacterType(org.hsqldb_voltpatches.types.CharacterType) BlobType(org.hsqldb_voltpatches.types.BlobType) Charset(org.hsqldb_voltpatches.types.Charset)

Example 3 with Charset

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

the class ParserDDL method compileCreateCharacterSet.

StatementSchema compileCreateCharacterSet() {
    read();
    readThis(Tokens.SET);
    HsqlName name = readNewSchemaObjectNameNoCheck(SchemaObject.CHARSET);
    readIfThis(Tokens.AS);
    readThis(Tokens.GET);
    String schema = session.getSchemaName(token.namePrefix);
    Charset source = (Charset) database.schemaManager.getSchemaObject(token.tokenString, schema, SchemaObject.CHARSET);
    read();
    if (token.tokenType == Tokens.COLLATION) {
        read();
        readThis(Tokens.FROM);
        readThis(Tokens.DEFAULT);
    }
    Charset charset = new Charset(name);
    charset.base = source.getName();
    String sql = getLastPart();
    Object[] args = new Object[] { charset };
    return new StatementSchema(sql, StatementTypes.CREATE_CHARACTER_SET, args, null, null);
}
Also used : Charset(org.hsqldb_voltpatches.types.Charset) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Aggregations

Charset (org.hsqldb_voltpatches.types.Charset)3 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)2 Constraint (org.hsqldb_voltpatches.Constraint)1 SchemaObject (org.hsqldb_voltpatches.SchemaObject)1 Table (org.hsqldb_voltpatches.Table)1 TextTable (org.hsqldb_voltpatches.TextTable)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)1 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)1 BlobType (org.hsqldb_voltpatches.types.BlobType)1 CharacterType (org.hsqldb_voltpatches.types.CharacterType)1 DTIType (org.hsqldb_voltpatches.types.DTIType)1 IntervalType (org.hsqldb_voltpatches.types.IntervalType)1 Type (org.hsqldb_voltpatches.types.Type)1