zb.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (c) 2000-2018, 达梦数据库有限公司.
  3. * All rights reserved.
  4. */
  5. package dm
  6. const (
  7. PARAM_COUNT_LIMIT int32 = 65536
  8. IGNORE_TARGET_LENGTH int32 = -1
  9. IGNORE_TARGET_SCALE int32 = -1
  10. IGNORE_TARGET_TYPE = INT32_MIN
  11. TYPE_FLAG_UNKNOWN byte = 0 // 未知类型
  12. TYPE_FLAG_EXACT byte = 1 // 精确类型
  13. TYPE_FLAG_RECOMMEND byte = 2 // 推荐类型
  14. IO_TYPE_UNKNOWN int8 = -1
  15. IO_TYPE_IN int8 = 0
  16. IO_TYPE_OUT int8 = 1
  17. IO_TYPE_INOUT int8 = 2
  18. MASK_ORACLE_DATE int32 = 1
  19. MASK_ORACLE_FLOAT int32 = 2
  20. MASK_BFILE int32 = 3
  21. MASK_LOCAL_DATETIME int32 = 4
  22. )
  23. type execRetInfo struct {
  24. // param
  25. outParamDatas [][]byte
  26. // rs
  27. hasResultSet bool
  28. rsDatas [][][]byte
  29. rsSizeof int // 结果集数据占用多少空间,(消息中结果集起始位置到 rsCacheOffset
  30. // 的空间大小,这和实际的rsDatas占用空间大小有一定出入,这里粗略估算,用于结果集缓存时的空间管理)
  31. rsCacheOffset int32 // 缓存信息,在响应消息体中的偏移,0表示不存在,仅结果集缓存中可以用
  32. rsBdta bool
  33. rsUpdatable bool
  34. rsRowIds []int64
  35. // rs cache
  36. tbIds []int32
  37. tbTss []int64
  38. // print
  39. printLen int32
  40. printMsg string
  41. // explain
  42. explain string
  43. // 影响行数
  44. updateCount int64 // Insert/Update/Delet影响行数, select结果集的总行数
  45. updateCounts []int64 // 批量影响行数
  46. // 键
  47. rowid int64
  48. lastInsertId int64
  49. // other
  50. retSqlType int16 // 执行返回的语句类型
  51. execId int32
  52. }
  53. type column struct {
  54. typeName string
  55. colType int32
  56. prec int32
  57. scale int32
  58. name string
  59. tableName string
  60. schemaName string
  61. nullable bool
  62. identity bool
  63. readonly bool // 是否只读
  64. baseName string
  65. // lob info
  66. lob bool
  67. lobTabId int32
  68. lobColId int16
  69. // 用于描述ARRAY、STRUCT类型的特有描述信息
  70. typeDescriptor *TypeDescriptor
  71. isBdta bool
  72. mask int32
  73. }
  74. type parameter struct {
  75. column
  76. typeFlag byte
  77. ioType int8
  78. outJType int32
  79. outScale int32
  80. outObjectName string
  81. cursorStmt *DmStatement
  82. hasDefault bool
  83. }
  84. func (column *column) InitColumn() *column {
  85. column.typeName = ""
  86. column.colType = 0
  87. column.prec = 0
  88. column.scale = 0
  89. column.name = ""
  90. column.tableName = ""
  91. column.schemaName = ""
  92. column.nullable = false
  93. column.identity = false
  94. column.readonly = false
  95. column.baseName = ""
  96. // lob info
  97. column.lob = false
  98. column.lobTabId = 0
  99. column.lobColId = 0
  100. // 用于描述ARRAY、STRUCT类型的特有描述信息
  101. column.typeDescriptor = nil
  102. column.isBdta = false
  103. return column
  104. }
  105. func (parameter *parameter) InitParameter() *parameter {
  106. parameter.InitColumn()
  107. parameter.typeFlag = TYPE_FLAG_UNKNOWN
  108. parameter.ioType = IO_TYPE_UNKNOWN
  109. parameter.outJType = IGNORE_TARGET_TYPE
  110. parameter.outScale = IGNORE_TARGET_SCALE
  111. parameter.outObjectName = ""
  112. parameter.cursorStmt = nil
  113. return parameter
  114. }
  115. func (parameter *parameter) resetType(colType int32) {
  116. parameter.colType = colType
  117. parameter.scale = 0
  118. switch colType {
  119. case BIT, BOOLEAN:
  120. parameter.prec = BIT_PREC
  121. case TINYINT:
  122. parameter.prec = TINYINT_PREC
  123. case SMALLINT:
  124. parameter.prec = SMALLINT_PREC
  125. case INT:
  126. parameter.prec = INT_PREC
  127. case BIGINT:
  128. parameter.prec = BIGINT_PREC
  129. case CHAR, VARCHAR, VARCHAR2:
  130. parameter.prec = VARCHAR_PREC
  131. case CLOB:
  132. parameter.prec = CLOB_PREC
  133. case BINARY, VARBINARY:
  134. parameter.prec = VARBINARY_PREC
  135. case BLOB:
  136. parameter.prec = BLOB_PREC
  137. case DATE:
  138. parameter.prec = DATE_PREC
  139. case TIME:
  140. parameter.prec = TIME_PREC
  141. parameter.scale = 6
  142. case TIME_TZ:
  143. parameter.prec = TIME_TZ_PREC
  144. parameter.scale = 6
  145. case DATETIME:
  146. parameter.prec = DATETIME_PREC
  147. parameter.scale = 6
  148. case DATETIME_TZ:
  149. parameter.prec = DATETIME_TZ_PREC
  150. parameter.scale = 6
  151. case DATETIME2:
  152. parameter.prec = DATETIME2_PREC
  153. parameter.scale = 9
  154. case DATETIME2_TZ:
  155. parameter.prec = DATETIME2_TZ_PREC
  156. parameter.scale = 9
  157. case REAL, DOUBLE, DECIMAL, INTERVAL_YM, INTERVAL_DT, ARRAY, CLASS, PLTYPE_RECORD, SARRAY:
  158. parameter.prec = 0
  159. case UNKNOWN, NULL:
  160. // UNKNOWN 导致服务器断言 // setNull导致服务器报错“字符转换失败”
  161. parameter.colType = VARCHAR
  162. parameter.prec = VARCHAR_PREC
  163. default:
  164. }
  165. }
  166. func (execInfo *execRetInfo) union(other *execRetInfo, startRow int, count int) {
  167. if count == 1 {
  168. execInfo.updateCounts[startRow] = other.updateCount
  169. } else if execInfo.updateCounts != nil {
  170. copy(execInfo.updateCounts[startRow:startRow+count], other.updateCounts[0:count])
  171. }
  172. if execInfo.outParamDatas != nil {
  173. execInfo.outParamDatas = append(execInfo.outParamDatas, other.outParamDatas...)
  174. }
  175. }
  176. func NewExceInfo() *execRetInfo {
  177. execInfo := execRetInfo{}
  178. execInfo.outParamDatas = nil
  179. execInfo.hasResultSet = false
  180. execInfo.rsDatas = nil
  181. execInfo.rsSizeof = 0
  182. execInfo.rsCacheOffset = 0
  183. execInfo.rsBdta = false
  184. execInfo.rsUpdatable = false
  185. execInfo.rsRowIds = nil
  186. execInfo.tbIds = nil
  187. execInfo.tbTss = nil
  188. execInfo.printLen = 0
  189. execInfo.printMsg = ""
  190. execInfo.explain = ""
  191. execInfo.updateCount = 0
  192. execInfo.updateCounts = nil
  193. execInfo.rowid = -1
  194. execInfo.lastInsertId = 0
  195. // other
  196. execInfo.retSqlType = -1 // 执行返回的语句类型
  197. execInfo.execId = 0
  198. return &execInfo
  199. }