gitee.com/chunanyong/dm@v1.8.12/zb.go (about)

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