fix(gbase8s): preserve varchar2 length in ddl
This commit is contained in:
4 files changed
+107
-1
No files matched your search
@@ -981,6 +981,8 @@ public final class Gbase8sAgent extends ConfiguredJdbcAgent {
|
||||
case 41 -> "BOOLEAN";
|
||||
case 43, 52 -> "BIGINT";
|
||||
case 44, 53 -> "BIGSERIAL";
|
||||
case 63 -> "VARCHAR2";
|
||||
case 64 -> "NVARCHAR2";
|
||||
// MySQL-compat extended types (SQLMODE=mysql); codes match the
|
||||
// 3.6.5+ driver's IfxBigIntUnsigned/IfxTinyInt/IfxMediumInt/IfxBit.
|
||||
case 66 -> "BIGINT UNSIGNED";
|
||||
@@ -1107,7 +1109,7 @@ public final class Gbase8sAgent extends ConfiguredJdbcAgent {
|
||||
|
||||
private static Integer characterMaximumLength(int baseType, int length) {
|
||||
return switch (baseType) {
|
||||
case 0, 13, 15, 16, 40 -> length;
|
||||
case 0, 13, 15, 16, 40, 63, 64 -> length;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.dbx.agent.gbase8s;
|
||||
|
||||
import com.dbx.agent.ConnectParams;
|
||||
import com.dbx.agent.ColumnInfo;
|
||||
import com.dbx.agent.DdlBuilder;
|
||||
import com.dbx.agent.IndexInfo;
|
||||
import com.dbx.agent.MetadataListConstraints;
|
||||
import com.dbx.agent.ObjectSource;
|
||||
@@ -395,6 +396,42 @@ class Gbase8sAgentTest {
|
||||
Assertions.assertTrue(sql.get(2).contains("LEFT JOIN syscolcomms"), sql.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void extendedCharacterColumnsPreserveTypeLengthAndNullabilityInDdl() {
|
||||
Gbase8sAgent agent = new Gbase8sAgent();
|
||||
TestSupport.setPrivateConnection(agent, preparedConnection(
|
||||
new ArrayList<>(),
|
||||
resultSet(new String[]{"part1"}, new Object[][]{}),
|
||||
resultSet(new String[]{"colname", "column_default"}, new Object[][]{}),
|
||||
resultSet(
|
||||
new String[]{"colname", "coltype", "colno", "collength", "comments"},
|
||||
new Object[][]{
|
||||
{"channel_list", 63, 1, 1024, null},
|
||||
{"name", 63 + 256, 2, 4096, null},
|
||||
{"national_text", 64, 3, 64, null},
|
||||
{"required_text", 64 + 256, 4, 128, null}
|
||||
}
|
||||
)
|
||||
));
|
||||
|
||||
List<ColumnInfo> columns = agent.getColumns("root", "activity");
|
||||
Assertions.assertEquals(List.of("VARCHAR2", "VARCHAR2", "NVARCHAR2", "NVARCHAR2"),
|
||||
columns.stream().map(ColumnInfo::getData_type).toList());
|
||||
Assertions.assertEquals(List.of(1024, 4096, 64, 128),
|
||||
columns.stream().map(ColumnInfo::getCharacter_maximum_length).toList());
|
||||
Assertions.assertEquals(List.of(true, false, true, false),
|
||||
columns.stream().map(ColumnInfo::getIs_nullable).toList());
|
||||
String ddl = DdlBuilder.buildTableDdl("root", "activity", columns, List.of(), List.of());
|
||||
Assertions.assertEquals("""
|
||||
CREATE TABLE "root"."activity" (
|
||||
"channel_list" VARCHAR2(1024),
|
||||
"name" VARCHAR2(4096) NOT NULL,
|
||||
"national_text" NVARCHAR2(64),
|
||||
"required_text" NVARCHAR2(128) NOT NULL
|
||||
);
|
||||
""", ddl);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getColumnsLoadsDefaultsFromDefaultExpressionCatalogInMysqlCompatMode() throws Exception {
|
||||
List<String> sql = new ArrayList<>();
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package com.dbx.agent.gbase8s;
|
||||
|
||||
import com.dbx.agent.ColumnInfo;
|
||||
import com.dbx.agent.ConnectParams;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
|
||||
class Gbase8sCharacterTypesLiveTest {
|
||||
@Test
|
||||
@EnabledIfEnvironmentVariable(named = "DBX_TEST_GBASE8S_URL", matches = ".+")
|
||||
void characterColumnDdlReplaysWithTheSameTypesLengthsAndNullability() throws Exception {
|
||||
String source = "dbx_char_" + UUID.randomUUID().toString().replace("-", "");
|
||||
String target = source + "_copy";
|
||||
Gbase8sAgent agent = new Gbase8sAgent();
|
||||
agent.connect(new ConnectParams(
|
||||
"", 0, "", System.getenv("DBX_TEST_GBASE8S_USER"), System.getenv("DBX_TEST_GBASE8S_PASSWORD"),
|
||||
"", System.getenv("DBX_TEST_GBASE8S_URL"), false
|
||||
));
|
||||
List<String> createdTables = new ArrayList<>();
|
||||
try (Statement statement = agent.getConnection().createStatement()) {
|
||||
try {
|
||||
statement.execute("CREATE TABLE " + source + " (payload VARCHAR2(1024), required VARCHAR2(4096) NOT NULL, "
|
||||
+ "national NVARCHAR2(64), required_national NVARCHAR2(128) NOT NULL)");
|
||||
createdTables.add(source);
|
||||
String ddl = agent.getTableDdl("", source);
|
||||
Assertions.assertFalse(ddl.contains("UNKNOWN("), ddl);
|
||||
Assertions.assertTrue(ddl.contains("VARCHAR2(1024)"), ddl);
|
||||
Assertions.assertTrue(ddl.contains("NVARCHAR2(128) NOT NULL"), ddl);
|
||||
statement.execute(ddl.replace(source, target));
|
||||
createdTables.add(target);
|
||||
statement.execute("INSERT INTO " + target + " VALUES ('channel', 'required-value', 'national-value', 'required-national')");
|
||||
try (ResultSet rows = statement.executeQuery("SELECT payload, national FROM " + target)) {
|
||||
Assertions.assertTrue(rows.next());
|
||||
Assertions.assertEquals("channel", rows.getString(1));
|
||||
Assertions.assertEquals("national-value", rows.getString(2));
|
||||
Assertions.assertFalse(rows.next());
|
||||
}
|
||||
List<ColumnInfo> original = agent.getColumns("", source);
|
||||
List<ColumnInfo> replayed = agent.getColumns("", target);
|
||||
Assertions.assertEquals(List.of("VARCHAR2", "VARCHAR2", "NVARCHAR2", "NVARCHAR2"),
|
||||
original.stream().map(ColumnInfo::getData_type).toList());
|
||||
Assertions.assertEquals(List.of(1024, 4096, 64, 128),
|
||||
original.stream().map(ColumnInfo::getCharacter_maximum_length).toList());
|
||||
Assertions.assertEquals(original.stream().map(ColumnInfo::getData_type).toList(),
|
||||
replayed.stream().map(ColumnInfo::getData_type).toList());
|
||||
Assertions.assertEquals(original.stream().map(ColumnInfo::getCharacter_maximum_length).toList(),
|
||||
replayed.stream().map(ColumnInfo::getCharacter_maximum_length).toList());
|
||||
Assertions.assertEquals(List.of(true, false, true, false),
|
||||
replayed.stream().map(ColumnInfo::getIs_nullable).toList());
|
||||
} finally {
|
||||
Collections.reverse(createdTables);
|
||||
for (String name : createdTables) statement.execute("DROP TABLE " + name);
|
||||
}
|
||||
} finally {
|
||||
agent.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user