rana / ora

An Oracle database driver in Go.
MIT License
272 stars 66 forks source link

How get blob? #80

Closed blackrez closed 8 years ago

blackrez commented 8 years ago

Hi

I try to export blob from an oracle database with this piece of code :

rows, err := db.Query(`select hash, content from "BLOBSTORE"."BLOB" where rownum < 10`)
    if err != nil {
        log.Fatal(err)
    }

    defer rows.Close()

    for rows.Next() {
        //row structure
        var hash string
        var content []byte
        err = rows.Scan(&hash, &content)
        checkErr(err)
        ...

And at the execution, I've got this :

➜  gotothefs ./blober -alsologtostderr=true
connection
query
I0406 10:48:27.675358   40107 util.go:187] [Drv.Open]
I0406 10:48:27.675751   40107 env.go:299] E1 [Env.OpenCon]
I0406 10:48:27.675790   40107 env.go:299] E1 [Env.OpenSrv]
I0406 10:48:27.765079   40107 srv.go:322] E1S1 [Srv.OpenSes]
I0406 10:48:27.849781   40107 ses.go:637] E1S1S1 [Ses.PrepAndQry]
I0406 10:48:27.849821   40107 ses.go:639] E1S1S1 [Ses.Prep] SELECT property_value FROM database_properties WHERE property_name = 'NLS_CHARACTERSET'
I0406 10:48:27.850010   40107 stmt.go:1154] E1S1S1S1 [Stmt.qry]
I0406 10:48:27.850027   40107 stmt.go:1167] E1S1S1S1 [Stmt.bind] Params 0
I0406 10:48:27.868394   40107 rset.go:772] E1S1S1S1R1 [Rset.open]
I0406 10:48:27.868498   40107 rset.go:785] E1S1S1S1R1 [Rset.open] 1. PROPERTY_VALUE/1
I0406 10:48:27.868712   40107 rset.go:785] E1S1S1S1R1 [Rset.open] []ora.def{(*ora.defString)(0xc820071410)}
I0406 10:48:27.868838   40107 conn.go:157] E1S1S1C1 [Con.Prepare]
I0406 10:48:27.868856   40107 ses.go:639] E1S1S1 [Ses.Prep] select hash, content from "BLOBSTORE"."PJ_BLOB" where rownum < 10
I0406 10:48:27.868987   40107 drvStmt.go:108] E1S1S1S2 [DrvStmt.Query]
I0406 10:48:27.869000   40107 stmt.go:1154] E1S1S1S2 [Stmt.qry]
I0406 10:48:27.869009   40107 stmt.go:1167] E1S1S1S2 [Stmt.bind] Params 0
I0406 10:48:27.887039   40107 rset.go:772] E1S1S1S2R2 [Rset.open]
I0406 10:48:27.887122   40107 rset.go:785] E1S1S1S2R2 [Rset.open] 1. HASH/1
I0406 10:48:27.887154   40107 rset.go:785] E1S1S1S2R2 [Rset.open] 2. CONTENT/113
I0406 10:48:27.887201   40107 rset.go:785] E1S1S1S2R2 [Rset.open] []ora.def{(*ora.defString)(0xc820071590), (*ora.defLob)(0xc820071620)}
I0406 10:48:27.948790   40107 drvStmt.go:108] E1S1S1S2 [DrvStmt.Close]
I0406 10:48:27.948823   40107 stmt.go:1154] E1S1S1S2 [Stmt.close]
I0406 10:48:27.948838   40107 rset.go:772] E1S1S1S2R2 [Rset.close]
I0406 10:48:27.966613   40107 conn.go:157] E1S1S1C1 [Con.close]
I0406 10:48:27.966638   40107 ses.go:637] E1S1S1 [Ses.close]
I0406 10:48:27.966648   40107 stmt.go:1154] E1S1S1S1 [Stmt.close]
I0406 10:48:27.966656   40107 rset.go:772] E1S1S1S1R1 [Rset.close]
I0406 10:48:27.985902   40107 srv.go:322] E1S1 [Srv.close]
panic: sql: Scan error on column index 1: unsupported Scan, storing driver.Value type *ora.lobReader into type *[]uint8

goroutine 1 [running]:
panic(0x4228420, 0xc82006f580)
    /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.checkErr(0x8896000, 0xc82006f580)
    /Users/nabil/projects/gotothefs/blober.go:126 +0x4b
main.main()
    /Users/nabil/projects/gotothefs/blober.go:65 +0x52b

How I can get blob?

tgulacsi commented 8 years ago

What do you want to do with the blob?

See ExampleWriteLOB in z_example_test.go - writes and reads black LOBs.

blackrez commented 8 years ago

I want to write the blob to the file system.

blackrez commented 8 years ago

Thanks with this example, I succeed to write.

Many thanks.