123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package xugu
- // /查询结果:driver.Rows
- import (
- "database/sql/driver"
- "encoding/binary"
- "errors"
- "fmt"
- "reflect"
- )
- // type Row struct {
- // // Data information storage carrier of each column in the result set
- // columns []FieldDescri
- // // The name of each column in the result set of the current query
- // names []string
- // done bool
- // }
- type xuguRows struct {
- // A context handle pointer, which can be used to obtain
- // information about the result set
- //result unsafe.Pointer
- results *SelectResult
- // The return value of the function cgo_xgc_read_next()
- lastRowRelt int
- // The return value of the function cgo_xgc_next_result()
- lastRelt int
- // Boolean value, used to identify whether the executed
- // SQL statement has been prepared
- prepared bool
- // Context connection handle pointer
- rows_conn *xuguConn
- //rowset Row
- }
- // Next用于把数据集中的下一行填入提供的slice中。该slice的
- // 长度应该跟Columns()的长度一致
- //
- // 当没有数据行时,Next应该返回io.EOF
- //
- // dest不应被声明在Next之外(应该作为Next的一个成员变量)
- // 关闭Rows时应特别注意,不要修改dest中缓冲区的值
- func (row *xuguRows) Next(dest []driver.Value) error {
- fmt.Println(">>>>>(self *xuguRows) Next() ")
- if row.results.rowIdx >= len(row.results.Values[0]) {
- return errors.New("The result set has been released")
- }
- // fmt.Println(" -- int(row.results.Field_Num)", int(row.results.Field_Num))
- for j := 0; j < int(row.results.Field_Num); j++ {
- coluType := row.results.Fields[j].FieldType
- //fmt.Println(" --coluType: ", coluType, row.results.Fields[j].typeDatabaseName())
- switch coluType {
- case fieldType_DATE:
- case fieldType_BINARY,
- fieldType_CLOB, fieldType_BLOB:
- case fieldType_TIME,
- fieldType_TIME_TZ:
- case fieldType_DATETIME,
- fieldType_DATETIME_TZ:
- case fieldType_I1:
- dest[j] = int8(row.results.Values[j][row.results.rowIdx].Col_Data[0])
- case fieldType_I4:
- dest[j] = binary.LittleEndian.Uint32(row.results.Values[j][row.results.rowIdx].Col_Data)
- default:
- //填入一行的数据
- //TODO这里长度改为一行长度
- dest[j] = make([]byte, len(row.results.Values))
- // Values[字段][0]
- dest[j] = row.results.Values[j][row.results.rowIdx].Col_Data
- }
- }
- row.results.rowIdx++
- return nil
- }
- // Columns返回列的名字集,它的个数是从slice的长度中推断出来的。
- // 如果不知道特定的列名,应该为该条目返回一个空的字符串
- func (row *xuguRows) Columns() []string {
- fmt.Println(">>>>>(self *xuguRows) Columns() ")
- // if row.results == nil {
- // return nil
- // }
- // if row.results.Fields != nil {
- // //return self.results.Fields
- // }
- //columns := make([]string, int(row.results.Field_Num))
- var columns []string
- for i, v := range row.results.Fields {
- columns = append(columns, v.FieldName)
- fmt.Printf("append(columns, v.FieldName) 个数%d ,%s", i+1, columns[i])
- }
- // fmt.Println(" -columns len ", len(columns))
- // for i, v := range columns {
- // fmt.Println(" -columns: ", i, v)
- // }
- return columns
- }
- func (row *xuguRows) ColumnTypeScanType(index int) reflect.Type {
- fmt.Println(">>>>>ColumnTypeScanType ")
- fmt.Printf(" -- row.results.Fields %#v \n", row.results.Fields[index].FieldType)
- fmt.Printf(" -- row.results.Fields %#v \n", row.results.Fields[index].scanType())
- return row.results.Fields[index].scanType()
- }
- func (self *xuguRows) Close() error {
- fmt.Println(">>>>>((self *xuguRows) Close() ")
- return nil
- }
|