Search in sources :

Example 1 with DataType

use of org.h2.mvstore.type.DataType in project h2database by h2database.

the class Parser method parseCreate.

private Prepared parseCreate() {
    boolean orReplace = false;
    if (readIf("OR")) {
        read("REPLACE");
        orReplace = true;
    }
    boolean force = readIf("FORCE");
    if (readIf("VIEW")) {
        return parseCreateView(force, orReplace);
    } else if (readIf("ALIAS")) {
        return parseCreateFunctionAlias(force);
    } else if (readIf("SEQUENCE")) {
        return parseCreateSequence();
    } else if (readIf("USER")) {
        return parseCreateUser();
    } else if (readIf("TRIGGER")) {
        return parseCreateTrigger(force);
    } else if (readIf("ROLE")) {
        return parseCreateRole();
    } else if (readIf("SCHEMA")) {
        return parseCreateSchema();
    } else if (readIf("CONSTANT")) {
        return parseCreateConstant();
    } else if (readIf("DOMAIN")) {
        return parseCreateUserDataType();
    } else if (readIf("TYPE")) {
        return parseCreateUserDataType();
    } else if (readIf("DATATYPE")) {
        return parseCreateUserDataType();
    } else if (readIf("AGGREGATE")) {
        return parseCreateAggregate(force);
    } else if (readIf("LINKED")) {
        return parseCreateLinkedTable(false, false, force);
    }
    // tables or linked tables
    boolean memory = false, cached = false;
    if (readIf("MEMORY")) {
        memory = true;
    } else if (readIf("CACHED")) {
        cached = true;
    }
    if (readIf("LOCAL")) {
        read("TEMPORARY");
        if (readIf("LINKED")) {
            return parseCreateLinkedTable(true, false, force);
        }
        read("TABLE");
        return parseCreateTable(true, false, cached);
    } else if (readIf("GLOBAL")) {
        read("TEMPORARY");
        if (readIf("LINKED")) {
            return parseCreateLinkedTable(true, true, force);
        }
        read("TABLE");
        return parseCreateTable(true, true, cached);
    } else if (readIf("TEMP") || readIf("TEMPORARY")) {
        if (readIf("LINKED")) {
            return parseCreateLinkedTable(true, true, force);
        }
        read("TABLE");
        return parseCreateTable(true, true, cached);
    } else if (readIf("TABLE")) {
        if (!cached && !memory) {
            cached = database.getDefaultTableType() == Table.TYPE_CACHED;
        }
        return parseCreateTable(false, false, cached);
    } else if (readIf("SYNONYM")) {
        return parseCreateSynonym(orReplace);
    } else {
        boolean hash = false, primaryKey = false;
        boolean unique = false, spatial = false;
        String indexName = null;
        Schema oldSchema = null;
        boolean ifNotExists = false;
        if (readIf("PRIMARY")) {
            read("KEY");
            if (readIf("HASH")) {
                hash = true;
            }
            primaryKey = true;
            if (!isToken("ON")) {
                ifNotExists = readIfNotExists();
                indexName = readIdentifierWithSchema(null);
                oldSchema = getSchema();
            }
        } else {
            if (readIf("UNIQUE")) {
                unique = true;
            }
            if (readIf("HASH")) {
                hash = true;
            }
            if (readIf("SPATIAL")) {
                spatial = true;
            }
            if (readIf("INDEX")) {
                if (!isToken("ON")) {
                    ifNotExists = readIfNotExists();
                    indexName = readIdentifierWithSchema(null);
                    oldSchema = getSchema();
                }
            } else {
                throw getSyntaxError();
            }
        }
        read("ON");
        String tableName = readIdentifierWithSchema();
        checkSchema(oldSchema);
        CreateIndex command = new CreateIndex(session, getSchema());
        command.setIfNotExists(ifNotExists);
        command.setPrimaryKey(primaryKey);
        command.setTableName(tableName);
        command.setUnique(unique);
        command.setIndexName(indexName);
        command.setComment(readCommentIf());
        read("(");
        command.setIndexColumns(parseIndexColumnList());
        if (readIf("USING")) {
            if (hash) {
                throw getSyntaxError();
            }
            if (spatial) {
                throw getSyntaxError();
            }
            if (readIf("BTREE")) {
            // default
            } else if (readIf("RTREE")) {
                spatial = true;
            } else if (readIf("HASH")) {
                hash = true;
            } else {
                throw getSyntaxError();
            }
        }
        command.setHash(hash);
        command.setSpatial(spatial);
        return command;
    }
}
Also used : CreateIndex(org.h2.command.ddl.CreateIndex) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) ValueString(org.h2.value.ValueString)

