加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
i.go 25.12 KB
一键复制 编辑 原始数据 按行查看 历史
moss 提交于 2023-07-04 18:10 . gitee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
import (
"strconv"
"time"
"gitee.com/zyx/dm/util"
)
var DB2G db2g
type db2g struct {
}
func (DB2G db2g) processVarchar2(bytes []byte, prec int) []byte {
rbytes := make([]byte, prec)
copy(rbytes[:len(bytes)], bytes[:])
for i := len(bytes); i < len(rbytes); i++ {
rbytes[i] = ' '
}
return rbytes
}
func (DB2G db2g) charToString(bytes []byte, column *column, conn *DmConnection) string {
if column.colType == VARCHAR2 {
bytes = DB2G.processVarchar2(bytes, int(column.prec))
} else if column.colType == CLOB {
clob := newClobFromDB(bytes, conn, column, true)
clobLen, _ := clob.GetLength()
clobStr, _ := clob.getSubString(1, int32(clobLen))
return clobStr
}
return Dm_build_1331.Dm_build_1584(bytes, conn.serverEncoding, conn)
}
func (DB2G db2g) charToFloat64(bytes []byte, column *column, conn *DmConnection) (float64, error) {
str := DB2G.charToString(bytes, column, conn)
val, err := strconv.ParseFloat(str, 64)
if err != nil {
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
return val, nil
}
func (DB2G db2g) charToDeciaml(bytes []byte, column *column, conn *DmConnection) (*DmDecimal, error) {
str := DB2G.charToString(bytes, column, conn)
return NewDecimalFromString(str)
}
func (DB2G db2g) BinaryToInt64(bytes []byte, column *column, conn *DmConnection) (int64, error) {
if column.colType == BLOB {
blob := newBlobFromDB(bytes, conn, column, true)
blobLen, err := blob.GetLength()
if err != nil {
return 0, err
}
bytes, err = blob.getBytes(1, int32(blobLen))
if err != nil {
return 0, err
}
}
var n, b int64 = 0, 0
startIndex := 0
var length int
if len(bytes) > 8 {
length = 8
for j := 0; j < len(bytes)-8; j++ {
if bytes[j] != 0 {
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
startIndex = len(bytes) - 8
length = 8
}
} else {
length = len(bytes)
}
for j := startIndex; j < startIndex+length; j++ {
b = int64(0xff & bytes[j])
n = b | (n << 8)
}
return n, nil
}
func (DB2G db2g) decToDecimal(bytes []byte, prec int, scale int, compatibleOracle bool) (*DmDecimal, error) {
if compatibleOracle {
prec = -1
scale = -1
}
return newDecimal(bytes, prec, scale)
}
func (DB2G db2g) toBytes(bytes []byte, column *column, conn *DmConnection) ([]byte, error) {
retBytes := Dm_build_1331.Dm_build_1482(bytes, 0, len(bytes))
switch column.colType {
case CLOB:
clob := newClobFromDB(retBytes, conn, column, true)
str, err := clob.getSubString(1, int32(clob.length))
if err != nil {
return nil, err
}
return Dm_build_1331.Dm_build_1547(str, conn.getServerEncoding(), conn), nil
case BLOB:
blob := newBlobFromDB(retBytes, conn, column, true)
bs, err := blob.getBytes(1, int32(blob.length))
if err != nil {
return nil, err
}
return bs, nil
}
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toString(bytes []byte, column *column, conn *DmConnection) string {
switch column.colType {
case CHAR, VARCHAR, VARCHAR2:
return DB2G.charToString(bytes, column, conn)
case BIT, BOOLEAN, TINYINT:
return strconv.FormatInt(int64(bytes[0]), 10)
case SMALLINT:
return strconv.FormatInt(int64(Dm_build_1331.Dm_build_1555(bytes)), 10)
case INT:
return strconv.FormatInt(int64(Dm_build_1331.Dm_build_1558(bytes)), 10)
case BIGINT:
return strconv.FormatInt(int64(Dm_build_1331.Dm_build_1561(bytes)), 10)
case REAL:
return strconv.FormatFloat(float64(Dm_build_1331.Dm_build_1564(bytes)), 'f', -1, 32)
case DOUBLE:
return strconv.FormatFloat(float64(Dm_build_1331.Dm_build_1567(bytes)), 'f', -1, 64)
case DECIMAL:
case BINARY, VARBINARY:
util.StringUtil.BytesToHexString(bytes, false)
case BLOB:
case CLOB:
case DATE:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
if conn.FormatDate != "" {
return dtToStringByOracleFormat(dt, conn.FormatDate, column.scale, int(conn.OracleDateLanguage))
}
case TIME:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
if conn.FormatTime != "" {
return dtToStringByOracleFormat(dt, conn.FormatTime, column.scale, int(conn.OracleDateLanguage))
}
case DATETIME, DATETIME2:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
if conn.FormatTimestamp != "" {
return dtToStringByOracleFormat(dt, conn.FormatTimestamp, column.scale, int(conn.OracleDateLanguage))
}
case TIME_TZ:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
if conn.FormatTimeTZ != "" {
return dtToStringByOracleFormat(dt, conn.FormatTimeTZ, column.scale, int(conn.OracleDateLanguage))
}
case DATETIME_TZ, DATETIME2_TZ:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
if conn.FormatTimestampTZ != "" {
return dtToStringByOracleFormat(dt, conn.FormatTimestampTZ, column.scale, int(conn.OracleDateLanguage))
}
case INTERVAL_DT:
return newDmIntervalDTByBytes(bytes).String()
case INTERVAL_YM:
return newDmIntervalYMByBytes(bytes).String()
case ARRAY:
case SARRAY:
case CLASS:
case PLTYPE_RECORD:
}
return ""
}
func (DB2G db2g) toBool(bytes []byte, column *column, conn *DmConnection) (bool, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
return bytes[0] != 0, nil
case SMALLINT:
return Dm_build_1331.Dm_build_1428(bytes, 0) != 0, nil
case INT:
return Dm_build_1331.Dm_build_1433(bytes, 0) != 0, nil
case BIGINT:
return Dm_build_1331.Dm_build_1438(bytes, 0) != 0, nil
case REAL:
return Dm_build_1331.Dm_build_1443(bytes, 0) != 0, nil
case DOUBLE:
return Dm_build_1331.Dm_build_1447(bytes, 0) != 0, nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
return G2DB.toBool(DB2G.charToString(bytes, column, conn))
}
return false, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toByte(bytes []byte, column *column, conn *DmConnection) (byte, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
} else {
return bytes[0], nil
}
case SMALLINT:
tval := Dm_build_1331.Dm_build_1428(bytes, 0)
if tval < int16(BYTE_MIN) || tval > int16(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case INT:
tval := Dm_build_1331.Dm_build_1433(bytes, 0)
if tval < int32(BYTE_MIN) || tval > int32(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(BYTE_MIN) || tval > int64(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(BYTE_MIN) || tval > float32(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(BYTE_MIN) || tval > float64(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(BYTE_MIN) || tval > float64(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(BYTE_MIN) || tval > int64(BYTE_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return byte(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toInt8(bytes []byte, column *column, conn *DmConnection) (int8, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return int8(bytes[0]), nil
case SMALLINT:
tval := Dm_build_1331.Dm_build_1428(bytes, 0)
if tval < int16(INT8_MIN) || tval < int16(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case INT:
tval := Dm_build_1331.Dm_build_1433(bytes, 0)
if tval < int32(INT8_MIN) || tval > int32(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(INT8_MIN) || tval > int64(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(INT8_MIN) || tval > float32(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(INT8_MIN) || tval > float64(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(INT8_MIN) || tval > float64(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(INT8_MIN) || tval > int64(INT8_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int8(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toInt16(bytes []byte, column *column, conn *DmConnection) (int16, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return int16(bytes[0]), nil
case SMALLINT:
return Dm_build_1331.Dm_build_1428(bytes, 0), nil
case INT:
tval := Dm_build_1331.Dm_build_1433(bytes, 0)
if tval < int32(INT16_MIN) || tval > int32(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(INT16_MIN) || tval > int64(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(INT16_MIN) || tval > float32(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(INT16_MIN) || tval > float64(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(INT16_MIN) || tval > float64(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(INT16_MIN) || tval > int64(INT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int16(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toUInt16(bytes []byte, column *column, conn *DmConnection) (uint16, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return uint16(bytes[0]), nil
case SMALLINT:
return uint16(Dm_build_1331.Dm_build_1428(bytes, 0)), nil
case INT:
tval := Dm_build_1331.Dm_build_1433(bytes, 0)
if tval < int32(UINT16_MIN) || tval > int32(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(UINT16_MIN) || tval > int64(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(UINT16_MIN) || tval > float32(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(UINT16_MIN) || tval > float64(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(UINT16_MIN) || tval > float64(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(UINT16_MIN) || tval > int64(UINT16_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint16(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toInt32(bytes []byte, column *column, conn *DmConnection) (int32, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return int32(bytes[0]), nil
case SMALLINT:
return int32(Dm_build_1331.Dm_build_1428(bytes, 0)), nil
case INT:
return Dm_build_1331.Dm_build_1433(bytes, 0), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(INT32_MIN) || tval > int64(INT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int32(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(INT32_MIN) || tval > float32(INT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int32(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(INT32_MIN) || tval > float64(INT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int32(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(INT32_MIN) || tval > float64(INT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int32(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(INT32_MIN) || tval > int64(INT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int32(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toUInt32(bytes []byte, column *column, conn *DmConnection) (uint32, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return uint32(bytes[0]), nil
case SMALLINT:
return uint32(Dm_build_1331.Dm_build_1428(bytes, 0)), nil
case INT:
return uint32(Dm_build_1331.Dm_build_1433(bytes, 0)), nil
case BIGINT:
tval := Dm_build_1331.Dm_build_1438(bytes, 0)
if tval < int64(UINT32_MIN) || tval > int64(UINT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint32(tval), nil
case REAL:
tval := Dm_build_1331.Dm_build_1443(bytes, 0)
if tval < float32(UINT32_MIN) || tval > float32(UINT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint32(tval), nil
case DOUBLE:
tval := Dm_build_1331.Dm_build_1447(bytes, 0)
if tval < float64(UINT32_MIN) || tval > float64(UINT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint32(tval), nil
case DECIMAL:
case CHAR, VARCHAR, VARCHAR2, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < float64(UINT32_MIN) || tval > float64(UINT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint32(tval), nil
case BINARY, VARBINARY, BLOB:
{
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
if tval < int64(UINT32_MIN) || tval > int64(UINT32_MAX) {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint32(tval), nil
}
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toInt64(bytes []byte, column *column, conn *DmConnection) (int64, error) {
switch column.colType {
case BOOLEAN, BIT, TINYINT:
if bytes == nil || len(bytes) == 0 {
return int64(0), nil
} else {
return int64(bytes[0]), nil
}
case SMALLINT:
return int64(Dm_build_1331.Dm_build_1555(bytes)), nil
case INT:
return int64(Dm_build_1331.Dm_build_1558(bytes)), nil
case BIGINT:
return int64(Dm_build_1331.Dm_build_1561(bytes)), nil
case REAL:
return int64(Dm_build_1331.Dm_build_1564(bytes)), nil
case DOUBLE:
return int64(Dm_build_1331.Dm_build_1567(bytes)), nil
case CHAR, VARCHAR2, VARCHAR, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if int64(tval) < INT64_MIN || int64(tval) > INT64_MAX {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return int64(tval), nil
case BINARY, VARBINARY, BLOB:
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
return tval, nil
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toUInt64(bytes []byte, column *column, conn *DmConnection) (uint64, error) {
switch column.colType {
case BOOLEAN, BIT, TINYINT:
if bytes == nil || len(bytes) == 0 {
return uint64(0), nil
} else {
return uint64(bytes[0]), nil
}
case SMALLINT:
return uint64(Dm_build_1331.Dm_build_1555(bytes)), nil
case INT:
return uint64(Dm_build_1331.Dm_build_1558(bytes)), nil
case BIGINT:
return uint64(Dm_build_1331.Dm_build_1561(bytes)), nil
case REAL:
return uint64(Dm_build_1331.Dm_build_1564(bytes)), nil
case DOUBLE:
return uint64(Dm_build_1331.Dm_build_1567(bytes)), nil
case CHAR, VARCHAR2, VARCHAR, CLOB:
tval, err := DB2G.charToFloat64(bytes, column, conn)
if err != nil {
return 0, err
}
if uint64(tval) < UINT64_MIN || uint64(tval) > UINT64_MAX {
return 0, ECGO_DATA_OVERFLOW.throw()
}
return uint64(tval), nil
case BINARY, VARBINARY, BLOB:
tval, err := DB2G.BinaryToInt64(bytes, column, conn)
if err != nil {
return 0, err
}
return uint64(tval), nil
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toInt(bytes []byte, column *column, conn *DmConnection) (int, error) {
if strconv.IntSize == 32 {
tmp, err := DB2G.toInt32(bytes, column, conn)
return int(tmp), err
} else {
tmp, err := DB2G.toInt64(bytes, column, conn)
return int(tmp), err
}
}
func (DB2G db2g) toUInt(bytes []byte, column *column, conn *DmConnection) (uint, error) {
if strconv.IntSize == 32 {
tmp, err := DB2G.toUInt32(bytes, column, conn)
return uint(tmp), err
} else {
tmp, err := DB2G.toUInt64(bytes, column, conn)
return uint(tmp), err
}
}
func (DB2G db2g) toFloat32(bytes []byte, column *column, conn *DmConnection) (float32, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return float32(bytes[0]), nil
case SMALLINT:
return float32(Dm_build_1331.Dm_build_1428(bytes, 0)), nil
case INT:
return float32(Dm_build_1331.Dm_build_1433(bytes, 0)), nil
case BIGINT:
return float32(Dm_build_1331.Dm_build_1438(bytes, 0)), nil
case REAL:
return Dm_build_1331.Dm_build_1443(bytes, 0), nil
case DOUBLE:
dval := Dm_build_1331.Dm_build_1447(bytes, 0)
return float32(dval), nil
case DECIMAL:
dval, err := DB2G.decToDecimal(bytes, int(column.prec), int(column.scale), conn.CompatibleOracle())
if err != nil {
return 0, err
}
return float32(dval.ToFloat64()), nil
case CHAR, VARCHAR2, VARCHAR, CLOB:
dval, err := DB2G.charToDeciaml(bytes, column, conn)
if err != nil {
return 0, err
}
return float32(dval.ToFloat64()), nil
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toFloat64(bytes []byte, column *column, conn *DmConnection) (float64, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if bytes == nil || len(bytes) == 0 {
return 0, nil
}
return float64(bytes[0]), nil
case SMALLINT:
return float64(Dm_build_1331.Dm_build_1428(bytes, 0)), nil
case INT:
return float64(Dm_build_1331.Dm_build_1433(bytes, 0)), nil
case BIGINT:
return float64(Dm_build_1331.Dm_build_1438(bytes, 0)), nil
case REAL:
return float64(Dm_build_1331.Dm_build_1443(bytes, 0)), nil
case DOUBLE:
return Dm_build_1331.Dm_build_1447(bytes, 0), nil
case DECIMAL:
dval, err := DB2G.decToDecimal(bytes, int(column.prec), int(column.scale), conn.CompatibleOracle())
if err != nil {
return 0, err
}
return dval.ToFloat64(), nil
case CHAR, VARCHAR2, VARCHAR, CLOB:
dval, err := DB2G.charToDeciaml(bytes, column, conn)
if err != nil {
return 0, err
}
return dval.ToFloat64(), nil
}
return 0, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toDmBlob(value []byte, column *column, conn *DmConnection) *DmBlob {
switch column.colType {
case BLOB:
return newBlobFromDB(value, conn, column, conn.lobFetchAll())
default:
return newBlobOfLocal(value, conn)
}
}
func (DB2G db2g) toDmClob(value []byte, conn *DmConnection, column *column) *DmClob {
switch column.colType {
case CLOB:
return newClobFromDB(value, conn, column, conn.lobFetchAll())
default:
return newClobOfLocal(DB2G.toString(value, column, conn), conn)
}
}
func (DB2G db2g) toDmDecimal(value []byte, column *column, conn *DmConnection) (*DmDecimal, error) {
switch column.colType {
case BIT, BOOLEAN, TINYINT:
if value == nil || len(value) == 0 {
return NewDecimalFromInt64(0)
} else {
return NewDecimalFromInt64(int64(value[0]))
}
case SMALLINT:
return NewDecimalFromInt64(int64(Dm_build_1331.Dm_build_1428(value, 0)))
case INT:
return NewDecimalFromInt64(int64(Dm_build_1331.Dm_build_1433(value, 0)))
case BIGINT:
return NewDecimalFromInt64(Dm_build_1331.Dm_build_1438(value, 0))
case REAL:
return NewDecimalFromFloat64(float64(Dm_build_1331.Dm_build_1443(value, 0)))
case DOUBLE:
return NewDecimalFromFloat64(Dm_build_1331.Dm_build_1447(value, 0))
case DECIMAL:
return decodeDecimal(value, int(column.prec), int(column.scale))
case CHAR, VARCHAR, VARCHAR2, CLOB:
return DB2G.charToDeciaml(value, column, conn)
}
return nil, ECGO_DATA_CONVERTION_ERROR
}
func (DB2G db2g) toTime(bytes []byte, column *column, conn *DmConnection) (time.Time, error) {
switch column.colType {
case DATE, TIME, TIME_TZ, DATETIME_TZ, DATETIME, DATETIME2_TZ, DATETIME2:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
return toTimeFromDT(dt, int(conn.dmConnector.localTimezone)), nil
case CHAR, VARCHAR2, VARCHAR, CLOB:
return toTimeFromString(DB2G.charToString(bytes, column, conn), int(conn.dmConnector.localTimezone)), nil
}
return time.Now(), ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toObject(bytes []byte, column *column, conn *DmConnection) (interface{}, error) {
switch column.colType {
case BIT, BOOLEAN:
return bytes[0] != 0, nil
case TINYINT:
return Dm_build_1331.Dm_build_1424(bytes, 0), nil
case SMALLINT:
return Dm_build_1331.Dm_build_1428(bytes, 0), nil
case INT:
return Dm_build_1331.Dm_build_1433(bytes, 0), nil
case BIGINT:
return Dm_build_1331.Dm_build_1438(bytes, 0), nil
case DECIMAL:
return DB2G.decToDecimal(bytes, int(column.prec), int(column.scale), conn.CompatibleOracle())
case REAL:
return Dm_build_1331.Dm_build_1443(bytes, 0), nil
case DOUBLE:
return Dm_build_1331.Dm_build_1447(bytes, 0), nil
case DATE, TIME, DATETIME, TIME_TZ, DATETIME_TZ, DATETIME2, DATETIME2_TZ:
dt := decode(bytes, column.isBdta, *column, int(conn.dmConnector.localTimezone), int(conn.DbTimezone))
return toTimeFromDT(dt, int(conn.dmConnector.localTimezone)), nil
case BINARY, VARBINARY:
return bytes, nil
case BLOB:
blob := newBlobFromDB(bytes, conn, column, conn.lobFetchAll())
if util.StringUtil.EqualsIgnoreCase(column.typeName, "LONGVARBINARY") {
l, err := blob.GetLength()
if err != nil {
return nil, err
}
return blob.getBytes(1, int32(l))
} else {
return blob, nil
}
case CHAR, VARCHAR, VARCHAR2:
val := DB2G.charToString(bytes, column, conn)
if column.mask == MASK_BFILE {
}
return val, nil
case CLOB:
clob := newClobFromDB(bytes, conn, column, conn.lobFetchAll())
if util.StringUtil.EqualsIgnoreCase(column.typeName, "LONGVARCHAR") {
l, err := clob.GetLength()
if err != nil {
return nil, err
}
return clob.getSubString(1, int32(l))
} else {
return clob, nil
}
case INTERVAL_YM:
return newDmIntervalYMByBytes(bytes), nil
case INTERVAL_DT:
return newDmIntervalDTByBytes(bytes), nil
case ARRAY:
return TypeDataSV.bytesToArray(bytes, nil, column.typeDescriptor)
case SARRAY:
return TypeDataSV.bytesToSArray(bytes, nil, column.typeDescriptor)
case CLASS:
case PLTYPE_RECORD:
default:
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
}
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
}
func (DB2G db2g) toComplexType(bytes []byte, column *column, conn *DmConnection) (interface{}, error) {
switch column.colType {
case BLOB:
if !isComplexType(int(column.colType), int(column.scale)) {
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
}
blob := newBlobFromDB(bytes, conn, column, true)
return TypeDataSV.objBlobToObj(blob, column.typeDescriptor)
case ARRAY:
return TypeDataSV.bytesToArray(bytes, nil, column.typeDescriptor)
case SARRAY:
return TypeDataSV.bytesToSArray(bytes, nil, column.typeDescriptor)
case CLASS:
return TypeDataSV.bytesToObj(bytes, nil, column.typeDescriptor)
case PLTYPE_RECORD:
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
default:
return nil, ECGO_DATA_CONVERTION_ERROR.throw()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化