tgulacsi / goracle

cx_Oracle translation for Oracle access
Other
47 stars 16 forks source link

Why i get nothing from clob? #14

Closed xpbliss closed 10 years ago

xpbliss commented 10 years ago
conn, err := connect.GetConnection("root/root@ORCL1")
defer conn.Close()
qry := "SELECT content FROM  article_iinfo"   //content is a clob field
rows, err := conn.Query(qry)
var (
    owner oracle.ExternalLobVar
)
for rows.Next() {
    if err = rows.Scan(&owner); err != nil {
        log.Println("error fetching: %s", err)
    }
    log.Printf(`row: %#v"`, owner)
}

// the error is:" row: oracle.ExternalLobVar{lobVar:(*oracle.Variable)(nil), pos:0x0, internalFetchNum:0x0, sFile:false, readPos:0}" //I use goracle under win xp 32bit

tgulacsi commented 10 years ago

This is not an error. You should use Open/Read/Close:

if err = owner.Open(); err == nil {
    if data, e := ioutil.ReadAll(owner); err != nil {
        err =e
    } else {
        log.Printf("row: %q", data)
    }
}
if err != nil {
    log.Printf("error: %v", err)
}

(Untested)