Example 2 with DataType

use of org.h2.mvstore.type.DataType in project h2database by h2database.

the class Parser method parseColumnWithType.

private Column parseColumnWithType(String columnName) {
    String original = currentToken;
    boolean regular = false;
    int originalScale = -1;
    if (readIf("LONG")) {
        if (readIf("RAW")) {
            original += " RAW";
        }
    } else if (readIf("DOUBLE")) {
        if (readIf("PRECISION")) {
            original += " PRECISION";
        }
    } else if (readIf("CHARACTER")) {
        if (readIf("VARYING")) {
            original += " VARYING";
        }
    } else if (readIf("TIME")) {
        if (readIf("(")) {
            originalScale = readPositiveInt();
            if (originalScale > ValueTime.MAXIMUM_SCALE) {
                throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(originalScale));
            }
            read(")");
        }
        if (readIf("WITHOUT")) {
            read("TIME");
            read("ZONE");
            original += " WITHOUT TIME ZONE";
        }
    } else if (readIf("TIMESTAMP")) {
        if (readIf("(")) {
            originalScale = readPositiveInt();
            // Allow non-standard TIMESTAMP(..., ...) syntax
            if (readIf(",")) {
                originalScale = readPositiveInt();
            }
            if (originalScale > ValueTimestamp.MAXIMUM_SCALE) {
                throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(originalScale));
            }
            read(")");
        }
        if (readIf("WITH")) {
            read("TIME");
            read("ZONE");
            original += " WITH TIME ZONE";
        } else if (readIf("WITHOUT")) {
            read("TIME");
            read("ZONE");
            original += " WITHOUT TIME ZONE";
        }
    } else {
        regular = true;
    }
    long precision = -1;
    int displaySize = -1;
    String[] enumerators = null;
    int scale = -1;
    String comment = null;
    Column templateColumn = null;
    DataType dataType;
    if (!identifiersToUpper) {
        original = StringUtils.toUpperEnglish(original);
    }
    UserDataType userDataType = database.findUserDataType(original);
    if (userDataType != null) {
        templateColumn = userDataType.getColumn();
        dataType = DataType.getDataType(templateColumn.getType());
        comment = templateColumn.getComment();
        original = templateColumn.getOriginalSQL();
        precision = templateColumn.getPrecision();
        displaySize = templateColumn.getDisplaySize();
        scale = templateColumn.getScale();
        enumerators = templateColumn.getEnumerators();
    } else {
        Mode mode = database.getMode();
        dataType = DataType.getTypeByName(original, mode);
        if (dataType == null || mode.disallowedTypes.contains(original)) {
            throw DbException.get(ErrorCode.UNKNOWN_DATA_TYPE_1, currentToken);
        }
    }
    if (database.getIgnoreCase() && dataType.type == Value.STRING && !equalsToken("VARCHAR_CASESENSITIVE", original)) {
        original = "VARCHAR_IGNORECASE";
        dataType = DataType.getTypeByName(original, database.getMode());
    }
    if (regular) {
        read();
    }
    precision = precision == -1 ? dataType.defaultPrecision : precision;
    displaySize = displaySize == -1 ? dataType.defaultDisplaySize : displaySize;
    scale = scale == -1 ? dataType.defaultScale : scale;
    if (dataType.supportsPrecision || dataType.supportsScale) {
        int t = dataType.type;
        if (t == Value.TIME || t == Value.TIMESTAMP || t == Value.TIMESTAMP_TZ) {
            if (originalScale >= 0) {
                scale = originalScale;
                switch(t) {
                    case Value.TIME:
                        if (original.equals("TIME WITHOUT TIME ZONE")) {
                            original = "TIME(" + originalScale + ") WITHOUT TIME ZONE";
                        } else {
                            original = original + '(' + originalScale + ')';
                        }
                        precision = displaySize = ValueTime.getDisplaySize(originalScale);
                        break;
                    case Value.TIMESTAMP:
                        if (original.equals("TIMESTAMP WITHOUT TIME ZONE")) {
                            original = "TIMESTAMP(" + originalScale + ") WITHOUT TIME ZONE";
                        } else {
                            original = original + '(' + originalScale + ')';
                        }
                        precision = displaySize = ValueTimestamp.getDisplaySize(originalScale);
                        break;
                    case Value.TIMESTAMP_TZ:
                        original = "TIMESTAMP(" + originalScale + ") WITH TIME ZONE";
                        precision = displaySize = ValueTimestampTimeZone.getDisplaySize(originalScale);
                        break;
                }
            }
        } else if (readIf("(")) {
            if (!readIf("MAX")) {
                long p = readLong();
                if (readIf("K")) {
                    p *= 1024;
                } else if (readIf("M")) {
                    p *= 1024 * 1024;
                } else if (readIf("G")) {
                    p *= 1024 * 1024 * 1024;
                }
                if (p > Long.MAX_VALUE) {
                    p = Long.MAX_VALUE;
                }
                original += "(" + p;
                // Oracle syntax
                if (!readIf("CHAR")) {
                    readIf("BYTE");
                }
                if (dataType.supportsScale) {
                    if (readIf(",")) {
                        scale = readInt();
                        original += ", " + scale;
                    } else {
                        scale = 0;
                    }
                }
                precision = p;
                displaySize = MathUtils.convertLongToInt(precision);
                original += ")";
            }
            read(")");
        }
    } else if (dataType.type == Value.DOUBLE && original.equals("FLOAT")) {
        if (readIf("(")) {
            int p = readPositiveInt();
            read(")");
            if (p > 53) {
                throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(p));
            }
            if (p <= 24) {
                dataType = DataType.getDataType(Value.FLOAT);
            }
            original = original + '(' + p + ')';
        }
    } else if (dataType.type == Value.ENUM) {
        if (readIf("(")) {
            java.util.List<String> enumeratorList = new ArrayList<>();
            original += '(';
            String enumerator0 = readString();
            enumeratorList.add(enumerator0);
            original += "'" + enumerator0 + "'";
            while (readIfMore(true)) {
                original += ',';
                String enumeratorN = readString();
                original += "'" + enumeratorN + "'";
                enumeratorList.add(enumeratorN);
            }
            original += ')';
            enumerators = enumeratorList.toArray(new String[0]);
        }
        try {
            ValueEnum.check(enumerators);
        } catch (DbException e) {
            throw e.addSQL(original);
        }
    } else if (readIf("(")) {
        // Support for MySQL: INT(11), MEDIUMINT(8) and so on.
        // Just ignore the precision.
        readPositiveInt();
        read(")");
    }
    if (readIf("FOR")) {
        read("BIT");
        read("DATA");
        if (dataType.type == Value.STRING) {
            dataType = DataType.getTypeByName("BINARY", database.getMode());
        }
    }
    // MySQL compatibility
    readIf("UNSIGNED");
    int type = dataType.type;
    if (scale > precision) {
        throw DbException.get(ErrorCode.INVALID_VALUE_SCALE_PRECISION, Integer.toString(scale), Long.toString(precision));
    }
    Column column = new Column(columnName, type, precision, scale, displaySize, enumerators);
    if (templateColumn != null) {
        column.setNullable(templateColumn.isNullable());
        column.setDefaultExpression(session, templateColumn.getDefaultExpression());
        int selectivity = templateColumn.getSelectivity();
        if (selectivity != Constants.SELECTIVITY_DEFAULT) {
            column.setSelectivity(selectivity);
        }
        Expression checkConstraint = templateColumn.getCheckConstraint(session, columnName);
        column.addCheckConstraint(session, checkConstraint);
    }
    column.setComment(comment);
    column.setOriginalSQL(original);
    return column;
}
Also used : CreateUserDataType(org.h2.command.ddl.CreateUserDataType) DropUserDataType(org.h2.command.ddl.DropUserDataType) UserDataType(org.h2.engine.UserDataType) Mode(org.h2.engine.Mode) CompareMode(org.h2.value.CompareMode) ArrayList(java.util.ArrayList) ValueString(org.h2.value.ValueString) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint) DbException(org.h2.message.DbException) AlterTableRenameColumn(org.h2.command.ddl.AlterTableRenameColumn) AlterTableAlterColumn(org.h2.command.ddl.AlterTableAlterColumn) Column(org.h2.table.Column) ExpressionColumn(org.h2.expression.ExpressionColumn) IndexColumn(org.h2.table.IndexColumn) Expression(org.h2.expression.Expression) ValueExpression(org.h2.expression.ValueExpression) CreateUserDataType(org.h2.command.ddl.CreateUserDataType) DataType(org.h2.value.DataType) DropUserDataType(org.h2.command.ddl.DropUserDataType) UserDataType(org.h2.engine.UserDataType)

