/** * If a type is an identity type, some dialects require the relevant * keywords after the [ NOT ] NULL constraint. */ static final void toSQLDDLTypeDeclarationIdentityAfterNull(Context<?> ctx, DataType<?> type) { if (type.identity()) { // [#5062] H2's (and others') AUTO_INCREMENT flag is syntactically located *after* NULL flags. switch (ctx.family()) { case H2: case MARIADB: case MYSQL: ctx.sql(' ').visit(K_AUTO_INCREMENT); break; } } }
/** * Defaults fields that have a default value and are nullable. * @param record the record * @return the record */ private Record setDefault(Record record) { int size = record.size(); for (int i = 0; i < size; i++) if (record.get(i) == null) { @SuppressWarnings("unchecked") Field<Object> field = (Field<Object>) record.field(i); if (!field.getDataType().nullable() && !field.getDataType().identity()) record.set(field, DSL.defaultValue()); } return record; }
/** * Defaults fields that have a default value and are nullable. * @param record the record * @return the record */ private Record setDefault(Record record) { int size = record.size(); for (int i = 0; i < size; i++) if (record.get(i) == null) { @SuppressWarnings("unchecked") Field<Object> field = (Field<Object>) record.field(i); if (!field.getDataType().nullable() && !field.getDataType().identity()) record.set(field, DSL.defaultValue()); } return record; }
public DataType<?> getDataType(DSLContext dsl) { override(dsl); DataType<?> result = DefaultDataType.getDataType(SQLDialect.DEFAULT, type); if (result.isNumeric() && !result.hasScale()) { result = result.identity(pk); } if (length >= 0) { result = result.length(length); } if (precision >= 0) { result = result.precision(precision); } if (scale >= 0) { result = result.scale(scale); } result = result.nullable(nullable); return result; }
/** * If a type is an identity type, some dialects require the relevant * keywords before the [ NOT ] NULL constraint. */ static final void toSQLDDLTypeDeclarationIdentityBeforeNull(Context<?> ctx, DataType<?> type) { if (type.identity()) { switch (ctx.family()) { case CUBRID: ctx.sql(' ').visit(K_AUTO_INCREMENT); break; case DERBY: ctx.sql(' ').visit(K_GENERATED_BY_DEFAULT_AS_IDENTITY); break; case HSQLDB: ctx.sql(' ').visit(K_GENERATED_BY_DEFAULT_AS_IDENTITY).sql('(').visit(K_START_WITH).sql(" 1)"); break; case SQLITE: ctx.sql(' ').visit(K_PRIMARY_KEY).sql(' ').visit(K_AUTOINCREMENT); break; } } }
if (identity == null && type.identity()) identity = columnFields.get(i);
public ColumnDefinition(Field<?> field) { DataType<?> dataType = field.getDataType(); setPk(dataType.identity()); DataType<?> defaultType = dataType.getSQLDataType(); if (defaultType == null) { defaultType = DefaultDataType.getDefaultDataType(dataType.getTypeName()); } setType(defaultType.getTypeName()); if (dataType.hasLength()) { setLength(dataType.length()); } if (dataType.hasPrecision()) { setPrecision(dataType.precision()); } if (dataType.hasScale()) { setScale(dataType.scale()); } setNullable(dataType.nullable()); }
boolean onUpdate = false; boolean unique = false; boolean identity = type.identity(); boolean comment = false; type = type.identity(true); defaultValue = true; identity = true; type = type.identity(true); defaultValue = true; identity = true; if (parseKeywordIf(ctx, "AUTO_INCREMENT") || parseKeywordIf(ctx, "AUTOINCREMENT")) { type = type.identity(true); identity = true; continue;
return parseUnsigned(ctx, parseAndIgnoreDataTypeLength(ctx, SQLDataType.BIGINT)); else if (parseKeywordOrIdentifierIf(ctx, "BIGSERIAL")) return SQLDataType.BIGINT.identity(true); else if (parseKeywordOrIdentifierIf(ctx, "BINARY")) return parseDataTypeLength(ctx, SQLDataType.BINARY); if (parseKeywordOrIdentifierIf(ctx, "SERIAL4") || parseKeywordOrIdentifierIf(ctx, "SERIAL")) return SQLDataType.INTEGER.identity(true); else if (parseKeywordOrIdentifierIf(ctx, "SERIAL8")) return SQLDataType.BIGINT.identity(true); else if (parseKeywordOrIdentifierIf(ctx, "SET")) return parseDataTypeCollation(ctx, parseDataTypeEnum(ctx)); else if (parseKeywordOrIdentifierIf(ctx, "SMALLSERIAL") || parseKeywordOrIdentifierIf(ctx, "SERIAL2")) return SQLDataType.SMALLINT.identity(true);