Skip to content

Commit 2134d95

Browse files
committed
Bulkcopy: add failing test case for column name with closing bracket
1 parent 3d2089f commit 2134d95

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

bulkcopy_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func testBulkcopy(t *testing.T, guidConversion bool) {
193193
{"test_int16nvarchar", int16(1234), "1234"},
194194
{"test_int8nvarchar", int8(12), "12"},
195195
{"test_intnvarchar", 1234, "1234"},
196+
{"test_[]{}?@!#$%^&*()_+-=~'\\\";:/.,<>|\\ ", 1, nil}, // col name escaping check
196197
}
197198

198199
columns := make([]string, len(testValues))
@@ -265,8 +266,14 @@ func testBulkcopy(t *testing.T, guidConversion bool) {
265266
t.Errorf("unexpected row count %d", rowCount)
266267
}
267268

269+
q := TSQLQuoter{}
270+
selectColumns := make([]string, len(columns))
271+
for i, col := range columns {
272+
selectColumns[i] = q.ID(col)
273+
}
274+
268275
//data verification
269-
rows, err := conn.QueryContext(ctx, "select "+strings.Join(columns, ",")+" from "+tableName)
276+
rows, err := conn.QueryContext(ctx, "select "+strings.Join(selectColumns, ",")+" from "+tableName)
270277
if err != nil {
271278
t.Fatal(err)
272279
}
@@ -435,6 +442,8 @@ func setupTable(ctx context.Context, t *testing.T, conn *sql.Conn, tableName str
435442
[test_nullint32] [int] NULL,
436443
[test_nullint16] [smallint] NULL,
437444
[test_nulltime] [datetime] NULL,
445+
446+
[test_[]]{}?@!#$%^&*()_+-=~'\";:/.,<>|\ ] [int] NULL,
438447
CONSTRAINT [PK_` + tableName + `_id] PRIMARY KEY CLUSTERED
439448
(
440449
[id] ASC

0 commit comments

Comments
 (0)