Example 3 with DataType

use of org.h2.mvstore.type.DataType in project h2database by h2database.

the class ScriptCommand method query.

@Override
public ResultInterface query(int maxrows) {
    session.getUser().checkAdmin();
    reset();
    Database db = session.getDatabase();
    if (schemaNames != null) {
        for (String schemaName : schemaNames) {
            Schema schema = db.findSchema(schemaName);
            if (schema == null) {
                throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName);
            }
        }
    }
    try {
        result = createResult();
        deleteStore();
        openOutput();
        if (out != null) {
            buffer = new byte[Constants.IO_BUFFER_SIZE];
        }
        if (settings) {
            for (Setting setting : db.getAllSettings()) {
                if (setting.getName().equals(SetTypes.getTypeName(SetTypes.CREATE_BUILD))) {
                    // (it is only set when creating the database)
                    continue;
                }
                add(setting.getCreateSQL(), false);
            }
        }
        if (out != null) {
            add("", true);
        }
        for (User user : db.getAllUsers()) {
            add(user.getCreateSQL(passwords), false);
        }
        for (Role role : db.getAllRoles()) {
            add(role.getCreateSQL(true), false);
        }
        for (Schema schema : db.getAllSchemas()) {
            if (excludeSchema(schema)) {
                continue;
            }
            add(schema.getCreateSQL(), false);
        }
        for (UserDataType datatype : db.getAllUserDataTypes()) {
            if (drop) {
                add(datatype.getDropSQL(), false);
            }
            add(datatype.getCreateSQL(), false);
        }
        for (SchemaObject obj : db.getAllSchemaObjects(DbObject.CONSTANT)) {
            if (excludeSchema(obj.getSchema())) {
                continue;
            }
            Constant constant = (Constant) obj;
            add(constant.getCreateSQL(), false);
        }
        final ArrayList<Table> tables = db.getAllTablesAndViews(false);
        // sort by id, so that views are after tables and views on views
        // after the base views
        Collections.sort(tables, new Comparator<Table>() {

            @Override
            public int compare(Table t1, Table t2) {
                return t1.getId() - t2.getId();
            }
        });
        // Generate the DROP XXX  ... IF EXISTS
        for (Table table : tables) {
            if (excludeSchema(table.getSchema())) {
                continue;
            }
            if (excludeTable(table)) {
                continue;
            }
            if (table.isHidden()) {
                continue;
            }
            table.lock(session, false, false);
            String sql = table.getCreateSQL();
            if (sql == null) {
                // null for metadata tables
                continue;
            }
            if (drop) {
                add(table.getDropSQL(), false);
            }
        }
        for (SchemaObject obj : db.getAllSchemaObjects(DbObject.FUNCTION_ALIAS)) {
            if (excludeSchema(obj.getSchema())) {
                continue;
            }
            if (drop) {
                add(obj.getDropSQL(), false);
            }
            add(obj.getCreateSQL(), false);
        }
        for (UserAggregate agg : db.getAllAggregates()) {
            if (drop) {
                add(agg.getDropSQL(), false);
            }
            add(agg.getCreateSQL(), false);
        }
        for (SchemaObject obj : db.getAllSchemaObjects(DbObject.SEQUENCE)) {
            if (excludeSchema(obj.getSchema())) {
                continue;
            }
            Sequence sequence = (Sequence) obj;
            if (drop) {
                add(sequence.getDropSQL(), false);
            }
            add(sequence.getCreateSQL(), false);
        }
        // Generate CREATE TABLE and INSERT...VALUES
        int count = 0;
        for (Table table : tables) {
            if (excludeSchema(table.getSchema())) {
                continue;
            }
            if (excludeTable(table)) {
                continue;
            }
            if (table.isHidden()) {
                continue;
            }
            table.lock(session, false, false);
            String createTableSql = table.getCreateSQL();
            if (createTableSql == null) {
                // null for metadata tables
                continue;
            }
            final TableType tableType = table.getTableType();
            add(createTableSql, false);
            final ArrayList<Constraint> constraints = table.getConstraints();
            if (constraints != null) {
                for (Constraint constraint : constraints) {
                    if (Constraint.Type.PRIMARY_KEY == constraint.getConstraintType()) {
                        add(constraint.getCreateSQLWithoutIndexes(), false);
                    }
                }
            }
            if (TableType.TABLE == tableType) {
                if (table.canGetRowCount()) {
                    String rowcount = "-- " + table.getRowCountApproximation() + " +/- SELECT COUNT(*) FROM " + table.getSQL();
                    add(rowcount, false);
                }
                if (data) {
                    count = generateInsertValues(count, table);
                }
            }
            final ArrayList<Index> indexes = table.getIndexes();
            for (int j = 0; indexes != null && j < indexes.size(); j++) {
                Index index = indexes.get(j);
                if (!index.getIndexType().getBelongsToConstraint()) {
                    add(index.getCreateSQL(), false);
                }
            }
        }
        if (tempLobTableCreated) {
            add("DROP TABLE IF EXISTS SYSTEM_LOB_STREAM", true);
            add("CALL SYSTEM_COMBINE_BLOB(-1)", true);
            add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_CLOB", true);
            add("DROP ALIAS IF EXISTS SYSTEM_COMBINE_BLOB", true);
            tempLobTableCreated = false;
        }
        // Generate CREATE CONSTRAINT ...
        final ArrayList<SchemaObject> constraints = db.getAllSchemaObjects(DbObject.CONSTRAINT);
        Collections.sort(constraints, new Comparator<SchemaObject>() {

            @Override
            public int compare(SchemaObject c1, SchemaObject c2) {
                return ((Constraint) c1).compareTo((Constraint) c2);
            }
        });
        for (SchemaObject obj : constraints) {
            if (excludeSchema(obj.getSchema())) {
                continue;
            }
            Constraint constraint = (Constraint) obj;
            if (excludeTable(constraint.getTable())) {
                continue;
            }
            if (constraint.getTable().isHidden()) {
                continue;
            }
            if (Constraint.Type.PRIMARY_KEY != constraint.getConstraintType()) {
                add(constraint.getCreateSQLWithoutIndexes(), false);
            }
        }
        // Generate CREATE TRIGGER ...
        for (SchemaObject obj : db.getAllSchemaObjects(DbObject.TRIGGER)) {
            if (excludeSchema(obj.getSchema())) {
                continue;
            }
            TriggerObject trigger = (TriggerObject) obj;
            if (excludeTable(trigger.getTable())) {
                continue;
            }
            add(trigger.getCreateSQL(), false);
        }
        // Generate GRANT ...
        for (Right right : db.getAllRights()) {
            DbObject object = right.getGrantedObject();
            if (object != null) {
                if (object instanceof Schema) {
                    if (excludeSchema((Schema) object)) {
                        continue;
                    }
                } else if (object instanceof Table) {
                    Table table = (Table) object;
                    if (excludeSchema(table.getSchema())) {
                        continue;
                    }
                    if (excludeTable(table)) {
                        continue;
                    }
                }
            }
            add(right.getCreateSQL(), false);
        }
        // Generate COMMENT ON ...
        for (Comment comment : db.getAllComments()) {
            add(comment.getCreateSQL(), false);
        }
        if (out != null) {
            out.close();
        }
    } catch (IOException e) {
        throw DbException.convertIOException(e, getFileName());
    } finally {
        closeIO();
    }
    result.done();
    LocalResult r = result;
    reset();
    return r;
}
Also used : SchemaObject(org.h2.schema.SchemaObject) User(org.h2.engine.User) Constraint(org.h2.constraint.Constraint) Constant(org.h2.schema.Constant) Schema(org.h2.schema.Schema) Right(org.h2.engine.Right) TriggerObject(org.h2.schema.TriggerObject) Index(org.h2.index.Index) ValueString(org.h2.value.ValueString) LocalResult(org.h2.result.LocalResult) Database(org.h2.engine.Database) Comment(org.h2.engine.Comment) Table(org.h2.table.Table) TableType(org.h2.table.TableType) DbObject(org.h2.engine.DbObject) Setting(org.h2.engine.Setting) UserDataType(org.h2.engine.UserDataType) Sequence(org.h2.schema.Sequence) IOException(java.io.IOException) Constraint(org.h2.constraint.Constraint) Role(org.h2.engine.Role) UserAggregate(org.h2.engine.UserAggregate)

