diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-10-12 08:12:46 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-10-12 08:12:55 +0200 |
commit | 14518156f2b14eb64297b2b70998ae65b81dd11b (patch) | |
tree | 33c01c40e2c50956a18b385ec4548603d9733c2f /sonar-db | |
parent | e2744e0879cc6fbefb79aec2ff1d45cc776ae3e0 (diff) | |
download | sonarqube-14518156f2b14eb64297b2b70998ae65b81dd11b.tar.gz sonarqube-14518156f2b14eb64297b2b70998ae65b81dd11b.zip |
Replace VARCHAR by NVARCHAR on MsSQL
Diffstat (limited to 'sonar-db')
4 files changed, 9 insertions, 4 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/StringColumnDef.java b/sonar-db/src/main/java/org/sonar/db/version/StringColumnDef.java index 6753e856f0e..11dee2383ac 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/StringColumnDef.java +++ b/sonar-db/src/main/java/org/sonar/db/version/StringColumnDef.java @@ -22,7 +22,9 @@ package org.sonar.db.version; import javax.annotation.CheckForNull; import org.sonar.db.dialect.Dialect; +import org.sonar.db.dialect.MsSql; +import static java.lang.String.format; import static java.util.Objects.requireNonNull; import static org.sonar.db.version.ColumnDefValidation.validateColumnName; @@ -44,7 +46,10 @@ public class StringColumnDef extends AbstractColumnDef { @Override public String generateSqlType(Dialect dialect) { - return "VARCHAR (" + Integer.toString(columnSize) + ")"; + if (MsSql.ID.equals(dialect.getId())) { + return format("NVARCHAR (%d)", columnSize); + } + return format("VARCHAR (%d)", columnSize); } public static class Builder { diff --git a/sonar-db/src/test/java/org/sonar/db/version/AddColumnsBuilderTest.java b/sonar-db/src/test/java/org/sonar/db/version/AddColumnsBuilderTest.java index 7970db2afec..ed76c4e6173 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/AddColumnsBuilderTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/AddColumnsBuilderTest.java @@ -65,7 +65,7 @@ public class AddColumnsBuilderTest { @Test public void add_columns_on_mssql() { assertThat(createSampleBuilder(new MsSql()).build()) - .isEqualTo("ALTER TABLE issues ADD date_in_ms BIGINT NULL, name VARCHAR (10) NOT NULL"); + .isEqualTo("ALTER TABLE issues ADD date_in_ms BIGINT NULL, name NVARCHAR (10) NOT NULL"); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/version/AlterColumnsBuilderTest.java b/sonar-db/src/test/java/org/sonar/db/version/AlterColumnsBuilderTest.java index d801cc37fb7..a87836e1166 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/AlterColumnsBuilderTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/AlterColumnsBuilderTest.java @@ -50,7 +50,7 @@ public class AlterColumnsBuilderTest { @Test public void update_columns_on_mssql() { assertThat(createSampleBuilder(new MsSql()).build()) - .containsOnly("ALTER TABLE issues ALTER COLUMN value DECIMAL (30,20)", "ALTER TABLE issues ALTER COLUMN name VARCHAR (10)"); + .containsOnly("ALTER TABLE issues ALTER COLUMN value DECIMAL (30,20)", "ALTER TABLE issues ALTER COLUMN name NVARCHAR (10)"); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/version/StringColumnDefTest.java b/sonar-db/src/test/java/org/sonar/db/version/StringColumnDefTest.java index 82e50b583f1..448457f9307 100644 --- a/sonar-db/src/test/java/org/sonar/db/version/StringColumnDefTest.java +++ b/sonar-db/src/test/java/org/sonar/db/version/StringColumnDefTest.java @@ -60,7 +60,7 @@ public class StringColumnDefTest { assertThat(def.generateSqlType(new H2())).isEqualTo("VARCHAR (10)"); assertThat(def.generateSqlType(new PostgreSql())).isEqualTo("VARCHAR (10)"); assertThat(def.generateSqlType(new MySql())).isEqualTo("VARCHAR (10)"); - assertThat(def.generateSqlType(new MsSql())).isEqualTo("VARCHAR (10)"); + assertThat(def.generateSqlType(new MsSql())).isEqualTo("NVARCHAR (10)"); assertThat(def.generateSqlType(new Oracle())).isEqualTo("VARCHAR (10)"); } |