diff --git a/README.md b/README.md index 997683c..3afca1b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,50 @@ # dm - ### 介绍 +达梦数据库是国产化的数据库,该类库是达梦数据的SDK +看到里面奇怪的文件名和函数名,不要喷,猜测是原版通过别的语言自动生成的吧。 + +### 特性 +Fork自`https://gitee.com/chunanyong/dm`,并做了一些优化 +* 去除全局配置 +* 优化命名方式 +* 增加mac方式编译 + ``` -go get gitee.com/chunanyong/dm +go get github.com/gotomicro/dmgo ``` -达梦数据库官方golang驱动,本项目和官方驱动版本同步,方便go mod 使用. -安装达梦数据库(版本>=8.1.1.126),安装目录下 drivers/go/dm-go-driver.zip -golang轻量ORM https://gitee.com/chunanyong/zorm 原生支持达梦数据库 +### 使用原生方式 +```go +package main + +import ( + "database/sql" + "fmt" + + _ "github.com/gotomicro/dmgo" +) + +func main() { + obj, err := sql.Open("dm", "dm://username:password@ip:5236") + if err != nil { + panic(err) + return + } + rows, err := obj.Query("select TABLE_NAME,comments TABLE_COMMENT from user_tab_comments") + for rows.Next() { + a := TableStruct{} + rows.Scan(&a.TableName, &a.TableComment) + fmt.Printf("a--------------->"+"%+v\n", a) + } +} + +type TableStruct struct { + TableName string //表名 + TableComment string //表注释 +} +``` + +### 使用gorm方式 ### DSN dm://userName:password@ip:port @@ -20,7 +57,7 @@ golang三段位版本号和达梦四段位版本号不兼容,统一使用1.达 * v1.8.0 备注是 达梦8.1.1.126 * v1.8.1 备注是 达梦8.1.1.190 * v1.8.2 备注是 达梦8.1.2.18 -* v1.8.3 备注是 达梦8.1.2.38 +* v1.8.4 备注是 达梦8.1.2.38 diff --git a/a.go b/a.go index 2cb83ab..f0074df 100644 --- a/a.go +++ b/a.go @@ -11,7 +11,7 @@ import ( "strconv" "time" - "gitee.com/chunanyong/dm/security" + "github.com/gotomicro/dmgo/security" ) const ( @@ -19,11 +19,11 @@ const ( Dm_build_331 = 2 * time.Second ) -type dm_build_332 struct { - dm_build_333 *net.TCPConn - dm_build_334 *tls.Conn +type Access struct { + tcpConn *net.TCPConn + tlsConn *tls.Conn dm_build_335 *Dm_build_0 - dm_build_336 *DmConnection + conn *Connection dm_build_337 security.Cipher dm_build_338 bool dm_build_339 bool @@ -34,34 +34,33 @@ type dm_build_332 struct { dm_build_343 bool } -func dm_build_344(dm_build_345 *DmConnection) (*dm_build_332, error) { - dm_build_346, dm_build_347 := dm_build_349(dm_build_345.dmConnector.host+":"+strconv.Itoa(int(dm_build_345.dmConnector.port)), time.Duration(dm_build_345.dmConnector.socketTimeout)*time.Second) - if dm_build_347 != nil { - return nil, dm_build_347 +func buildAccess(conn *Connection) (*Access, error) { + tcpConn, err := buildTCPConn(conn.dmConnector.host+":"+strconv.Itoa(int(conn.dmConnector.port)), time.Duration(conn.dmConnector.socketTimeout)*time.Second) + if err != nil { + return nil, err } - dm_build_348 := dm_build_332{} - dm_build_348.dm_build_333 = dm_build_346 - dm_build_348.dm_build_335 = Dm_build_3(Dm_build_604) - dm_build_348.dm_build_336 = dm_build_345 - dm_build_348.dm_build_338 = false - dm_build_348.dm_build_339 = false - dm_build_348.dm_build_341 = false - dm_build_348.dm_build_342 = "" - dm_build_348.dm_build_343 = false - dm_build_345.Access = &dm_build_348 + access := Access{} + access.tcpConn = tcpConn + access.dm_build_335 = Dm_build_3(Dm_build_604) + access.conn = conn + access.dm_build_338 = false + access.dm_build_339 = false + access.dm_build_341 = false + access.dm_build_342 = "" + access.dm_build_343 = false + conn.Access = &access - return &dm_build_348, nil + return &access, nil } -func dm_build_349(dm_build_350 string, dm_build_351 time.Duration) (*net.TCPConn, error) { - dm_build_352, dm_build_353 := net.DialTimeout("tcp", dm_build_350, dm_build_351) - if dm_build_353 != nil { - return nil, ECGO_COMMUNITION_ERROR.addDetail("\tdial address: " + dm_build_350).throw() +func buildTCPConn(addr string, t time.Duration) (*net.TCPConn, error) { + conn, err := net.DialTimeout("tcp", addr, t) + if err != nil { + return nil, ECGO_COMMUNITION_ERROR.addDetail("\tdial address: " + addr).throw() } - if tcpConn, ok := dm_build_352.(*net.TCPConn); ok { - + if tcpConn, ok := conn.(*net.TCPConn); ok { tcpConn.SetKeepAlive(true) tcpConn.SetKeepAlivePeriod(Dm_build_331) tcpConn.SetNoDelay(true) @@ -72,8 +71,8 @@ func dm_build_349(dm_build_350 string, dm_build_351 time.Duration) (*net.TCPConn return nil, nil } -func (dm_build_355 *dm_build_332) dm_build_354(dm_build_356 dm_build_724) bool { - var dm_build_357 = dm_build_355.dm_build_336.dmConnector.compress +func (access *Access) dm_build_354(dm_build_356 dm_build_724) bool { + var dm_build_357 = access.conn.dmConnector.compress if dm_build_356.dm_build_739() == Dm_build_631 || dm_build_357 == Dm_build_680 { return false } @@ -81,14 +80,14 @@ func (dm_build_355 *dm_build_332) dm_build_354(dm_build_356 dm_build_724) bool { if dm_build_357 == Dm_build_678 { return true } else if dm_build_357 == Dm_build_679 { - return !dm_build_355.dm_build_336.Local && dm_build_356.dm_build_737() > Dm_build_677 + return !access.conn.Local && dm_build_356.dm_build_737() > Dm_build_677 } return false } -func (dm_build_359 *dm_build_332) dm_build_358(dm_build_360 dm_build_724) bool { - var dm_build_361 = dm_build_359.dm_build_336.dmConnector.compress +func (access *Access) dm_build_358(dm_build_360 dm_build_724) bool { + var dm_build_361 = access.conn.dmConnector.compress if dm_build_360.dm_build_739() == Dm_build_631 || dm_build_361 == Dm_build_680 { return false } @@ -96,13 +95,13 @@ func (dm_build_359 *dm_build_332) dm_build_358(dm_build_360 dm_build_724) bool { if dm_build_361 == Dm_build_678 { return true } else if dm_build_361 == Dm_build_679 { - return dm_build_359.dm_build_335.Dm_build_263(Dm_build_639) == 1 + return access.dm_build_335.Dm_build_263(Dm_build_639) == 1 } return false } -func (dm_build_363 *dm_build_332) dm_build_362(dm_build_364 dm_build_724) (err error) { +func (access *Access) dm_build_362(dm_build_364 dm_build_724) (err error) { defer func() { if p := recover(); p != nil { if _, ok := p.(string); ok { @@ -117,49 +116,49 @@ func (dm_build_363 *dm_build_332) dm_build_362(dm_build_364 dm_build_724) (err e if dm_build_366 > 0 { - if dm_build_363.dm_build_354(dm_build_364) { - var retBytes, err = Compress(dm_build_363.dm_build_335, Dm_build_632, int(dm_build_366), int(dm_build_363.dm_build_336.dmConnector.compressID)) + if access.dm_build_354(dm_build_364) { + var retBytes, err = Compress(access.dm_build_335, Dm_build_632, int(dm_build_366), int(access.conn.dmConnector.compressID)) if err != nil { return err } - dm_build_363.dm_build_335.Dm_build_14(Dm_build_632) + access.dm_build_335.Dm_build_14(Dm_build_632) - dm_build_363.dm_build_335.Dm_build_51(dm_build_366) + access.dm_build_335.Dm_build_51(dm_build_366) - dm_build_363.dm_build_335.Dm_build_79(retBytes) + access.dm_build_335.Dm_build_79(retBytes) dm_build_364.dm_build_738(int32(len(retBytes)) + ULINT_SIZE) - dm_build_363.dm_build_335.Dm_build_183(Dm_build_639, 1) + access.dm_build_335.Dm_build_183(Dm_build_639, 1) } - if dm_build_363.dm_build_339 { + if access.dm_build_339 { dm_build_366 = dm_build_364.dm_build_737() - var retBytes = dm_build_363.dm_build_337.Encrypt(dm_build_363.dm_build_335.Dm_build_290(Dm_build_632, int(dm_build_366)), true) + var retBytes = access.dm_build_337.Encrypt(access.dm_build_335.Dm_build_290(Dm_build_632, int(dm_build_366)), true) - dm_build_363.dm_build_335.Dm_build_14(Dm_build_632) + access.dm_build_335.Dm_build_14(Dm_build_632) - dm_build_363.dm_build_335.Dm_build_79(retBytes) + access.dm_build_335.Dm_build_79(retBytes) dm_build_364.dm_build_738(int32(len(retBytes))) } } dm_build_364.dm_build_733() - if dm_build_363.dm_build_594(dm_build_364) { - if dm_build_363.dm_build_334 != nil { - dm_build_363.dm_build_335.Dm_build_17(0) - dm_build_363.dm_build_335.Dm_build_36(dm_build_363.dm_build_334) + if access.dm_build_594(dm_build_364) { + if access.tlsConn != nil { + access.dm_build_335.Dm_build_17(0) + access.dm_build_335.Dm_build_36(access.tlsConn) } } else { - dm_build_363.dm_build_335.Dm_build_17(0) - dm_build_363.dm_build_335.Dm_build_36(dm_build_363.dm_build_333) + access.dm_build_335.Dm_build_17(0) + access.dm_build_335.Dm_build_36(access.tcpConn) } return nil } -func (dm_build_368 *dm_build_332) dm_build_367(dm_build_369 dm_build_724) (err error) { +func (access *Access) dm_build_367(dm_build_369 dm_build_724) (err error) { defer func() { if p := recover(); p != nil { if _, ok := p.(string); ok { @@ -171,23 +170,23 @@ func (dm_build_368 *dm_build_332) dm_build_367(dm_build_369 dm_build_724) (err e }() dm_build_371 := int32(0) - if dm_build_368.dm_build_594(dm_build_369) { - if dm_build_368.dm_build_334 != nil { - dm_build_368.dm_build_335.Dm_build_14(0) - dm_build_368.dm_build_335.Dm_build_30(dm_build_368.dm_build_334, Dm_build_632) + if access.dm_build_594(dm_build_369) { + if access.tlsConn != nil { + access.dm_build_335.Dm_build_14(0) + access.dm_build_335.Dm_build_30(access.tlsConn, Dm_build_632) dm_build_371 = dm_build_369.dm_build_737() if dm_build_371 > 0 { - dm_build_368.dm_build_335.Dm_build_30(dm_build_368.dm_build_334, int(dm_build_371)) + access.dm_build_335.Dm_build_30(access.tlsConn, int(dm_build_371)) } } } else { - dm_build_368.dm_build_335.Dm_build_14(0) - dm_build_368.dm_build_335.Dm_build_30(dm_build_368.dm_build_333, Dm_build_632) + access.dm_build_335.Dm_build_14(0) + access.dm_build_335.Dm_build_30(access.tcpConn, Dm_build_632) dm_build_371 = dm_build_369.dm_build_737() if dm_build_371 > 0 { - dm_build_368.dm_build_335.Dm_build_30(dm_build_368.dm_build_333, int(dm_build_371)) + access.dm_build_335.Dm_build_30(access.tcpConn, int(dm_build_371)) } } @@ -198,44 +197,44 @@ func (dm_build_368 *dm_build_332) dm_build_367(dm_build_369 dm_build_724) (err e return nil } - if dm_build_368.dm_build_339 { - ebytes := dm_build_368.dm_build_335.Dm_build_290(Dm_build_632, int(dm_build_371)) - bytes, err := dm_build_368.dm_build_337.Decrypt(ebytes, true) + if access.dm_build_339 { + ebytes := access.dm_build_335.Dm_build_290(Dm_build_632, int(dm_build_371)) + bytes, err := access.dm_build_337.Decrypt(ebytes, true) if err != nil { return err } - dm_build_368.dm_build_335.Dm_build_14(Dm_build_632) - dm_build_368.dm_build_335.Dm_build_79(bytes) + access.dm_build_335.Dm_build_14(Dm_build_632) + access.dm_build_335.Dm_build_79(bytes) dm_build_369.dm_build_738(int32(len(bytes))) } - if dm_build_368.dm_build_358(dm_build_369) { + if access.dm_build_358(dm_build_369) { dm_build_371 = dm_build_369.dm_build_737() - cbytes := dm_build_368.dm_build_335.Dm_build_290(Dm_build_632+ULINT_SIZE, int(dm_build_371-ULINT_SIZE)) - bytes, err := UnCompress(cbytes, int(dm_build_368.dm_build_336.dmConnector.compressID)) + cbytes := access.dm_build_335.Dm_build_290(Dm_build_632+ULINT_SIZE, int(dm_build_371-ULINT_SIZE)) + bytes, err := UnCompress(cbytes, int(access.conn.dmConnector.compressID)) if err != nil { return err } - dm_build_368.dm_build_335.Dm_build_14(Dm_build_632) - dm_build_368.dm_build_335.Dm_build_79(bytes) + access.dm_build_335.Dm_build_14(Dm_build_632) + access.dm_build_335.Dm_build_79(bytes) dm_build_369.dm_build_738(int32(len(bytes))) } return nil } -func (dm_build_373 *dm_build_332) dm_build_372(dm_build_374 dm_build_724) (dm_build_375 interface{}, dm_build_376 error) { +func (access *Access) dm_build_372(dm_build_374 dm_build_724) (dm_build_375 interface{}, dm_build_376 error) { dm_build_376 = dm_build_374.dm_build_728(dm_build_374) if dm_build_376 != nil { return nil, dm_build_376 } - dm_build_376 = dm_build_373.dm_build_362(dm_build_374) + dm_build_376 = access.dm_build_362(dm_build_374) if dm_build_376 != nil { return nil, dm_build_376 } - dm_build_376 = dm_build_373.dm_build_367(dm_build_374) + dm_build_376 = access.dm_build_367(dm_build_374) if dm_build_376 != nil { return nil, dm_build_376 } @@ -243,10 +242,10 @@ func (dm_build_373 *dm_build_332) dm_build_372(dm_build_374 dm_build_724) (dm_bu return dm_build_374.dm_build_732(dm_build_374) } -func (dm_build_378 *dm_build_332) dm_build_377() (*dm_build_1161, error) { +func (access *Access) dm_build_377() (*dm_build_1161, error) { - Dm_build_379 := dm_build_1167(dm_build_378) - _, dm_build_380 := dm_build_378.dm_build_372(Dm_build_379) + Dm_build_379 := dm_build_1167(access) + _, dm_build_380 := access.dm_build_372(Dm_build_379) if dm_build_380 != nil { return nil, dm_build_380 } @@ -254,10 +253,10 @@ func (dm_build_378 *dm_build_332) dm_build_377() (*dm_build_1161, error) { return Dm_build_379, nil } -func (dm_build_382 *dm_build_332) dm_build_381() error { +func (access *Access) dm_build_381() error { - dm_build_383 := dm_build_1029(dm_build_382) - _, dm_build_384 := dm_build_382.dm_build_372(dm_build_383) + dm_build_383 := dm_build_1029(access) + _, dm_build_384 := access.dm_build_372(dm_build_383) if dm_build_384 != nil { return dm_build_384 } @@ -265,26 +264,26 @@ func (dm_build_382 *dm_build_332) dm_build_381() error { return nil } -func (dm_build_386 *dm_build_332) dm_build_385() error { +func (access *Access) initialize() error { var dm_build_387 *dm_build_1161 var err error - if dm_build_387, err = dm_build_386.dm_build_377(); err != nil { + if dm_build_387, err = access.dm_build_377(); err != nil { return err } - if dm_build_386.dm_build_336.sslEncrypt == 2 { - if err = dm_build_386.dm_build_590(false); err != nil { + if access.conn.sslEncrypt == 2 { + if err = access.dm_build_590(false); err != nil { return ECGO_INIT_SSL_FAILED.addDetail("\n" + err.Error()).throw() } - } else if dm_build_386.dm_build_336.sslEncrypt == 1 { - if err = dm_build_386.dm_build_590(true); err != nil { + } else if access.conn.sslEncrypt == 1 { + if err = access.dm_build_590(true); err != nil { return ECGO_INIT_SSL_FAILED.addDetail("\n" + err.Error()).throw() } } - if dm_build_386.dm_build_339 || dm_build_386.dm_build_338 { - k, err := dm_build_386.dm_build_580() + if access.dm_build_339 || access.dm_build_338 { + k, err := access.dm_build_580() if err != nil { return err } @@ -297,21 +296,21 @@ func (dm_build_386 *dm_build_332) dm_build_385() error { if hashType == -1 { hashType = security.MD5 } - err = dm_build_386.dm_build_583(encryptType, sessionKey, dm_build_386.dm_build_336.dmConnector.cipherPath, hashType) + err = access.dm_build_583(encryptType, sessionKey, access.conn.dmConnector.cipherPath, hashType) if err != nil { return err } } - if err := dm_build_386.dm_build_381(); err != nil { + if err := access.dm_build_381(); err != nil { return err } return nil } -func (dm_build_390 *dm_build_332) Dm_build_389(dm_build_391 *DmStatement) error { - dm_build_392 := dm_build_1190(dm_build_390, dm_build_391) - _, dm_build_393 := dm_build_390.dm_build_372(dm_build_392) +func (access *Access) Dm_build_389(dm_build_391 *DmStatement) error { + dm_build_392 := dm_build_1190(access, dm_build_391) + _, dm_build_393 := access.dm_build_372(dm_build_392) if dm_build_393 != nil { return dm_build_393 } @@ -319,9 +318,9 @@ func (dm_build_390 *dm_build_332) Dm_build_389(dm_build_391 *DmStatement) error return nil } -func (dm_build_395 *dm_build_332) Dm_build_394(dm_build_396 int32) error { - dm_build_397 := dm_build_1200(dm_build_395, dm_build_396) - _, dm_build_398 := dm_build_395.dm_build_372(dm_build_397) +func (access *Access) Dm_build_394(dm_build_396 int32) error { + dm_build_397 := dm_build_1200(access, dm_build_396) + _, dm_build_398 := access.dm_build_372(dm_build_397) if dm_build_398 != nil { return dm_build_398 } @@ -329,21 +328,21 @@ func (dm_build_395 *dm_build_332) Dm_build_394(dm_build_396 int32) error { return nil } -func (dm_build_400 *dm_build_332) Dm_build_399(dm_build_401 *DmStatement, dm_build_402 bool, dm_build_403 int16) (*execRetInfo, error) { - dm_build_404 := dm_build_1067(dm_build_400, dm_build_401, dm_build_402, dm_build_403) - dm_build_405, dm_build_406 := dm_build_400.dm_build_372(dm_build_404) +func (access *Access) Dm_build_399(dm_build_401 *DmStatement, dm_build_402 bool, dm_build_403 int16) (*execRetInfo, error) { + dm_build_404 := dm_build_1067(access, dm_build_401, dm_build_402, dm_build_403) + dm_build_405, dm_build_406 := access.dm_build_372(dm_build_404) if dm_build_406 != nil { return nil, dm_build_406 } return dm_build_405.(*execRetInfo), nil } -func (dm_build_408 *dm_build_332) Dm_build_407(dm_build_409 *DmStatement, dm_build_410 int16) (*execRetInfo, error) { - return dm_build_408.Dm_build_399(dm_build_409, false, Dm_build_684) +func (access *Access) Dm_build_407(dm_build_409 *DmStatement, dm_build_410 int16) (*execRetInfo, error) { + return access.Dm_build_399(dm_build_409, false, Dm_build_684) } -func (dm_build_412 *dm_build_332) Dm_build_411(dm_build_413 *DmStatement, dm_build_414 []OptParameter) (*execRetInfo, error) { - dm_build_415, dm_build_416 := dm_build_412.dm_build_372(dm_build_826(dm_build_412, dm_build_413, dm_build_414)) +func (access *Access) Dm_build_411(dm_build_413 *DmStatement, dm_build_414 []OptParameter) (*execRetInfo, error) { + dm_build_415, dm_build_416 := access.dm_build_372(dm_build_826(access, dm_build_413, dm_build_414)) if dm_build_416 != nil { return nil, dm_build_416 } @@ -351,20 +350,20 @@ func (dm_build_412 *dm_build_332) Dm_build_411(dm_build_413 *DmStatement, dm_bui return dm_build_415.(*execRetInfo), nil } -func (dm_build_418 *dm_build_332) Dm_build_417(dm_build_419 *DmStatement, dm_build_420 int16) (*execRetInfo, error) { - return dm_build_418.Dm_build_399(dm_build_419, true, dm_build_420) +func (access *Access) Dm_build_417(dm_build_419 *DmStatement, dm_build_420 int16) (*execRetInfo, error) { + return access.Dm_build_399(dm_build_419, true, dm_build_420) } -func (dm_build_422 *dm_build_332) Dm_build_421(dm_build_423 *DmStatement, dm_build_424 [][]interface{}) (*execRetInfo, error) { - dm_build_425 := dm_build_849(dm_build_422, dm_build_423, dm_build_424) - dm_build_426, dm_build_427 := dm_build_422.dm_build_372(dm_build_425) +func (access *Access) Dm_build_421(dm_build_423 *DmStatement, dm_build_424 [][]interface{}) (*execRetInfo, error) { + dm_build_425 := dm_build_849(access, dm_build_423, dm_build_424) + dm_build_426, dm_build_427 := access.dm_build_372(dm_build_425) if dm_build_427 != nil { return nil, dm_build_427 } return dm_build_426.(*execRetInfo), nil } -func (dm_build_429 *dm_build_332) Dm_build_428(dm_build_430 *DmStatement, dm_build_431 [][]interface{}, dm_build_432 bool) (*execRetInfo, error) { +func (access *Access) Dm_build_428(dm_build_430 *DmStatement, dm_build_431 [][]interface{}, dm_build_432 bool) (*execRetInfo, error) { var dm_build_433, dm_build_434 = 0, 0 var dm_build_435 = len(dm_build_431) var dm_build_436 [][]interface{} @@ -380,7 +379,7 @@ func (dm_build_429 *dm_build_332) Dm_build_428(dm_build_430 *DmStatement, dm_bui if dm_build_430.params[icol].ioType == IO_TYPE_OUT { continue } - if dm_build_429.dm_build_563(bindData, paramData, icol) { + if access.dm_build_563(bindData, paramData, icol) { dm_build_438 = true break } @@ -393,7 +392,7 @@ func (dm_build_429 *dm_build_332) Dm_build_428(dm_build_430 *DmStatement, dm_bui } if dm_build_434 != dm_build_433 { - tmpExecInfo, err := dm_build_429.Dm_build_421(dm_build_430, dm_build_436) + tmpExecInfo, err := access.Dm_build_421(dm_build_430, dm_build_436) if err != nil { return nil, err } @@ -402,7 +401,7 @@ func (dm_build_429 *dm_build_332) Dm_build_428(dm_build_430 *DmStatement, dm_bui } if dm_build_434 < dm_build_435 { - tmpExecInfo, err := dm_build_429.Dm_build_439(dm_build_430, dm_build_431[dm_build_434], dm_build_432) + tmpExecInfo, err := access.Dm_build_439(dm_build_430, dm_build_431[dm_build_434], dm_build_432) if err != nil { return nil, err } @@ -421,22 +420,22 @@ func (dm_build_429 *dm_build_332) Dm_build_428(dm_build_430 *DmStatement, dm_bui return dm_build_437, nil } -func (dm_build_440 *dm_build_332) Dm_build_439(dm_build_441 *DmStatement, dm_build_442 []interface{}, dm_build_443 bool) (*execRetInfo, error) { +func (access *Access) Dm_build_439(dm_build_441 *DmStatement, dm_build_442 []interface{}, dm_build_443 bool) (*execRetInfo, error) { var dm_build_444 = make([]interface{}, dm_build_441.paramCount) for icol := 0; icol < int(dm_build_441.paramCount); icol++ { if dm_build_441.params[icol].ioType == IO_TYPE_OUT { continue } - if dm_build_440.dm_build_563(dm_build_444, dm_build_442, icol) { + if access.dm_build_563(dm_build_444, dm_build_442, icol) { if !dm_build_443 { - preExecute := dm_build_1057(dm_build_440, dm_build_441, dm_build_441.params) - dm_build_440.dm_build_372(preExecute) + preExecute := dm_build_1057(access, dm_build_441, dm_build_441.params) + access.dm_build_372(preExecute) dm_build_443 = true } - dm_build_440.dm_build_569(dm_build_441, dm_build_441.params[icol], icol, dm_build_442[icol].(iOffRowBinder)) + access.dm_build_569(dm_build_441, dm_build_441.params[icol], icol, dm_build_442[icol].(iOffRowBinder)) dm_build_444[icol] = ParamDataEnum_OFF_ROW } } @@ -444,36 +443,36 @@ func (dm_build_440 *dm_build_332) Dm_build_439(dm_build_441 *DmStatement, dm_bui var dm_build_445 = make([][]interface{}, 1, 1) dm_build_445[0] = dm_build_444 - dm_build_446 := dm_build_849(dm_build_440, dm_build_441, dm_build_445) - dm_build_447, dm_build_448 := dm_build_440.dm_build_372(dm_build_446) + dm_build_446 := dm_build_849(access, dm_build_441, dm_build_445) + dm_build_447, dm_build_448 := access.dm_build_372(dm_build_446) if dm_build_448 != nil { return nil, dm_build_448 } return dm_build_447.(*execRetInfo), nil } -func (dm_build_450 *dm_build_332) Dm_build_449(dm_build_451 *DmStatement, dm_build_452 int16) (*execRetInfo, error) { - dm_build_453 := dm_build_1044(dm_build_450, dm_build_451, dm_build_452) +func (access *Access) Dm_build_449(dm_build_451 *DmStatement, dm_build_452 int16) (*execRetInfo, error) { + dm_build_453 := dm_build_1044(access, dm_build_451, dm_build_452) - dm_build_454, dm_build_455 := dm_build_450.dm_build_372(dm_build_453) + dm_build_454, dm_build_455 := access.dm_build_372(dm_build_453) if dm_build_455 != nil { return nil, dm_build_455 } return dm_build_454.(*execRetInfo), nil } -func (dm_build_457 *dm_build_332) Dm_build_456(dm_build_458 *innerRows, dm_build_459 int64) (*execRetInfo, error) { - dm_build_460 := dm_build_949(dm_build_457, dm_build_458, dm_build_459, INT64_MAX) - dm_build_461, dm_build_462 := dm_build_457.dm_build_372(dm_build_460) +func (access *Access) Dm_build_456(dm_build_458 *innerRows, dm_build_459 int64) (*execRetInfo, error) { + dm_build_460 := dm_build_949(access, dm_build_458, dm_build_459, INT64_MAX) + dm_build_461, dm_build_462 := access.dm_build_372(dm_build_460) if dm_build_462 != nil { return nil, dm_build_462 } return dm_build_461.(*execRetInfo), nil } -func (dm_build_464 *dm_build_332) Commit() error { - dm_build_465 := dm_build_812(dm_build_464) - _, dm_build_466 := dm_build_464.dm_build_372(dm_build_465) +func (access *Access) Commit() error { + dm_build_465 := dm_build_812(access) + _, dm_build_466 := access.dm_build_372(dm_build_465) if dm_build_466 != nil { return dm_build_466 } @@ -481,9 +480,9 @@ func (dm_build_464 *dm_build_332) Commit() error { return nil } -func (dm_build_468 *dm_build_332) Rollback() error { - dm_build_469 := dm_build_1105(dm_build_468) - _, dm_build_470 := dm_build_468.dm_build_372(dm_build_469) +func (access *Access) Rollback() error { + dm_build_469 := dm_build_1105(access) + _, dm_build_470 := access.dm_build_372(dm_build_469) if dm_build_470 != nil { return dm_build_470 } @@ -491,9 +490,9 @@ func (dm_build_468 *dm_build_332) Rollback() error { return nil } -func (dm_build_472 *dm_build_332) Dm_build_471(dm_build_473 *DmConnection) error { - dm_build_474 := dm_build_1110(dm_build_472, dm_build_473.IsoLevel) - _, dm_build_475 := dm_build_472.dm_build_372(dm_build_474) +func (access *Access) Dm_build_471(dm_build_473 *Connection) error { + dm_build_474 := dm_build_1110(access, dm_build_473.IsoLevel) + _, dm_build_475 := access.dm_build_372(dm_build_474) if dm_build_475 != nil { return dm_build_475 } @@ -501,9 +500,9 @@ func (dm_build_472 *dm_build_332) Dm_build_471(dm_build_473 *DmConnection) error return nil } -func (dm_build_477 *dm_build_332) Dm_build_476(dm_build_478 *DmStatement, dm_build_479 string) error { - dm_build_480 := dm_build_817(dm_build_477, dm_build_478, dm_build_479) - _, dm_build_481 := dm_build_477.dm_build_372(dm_build_480) +func (access *Access) Dm_build_476(dm_build_478 *DmStatement, dm_build_479 string) error { + dm_build_480 := dm_build_817(access, dm_build_478, dm_build_479) + _, dm_build_481 := access.dm_build_372(dm_build_480) if dm_build_481 != nil { return dm_build_481 } @@ -511,49 +510,49 @@ func (dm_build_477 *dm_build_332) Dm_build_476(dm_build_478 *DmStatement, dm_bui return nil } -func (dm_build_483 *dm_build_332) Dm_build_482(dm_build_484 []uint32) ([]int64, error) { - dm_build_485 := dm_build_1208(dm_build_483, dm_build_484) - dm_build_486, dm_build_487 := dm_build_483.dm_build_372(dm_build_485) +func (access *Access) Dm_build_482(dm_build_484 []uint32) ([]int64, error) { + dm_build_485 := dm_build_1208(access, dm_build_484) + dm_build_486, dm_build_487 := access.dm_build_372(dm_build_485) if dm_build_487 != nil { return nil, dm_build_487 } return dm_build_486.([]int64), nil } -func (dm_build_489 *dm_build_332) Close() error { - if dm_build_489.dm_build_343 { +func (access *Access) Close() error { + if access.dm_build_343 { return nil } - dm_build_490 := dm_build_489.dm_build_333.Close() + dm_build_490 := access.tcpConn.Close() if dm_build_490 != nil { return dm_build_490 } - dm_build_489.dm_build_336 = nil - dm_build_489.dm_build_343 = true + access.conn = nil + access.dm_build_343 = true return nil } -func (dm_build_492 *dm_build_332) dm_build_491(dm_build_493 *lob) (int64, error) { - dm_build_494 := dm_build_980(dm_build_492, dm_build_493) - dm_build_495, dm_build_496 := dm_build_492.dm_build_372(dm_build_494) +func (access *Access) dm_build_491(dm_build_493 *lob) (int64, error) { + dm_build_494 := dm_build_980(access, dm_build_493) + dm_build_495, dm_build_496 := access.dm_build_372(dm_build_494) if dm_build_496 != nil { return 0, dm_build_496 } return dm_build_495.(int64), nil } -func (dm_build_498 *dm_build_332) dm_build_497(dm_build_499 *lob, dm_build_500 int32, dm_build_501 int32) ([]byte, error) { - dm_build_502 := dm_build_967(dm_build_498, dm_build_499, int(dm_build_500), int(dm_build_501)) - dm_build_503, dm_build_504 := dm_build_498.dm_build_372(dm_build_502) +func (access *Access) dm_build_497(dm_build_499 *lob, dm_build_500 int32, dm_build_501 int32) ([]byte, error) { + dm_build_502 := dm_build_967(access, dm_build_499, int(dm_build_500), int(dm_build_501)) + dm_build_503, dm_build_504 := access.dm_build_372(dm_build_502) if dm_build_504 != nil { return nil, dm_build_504 } return dm_build_503.([]byte), nil } -func (dm_build_506 *dm_build_332) dm_build_505(dm_build_507 *DmBlob, dm_build_508 int32, dm_build_509 int32) ([]byte, error) { +func (access *Access) dm_build_505(dm_build_507 *DmBlob, dm_build_508 int32, dm_build_509 int32) ([]byte, error) { var dm_build_510 = make([]byte, dm_build_509) var dm_build_511 int32 = 0 var dm_build_512 int32 = 0 @@ -564,7 +563,7 @@ func (dm_build_506 *dm_build_332) dm_build_505(dm_build_507 *DmBlob, dm_build_50 if dm_build_512 > Dm_build_717 { dm_build_512 = Dm_build_717 } - dm_build_513, dm_build_514 = dm_build_506.dm_build_497(&dm_build_507.lob, dm_build_508, dm_build_512) + dm_build_513, dm_build_514 = access.dm_build_497(&dm_build_507.lob, dm_build_508, dm_build_512) if dm_build_514 != nil { return nil, dm_build_514 } @@ -581,7 +580,7 @@ func (dm_build_506 *dm_build_332) dm_build_505(dm_build_507 *DmBlob, dm_build_50 return dm_build_510, nil } -func (dm_build_516 *dm_build_332) dm_build_515(dm_build_517 *DmClob, dm_build_518 int32, dm_build_519 int32) (string, error) { +func (access *Access) dm_build_515(dm_build_517 *DmClob, dm_build_518 int32, dm_build_519 int32) (string, error) { var dm_build_520 bytes.Buffer var dm_build_521 int32 = 0 var dm_build_522 int32 = 0 @@ -593,14 +592,14 @@ func (dm_build_516 *dm_build_332) dm_build_515(dm_build_517 *DmClob, dm_build_51 if dm_build_522 > Dm_build_717/2 { dm_build_522 = Dm_build_717 / 2 } - dm_build_523, dm_build_525 = dm_build_516.dm_build_497(&dm_build_517.lob, dm_build_518, dm_build_522) + dm_build_523, dm_build_525 = access.dm_build_497(&dm_build_517.lob, dm_build_518, dm_build_522) if dm_build_525 != nil { return "", dm_build_525 } if dm_build_523 == nil || len(dm_build_523) == 0 { break } - dm_build_524 = Dm_build_1219.Dm_build_1376(dm_build_523, 0, len(dm_build_523), dm_build_517.serverEncoding, dm_build_516.dm_build_336) + dm_build_524 = Dm_build_1219.Dm_build_1376(dm_build_523, 0, len(dm_build_523), dm_build_517.serverEncoding, access.conn) dm_build_520.WriteString(dm_build_524) dm_build_521 += int32(len(dm_build_524)) @@ -612,8 +611,8 @@ func (dm_build_516 *dm_build_332) dm_build_515(dm_build_517 *DmClob, dm_build_51 return dm_build_520.String(), nil } -func (dm_build_527 *dm_build_332) dm_build_526(dm_build_528 *DmClob, dm_build_529 int, dm_build_530 string, dm_build_531 string) (int, error) { - var dm_build_532 = Dm_build_1219.Dm_build_1432(dm_build_530, dm_build_531, dm_build_527.dm_build_336) +func (access *Access) dm_build_526(dm_build_528 *DmClob, dm_build_529 int, dm_build_530 string, dm_build_531 string) (int, error) { + var dm_build_532 = Dm_build_1219.Dm_build_1432(dm_build_530, dm_build_531, access.conn) var dm_build_533 = 0 var dm_build_534 = len(dm_build_532) var dm_build_535 = 0 @@ -636,8 +635,8 @@ func (dm_build_527 *dm_build_332) dm_build_526(dm_build_528 *DmClob, dm_build_52 dm_build_537 = Dm_build_716 } - setLobData := dm_build_1124(dm_build_527, &dm_build_528.lob, dm_build_539, dm_build_529, dm_build_532, dm_build_533, dm_build_537) - ret, err := dm_build_527.dm_build_372(setLobData) + setLobData := dm_build_1124(access, &dm_build_528.lob, dm_build_539, dm_build_529, dm_build_532, dm_build_533, dm_build_537) + ret, err := access.dm_build_372(setLobData) if err != nil { return 0, err } @@ -657,7 +656,7 @@ func (dm_build_527 *dm_build_332) dm_build_526(dm_build_528 *DmClob, dm_build_52 return dm_build_535, nil } -func (dm_build_543 *dm_build_332) dm_build_542(dm_build_544 *DmBlob, dm_build_545 int, dm_build_546 []byte) (int, error) { +func (access *Access) dm_build_542(dm_build_544 *DmBlob, dm_build_545 int, dm_build_546 []byte) (int, error) { var dm_build_547 = 0 var dm_build_548 = len(dm_build_546) var dm_build_549 = 0 @@ -680,8 +679,8 @@ func (dm_build_543 *dm_build_332) dm_build_542(dm_build_544 *DmBlob, dm_build_54 dm_build_551 = Dm_build_716 } - setLobData := dm_build_1124(dm_build_543, &dm_build_544.lob, dm_build_553, dm_build_545, dm_build_546, dm_build_547, dm_build_551) - ret, err := dm_build_543.dm_build_372(setLobData) + setLobData := dm_build_1124(access, &dm_build_544.lob, dm_build_553, dm_build_545, dm_build_546, dm_build_547, dm_build_551) + ret, err := access.dm_build_372(setLobData) if err != nil { return 0, err } @@ -698,16 +697,16 @@ func (dm_build_543 *dm_build_332) dm_build_542(dm_build_544 *DmBlob, dm_build_54 return dm_build_549, nil } -func (dm_build_557 *dm_build_332) dm_build_556(dm_build_558 *lob, dm_build_559 int) (int64, error) { - dm_build_560 := dm_build_991(dm_build_557, dm_build_558, dm_build_559) - dm_build_561, dm_build_562 := dm_build_557.dm_build_372(dm_build_560) +func (access *Access) dm_build_556(dm_build_558 *lob, dm_build_559 int) (int64, error) { + dm_build_560 := dm_build_991(access, dm_build_558, dm_build_559) + dm_build_561, dm_build_562 := access.dm_build_372(dm_build_560) if dm_build_562 != nil { return dm_build_558.length, dm_build_562 } return dm_build_561.(int64), nil } -func (dm_build_564 *dm_build_332) dm_build_563(dm_build_565 []interface{}, dm_build_566 []interface{}, dm_build_567 int) bool { +func (access *Access) dm_build_563(dm_build_565 []interface{}, dm_build_566 []interface{}, dm_build_567 int) bool { var dm_build_568 = false if dm_build_567 >= len(dm_build_566) || dm_build_566[dm_build_567] == nil { dm_build_565[dm_build_567] = ParamDataEnum_Null @@ -720,7 +719,7 @@ func (dm_build_564 *dm_build_332) dm_build_563(dm_build_565 []interface{}, dm_bu } else if l, ok := binder.getObj().(DmClob); ok { lob = l.lob } - if &lob != nil && lob.canOptimized(dm_build_564.dm_build_336) { + if &lob != nil && lob.canOptimized(access.conn) { dm_build_565[dm_build_567] = &lobCtl{lob.buildCtlData()} dm_build_568 = false } @@ -730,7 +729,7 @@ func (dm_build_564 *dm_build_332) dm_build_563(dm_build_565 []interface{}, dm_bu return dm_build_568 } -func (dm_build_570 *dm_build_332) dm_build_569(dm_build_571 *DmStatement, dm_build_572 parameter, dm_build_573 int, dm_build_574 iOffRowBinder) error { +func (access *Access) dm_build_569(dm_build_571 *DmStatement, dm_build_572 parameter, dm_build_573 int, dm_build_574 iOffRowBinder) error { var dm_build_575 = Dm_build_1502() dm_build_574.read(dm_build_575) var dm_build_576 = 0 @@ -744,8 +743,8 @@ func (dm_build_570 *dm_build_332) dm_build_569(dm_build_571 *DmStatement, dm_bui dm_build_576 = dm_build_575.Dm_build_1503() } - putData := dm_build_1095(dm_build_570, dm_build_571, int16(dm_build_573), dm_build_575, int32(dm_build_576)) - _, err := dm_build_570.dm_build_372(putData) + putData := dm_build_1095(access, dm_build_571, int16(dm_build_573), dm_build_575, int32(dm_build_576)) + _, err := access.dm_build_372(putData) if err != nil { return err } @@ -753,47 +752,47 @@ func (dm_build_570 *dm_build_332) dm_build_569(dm_build_571 *DmStatement, dm_bui return nil } -func (dm_build_578 *dm_build_332) dm_build_577() ([]byte, error) { +func (access *Access) dm_build_577() ([]byte, error) { var dm_build_579 error - if dm_build_578.dm_build_340 == nil { - if dm_build_578.dm_build_340, dm_build_579 = security.NewClientKeyPair(); dm_build_579 != nil { + if access.dm_build_340 == nil { + if access.dm_build_340, dm_build_579 = security.NewClientKeyPair(); dm_build_579 != nil { return nil, dm_build_579 } } - return security.Bn2Bytes(dm_build_578.dm_build_340.GetY(), security.DH_KEY_LENGTH), nil + return security.Bn2Bytes(access.dm_build_340.GetY(), security.DH_KEY_LENGTH), nil } -func (dm_build_581 *dm_build_332) dm_build_580() (*security.DhKey, error) { +func (access *Access) dm_build_580() (*security.DhKey, error) { var dm_build_582 error - if dm_build_581.dm_build_340 == nil { - if dm_build_581.dm_build_340, dm_build_582 = security.NewClientKeyPair(); dm_build_582 != nil { + if access.dm_build_340 == nil { + if access.dm_build_340, dm_build_582 = security.NewClientKeyPair(); dm_build_582 != nil { return nil, dm_build_582 } } - return dm_build_581.dm_build_340, nil + return access.dm_build_340, nil } -func (dm_build_584 *dm_build_332) dm_build_583(dm_build_585 int, dm_build_586 []byte, dm_build_587 string, dm_build_588 int) (dm_build_589 error) { +func (access *Access) dm_build_583(dm_build_585 int, dm_build_586 []byte, dm_build_587 string, dm_build_588 int) (dm_build_589 error) { if dm_build_585 > 0 && dm_build_585 < security.MIN_EXTERNAL_CIPHER_ID && dm_build_586 != nil { - dm_build_584.dm_build_337, dm_build_589 = security.NewSymmCipher(dm_build_585, dm_build_586) + access.dm_build_337, dm_build_589 = security.NewSymmCipher(dm_build_585, dm_build_586) } else if dm_build_585 >= security.MIN_EXTERNAL_CIPHER_ID { - if dm_build_584.dm_build_337, dm_build_589 = security.NewThirdPartCipher(dm_build_585, dm_build_586, dm_build_587, dm_build_588); dm_build_589 != nil { + if access.dm_build_337, dm_build_589 = security.NewThirdPartCipher(dm_build_585, dm_build_586, dm_build_587, dm_build_588); dm_build_589 != nil { dm_build_589 = THIRD_PART_CIPHER_INIT_FAILED.addDetailln(dm_build_589.Error()).throw() } } return } -func (dm_build_591 *dm_build_332) dm_build_590(dm_build_592 bool) (dm_build_593 error) { - if dm_build_591.dm_build_334, dm_build_593 = security.NewTLSFromTCP(dm_build_591.dm_build_333, dm_build_591.dm_build_336.dmConnector.sslCertPath, dm_build_591.dm_build_336.dmConnector.sslKeyPath, dm_build_591.dm_build_336.dmConnector.user); dm_build_593 != nil { +func (access *Access) dm_build_590(dm_build_592 bool) (dm_build_593 error) { + if access.tlsConn, dm_build_593 = security.NewTLSFromTCP(access.tcpConn, access.conn.dmConnector.sslCertPath, access.conn.dmConnector.sslKeyPath, access.conn.dmConnector.user); dm_build_593 != nil { return } if !dm_build_592 { - dm_build_591.dm_build_334 = nil + access.tlsConn = nil } return } -func (dm_build_595 *dm_build_332) dm_build_594(dm_build_596 dm_build_724) bool { - return dm_build_596.dm_build_739() != Dm_build_631 && dm_build_595.dm_build_336.sslEncrypt == 1 +func (access *Access) dm_build_594(dm_build_596 dm_build_724) bool { + return dm_build_596.dm_build_739() != Dm_build_631 && access.conn.sslEncrypt == 1 } diff --git a/b.go b/b.go index 6939100..70e203a 100644 --- a/b.go +++ b/b.go @@ -9,7 +9,7 @@ type ArrayDescriptor struct { m_typeDesc *TypeDescriptor } -func newArrayDescriptor(fulName string, conn *DmConnection) (*ArrayDescriptor, error) { +func newArrayDescriptor(fulName string, conn *Connection) (*ArrayDescriptor, error) { ad := new(ArrayDescriptor) diff --git a/c.go b/c.go index 0d9302c..563d07d 100644 --- a/c.go +++ b/c.go @@ -205,22 +205,22 @@ func (dm_build_93 *Dm_build_0) Dm_build_92(dm_build_94 []byte) int { return dm_build_93.Dm_build_79(dm_build_94) + dm_build_93.Dm_build_43(0) } -func (dm_build_96 *Dm_build_0) Dm_build_95(dm_build_97 string, dm_build_98 string, dm_build_99 *DmConnection) int { +func (dm_build_96 *Dm_build_0) Dm_build_95(dm_build_97 string, dm_build_98 string, dm_build_99 *Connection) int { dm_build_100 := Dm_build_1219.Dm_build_1432(dm_build_97, dm_build_98, dm_build_99) return dm_build_96.Dm_build_83(dm_build_100) } -func (dm_build_102 *Dm_build_0) Dm_build_101(dm_build_103 string, dm_build_104 string, dm_build_105 *DmConnection) int { +func (dm_build_102 *Dm_build_0) Dm_build_101(dm_build_103 string, dm_build_104 string, dm_build_105 *Connection) int { dm_build_106 := Dm_build_1219.Dm_build_1432(dm_build_103, dm_build_104, dm_build_105) return dm_build_102.Dm_build_86(dm_build_106) } -func (dm_build_108 *Dm_build_0) Dm_build_107(dm_build_109 string, dm_build_110 string, dm_build_111 *DmConnection) int { +func (dm_build_108 *Dm_build_0) Dm_build_107(dm_build_109 string, dm_build_110 string, dm_build_111 *Connection) int { dm_build_112 := Dm_build_1219.Dm_build_1432(dm_build_109, dm_build_110, dm_build_111) return dm_build_108.Dm_build_89(dm_build_112) } -func (dm_build_114 *Dm_build_0) Dm_build_113(dm_build_115 string, dm_build_116 string, dm_build_117 *DmConnection) int { +func (dm_build_114 *Dm_build_0) Dm_build_113(dm_build_115 string, dm_build_116 string, dm_build_117 *Connection) int { dm_build_118 := Dm_build_1219.Dm_build_1432(dm_build_115, dm_build_116, dm_build_117) return dm_build_114.Dm_build_92(dm_build_118) } @@ -310,23 +310,23 @@ func (dm_build_160 *Dm_build_0) Dm_build_159() []byte { return dm_build_160.Dm_build_146(dm_build_161) } -func (dm_build_163 *Dm_build_0) Dm_build_162(dm_build_164 int, dm_build_165 string, dm_build_166 *DmConnection) string { +func (dm_build_163 *Dm_build_0) Dm_build_162(dm_build_164 int, dm_build_165 string, dm_build_166 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_163.Dm_build_146(dm_build_164), dm_build_165, dm_build_166) } -func (dm_build_168 *Dm_build_0) Dm_build_167(dm_build_169 string, dm_build_170 *DmConnection) string { +func (dm_build_168 *Dm_build_0) Dm_build_167(dm_build_169 string, dm_build_170 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_168.Dm_build_150(), dm_build_169, dm_build_170) } -func (dm_build_172 *Dm_build_0) Dm_build_171(dm_build_173 string, dm_build_174 *DmConnection) string { +func (dm_build_172 *Dm_build_0) Dm_build_171(dm_build_173 string, dm_build_174 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_172.Dm_build_152(), dm_build_173, dm_build_174) } -func (dm_build_176 *Dm_build_0) Dm_build_175(dm_build_177 string, dm_build_178 *DmConnection) string { +func (dm_build_176 *Dm_build_0) Dm_build_175(dm_build_177 string, dm_build_178 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_176.Dm_build_154(), dm_build_177, dm_build_178) } -func (dm_build_180 *Dm_build_0) Dm_build_179(dm_build_181 string, dm_build_182 *DmConnection) string { +func (dm_build_180 *Dm_build_0) Dm_build_179(dm_build_181 string, dm_build_182 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_180.Dm_build_159(), dm_build_181, dm_build_182) } @@ -386,19 +386,19 @@ func (dm_build_236 *Dm_build_0) Dm_build_235(dm_build_237 int, dm_build_238 []by return dm_build_236.Dm_build_219(dm_build_237, dm_build_238) + dm_build_236.Dm_build_183(dm_build_237+len(dm_build_238), 0) } -func (dm_build_240 *Dm_build_0) Dm_build_239(dm_build_241 int, dm_build_242 string, dm_build_243 string, dm_build_244 *DmConnection) int { +func (dm_build_240 *Dm_build_0) Dm_build_239(dm_build_241 int, dm_build_242 string, dm_build_243 string, dm_build_244 *Connection) int { return dm_build_240.Dm_build_223(dm_build_241, Dm_build_1219.Dm_build_1432(dm_build_242, dm_build_243, dm_build_244)) } -func (dm_build_246 *Dm_build_0) Dm_build_245(dm_build_247 int, dm_build_248 string, dm_build_249 string, dm_build_250 *DmConnection) int { +func (dm_build_246 *Dm_build_0) Dm_build_245(dm_build_247 int, dm_build_248 string, dm_build_249 string, dm_build_250 *Connection) int { return dm_build_246.Dm_build_227(dm_build_247, Dm_build_1219.Dm_build_1432(dm_build_248, dm_build_249, dm_build_250)) } -func (dm_build_252 *Dm_build_0) Dm_build_251(dm_build_253 int, dm_build_254 string, dm_build_255 string, dm_build_256 *DmConnection) int { +func (dm_build_252 *Dm_build_0) Dm_build_251(dm_build_253 int, dm_build_254 string, dm_build_255 string, dm_build_256 *Connection) int { return dm_build_252.Dm_build_231(dm_build_253, Dm_build_1219.Dm_build_1432(dm_build_254, dm_build_255, dm_build_256)) } -func (dm_build_258 *Dm_build_0) Dm_build_257(dm_build_259 int, dm_build_260 string, dm_build_261 string, dm_build_262 *DmConnection) int { +func (dm_build_258 *Dm_build_0) Dm_build_257(dm_build_259 int, dm_build_260 string, dm_build_261 string, dm_build_262 *Connection) int { return dm_build_258.Dm_build_235(dm_build_259, Dm_build_1219.Dm_build_1432(dm_build_260, dm_build_261, dm_build_262)) } @@ -467,18 +467,18 @@ func (dm_build_307 *Dm_build_0) Dm_build_306(dm_build_308 int) []byte { return dm_build_307.Dm_build_290(dm_build_308-dm_build_309, int(dm_build_309)) } -func (dm_build_311 *Dm_build_0) Dm_build_310(dm_build_312 int, dm_build_313 string, dm_build_314 *DmConnection) string { +func (dm_build_311 *Dm_build_0) Dm_build_310(dm_build_312 int, dm_build_313 string, dm_build_314 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_311.Dm_build_294(dm_build_312), dm_build_313, dm_build_314) } -func (dm_build_316 *Dm_build_0) Dm_build_315(dm_build_317 int, dm_build_318 string, dm_build_319 *DmConnection) string { +func (dm_build_316 *Dm_build_0) Dm_build_315(dm_build_317 int, dm_build_318 string, dm_build_319 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_316.Dm_build_298(dm_build_317), dm_build_318, dm_build_319) } -func (dm_build_321 *Dm_build_0) Dm_build_320(dm_build_322 int, dm_build_323 string, dm_build_324 *DmConnection) string { +func (dm_build_321 *Dm_build_0) Dm_build_320(dm_build_322 int, dm_build_323 string, dm_build_324 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_321.Dm_build_302(dm_build_322), dm_build_323, dm_build_324) } -func (dm_build_326 *Dm_build_0) Dm_build_325(dm_build_327 int, dm_build_328 string, dm_build_329 *DmConnection) string { +func (dm_build_326 *Dm_build_0) Dm_build_325(dm_build_327 int, dm_build_328 string, dm_build_329 *Connection) string { return Dm_build_1219.Dm_build_1469(dm_build_326.Dm_build_306(dm_build_327), dm_build_328, dm_build_329) } diff --git a/connection.go b/connection.go new file mode 100644 index 0000000..e72be1f --- /dev/null +++ b/connection.go @@ -0,0 +1,869 @@ +/* + * Copyright (c) 2000-2018, 达梦数据库有限公司. + * All rights reserved. + */ +package dm + +import ( + "bytes" + "context" + "database/sql" + "database/sql/driver" + "fmt" + "sync/atomic" + + "github.com/gotomicro/dmgo/parser" + "golang.org/x/text/encoding" +) + +type Connection struct { + filterable + + dmConnector *Connector + Access *Access + stmtMap map[int32]*DmStatement + stmtPool []stmtPoolInfo + lastExecInfo *execRetInfo + lexer *parser.Lexer + encode encoding.Encoding + encodeBuffer *bytes.Buffer + transformReaderDst []byte + transformReaderSrc []byte + + serverEncoding string + GlobalServerSeries int + ServerVersion string + Malini2 bool + Execute2 bool + LobEmptyCompOrcl bool + IsoLevel int32 + ReadOnly bool + NewLobFlag bool + sslEncrypt int + MaxRowSize int32 + DDLAutoCommit bool + BackslashEscape bool + SvrStat int32 + SvrMode int32 + ConstParaOpt bool + DbTimezone int16 + LifeTimeRemainder int16 + InstanceName string + Schema string + LastLoginIP string + LastLoginTime string + FailedAttempts int32 + LoginWarningID int32 + GraceTimeRemainder int32 + Guid string + DbName string + StandbyHost string + StandbyPort int32 + StandbyCount int32 + SessionID int64 + OracleDateLanguage byte + FormatDate string + FormatTimestamp string + FormatTimestampTZ string + FormatTime string + FormatTimeTZ string + Local bool + MsgVersion int32 + TrxStatus int32 + dscControl bool + trxFinish bool + sessionID int64 + autoCommit bool + isBatch bool + + watching bool + watcher chan<- context.Context + closech chan struct{} + finished chan<- struct{} + canceled atomicError + closed atomicBool +} + +func (dmConn *Connection) setTrxFinish(status int32) { + switch status & Dm_build_721 { + case Dm_build_718, Dm_build_719, Dm_build_720: + dmConn.trxFinish = true + default: + dmConn.trxFinish = false + } +} + +func (dmConn *Connection) init() { + if dmConn.dmConnector.stmtPoolMaxSize > 0 { + dmConn.stmtPool = make([]stmtPoolInfo, 0, dmConn.dmConnector.stmtPoolMaxSize) + } + + dmConn.stmtMap = make(map[int32]*DmStatement) + dmConn.DbTimezone = 0 + dmConn.GlobalServerSeries = 0 + dmConn.MaxRowSize = 0 + dmConn.LobEmptyCompOrcl = false + dmConn.ReadOnly = false + dmConn.DDLAutoCommit = false + dmConn.ConstParaOpt = false + dmConn.IsoLevel = -1 + dmConn.sessionID = -1 + dmConn.Malini2 = true + dmConn.NewLobFlag = true + dmConn.Execute2 = true + dmConn.serverEncoding = ENCODING_GB18030 + dmConn.TrxStatus = Dm_build_669 + dmConn.OracleDateLanguage = byte(Locale) + dmConn.lastExecInfo = NewExceInfo() + dmConn.MsgVersion = Dm_build_603 + + dmConn.idGenerator = dmConnIDGenerator +} + +func (dmConn *Connection) reset() { + dmConn.DbTimezone = 0 + dmConn.GlobalServerSeries = 0 + dmConn.MaxRowSize = 0 + dmConn.LobEmptyCompOrcl = false + dmConn.ReadOnly = false + dmConn.DDLAutoCommit = false + dmConn.ConstParaOpt = false + dmConn.IsoLevel = -1 + dmConn.sessionID = -1 + dmConn.Malini2 = true + dmConn.NewLobFlag = true + dmConn.Execute2 = true + dmConn.serverEncoding = ENCODING_GB18030 + dmConn.TrxStatus = Dm_build_669 +} + +func (dmConn *Connection) checkClosed() error { + if dmConn.closed.IsSet() { + return driver.ErrBadConn + } + + return nil +} + +func (dmConn *Connection) executeInner(query string, execType int16) (interface{}, error) { + + stmt, err := NewDmStmt(dmConn, query) + + if err != nil { + return nil, err + } + + if execType == Dm_build_686 { + defer stmt.close() + } + + stmt.innerUsed = true + if stmt.dmConn.dmConnector.escapeProcess { + stmt.nativeSql, err = stmt.dmConn.escape(stmt.nativeSql, stmt.dmConn.dmConnector.keyWords) + if err != nil { + stmt.close() + return nil, err + } + } + + var optParamList []OptParameter + + if stmt.dmConn.ConstParaOpt { + optParamList = make([]OptParameter, 0) + stmt.nativeSql, optParamList, err = stmt.dmConn.execOpt(stmt.nativeSql, optParamList, stmt.dmConn.getServerEncoding()) + if err != nil { + stmt.close() + optParamList = nil + } + } + + if execType == Dm_build_685 && dmConn.dmConnector.enRsCache { + rpv, err := rp.get(stmt, query) + if err != nil { + return nil, err + } + + if rpv != nil { + stmt.execInfo = rpv.execInfo + dmConn.lastExecInfo = rpv.execInfo + return newDmRows(rpv.getResultSet(stmt)), nil + } + } + + var info *execRetInfo + + if optParamList != nil && len(optParamList) > 0 { + info, err = dmConn.Access.Dm_build_411(stmt, optParamList) + if err != nil { + stmt.nativeSql = query + info, err = dmConn.Access.Dm_build_417(stmt, execType) + } + } else { + info, err = dmConn.Access.Dm_build_417(stmt, execType) + } + + if err != nil { + stmt.close() + return nil, err + } + dmConn.lastExecInfo = info + + if info.hasResultSet { + return newDmRows(newInnerRows(0, stmt, info)), nil + } else { + return newDmResult(stmt, info), nil + } +} + +func g2dbIsoLevel(isoLevel int32) int32 { + switch isoLevel { + case 1: + return Dm_build_673 + case 2: + return Dm_build_674 + case 4: + return Dm_build_675 + case 6: + return Dm_build_676 + default: + return -1 + } +} + +func (dmConn *Connection) Begin() (driver.Tx, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.begin() + } else { + return dmConn.filterChain.reset().DmConnectionBegin(dmConn) + } +} + +func (dmConn *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.beginTx(ctx, opts) + } + return dmConn.filterChain.reset().DmConnectionBeginTx(dmConn, ctx, opts) +} + +func (dmConn *Connection) Commit() error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.commit() + } else { + return dmConn.filterChain.reset().DmConnectionCommit(dmConn) + } +} + +func (dmConn *Connection) Rollback() error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.rollback() + } else { + return dmConn.filterChain.reset().DmConnectionRollback(dmConn) + } +} + +func (dmConn *Connection) Close() error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.close() + } else { + return dmConn.filterChain.reset().DmConnectionClose(dmConn) + } +} + +func (dmConn *Connection) Ping(ctx context.Context) error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.ping(ctx) + } else { + return dmConn.filterChain.reset().DmConnectionPing(dmConn, ctx) + } +} + +func (dmConn *Connection) Exec(query string, args []driver.Value) (driver.Result, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.exec(query, args) + } + return dmConn.filterChain.reset().DmConnectionExec(dmConn, query, args) +} + +func (dmConn *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.execContext(ctx, query, args) + } + return dmConn.filterChain.reset().DmConnectionExecContext(dmConn, ctx, query, args) +} + +func (dmConn *Connection) Query(query string, args []driver.Value) (driver.Rows, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.query(query, args) + } + return dmConn.filterChain.reset().DmConnectionQuery(dmConn, query, args) +} + +func (dmConn *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.queryContext(ctx, query, args) + } + return dmConn.filterChain.reset().DmConnectionQueryContext(dmConn, ctx, query, args) +} + +func (dmConn *Connection) Prepare(query string) (driver.Stmt, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.prepare(query) + } + return dmConn.filterChain.reset().DmConnectionPrepare(dmConn, query) +} + +func (dmConn *Connection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.prepareContext(ctx, query) + } + return dmConn.filterChain.reset().DmConnectionPrepareContext(dmConn, ctx, query) +} + +func (dmConn *Connection) ResetSession(ctx context.Context) error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.resetSession(ctx) + } + return dmConn.filterChain.reset().DmConnectionResetSession(dmConn, ctx) +} + +func (dmConn *Connection) CheckNamedValue(nv *driver.NamedValue) error { + if len(dmConn.filterChain.filters) == 0 { + return dmConn.checkNamedValue(nv) + } + return dmConn.filterChain.reset().DmConnectionCheckNamedValue(dmConn, nv) +} + +func (dmConn *Connection) begin() (*Connection, error) { + return dmConn.beginTx(context.Background(), driver.TxOptions{driver.IsolationLevel(sql.LevelDefault), false}) +} + +func (dmConn *Connection) beginTx(ctx context.Context, opts driver.TxOptions) (*Connection, error) { + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if err := dmConn.watchCancel(ctx); err != nil { + return nil, err + } + defer dmConn.finish() + + if sql.IsolationLevel(opts.Isolation) == sql.LevelDefault { + opts.Isolation = driver.IsolationLevel(sql.LevelReadCommitted) + } + + dmConn.ReadOnly = opts.ReadOnly + + if dmConn.IsoLevel == int32(opts.Isolation) { + return dmConn, nil + } + + switch sql.IsolationLevel(opts.Isolation) { + case sql.LevelDefault: + return dmConn, nil + case sql.LevelReadUncommitted, sql.LevelReadCommitted, sql.LevelSerializable: + dmConn.IsoLevel = int32(opts.Isolation) + case sql.LevelRepeatableRead: + if dmConn.CompatibleMysql() { + dmConn.IsoLevel = int32(sql.LevelReadCommitted) + } else { + return nil, ECGO_INVALID_TRAN_ISOLATION.throw() + } + default: + return nil, ECGO_INVALID_TRAN_ISOLATION.throw() + } + + err = dmConn.Access.Dm_build_471(dmConn) + if err != nil { + return nil, err + } + return dmConn, nil +} + +func (dmConn *Connection) commit() error { + err := dmConn.checkClosed() + if err != nil { + return err + } + + defer func() { + dmConn.autoCommit = dmConn.dmConnector.autoCommit + }() + + if !dmConn.autoCommit { + err = dmConn.Access.Commit() + if err != nil { + return err + } + dmConn.trxFinish = true + return nil + } else if !dmConn.dmConnector.alwayseAllowCommit { + return ECGO_COMMIT_IN_AUTOCOMMIT_MODE.throw() + } + + return nil +} + +func (dmConn *Connection) rollback() error { + err := dmConn.checkClosed() + if err != nil { + return err + } + + defer func() { + dmConn.autoCommit = dmConn.dmConnector.autoCommit + }() + + if !dmConn.autoCommit { + err = dmConn.Access.Rollback() + if err != nil { + return err + } + dmConn.trxFinish = true + return nil + } else if !dmConn.dmConnector.alwayseAllowCommit { + return ECGO_ROLLBACK_IN_AUTOCOMMIT_MODE.throw() + } + + return nil +} + +func (dmConn *Connection) reconnect() error { + err := dmConn.Access.Close() + if err != nil { + return err + } + + for _, stmt := range dmConn.stmtMap { + stmt.closed = true + for id, _ := range stmt.rsMap { + delete(stmt.rsMap, id) + } + } + + if dmConn.stmtPool != nil { + dmConn.stmtPool = dmConn.stmtPool[:0] + } + + dmConn.dmConnector.reConnection = dmConn + + if dmConn.dmConnector.group != nil { + _, err = dmConn.dmConnector.group.connect(dmConn.dmConnector) + if err != nil { + return err + } + } else { + _, err = dmConn.dmConnector.connect(context.Background()) + } + + for _, stmt := range dmConn.stmtMap { + err = dmConn.Access.Dm_build_389(stmt) + if err != nil { + return err + } + + if stmt.paramCount > 0 { + err = stmt.prepare() + if err != nil { + return err + } + } + } + + return nil +} + +func (dmConn *Connection) close() error { + if dmConn.closed.IsSet() { + return nil + } + + close(dmConn.closech) + if dmConn.Access == nil { + return nil + } + + err := dmConn.rollback() + if err != nil { + return err + } + + for _, stmt := range dmConn.stmtMap { + err = stmt.free() + if err != nil { + return err + } + } + + if dmConn.stmtPool != nil { + for _, spi := range dmConn.stmtPool { + err = dmConn.Access.Dm_build_394(spi.id) + if err != nil { + return err + } + } + dmConn.stmtPool = nil + } + + err = dmConn.Access.Close() + if err != nil { + return err + } + + dmConn.closed.Set(true) + return nil +} + +func (dmConn *Connection) ping(ctx context.Context) error { + rows, err := dmConn.query("select 1", nil) + if err != nil { + return err + } + return rows.close() +} + +func (dmConn *Connection) exec(query string, args []driver.Value) (*DmResult, error) { + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if args != nil && len(args) > 0 { + stmt, err := dmConn.prepare(query) + defer stmt.close() + if err != nil { + return nil, err + } + dmConn.lastExecInfo = stmt.execInfo + + return stmt.exec(args) + } else { + r1, err := dmConn.executeInner(query, Dm_build_686) + if err != nil { + return nil, err + } + + if r2, ok := r1.(*DmResult); ok { + return r2, nil + } else { + return nil, ECGO_NOT_EXEC_SQL.throw() + } + } +} + +func (dmConn *Connection) execContext(ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { + + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if err := dmConn.watchCancel(ctx); err != nil { + return nil, err + } + defer dmConn.finish() + + if args != nil && len(args) > 0 { + stmt, err := dmConn.prepare(query) + defer stmt.close() + if err != nil { + return nil, err + } + dmConn.lastExecInfo = stmt.execInfo + + return stmt.execContext(ctx, args) + } else { + r1, err := dmConn.executeInner(query, Dm_build_686) + if err != nil { + return nil, err + } + + if r2, ok := r1.(*DmResult); ok { + return r2, nil + } else { + return nil, ECGO_NOT_EXEC_SQL.throw() + } + } +} + +func (dmConn *Connection) query(query string, args []driver.Value) (*DmRows, error) { + + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if args != nil && len(args) > 0 { + stmt, err := dmConn.prepare(query) + if err != nil { + stmt.close() + return nil, err + } + dmConn.lastExecInfo = stmt.execInfo + + stmt.innerUsed = true + return stmt.query(args) + + } else { + r1, err := dmConn.executeInner(query, Dm_build_685) + if err != nil { + return nil, err + } + + if r2, ok := r1.(*DmRows); ok { + return r2, nil + } else { + return nil, ECGO_NOT_QUERY_SQL.throw() + } + } +} + +func (dmConn *Connection) queryContext(ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { + + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if err := dmConn.watchCancel(ctx); err != nil { + return nil, err + } + defer dmConn.finish() + + if args != nil && len(args) > 0 { + stmt, err := dmConn.prepare(query) + if err != nil { + stmt.close() + return nil, err + } + dmConn.lastExecInfo = stmt.execInfo + + stmt.innerUsed = true + return stmt.queryContext(ctx, args) + + } else { + r1, err := dmConn.executeInner(query, Dm_build_685) + if err != nil { + return nil, err + } + + if r2, ok := r1.(*DmRows); ok { + return r2, nil + } else { + return nil, ECGO_NOT_QUERY_SQL.throw() + } + } + +} + +func (dmConn *Connection) prepare(query string) (*DmStatement, error) { + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + stmt, err := NewDmStmt(dmConn, query) + if err != nil { + return nil, err + } + + err = stmt.prepare() + return stmt, err +} + +func (dmConn *Connection) prepareContext(ctx context.Context, query string) (*DmStatement, error) { + err := dmConn.checkClosed() + if err != nil { + return nil, err + } + + if err := dmConn.watchCancel(ctx); err != nil { + return nil, err + } + defer dmConn.finish() + + stmt, err := dmConn.prepare(query) + if err != nil { + return nil, err + } + + return stmt, nil +} + +func (dmConn *Connection) resetSession(ctx context.Context) error { + err := dmConn.checkClosed() + if err != nil { + return err + } + + for _, stmt := range dmConn.stmtMap { + stmt.inUse = false + } + + return nil +} + +func (dmConn *Connection) checkNamedValue(nv *driver.NamedValue) error { + var err error + var cvt = converter{dmConn, false} + nv.Value, err = cvt.ConvertValue(nv.Value) + dmConn.isBatch = cvt.isBatch + return err +} + +func (dmConn *Connection) driverQuery(query string) (*DmStatement, *DmRows, error) { + stmt, err := NewDmStmt(dmConn, query) + if err != nil { + return nil, nil, err + } + stmt.innerUsed = true + stmt.innerExec = true + info, err := dmConn.Access.Dm_build_417(stmt, Dm_build_685) + if err != nil { + return nil, nil, err + } + dmConn.lastExecInfo = info + stmt.innerExec = false + return stmt, newDmRows(newInnerRows(0, stmt, info)), nil +} + +func (dmConn *Connection) getIndexOnEPGroup() int32 { + if dmConn.dmConnector.group == nil || dmConn.dmConnector.group.epList == nil { + return -1 + } + for i := 0; i < len(dmConn.dmConnector.group.epList); i++ { + ep := dmConn.dmConnector.group.epList[i] + if dmConn.dmConnector.host == ep.host && dmConn.dmConnector.port == ep.port { + return int32(i) + } + } + return -1 +} + +func (dmConn *Connection) getServerEncoding() string { + if dmConn.dmConnector.charCode != "" { + return dmConn.dmConnector.charCode + } + return dmConn.serverEncoding +} + +func (dmConn *Connection) lobFetchAll() bool { + return dmConn.dmConnector.lobMode == 2 +} + +func (dmConn *Connection) CompatibleOracle() bool { + return dmConn.dmConnector.compatibleMode == COMPATIBLE_MODE_ORACLE +} + +func (dmConn *Connection) CompatibleMysql() bool { + return dmConn.dmConnector.compatibleMode == COMPATIBLE_MODE_MYSQL +} + +func (dmConn *Connection) cancel(err error) { + dmConn.canceled.Set(err) + fmt.Println(dmConn.close()) +} + +func (dmConn *Connection) finish() { + if !dmConn.watching || dmConn.finished == nil { + return + } + select { + case dmConn.finished <- struct{}{}: + dmConn.watching = false + case <-dmConn.closech: + } +} + +func (dmConn *Connection) startWatcher() { + watcher := make(chan context.Context, 1) + dmConn.watcher = watcher + finished := make(chan struct{}) + dmConn.finished = finished + go func() { + for { + var ctx context.Context + select { + case ctx = <-watcher: + case <-dmConn.closech: + return + } + + select { + case <-ctx.Done(): + dmConn.cancel(ctx.Err()) + case <-finished: + case <-dmConn.closech: + return + } + } + }() +} + +func (dmConn *Connection) watchCancel(ctx context.Context) error { + if dmConn.watching { + + return dmConn.close() + } + + if err := ctx.Err(); err != nil { + return err + } + + if ctx.Done() == nil { + return nil + } + + if dmConn.watcher == nil { + return nil + } + + dmConn.watching = true + dmConn.watcher <- ctx + return nil +} + +type noCopy struct{} + +func (*noCopy) Lock() {} + +type atomicBool struct { + _noCopy noCopy + value uint32 +} + +func (ab *atomicBool) IsSet() bool { + return atomic.LoadUint32(&ab.value) > 0 +} + +func (ab *atomicBool) Set(value bool) { + if value { + atomic.StoreUint32(&ab.value, 1) + } else { + atomic.StoreUint32(&ab.value, 0) + } +} + +func (ab *atomicBool) TrySet(value bool) bool { + if value { + return atomic.SwapUint32(&ab.value, 1) == 0 + } + return atomic.SwapUint32(&ab.value, 0) > 0 +} + +type atomicError struct { + _noCopy noCopy + value atomic.Value +} + +func (ae *atomicError) Set(value error) { + ae.value.Store(value) +} + +func (ae *atomicError) Value() error { + if v := ae.value.Load(); v != nil { + + return v.(error) + } + return nil +} diff --git a/n.go b/connector.go similarity index 93% rename from n.go rename to connector.go index 60faa7a..ef2c222 100644 --- a/n.go +++ b/connector.go @@ -17,7 +17,7 @@ import ( "strconv" "strings" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( @@ -254,10 +254,10 @@ const ( localTimezoneDef = TIME_ZONE_DEFAULT ) -type DmConnector struct { +type Connector struct { filterable - dmDriver *DmDriver + dmDriver *Driver compress int @@ -391,7 +391,7 @@ type DmConnector struct { schema string - reConnection *DmConnection + reConnection *Connection logLevel int @@ -418,7 +418,7 @@ type DmConnector struct { statSqlRemoveMode int } -func (c *DmConnector) init() *DmConnector { +func (c *Connector) init() *Connector { c.compress = compressDef c.compressID = compressIDDef c.charCode = charCodeDef @@ -494,7 +494,7 @@ func (c *DmConnector) init() *DmConnector { return c } -func (c *DmConnector) setAttributes(props *Properties) error { +func (c *Connector) setAttributes(props *Properties) error { if props == nil || props.Len() == 0 { return nil } @@ -624,7 +624,7 @@ func (c *DmConnector) setAttributes(props *Properties) error { return nil } -func (c *DmConnector) parseOsAuthType(props *Properties) error { +func (c *Connector) parseOsAuthType(props *Properties) error { value := props.GetString(OsAuthTypeKey, "") if value != "" && !util.StringUtil.IsDigit(value) { if util.StringUtil.EqualsIgnoreCase(value, "ON") { @@ -654,7 +654,7 @@ func (c *DmConnector) parseOsAuthType(props *Properties) error { return nil } -func (c *DmConnector) parseCompatibleMode(props *Properties) { +func (c *Connector) parseCompatibleMode(props *Properties) { value := props.GetString(CompatibleModeKey, "") if value != "" && !util.StringUtil.IsDigit(value) { if util.StringUtil.EqualsIgnoreCase(value, "oracle") { @@ -667,7 +667,7 @@ func (c *DmConnector) parseCompatibleMode(props *Properties) { } } -func (c *DmConnector) parseStatSqlRemoveMode(props *Properties) { +func (c *Connector) parseStatSqlRemoveMode(props *Properties) { value := props.GetString(StatSqlRemoveModeKey, "") if value != "" && !util.StringUtil.IsDigit(value) { if util.StringUtil.EqualsIgnoreCase("oldest", value) || util.StringUtil.EqualsIgnoreCase("eldest", value) { @@ -680,7 +680,7 @@ func (c *DmConnector) parseStatSqlRemoveMode(props *Properties) { } } -func (c *DmConnector) parseCluster(props *Properties) { +func (c *Connector) parseCluster(props *Properties) { value := props.GetTrimString(ClusterKey, "") if util.StringUtil.EqualsIgnoreCase(value, "DSC") { c.cluster = CLUSTER_TYPE_DSC @@ -695,7 +695,7 @@ func (c *DmConnector) parseCluster(props *Properties) { } } -func (c *DmConnector) parseDSN(dsn string) (*Properties, string, error) { +func (c *Connector) parseDSN(dsn string) (*Properties, string, error) { var dsnProps = NewProperties() url, err := url.Parse(dsn) if err != nil { @@ -718,7 +718,7 @@ func (c *DmConnector) parseDSN(dsn string) (*Properties, string, error) { return dsnProps, url.Host, nil } -func (c *DmConnector) BuildDSN() string { +func (c *Connector) BuildDSN() string { var buf bytes.Buffer buf.WriteString("dm://") @@ -753,22 +753,15 @@ func (c *DmConnector) BuildDSN() string { return buf.String() } -func (c *DmConnector) mergeConfigs(dsn string) error { +func (c *Connector) mergeConfigs(dsn string) error { props, host, err := c.parseDSN(dsn) if err != nil { return err } - driverInit(props.GetString("svcConfPath", "")) - + driverInit() addressRemapStr := props.GetTrimString(AddressRemapKey, "") userRemapStr := props.GetTrimString(UserRemapKey, "") - if addressRemapStr == "" { - addressRemapStr = GlobalProperties.GetTrimString(AddressRemapKey, "") - } - if userRemapStr == "" { - userRemapStr = GlobalProperties.GetTrimString(UserRemapKey, "") - } host = c.remap(host, addressRemapStr) @@ -795,8 +788,6 @@ func (c *DmConnector) mergeConfigs(dsn string) error { props.SetDiffProperties(c.group.props) - props.SetDiffProperties(GlobalProperties) - if props.GetBool(RwSeparateKey, false) { props.SetIfNotExist(LoginModeKey, strconv.Itoa(int(LOGIN_MODE_PRIMARY_ONLY))) props.SetIfNotExist(LoginStatusKey, strconv.Itoa(int(SERVER_STATUS_OPEN))) @@ -810,7 +801,7 @@ func (c *DmConnector) mergeConfigs(dsn string) error { return nil } -func (c *DmConnector) remap(origin string, cfgStr string) string { +func (c *Connector) remap(origin string, cfgStr string) string { if cfgStr == "" || origin == "" { return origin } @@ -825,15 +816,15 @@ func (c *DmConnector) remap(origin string, cfgStr string) string { return origin } -func (c *DmConnector) Connect(ctx context.Context) (driver.Conn, error) { +func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) { return c.filterChain.reset().DmConnectorConnect(c, ctx) } -func (c *DmConnector) Driver() driver.Driver { +func (c *Connector) Driver() driver.Driver { return c.filterChain.reset().DmConnectorDriver(c) } -func (c *DmConnector) connect(ctx context.Context) (*DmConnection, error) { +func (c *Connector) connect(ctx context.Context) (*Connection, error) { if c.group != nil && len(c.group.epList) > 0 { return c.group.connect(c) } else { @@ -841,15 +832,15 @@ func (c *DmConnector) connect(ctx context.Context) (*DmConnection, error) { } } -func (c *DmConnector) driver() *DmDriver { +func (c *Connector) driver() *Driver { return c.dmDriver } -func (c *DmConnector) connectSingle(ctx context.Context) (*DmConnection, error) { +func (c *Connector) connectSingle(ctx context.Context) (*Connection, error) { var err error - var dc *DmConnection + var dc *Connection if c.reConnection == nil { - dc = &DmConnection{ + dc = &Connection{ closech: make(chan struct{}), } dc.dmConnector = c @@ -869,12 +860,12 @@ func (c *DmConnector) connectSingle(ctx context.Context) (*DmConnection, error) dc.reset() } - dc.Access, err = dm_build_344(dc) + dc.Access, err = buildAccess(dc) if err != nil { return nil, err } - if err = dc.Access.dm_build_385(); err != nil { + if err = dc.Access.initialize(); err != nil { if !dc.closed.IsSet() { close(dc.closech) diff --git a/e.go b/e.go index 95d682b..ef108b8 100644 --- a/e.go +++ b/e.go @@ -131,13 +131,13 @@ func (Dm_build_1290 *dm_build_1218) Dm_build_1289(dm_build_1291 []byte, dm_build return 2 + Dm_build_1290.Dm_build_1275(dm_build_1291, dm_build_1292, dm_build_1293, dm_build_1294, dm_build_1295) } -func (Dm_build_1297 *dm_build_1218) Dm_build_1296(dm_build_1298 []byte, dm_build_1299 int, dm_build_1300 string, dm_build_1301 string, dm_build_1302 *DmConnection) int { +func (Dm_build_1297 *dm_build_1218) Dm_build_1296(dm_build_1298 []byte, dm_build_1299 int, dm_build_1300 string, dm_build_1301 string, dm_build_1302 *Connection) int { dm_build_1303 := Dm_build_1297.Dm_build_1432(dm_build_1300, dm_build_1301, dm_build_1302) dm_build_1299 += Dm_build_1297.Dm_build_1265(dm_build_1298, dm_build_1299, uint32(len(dm_build_1303))) return 4 + Dm_build_1297.Dm_build_1275(dm_build_1298, dm_build_1299, dm_build_1303, 0, len(dm_build_1303)) } -func (Dm_build_1305 *dm_build_1218) Dm_build_1304(dm_build_1306 []byte, dm_build_1307 int, dm_build_1308 string, dm_build_1309 string, dm_build_1310 *DmConnection) int { +func (Dm_build_1305 *dm_build_1218) Dm_build_1304(dm_build_1306 []byte, dm_build_1307 int, dm_build_1308 string, dm_build_1309 string, dm_build_1310 *Connection) int { dm_build_1311 := Dm_build_1305.Dm_build_1432(dm_build_1308, dm_build_1309, dm_build_1310) dm_build_1307 += Dm_build_1305.Dm_build_1260(dm_build_1306, dm_build_1307, uint16(len(dm_build_1311))) @@ -263,17 +263,17 @@ func (Dm_build_1371 *dm_build_1218) Dm_build_1370(dm_build_1372 []byte, dm_build return dm_build_1375 } -func (Dm_build_1377 *dm_build_1218) Dm_build_1376(dm_build_1378 []byte, dm_build_1379 int, dm_build_1380 int, dm_build_1381 string, dm_build_1382 *DmConnection) string { +func (Dm_build_1377 *dm_build_1218) Dm_build_1376(dm_build_1378 []byte, dm_build_1379 int, dm_build_1380 int, dm_build_1381 string, dm_build_1382 *Connection) string { return Dm_build_1377.Dm_build_1469(dm_build_1378[dm_build_1379:dm_build_1379+dm_build_1380], dm_build_1381, dm_build_1382) } -func (Dm_build_1384 *dm_build_1218) Dm_build_1383(dm_build_1385 []byte, dm_build_1386 int, dm_build_1387 string, dm_build_1388 *DmConnection) string { +func (Dm_build_1384 *dm_build_1218) Dm_build_1383(dm_build_1385 []byte, dm_build_1386 int, dm_build_1387 string, dm_build_1388 *Connection) string { dm_build_1389 := Dm_build_1384.Dm_build_1348(dm_build_1385, dm_build_1386) dm_build_1386 += 4 return Dm_build_1384.Dm_build_1376(dm_build_1385, dm_build_1386, int(dm_build_1389), dm_build_1387, dm_build_1388) } -func (Dm_build_1391 *dm_build_1218) Dm_build_1390(dm_build_1392 []byte, dm_build_1393 int, dm_build_1394 string, dm_build_1395 *DmConnection) string { +func (Dm_build_1391 *dm_build_1218) Dm_build_1390(dm_build_1392 []byte, dm_build_1393 int, dm_build_1394 string, dm_build_1395 *Connection) string { dm_build_1396 := Dm_build_1391.Dm_build_1343(dm_build_1392, dm_build_1393) dm_build_1393 += 2 return Dm_build_1391.Dm_build_1376(dm_build_1392, dm_build_1393, int(dm_build_1396), dm_build_1394, dm_build_1395) @@ -320,7 +320,7 @@ func (Dm_build_1425 *dm_build_1218) Dm_build_1424(dm_build_1426 uint64) []byte { return []byte{byte(dm_build_1426), byte(dm_build_1426 >> 8), byte(dm_build_1426 >> 16), byte(dm_build_1426 >> 24), byte(dm_build_1426 >> 32), byte(dm_build_1426 >> 40), byte(dm_build_1426 >> 48), byte(dm_build_1426 >> 56)} } -func (Dm_build_1428 *dm_build_1218) Dm_build_1427(dm_build_1429 []byte, dm_build_1430 string, dm_build_1431 *DmConnection) []byte { +func (Dm_build_1428 *dm_build_1218) Dm_build_1427(dm_build_1429 []byte, dm_build_1430 string, dm_build_1431 *Connection) []byte { if dm_build_1430 == "UTF-8" { return dm_build_1429 } @@ -367,7 +367,7 @@ func (Dm_build_1428 *dm_build_1218) Dm_build_1427(dm_build_1429 []byte, dm_build panic("Unsupported Charset!") } -func (Dm_build_1433 *dm_build_1218) Dm_build_1432(dm_build_1434 string, dm_build_1435 string, dm_build_1436 *DmConnection) []byte { +func (Dm_build_1433 *dm_build_1218) Dm_build_1432(dm_build_1434 string, dm_build_1435 string, dm_build_1436 *Connection) []byte { return Dm_build_1433.Dm_build_1427([]byte(dm_build_1434), dm_build_1435, dm_build_1436) } @@ -407,7 +407,7 @@ func (Dm_build_1462 *dm_build_1218) Dm_build_1461(dm_build_1463 []byte) uint32 { return Dm_build_1462.Dm_build_1348(dm_build_1463, 0) } -func (Dm_build_1465 *dm_build_1218) Dm_build_1464(dm_build_1466 []byte, dm_build_1467 string, dm_build_1468 *DmConnection) []byte { +func (Dm_build_1465 *dm_build_1218) Dm_build_1464(dm_build_1466 []byte, dm_build_1467 string, dm_build_1468 *Connection) []byte { if dm_build_1467 == "UTF-8" { return dm_build_1466 } @@ -454,7 +454,7 @@ func (Dm_build_1465 *dm_build_1218) Dm_build_1464(dm_build_1466 []byte, dm_build panic("Unsupported Charset!") } -func (Dm_build_1470 *dm_build_1218) Dm_build_1469(dm_build_1471 []byte, dm_build_1472 string, dm_build_1473 *DmConnection) string { +func (Dm_build_1470 *dm_build_1218) Dm_build_1469(dm_build_1471 []byte, dm_build_1472 string, dm_build_1473 *Connection) string { return string(Dm_build_1470.Dm_build_1464(dm_build_1471, dm_build_1472, dm_build_1473)) } diff --git a/x.go b/endpoint.go similarity index 95% rename from x.go rename to endpoint.go index 97ebd9a..669b496 100644 --- a/x.go +++ b/endpoint.go @@ -46,8 +46,8 @@ type ep struct { serverStatus int32 dscControl bool sort int32 - epSeqno int32 - epStatus int32 + epSeqno int32 + epStatus int32 lock sync.Mutex } @@ -122,7 +122,7 @@ func (ep *ep) calcSort(loginMode int32) int32 { return sort } -func (ep *ep) refreshStatus(alive bool, conn *DmConnection) { +func (ep *ep) refreshStatus(alive bool, conn *Connection) { ep.lock.Lock() defer ep.lock.Unlock() ep.alive = alive @@ -140,7 +140,7 @@ func (ep *ep) refreshStatus(alive bool, conn *DmConnection) { } } -func (ep *ep) connect(connector *DmConnector) (*DmConnection, error) { +func (ep *ep) connect(connector *Connector) (*Connection, error) { connector.host = ep.host connector.port = ep.port conn, err := connector.connectSingle(context.Background()) diff --git a/g.go b/g.go index 84bf224..9fadacb 100644 --- a/g.go +++ b/g.go @@ -15,7 +15,7 @@ import ( "sync/atomic" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) type ExecuteTypeEnum int @@ -1248,7 +1248,7 @@ func newGoStat(maxConnSize int) *GoStat { return gs } -func (gs *GoStat) createConnStat(conn *DmConnection) *connectionStat { +func (gs *GoStat) createConnStat(conn *Connection) *connectionStat { url := conn.dmConnector.host + ":" + strconv.Itoa(int(conn.dmConnector.port)) gs.lock.Lock() defer gs.lock.Unlock() diff --git a/go.mod b/go.mod index f3d5b57..732fe11 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gitee.com/chunanyong/dm +module github.com/gotomicro/dmgo go 1.13 diff --git a/i.go b/i.go index f7a17f0..67353bd 100644 --- a/i.go +++ b/i.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) var DB2G db2g @@ -25,7 +25,7 @@ func (DB2G db2g) processVarchar2(bytes []byte, prec int) []byte { return rbytes } -func (DB2G db2g) charToString(bytes []byte, column *column, conn *DmConnection) string { +func (DB2G db2g) charToString(bytes []byte, column *column, conn *Connection) string { if column.colType == VARCHAR2 { bytes = DB2G.processVarchar2(bytes, int(column.prec)) } else if column.colType == CLOB { @@ -37,7 +37,7 @@ func (DB2G db2g) charToString(bytes []byte, column *column, conn *DmConnection) return Dm_build_1219.Dm_build_1469(bytes, conn.serverEncoding, conn) } -func (DB2G db2g) charToFloat64(bytes []byte, column *column, conn *DmConnection) (float64, error) { +func (DB2G db2g) charToFloat64(bytes []byte, column *column, conn *Connection) (float64, error) { str := DB2G.charToString(bytes, column, conn) val, err := strconv.ParseFloat(str, 64) if err != nil { @@ -47,12 +47,12 @@ func (DB2G db2g) charToFloat64(bytes []byte, column *column, conn *DmConnection) return val, nil } -func (DB2G db2g) charToDeciaml(bytes []byte, column *column, conn *DmConnection) (*DmDecimal, error) { +func (DB2G db2g) charToDeciaml(bytes []byte, column *column, conn *Connection) (*DmDecimal, error) { str := DB2G.charToString(bytes, column, conn) return NewDecimalFromString(str) } -func (DB2G db2g) BinaryToInt64(bytes []byte, column *column, conn *DmConnection) (int64, error) { +func (DB2G db2g) BinaryToInt64(bytes []byte, column *column, conn *Connection) (int64, error) { if column.colType == BLOB { blob := newBlobFromDB(bytes, conn, column, true) blobLen, err := blob.GetLength() @@ -99,7 +99,7 @@ func (DB2G db2g) decToDecimal(bytes []byte, prec int, scale int, compatibleOracl return newDecimal(bytes, prec, scale) } -func (DB2G db2g) toBytes(bytes []byte, column *column, conn *DmConnection) ([]byte, error) { +func (DB2G db2g) toBytes(bytes []byte, column *column, conn *Connection) ([]byte, error) { retBytes := Dm_build_1219.Dm_build_1370(bytes, 0, len(bytes)) switch column.colType { case CLOB: @@ -122,7 +122,7 @@ func (DB2G db2g) toBytes(bytes []byte, column *column, conn *DmConnection) ([]by return nil, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toString(bytes []byte, column *column, conn *DmConnection) string { +func (DB2G db2g) toString(bytes []byte, column *column, conn *Connection) string { switch column.colType { case CHAR, VARCHAR, VARCHAR2: return DB2G.charToString(bytes, column, conn) @@ -187,7 +187,7 @@ func (DB2G db2g) toString(bytes []byte, column *column, conn *DmConnection) stri return "" } -func (DB2G db2g) toBool(bytes []byte, column *column, conn *DmConnection) (bool, error) { +func (DB2G db2g) toBool(bytes []byte, column *column, conn *Connection) (bool, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: return bytes[0] != 0, nil @@ -210,7 +210,7 @@ func (DB2G db2g) toBool(bytes []byte, column *column, conn *DmConnection) (bool, return false, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toByte(bytes []byte, column *column, conn *DmConnection) (byte, error) { +func (DB2G db2g) toByte(bytes []byte, column *column, conn *Connection) (byte, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: @@ -278,7 +278,7 @@ func (DB2G db2g) toByte(bytes []byte, column *column, conn *DmConnection) (byte, return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toInt8(bytes []byte, column *column, conn *DmConnection) (int8, error) { +func (DB2G db2g) toInt8(bytes []byte, column *column, conn *Connection) (int8, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -346,7 +346,7 @@ func (DB2G db2g) toInt8(bytes []byte, column *column, conn *DmConnection) (int8, return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toInt16(bytes []byte, column *column, conn *DmConnection) (int16, error) { +func (DB2G db2g) toInt16(bytes []byte, column *column, conn *Connection) (int16, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -410,7 +410,7 @@ func (DB2G db2g) toInt16(bytes []byte, column *column, conn *DmConnection) (int1 return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toUInt16(bytes []byte, column *column, conn *DmConnection) (uint16, error) { +func (DB2G db2g) toUInt16(bytes []byte, column *column, conn *Connection) (uint16, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -473,7 +473,7 @@ func (DB2G db2g) toUInt16(bytes []byte, column *column, conn *DmConnection) (uin return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toInt32(bytes []byte, column *column, conn *DmConnection) (int32, error) { +func (DB2G db2g) toInt32(bytes []byte, column *column, conn *Connection) (int32, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -532,7 +532,7 @@ func (DB2G db2g) toInt32(bytes []byte, column *column, conn *DmConnection) (int3 return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toUInt32(bytes []byte, column *column, conn *DmConnection) (uint32, error) { +func (DB2G db2g) toUInt32(bytes []byte, column *column, conn *Connection) (uint32, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -591,7 +591,7 @@ func (DB2G db2g) toUInt32(bytes []byte, column *column, conn *DmConnection) (uin return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toInt64(bytes []byte, column *column, conn *DmConnection) (int64, error) { +func (DB2G db2g) toInt64(bytes []byte, column *column, conn *Connection) (int64, error) { switch column.colType { case BOOLEAN, BIT, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -631,7 +631,7 @@ func (DB2G db2g) toInt64(bytes []byte, column *column, conn *DmConnection) (int6 return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toUInt64(bytes []byte, column *column, conn *DmConnection) (uint64, error) { +func (DB2G db2g) toUInt64(bytes []byte, column *column, conn *Connection) (uint64, error) { switch column.colType { case BOOLEAN, BIT, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -671,7 +671,7 @@ func (DB2G db2g) toUInt64(bytes []byte, column *column, conn *DmConnection) (uin return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toInt(bytes []byte, column *column, conn *DmConnection) (int, error) { +func (DB2G db2g) toInt(bytes []byte, column *column, conn *Connection) (int, error) { if strconv.IntSize == 32 { tmp, err := DB2G.toInt32(bytes, column, conn) return int(tmp), err @@ -681,7 +681,7 @@ func (DB2G db2g) toInt(bytes []byte, column *column, conn *DmConnection) (int, e } } -func (DB2G db2g) toUInt(bytes []byte, column *column, conn *DmConnection) (uint, error) { +func (DB2G db2g) toUInt(bytes []byte, column *column, conn *Connection) (uint, error) { if strconv.IntSize == 32 { tmp, err := DB2G.toUInt32(bytes, column, conn) return uint(tmp), err @@ -691,7 +691,7 @@ func (DB2G db2g) toUInt(bytes []byte, column *column, conn *DmConnection) (uint, } } -func (DB2G db2g) toFloat32(bytes []byte, column *column, conn *DmConnection) (float32, error) { +func (DB2G db2g) toFloat32(bytes []byte, column *column, conn *Connection) (float32, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -725,7 +725,7 @@ func (DB2G db2g) toFloat32(bytes []byte, column *column, conn *DmConnection) (fl return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toFloat64(bytes []byte, column *column, conn *DmConnection) (float64, error) { +func (DB2G db2g) toFloat64(bytes []byte, column *column, conn *Connection) (float64, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: if bytes == nil || len(bytes) == 0 { @@ -759,7 +759,7 @@ func (DB2G db2g) toFloat64(bytes []byte, column *column, conn *DmConnection) (fl return 0, ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toDmBlob(value []byte, column *column, conn *DmConnection) *DmBlob { +func (DB2G db2g) toDmBlob(value []byte, column *column, conn *Connection) *DmBlob { switch column.colType { case BLOB: @@ -769,7 +769,7 @@ func (DB2G db2g) toDmBlob(value []byte, column *column, conn *DmConnection) *DmB return nil } -func (DB2G db2g) toDmClob(value []byte, conn *DmConnection, column *column) *DmClob { +func (DB2G db2g) toDmClob(value []byte, conn *Connection, column *column) *DmClob { switch column.colType { case CLOB: @@ -779,7 +779,7 @@ func (DB2G db2g) toDmClob(value []byte, conn *DmConnection, column *column) *DmC return nil } -func (DB2G db2g) toDmDecimal(value []byte, column *column, conn *DmConnection) (*DmDecimal, error) { +func (DB2G db2g) toDmDecimal(value []byte, column *column, conn *Connection) (*DmDecimal, error) { switch column.colType { case BIT, BOOLEAN, TINYINT: @@ -807,7 +807,7 @@ func (DB2G db2g) toDmDecimal(value []byte, column *column, conn *DmConnection) ( return nil, ECGO_DATA_CONVERTION_ERROR } -func (DB2G db2g) toTime(bytes []byte, column *column, conn *DmConnection) (time.Time, error) { +func (DB2G db2g) toTime(bytes []byte, column *column, conn *Connection) (time.Time, error) { switch column.colType { case DATE, TIME, TIME_TZ, DATETIME_TZ, DATETIME: dt := decode(bytes, column.isBdta, int(column.colType), int(column.scale), int(conn.dmConnector.localTimezone), int(conn.DbTimezone)) @@ -818,7 +818,7 @@ func (DB2G db2g) toTime(bytes []byte, column *column, conn *DmConnection) (time. return time.Now(), ECGO_DATA_CONVERTION_ERROR.throw() } -func (DB2G db2g) toObject(bytes []byte, column *column, conn *DmConnection) (interface{}, error) { +func (DB2G db2g) toObject(bytes []byte, column *column, conn *Connection) (interface{}, error) { switch column.colType { case BIT, BOOLEAN: diff --git a/j.go b/j.go index 5a3b851..7a4374e 100644 --- a/j.go +++ b/j.go @@ -49,7 +49,7 @@ func NewDmArray(typeName string, elements []interface{}) *DmArray { return da } -func (da *DmArray) create(dc *DmConnection) (*DmArray, error) { +func (da *DmArray) create(dc *Connection) (*DmArray, error) { desc, err := newArrayDescriptor(da.typeName, dc) if err != nil { return nil, err @@ -57,7 +57,7 @@ func (da *DmArray) create(dc *DmConnection) (*DmArray, error) { return da.createByArrayDescriptor(desc, dc) } -func (da *DmArray) createByArrayDescriptor(arrDesc *ArrayDescriptor, conn *DmConnection) (*DmArray, error) { +func (da *DmArray) createByArrayDescriptor(arrDesc *ArrayDescriptor, conn *Connection) (*DmArray, error) { if nil == arrDesc { return nil, ECGO_INVALID_PARAMETER_VALUE.throw() diff --git a/k.go b/k.go index 939884e..ba735ed 100644 --- a/k.go +++ b/k.go @@ -34,7 +34,7 @@ func newDmBlob() *DmBlob { } } -func newBlobFromDB(value []byte, conn *DmConnection, column *column, fetchAll bool) *DmBlob { +func newBlobFromDB(value []byte, conn *Connection, column *column, fetchAll bool) *DmBlob { var blob = newDmBlob() blob.connection = conn blob.lobFlag = LOB_FLAG_BYTE @@ -75,7 +75,7 @@ func newBlobFromDB(value []byte, conn *DmConnection, column *column, fetchAll bo return blob } -func newBlobOfLocal(value []byte, conn *DmConnection) *DmBlob { +func newBlobOfLocal(value []byte, conn *Connection) *DmBlob { var blob = newDmBlob() blob.connection = conn blob.lobFlag = LOB_FLAG_BYTE diff --git a/l.go b/l.go index eadc846..899256d 100644 --- a/l.go +++ b/l.go @@ -33,7 +33,7 @@ func newDmClob() *DmClob { } } -func newClobFromDB(value []byte, conn *DmConnection, column *column, fetchAll bool) *DmClob { +func newClobFromDB(value []byte, conn *Connection, column *column, fetchAll bool) *DmClob { var clob = newDmClob() clob.connection = conn clob.lobFlag = LOB_FLAG_CHAR @@ -74,7 +74,7 @@ func newClobFromDB(value []byte, conn *DmConnection, column *column, fetchAll bo return clob } -func newClobOfLocal(value string, conn *DmConnection) *DmClob { +func newClobOfLocal(value string, conn *Connection) *DmClob { var clob = newDmClob() clob.connection = conn clob.lobFlag = LOB_FLAG_CHAR diff --git a/m.go b/m.go deleted file mode 100644 index 27cf5cf..0000000 --- a/m.go +++ /dev/null @@ -1,869 +0,0 @@ -/* - * Copyright (c) 2000-2018, 达梦数据库有限公司. - * All rights reserved. - */ -package dm - -import ( - "bytes" - "context" - "database/sql" - "database/sql/driver" - "fmt" - "sync/atomic" - - "gitee.com/chunanyong/dm/parser" - "golang.org/x/text/encoding" -) - -type DmConnection struct { - filterable - - dmConnector *DmConnector - Access *dm_build_332 - stmtMap map[int32]*DmStatement - stmtPool []stmtPoolInfo - lastExecInfo *execRetInfo - lexer *parser.Lexer - encode encoding.Encoding - encodeBuffer *bytes.Buffer - transformReaderDst []byte - transformReaderSrc []byte - - serverEncoding string - GlobalServerSeries int - ServerVersion string - Malini2 bool - Execute2 bool - LobEmptyCompOrcl bool - IsoLevel int32 - ReadOnly bool - NewLobFlag bool - sslEncrypt int - MaxRowSize int32 - DDLAutoCommit bool - BackslashEscape bool - SvrStat int32 - SvrMode int32 - ConstParaOpt bool - DbTimezone int16 - LifeTimeRemainder int16 - InstanceName string - Schema string - LastLoginIP string - LastLoginTime string - FailedAttempts int32 - LoginWarningID int32 - GraceTimeRemainder int32 - Guid string - DbName string - StandbyHost string - StandbyPort int32 - StandbyCount int32 - SessionID int64 - OracleDateLanguage byte - FormatDate string - FormatTimestamp string - FormatTimestampTZ string - FormatTime string - FormatTimeTZ string - Local bool - MsgVersion int32 - TrxStatus int32 - dscControl bool - trxFinish bool - sessionID int64 - autoCommit bool - isBatch bool - - watching bool - watcher chan<- context.Context - closech chan struct{} - finished chan<- struct{} - canceled atomicError - closed atomicBool -} - -func (conn *DmConnection) setTrxFinish(status int32) { - switch status & Dm_build_721 { - case Dm_build_718, Dm_build_719, Dm_build_720: - conn.trxFinish = true - default: - conn.trxFinish = false - } -} - -func (dmConn *DmConnection) init() { - if dmConn.dmConnector.stmtPoolMaxSize > 0 { - dmConn.stmtPool = make([]stmtPoolInfo, 0, dmConn.dmConnector.stmtPoolMaxSize) - } - - dmConn.stmtMap = make(map[int32]*DmStatement) - dmConn.DbTimezone = 0 - dmConn.GlobalServerSeries = 0 - dmConn.MaxRowSize = 0 - dmConn.LobEmptyCompOrcl = false - dmConn.ReadOnly = false - dmConn.DDLAutoCommit = false - dmConn.ConstParaOpt = false - dmConn.IsoLevel = -1 - dmConn.sessionID = -1 - dmConn.Malini2 = true - dmConn.NewLobFlag = true - dmConn.Execute2 = true - dmConn.serverEncoding = ENCODING_GB18030 - dmConn.TrxStatus = Dm_build_669 - dmConn.OracleDateLanguage = byte(Locale) - dmConn.lastExecInfo = NewExceInfo() - dmConn.MsgVersion = Dm_build_603 - - dmConn.idGenerator = dmConnIDGenerator -} - -func (dmConn *DmConnection) reset() { - dmConn.DbTimezone = 0 - dmConn.GlobalServerSeries = 0 - dmConn.MaxRowSize = 0 - dmConn.LobEmptyCompOrcl = false - dmConn.ReadOnly = false - dmConn.DDLAutoCommit = false - dmConn.ConstParaOpt = false - dmConn.IsoLevel = -1 - dmConn.sessionID = -1 - dmConn.Malini2 = true - dmConn.NewLobFlag = true - dmConn.Execute2 = true - dmConn.serverEncoding = ENCODING_GB18030 - dmConn.TrxStatus = Dm_build_669 -} - -func (dc *DmConnection) checkClosed() error { - if dc.closed.IsSet() { - return driver.ErrBadConn - } - - return nil -} - -func (dc *DmConnection) executeInner(query string, execType int16) (interface{}, error) { - - stmt, err := NewDmStmt(dc, query) - - if err != nil { - return nil, err - } - - if execType == Dm_build_686 { - defer stmt.close() - } - - stmt.innerUsed = true - if stmt.dmConn.dmConnector.escapeProcess { - stmt.nativeSql, err = stmt.dmConn.escape(stmt.nativeSql, stmt.dmConn.dmConnector.keyWords) - if err != nil { - stmt.close() - return nil, err - } - } - - var optParamList []OptParameter - - if stmt.dmConn.ConstParaOpt { - optParamList = make([]OptParameter, 0) - stmt.nativeSql, optParamList, err = stmt.dmConn.execOpt(stmt.nativeSql, optParamList, stmt.dmConn.getServerEncoding()) - if err != nil { - stmt.close() - optParamList = nil - } - } - - if execType == Dm_build_685 && dc.dmConnector.enRsCache { - rpv, err := rp.get(stmt, query) - if err != nil { - return nil, err - } - - if rpv != nil { - stmt.execInfo = rpv.execInfo - dc.lastExecInfo = rpv.execInfo - return newDmRows(rpv.getResultSet(stmt)), nil - } - } - - var info *execRetInfo - - if optParamList != nil && len(optParamList) > 0 { - info, err = dc.Access.Dm_build_411(stmt, optParamList) - if err != nil { - stmt.nativeSql = query - info, err = dc.Access.Dm_build_417(stmt, execType) - } - } else { - info, err = dc.Access.Dm_build_417(stmt, execType) - } - - if err != nil { - stmt.close() - return nil, err - } - dc.lastExecInfo = info - - if info.hasResultSet { - return newDmRows(newInnerRows(0, stmt, info)), nil - } else { - return newDmResult(stmt, info), nil - } -} - -func g2dbIsoLevel(isoLevel int32) int32 { - switch isoLevel { - case 1: - return Dm_build_673 - case 2: - return Dm_build_674 - case 4: - return Dm_build_675 - case 6: - return Dm_build_676 - default: - return -1 - } -} - -func (dc *DmConnection) Begin() (driver.Tx, error) { - if len(dc.filterChain.filters) == 0 { - return dc.begin() - } else { - return dc.filterChain.reset().DmConnectionBegin(dc) - } -} - -func (dc *DmConnection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { - if len(dc.filterChain.filters) == 0 { - return dc.beginTx(ctx, opts) - } - return dc.filterChain.reset().DmConnectionBeginTx(dc, ctx, opts) -} - -func (dc *DmConnection) Commit() error { - if len(dc.filterChain.filters) == 0 { - return dc.commit() - } else { - return dc.filterChain.reset().DmConnectionCommit(dc) - } -} - -func (dc *DmConnection) Rollback() error { - if len(dc.filterChain.filters) == 0 { - return dc.rollback() - } else { - return dc.filterChain.reset().DmConnectionRollback(dc) - } -} - -func (dc *DmConnection) Close() error { - if len(dc.filterChain.filters) == 0 { - return dc.close() - } else { - return dc.filterChain.reset().DmConnectionClose(dc) - } -} - -func (dc *DmConnection) Ping(ctx context.Context) error { - if len(dc.filterChain.filters) == 0 { - return dc.ping(ctx) - } else { - return dc.filterChain.reset().DmConnectionPing(dc, ctx) - } -} - -func (dc *DmConnection) Exec(query string, args []driver.Value) (driver.Result, error) { - if len(dc.filterChain.filters) == 0 { - return dc.exec(query, args) - } - return dc.filterChain.reset().DmConnectionExec(dc, query, args) -} - -func (dc *DmConnection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) { - if len(dc.filterChain.filters) == 0 { - return dc.execContext(ctx, query, args) - } - return dc.filterChain.reset().DmConnectionExecContext(dc, ctx, query, args) -} - -func (dc *DmConnection) Query(query string, args []driver.Value) (driver.Rows, error) { - if len(dc.filterChain.filters) == 0 { - return dc.query(query, args) - } - return dc.filterChain.reset().DmConnectionQuery(dc, query, args) -} - -func (dc *DmConnection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) { - if len(dc.filterChain.filters) == 0 { - return dc.queryContext(ctx, query, args) - } - return dc.filterChain.reset().DmConnectionQueryContext(dc, ctx, query, args) -} - -func (dc *DmConnection) Prepare(query string) (driver.Stmt, error) { - if len(dc.filterChain.filters) == 0 { - return dc.prepare(query) - } - return dc.filterChain.reset().DmConnectionPrepare(dc, query) -} - -func (dc *DmConnection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) { - if len(dc.filterChain.filters) == 0 { - return dc.prepareContext(ctx, query) - } - return dc.filterChain.reset().DmConnectionPrepareContext(dc, ctx, query) -} - -func (dc *DmConnection) ResetSession(ctx context.Context) error { - if len(dc.filterChain.filters) == 0 { - return dc.resetSession(ctx) - } - return dc.filterChain.reset().DmConnectionResetSession(dc, ctx) -} - -func (dc *DmConnection) CheckNamedValue(nv *driver.NamedValue) error { - if len(dc.filterChain.filters) == 0 { - return dc.checkNamedValue(nv) - } - return dc.filterChain.reset().DmConnectionCheckNamedValue(dc, nv) -} - -func (dc *DmConnection) begin() (*DmConnection, error) { - return dc.beginTx(context.Background(), driver.TxOptions{driver.IsolationLevel(sql.LevelDefault), false}) -} - -func (dc *DmConnection) beginTx(ctx context.Context, opts driver.TxOptions) (*DmConnection, error) { - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if err := dc.watchCancel(ctx); err != nil { - return nil, err - } - defer dc.finish() - - if sql.IsolationLevel(opts.Isolation) == sql.LevelDefault { - opts.Isolation = driver.IsolationLevel(sql.LevelReadCommitted) - } - - dc.ReadOnly = opts.ReadOnly - - if dc.IsoLevel == int32(opts.Isolation) { - return dc, nil - } - - switch sql.IsolationLevel(opts.Isolation) { - case sql.LevelDefault: - return dc, nil - case sql.LevelReadUncommitted, sql.LevelReadCommitted, sql.LevelSerializable: - dc.IsoLevel = int32(opts.Isolation) - case sql.LevelRepeatableRead: - if dc.CompatibleMysql() { - dc.IsoLevel = int32(sql.LevelReadCommitted) - } else { - return nil, ECGO_INVALID_TRAN_ISOLATION.throw() - } - default: - return nil, ECGO_INVALID_TRAN_ISOLATION.throw() - } - - err = dc.Access.Dm_build_471(dc) - if err != nil { - return nil, err - } - return dc, nil -} - -func (dc *DmConnection) commit() error { - err := dc.checkClosed() - if err != nil { - return err - } - - defer func() { - dc.autoCommit = dc.dmConnector.autoCommit - }() - - if !dc.autoCommit { - err = dc.Access.Commit() - if err != nil { - return err - } - dc.trxFinish = true - return nil - } else if !dc.dmConnector.alwayseAllowCommit { - return ECGO_COMMIT_IN_AUTOCOMMIT_MODE.throw() - } - - return nil -} - -func (dc *DmConnection) rollback() error { - err := dc.checkClosed() - if err != nil { - return err - } - - defer func() { - dc.autoCommit = dc.dmConnector.autoCommit - }() - - if !dc.autoCommit { - err = dc.Access.Rollback() - if err != nil { - return err - } - dc.trxFinish = true - return nil - } else if !dc.dmConnector.alwayseAllowCommit { - return ECGO_ROLLBACK_IN_AUTOCOMMIT_MODE.throw() - } - - return nil -} - -func (dc *DmConnection) reconnect() error { - err := dc.Access.Close() - if err != nil { - return err - } - - for _, stmt := range dc.stmtMap { - stmt.closed = true - for id, _ := range stmt.rsMap { - delete(stmt.rsMap, id) - } - } - - if dc.stmtPool != nil { - dc.stmtPool = dc.stmtPool[:0] - } - - dc.dmConnector.reConnection = dc - - if dc.dmConnector.group != nil { - _, err = dc.dmConnector.group.connect(dc.dmConnector) - if err != nil { - return err - } - } else { - _, err = dc.dmConnector.connect(context.Background()) - } - - for _, stmt := range dc.stmtMap { - err = dc.Access.Dm_build_389(stmt) - if err != nil { - return err - } - - if stmt.paramCount > 0 { - err = stmt.prepare() - if err != nil { - return err - } - } - } - - return nil -} - -func (dc *DmConnection) close() error { - if dc.closed.IsSet() { - return nil - } - - close(dc.closech) - if dc.Access == nil { - return nil - } - - err := dc.rollback() - if err != nil { - return err - } - - for _, stmt := range dc.stmtMap { - err = stmt.free() - if err != nil { - return err - } - } - - if dc.stmtPool != nil { - for _, spi := range dc.stmtPool { - err = dc.Access.Dm_build_394(spi.id) - if err != nil { - return err - } - } - dc.stmtPool = nil - } - - err = dc.Access.Close() - if err != nil { - return err - } - - dc.closed.Set(true) - return nil -} - -func (dc *DmConnection) ping(ctx context.Context) error { - rows, err := dc.query("select 1", nil) - if err != nil { - return err - } - return rows.close() -} - -func (dc *DmConnection) exec(query string, args []driver.Value) (*DmResult, error) { - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if args != nil && len(args) > 0 { - stmt, err := dc.prepare(query) - defer stmt.close() - if err != nil { - return nil, err - } - dc.lastExecInfo = stmt.execInfo - - return stmt.exec(args) - } else { - r1, err := dc.executeInner(query, Dm_build_686) - if err != nil { - return nil, err - } - - if r2, ok := r1.(*DmResult); ok { - return r2, nil - } else { - return nil, ECGO_NOT_EXEC_SQL.throw() - } - } -} - -func (dc *DmConnection) execContext(ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { - - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if err := dc.watchCancel(ctx); err != nil { - return nil, err - } - defer dc.finish() - - if args != nil && len(args) > 0 { - stmt, err := dc.prepare(query) - defer stmt.close() - if err != nil { - return nil, err - } - dc.lastExecInfo = stmt.execInfo - - return stmt.execContext(ctx, args) - } else { - r1, err := dc.executeInner(query, Dm_build_686) - if err != nil { - return nil, err - } - - if r2, ok := r1.(*DmResult); ok { - return r2, nil - } else { - return nil, ECGO_NOT_EXEC_SQL.throw() - } - } -} - -func (dc *DmConnection) query(query string, args []driver.Value) (*DmRows, error) { - - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if args != nil && len(args) > 0 { - stmt, err := dc.prepare(query) - if err != nil { - stmt.close() - return nil, err - } - dc.lastExecInfo = stmt.execInfo - - stmt.innerUsed = true - return stmt.query(args) - - } else { - r1, err := dc.executeInner(query, Dm_build_685) - if err != nil { - return nil, err - } - - if r2, ok := r1.(*DmRows); ok { - return r2, nil - } else { - return nil, ECGO_NOT_QUERY_SQL.throw() - } - } -} - -func (dc *DmConnection) queryContext(ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { - - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if err := dc.watchCancel(ctx); err != nil { - return nil, err - } - defer dc.finish() - - if args != nil && len(args) > 0 { - stmt, err := dc.prepare(query) - if err != nil { - stmt.close() - return nil, err - } - dc.lastExecInfo = stmt.execInfo - - stmt.innerUsed = true - return stmt.queryContext(ctx, args) - - } else { - r1, err := dc.executeInner(query, Dm_build_685) - if err != nil { - return nil, err - } - - if r2, ok := r1.(*DmRows); ok { - return r2, nil - } else { - return nil, ECGO_NOT_QUERY_SQL.throw() - } - } - -} - -func (dc *DmConnection) prepare(query string) (*DmStatement, error) { - err := dc.checkClosed() - if err != nil { - return nil, err - } - - stmt, err := NewDmStmt(dc, query) - if err != nil { - return nil, err - } - - err = stmt.prepare() - return stmt, err -} - -func (dc *DmConnection) prepareContext(ctx context.Context, query string) (*DmStatement, error) { - err := dc.checkClosed() - if err != nil { - return nil, err - } - - if err := dc.watchCancel(ctx); err != nil { - return nil, err - } - defer dc.finish() - - stmt, err := dc.prepare(query) - if err != nil { - return nil, err - } - - return stmt, nil -} - -func (dc *DmConnection) resetSession(ctx context.Context) error { - err := dc.checkClosed() - if err != nil { - return err - } - - for _, stmt := range dc.stmtMap { - stmt.inUse = false - } - - return nil -} - -func (dc *DmConnection) checkNamedValue(nv *driver.NamedValue) error { - var err error - var cvt = converter{dc, false} - nv.Value, err = cvt.ConvertValue(nv.Value) - dc.isBatch = cvt.isBatch - return err -} - -func (dc *DmConnection) driverQuery(query string) (*DmStatement, *DmRows, error) { - stmt, err := NewDmStmt(dc, query) - if err != nil { - return nil, nil, err - } - stmt.innerUsed = true - stmt.innerExec = true - info, err := dc.Access.Dm_build_417(stmt, Dm_build_685) - if err != nil { - return nil, nil, err - } - dc.lastExecInfo = info - stmt.innerExec = false - return stmt, newDmRows(newInnerRows(0, stmt, info)), nil -} - -func (dc *DmConnection) getIndexOnEPGroup() int32 { - if dc.dmConnector.group == nil || dc.dmConnector.group.epList == nil { - return -1 - } - for i := 0; i < len(dc.dmConnector.group.epList); i++ { - ep := dc.dmConnector.group.epList[i] - if dc.dmConnector.host == ep.host && dc.dmConnector.port == ep.port { - return int32(i) - } - } - return -1 -} - -func (dc *DmConnection) getServerEncoding() string { - if dc.dmConnector.charCode != "" { - return dc.dmConnector.charCode - } - return dc.serverEncoding -} - -func (dc *DmConnection) lobFetchAll() bool { - return dc.dmConnector.lobMode == 2 -} - -func (conn *DmConnection) CompatibleOracle() bool { - return conn.dmConnector.compatibleMode == COMPATIBLE_MODE_ORACLE -} - -func (conn *DmConnection) CompatibleMysql() bool { - return conn.dmConnector.compatibleMode == COMPATIBLE_MODE_MYSQL -} - -func (conn *DmConnection) cancel(err error) { - conn.canceled.Set(err) - fmt.Println(conn.close()) -} - -func (conn *DmConnection) finish() { - if !conn.watching || conn.finished == nil { - return - } - select { - case conn.finished <- struct{}{}: - conn.watching = false - case <-conn.closech: - } -} - -func (conn *DmConnection) startWatcher() { - watcher := make(chan context.Context, 1) - conn.watcher = watcher - finished := make(chan struct{}) - conn.finished = finished - go func() { - for { - var ctx context.Context - select { - case ctx = <-watcher: - case <-conn.closech: - return - } - - select { - case <-ctx.Done(): - conn.cancel(ctx.Err()) - case <-finished: - case <-conn.closech: - return - } - } - }() -} - -func (conn *DmConnection) watchCancel(ctx context.Context) error { - if conn.watching { - - return conn.close() - } - - if err := ctx.Err(); err != nil { - return err - } - - if ctx.Done() == nil { - return nil - } - - if conn.watcher == nil { - return nil - } - - conn.watching = true - conn.watcher <- ctx - return nil -} - -type noCopy struct{} - -func (*noCopy) Lock() {} - -type atomicBool struct { - _noCopy noCopy - value uint32 -} - -func (ab *atomicBool) IsSet() bool { - return atomic.LoadUint32(&ab.value) > 0 -} - -func (ab *atomicBool) Set(value bool) { - if value { - atomic.StoreUint32(&ab.value, 1) - } else { - atomic.StoreUint32(&ab.value, 0) - } -} - -func (ab *atomicBool) TrySet(value bool) bool { - if value { - return atomic.SwapUint32(&ab.value, 1) == 0 - } - return atomic.SwapUint32(&ab.value, 0) > 0 -} - -type atomicError struct { - _noCopy noCopy - value atomic.Value -} - -func (ae *atomicError) Set(value error) { - ae.value.Store(value) -} - -func (ae *atomicError) Value() error { - if v := ae.value.Load(); v != nil { - - return v.(error) - } - return nil -} diff --git a/p.go b/main.go similarity index 52% rename from p.go rename to main.go index 70c095c..e783f39 100644 --- a/p.go +++ b/main.go @@ -10,13 +10,13 @@ import ( "database/sql/driver" "sync" - "gitee.com/chunanyong/dm/i18n" + "github.com/gotomicro/dmgo/i18n" ) // 发版标记 -var version = "8.1.2.38" -var build_date = "2021.07.14" -var svn = "7050" +//var version = "8.1.2.38" +//var build_date = "2021.07.14" +//var svn = "7050" var globalDmDriver = newDmDriver() @@ -24,13 +24,7 @@ func init() { sql.Register("dm", globalDmDriver) } -func driverInit(svcConfPath string) { - load(svcConfPath) - if GlobalProperties != nil && GlobalProperties.Len() > 0 { - setDriverAttributes(GlobalProperties) - } - globalDmDriver.createFilterChain(nil, GlobalProperties) - +func driverInit() { switch Locale { case 0: i18n.InitConfig(i18n.Messages_zh_CN) @@ -41,29 +35,26 @@ func driverInit(svcConfPath string) { } } -type DmDriver struct { +type Driver struct { filterable readPropMutex sync.Mutex } -func newDmDriver() *DmDriver { - d := new(DmDriver) +func newDmDriver() *Driver { + d := new(Driver) d.idGenerator = dmDriverIDGenerator return d } -/************************************************************* - ** PUBLIC METHODS AND FUNCTIONS - *************************************************************/ -func (d *DmDriver) Open(dsn string) (driver.Conn, error) { +func (d *Driver) Open(dsn string) (driver.Conn, error) { return d.open(dsn) } -func (d *DmDriver) OpenConnector(dsn string) (driver.Connector, error) { +func (d *Driver) OpenConnector(dsn string) (driver.Connector, error) { return d.openConnector(dsn) } -func (d *DmDriver) open(dsn string) (*DmConnection, error) { +func (d *Driver) open(dsn string) (*Connection, error) { c, err := d.openConnector(dsn) if err != nil { return nil, err @@ -71,8 +62,8 @@ func (d *DmDriver) open(dsn string) (*DmConnection, error) { return c.connect(context.Background()) } -func (d *DmDriver) openConnector(dsn string) (*DmConnector, error) { - connector := new(DmConnector).init() +func (d *Driver) openConnector(dsn string) (*Connector, error) { + connector := new(Connector).init() connector.url = dsn connector.dmDriver = d d.readPropMutex.Lock() diff --git a/parser/zt.go b/parser/zt.go index 04963dd..56c6491 100644 --- a/parser/zt.go +++ b/parser/zt.go @@ -27,9 +27,10 @@ type LVal struct { Position int } -func newLValNoParams() *LVal { - return new(LVal).reset() -} +// +//func newLValNoParams() *LVal { +// return new(LVal).reset() +//} func newLVal(value string, tp int) *LVal { return &LVal{Value: value, Tp: tp} diff --git a/parser/zu.go b/parser/zu.go index f516536..73bed4e 100644 --- a/parser/zu.go +++ b/parser/zu.go @@ -11,19 +11,19 @@ import ( ) const ( - YYEOF = -1 /** This character denotes the end of file */ - ZZ_BUFFERSIZE = 16384 /** initial size of the lookahead buffer */ + YYEOF = -1 /** This character denotes the end of file */ + ZZ_BUFFERSIZE = 16384 /** initial size of the lookahead buffer */ /** lexical states */ YYINITIAL = 0 xc = 2 xq = 4 xdq = 6 - xsb = 8 - xbin = 10 - xhex = 12 - xhint = 14 - xq2 = 16 - xq2_2 = 18 + //xsb = 8 + xbin = 10 + xhex = 12 + //xhint = 14 + xq2 = 16 + xq2_2 = 18 ) /** @@ -458,7 +458,7 @@ func (lexer *Lexer) zzRefill() (bool, error) { requested := len(lexer.zzBuffer) - lexer.zzEndRead var numRead = 0 - for i := lexer.zzEndRead; i < lexer.zzEndRead + requested; i ++ { + for i := lexer.zzEndRead; i < lexer.zzEndRead+requested; i++ { r, _, err := lexer.zzReader.ReadRune() if err == io.EOF { if numRead == 0 { @@ -728,7 +728,7 @@ func (lexer *Lexer) Yylex() (*LVal, error) { if zzCurrentPosL < zzEndReadL { zzInput = zzBufferL[zzCurrentPosL] - zzCurrentPosL += 1//utf8.RuneLen(zzInput) + zzCurrentPosL += 1 //utf8.RuneLen(zzInput) } else if lexer.zzAtEOF { zzInput = YYEOF goto zzForAction @@ -750,7 +750,7 @@ func (lexer *Lexer) Yylex() (*LVal, error) { goto zzForAction } else { zzInput = zzBufferL[zzCurrentPosL] - zzCurrentPosL += 1//utf8.RuneLen(zzInput) + zzCurrentPosL += 1 //utf8.RuneLen(zzInput) } } diff --git a/q.go b/q.go index 68e97ee..06ba0bc 100644 --- a/q.go +++ b/q.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( diff --git a/r.go b/r.go index 2efb90a..0e327e0 100644 --- a/r.go +++ b/r.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( diff --git a/security/zzg_mac.go b/security/zzg_mac.go new file mode 100644 index 0000000..835002e --- /dev/null +++ b/security/zzg_mac.go @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2000-2018, 达梦数据库有限公司. + * All rights reserved. + */ + +package security + +import "plugin" + +var ( + dmCipherEncryptSo *plugin.Plugin + cipherGetCountProc plugin.Symbol + cipherGetInfoProc plugin.Symbol + cipherEncryptInitProc plugin.Symbol + cipherGetCipherTextSizeProc plugin.Symbol + cipherEncryptProc plugin.Symbol + cipherCleanupProc plugin.Symbol + cipherDecryptInitProc plugin.Symbol + cipherDecryptProc plugin.Symbol +) + +func initThirdPartCipher(cipherPath string) (err error) { + if dmCipherEncryptSo, err = plugin.Open(cipherPath); err != nil { + return err + } + if cipherGetCountProc, err = dmCipherEncryptSo.Lookup("cipher_get_count"); err != nil { + return err + } + if cipherGetInfoProc, err = dmCipherEncryptSo.Lookup("cipher_get_info"); err != nil { + return err + } + if cipherEncryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt_init"); err != nil { + return err + } + if cipherGetCipherTextSizeProc, err = dmCipherEncryptSo.Lookup("cipher_get_cipher_text_size"); err != nil { + return err + } + if cipherEncryptProc, err = dmCipherEncryptSo.Lookup("cipher_encrypt"); err != nil { + return err + } + if cipherCleanupProc, err = dmCipherEncryptSo.Lookup("cipher_cleanup"); err != nil { + return err + } + if cipherDecryptInitProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt_init"); err != nil { + return err + } + if cipherDecryptProc, err = dmCipherEncryptSo.Lookup("cipher_decrypt"); err != nil { + return err + } + return nil +} + +func cipherGetCount() int { + ret := cipherGetCountProc.(func() interface{})() + return ret.(int) +} + +func cipherGetInfo(seqno, cipherId, cipherName, _type, blkSize, khSIze uintptr) { + ret := cipherGetInfoProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(seqno, cipherId, cipherName, _type, blkSize, khSIze) + if ret.(int) == 0 { + panic("ThirdPartyCipher: call cipher_get_info failed") + } +} + +func cipherEncryptInit(cipherId, key, keySize, cipherPara uintptr) { + ret := cipherEncryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara) + if ret.(int) == 0 { + panic("ThirdPartyCipher: call cipher_encrypt_init failed") + } +} + +func cipherGetCipherTextSize(cipherId, cipherPara, plainTextSize uintptr) uintptr { + ciphertextLen := cipherGetCipherTextSizeProc.(func(uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainTextSize) + return ciphertextLen.(uintptr) +} + +func cipherEncrypt(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize uintptr) uintptr { + ret := cipherEncryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, plainText, plainTextSize, cipherText, cipherTextBufSize) + return ret.(uintptr) +} + +func cipherClean(cipherId, cipherPara uintptr) { + cipherEncryptProc.(func(uintptr, uintptr))(cipherId, cipherPara) +} + +func cipherDecryptInit(cipherId, key, keySize, cipherPara uintptr) { + ret := cipherDecryptInitProc.(func(uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, key, keySize, cipherPara) + if ret.(int) == 0 { + panic("ThirdPartyCipher: call cipher_decrypt_init failed") + } +} + +func cipherDecrypt(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize uintptr) uintptr { + ret := cipherDecryptProc.(func(uintptr, uintptr, uintptr, uintptr, uintptr, uintptr) interface{})(cipherId, cipherPara, cipherText, cipherTextSize, plainText, plainTextBufSize) + return ret.(uintptr) +} diff --git a/u.go b/u.go index a0d74ae..1e95c8b 100644 --- a/u.go +++ b/u.go @@ -17,7 +17,7 @@ import ( "strings" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( @@ -31,7 +31,7 @@ var rp = newRsPool() type DmStatement struct { filterable - dmConn *DmConnection + dmConn *Connection rsMap map[int16]*innerRows inUse bool innerUsed bool @@ -134,7 +134,7 @@ func newRsPoolValue(execInfo *execRetInfo) rsPoolValue { return *rpv } -func (rpv rsPoolValue) refreshed(conn *DmConnection) (bool, error) { +func (rpv rsPoolValue) refreshed(conn *Connection) (bool, error) { if conn.dmConnector.rsRefreshFreq == 0 { return false, nil @@ -443,7 +443,7 @@ func (stmt *DmStatement) queryContext(ctx context.Context, args []driver.NamedVa return rows, err } -func NewDmStmt(conn *DmConnection, sql string) (*DmStatement, error) { +func NewDmStmt(conn *Connection, sql string) (*DmStatement, error) { var s *DmStatement if conn.stmtMap != nil && len(conn.stmtMap) > 0 { @@ -734,7 +734,7 @@ func encodeArgs(stmt *DmStatement, args []driver.Value) ([]interface{}, error) { } type converter struct { - conn *DmConnection + conn *Connection isBatch bool } type decimalDecompose interface { diff --git a/v.go b/v.go index 30fb8b6..13fae71 100644 --- a/v.go +++ b/v.go @@ -27,7 +27,7 @@ func newDmStruct(typeName string, elements []interface{}) *DmStruct { return ds } -func (ds *DmStruct) create(dc *DmConnection) (*DmStruct, error) { +func (ds *DmStruct) create(dc *Connection) (*DmStruct, error) { desc, err := newStructDescriptor(ds.typeName, dc) if err != nil { return nil, err @@ -60,7 +60,7 @@ func (ds *DmStruct) getAttribsTypeData() []TypeData { return ds.m_attribs } -func (ds *DmStruct) createByStructDescriptor(desc *StructDescriptor, conn *DmConnection) (*DmStruct, error) { +func (ds *DmStruct) createByStructDescriptor(desc *StructDescriptor, conn *Connection) (*DmStruct, error) { ds.initTypeData() if nil == desc { diff --git a/w.go b/w.go index ac74c4a..3f05dc0 100644 --- a/w.go +++ b/w.go @@ -50,7 +50,7 @@ func newDmTimestampFromDt(dt []int, dtype int, scale int) *DmTimestamp { return dmts } -func newDmTimestampFromBytes(bytes []byte, column column, conn *DmConnection) *DmTimestamp { +func newDmTimestampFromBytes(bytes []byte, column column, conn *Connection) *DmTimestamp { dmts := new(DmTimestamp) dmts.dt = decode(bytes, column.isBdta, int(column.colType), int(column.scale), int(conn.dmConnector.localTimezone), int(conn.DbTimezone)) diff --git a/y.go b/y.go index dcf2f12..6fc3d6c 100644 --- a/y.go +++ b/y.go @@ -11,7 +11,7 @@ import ( "sync" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) /** @@ -48,7 +48,7 @@ func newEPGroup(name string, serverList []*ep) *epGroup { return g } -func (g *epGroup) connect(connector *DmConnector) (*DmConnection, error) { +func (g *epGroup) connect(connector *Connector) (*Connection, error) { var dbSelector = g.getEPSelector(connector) var ex error = nil // 如果配置了loginMode的主、备等优先策略,而未找到最高优先级的节点时持续循环switchtimes次,如果最终还是没有找到最高优先级则选择次优先级的 @@ -72,7 +72,7 @@ func (g *epGroup) connect(connector *DmConnector) (*DmConnection, error) { return nil, ex } -func (g *epGroup) getEPSelector(connector *DmConnector) *epSelector { +func (g *epGroup) getEPSelector(connector *Connector) *epSelector { if connector.epSelector == TYPE_HEAD_FIRST { return newEPSelector(g.epList) } else { @@ -97,7 +97,7 @@ func (g *epGroup) getEPSelector(connector *DmConnector) *epSelector { * DBError.ECJDBC_INVALID_SERVER_MODE 有站点的模式不匹配 * DBError.ECJDBC_COMMUNITION_ERROR 所有站点都连不上 */ -func (g *epGroup) traverseServerList(connector *DmConnector, epSelector *epSelector, first bool, last bool) (*DmConnection, error) { +func (g *epGroup) traverseServerList(connector *Connector, epSelector *epSelector, first bool, last bool) (*Connection, error) { epList := epSelector.sortDBList(first) errorMsg := bytes.NewBufferString("") var ex error = nil // 第一个错误 diff --git a/z.go b/z.go index 7bb3315..97c441d 100644 --- a/z.go +++ b/z.go @@ -30,7 +30,7 @@ func (s *epSelector) sortDBList(first bool) []*ep { return s.dbs } -func (s *epSelector) checkServerMode(conn *DmConnection, last bool) (bool, error) { +func (s *epSelector) checkServerMode(conn *Connection, last bool) (bool, error) { // 只连dsc control节点 if conn.dmConnector.loginDscCtrl && !conn.dscControl { conn.close() diff --git a/za.go b/za.go index fb2120f..6bd98be 100644 --- a/za.go +++ b/za.go @@ -10,7 +10,7 @@ import ( "fmt" "runtime" - "gitee.com/chunanyong/dm/i18n" + "github.com/gotomicro/dmgo/i18n" ) // 驱动级错误 diff --git a/zc.go b/zc.go index 54307f3..bb8fa48 100644 --- a/zc.go +++ b/zc.go @@ -14,26 +14,26 @@ import ( ) type filter interface { - DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnection, error) - DmDriverOpenConnector(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnector, error) - - DmConnectorConnect(filterChain *filterChain, c *DmConnector, ctx context.Context) (*DmConnection, error) - DmConnectorDriver(filterChain *filterChain, c *DmConnector) *DmDriver - - DmConnectionBegin(filterChain *filterChain, c *DmConnection) (*DmConnection, error) - DmConnectionBeginTx(filterChain *filterChain, c *DmConnection, ctx context.Context, opts driver.TxOptions) (*DmConnection, error) - DmConnectionCommit(filterChain *filterChain, c *DmConnection) error - DmConnectionRollback(filterChain *filterChain, c *DmConnection) error - DmConnectionClose(filterChain *filterChain, c *DmConnection) error - DmConnectionPing(filterChain *filterChain, c *DmConnection, ctx context.Context) error - DmConnectionExec(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmResult, error) - DmConnectionExecContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) - DmConnectionQuery(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmRows, error) - DmConnectionQueryContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) - DmConnectionPrepare(filterChain *filterChain, c *DmConnection, query string) (*DmStatement, error) - DmConnectionPrepareContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string) (*DmStatement, error) - DmConnectionResetSession(filterChain *filterChain, c *DmConnection, ctx context.Context) error - DmConnectionCheckNamedValue(filterChain *filterChain, c *DmConnection, nv *driver.NamedValue) error + DmDriverOpen(filterChain *filterChain, d *Driver, dsn string) (*Connection, error) + DmDriverOpenConnector(filterChain *filterChain, d *Driver, dsn string) (*Connector, error) + + DmConnectorConnect(filterChain *filterChain, c *Connector, ctx context.Context) (*Connection, error) + DmConnectorDriver(filterChain *filterChain, c *Connector) *Driver + + DmConnectionBegin(filterChain *filterChain, c *Connection) (*Connection, error) + DmConnectionBeginTx(filterChain *filterChain, c *Connection, ctx context.Context, opts driver.TxOptions) (*Connection, error) + DmConnectionCommit(filterChain *filterChain, c *Connection) error + DmConnectionRollback(filterChain *filterChain, c *Connection) error + DmConnectionClose(filterChain *filterChain, c *Connection) error + DmConnectionPing(filterChain *filterChain, c *Connection, ctx context.Context) error + DmConnectionExec(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmResult, error) + DmConnectionExecContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) + DmConnectionQuery(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmRows, error) + DmConnectionQueryContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) + DmConnectionPrepare(filterChain *filterChain, c *Connection, query string) (*DmStatement, error) + DmConnectionPrepareContext(filterChain *filterChain, c *Connection, ctx context.Context, query string) (*DmStatement, error) + DmConnectionResetSession(filterChain *filterChain, c *Connection, ctx context.Context) error + DmConnectionCheckNamedValue(filterChain *filterChain, c *Connection, nv *driver.NamedValue) error DmStatementClose(filterChain *filterChain, s *DmStatement) error DmStatementNumInput(filterChain *filterChain, s *DmStatement) int @@ -122,7 +122,7 @@ func runStat() { goMapMu.Unlock() } -func (f *filterable) createFilterChain(bc *DmConnector, props *Properties) { +func (f *filterable) createFilterChain(bc *Connector, props *Properties) { var filters = make([]filter, 0, 5) if bc != nil { @@ -207,9 +207,9 @@ type rwInfo struct { rwCounter *rwCounter - connStandby *DmConnection + connStandby *Connection - connCurrent *DmConnection + connCurrent *Connection tryRecoverTs int64 @@ -302,7 +302,7 @@ func newStatInfo() *statInfo { si := new(statInfo) return si } -func (si *statInfo) init(conn *DmConnection) { +func (si *statInfo) init(conn *Connection) { si.connStat = goStat.createConnStat(conn) } diff --git a/zd.go b/zd.go index 2cf414c..0c286d9 100644 --- a/zd.go +++ b/zd.go @@ -28,7 +28,7 @@ func (filterChain *filterChain) reset() *filterChain { return filterChain } -func (filterChain *filterChain) DmDriverOpen(d *DmDriver, dsn string) (*DmConnection, error) { +func (filterChain *filterChain) DmDriverOpen(d *Driver, dsn string) (*Connection, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -38,7 +38,7 @@ func (filterChain *filterChain) DmDriverOpen(d *DmDriver, dsn string) (*DmConnec return d.open(dsn) } -func (filterChain *filterChain) DmDriverOpenConnector(d *DmDriver, dsn string) (*DmConnector, error) { +func (filterChain *filterChain) DmDriverOpenConnector(d *Driver, dsn string) (*Connector, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -49,7 +49,7 @@ func (filterChain *filterChain) DmDriverOpenConnector(d *DmDriver, dsn string) ( } //DmConnector -func (filterChain *filterChain) DmConnectorConnect(c *DmConnector, ctx context.Context) (*DmConnection, error) { +func (filterChain *filterChain) DmConnectorConnect(c *Connector, ctx context.Context) (*Connection, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -59,7 +59,7 @@ func (filterChain *filterChain) DmConnectorConnect(c *DmConnector, ctx context.C return c.connect(ctx) } -func (filterChain *filterChain) DmConnectorDriver(c *DmConnector) *DmDriver { +func (filterChain *filterChain) DmConnectorDriver(c *Connector) *Driver { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -70,7 +70,7 @@ func (filterChain *filterChain) DmConnectorDriver(c *DmConnector) *DmDriver { } //DmConnection -func (filterChain *filterChain) DmConnectionBegin(c *DmConnection) (*DmConnection, error) { +func (filterChain *filterChain) DmConnectionBegin(c *Connection) (*Connection, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -79,7 +79,7 @@ func (filterChain *filterChain) DmConnectionBegin(c *DmConnection) (*DmConnectio return c.begin() } -func (filterChain *filterChain) DmConnectionBeginTx(c *DmConnection, ctx context.Context, opts driver.TxOptions) (*DmConnection, error) { +func (filterChain *filterChain) DmConnectionBeginTx(c *Connection, ctx context.Context, opts driver.TxOptions) (*Connection, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -89,7 +89,7 @@ func (filterChain *filterChain) DmConnectionBeginTx(c *DmConnection, ctx context return c.beginTx(ctx, opts) } -func (filterChain *filterChain) DmConnectionCommit(c *DmConnection) error { +func (filterChain *filterChain) DmConnectionCommit(c *Connection) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -99,7 +99,7 @@ func (filterChain *filterChain) DmConnectionCommit(c *DmConnection) error { return c.commit() } -func (filterChain *filterChain) DmConnectionRollback(c *DmConnection) error { +func (filterChain *filterChain) DmConnectionRollback(c *Connection) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -109,7 +109,7 @@ func (filterChain *filterChain) DmConnectionRollback(c *DmConnection) error { return c.rollback() } -func (filterChain *filterChain) DmConnectionClose(c *DmConnection) error { +func (filterChain *filterChain) DmConnectionClose(c *Connection) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -119,7 +119,7 @@ func (filterChain *filterChain) DmConnectionClose(c *DmConnection) error { return c.close() } -func (filterChain *filterChain) DmConnectionPing(c *DmConnection, ctx context.Context) error { +func (filterChain *filterChain) DmConnectionPing(c *Connection, ctx context.Context) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -129,7 +129,7 @@ func (filterChain *filterChain) DmConnectionPing(c *DmConnection, ctx context.Co return c.ping(ctx) } -func (filterChain *filterChain) DmConnectionExec(c *DmConnection, query string, args []driver.Value) (*DmResult, error) { +func (filterChain *filterChain) DmConnectionExec(c *Connection, query string, args []driver.Value) (*DmResult, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -139,7 +139,7 @@ func (filterChain *filterChain) DmConnectionExec(c *DmConnection, query string, return c.exec(query, args) } -func (filterChain *filterChain) DmConnectionExecContext(c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { +func (filterChain *filterChain) DmConnectionExecContext(c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -149,7 +149,7 @@ func (filterChain *filterChain) DmConnectionExecContext(c *DmConnection, ctx con return c.execContext(ctx, query, args) } -func (filterChain *filterChain) DmConnectionQuery(c *DmConnection, query string, args []driver.Value) (*DmRows, error) { +func (filterChain *filterChain) DmConnectionQuery(c *Connection, query string, args []driver.Value) (*DmRows, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -159,7 +159,7 @@ func (filterChain *filterChain) DmConnectionQuery(c *DmConnection, query string, return c.query(query, args) } -func (filterChain *filterChain) DmConnectionQueryContext(c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { +func (filterChain *filterChain) DmConnectionQueryContext(c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -169,7 +169,7 @@ func (filterChain *filterChain) DmConnectionQueryContext(c *DmConnection, ctx co return c.queryContext(ctx, query, args) } -func (filterChain *filterChain) DmConnectionPrepare(c *DmConnection, query string) (*DmStatement, error) { +func (filterChain *filterChain) DmConnectionPrepare(c *Connection, query string) (*DmStatement, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -179,7 +179,7 @@ func (filterChain *filterChain) DmConnectionPrepare(c *DmConnection, query strin return c.prepare(query) } -func (filterChain *filterChain) DmConnectionPrepareContext(c *DmConnection, ctx context.Context, query string) (*DmStatement, error) { +func (filterChain *filterChain) DmConnectionPrepareContext(c *Connection, ctx context.Context, query string) (*DmStatement, error) { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -189,7 +189,7 @@ func (filterChain *filterChain) DmConnectionPrepareContext(c *DmConnection, ctx return c.prepareContext(ctx, query) } -func (filterChain *filterChain) DmConnectionResetSession(c *DmConnection, ctx context.Context) error { +func (filterChain *filterChain) DmConnectionResetSession(c *Connection, ctx context.Context) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ @@ -199,7 +199,7 @@ func (filterChain *filterChain) DmConnectionResetSession(c *DmConnection, ctx co return c.resetSession(ctx) } -func (filterChain *filterChain) DmConnectionCheckNamedValue(c *DmConnection, nv *driver.NamedValue) error { +func (filterChain *filterChain) DmConnectionCheckNamedValue(c *Connection, nv *driver.NamedValue) error { if filterChain.fpos < len(filterChain.filters) { f := filterChain.filters[filterChain.fpos] filterChain.fpos++ diff --git a/ze.go b/ze.go index 98b2167..67b3e1d 100644 --- a/ze.go +++ b/ze.go @@ -12,12 +12,12 @@ import ( "strconv" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) type logFilter struct{} -func (filter *logFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn string) (ret *DmConnection, err error) { +func (filter *logFilter) DmDriverOpen(filterChain *filterChain, d *Driver, dsn string) (ret *Connection, err error) { var logRecord = d.logInfo.logRecord logRecord.Set(d, "open", dsn) defer func() { @@ -32,7 +32,7 @@ func (filter *logFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn return } -func (filter *logFilter) DmDriverOpenConnector(filterChain *filterChain, d *DmDriver, dsn string) (ret *DmConnector, err error) { +func (filter *logFilter) DmDriverOpenConnector(filterChain *filterChain, d *Driver, dsn string) (ret *Connector, err error) { var logRecord = d.logInfo.logRecord logRecord.Set(d, "openConnector", dsn) defer func() { @@ -47,7 +47,7 @@ func (filter *logFilter) DmDriverOpenConnector(filterChain *filterChain, d *DmDr return } -func (filter *logFilter) DmConnectorConnect(filterChain *filterChain, c *DmConnector, ctx context.Context) (ret *DmConnection, err error) { +func (filter *logFilter) DmConnectorConnect(filterChain *filterChain, c *Connector, ctx context.Context) (ret *Connection, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "connect") defer func() { @@ -62,7 +62,7 @@ func (filter *logFilter) DmConnectorConnect(filterChain *filterChain, c *DmConne return } -func (filter *logFilter) DmConnectorDriver(filterChain *filterChain, c *DmConnector) (ret *DmDriver) { +func (filter *logFilter) DmConnectorDriver(filterChain *filterChain, c *Connector) (ret *Driver) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "driver") defer func() { @@ -73,7 +73,7 @@ func (filter *logFilter) DmConnectorDriver(filterChain *filterChain, c *DmConnec return } -func (filter *logFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnection) (ret *DmConnection, err error) { +func (filter *logFilter) DmConnectionBegin(filterChain *filterChain, c *Connection) (ret *Connection, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "begin") defer func() { @@ -88,7 +88,7 @@ func (filter *logFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnec return } -func (filter *logFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConnection, ctx context.Context, opts driver.TxOptions) (ret *DmConnection, err error) { +func (filter *logFilter) DmConnectionBeginTx(filterChain *filterChain, c *Connection, ctx context.Context, opts driver.TxOptions) (ret *Connection, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "beginTx", opts) defer func() { @@ -103,7 +103,7 @@ func (filter *logFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConn return } -func (filter *logFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnection) (err error) { +func (filter *logFilter) DmConnectionCommit(filterChain *filterChain, c *Connection) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "commit") defer func() { @@ -117,7 +117,7 @@ func (filter *logFilter) DmConnectionCommit(filterChain *filterChain, c *DmConne return } -func (filter *logFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnection) (err error) { +func (filter *logFilter) DmConnectionRollback(filterChain *filterChain, c *Connection) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "rollback") defer func() { @@ -131,7 +131,7 @@ func (filter *logFilter) DmConnectionRollback(filterChain *filterChain, c *DmCon return } -func (filter *logFilter) DmConnectionClose(filterChain *filterChain, c *DmConnection) (err error) { +func (filter *logFilter) DmConnectionClose(filterChain *filterChain, c *Connection) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "close") defer func() { @@ -145,7 +145,7 @@ func (filter *logFilter) DmConnectionClose(filterChain *filterChain, c *DmConnec return } -func (filter *logFilter) DmConnectionPing(filterChain *filterChain, c *DmConnection, ctx context.Context) (err error) { +func (filter *logFilter) DmConnectionPing(filterChain *filterChain, c *Connection, ctx context.Context) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "ping") defer func() { @@ -159,7 +159,7 @@ func (filter *logFilter) DmConnectionPing(filterChain *filterChain, c *DmConnect return } -func (filter *logFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (ret *DmResult, err error) { +func (filter *logFilter) DmConnectionExec(filterChain *filterChain, c *Connection, query string, args []driver.Value) (ret *DmResult, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "executeByStmt", query, args) defer func() { @@ -177,7 +177,7 @@ func (filter *logFilter) DmConnectionExec(filterChain *filterChain, c *DmConnect return } -func (filter *logFilter) DmConnectionExecContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (ret *DmResult, err error) { +func (filter *logFilter) DmConnectionExecContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (ret *DmResult, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "executeCtx", query, args) defer func() { @@ -195,7 +195,7 @@ func (filter *logFilter) DmConnectionExecContext(filterChain *filterChain, c *Dm return } -func (filter *logFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (ret *DmRows, err error) { +func (filter *logFilter) DmConnectionQuery(filterChain *filterChain, c *Connection, query string, args []driver.Value) (ret *DmRows, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "query", query, args) defer func() { @@ -213,7 +213,7 @@ func (filter *logFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnec return } -func (filter *logFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (ret *DmRows, err error) { +func (filter *logFilter) DmConnectionQueryContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (ret *DmRows, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "queryCtx", query, args) defer func() { @@ -231,7 +231,7 @@ func (filter *logFilter) DmConnectionQueryContext(filterChain *filterChain, c *D return } -func (filter *logFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnection, query string) (ret *DmStatement, err error) { +func (filter *logFilter) DmConnectionPrepare(filterChain *filterChain, c *Connection, query string) (ret *DmStatement, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "prepareStatement", query) defer func() { @@ -247,7 +247,7 @@ func (filter *logFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConn return } -func (filter *logFilter) DmConnectionPrepareContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string) (ret *DmStatement, err error) { +func (filter *logFilter) DmConnectionPrepareContext(filterChain *filterChain, c *Connection, ctx context.Context, query string) (ret *DmStatement, err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "prepareStatementCtx", query) defer func() { @@ -263,7 +263,7 @@ func (filter *logFilter) DmConnectionPrepareContext(filterChain *filterChain, c return } -func (filter *logFilter) DmConnectionResetSession(filterChain *filterChain, c *DmConnection, ctx context.Context) (err error) { +func (filter *logFilter) DmConnectionResetSession(filterChain *filterChain, c *Connection, ctx context.Context) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "resetSession") defer func() { @@ -277,7 +277,7 @@ func (filter *logFilter) DmConnectionResetSession(filterChain *filterChain, c *D return } -func (filter *logFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *DmConnection, nv *driver.NamedValue) (err error) { +func (filter *logFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *Connection, nv *driver.NamedValue) (err error) { var logRecord = c.logInfo.logRecord logRecord.Set(c, "checkNamedValue", nv) defer func() { @@ -667,11 +667,11 @@ func formatSource(source interface{}) string { switch src := source.(type) { case string: str += src - case *DmDriver: + case *Driver: str += formatDriver(src) - case *DmConnector: + case *Connector: str += formatContor(src) - case *DmConnection: + case *Connection: str += formatConn(src) case *DmStatement: str += formatConn(src.dmConn) + ", " @@ -690,21 +690,21 @@ func formatSource(source interface{}) string { return str } -func formatDriver(driver *DmDriver) string { +func formatDriver(driver *Driver) string { if driver != nil && driver.logInfo != nil { return "driver-" + strconv.FormatInt(driver.getID(), 10) } return "driver-nil" } -func formatContor(contor *DmConnector) string { +func formatContor(contor *Connector) string { if contor != nil && contor.logInfo != nil { return "contor-" + strconv.FormatInt(contor.getID(), 10) } return "contor-nil" } -func formatConn(conn *DmConnection) string { +func formatConn(conn *Connection) string { if conn != nil && conn.logInfo != nil { return "conn-" + strconv.FormatInt(conn.getID(), 10) } @@ -776,7 +776,7 @@ func formatTrace(source string, method string, returnValue interface{}, params . func formatReturn(returnObj interface{}) string { var str string switch o := returnObj.(type) { - case *DmConnection: + case *Connection: str = formatConn(o) sessID := o.SessionID if sessID != -1 { diff --git a/zf.go b/zf.go index 83a7a88..b155a03 100644 --- a/zf.go +++ b/zf.go @@ -12,7 +12,7 @@ import ( "reflect" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const SQL_GET_DSC_EP_SITE = "SELECT " + @@ -30,7 +30,7 @@ type reconnectFilter struct { } // 一定抛错 -func (rf *reconnectFilter) autoReconnect(connection *DmConnection, err error) error { +func (rf *reconnectFilter) autoReconnect(connection *Connection, err error) error { if dmErr, ok := err.(*DmError); ok { if dmErr.ErrCode == ECGO_COMMUNITION_ERROR.ErrCode { return rf.reconnect(connection, dmErr.Error()) @@ -40,7 +40,7 @@ func (rf *reconnectFilter) autoReconnect(connection *DmConnection, err error) er } // 一定抛错 -func (rf *reconnectFilter) reconnect(connection *DmConnection, reason string) error { +func (rf *reconnectFilter) reconnect(connection *Connection, reason string) error { // 读写分离,重连需要处理备机 var err error if connection.dmConnector.rwSeparate { @@ -57,7 +57,7 @@ func (rf *reconnectFilter) reconnect(connection *DmConnection, reason string) er return ECGO_CONNECTION_SWITCHED.addDetailln(reason).throw() } -func (rf *reconnectFilter) loadDscEpSites(conn *DmConnection) []*ep { +func (rf *reconnectFilter) loadDscEpSites(conn *Connection) []*ep { stmt, rs, err := conn.driverQuery(SQL_GET_DSC_EP_SITE) if err != nil { return nil @@ -81,7 +81,7 @@ func (rf *reconnectFilter) loadDscEpSites(conn *DmConnection) []*ep { return epList } -func (rf *reconnectFilter) checkAndRecover(conn *DmConnection) error { +func (rf *reconnectFilter) checkAndRecover(conn *Connection) error { if conn.dmConnector.doSwitch != DO_SWITCH_WHEN_EP_RECOVER { return nil } @@ -127,25 +127,25 @@ func (rf *reconnectFilter) checkAndRecover(conn *DmConnection) error { } //DmDriver -func (rf *reconnectFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnection, error) { +func (rf *reconnectFilter) DmDriverOpen(filterChain *filterChain, d *Driver, dsn string) (*Connection, error) { return filterChain.DmDriverOpen(d, dsn) } -func (rf *reconnectFilter) DmDriverOpenConnector(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnector, error) { +func (rf *reconnectFilter) DmDriverOpenConnector(filterChain *filterChain, d *Driver, dsn string) (*Connector, error) { return filterChain.DmDriverOpenConnector(d, dsn) } //DmConnector -func (rf *reconnectFilter) DmConnectorConnect(filterChain *filterChain, c *DmConnector, ctx context.Context) (*DmConnection, error) { +func (rf *reconnectFilter) DmConnectorConnect(filterChain *filterChain, c *Connector, ctx context.Context) (*Connection, error) { return filterChain.DmConnectorConnect(c, ctx) } -func (rf *reconnectFilter) DmConnectorDriver(filterChain *filterChain, c *DmConnector) *DmDriver { +func (rf *reconnectFilter) DmConnectorDriver(filterChain *filterChain, c *Connector) *Driver { return filterChain.DmConnectorDriver(c) } //DmConnection -func (rf *reconnectFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnection) (*DmConnection, error) { +func (rf *reconnectFilter) DmConnectionBegin(filterChain *filterChain, c *Connection) (*Connection, error) { dc, err := filterChain.DmConnectionBegin(c) if err != nil { return nil, rf.autoReconnect(c, err) @@ -153,7 +153,7 @@ func (rf *reconnectFilter) DmConnectionBegin(filterChain *filterChain, c *DmConn return dc, err } -func (rf *reconnectFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConnection, ctx context.Context, opts driver.TxOptions) (*DmConnection, error) { +func (rf *reconnectFilter) DmConnectionBeginTx(filterChain *filterChain, c *Connection, ctx context.Context, opts driver.TxOptions) (*Connection, error) { dc, err := filterChain.DmConnectionBeginTx(c, ctx, opts) if err != nil { return nil, rf.autoReconnect(c, err) @@ -161,7 +161,7 @@ func (rf *reconnectFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmCo return dc, err } -func (rf *reconnectFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnection) error { +func (rf *reconnectFilter) DmConnectionCommit(filterChain *filterChain, c *Connection) error { if err := filterChain.DmConnectionCommit(c); err != nil { return rf.autoReconnect(c, err) } @@ -171,7 +171,7 @@ func (rf *reconnectFilter) DmConnectionCommit(filterChain *filterChain, c *DmCon return nil } -func (rf *reconnectFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnection) error { +func (rf *reconnectFilter) DmConnectionRollback(filterChain *filterChain, c *Connection) error { err := filterChain.DmConnectionRollback(c) if err != nil { err = rf.autoReconnect(c, err) @@ -180,7 +180,7 @@ func (rf *reconnectFilter) DmConnectionRollback(filterChain *filterChain, c *DmC return err } -func (rf *reconnectFilter) DmConnectionClose(filterChain *filterChain, c *DmConnection) error { +func (rf *reconnectFilter) DmConnectionClose(filterChain *filterChain, c *Connection) error { err := filterChain.DmConnectionClose(c) if err != nil { err = rf.autoReconnect(c, err) @@ -189,7 +189,7 @@ func (rf *reconnectFilter) DmConnectionClose(filterChain *filterChain, c *DmConn return err } -func (rf *reconnectFilter) DmConnectionPing(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (rf *reconnectFilter) DmConnectionPing(filterChain *filterChain, c *Connection, ctx context.Context) error { err := filterChain.DmConnectionPing(c, ctx) if err != nil { err = rf.autoReconnect(c, err) @@ -198,7 +198,7 @@ func (rf *reconnectFilter) DmConnectionPing(filterChain *filterChain, c *DmConne return err } -func (rf *reconnectFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmResult, error) { +func (rf *reconnectFilter) DmConnectionExec(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmResult, error) { if err := rf.checkAndRecover(c); err != nil { return nil, rf.autoReconnect(c, err) } @@ -210,7 +210,7 @@ func (rf *reconnectFilter) DmConnectionExec(filterChain *filterChain, c *DmConne return dr, err } -func (rf *reconnectFilter) DmConnectionExecContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { +func (rf *reconnectFilter) DmConnectionExecContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { if err := rf.checkAndRecover(c); err != nil { return nil, rf.autoReconnect(c, err) } @@ -222,7 +222,7 @@ func (rf *reconnectFilter) DmConnectionExecContext(filterChain *filterChain, c * return dr, err } -func (rf *reconnectFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmRows, error) { +func (rf *reconnectFilter) DmConnectionQuery(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmRows, error) { if err := rf.checkAndRecover(c); err != nil { return nil, rf.autoReconnect(c, err) } @@ -234,7 +234,7 @@ func (rf *reconnectFilter) DmConnectionQuery(filterChain *filterChain, c *DmConn return dr, err } -func (rf *reconnectFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { +func (rf *reconnectFilter) DmConnectionQueryContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { if err := rf.checkAndRecover(c); err != nil { return nil, rf.autoReconnect(c, err) } @@ -246,7 +246,7 @@ func (rf *reconnectFilter) DmConnectionQueryContext(filterChain *filterChain, c return dr, err } -func (rf *reconnectFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnection, query string) (*DmStatement, error) { +func (rf *reconnectFilter) DmConnectionPrepare(filterChain *filterChain, c *Connection, query string) (*DmStatement, error) { ds, err := filterChain.DmConnectionPrepare(c, query) if err != nil { return nil, rf.autoReconnect(c, err) @@ -255,7 +255,7 @@ func (rf *reconnectFilter) DmConnectionPrepare(filterChain *filterChain, c *DmCo return ds, err } -func (rf *reconnectFilter) DmConnectionPrepareContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string) (*DmStatement, error) { +func (rf *reconnectFilter) DmConnectionPrepareContext(filterChain *filterChain, c *Connection, ctx context.Context, query string) (*DmStatement, error) { ds, err := filterChain.DmConnectionPrepareContext(c, ctx, query) if err != nil { return nil, rf.autoReconnect(c, err) @@ -264,7 +264,7 @@ func (rf *reconnectFilter) DmConnectionPrepareContext(filterChain *filterChain, return ds, err } -func (rf *reconnectFilter) DmConnectionResetSession(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (rf *reconnectFilter) DmConnectionResetSession(filterChain *filterChain, c *Connection, ctx context.Context) error { err := filterChain.DmConnectionResetSession(c, ctx) if err != nil { err = rf.autoReconnect(c, err) @@ -273,7 +273,7 @@ func (rf *reconnectFilter) DmConnectionResetSession(filterChain *filterChain, c return err } -func (rf *reconnectFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *DmConnection, nv *driver.NamedValue) error { +func (rf *reconnectFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *Connection, nv *driver.NamedValue) error { err := filterChain.DmConnectionCheckNamedValue(c, nv) if err != nil { err = rf.autoReconnect(c, err) diff --git a/zg.go b/zg.go index 79efa21..789eb11 100644 --- a/zg.go +++ b/zg.go @@ -15,25 +15,25 @@ type rwFilter struct { } //DmDriver -func (rwf *rwFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnection, error) { +func (rwf *rwFilter) DmDriverOpen(filterChain *filterChain, d *Driver, dsn string) (*Connection, error) { return filterChain.DmDriverOpen(d, dsn) } -func (rwf *rwFilter) DmDriverOpenConnector(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnector, error) { +func (rwf *rwFilter) DmDriverOpenConnector(filterChain *filterChain, d *Driver, dsn string) (*Connector, error) { return filterChain.DmDriverOpenConnector(d, dsn) } //DmConnector -func (rwf *rwFilter) DmConnectorConnect(filterChain *filterChain, c *DmConnector, ctx context.Context) (*DmConnection, error) { +func (rwf *rwFilter) DmConnectorConnect(filterChain *filterChain, c *Connector, ctx context.Context) (*Connection, error) { return RWUtil.connect(c, ctx) } -func (rwf *rwFilter) DmConnectorDriver(filterChain *filterChain, c *DmConnector) *DmDriver { +func (rwf *rwFilter) DmConnectorDriver(filterChain *filterChain, c *Connector) *Driver { return filterChain.DmConnectorDriver(c) } //DmConnection -func (rwf *rwFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnection) (*DmConnection, error) { +func (rwf *rwFilter) DmConnectionBegin(filterChain *filterChain, c *Connection) (*Connection, error) { if RWUtil.isStandbyAlive(c) { _, err := c.rwInfo.connStandby.begin() if err != nil { @@ -44,7 +44,7 @@ func (rwf *rwFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnection return filterChain.DmConnectionBegin(c) } -func (rwf *rwFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConnection, ctx context.Context, opts driver.TxOptions) (*DmConnection, error) { +func (rwf *rwFilter) DmConnectionBeginTx(filterChain *filterChain, c *Connection, ctx context.Context, opts driver.TxOptions) (*Connection, error) { if RWUtil.isStandbyAlive(c) { _, err := c.rwInfo.connStandby.beginTx(ctx, opts) if err != nil { @@ -55,7 +55,7 @@ func (rwf *rwFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConnecti return filterChain.DmConnectionBeginTx(c, ctx, opts) } -func (rwf *rwFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnection) error { +func (rwf *rwFilter) DmConnectionCommit(filterChain *filterChain, c *Connection) error { if RWUtil.isStandbyAlive(c) { err := c.rwInfo.connStandby.commit() if err != nil { @@ -66,7 +66,7 @@ func (rwf *rwFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnectio return filterChain.DmConnectionCommit(c) } -func (rwf *rwFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnection) error { +func (rwf *rwFilter) DmConnectionRollback(filterChain *filterChain, c *Connection) error { if RWUtil.isStandbyAlive(c) { err := c.rwInfo.connStandby.rollback() if err != nil { @@ -77,7 +77,7 @@ func (rwf *rwFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnect return filterChain.DmConnectionRollback(c) } -func (rwf *rwFilter) DmConnectionClose(filterChain *filterChain, c *DmConnection) error { +func (rwf *rwFilter) DmConnectionClose(filterChain *filterChain, c *Connection) error { if RWUtil.isStandbyAlive(c) { err := c.rwInfo.connStandby.close() if err != nil { @@ -88,14 +88,14 @@ func (rwf *rwFilter) DmConnectionClose(filterChain *filterChain, c *DmConnection return filterChain.DmConnectionClose(c) } -func (rwf *rwFilter) DmConnectionPing(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (rwf *rwFilter) DmConnectionPing(filterChain *filterChain, c *Connection, ctx context.Context) error { return filterChain.DmConnectionPing(c, ctx) } -func (rwf *rwFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmResult, error) { +func (rwf *rwFilter) DmConnectionExec(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmResult, error) { ret, err := RWUtil.executeByConn(c, query, func() (interface{}, error) { return c.rwInfo.connCurrent.exec(query, args) - }, func(otherConn *DmConnection) (interface{}, error) { + }, func(otherConn *Connection) (interface{}, error) { return otherConn.exec(query, args) }) if err != nil { @@ -104,10 +104,10 @@ func (rwf *rwFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection, return ret.(*DmResult), nil } -func (rwf *rwFilter) DmConnectionExecContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { +func (rwf *rwFilter) DmConnectionExecContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { ret, err := RWUtil.executeByConn(c, query, func() (interface{}, error) { return c.rwInfo.connCurrent.execContext(ctx, query, args) - }, func(otherConn *DmConnection) (interface{}, error) { + }, func(otherConn *Connection) (interface{}, error) { return otherConn.execContext(ctx, query, args) }) if err != nil { @@ -116,10 +116,10 @@ func (rwf *rwFilter) DmConnectionExecContext(filterChain *filterChain, c *DmConn return ret.(*DmResult), nil } -func (rwf *rwFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmRows, error) { +func (rwf *rwFilter) DmConnectionQuery(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmRows, error) { ret, err := RWUtil.executeByConn(c, query, func() (interface{}, error) { return c.rwInfo.connCurrent.query(query, args) - }, func(otherConn *DmConnection) (interface{}, error) { + }, func(otherConn *Connection) (interface{}, error) { return otherConn.query(query, args) }) if err != nil { @@ -128,10 +128,10 @@ func (rwf *rwFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnection return ret.(*DmRows), nil } -func (rwf *rwFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { +func (rwf *rwFilter) DmConnectionQueryContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { ret, err := RWUtil.executeByConn(c, query, func() (interface{}, error) { return c.rwInfo.connCurrent.queryContext(ctx, query, args) - }, func(otherConn *DmConnection) (interface{}, error) { + }, func(otherConn *Connection) (interface{}, error) { return otherConn.queryContext(ctx, query, args) }) if err != nil { @@ -140,7 +140,7 @@ func (rwf *rwFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmCon return ret.(*DmRows), nil } -func (rwf *rwFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnection, query string) (*DmStatement, error) { +func (rwf *rwFilter) DmConnectionPrepare(filterChain *filterChain, c *Connection, query string) (*DmStatement, error) { stmt, err := c.prepare(query) if err != nil { return nil, err @@ -158,7 +158,7 @@ func (rwf *rwFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnecti return stmt, nil } -func (rwf *rwFilter) DmConnectionPrepareContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string) (*DmStatement, error) { +func (rwf *rwFilter) DmConnectionPrepareContext(filterChain *filterChain, c *Connection, ctx context.Context, query string) (*DmStatement, error) { stmt, err := c.prepareContext(ctx, query) if err != nil { return nil, err @@ -176,7 +176,7 @@ func (rwf *rwFilter) DmConnectionPrepareContext(filterChain *filterChain, c *DmC return stmt, nil } -func (rwf *rwFilter) DmConnectionResetSession(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (rwf *rwFilter) DmConnectionResetSession(filterChain *filterChain, c *Connection, ctx context.Context) error { if RWUtil.isStandbyAlive(c) { err := c.rwInfo.connStandby.resetSession(ctx) if err != nil { @@ -187,7 +187,7 @@ func (rwf *rwFilter) DmConnectionResetSession(filterChain *filterChain, c *DmCon return filterChain.DmConnectionResetSession(c, ctx) } -func (rwf *rwFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *DmConnection, nv *driver.NamedValue) error { +func (rwf *rwFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *Connection, nv *driver.NamedValue) error { return filterChain.DmConnectionCheckNamedValue(c, nv) } diff --git a/zh.go b/zh.go index cd74d70..6f6f59e 100644 --- a/zh.go +++ b/zh.go @@ -18,7 +18,7 @@ type statFilter struct { } //DmDriver -func (sf *statFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnection, error) { +func (sf *statFilter) DmDriverOpen(filterChain *filterChain, d *Driver, dsn string) (*Connection, error) { conn, err := filterChain.DmDriverOpen(d, dsn) if err != nil { return nil, err @@ -29,12 +29,12 @@ func (sf *statFilter) DmDriverOpen(filterChain *filterChain, d *DmDriver, dsn st return conn, nil } -func (sf *statFilter) DmDriverOpenConnector(filterChain *filterChain, d *DmDriver, dsn string) (*DmConnector, error) { +func (sf *statFilter) DmDriverOpenConnector(filterChain *filterChain, d *Driver, dsn string) (*Connector, error) { return filterChain.DmDriverOpenConnector(d, dsn) } //DmConnector -func (sf *statFilter) DmConnectorConnect(filterChain *filterChain, c *DmConnector, ctx context.Context) (*DmConnection, error) { +func (sf *statFilter) DmConnectorConnect(filterChain *filterChain, c *Connector, ctx context.Context) (*Connection, error) { conn, err := filterChain.DmConnectorConnect(c, ctx) if err != nil { return nil, err @@ -45,20 +45,20 @@ func (sf *statFilter) DmConnectorConnect(filterChain *filterChain, c *DmConnecto return conn, nil } -func (sf *statFilter) DmConnectorDriver(filterChain *filterChain, c *DmConnector) *DmDriver { +func (sf *statFilter) DmConnectorDriver(filterChain *filterChain, c *Connector) *Driver { return filterChain.DmConnectorDriver(c) } //DmConnection -func (sf *statFilter) DmConnectionBegin(filterChain *filterChain, c *DmConnection) (*DmConnection, error) { +func (sf *statFilter) DmConnectionBegin(filterChain *filterChain, c *Connection) (*Connection, error) { return filterChain.DmConnectionBegin(c) } -func (sf *statFilter) DmConnectionBeginTx(filterChain *filterChain, c *DmConnection, ctx context.Context, opts driver.TxOptions) (*DmConnection, error) { +func (sf *statFilter) DmConnectionBeginTx(filterChain *filterChain, c *Connection, ctx context.Context, opts driver.TxOptions) (*Connection, error) { return filterChain.DmConnectionBeginTx(c, ctx, opts) } -func (sf *statFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnection) error { +func (sf *statFilter) DmConnectionCommit(filterChain *filterChain, c *Connection) error { err := filterChain.DmConnectionCommit(c) if err != nil { return err @@ -67,7 +67,7 @@ func (sf *statFilter) DmConnectionCommit(filterChain *filterChain, c *DmConnecti return nil } -func (sf *statFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnection) error { +func (sf *statFilter) DmConnectionRollback(filterChain *filterChain, c *Connection) error { err := filterChain.DmConnectionRollback(c) if err != nil { return err @@ -76,7 +76,7 @@ func (sf *statFilter) DmConnectionRollback(filterChain *filterChain, c *DmConnec return nil } -func (sf *statFilter) DmConnectionClose(filterChain *filterChain, c *DmConnection) error { +func (sf *statFilter) DmConnectionClose(filterChain *filterChain, c *Connection) error { if !c.closed.IsSet() { c.statInfo.getConnStat().decrementStmtByActiveStmtCount(int64(getActiveStmtCount(c))) c.statInfo.getConnStat().decrementConn() @@ -85,11 +85,11 @@ func (sf *statFilter) DmConnectionClose(filterChain *filterChain, c *DmConnectio return filterChain.DmConnectionClose(c) } -func (sf *statFilter) DmConnectionPing(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (sf *statFilter) DmConnectionPing(filterChain *filterChain, c *Connection, ctx context.Context) error { return c.ping(ctx) } -func (sf *statFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmResult, error) { +func (sf *statFilter) DmConnectionExec(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmResult, error) { connExecBefore(c, query) dr, err := filterChain.DmConnectionExec(c, query, args) if err != nil { @@ -100,7 +100,7 @@ func (sf *statFilter) DmConnectionExec(filterChain *filterChain, c *DmConnection return dr, nil } -func (sf *statFilter) DmConnectionExecContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { +func (sf *statFilter) DmConnectionExecContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmResult, error) { connExecBefore(c, query) dr, err := filterChain.DmConnectionExecContext(c, ctx, query, args) if err != nil { @@ -111,7 +111,7 @@ func (sf *statFilter) DmConnectionExecContext(filterChain *filterChain, c *DmCon return dr, nil } -func (sf *statFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnection, query string, args []driver.Value) (*DmRows, error) { +func (sf *statFilter) DmConnectionQuery(filterChain *filterChain, c *Connection, query string, args []driver.Value) (*DmRows, error) { connQueryBefore(c, query) dr, err := filterChain.DmConnectionQuery(c, query, args) if err != nil { @@ -122,7 +122,7 @@ func (sf *statFilter) DmConnectionQuery(filterChain *filterChain, c *DmConnectio return dr, nil } -func (sf *statFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { +func (sf *statFilter) DmConnectionQueryContext(filterChain *filterChain, c *Connection, ctx context.Context, query string, args []driver.NamedValue) (*DmRows, error) { connQueryBefore(c, query) dr, err := filterChain.DmConnectionQueryContext(c, ctx, query, args) if err != nil { @@ -133,7 +133,7 @@ func (sf *statFilter) DmConnectionQueryContext(filterChain *filterChain, c *DmCo return dr, nil } -func (sf *statFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnection, query string) (*DmStatement, error) { +func (sf *statFilter) DmConnectionPrepare(filterChain *filterChain, c *Connection, query string) (*DmStatement, error) { stmt, err := filterChain.DmConnectionPrepare(c, query) if err != nil { return nil, err @@ -142,7 +142,7 @@ func (sf *statFilter) DmConnectionPrepare(filterChain *filterChain, c *DmConnect return stmt, nil } -func (sf *statFilter) DmConnectionPrepareContext(filterChain *filterChain, c *DmConnection, ctx context.Context, query string) (*DmStatement, error) { +func (sf *statFilter) DmConnectionPrepareContext(filterChain *filterChain, c *Connection, ctx context.Context, query string) (*DmStatement, error) { stmt, err := filterChain.DmConnectionPrepareContext(c, ctx, query) if err != nil { return nil, err @@ -151,11 +151,11 @@ func (sf *statFilter) DmConnectionPrepareContext(filterChain *filterChain, c *Dm return stmt, nil } -func (sf *statFilter) DmConnectionResetSession(filterChain *filterChain, c *DmConnection, ctx context.Context) error { +func (sf *statFilter) DmConnectionResetSession(filterChain *filterChain, c *Connection, ctx context.Context) error { return filterChain.DmConnectionResetSession(c, ctx) } -func (sf *statFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *DmConnection, nv *driver.NamedValue) error { +func (sf *statFilter) DmConnectionCheckNamedValue(filterChain *filterChain, c *Connection, nv *driver.NamedValue) error { return filterChain.DmConnectionCheckNamedValue(c, nv) } @@ -272,7 +272,7 @@ func (sf *statFilter) DmRowsColumnTypePrecisionScale(filterChain *filterChain, r return filterChain.DmRowsColumnTypePrecisionScale(r, index) } -func getActiveStmtCount(conn *DmConnection) int { +func getActiveStmtCount(conn *Connection) int { if conn.stmtMap == nil { return 0 } else { @@ -280,30 +280,30 @@ func getActiveStmtCount(conn *DmConnection) int { } } -func statementCreateAfter(conn *DmConnection, stmt *DmStatement) { +func statementCreateAfter(conn *Connection, stmt *DmStatement) { stmt.statInfo.setConstructNano() conn.statInfo.getConnStat().incrementStmt() } -func connExecBefore(conn *DmConnection, sql string) { +func connExecBefore(conn *Connection, sql string) { conn.statInfo.setLastExecuteSql(sql) conn.statInfo.setFirstResultSet(false) conn.statInfo.setLastExecuteType(ExecuteUpdate) internalBeforeConnExecute(conn, sql) } -func connExecAfter(conn *DmConnection, sql string, args interface{}, updateCount int) { +func connExecAfter(conn *Connection, sql string, args interface{}, updateCount int) { internalAfterConnExecute(conn, args, updateCount) } -func connQueryBefore(conn *DmConnection, sql string) { +func connQueryBefore(conn *Connection, sql string) { conn.statInfo.setLastExecuteSql(sql) conn.statInfo.setFirstResultSet(true) conn.statInfo.setLastExecuteType(ExecuteQuery) internalBeforeConnExecute(conn, sql) } -func connQueryAfter(conn *DmConnection, sql string, args interface{}, resultSet *DmRows) { +func connQueryAfter(conn *Connection, sql string, args interface{}, resultSet *DmRows) { if resultSet != nil { connResultSetCreateAfter(resultSet, conn) } @@ -335,7 +335,7 @@ func stmtQueryAfter(stmt *DmStatement, args interface{}, resultSet *DmRows) { internalAfterStatementExecute(stmt, args, 0) } -func internalBeforeConnExecute(conn *DmConnection, sql string) { +func internalBeforeConnExecute(conn *Connection, sql string) { connStat := conn.statInfo.getConnStat() connStat.incrementExecuteCount() conn.statInfo.beforeExecute() @@ -359,7 +359,7 @@ func internalBeforeConnExecute(conn *DmConnection, sql string) { } } -func internalAfterConnExecute(conn *DmConnection, args interface{}, updateCount int) { +func internalAfterConnExecute(conn *Connection, args interface{}, updateCount int) { nowNano := time.Now().UnixNano() nanos := nowNano - conn.statInfo.getLastExecuteStartNano() @@ -520,7 +520,7 @@ func buildStmtSlowParameters(stmt *DmStatement, args interface{}) string { } } -func connExecuteErrorAfter(conn *DmConnection, args interface{}, err error) { +func connExecuteErrorAfter(conn *Connection, args interface{}, err error) { nanos := time.Now().UnixNano() - conn.statInfo.getLastExecuteStartNano() conn.statInfo.getConnStat().incrementErrorCount() conn.statInfo.afterExecute(nanos) @@ -561,7 +561,7 @@ func statementCloseBefore(stmt *DmStatement) { stmt.dmConn.statInfo.getConnStat().decrementStmt() } -func connResultSetCreateAfter(dmdbResultSet *DmRows, conn *DmConnection) { +func connResultSetCreateAfter(dmdbResultSet *DmRows, conn *Connection) { dmdbResultSet.statInfo.setSql(conn.statInfo.getLastExecuteSql()) dmdbResultSet.statInfo.setSqlStat(conn.statInfo.getSqlStat()) dmdbResultSet.statInfo.setConstructNano() diff --git a/zi.go b/zi.go index 9cc781e..002e8bb 100644 --- a/zi.go +++ b/zi.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) var G2DB g2db @@ -95,7 +95,7 @@ func (G2DB g2db) checkReal(val interface{}) error { return nil } -func (G2DB g2db) fromBool(val bool, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromBool(val bool, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case BOOLEAN, BIT, TINYINT, SMALLINT, INT, BIGINT, REAL, DOUBLE, DECIMAL, CHAR, VARCHAR2, VARCHAR, CLOB: @@ -114,7 +114,7 @@ func (G2DB g2db) fromBool(val bool, param parameter, conn *DmConnection) ([]byte return nil, ECGO_DATA_CONVERTION_ERROR.throw() } -func (G2DB g2db) fromInt64(val int64, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromInt64(val int64, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case BOOLEAN, BIT: @@ -204,7 +204,7 @@ func (G2DB g2db) ToBinary(x int64, prec int) []byte { return b } -func (G2DB g2db) fromFloat32(val float32, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromFloat32(val float32, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case BOOLEAN, BIT: if val == 0.0 { @@ -250,7 +250,7 @@ func (G2DB g2db) fromFloat32(val float32, param parameter, conn *DmConnection) ( return nil, ECGO_DATA_CONVERTION_ERROR.throw() } -func (G2DB g2db) fromFloat64(val float64, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromFloat64(val float64, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case BOOLEAN, BIT: @@ -313,7 +313,7 @@ func (G2DB g2db) fromFloat64(val float64, param parameter, conn *DmConnection) ( return nil, ECGO_DATA_CONVERTION_ERROR.throw() } -func (G2DB g2db) fromBytes(val []byte, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) fromBytes(val []byte, param parameter, conn *Connection) (interface{}, error) { switch param.colType { case CHAR, VARCHAR2, VARCHAR: return G2DB.toVarchar(val) @@ -384,7 +384,7 @@ func (G2DB g2db) getCharByNumVal(val byte) (byte, error) { return 0, ECGO_INVALID_HEX.throw() } -func (G2DB g2db) fromString(val string, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) fromString(val string, param parameter, conn *Connection) (interface{}, error) { switch param.colType { case BOOLEAN, BIT: ret, err := G2DB.toBool(val) @@ -512,7 +512,7 @@ func (G2DB g2db) toBool(str string) (bool, error) { return strings.ToLower(str) == "true", nil } -func (G2DB g2db) fromBigInt(val *big.Int, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromBigInt(val *big.Int, param parameter, conn *Connection) ([]byte, error) { var ret []byte switch param.colType { case BOOLEAN, BIT: @@ -580,7 +580,7 @@ func (G2DB g2db) fromBigInt(val *big.Int, param parameter, conn *DmConnection) ( return ret, nil } -func (G2DB g2db) fromBigFloat(val *big.Float, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromBigFloat(val *big.Float, param parameter, conn *Connection) ([]byte, error) { var ret []byte switch param.colType { case BOOLEAN, BIT: @@ -659,7 +659,7 @@ func (G2DB g2db) fromBigFloat(val *big.Float, param parameter, conn *DmConnectio return ret, nil } -func (G2DB g2db) fromDecimal(val DmDecimal, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromDecimal(val DmDecimal, param parameter, conn *Connection) ([]byte, error) { var ret []byte switch param.colType { case BOOLEAN, BIT: @@ -711,7 +711,7 @@ func (G2DB g2db) fromDecimal(val DmDecimal, param parameter, conn *DmConnection) return ret, nil } -func (G2DB g2db) fromTime(val time.Time, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromTime(val time.Time, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case DATE, DATETIME, DATETIME_TZ, TIME, TIME_TZ: @@ -723,7 +723,7 @@ func (G2DB g2db) fromTime(val time.Time, param parameter, conn *DmConnection) ([ return nil, ECGO_DATA_CONVERTION_ERROR.throw() } -func (G2DB g2db) fromDmIntervalDT(val DmIntervalDT, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromDmIntervalDT(val DmIntervalDT, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case CHAR, VARCHAR2, VARCHAR, CLOB: return Dm_build_1219.Dm_build_1432(val.String(), conn.getServerEncoding(), conn), nil @@ -734,7 +734,7 @@ func (G2DB g2db) fromDmIntervalDT(val DmIntervalDT, param parameter, conn *DmCon } } -func (G2DB g2db) fromDmdbIntervalYM(val DmIntervalYM, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromDmdbIntervalYM(val DmIntervalYM, param parameter, conn *Connection) ([]byte, error) { switch param.colType { case CHAR, VARCHAR, VARCHAR2, CLOB: @@ -746,7 +746,7 @@ func (G2DB g2db) fromDmdbIntervalYM(val DmIntervalYM, param parameter, conn *DmC } } -func (G2DB g2db) fromBlob(val DmBlob, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) fromBlob(val DmBlob, param parameter, conn *Connection) (interface{}, error) { var ret interface{} switch param.colType { case BINARY, VARBINARY: @@ -772,7 +772,7 @@ func (G2DB g2db) fromBlob(val DmBlob, param parameter, conn *DmConnection) (inte return ret, nil } -func (G2DB g2db) fromClob(val DmClob, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) fromClob(val DmClob, param parameter, conn *Connection) (interface{}, error) { var ret interface{} switch param.colType { case CHAR, VARCHAR, VARCHAR2: @@ -800,7 +800,7 @@ func (G2DB g2db) fromClob(val DmClob, param parameter, conn *DmConnection) (inte return ret, nil } -func (G2DB g2db) fromReader(val io.Reader, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) fromReader(val io.Reader, param parameter, conn *Connection) (interface{}, error) { var ret interface{} switch param.colType { case CHAR, VARCHAR2, VARCHAR: @@ -828,15 +828,15 @@ func (G2DB g2db) fromReader(val io.Reader, param parameter, conn *DmConnection) return ret, nil } -func (G2DB g2db) string2Clob(val string, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) string2Clob(val string, param parameter, conn *Connection) (interface{}, error) { return G2DB.changeOffRowData(param, Dm_build_1219.Dm_build_1432(val, conn.getServerEncoding(), conn), conn.getServerEncoding()) } -func (G2DB g2db) bytes2Blob(val []byte, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) bytes2Blob(val []byte, param parameter, conn *Connection) (interface{}, error) { return G2DB.changeOffRowData(param, val, conn.getServerEncoding()) } -func (G2DB g2db) clob2Clob(val DmClob, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) clob2Clob(val DmClob, param parameter, conn *Connection) (interface{}, error) { var clobLen int64 var err error if clobLen, err = val.GetLength(); err != nil { @@ -857,7 +857,7 @@ func (G2DB g2db) clob2Clob(val DmClob, param parameter, conn *DmConnection) (int } } -func (G2DB g2db) blob2Blob(val DmBlob, param parameter, conn *DmConnection) (interface{}, error) { +func (G2DB g2db) blob2Blob(val DmBlob, param parameter, conn *Connection) (interface{}, error) { var clobLen int64 var err error if clobLen, err = val.GetLength(); err != nil { @@ -886,7 +886,7 @@ func (G2DB g2db) isOffRow(dtype int32, length int64) bool { return (dtype == BLOB || dtype == CLOB) && length > Dm_build_713 } -func (G2DB g2db) fromObject(mem interface{}, param parameter, conn *DmConnection) ([]byte, error) { +func (G2DB g2db) fromObject(mem interface{}, param parameter, conn *Connection) ([]byte, error) { switch v := mem.(type) { case bool: return G2DB.fromBool(v, param, conn) @@ -964,7 +964,7 @@ func (G2DB g2db) toDecimal(val string, prec int, scale int) ([]byte, error) { return d.encodeDecimal() } -func (G2DB g2db) fromArray(x *DmArray, param parameter, connection *DmConnection) (interface{}, error) { +func (G2DB g2db) fromArray(x *DmArray, param parameter, connection *Connection) (interface{}, error) { var ret interface{} var err error switch param.colType { @@ -983,7 +983,7 @@ func (G2DB g2db) fromArray(x *DmArray, param parameter, connection *DmConnection return ret, err } -func (G2DB g2db) fromStruct(x *DmStruct, param parameter, connection *DmConnection) (interface{}, error) { +func (G2DB g2db) fromStruct(x *DmStruct, param parameter, connection *Connection) (interface{}, error) { var ret interface{} var err error switch param.colType { diff --git a/zn.go b/zn.go index 98c0424..a75b1eb 100644 --- a/zn.go +++ b/zn.go @@ -52,7 +52,7 @@ type lob struct { totalOffset int32 readOver bool - connection *DmConnection + connection *Connection local bool updateable bool lobFlag int8 @@ -95,7 +95,7 @@ func (lob *lob) getLengthFromHead(head []byte) int64 { return int64(Dm_build_1219.Dm_build_1321(head, NBLOB_HEAD_BLOB_LEN)) } -func (lob *lob) canOptimized(connection *DmConnection) bool { +func (lob *lob) canOptimized(connection *Connection) bool { return !(lob.inRow || lob.fetchAll || lob.local || connection != lob.connection) } diff --git a/zp.go b/zp.go index 0e3c631..77742d5 100644 --- a/zp.go +++ b/zp.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( diff --git a/zq.go b/zq.go index e1266b1..9afbcf7 100644 --- a/zq.go +++ b/zq.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( @@ -639,7 +639,7 @@ type dm_build_724 interface { } type dm_build_740 struct { - dm_build_741 *dm_build_332 + dm_build_741 *Access dm_build_742 int16 @@ -648,22 +648,22 @@ type dm_build_740 struct { dm_build_744 *DmStatement } -func (dm_build_746 *dm_build_740) dm_build_745(dm_build_747 *dm_build_332, dm_build_748 int16) *dm_build_740 { +func (dm_build_746 *dm_build_740) dm_build_745(dm_build_747 *Access, dm_build_748 int16) *dm_build_740 { dm_build_746.dm_build_741 = dm_build_747 dm_build_746.dm_build_742 = dm_build_748 return dm_build_746 } -func (dm_build_750 *dm_build_740) dm_build_749(dm_build_751 *dm_build_332, dm_build_752 int16, dm_build_753 *DmStatement) *dm_build_740 { +func (dm_build_750 *dm_build_740) dm_build_749(dm_build_751 *Access, dm_build_752 int16, dm_build_753 *DmStatement) *dm_build_740 { dm_build_750.dm_build_745(dm_build_751, dm_build_752).dm_build_744 = dm_build_753 return dm_build_750 } -func dm_build_754(dm_build_755 *dm_build_332, dm_build_756 int16) *dm_build_740 { +func dm_build_754(dm_build_755 *Access, dm_build_756 int16) *dm_build_740 { return new(dm_build_740).dm_build_745(dm_build_755, dm_build_756) } -func dm_build_757(dm_build_758 *dm_build_332, dm_build_759 int16, dm_build_760 *DmStatement) *dm_build_740 { +func dm_build_757(dm_build_758 *Access, dm_build_759 int16, dm_build_760 *DmStatement) *dm_build_740 { return new(dm_build_740).dm_build_749(dm_build_758, dm_build_759, dm_build_760) } @@ -715,7 +715,7 @@ func (dm_build_774 *dm_build_740) dm_build_773() error { func (dm_build_776 *dm_build_740) dm_build_775() string { - dm_build_777 := dm_build_776.dm_build_741.dm_build_336.getServerEncoding() + dm_build_777 := dm_build_776.dm_build_741.conn.getServerEncoding() if dm_build_777 != "" && dm_build_777 == ENCODING_EUCKR && Locale != LANGUAGE_EN { dm_build_777 = ENCODING_GB18030 @@ -727,7 +727,7 @@ func (dm_build_776 *dm_build_740) dm_build_775() string { dm_build_776.dm_build_741.dm_build_335.Dm_build_25(int(dm_build_776.dm_build_741.dm_build_335.Dm_build_125()), false, true) - return dm_build_776.dm_build_741.dm_build_335.Dm_build_167(dm_build_777, dm_build_776.dm_build_741.dm_build_336) + return dm_build_776.dm_build_741.dm_build_335.Dm_build_167(dm_build_777, dm_build_776.dm_build_741.conn) } func (dm_build_779 *dm_build_740) dm_build_728(dm_build_780 dm_build_724) (dm_build_781 error) { @@ -844,7 +844,7 @@ type dm_build_811 struct { dm_build_740 } -func dm_build_812(dm_build_813 *dm_build_332) *dm_build_811 { +func dm_build_812(dm_build_813 *Access) *dm_build_811 { dm_build_814 := new(dm_build_811) dm_build_814.dm_build_745(dm_build_813, Dm_build_612) return dm_build_814 @@ -855,7 +855,7 @@ type dm_build_815 struct { dm_build_816 string } -func dm_build_817(dm_build_818 *dm_build_332, dm_build_819 *DmStatement, dm_build_820 string) *dm_build_815 { +func dm_build_817(dm_build_818 *Access, dm_build_819 *DmStatement, dm_build_820 string) *dm_build_815 { dm_build_821 := new(dm_build_815) dm_build_821.dm_build_749(dm_build_818, Dm_build_620, dm_build_819) dm_build_821.dm_build_816 = dm_build_820 @@ -864,7 +864,7 @@ func dm_build_817(dm_build_818 *dm_build_332, dm_build_819 *DmStatement, dm_buil } func (dm_build_823 *dm_build_815) dm_build_726() error { - dm_build_823.dm_build_741.dm_build_335.Dm_build_113(dm_build_823.dm_build_816, dm_build_823.dm_build_741.dm_build_336.getServerEncoding(), dm_build_823.dm_build_741.dm_build_336) + dm_build_823.dm_build_741.dm_build_335.Dm_build_113(dm_build_823.dm_build_816, dm_build_823.dm_build_741.conn.getServerEncoding(), dm_build_823.dm_build_741.conn) dm_build_823.dm_build_741.dm_build_335.Dm_build_51(1) return nil } @@ -874,7 +874,7 @@ type Dm_build_824 struct { dm_build_825 []OptParameter } -func dm_build_826(dm_build_827 *dm_build_332, dm_build_828 *DmStatement, dm_build_829 []OptParameter) *Dm_build_824 { +func dm_build_826(dm_build_827 *Access, dm_build_828 *DmStatement, dm_build_829 []OptParameter) *Dm_build_824 { dm_build_830 := new(Dm_build_824) dm_build_830.dm_build_749(dm_build_827, Dm_build_630, dm_build_828) dm_build_830.dm_build_825 = dm_build_829 @@ -926,17 +926,17 @@ type dm_build_840 struct { dm_build_843 bool } -func dm_build_844(dm_build_845 *dm_build_332, dm_build_846 int16, dm_build_847 *DmStatement) *dm_build_840 { +func dm_build_844(dm_build_845 *Access, dm_build_846 int16, dm_build_847 *DmStatement) *dm_build_840 { dm_build_848 := new(dm_build_840) dm_build_848.dm_build_749(dm_build_845, dm_build_846, dm_build_847) dm_build_848.dm_build_843 = true return dm_build_848 } -func dm_build_849(dm_build_850 *dm_build_332, dm_build_851 *DmStatement, dm_build_852 [][]interface{}) *dm_build_840 { +func dm_build_849(dm_build_850 *Access, dm_build_851 *DmStatement, dm_build_852 [][]interface{}) *dm_build_840 { dm_build_853 := new(dm_build_840) - if dm_build_850.dm_build_336.Execute2 { + if dm_build_850.conn.Execute2 { dm_build_853.dm_build_749(dm_build_850, Dm_build_614, dm_build_851) } else { dm_build_853.dm_build_749(dm_build_850, Dm_build_610, dm_build_851) @@ -952,7 +952,7 @@ func (dm_build_855 *dm_build_840) dm_build_854(dm_build_856 int32, dm_build_857 dm_build_858 := Dm_build_633 - if dm_build_855.dm_build_741.dm_build_336.autoCommit { + if dm_build_855.dm_build_741.conn.autoCommit { dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 1) } else { dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 0) @@ -974,7 +974,7 @@ func (dm_build_855 *dm_build_840) dm_build_854(dm_build_856 int32, dm_build_857 dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 1) - if dm_build_855.dm_build_741.dm_build_336.dmConnector.continueBatchOnError { + if dm_build_855.dm_build_741.conn.dmConnector.continueBatchOnError { dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 1) } else { dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 0) @@ -990,7 +990,7 @@ func (dm_build_855 *dm_build_840) dm_build_854(dm_build_856 int32, dm_build_857 dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_191(dm_build_858, dm_build_855.dm_build_744.queryTimeout) } - dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_191(dm_build_858, dm_build_855.dm_build_741.dm_build_336.dmConnector.batchAllowMaxErrors) + dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_191(dm_build_858, dm_build_855.dm_build_741.conn.dmConnector.batchAllowMaxErrors) if dm_build_855.dm_build_744.innerExec { dm_build_858 += dm_build_855.dm_build_741.dm_build_335.Dm_build_183(dm_build_858, 1) @@ -1323,7 +1323,7 @@ func (dm_build_882 *dm_build_840) dm_build_881(dm_build_883 int) [][]byte { } func (dm_build_891 *dm_build_840) dm_build_890(dm_build_892 int, dm_build_893 bool) []column { - dm_build_894 := dm_build_891.dm_build_741.dm_build_336.getServerEncoding() + dm_build_894 := dm_build_891.dm_build_741.conn.getServerEncoding() var dm_build_895, dm_build_896, dm_build_897, dm_build_898 int16 dm_build_899 := make([]column, dm_build_892) for i := 0; i < dm_build_892; i++ { @@ -1353,13 +1353,13 @@ func (dm_build_891 *dm_build_840) dm_build_890(dm_build_892 int, dm_build_893 bo dm_build_897 = dm_build_891.dm_build_741.dm_build_335.Dm_build_122() dm_build_898 = dm_build_891.dm_build_741.dm_build_335.Dm_build_122() - dm_build_899[i].name = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_895), dm_build_894, dm_build_891.dm_build_741.dm_build_336) - dm_build_899[i].typeName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_896), dm_build_894, dm_build_891.dm_build_741.dm_build_336) - dm_build_899[i].tableName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_897), dm_build_894, dm_build_891.dm_build_741.dm_build_336) - dm_build_899[i].schemaName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_898), dm_build_894, dm_build_891.dm_build_741.dm_build_336) + dm_build_899[i].name = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_895), dm_build_894, dm_build_891.dm_build_741.conn) + dm_build_899[i].typeName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_896), dm_build_894, dm_build_891.dm_build_741.conn) + dm_build_899[i].tableName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_897), dm_build_894, dm_build_891.dm_build_741.conn) + dm_build_899[i].schemaName = dm_build_891.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_898), dm_build_894, dm_build_891.dm_build_741.conn) if dm_build_891.dm_build_744.readBaseColName { - dm_build_899[i].baseName = dm_build_891.dm_build_741.dm_build_335.Dm_build_175(dm_build_894, dm_build_891.dm_build_741.dm_build_336) + dm_build_899[i].baseName = dm_build_891.dm_build_741.dm_build_335.Dm_build_175(dm_build_894, dm_build_891.dm_build_741.conn) } if dm_build_899[i].lob { @@ -1372,7 +1372,7 @@ func (dm_build_891 *dm_build_840) dm_build_890(dm_build_892 int, dm_build_893 bo for i := 0; i < dm_build_892; i++ { if isComplexType(int(dm_build_899[i].colType), int(dm_build_899[i].scale)) { - strDesc := newTypeDescriptor(dm_build_891.dm_build_741.dm_build_336) + strDesc := newTypeDescriptor(dm_build_891.dm_build_741.conn) strDesc.unpack(dm_build_891.dm_build_741.dm_build_335) dm_build_899[i].typeDescriptor = strDesc } @@ -1447,7 +1447,7 @@ func (dm_build_907 *dm_build_840) dm_build_906(dm_build_908 []int64) error { code := dm_build_907.dm_build_741.dm_build_335.Dm_build_125() - errStr := dm_build_907.dm_build_741.dm_build_335.Dm_build_175(dm_build_907.dm_build_741.dm_build_336.getServerEncoding(), dm_build_907.dm_build_741.dm_build_336) + errStr := dm_build_907.dm_build_741.dm_build_335.Dm_build_175(dm_build_907.dm_build_741.conn.getServerEncoding(), dm_build_907.dm_build_741.conn) dm_build_910 = append(dm_build_910, "row["+strconv.Itoa(int(irow))+"]:"+strconv.Itoa(int(code))+", "+errStr) } @@ -1649,7 +1649,7 @@ type dm_build_945 struct { dm_build_948 int64 } -func dm_build_949(dm_build_950 *dm_build_332, dm_build_951 *innerRows, dm_build_952 int64, dm_build_953 int64) *dm_build_945 { +func dm_build_949(dm_build_950 *Access, dm_build_951 *innerRows, dm_build_952 int64, dm_build_953 int64) *dm_build_945 { dm_build_954 := new(dm_build_945) dm_build_954.dm_build_749(dm_build_950, Dm_build_611, dm_build_951.dmStmt) dm_build_954.dm_build_946 = dm_build_951 @@ -1708,7 +1708,7 @@ type dm_build_963 struct { dm_build_966 int } -func dm_build_967(dm_build_968 *dm_build_332, dm_build_969 *lob, dm_build_970 int, dm_build_971 int) *dm_build_963 { +func dm_build_967(dm_build_968 *Access, dm_build_969 *lob, dm_build_970 int, dm_build_971 int) *dm_build_963 { dm_build_972 := new(dm_build_963) dm_build_972.dm_build_745(dm_build_968, Dm_build_624) dm_build_972.dm_build_964 = dm_build_969 @@ -1743,7 +1743,7 @@ func (dm_build_974 *dm_build_963) dm_build_726() error { dm_build_974.dm_build_741.dm_build_335.Dm_build_51(int32(dm_build_974.dm_build_966)) - if dm_build_974.dm_build_741.dm_build_336.NewLobFlag { + if dm_build_974.dm_build_741.conn.NewLobFlag { dm_build_974.dm_build_741.dm_build_335.Dm_build_67(uint64(dm_build_974.dm_build_964.rowId)) dm_build_974.dm_build_741.dm_build_335.Dm_build_47(dm_build_974.dm_build_964.exGroupId) dm_build_974.dm_build_741.dm_build_335.Dm_build_47(dm_build_974.dm_build_964.exFileId) @@ -1772,7 +1772,7 @@ type dm_build_978 struct { dm_build_979 *lob } -func dm_build_980(dm_build_981 *dm_build_332, dm_build_982 *lob) *dm_build_978 { +func dm_build_980(dm_build_981 *Access, dm_build_982 *lob) *dm_build_978 { dm_build_983 := new(dm_build_978) dm_build_983.dm_build_745(dm_build_981, Dm_build_621) dm_build_983.dm_build_979 = dm_build_982 @@ -1791,7 +1791,7 @@ func (dm_build_985 *dm_build_978) dm_build_726() error { dm_build_985.dm_build_741.dm_build_335.Dm_build_51(dm_build_985.dm_build_979.pageNo) - if dm_build_985.dm_build_741.dm_build_336.NewLobFlag { + if dm_build_985.dm_build_741.conn.NewLobFlag { dm_build_985.dm_build_741.dm_build_335.Dm_build_51(dm_build_985.dm_build_979.tabId) dm_build_985.dm_build_741.dm_build_335.Dm_build_47(dm_build_985.dm_build_979.colId) dm_build_985.dm_build_741.dm_build_335.Dm_build_67(uint64(dm_build_985.dm_build_979.rowId)) @@ -1819,7 +1819,7 @@ type dm_build_988 struct { dm_build_990 int } -func dm_build_991(dm_build_992 *dm_build_332, dm_build_993 *lob, dm_build_994 int) *dm_build_988 { +func dm_build_991(dm_build_992 *Access, dm_build_993 *lob, dm_build_994 int) *dm_build_988 { dm_build_995 := new(dm_build_988) dm_build_995.dm_build_745(dm_build_992, Dm_build_623) dm_build_995.dm_build_989 = dm_build_993 @@ -1844,7 +1844,7 @@ func (dm_build_997 *dm_build_988) dm_build_726() error { dm_build_997.dm_build_741.dm_build_335.Dm_build_67(uint64(dm_build_997.dm_build_989.rowId)) dm_build_997.dm_build_741.dm_build_335.Dm_build_79(Dm_build_1219.Dm_build_1421(uint32(dm_build_997.dm_build_990))) - if dm_build_997.dm_build_741.dm_build_336.NewLobFlag { + if dm_build_997.dm_build_741.conn.NewLobFlag { dm_build_997.dm_build_741.dm_build_335.Dm_build_47(dm_build_997.dm_build_989.exGroupId) dm_build_997.dm_build_741.dm_build_335.Dm_build_47(dm_build_997.dm_build_989.exFileId) dm_build_997.dm_build_741.dm_build_335.Dm_build_51(dm_build_997.dm_build_989.exPageNo) @@ -1915,15 +1915,15 @@ const ( type dm_build_1026 struct { dm_build_740 - dm_build_1027 *DmConnection + dm_build_1027 *Connection dm_build_1028 bool } -func dm_build_1029(dm_build_1030 *dm_build_332) *dm_build_1026 { +func dm_build_1029(dm_build_1030 *Access) *dm_build_1026 { dm_build_1031 := new(dm_build_1026) dm_build_1031.dm_build_745(dm_build_1030, Dm_build_605) - dm_build_1031.dm_build_1027 = dm_build_1030.dm_build_336 + dm_build_1031.dm_build_1027 = dm_build_1030.conn return dm_build_1031 } @@ -1973,8 +1973,8 @@ func (dm_build_1033 *dm_build_1026) dm_build_726() error { } - dm_build_1035 := Dm_build_1219.Dm_build_1432(dm_build_1033.dm_build_1027.dmConnector.user, dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) - dm_build_1036 := Dm_build_1219.Dm_build_1432(dm_build_1033.dm_build_1027.dmConnector.password, dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) + dm_build_1035 := Dm_build_1219.Dm_build_1432(dm_build_1033.dm_build_1027.dmConnector.user, dm_build_1034, dm_build_1033.dm_build_741.conn) + dm_build_1036 := Dm_build_1219.Dm_build_1432(dm_build_1033.dm_build_1027.dmConnector.password, dm_build_1034, dm_build_1033.dm_build_741.conn) if len(dm_build_1035) > Dm_build_641 { return ECGO_USERNAME_TOO_LONG.throw() } @@ -1992,13 +1992,13 @@ func (dm_build_1033 *dm_build_1026) dm_build_726() error { dm_build_1033.dm_build_741.dm_build_335.Dm_build_83(dm_build_1035) dm_build_1033.dm_build_741.dm_build_335.Dm_build_83(dm_build_1036) - dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(dm_build_1033.dm_build_1027.dmConnector.appName, dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) - dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(dm_build_1033.dm_build_1027.dmConnector.osName, dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) + dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(dm_build_1033.dm_build_1027.dmConnector.appName, dm_build_1034, dm_build_1033.dm_build_741.conn) + dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(dm_build_1033.dm_build_1027.dmConnector.osName, dm_build_1034, dm_build_1033.dm_build_741.conn) if hostName, err := os.Hostname(); err != nil { - dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(hostName, dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) + dm_build_1033.dm_build_741.dm_build_335.Dm_build_95(hostName, dm_build_1034, dm_build_1033.dm_build_741.conn) } else { - dm_build_1033.dm_build_741.dm_build_335.Dm_build_95("", dm_build_1034, dm_build_1033.dm_build_741.dm_build_336) + dm_build_1033.dm_build_741.dm_build_335.Dm_build_95("", dm_build_1034, dm_build_1033.dm_build_741.conn) } if dm_build_1033.dm_build_1027.dmConnector.rwStandby { @@ -2032,25 +2032,25 @@ func (dm_build_1038 *dm_build_1026) dm_build_730() (interface{}, error) { dm_build_1039 := dm_build_1038.dm_build_1027.getServerEncoding() - dm_build_1038.dm_build_1027.InstanceName = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + dm_build_1038.dm_build_1027.InstanceName = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) var dm_build_1040 = dm_build_1038.dm_build_741.dm_build_335.Dm_build_125() if dm_build_1040 == 0 && dm_build_1038.dm_build_1027.MsgVersion > 0 { dm_build_1038.dm_build_1027.Schema = strings.ToUpper(dm_build_1038.dm_build_1027.dmConnector.user) } else { - dm_build_1038.dm_build_1027.Schema = dm_build_1038.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1040), dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + dm_build_1038.dm_build_1027.Schema = dm_build_1038.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1040), dm_build_1039, dm_build_1038.dm_build_741.conn) } - dm_build_1038.dm_build_1027.LastLoginIP = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) - dm_build_1038.dm_build_1027.LastLoginTime = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + dm_build_1038.dm_build_1027.LastLoginIP = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) + dm_build_1038.dm_build_1027.LastLoginTime = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) dm_build_1038.dm_build_1027.FailedAttempts = dm_build_1038.dm_build_741.dm_build_335.Dm_build_125() dm_build_1038.dm_build_1027.LoginWarningID = dm_build_1038.dm_build_741.dm_build_335.Dm_build_125() dm_build_1038.dm_build_1027.GraceTimeRemainder = dm_build_1038.dm_build_741.dm_build_335.Dm_build_125() - dm_build_1038.dm_build_1027.Guid = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) - dm_build_1038.dm_build_1027.DbName = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + dm_build_1038.dm_build_1027.Guid = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) + dm_build_1038.dm_build_1027.DbName = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) if dm_build_1038.dm_build_741.dm_build_335.Dm_build_263(Dm_build_1021) == 1 { - dm_build_1038.dm_build_1027.StandbyHost = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + dm_build_1038.dm_build_1027.StandbyHost = dm_build_1038.dm_build_741.dm_build_335.Dm_build_167(dm_build_1039, dm_build_1038.dm_build_741.conn) dm_build_1038.dm_build_1027.StandbyPort = dm_build_1038.dm_build_741.dm_build_335.Dm_build_125() dm_build_1038.dm_build_1027.StandbyCount = int32(dm_build_1038.dm_build_741.dm_build_335.Dm_build_140()) } @@ -2076,23 +2076,23 @@ func (dm_build_1038 *dm_build_1026) dm_build_730() (interface{}, error) { if dm_build_1038.dm_build_741.dm_build_335.Dm_build_22(false) > 0 { - format := dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + format := dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.conn) if format != "" { dm_build_1038.dm_build_1027.FormatDate = format } - format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.conn) if format != "" { dm_build_1038.dm_build_1027.FormatTime = format } - format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.conn) if format != "" { dm_build_1038.dm_build_1027.FormatTimestamp = format } - format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.conn) if format != "" { dm_build_1038.dm_build_1027.FormatTimestampTZ = format } - format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.dm_build_336) + format = dm_build_1038.dm_build_741.dm_build_335.Dm_build_171(dm_build_1039, dm_build_1038.dm_build_741.conn) if format != "" { dm_build_1038.dm_build_1027.FormatTimeTZ = format } @@ -2110,7 +2110,7 @@ type dm_build_1042 struct { dm_build_1043 int16 } -func dm_build_1044(dm_build_1045 *dm_build_332, dm_build_1046 *DmStatement, dm_build_1047 int16) *dm_build_1042 { +func dm_build_1044(dm_build_1045 *Access, dm_build_1046 *DmStatement, dm_build_1047 int16) *dm_build_1042 { dm_build_1048 := new(dm_build_1042) dm_build_1048.dm_build_749(dm_build_1045, Dm_build_625, dm_build_1046) dm_build_1048.dm_build_1043 = dm_build_1047 @@ -2136,7 +2136,7 @@ type dm_build_1055 struct { dm_build_1056 []parameter } -func dm_build_1057(dm_build_1058 *dm_build_332, dm_build_1059 *DmStatement, dm_build_1060 []parameter) *dm_build_1055 { +func dm_build_1057(dm_build_1058 *Access, dm_build_1059 *DmStatement, dm_build_1060 []parameter) *dm_build_1055 { dm_build_1061 := new(dm_build_1055) dm_build_1061.dm_build_749(dm_build_1058, Dm_build_629, dm_build_1059) dm_build_1061.dm_build_1056 = dm_build_1060 @@ -2162,7 +2162,7 @@ type dm_build_1064 struct { dm_build_1066 int16 } -func dm_build_1067(dm_build_1068 *dm_build_332, dm_build_1069 *DmStatement, dm_build_1070 bool, dm_build_1071 int16) *dm_build_1064 { +func dm_build_1067(dm_build_1068 *Access, dm_build_1069 *DmStatement, dm_build_1070 bool, dm_build_1071 int16) *dm_build_1064 { dm_build_1072 := new(dm_build_1064) dm_build_1072.dm_build_749(dm_build_1068, Dm_build_609, dm_build_1069) dm_build_1072.dm_build_1065 = dm_build_1070 @@ -2174,7 +2174,7 @@ func (dm_build_1074 *dm_build_1064) dm_build_726() error { dm_build_1075 := Dm_build_633 - if dm_build_1074.dm_build_741.dm_build_336.autoCommit { + if dm_build_1074.dm_build_741.conn.autoCommit { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 1) } else { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 0) @@ -2190,7 +2190,7 @@ func (dm_build_1074 *dm_build_1064) dm_build_726() error { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 1) - if dm_build_1074.dm_build_741.dm_build_336.CompatibleOracle() { + if dm_build_1074.dm_build_741.conn.CompatibleOracle() { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 0) } else { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 1) @@ -2198,13 +2198,13 @@ func (dm_build_1074 *dm_build_1064) dm_build_726() error { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_187(dm_build_1075, dm_build_1074.dm_build_1066) - if dm_build_1074.dm_build_744.maxRows <= 0 || dm_build_1074.dm_build_741.dm_build_336.dmConnector.enRsCache { + if dm_build_1074.dm_build_744.maxRows <= 0 || dm_build_1074.dm_build_741.conn.dmConnector.enRsCache { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_195(dm_build_1075, INT64_MAX) } else { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_195(dm_build_1075, dm_build_1074.dm_build_744.maxRows) } - if dm_build_1074.dm_build_741.dm_build_336.dmConnector.isBdtaRS { + if dm_build_1074.dm_build_741.conn.dmConnector.isBdtaRS { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, Dm_build_712) } else { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, Dm_build_711) @@ -2226,7 +2226,7 @@ func (dm_build_1074 *dm_build_1064) dm_build_726() error { dm_build_1075 += dm_build_1074.dm_build_741.dm_build_335.Dm_build_183(dm_build_1075, 0) } - dm_build_1074.dm_build_741.dm_build_335.Dm_build_113(dm_build_1074.dm_build_744.nativeSql, dm_build_1074.dm_build_741.dm_build_336.getServerEncoding(), dm_build_1074.dm_build_741.dm_build_336) + dm_build_1074.dm_build_741.dm_build_335.Dm_build_113(dm_build_1074.dm_build_744.nativeSql, dm_build_1074.dm_build_741.conn.getServerEncoding(), dm_build_1074.dm_build_741.conn) return nil } @@ -2252,7 +2252,7 @@ func (dm_build_1077 *dm_build_1064) dm_build_730() (interface{}, error) { dm_build_1077.dm_build_741.dm_build_335.Dm_build_272(dm_build_1079) dm_build_1079 += DDWORD_SIZE - dm_build_1077.dm_build_741.dm_build_336.TrxStatus = dm_build_1077.dm_build_741.dm_build_335.Dm_build_269(dm_build_1079) + dm_build_1077.dm_build_741.conn.TrxStatus = dm_build_1077.dm_build_741.dm_build_335.Dm_build_269(dm_build_1079) dm_build_1079 += ULINT_SIZE if dm_build_1080 > 0 { @@ -2310,10 +2310,10 @@ func (dm_build_1083 *dm_build_1064) dm_build_1082(dm_build_1084 int) []parameter dm_build_1087 = dm_build_1083.dm_build_741.dm_build_335.Dm_build_122() dm_build_1088 = dm_build_1083.dm_build_741.dm_build_335.Dm_build_122() - dm_build_1089[i].name = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1085), dm_build_1083.dm_build_741.dm_build_336.getServerEncoding(), dm_build_1083.dm_build_741.dm_build_336) - dm_build_1089[i].typeName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1086), dm_build_1083.dm_build_741.dm_build_336.getServerEncoding(), dm_build_1083.dm_build_741.dm_build_336) - dm_build_1089[i].tableName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1087), dm_build_1083.dm_build_741.dm_build_336.getServerEncoding(), dm_build_1083.dm_build_741.dm_build_336) - dm_build_1089[i].schemaName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1088), dm_build_1083.dm_build_741.dm_build_336.getServerEncoding(), dm_build_1083.dm_build_741.dm_build_336) + dm_build_1089[i].name = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1085), dm_build_1083.dm_build_741.conn.getServerEncoding(), dm_build_1083.dm_build_741.conn) + dm_build_1089[i].typeName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1086), dm_build_1083.dm_build_741.conn.getServerEncoding(), dm_build_1083.dm_build_741.conn) + dm_build_1089[i].tableName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1087), dm_build_1083.dm_build_741.conn.getServerEncoding(), dm_build_1083.dm_build_741.conn) + dm_build_1089[i].schemaName = dm_build_1083.dm_build_741.dm_build_335.Dm_build_162(int(dm_build_1088), dm_build_1083.dm_build_741.conn.getServerEncoding(), dm_build_1083.dm_build_741.conn) if dm_build_1089[i].lob { dm_build_1089[i].lobTabId = dm_build_1083.dm_build_741.dm_build_335.Dm_build_125() @@ -2325,7 +2325,7 @@ func (dm_build_1083 *dm_build_1064) dm_build_1082(dm_build_1084 int) []parameter if isComplexType(int(dm_build_1089[i].colType), int(dm_build_1089[i].scale)) { - strDesc := newTypeDescriptor(dm_build_1083.dm_build_741.dm_build_336) + strDesc := newTypeDescriptor(dm_build_1083.dm_build_741.conn) strDesc.unpack(dm_build_1083.dm_build_741.dm_build_335) dm_build_1089[i].typeDescriptor = strDesc } @@ -2345,7 +2345,7 @@ type dm_build_1091 struct { dm_build_1094 int32 } -func dm_build_1095(dm_build_1096 *dm_build_332, dm_build_1097 *DmStatement, dm_build_1098 int16, dm_build_1099 *Dm_build_1498, dm_build_1100 int32) *dm_build_1091 { +func dm_build_1095(dm_build_1096 *Access, dm_build_1097 *DmStatement, dm_build_1098 int16, dm_build_1099 *Dm_build_1498, dm_build_1100 int32) *dm_build_1091 { dm_build_1101 := new(dm_build_1091) dm_build_1101.dm_build_749(dm_build_1096, Dm_build_615, dm_build_1097) dm_build_1101.dm_build_1092 = dm_build_1098 @@ -2359,7 +2359,7 @@ func (dm_build_1103 *dm_build_1091) dm_build_726() error { dm_build_1103.dm_build_741.dm_build_335.Dm_build_51(dm_build_1103.dm_build_1094) - if dm_build_1103.dm_build_741.dm_build_336.NewLobFlag { + if dm_build_1103.dm_build_741.conn.NewLobFlag { dm_build_1103.dm_build_741.dm_build_335.Dm_build_51(-1) } dm_build_1103.dm_build_1093.Dm_build_1505(dm_build_1103.dm_build_741.dm_build_335, int(dm_build_1103.dm_build_1094)) @@ -2370,7 +2370,7 @@ type dm_build_1104 struct { dm_build_740 } -func dm_build_1105(dm_build_1106 *dm_build_332) *dm_build_1104 { +func dm_build_1105(dm_build_1106 *Access) *dm_build_1104 { dm_build_1107 := new(dm_build_1104) dm_build_1107.dm_build_745(dm_build_1106, Dm_build_613) return dm_build_1107 @@ -2381,7 +2381,7 @@ type dm_build_1108 struct { dm_build_1109 int32 } -func dm_build_1110(dm_build_1111 *dm_build_332, dm_build_1112 int32) *dm_build_1108 { +func dm_build_1110(dm_build_1111 *Access, dm_build_1112 int32) *dm_build_1108 { dm_build_1113 := new(dm_build_1108) dm_build_1113.dm_build_745(dm_build_1111, Dm_build_626) dm_build_1113.dm_build_1109 = dm_build_1112 @@ -2405,7 +2405,7 @@ type dm_build_1117 struct { dm_build_1123 int } -func dm_build_1124(dm_build_1125 *dm_build_332, dm_build_1126 *lob, dm_build_1127 byte, dm_build_1128 int, dm_build_1129 []byte, +func dm_build_1124(dm_build_1125 *Access, dm_build_1126 *lob, dm_build_1127 byte, dm_build_1128 int, dm_build_1129 []byte, dm_build_1130 int, dm_build_1131 int) *dm_build_1117 { dm_build_1132 := new(dm_build_1117) dm_build_1132.dm_build_745(dm_build_1125, Dm_build_622) @@ -2437,7 +2437,7 @@ func (dm_build_1134 *dm_build_1117) dm_build_726() error { dm_build_1134.dm_build_741.dm_build_335.Dm_build_51(int32(dm_build_1134.dm_build_1123)) dm_build_1134.dm_build_741.dm_build_335.Dm_build_79(dm_build_1134.dm_build_1121) - if dm_build_1134.dm_build_741.dm_build_336.NewLobFlag { + if dm_build_1134.dm_build_741.conn.NewLobFlag { dm_build_1134.dm_build_741.dm_build_335.Dm_build_47(dm_build_1134.dm_build_1118.exGroupId) dm_build_1134.dm_build_741.dm_build_335.Dm_build_47(dm_build_1134.dm_build_1118.exFileId) dm_build_1134.dm_build_741.dm_build_335.Dm_build_51(dm_build_1134.dm_build_1118.exPageNo) @@ -2507,17 +2507,17 @@ const ( type dm_build_1161 struct { dm_build_740 - dm_build_1162 *DmConnection + dm_build_1162 *Connection dm_build_1163 int Dm_build_1164 int32 Dm_build_1165 []byte dm_build_1166 byte } -func dm_build_1167(dm_build_1168 *dm_build_332) *dm_build_1161 { +func dm_build_1167(dm_build_1168 *Access) *dm_build_1161 { dm_build_1169 := new(dm_build_1161) dm_build_1169.dm_build_745(dm_build_1168, Dm_build_631) - dm_build_1169.dm_build_1162 = dm_build_1168.dm_build_336 + dm_build_1169.dm_build_1162 = dm_build_1168.conn return dm_build_1169 } @@ -2572,7 +2572,7 @@ func (dm_build_1176 *dm_build_1161) dm_build_726() error { dm_build_1176.dm_build_741.dm_build_335.Dm_build_211(Dm_build_1147, uint16(dm_build_1176.dm_build_1162.MsgVersion)) dm_build_1177 := dm_build_1176.dm_build_1162.getServerEncoding() - dm_build_1176.dm_build_741.dm_build_335.Dm_build_95(Dm_build_597, dm_build_1177, dm_build_1176.dm_build_741.dm_build_336) + dm_build_1176.dm_build_741.dm_build_335.Dm_build_95(Dm_build_597, dm_build_1177, dm_build_1176.dm_build_741.conn) var dm_build_1178 byte if dm_build_1176.dm_build_1162.dmConnector.uKeyName != "" { @@ -2633,7 +2633,7 @@ func (dm_build_1182 *dm_build_1161) dm_build_730() (interface{}, error) { return nil, dm_build_1185 } - dm_build_1186 := dm_build_1182.dm_build_741.dm_build_335.Dm_build_167(dm_build_1182.dm_build_1162.getServerEncoding(), dm_build_1182.dm_build_741.dm_build_336) + dm_build_1186 := dm_build_1182.dm_build_741.dm_build_335.Dm_build_167(dm_build_1182.dm_build_1162.getServerEncoding(), dm_build_1182.dm_build_741.conn) if dm_build_1170(dm_build_1186, Dm_build_598) < 0 { return nil, ECGO_ERROR_SERVER_VERSION.throw() } @@ -2643,14 +2643,14 @@ func (dm_build_1182 *dm_build_1161) dm_build_730() (interface{}, error) { dm_build_1182.dm_build_1162.Execute2 = dm_build_1170(dm_build_1186, Dm_build_600) > 0 dm_build_1182.dm_build_1162.LobEmptyCompOrcl = dm_build_1170(dm_build_1186, Dm_build_601) > 0 - if dm_build_1182.dm_build_741.dm_build_336.dmConnector.uKeyName != "" { + if dm_build_1182.dm_build_741.conn.dmConnector.uKeyName != "" { dm_build_1182.dm_build_1166 = 1 } else { dm_build_1182.dm_build_1166 = 0 } if dm_build_1182.dm_build_1166 == 1 { - dm_build_1182.dm_build_741.dm_build_342 = dm_build_1182.dm_build_741.dm_build_335.Dm_build_162(16, dm_build_1182.dm_build_1162.getServerEncoding(), dm_build_1182.dm_build_741.dm_build_336) + dm_build_1182.dm_build_741.dm_build_342 = dm_build_1182.dm_build_741.dm_build_335.Dm_build_162(16, dm_build_1182.dm_build_1162.getServerEncoding(), dm_build_1182.dm_build_741.conn) } dm_build_1182.dm_build_1163 = -1 @@ -2685,7 +2685,7 @@ type dm_build_1189 struct { dm_build_740 } -func dm_build_1190(dm_build_1191 *dm_build_332, dm_build_1192 *DmStatement) *dm_build_1189 { +func dm_build_1190(dm_build_1191 *Access, dm_build_1192 *DmStatement) *dm_build_1189 { dm_build_1193 := new(dm_build_1189) dm_build_1193.dm_build_749(dm_build_1191, Dm_build_607, dm_build_1192) return dm_build_1193 @@ -2710,7 +2710,7 @@ type dm_build_1198 struct { dm_build_1199 int32 } -func dm_build_1200(dm_build_1201 *dm_build_332, dm_build_1202 int32) *dm_build_1198 { +func dm_build_1200(dm_build_1201 *Access, dm_build_1202 int32) *dm_build_1198 { dm_build_1203 := new(dm_build_1198) dm_build_1203.dm_build_745(dm_build_1201, Dm_build_608) dm_build_1203.dm_build_1199 = dm_build_1202 @@ -2727,7 +2727,7 @@ type dm_build_1206 struct { dm_build_1207 []uint32 } -func dm_build_1208(dm_build_1209 *dm_build_332, dm_build_1210 []uint32) *dm_build_1206 { +func dm_build_1208(dm_build_1209 *Access, dm_build_1210 []uint32) *dm_build_1206 { dm_build_1211 := new(dm_build_1206) dm_build_1211.dm_build_745(dm_build_1209, Dm_build_628) dm_build_1211.dm_build_1207 = dm_build_1210 diff --git a/zs.go b/zs.go index 717bde6..bf79366 100644 --- a/zs.go +++ b/zs.go @@ -14,7 +14,7 @@ import ( "unicode" "unicode/utf8" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) type oracleDateFormat struct { diff --git a/zw.go b/zw.go index d84d81d..c287e39 100644 --- a/zw.go +++ b/zw.go @@ -10,7 +10,7 @@ import ( "strconv" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) var rwMap = make(map[string]*rwCounter) @@ -66,7 +66,7 @@ func (rwc *rwCounter) reset(primaryPercent int32, standbyCount int32) { } // 连接创建成功后调用,需要服务器返回standbyCount -func getRwCounterInstance(conn *DmConnection, standbyCount int32) *rwCounter { +func getRwCounterInstance(conn *Connection, standbyCount int32) *rwCounter { key := conn.dmConnector.host + "_" + strconv.Itoa(int(conn.dmConnector.port)) + "_" + strconv.Itoa(int(conn.dmConnector.rwPercent)) rwc, ok := rwMap[key] @@ -92,7 +92,7 @@ func (rwc *rwCounter) countPrimary() RWSiteEnum { * @param dest 主机; 备机; any; * @return 主机; 备机 */ -func (rwc *rwCounter) count(dest RWSiteEnum, standby *DmConnection) RWSiteEnum { +func (rwc *rwCounter) count(dest RWSiteEnum, standby *Connection) RWSiteEnum { rwc.adjustNtrx() switch dest { case ANYSITE: @@ -164,7 +164,7 @@ func (rwc *rwCounter) increasePrimaryNtrx() { // return ret //} -func (rwc *rwCounter) getStandbyId(standby *DmConnection) int32 { +func (rwc *rwCounter) getStandbyId(standby *Connection) int32 { key := standby.dmConnector.host + ":" + strconv.Itoa(int(standby.dmConnector.port)) sid, ok := rwc.standbyIdMap[key] if !ok { @@ -178,7 +178,7 @@ func (rwc *rwCounter) getStandbyId(standby *DmConnection) int32 { return sid } -func (rwc *rwCounter) getStandbyFlag(standby *DmConnection) int32 { +func (rwc *rwCounter) getStandbyFlag(standby *Connection) int32 { sid := rwc.getStandbyId(standby) if sid > 0 && sid < int32(len(rwc.flag)) { // 保证备库有效 @@ -187,7 +187,7 @@ func (rwc *rwCounter) getStandbyFlag(standby *DmConnection) int32 { return 0 } -func (rwc *rwCounter) increaseStandbyNtrx(standby *DmConnection) { +func (rwc *rwCounter) increaseStandbyNtrx(standby *Connection) { key := standby.dmConnector.host + ":" + strconv.Itoa(int(standby.dmConnector.port)) ret, ok := rwc.standbyNTrxMap[key] if ok { diff --git a/zx.go b/zx.go index d300d97..03daa16 100644 --- a/zx.go +++ b/zx.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( @@ -37,7 +37,7 @@ type rwUtil struct { var RWUtil = rwUtil{} -func (RWUtil rwUtil) connect(c *DmConnector, ctx context.Context) (*DmConnection, error) { +func (RWUtil rwUtil) connect(c *Connector, ctx context.Context) (*Connection, error) { c.loginMode = LOGIN_MODE_PRIMARY_ONLY connection, err := c.connect(ctx) if err != nil { @@ -50,7 +50,7 @@ func (RWUtil rwUtil) connect(c *DmConnector, ctx context.Context) (*DmConnection return connection, err } -func (RWUtil rwUtil) reconnect(connection *DmConnection) error { +func (RWUtil rwUtil) reconnect(connection *Connection) error { if connection.rwInfo == nil { return nil } @@ -69,7 +69,7 @@ func (RWUtil rwUtil) reconnect(connection *DmConnection) error { return err } -func (RWUtil rwUtil) recoverStandby(connection *DmConnection) error { +func (RWUtil rwUtil) recoverStandby(connection *Connection) error { if connection.closed.IsSet() || RWUtil.isStandbyAlive(connection) { return nil } @@ -87,7 +87,7 @@ func (RWUtil rwUtil) recoverStandby(connection *DmConnection) error { return err } -func (RWUtil rwUtil) connectStandby(connection *DmConnection) error { +func (RWUtil rwUtil) connectStandby(connection *Connection) error { var err error db, err := RWUtil.chooseValidStandby(connection) if err != nil { @@ -116,7 +116,7 @@ func (RWUtil rwUtil) connectStandby(connection *DmConnection) error { return nil } -func (RWUtil rwUtil) chooseValidStandby(connection *DmConnection) (*ep, error) { +func (RWUtil rwUtil) chooseValidStandby(connection *Connection) (*ep, error) { stmt, rs, err := connection.driverQuery(SQL_SELECT_STANDBY2) if err != nil { stmt, rs, err = connection.driverQuery(SQL_SELECT_STANDBY) @@ -151,13 +151,13 @@ func (RWUtil rwUtil) chooseValidStandby(connection *DmConnection) (*ep, error) { return nil, nil } -func (RWUtil rwUtil) afterExceptionOnStandby(connection *DmConnection, e error) { +func (RWUtil rwUtil) afterExceptionOnStandby(connection *Connection, e error) { if e.(*DmError).ErrCode == ECGO_COMMUNITION_ERROR.ErrCode { RWUtil.removeStandby(connection) } } -func (RWUtil rwUtil) removeStandby(connection *DmConnection) { +func (RWUtil rwUtil) removeStandby(connection *Connection) { if connection.rwInfo.connStandby != nil { connection.rwInfo.connStandby.close() connection.rwInfo.connStandby = nil @@ -168,7 +168,7 @@ func (RWUtil rwUtil) isCreateStandbyStmt(stmt *DmStatement) bool { return stmt != nil && stmt.rwInfo.readOnly && RWUtil.isStandbyAlive(stmt.dmConn) } -func (RWUtil rwUtil) executeByConn(conn *DmConnection, query string, execute1 func() (interface{}, error), execute2 func(otherConn *DmConnection) (interface{}, error)) (interface{}, error) { +func (RWUtil rwUtil) executeByConn(conn *Connection, query string, execute1 func() (interface{}, error), execute2 func(otherConn *Connection) (interface{}, error)) (interface{}, error) { if err := RWUtil.recoverStandby(conn); err != nil { return nil, err @@ -190,7 +190,7 @@ func (RWUtil rwUtil) executeByConn(conn *DmConnection, query string, execute1 fu } curConn := conn.rwInfo.connCurrent - var otherConn *DmConnection + var otherConn *Connection if curConn != conn { otherConn = conn } else { @@ -317,7 +317,7 @@ func (RWUtil rwUtil) executeByStmt(stmt *DmStatement, execute1 func() (interface return ret, nil } -func (RWUtil rwUtil) checkReadonlyByConn(conn *DmConnection, sql string) bool { +func (RWUtil rwUtil) checkReadonlyByConn(conn *Connection, sql string) bool { readonly := true if sql != "" && !conn.dmConnector.rwIgnoreSql { @@ -342,7 +342,7 @@ func (RWUtil rwUtil) checkReadonlyByStmt(stmt *DmStatement) bool { return RWUtil.checkReadonlyByConn(stmt.dmConn, stmt.nativeSql) } -func (RWUtil rwUtil) distributeSqlByConn(conn *DmConnection, query string) RWSiteEnum { +func (RWUtil rwUtil) distributeSqlByConn(conn *Connection, query string) RWSiteEnum { var dest RWSiteEnum if !RWUtil.isStandbyAlive(conn) { @@ -405,7 +405,7 @@ func (RWUtil rwUtil) distributeSqlByStmt(stmt *DmStatement) RWSiteEnum { return dest } -func (RWUtil rwUtil) isStandbyAlive(connection *DmConnection) bool { +func (RWUtil rwUtil) isStandbyAlive(connection *Connection) bool { return connection.rwInfo.connStandby != nil && !connection.rwInfo.connStandby.closed.IsSet() } diff --git a/zzj.go b/zzj.go index f66bd8e..f08af86 100644 --- a/zzj.go +++ b/zzj.go @@ -25,7 +25,7 @@ type sqlName struct { m_packId int // 保存包的id,包名无法传出,用于查找包名 - m_conn *DmConnection + m_conn *Connection } func (SqlName *sqlName) init() { @@ -45,7 +45,7 @@ func newSqlNameByFulName(fulName string) *sqlName { return o } -func newSqlNameByConn(conn *DmConnection) *sqlName { +func newSqlNameByConn(conn *Connection) *sqlName { o := new(sqlName) o.init() o.m_conn = conn diff --git a/zzk.go b/zzk.go index 62b56fb..086eed5 100644 --- a/zzk.go +++ b/zzk.go @@ -9,19 +9,19 @@ import ( "strconv" "strings" - "gitee.com/chunanyong/dm/parser" + "github.com/gotomicro/dmgo/parser" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) -func (dc *DmConnection) lex(sql string) ([]*parser.LVal, error) { - if dc.lexer == nil { - dc.lexer = parser.NewLexer(strings.NewReader(sql), false) +func (dmConn *Connection) lex(sql string) ([]*parser.LVal, error) { + if dmConn.lexer == nil { + dmConn.lexer = parser.NewLexer(strings.NewReader(sql), false) } else { - dc.lexer.Reset(strings.NewReader(sql)) + dmConn.lexer.Reset(strings.NewReader(sql)) } - lexer := dc.lexer + lexer := dmConn.lexer var lval *parser.LVal var err error lvalList := make([]*parser.LVal, 0, 64) @@ -71,7 +71,7 @@ func lexSkipWhitespace(sql string, n int) ([]*parser.LVal, error) { return lvalList, nil } -func (dc *DmConnection) escape(sql string, keywords []string) (string, error) { +func (dmConn *Connection) escape(sql string, keywords []string) (string, error) { if (keywords == nil || len(keywords) == 0) && strings.Index(sql, "{") == -1 { return sql, nil @@ -85,7 +85,7 @@ func (dc *DmConnection) escape(sql string, keywords []string) (string, error) { } nsql := bytes.NewBufferString("") stack := make([]bool, 0, 64) - lvalList, err := dc.lex(sql) + lvalList, err := dmConn.lex(sql) if err != nil { return "", err } @@ -183,10 +183,10 @@ func next(lvalList []*parser.LVal, start int) *parser.LVal { return lval } -func (dc *DmConnection) execOpt(sql string, optParamList []OptParameter, serverEncoding string) (string, []OptParameter, error) { +func (dmConn *Connection) execOpt(sql string, optParamList []OptParameter, serverEncoding string) (string, []OptParameter, error) { nsql := bytes.NewBufferString("") - lvalList, err := dc.lex(sql) + lvalList, err := dmConn.lex(sql) if err != nil { return "", optParamList, err } @@ -252,7 +252,7 @@ func (dc *DmConnection) execOpt(sql string, optParamList []OptParameter, serverE nsql.WriteString("'" + util.StringUtil.ProcessSingleQuoteOfName(lval.Value) + "'") } else { nsql.WriteString("?") - optParamList = append(optParamList, newOptParameter(Dm_build_1219.Dm_build_1432(lval.Value, serverEncoding, dc), VARCHAR, VARCHAR_PREC)) + optParamList = append(optParamList, newOptParameter(Dm_build_1219.Dm_build_1432(lval.Value, serverEncoding, dmConn), VARCHAR, VARCHAR_PREC)) } } case parser.HEX_INT: @@ -277,8 +277,8 @@ func (dc *DmConnection) execOpt(sql string, optParamList []OptParameter, serverE return nsql.String(), optParamList, nil } -func (dc *DmConnection) hasConst(sql string) (bool, error) { - lvalList, err := dc.lex(sql) +func (dmConn *Connection) hasConst(sql string) (bool, error) { + lvalList, err := dmConn.lex(sql) if err != nil { return false, err } diff --git a/zzl.go b/zzl.go index e28795b..def48fd 100644 --- a/zzl.go +++ b/zzl.go @@ -9,7 +9,7 @@ type StructDescriptor struct { m_typeDesc *TypeDescriptor } -func newStructDescriptor(fulName string, conn *DmConnection) (*StructDescriptor, error) { +func newStructDescriptor(fulName string, conn *Connection) (*StructDescriptor, error) { sd := new(StructDescriptor) if fulName == "" { return nil, ECGO_INVALID_COMPLEX_TYPE_NAME.throw() diff --git a/zzm.go b/zzm.go index 90d327b..6704180 100644 --- a/zzm.go +++ b/zzm.go @@ -6,14 +6,9 @@ package dm import ( - "bufio" - "io" "os" - "runtime" - "strconv" - "strings" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) var LogDirDef, _ = os.Getwd() @@ -110,310 +105,8 @@ var ( /*---------------------------------------------------------------*/ ServerGroupMap = make(map[string]*epGroup) - - GlobalProperties *Properties ) -// filePath: dm_svc.conf 文件路径 -func load(filePath string) { - if filePath == "" { - switch runtime.GOOS { - case "windows": - filePath = os.Getenv("SystemRoot") + "\\system32\\dm_svc.conf" - case "linux": - filePath = "/etc/dm_svc.conf" - default: - return - } - } - file, err := os.Open(filePath) - defer file.Close() - if err != nil { - return - } - fileReader := bufio.NewReader(file) - - GlobalProperties = NewProperties() - var groupProps *Properties - var line string //dm_svc.conf读取到的一行 - - for line, err = fileReader.ReadString('\n'); line != "" && (err == nil || err == io.EOF); line, err = fileReader.ReadString('\n') { - // 去除#标记的注释 - if notesIndex := strings.IndexByte(line, '#'); notesIndex != -1 { - line = line[:notesIndex] - } - // 去除前后多余的空格 - line = strings.TrimSpace(line) - if line == "" { - continue - } - - if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") { - groupName := strings.ToLower(line[1 : len(line)-1]) - dbGroup, ok := ServerGroupMap[groupName] - if groupName == "" || !ok { - continue - } - groupProps = dbGroup.props - if groupProps.IsNil() { - groupProps = NewProperties() - groupProps.SetProperties(GlobalProperties) - dbGroup.props = groupProps - } - - } else { - cfgInfo := strings.Split(line, "=") - if len(cfgInfo) < 2 { - continue - } - key := strings.TrimSpace(cfgInfo[0]) - value := strings.TrimSpace(cfgInfo[1]) - if strings.HasPrefix(value, "(") && strings.HasSuffix(value, ")") { - value = strings.TrimSpace(value[1 : len(value)-1]) - } - if key == "" || value == "" { - continue - } - // 区分属性是全局的还是组的 - var success bool - if groupProps.IsNil() { - success = SetServerGroupProperties(GlobalProperties, key, value) - } else { - success = SetServerGroupProperties(groupProps, key, value) - } - if !success { - var serverGroup = parseServerName(key, value) - if serverGroup != nil { - serverGroup.props = NewProperties() - serverGroup.props.SetProperties(GlobalProperties) - ServerGroupMap[strings.ToLower(key)] = serverGroup - } - } - } - } -} - -func SetServerGroupProperties(props *Properties, key string, value string) bool { - if util.StringUtil.EqualsIgnoreCase(key, "ADDRESS_REMAP") { - tmp := props.GetString(AddressRemapKey, "") - props.Set(AddressRemapKey, tmp+"("+value+")") - } else if util.StringUtil.EqualsIgnoreCase(key, "ALWAYS_ALLOW_COMMIT") { - props.Set(AlwayseAllowCommitKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "APP_NAME") { - props.Set(AppNameKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "AUTO_COMMIT") { - props.Set(AutoCommitKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "BATCH_ALLOW_MAX_ERRORS") { - props.Set(BatchAllowMaxErrorsKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "BATCH_CONTINUE_ON_ERROR") || - util.StringUtil.EqualsIgnoreCase(key, "CONTINUE_BATCH_ON_ERROR") { - props.Set(ContinueBatchOnErrorKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "BATCH_NOT_ON_CALL") { - props.Set(BatchNotOnCallKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "BATCH_TYPE") { - props.Set(BatchTypeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "BUF_PREFETCH") { - props.Set(BufPrefetchKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "CIPHER_PATH") { - props.Set(CipherPathKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "CLUSTER") { - props.Set(ClusterKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "COLUMN_NAME_UPPER_CASE") { - props.Set(ColumnNameUpperCaseKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "COLUMN_NAME_CASE") { - props.Set(ColumnNameCaseKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "COMPATIBLE_MODE") { - props.Set(CompatibleModeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "COMPRESS") || - util.StringUtil.EqualsIgnoreCase(key, "COMPRESS_MSG") { - props.Set(CompressKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "COMPRESS_ID") { - props.Set(CompressIdKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "CONNECT_TIMEOUT") { - props.Set(ConnectTimeoutKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "DO_SWITCH") || - util.StringUtil.EqualsIgnoreCase(key, "AUTO_RECONNECT") { - props.Set(DoSwitchKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "ENABLE_RS_CACHE") { - props.Set(EnRsCacheKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "EP_SELECTION") { - props.Set(EpSelectorKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "ESCAPE_PROCESS") { - props.Set(EscapeProcessKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "IS_BDTA_RS") { - props.Set(IsBdtaRSKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "KEY_WORDS") || - util.StringUtil.EqualsIgnoreCase(key, "KEYWORDS") { - props.Set(KeywordsKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LANGUAGE") { - props.Set(LanguageKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOB_MODE") { - props.Set(LobModeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOG_DIR") { - props.Set(LogDirKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOG_FLUSH_FREQ") { - props.Set(LogFlushFreqKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOG_LEVEL") { - props.Set(LogLevelKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOGIN_DSC_CTRL") { - props.Set(LoginDscCtrlKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOGIN_ENCRYPT") { - props.Set(LoginEncryptKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOGIN_MODE") { - props.Set(LoginModeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "LOGIN_STATUS") { - props.Set(LoginStatusKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "MAX_ROWS") { - props.Set(MaxRowsKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "MPP_LOCAL") { - props.Set(MppLocalKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "OS_NAME") { - props.Set(OsNameKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RS_CACHE_SIZE") { - props.Set(RsCacheSizeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RS_REFRESH_FREQ") { - props.Set(RsRefreshFreqKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RW_HA") { - props.Set(RwHAKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RW_IGNORE_SQL") { - props.Set(RwIgnoreSqlKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RW_PERCENT") { - props.Set(RwPercentKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RW_SEPARATE") { - props.Set(RwSeparateKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "RW_STANDBY_RECOVER_TIME") { - props.Set(RwStandbyRecoverTimeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SCHEMA") { - props.Set(SchemaKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SESS_ENCODE") { - if IsSupportedCharset(value) { - props.Set("sessEncode", value) - } - } else if util.StringUtil.EqualsIgnoreCase(key, "SESSION_TIMEOUT") { - props.Set(SessionTimeoutKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SOCKET_TIMEOUT") { - props.Set(SocketTimeoutKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SSL_FILES_PATH") { - props.Set(SslFilesPathKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_DIR") { - props.Set(StatDirKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_ENABLE") { - props.Set(StatEnableKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_FLUSH_FREQ") { - props.Set(StatFlushFreqKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_HIGH_FREQ_SQL_COUNT") { - props.Set(StatHighFreqSqlCountKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_SLOW_SQL_COUNT") { - props.Set(StatSlowSqlCountKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_SQL_MAX_COUNT") { - props.Set(StatSqlMaxCountKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "STAT_SQL_REMOVE_MODE") { - props.Set(StatSqlRemoveModeKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SWITCH_INTERVAL") { - props.Set(SwitchIntervalKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "SWITCH_TIME") || - util.StringUtil.EqualsIgnoreCase(key, "SWITCH_TIMES") { - props.Set(SwitchTimesKey, value) - } else if util.StringUtil.EqualsIgnoreCase(key, "TIME_ZONE") { - props.Set(TimeZoneKey, value) - props.Set("localTimezone", value) - } else if util.StringUtil.EqualsIgnoreCase(key, "USER_REMAP") { - tmp := props.GetString(UserRemapKey, "") - props.Set(UserRemapKey, tmp+"("+value+")") - } else { - return false - } - return true -} - -func parseServerName(name string, value string) *epGroup { - values := strings.Split(value, ",") - - var tmpVals []string - var tmpName string - var tmpPort int - var svrList = make([]*ep, 0, len(values)) - - for _, v := range values { - - var tmp *ep - // 先查找IPV6,以[]包括 - begin := strings.IndexByte(v, '[') - end := -1 - if begin != -1 { - end = strings.IndexByte(v[begin:], ']') - } - if end != -1 { - tmpName = v[begin+1 : end] - - // port - if portIndex := strings.IndexByte(v[end:], ':'); portIndex != -1 { - tmpPort, _ = strconv.Atoi(strings.TrimSpace(v[portIndex+1:])) - } else { - tmpPort = int(DEFAULT_PORT) - } - tmp = newEP(tmpName, int32(tmpPort)) - svrList = append(svrList, tmp) - continue - } - // IPV4 - tmpVals = strings.Split(v, ":") - tmpName = strings.TrimSpace(tmpVals[0]) - if len(tmpVals) >= 2 { - tmpPort, _ = strconv.Atoi(tmpVals[1]) - } else { - tmpPort = int(DEFAULT_PORT) - } - tmp = newEP(tmpName, int32(tmpPort)) - svrList = append(svrList, tmp) - } - - if len(svrList) == 0 { - return nil - } - return newEPGroup(name, svrList) -} - -func setDriverAttributes(props *Properties) { - if props == nil || props.Len() == 0 { - return - } - - parseLanguage(props.GetString(LanguageKey, "cn")) - DbAliveCheckFreq = props.GetInt(DbAliveCheckFreqKey, DbAliveCheckFreqDef, 1, int(INT32_MAX)) - - //// log - //LogLevel = ParseLogLevel(props) - //LogDir = util.StringUtil.FormatDir(props.GetTrimString(LogDirKey, LogDirDef)) - //LogBufferSize = props.GetInt(LogBufferSizeKey, LogBufferSizeDef, 1, int(INT32_MAX)) - //LogFlushFreq = props.GetInt(LogFlushFreqKey, LogFlushFreqDef, 1, int(INT32_MAX)) - //LogFlushQueueSize = props.GetInt(LogFlusherQueueSizeKey, LogFlushQueueSizeDef, 1, int(INT32_MAX)) - // - //// stat - //StatEnable = props.GetBool(StatEnableKey, StatEnableDef) - //StatDir = util.StringUtil.FormatDir(props.GetTrimString(StatDirKey, StatDirDef)) - //StatFlushFreq = props.GetInt(StatFlushFreqKey, StatFlushFreqDef, 1, int(INT32_MAX)) - //StatHighFreqSqlCount = props.GetInt(StatHighFreqSqlCountKey, StatHighFreqSqlCountDef, 0, 1000) - //StatSlowSqlCount = props.GetInt(StatSlowSqlCountKey, StatSlowSqlCountDef, 0, 1000) - //StatSqlMaxCount = props.GetInt(StatSqlMaxCountKey, StatSqlMaxCountDef, 0, 100000) - //parseStatSqlRemoveMode(props) -} - -func parseLanguage(value string) { - if util.StringUtil.EqualsIgnoreCase("cn", value) { - Locale = 0 - } else if util.StringUtil.EqualsIgnoreCase("en", value) { - Locale = 1 - } -} - -func IsSupportedCharset(charset string) bool { - if util.StringUtil.EqualsIgnoreCase(ENCODING_UTF8, charset) || util.StringUtil.EqualsIgnoreCase(ENCODING_GB18030, charset) || util.StringUtil.EqualsIgnoreCase(ENCODING_EUCKR, charset) { - return true - } - return false -} - func ParseLogLevel(props *Properties) int { logLevel := LOG_OFF value := props.GetString(LogLevelKey, "") diff --git a/zzn.go b/zzn.go index 27c37e8..3f91a31 100644 --- a/zzn.go +++ b/zzn.go @@ -184,7 +184,7 @@ const ( CURRENCY_SCALE = 4 - FLOAT_SCALE_MASK = 0X81 + FLOAT_SCALE_MASK = 0x81 ) func resetColType(stmt *DmStatement, i int, colType int32) bool { @@ -387,7 +387,7 @@ func (column *column) PrecisionScale() (precision, scale int64, ok bool) { return int64(0), int64(0), false } -func (column *column) getColumnData(bytes []byte, conn *DmConnection) (driver.Value, error) { +func (column *column) getColumnData(bytes []byte, conn *Connection) (driver.Value, error) { if bytes == nil { return nil, nil } diff --git a/zzo.go b/zzo.go index a48df44..c69b792 100644 --- a/zzo.go +++ b/zzo.go @@ -7,7 +7,7 @@ package dm import ( "strconv" - "gitee.com/chunanyong/dm/util" + "github.com/gotomicro/dmgo/util" ) const ( diff --git a/zzp.go b/zzp.go index 0538443..56144fb 100644 --- a/zzp.go +++ b/zzp.go @@ -41,7 +41,7 @@ type TypeDescriptor struct { m_size int - m_conn *DmConnection + m_conn *Connection m_serverEncoding string @@ -52,7 +52,7 @@ type TypeDescriptor struct { m_descBuf []byte } -func newTypeDescriptorWithFulName(fulName string, conn *DmConnection) *TypeDescriptor { +func newTypeDescriptorWithFulName(fulName string, conn *Connection) *TypeDescriptor { td := new(TypeDescriptor) td.init() td.m_sqlName = newSqlNameByFulName(fulName) @@ -60,7 +60,7 @@ func newTypeDescriptorWithFulName(fulName string, conn *DmConnection) *TypeDescr return td } -func newTypeDescriptor(conn *DmConnection) *TypeDescriptor { +func newTypeDescriptor(conn *Connection) *TypeDescriptor { td := new(TypeDescriptor) td.init() td.m_sqlName = newSqlNameByConn(conn)