Example 4 with DataType

use of org.h2.mvstore.type.DataType in project h2database by h2database.

the class Function method calculatePrecisionAndDisplaySize.

private void calculatePrecisionAndDisplaySize() {
    switch(info.type) {
        case ENCRYPT:
        case DECRYPT:
            precision = args[2].getPrecision();
            displaySize = args[2].getDisplaySize();
            break;
        case COMPRESS:
            precision = args[0].getPrecision();
            displaySize = args[0].getDisplaySize();
            break;
        case CHAR:
            precision = 1;
            displaySize = 1;
            break;
        case CONCAT:
            precision = 0;
            displaySize = 0;
            for (Expression e : args) {
                precision += e.getPrecision();
                displaySize = MathUtils.convertLongToInt((long) displaySize + e.getDisplaySize());
                if (precision < 0) {
                    precision = Long.MAX_VALUE;
                }
            }
            break;
        case HEXTORAW:
            precision = (args[0].getPrecision() + 3) / 4;
            displaySize = MathUtils.convertLongToInt(precision);
            break;
        case LCASE:
        case LTRIM:
        case RIGHT:
        case RTRIM:
        case UCASE:
        case LOWER:
        case UPPER:
        case TRIM:
        case STRINGDECODE:
        case UTF8TOSTRING:
        case TRUNCATE:
            precision = args[0].getPrecision();
            displaySize = args[0].getDisplaySize();
            break;
        case RAWTOHEX:
            precision = args[0].getPrecision() * 4;
            displaySize = MathUtils.convertLongToInt(precision);
            break;
        case SOUNDEX:
            precision = 4;
            displaySize = (int) precision;
            break;
        case DAY_NAME:
        case MONTH_NAME:
            // day and month names may be long in some languages
            precision = 20;
            displaySize = (int) precision;
            break;
        default:
            DataType type = DataType.getDataType(dataType);
            precision = type.defaultPrecision;
            displaySize = type.defaultDisplaySize;
    }
}
Also used : DataType(org.h2.value.DataType)

