xugu_rows.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package xugu
  2. // /查询结果:driver.Rows
  3. import (
  4. "database/sql/driver"
  5. "fmt"
  6. "reflect"
  7. )
  8. // type Row struct {
  9. // // Data information storage carrier of each column in the result set
  10. // columns []FieldDescri
  11. // // The name of each column in the result set of the current query
  12. // names []string
  13. // done bool
  14. // }
  15. type xuguRows struct {
  16. // A context handle pointer, which can be used to obtain
  17. // information about the result set
  18. //result unsafe.Pointer
  19. results *SelectResult
  20. // The return value of the function cgo_xgc_read_next()
  21. lastRowRelt int
  22. // The return value of the function cgo_xgc_next_result()
  23. lastRelt int
  24. // Boolean value, used to identify whether the executed
  25. // SQL statement has been prepared
  26. prepared bool
  27. // Context connection handle pointer
  28. rows_conn *xuguConn
  29. //rowset Row
  30. }
  31. // Next用于把数据集中的下一行填入提供的slice中。该slice的
  32. // 长度应该跟Columns()的长度一致
  33. //
  34. // 当没有数据行时,Next应该返回io.EOF
  35. //
  36. // dest不应被声明在Next之外(应该作为Next的一个成员变量)
  37. // 关闭Rows时应特别注意,不要修改dest中缓冲区的值
  38. func (row *xuguRows) Next(dest []driver.Value) error {
  39. fmt.Println(">>>>>(self *xuguRows) Next() ")
  40. fmt.Println(" -- int(row.results.Field_Num)", int(row.results.Field_Num))
  41. for j := 0; j < int(row.results.Field_Num); j++ {
  42. coluType := row.results.Fields[j].FieldType
  43. fmt.Println(" --coluType: ", coluType, row.results.Fields[j].typeDatabaseName())
  44. switch coluType {
  45. case fieldTypeDate:
  46. case fieldTypeBinary, fieldTypeLob,
  47. fieldTypeClob, fieldTypeBlob:
  48. case fieldTypeTime,
  49. fieldTypeTimeTZ:
  50. case fieldTypeDatetime,
  51. fieldTypeDatetimeTZ:
  52. default:
  53. fmt.Println(" ----(self *xuguRows) Next() default ")
  54. dest[j] = make([]byte, len(row.results.Values))
  55. dest[j] = row.results.Values[j][0].Col_Data
  56. fmt.Println(" dest[j]:", dest[j])
  57. fmt.Println(" row.results.Values[j][0].Col_Data:", string(row.results.Values[j][0].Col_Data))
  58. }
  59. }
  60. fmt.Println(" -dest: ", dest)
  61. return nil
  62. }
  63. // Columns返回列的名字集,它的个数是从slice的长度中推断出来的。
  64. // 如果不知道特定的列名,应该为该条目返回一个空的字符串
  65. func (row *xuguRows) Columns() []string {
  66. fmt.Println(">>>>>(self *xuguRows) Columns() ")
  67. // if row.results == nil {
  68. // return nil
  69. // }
  70. // if row.results.Fields != nil {
  71. // //return self.results.Fields
  72. // }
  73. //columns := make([]string, int(row.results.Field_Num))
  74. var columns []string
  75. fmt.Println("字段总数row.results.Field_Num", int(row.results.Field_Num))
  76. for i, v := range row.results.Fields {
  77. columns = append(columns, v.FieldName)
  78. fmt.Println("ppend(columns, v.FieldName)", i, columns[i])
  79. }
  80. fmt.Println(" -columns len ", len(columns))
  81. for i, v := range columns {
  82. fmt.Println(" -columns: ", i, v)
  83. }
  84. return columns
  85. }
  86. func (row *xuguRows) ColumnTypeScanType(index int) reflect.Type {
  87. fmt.Println(">>>>>ColumnTypeScanType ")
  88. fmt.Printf(" -- row.results.Fields %#v \n", row.results.Fields)
  89. return row.results.Fields[index].scanType()
  90. }
  91. func (self *xuguRows) Close() error {
  92. fmt.Println(">>>>>((self *xuguRows) Close() ")
  93. return nil
  94. }