Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into unpool
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Songhurst committed Oct 26, 2017
2 parents e79e30e + 1fcbd78 commit 9e55ff3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package freetds

import (
"errors"
// "fmt"
"unsafe"
)

Expand Down Expand Up @@ -47,7 +46,9 @@ func (conn *Conn) fetchResults() ([]*Result, error) {
// detecting varchar(max) or varbinary(max) types
col.canVary = (size == 2147483647 && typ == SYBCHAR) ||
(size == 2147483647 && typ == XSYBXML) ||
(size == 1073741823 && typ == SYBBINARY)
(size == 1073741823 && typ == SYBBINARY) ||
(size == 64512 && typ == SYBIMAGE) //varbinary(MAX)

col.name = name
col.typ = int(typ)
col.size = int(size)
Expand Down Expand Up @@ -109,7 +110,7 @@ func (conn *Conn) fetchResults() ([]*Result, error) {
}
if data != nil {
// @see https://github.com/golang/go/wiki/cgo
col.buffer = C.GoBytes(unsafe.Pointer(data), C.int(size))
col.buffer = C.GoBytes(unsafe.Pointer(data), C.int(size+1))
}
}

Expand Down
3 changes: 3 additions & 0 deletions mssql_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ func (r *MssqlResult) statusRowValue(columnName string) int64 {
if val, ok := lastResult.Rows[0][idx].(int64); ok {
return val
}
if val, ok := lastResult.Rows[0][idx].(float64); ok {
return int64(val)
}
}
return -1
}
13 changes: 11 additions & 2 deletions mssql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func TestTransRollback(t *testing.T) {

func TestBlobs(t *testing.T) {
db, _ := open()
createTestTable(t, db, "test_blobs", "id int identity, blob varbinary(16)")
createTestTable(t, db, "test_blobs", "id int identity, blob varbinary(16), blob2 varbinary(MAX)")
want := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
_, err := db.Exec("insert into test_blobs values(?)", want)
_, err := db.Exec("insert into test_blobs values(?, ?)", want, want)
assert.Nil(t, err)

var got []byte
Expand All @@ -177,4 +177,13 @@ func TestBlobs(t *testing.T) {
strGot := fmt.Sprintf("%x", got)
assert.Equal(t, strWant, strGot)
assert.Equal(t, want, got)

err = db.QueryRow("select blob2 from test_blobs").Scan(&got)
assert.Nil(t, err)
assert.Equal(t, 16, len(got))

strWant = fmt.Sprintf("%x", want)
strGot = fmt.Sprintf("%x", got)
assert.Equal(t, strWant, strGot)
assert.Equal(t, want, got)
}

0 comments on commit 9e55ff3

Please sign in to comment.