Example 5 with DataType

use of org.h2.mvstore.type.DataType in project h2database by h2database.

the class Function method getSQL.

@Override
public String getSQL() {
    StatementBuilder buff = new StatementBuilder(info.name);
    if (info.type == CASE) {
        if (args[0] != null) {
            buff.append(" ").append(args[0].getSQL());
        }
        for (int i = 1, len = args.length - 1; i < len; i += 2) {
            buff.append(" WHEN ").append(args[i].getSQL());
            buff.append(" THEN ").append(args[i + 1].getSQL());
        }
        if (args.length % 2 == 0) {
            buff.append(" ELSE ").append(args[args.length - 1].getSQL());
        }
        return buff.append(" END").toString();
    }
    buff.append('(');
    switch(info.type) {
        case CAST:
            {
                buff.append(args[0].getSQL()).append(" AS ").append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
                break;
            }
        case CONVERT:
            {
                if (database.getMode().swapConvertFunctionParameters) {
                    buff.append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()).append(',').append(args[0].getSQL());
                } else {
                    buff.append(args[0].getSQL()).append(',').append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
                }
                break;
            }
        case EXTRACT:
            {
                ValueString v = (ValueString) ((ValueExpression) args[0]).getValue(null);
                buff.append(v.getString()).append(" FROM ").append(args[1].getSQL());
                break;
            }
        default:
            {
                for (Expression e : args) {
                    buff.appendExceptFirst(", ");
                    buff.append(e.getSQL());
                }
            }
    }
    return buff.append(')').toString();
}
Also used : Column(org.h2.table.Column) StatementBuilder(org.h2.util.StatementBuilder) ValueString(org.h2.value.ValueString)

Aggregations

Value (org.h2.value.Value)16 ValueString (org.h2.value.ValueString)13 DataType (org.h2.value.DataType)12 Expression (org.h2.expression.Expression)6 Column (org.h2.table.Column)6 Constraint (org.h2.constraint.Constraint)5 UserDataType (org.h2.engine.UserDataType)5 UserAggregate (org.h2.engine.UserAggregate)4 Index (org.h2.index.Index)4 Table (org.h2.table.Table)4 ArrayList (java.util.ArrayList)3 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)3 Mode (org.h2.engine.Mode)3 ValueExpression (org.h2.expression.ValueExpression)3 SearchRow (org.h2.result.SearchRow)3 Schema (org.h2.schema.Schema)3 SimpleResultSet (org.h2.tools.SimpleResultSet)3 StatementBuilder (org.h2.util.StatementBuilder)3 CompareMode (org.h2.value.CompareMode)3 IOException (java.io.IOException)2