sijms / go-ora

Pure go oracle client
MIT License
796 stars 177 forks source link

Problem when listing CLOB fields, it doesn't bring all the bytes. #511

Closed fitlcarlos closed 7 months ago

fitlcarlos commented 8 months ago

I have a query with several fields and these fields are of type string, date, int and clob and this query will return several rows.

I'm running a DB.query and returning the rows, but the CLob field is already returned to me as a string in the row and does not contain all the bytes of the CLb.

Note: I can't type my fields as go_ora.clob because of my logic.

The logic is as follows:

func Open(){

  var dataset []map[string]*any  

  rows, err = ds.Connection.DB.Query(query, ds.GetParams()...)

  fieldTypes, _ := rows.ColumnTypes()
  fields, _ := rows.Columns()

  for rows.Next() {
     columns := make([]any, len(fields))    

     for i := 0; i < len(columns); i++ {
       columns[i] = &columns[i]
     }

     err := rows.Scan(columns...)  // <--- Here the CLob column already has a string

     if err != nil {
       print(err)
     }

     line := make(map[string]*any)

     for i := 0; i < len(columns); i++ {
       line[strings.ToUpper(fields[i])] = columns[i]
     }

     dataset = append(dataset, line)
  }   
}

columns[0] <----- Here it already brings me the CLob column as a string because the field type is ANY.

Internally in go_ora, it cannot identify that the field is of type OCIClobLocator and perform the correct conversion bringing all the CLob bytes?

sijms commented 7 months ago

Hi @fitlcarlos sorry for late replay according to this doc of scanner interface oracle types should by mapped to one of the following:

// int64
// float64
// bool
// []byte
// string
// time.Time
// nil - for NULL values

so these oracle types will be converted internally into the corresponding go types

oracle type go type
CLOB string
NCLOB string
BLOB []byte

if your data is larger than 32kb so you should use url option lob fetch=post it is not the default option because it slightly slow down the query. (note default will return clob as varchar2 and nclob as nvarchar2 and blob as raw)

sijms commented 7 months ago

I am working on increase number of bytes received during lob prefetch from 32KB to 1 GB (same as official drivers)

fitlcarlos commented 7 months ago

I am working on increase number of bytes received during lob prefetch from 32KB to 1 GB (same as official drivers)

Thank's

sijms commented 7 months ago

fixed in v2.8.8