Skip to content

Commit

Permalink
Add "binary" data type support for CopyIn functionality. (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitiokss authored and denisenkom committed Sep 1, 2018
1 parent 8fac8b9 commit 1eb28af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bulkcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (b *Bulk) makeParam(val DataValue, col columnStruct) (res param, err error)
buf[i] = ub[j]
}
res.buffer = buf
case typeBigVarBin:
case typeBigVarBin, typeBigBinary:
switch val := val.(type) {
case []byte:
res.ti.Size = len(val)
Expand Down
11 changes: 11 additions & 0 deletions bulkcopy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestBulkcopy(t *testing.T) {

tableName := "#table_test"
geom, _ := hex.DecodeString("E6100000010C00000000000034400000000000004440")
bin, _ := hex.DecodeString("ba8b7782168d4033a299333aec17bd33")
testValues := []testValue{

{"test_nvarchar", "ab©ĎéⒻghïjklmnopqЯ☀tuvwxyz"},
Expand Down Expand Up @@ -62,6 +63,11 @@ func TestBulkcopy(t *testing.T) {
{"test_decimal_9_2", 1234.560001},
{"test_decimal_20_0", 1234.0001},
{"test_numeric_30_10", 1234567.1234567},
{"test_varbinary", []byte("1")},
{"test_varbinary_16", bin},
{"test_varbinary_max", bin},
{"test_binary", []byte("1")},
{"test_binary_16", bin},
}

columns := make([]string, len(testValues))
Expand Down Expand Up @@ -213,6 +219,11 @@ func setupTable(ctx context.Context, t *testing.T, conn *sql.Conn, tableName str
[test_decimal_9_2] [decimal](9, 2) NULL,
[test_decimal_20_0] [decimal](20, 0) NULL,
[test_numeric_30_10] [decimal](30, 10) NULL,
[test_varbinary] VARBINARY NOT NULL,
[test_varbinary_16] VARBINARY(16) NOT NULL,
[test_varbinary_max] VARBINARY(max) NOT NULL,
[test_binary] BINARY NOT NULL,
[test_binary_16] BINARY(16) NOT NULL,
CONSTRAINT [PK_` + tableName + `_id] PRIMARY KEY CLUSTERED
(
[id] ASC
Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ func makeDecl(ti typeInfo) string {
return "nvarchar(1)"
case typeInt1:
return "tinyint"
case typeBigBinary:
return fmt.Sprintf("binary(%d)", ti.Size)
case typeInt2:
return "smallint"
case typeInt4:
Expand Down

0 comments on commit 1eb28af

Please sign in to comment.