diff --git a/bulkcopy.go b/bulkcopy.go index be8398b1..1bec4ae5 100644 --- a/bulkcopy.go +++ b/bulkcopy.go @@ -98,11 +98,12 @@ func (b *Bulk) sendBulkCommand(ctx context.Context) (err error) { //columns definitions var col_defs bytes.Buffer + q := TSQLQuoter{} for i, col := range b.bulkColumns { if i != 0 { col_defs.WriteString(", ") } - col_defs.WriteString("[" + col.ColName + "] " + makeDecl(col.ti)) + col_defs.WriteString(q.ID(col.ColName) + " " + makeDecl(col.ti)) } //options diff --git a/bulkcopy_test.go b/bulkcopy_test.go index 180b8c96..e1f550ef 100644 --- a/bulkcopy_test.go +++ b/bulkcopy_test.go @@ -193,6 +193,7 @@ func testBulkcopy(t *testing.T, guidConversion bool) { {"test_int16nvarchar", int16(1234), "1234"}, {"test_int8nvarchar", int8(12), "12"}, {"test_intnvarchar", 1234, "1234"}, + {"test_[]{}?@!#$%^&*()_+-=~'\\\";:/.,<>|\\ ", 1, nil}, // col name escaping check } columns := make([]string, len(testValues)) @@ -265,8 +266,14 @@ func testBulkcopy(t *testing.T, guidConversion bool) { t.Errorf("unexpected row count %d", rowCount) } + q := TSQLQuoter{} + selectColumns := make([]string, len(columns)) + for i, col := range columns { + selectColumns[i] = q.ID(col) + } + //data verification - rows, err := conn.QueryContext(ctx, "select "+strings.Join(columns, ",")+" from "+tableName) + rows, err := conn.QueryContext(ctx, "select "+strings.Join(selectColumns, ",")+" from "+tableName) if err != nil { t.Fatal(err) } @@ -435,6 +442,8 @@ func setupTable(ctx context.Context, t *testing.T, conn *sql.Conn, tableName str [test_nullint32] [int] NULL, [test_nullint16] [smallint] NULL, [test_nulltime] [datetime] NULL, + + [test_[]]{}?@!#$%^&*()_+-=~'\";:/.,<>|\ ] [int] NULL, CONSTRAINT [PK_` + tableName + `_id] PRIMARY KEY CLUSTERED ( [id] ASC diff --git a/lastinsertid_example_test.go b/lastinsertid_example_test.go index 260b44ec..239b1ab6 100644 --- a/lastinsertid_example_test.go +++ b/lastinsertid_example_test.go @@ -9,7 +9,7 @@ import ( ) // This example shows the usage of Connector type -func ExampleLastInsertId() { +func ExampleResult_LastInsertId() { connString := makeConnURL().String()