代码拉取完成,页面将自动刷新
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))
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。