import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.MsSql;
import org.sonar.db.dialect.Oracle;
import static java.lang.String.format;
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case MsSql.ID:
- return format("NVARCHAR (%d)", columnSize);
- case Oracle.ID:
- return format("VARCHAR2 (%d%s)", columnSize, ignoreOracleUnit ? "" : " CHAR");
- default:
- return format("VARCHAR (%d)", columnSize);
+ if (dialect.getId().equals(Oracle.ID)) {
+ return format("VARCHAR2 (%d%s)", columnSize, ignoreOracleUnit ? "" : " CHAR");
}
+ return format("VARCHAR (%d)", columnSize);
}
public static class Builder {
assertThat(def.generateSqlType(new H2())).isEqualTo("VARCHAR (10)");
assertThat(def.generateSqlType(new PostgreSql())).isEqualTo("VARCHAR (10)");
- assertThat(def.generateSqlType(new MsSql())).isEqualTo("NVARCHAR (10)");
+ assertThat(def.generateSqlType(new MsSql())).isEqualTo("VARCHAR (10)");
assertThat(def.generateSqlType(new Oracle())).isEqualTo("VARCHAR2 (10 CHAR)");
}
@Test
public void add_columns_on_mssql() {
assertThat(createSampleBuilder(new MsSql()).build())
- .isEqualTo("ALTER TABLE issues ADD date_in_ms BIGINT NULL, name NVARCHAR (10) NOT NULL, col_with_default BIT DEFAULT 0 NOT NULL, varchar_col_with_default NVARCHAR (3) DEFAULT 'foo' NOT NULL");
+ .isEqualTo("ALTER TABLE issues ADD date_in_ms BIGINT NULL, name VARCHAR (10) NOT NULL, col_with_default BIT DEFAULT 0 NOT NULL, varchar_col_with_default VARCHAR (3) DEFAULT 'foo' NOT NULL");
}
@Test
assertThat(createSampleBuilder(new MsSql()).build())
.containsOnly(
"ALTER TABLE issues ALTER COLUMN value DECIMAL (30,20) NULL",
- "ALTER TABLE issues ALTER COLUMN name NVARCHAR (10) NULL");
+ "ALTER TABLE issues ALTER COLUMN name VARCHAR (10) NULL");
}
@Test
public void update_not_nullable_column_on_mssql() {
assertThat(createNotNullableBuilder(new MsSql()).build())
- .containsOnly("ALTER TABLE issues ALTER COLUMN name NVARCHAR (10) NOT NULL");
+ .containsOnly("ALTER TABLE issues ALTER COLUMN name VARCHAR (10) NOT NULL");
}
@Test
String selectInto = "SELECT rule_uuid INTO issues_copy FROM issues";
verifySql(new H2(), createTableAs, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
- verifySql(new MsSql(), selectInto, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid NVARCHAR (40) NOT NULL");
+ verifySql(new MsSql(), selectInto, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
verifySql(new Oracle(), createTableAs, "ALTER TABLE issues_copy MODIFY (rule_uuid VARCHAR2 (40 CHAR) NOT NULL)");
verifySql(new PostgreSql(), createTableAs, "ALTER TABLE issues_copy ALTER COLUMN rule_uuid TYPE VARCHAR (40), ALTER COLUMN rule_uuid SET NOT NULL");
}
public void create_table_with_cast() {
verifySqlWithCast(new H2(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR (40)) AS rule_uuid FROM issues)",
"ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
- verifySqlWithCast(new MsSql(), "SELECT CAST (rule_id AS NVARCHAR (40)) AS rule_uuid INTO issues_copy FROM issues",
- "ALTER TABLE issues_copy ALTER COLUMN rule_uuid NVARCHAR (40) NOT NULL");
+ verifySqlWithCast(new MsSql(), "SELECT CAST (rule_id AS VARCHAR (40)) AS rule_uuid INTO issues_copy FROM issues",
+ "ALTER TABLE issues_copy ALTER COLUMN rule_uuid VARCHAR (40) NOT NULL");
verifySqlWithCast(new Oracle(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR2 (40 CHAR)) AS rule_uuid FROM issues)",
"ALTER TABLE issues_copy MODIFY (rule_uuid VARCHAR2 (40 CHAR) NOT NULL)");
verifySqlWithCast(new PostgreSql(), "CREATE TABLE issues_copy (rule_uuid) AS (SELECT CAST (rule_id AS VARCHAR (40)) AS rule_uuid FROM issues)",
@Test
public void build_adds_DEFAULT_clause_on_varchar_column_on_MSSQL() {
- verifyDefaultClauseOnVarcharColumn(MS_SQL, "CREATE TABLE table_42 (status NVARCHAR (1) DEFAULT 'P' NOT NULL)");
+ verifyDefaultClauseOnVarcharColumn(MS_SQL, "CREATE TABLE table_42 (status VARCHAR (1) DEFAULT 'P' NOT NULL)");
}
@Test