From 0257563881644a484dcd1d868a1475da22f5b32d Mon Sep 17 00:00:00 2001 From: Robin Tang Date: Thu, 26 Sep 2024 09:28:02 -0700 Subject: [PATCH] Implement MSSQL. --- clients/mssql/dialect/dialect.go | 5 ++--- clients/mssql/dialect/dialect_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clients/mssql/dialect/dialect.go b/clients/mssql/dialect/dialect.go index ec8f43bdc..c39eca892 100644 --- a/clients/mssql/dialect/dialect.go +++ b/clients/mssql/dialect/dialect.go @@ -160,9 +160,8 @@ func (MSSQLDialect) BuildAlterColumnQuery(tableID sql.TableIdentifier, columnOp return fmt.Sprintf("ALTER TABLE %s %s %s", tableID.FullyQualifiedName(), columnOp, colSQLPart) } -func (MSSQLDialect) BuildIncreaseStringPrecisionQuery(tableID sql.TableIdentifier, column columns.Column, newPrecision int32) string { - // TODO: Implement this - return "" +func (md MSSQLDialect) BuildIncreaseStringPrecisionQuery(tableID sql.TableIdentifier, column columns.Column, newPrecision int32) string { + return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s VARCHAR(%d)", tableID.FullyQualifiedName(), md.QuoteIdentifier(column.Name()), newPrecision) } func (md MSSQLDialect) BuildIsNotToastValueExpression(tableAlias constants.TableAlias, column columns.Column) string { diff --git a/clients/mssql/dialect/dialect_test.go b/clients/mssql/dialect/dialect_test.go index 5386048cd..0470491e7 100644 --- a/clients/mssql/dialect/dialect_test.go +++ b/clients/mssql/dialect/dialect_test.go @@ -146,6 +146,16 @@ func TestMSSQLDialect_BuildAlterColumnQuery(t *testing.T) { ) } +func TestMSSQLDialect_BuildIncreaseStringPrecisionQuery(t *testing.T) { + fakeTableID := &mocks.FakeTableIdentifier{} + fakeTableID.FullyQualifiedNameReturns("{TABLE}") + + assert.Equal(t, + `ALTER TABLE {TABLE} ALTER COLUMN "{COLUMN}" VARCHAR(12345)`, + MSSQLDialect{}.BuildIncreaseStringPrecisionQuery(fakeTableID, columns.NewColumn("{COLUMN}", typing.String), 12345), + ) +} + func TestMSSQLDialect_BuildIsNotToastValueExpression(t *testing.T) { assert.Equal(t, `COALESCE(tbl."bar", '') != '__debezium_unavailable_value'`,