1 Star 0 Fork 0

GBase8s/go-gci

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
globals.go 5.60 KB
一键复制 编辑 原始数据 按行查看 历史
package gbase8s
/*
#cgo !noPkgConfig pkg-config: gbase8s
#include "gbase8s.go.h"
*/
import "C"
// noPkgConfig is a Go tag for disabling using pkg-config and using environmental settings like CGO_CFLAGS and CGO_LDFLAGS instead
import (
"context"
"database/sql"
"errors"
"io/ioutil"
"log"
"reflect"
"regexp"
"strconv"
"sync"
"time"
"unsafe"
)
const (
lobBufferSize = 4000
useGCISessionBegin = true
sizeOfNilPointer = unsafe.Sizeof(unsafe.Pointer(nil))
)
type (
// DSN is gbase8s Data Source Name
DSN struct {
Connect string
Username string
Password string
prefetchRows C.ub4
prefetchMemory C.ub4
timeLocation *time.Location
transactionMode C.ub4
enableQMPlaceholders bool
operationMode C.ub4
stmtCacheSize C.ub4
GOGCILogTrac bool
}
// DriverStruct is gbase8s driver struct
DriverStruct struct {
// Logger is used to log connection ping errors, defaults to discard
// To log set it to something like: log.New(os.Stderr, "gbase8s ", log.Ldate|log.Ltime|log.LUTC|log.Lshortfile)
Logger *log.Logger
}
// Connector is the sql driver connector
Connector struct {
// Logger is used to log connection ping errors
Logger *log.Logger
}
// Conn is gbase8s connection
Conn struct {
svc *C.GCISvcCtx
srv *C.GCIServer
env *C.GCIEnv
errHandle *C.GCIError
usrSession *C.GCISession
txHandle *C.GCITrans
prefetchRows C.ub4
prefetchMemory C.ub4
transactionMode C.ub4
operationMode C.ub4
stmtCacheSize C.ub4
inTransaction bool
enableQMPlaceholders bool
closed bool
timeLocation *time.Location
logger *log.Logger
}
// Tx is gbase8s transaction
Tx struct {
conn *Conn
}
// Stmt is gbase8s statement
Stmt struct {
conn *Conn
stmt *C.GCIStmt
closed bool
ctx context.Context
cacheKey string // if statement caching is enabled, this is the key for this statement into the cache
releaseMode C.ub4
}
// Rows is gbase8s rows
Rows struct {
stmt *Stmt
defines []defineStruct
closed bool
}
// Result is gbase8s result
Result struct {
rowsAffected int64
rowsAffectedErr error
rowid string
rowidErr error
stmt *Stmt
}
defineStruct struct {
name string
dataType C.ub2
pbuf unsafe.Pointer
maxSize C.sb4
length *C.ub2
indicator *C.sb2
defineHandle *C.GCIDefine
subDefines []defineStruct
}
bindStruct struct {
dataType C.ub2
pbuf unsafe.Pointer
maxSize C.sb4
length *C.ub2
indicator *C.sb2
bindHandle *C.GCIBind
out sql.Out
}
)
var (
// ErrGCIInvalidHandle is GCI_INVALID_HANDLE
ErrGCIInvalidHandle = errors.New("GCI_INVALID_HANDLE")
// ErrGCISuccessWithInfo is GCI_SUCCESS_WITH_INFO
ErrGCISuccessWithInfo = errors.New("GCI_SUCCESS_WITH_INFO")
// ErrGCIReservedForIntUse is GCI_RESERVED_FOR_INT_USE
ErrGCIReservedForIntUse = errors.New("GCI_RESERVED_FOR_INT_USE")
// ErrGCINoData is GCI_NO_DATA
ErrGCINoData = errors.New("GCI_NO_DATA")
// ErrGCINeedData is GCI_NEED_DATA
ErrGCINeedData = errors.New("GCI_NEED_DATA")
// ErrGCIStillExecuting is GCI_STILL_EXECUTING
ErrGCIStillExecuting = errors.New("GCI_STILL_EXECUTING")
// ErrNoRowid is result has no rowid
ErrNoRowid = errors.New("result has no rowid")
phre = regexp.MustCompile(`\?`)
defaultCharset = C.ub2(0)
typeNil = reflect.TypeOf(nil)
typeString = reflect.TypeOf("a")
typeSliceByte = reflect.TypeOf([]byte{})
typeInt64 = reflect.TypeOf(int64(1))
typeFloat64 = reflect.TypeOf(float64(1))
typeTime = reflect.TypeOf(time.Time{})
// Driver is the sql driver
Driver = &DriverStruct{
Logger: log.New(ioutil.Discard, "", 0),
}
timeLocations []*time.Location
byteBufferPool = sync.Pool{
New: func() interface{} {
return make([]byte, lobBufferSize)
},
}
)
func init() {
sql.Register("gbase8s", Driver)
// set defaultCharset to AL32UTF8
var envP *C.GCIEnv
envPP := &envP
var result C.sword
result = C.GCIEnvCreate(envPP, C.GCI_DEFAULT, nil, nil, nil, nil, 0, nil)
if result != C.GCI_SUCCESS {
panic("GCIEnvCreate error")
}
nlsLang := cString("AL32UTF8")
defaultCharset = C.GCINlsCharSetNameToId(unsafe.Pointer(*envPP), (*C.GCItext)(nlsLang))
C.free(unsafe.Pointer(nlsLang))
C.GCIHandleFree(unsafe.Pointer(*envPP), C.GCI_HTYPE_ENV)
// build timeLocations: GMT -12 to 14
timeLocationNames := []string{"Etc/GMT+12", "Pacific/Pago_Pago", // -12 to -11
"Pacific/Honolulu", "Pacific/Gambier", "Pacific/Pitcairn", "America/Phoenix", "America/Costa_Rica", // -10 to -6
"America/Panama", "America/Puerto_Rico", "America/Punta_Arenas", "America/Noronha", "Atlantic/Cape_Verde", // -5 to -1
"GMT", // 0
"Africa/Lagos", "Africa/Cairo", "Europe/Moscow", "Asia/Dubai", "Asia/Karachi", // 1 to 5
"Asia/Dhaka", "Asia/Jakarta", "Asia/Shanghai", "Asia/Tokyo", "Australia/Brisbane", // 6 to 10
"Pacific/Noumea", "Asia/Anadyr", "Pacific/Enderbury", "Pacific/Kiritimati", // 11 to 14
}
var err error
timeLocations = make([]*time.Location, len(timeLocationNames))
for i := 0; i < len(timeLocations); i++ {
timeLocations[i], err = time.LoadLocation(timeLocationNames[i])
if err != nil {
name := "GMT"
if i < 12 {
name += strconv.FormatInt(int64(i-12), 10)
} else if i > 12 {
name += "+" + strconv.FormatInt(int64(i-12), 10)
}
timeLocations[i] = time.FixedZone(name, 3600*(i-12))
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/GBase8s/go-gci.git
git@gitee.com:GBase8s/go-gci.git
GBase8s
go-gci
go-gci
master

搜索帮助