Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
fetch as string value about blob subtype ==1. nakagami#10
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Jan 27, 2015
1 parent 704406a commit e2d81eb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 8 additions & 6 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package firebirdsql
import (
"database/sql"
"fmt"
"reflect"
"testing"
"time"
)
Expand Down Expand Up @@ -248,13 +249,14 @@ func TestIssue9(t *testing.T) {
func TestIssue10(t *testing.T) {
conn, _ := sql.Open("firebirdsql_createdb", "sysdba:masterkey@localhost:3050/tmp/go_test_issue10.fdb")

conn.Exec("CREATE TABLE test_issue10 (f1 BLOB SUB_TYPE 1)")
conn.Exec("CREATE TABLE test_issue10 (f1 BLOB SUB_TYPE 0, f2 BLOB SUB_TYPE 1)")
defer conn.Close()
conn.Exec("INSERT INTO test_issue10 (f1) values ('ABC')")
var blob []byte
err := conn.QueryRow("SELECT f1 from test_issue10").Scan(&blob)
if err != nil || blob == nil || len(blob) != 3 || blob[0] != 65 {
t.Fatalf("Invalid blob value:%v:%v", err, blob)
conn.Exec("INSERT INTO test_issue10 (f1, f2) values ('ABC', 'ABC')")
var s string
var b []byte
err := conn.QueryRow("SELECT f1, f2 from test_issue10").Scan(&s, &b)
if err != nil || s != "ABC" || reflect.DeepEqual(b, []byte{65, 67, 68}) {
t.Fatalf("Invalid blob value:%v:%v,%v", err, s, b)
}
}

Expand Down
10 changes: 9 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package firebirdsql

import (
"bytes"
"container/list"
"database/sql/driver"
"io"
Expand Down Expand Up @@ -96,7 +97,14 @@ func (rows *firebirdsqlRows) Next(dest []driver.Value) (err error) {
for i, v := range row {
if rows.stmt.xsqlda[i].sqltype == SQL_TYPE_BLOB {
blobId := v.([]byte)
dest[i], err = rows.stmt.wp.getBlobSegments(blobId, rows.stmt.tx.transHandle)
var blob []byte
blob, err = rows.stmt.wp.getBlobSegments(blobId, rows.stmt.tx.transHandle)
if rows.stmt.xsqlda[i].sqlsubtype == 1 {
dest[i] = bytes.NewBuffer(blob).String()
} else {
dest[i] = blob
}

} else {
dest[i] = v
}
Expand Down

0 comments on commit e2d81eb

Please sign in to comment.