yasdb

package module
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 1

README

yasdb-go|崖山数据库GO语言驱动程序

yasdb-go 是 YashanDB 官方 Go 语言数据库驱动,完全兼容 Go 标准的 database/sql 接口,依赖崖山数据库C驱动。

特性
  • ✅ 全面兼容 Go 1.18+
  • ✅ 符合 Go 标准 database/sql 接口
  • ✅ 预处理语句与批量操作
  • ✅ 事务支持
  • ✅ 上下文控制(Cancel/Timeout)
  • ✅ 多版本运行时检测与自动适配
DSN的填写说明

参考教程: DSN format

兼容性说明
GO驱动版本 版本发布时间 新特性 最低兼容C驱动版本 完全支持C驱动版本
1.4.2 2026.3.18 首版本支持 v23.4.1.100 v23.4.1.100

Documentation

Overview

Copyright 2022, YashanDB and/or its affiliates. All rights reserved. YashanDB Driver for golang is licensed under the terms of the mulan PSL v2.0

License: http://license.coscl.org.cn/MulanPSL2 Home page: https://www.yashandb.com/

Index

Constants

View Source
const (
	SS_UNKNOWN     serverStatus = 255
	SS_UNCONNECTED serverStatus = 0
	SS_NORMAL      serverStatus = 1
)
View Source
const (
	NormalConnErr     = "error connecting: "
	IntegerPrimaryKey = "integer primary key"
)
View Source
const (
	DBG_RUNNING_ATTR_STATUS      DebugRunningAttr = 0
	DBG_RUNNING_ATTR_OBJ_ID      DebugRunningAttr = 1
	DBG_RUNNING_ATTR_SUB_ID      DebugRunningAttr = 2
	DBG_RUNNING_ATTR_LINE_NO     DebugRunningAttr = 3
	DBG_RUNNING_ATTR_CLASS_NAME  DebugRunningAttr = 4
	DBG_RUNNING_ATTR_METHOD_NAME DebugRunningAttr = 5

	DBG_FRAME_ATTR_OBJ_ID      DebugFrameAttr = 0
	DBG_FRAME_ATTR_SUB_ID      DebugFrameAttr = 1
	DBG_FRAME_ATTR_LINE_NO     DebugFrameAttr = 2
	DBG_FRAME_ATTR_STACK_NO    DebugFrameAttr = 3
	DBG_FRAME_ATTR_CLASS_NAME  DebugFrameAttr = 4
	DBG_FRAME_ATTR_METHOD_NAME DebugFrameAttr = 5

	DBG_VAR_ATTR_BLOCK_NO   DebugVarAttr = 0
	DBG_VAR_ATTR_TYPE       DebugVarAttr = 1
	DBG_VAR_ATTR_IS_GLOBAL  DebugVarAttr = 2
	DBG_VAR_ATTR_NAME       DebugVarAttr = 3
	DBG_VAR_ATTR_VALUE_SIZE DebugVarAttr = 4

	DBG_BP_ATTR_OBJ_ID  DebugBpAttr = 0
	DBG_BP_ATTR_SUB_ID  DebugBpAttr = 1
	DBG_BP_ATTR_LINE_NO DebugBpAttr = 2

	DBG_STATUS_OFF DebuggerStatus = 0
	DBG_STATUS_ON  DebuggerStatus = 1

	DEFAULT_ATTRS_BUFFER = 68*2 + 1
)

Variables

View Source
var (
	CST_UNKNOW cliSqlType = 0
	CST_SELECT cliSqlType = 1
	CST_INSERT cliSqlType = 2
	CST_UPDATE cliSqlType = 3
	CST_DELETE cliSqlType = 4
	CST_PLSQL  cliSqlType = 126
)
View Source
var (
	ValueTypeUint64Err = errors.New("the value parameter type must be *uint64")
	ValueTypeUint16Err = errors.New("the value parameter type must be *uint16")
	ValueTypeUint32Err = errors.New("the value parameter type must be *uint32")
	ValueTypeStringErr = errors.New("the value parameter type must be *string")
)
View Source
var ErrInsertIdUnsupport = errors.New("last insert id is unsupport")

Functions

func ConvertToNameValue

func ConvertToNameValue(args ...any) ([]driver.NamedValue, error)

func FormatTime

func FormatTime(format string, t time.Time) string

取值范围/格式:[0001-01-01 00:00:00.000000,9999-12-31 23:59:59.999999],[-15:59~+15:59],支持的格式符:'YYYY'/'YYY'/'YY'/'Y'/'MM'/'MON'/'MONTH'/'DD'/'D'/'DAY'/'HH'/'HH12'/'HH24'/'MI'/'SS'/'AM'/'A.M.'/'PM'/'P.M.'/'FF'/'FF1'/'FF2'/'FF3'/'FF4'/'FF5'/'FF6'/'FF7'/'FF8'/'FF9'/'TZH'/'TZM'

doc: https://cod-doc.yasdb.com/yashandb/23.4/zh/Reference-Manual/Configuration-Parameters.html#timestamp-format

func FormatYMInterval

func FormatYMInterval(format string, year, month int32) string

func GetDatabaseTypeName

func GetDatabaseTypeName(yapiType uint32) string

func GetDatabaseTypeSize

func GetDatabaseTypeSize(yType C.YapiType) int32

func NewOutputBindValue

func NewOutputBindValue(dest interface{}, opts ...outputBindOpt) (*outputBindInfo, error)

func NewYasRow

func NewYasRow(size uint32, yacType C.YapiType, precision uint8, scale int8, nullable uint8) *yasRow

func PbdgGetBindOutValue

func PbdgGetBindOutValue(stmt *YasStmt) error

func PdbgAbort

func PdbgAbort(stmt *YasStmt) error

func PdbgAddBreakpoint

func PdbgAddBreakpoint(stmt *YasStmt, objId uint64, subId uint16, lineNo uint32) (uint32, error)

func PdbgCheckVersion

func PdbgCheckVersion(stmt *YasStmt, objId uint64, subId uint16, version uint32) error

func PdbgContinue

func PdbgContinue(stmt *YasStmt) error

func PdbgDeleteAllBreakpoints

func PdbgDeleteAllBreakpoints(stmt *YasStmt) error

func PdbgDeleteBreakpoint

func PdbgDeleteBreakpoint(stmt *YasStmt, objId uint64, subId uint16, lineNo uint32) error

func PdbgGetAllFrames

func PdbgGetAllFrames(stmt *YasStmt) (uint32, error)

func PdbgGetAllVars

func PdbgGetAllVars(stmt *YasStmt) (uint32, error)

func PdbgGetBreakpointAttrs

func PdbgGetBreakpointAttrs(stmt *YasStmt, id uint32, attr DebugBpAttr, value interface{}) error

func PdbgGetBreakpointsCount

func PdbgGetBreakpointsCount(stmt *YasStmt) (uint32, error)

func PdbgGetFrameAttrs

func PdbgGetFrameAttrs(stmt *YasStmt, id uint32, attr DebugFrameAttr, value interface{}) error

func PdbgGetRunningAttrs

func PdbgGetRunningAttrs(stmt *YasStmt, attr DebugRunningAttr, value interface{}) error

func PdbgGetVarAttrs

func PdbgGetVarAttrs(stmt *YasStmt, id uint32, attr DebugVarAttr, value interface{}) error

func PdbgGetVarValue

func PdbgGetVarValue(stmt *YasStmt, id uint32) (string, error)

func PdbgStart

func PdbgStart(stmt *YasStmt, objId uint64, subId uint16) error

func PdbgStatementClose

func PdbgStatementClose(stmt *YasStmt) error

func PdbgStepInto

func PdbgStepInto(stmt *YasStmt) error

func PdbgStepNext

func PdbgStepNext(stmt *YasStmt) error

func PdbgStepOut

func PdbgStepOut(stmt *YasStmt) error

func SetClientDriverName

func SetClientDriverName(name string)

func SetDebugMode

func SetDebugMode()

func WithBindSize

func WithBindSize(bindSize uint32) outputBindOpt

func WithTypeBigInt

func WithTypeBigInt() outputBindOpt

func WithTypeBit

func WithTypeBit() outputBindOpt

func WithTypeBlob

func WithTypeBlob() outputBindOpt

func WithTypeBool

func WithTypeBool() outputBindOpt

func WithTypeChar

func WithTypeChar() outputBindOpt

func WithTypeClob

func WithTypeClob() outputBindOpt

func WithTypeDSInterval

func WithTypeDSInterval() outputBindOpt

func WithTypeDate

func WithTypeDate() outputBindOpt

func WithTypeDouble

func WithTypeDouble() outputBindOpt

func WithTypeFloat

func WithTypeFloat() outputBindOpt

func WithTypeInteger

func WithTypeInteger() outputBindOpt

func WithTypeNumber

func WithTypeNumber() outputBindOpt

func WithTypeNvarchar

func WithTypeNvarchar() outputBindOpt

func WithTypeRaw

func WithTypeRaw() outputBindOpt

func WithTypeRowid

func WithTypeRowid() outputBindOpt

func WithTypeSmallInt

func WithTypeSmallInt() outputBindOpt

func WithTypeTimestamp

func WithTypeTimestamp() outputBindOpt

func WithTypeTimestampLocalTimeZone

func WithTypeTimestampLocalTimeZone() outputBindOpt

func WithTypeTimestampTimeZone

func WithTypeTimestampTimeZone() outputBindOpt

func WithTypeTinyint

func WithTypeTinyint() outputBindOpt

func WithTypeVarchar

func WithTypeVarchar() outputBindOpt

func WithTypeYMInterval

func WithTypeYMInterval() outputBindOpt

Types

type BindOutDestTypeErr

type BindOutDestTypeErr struct {
	TypeFormat string
}

func NewBindOutDestTypeErr

func NewBindOutDestTypeErr(typeFormat string) *BindOutDestTypeErr

func (*BindOutDestTypeErr) Error

func (d *BindOutDestTypeErr) Error() string

type DataSourceName

type DataSourceName struct {
	User         string
	Password     string
	Url          string
	DataPath     string
	IsAutoCommit bool
	// contains filtered or unexported fields
}

func ParseDSN

func ParseDSN(dsnStr string) (*DataSourceName, error)

ParseDSN parses a DataSourceName used to connect to YashanDB

It expects to receive a string in the form:

[username/[password]@]host[:port][?param1=value1&...&paramN=valueN] OR YASDB_DATA_PATH[?param1=value1&...&paramN=valueN] Supported parameters are:

autocommit - When it is true, the transaction will be automatically committed every time an SQL statement is executed. Default is false

type DebugBpAttr

type DebugBpAttr int8

type DebugFrameAttr

type DebugFrameAttr int8

type DebugRunningAttr

type DebugRunningAttr int8

type DebugVarAttr

type DebugVarAttr int8

type DebuggerStatus

type DebuggerStatus int8

type PdbgBreakpointAttr

type PdbgBreakpointAttr struct {
	Id     uint32
	ObjId  uint64
	SubId  uint16
	LineNo uint32
}

func PdbgGetAllBreakpointAttrs

func PdbgGetAllBreakpointAttrs(stmt *YasStmt) ([]*PdbgBreakpointAttr, error)

type PdbgFrameData

type PdbgFrameData struct {
	Id         uint32
	ObjId      uint64
	SubId      uint16
	LineNo     uint32
	StackNo    uint32
	ClassName  string
	MethodName string
}

func PdbgGetAllFrameAttrs

func PdbgGetAllFrameAttrs(stmt *YasStmt) ([]*PdbgFrameData, error)

type PdbgRunningAttr

type PdbgRunningAttr struct {
	Status     DebuggerStatus
	ObjId      uint64
	SubId      uint16
	LineNo     uint32
	ClassName  string
	MethodName string
}

func PdbgGetAllRunningAttrs

func PdbgGetAllRunningAttrs(stmt *YasStmt) (*PdbgRunningAttr, error)

type PdbgVarAttr

type PdbgVarAttr struct {
	Id           uint32
	BlockNo      uint32
	DataType     uint8
	DataTypeName string
	IsGlobal     bool
	Name         string
	Size         uint32
	Value        string
}

func PdbgGetAllVarAttrs

func PdbgGetAllVarAttrs(stmt *YasStmt) ([]*PdbgVarAttr, error)

type PlsqlDebug

type PlsqlDebug struct {
	Stmt *YasStmt
}

func NewPlsqlDebug

func NewPlsqlDebug(dsn string, sql string, args ...any) (*PlsqlDebug, error)

func (*PlsqlDebug) Abort

func (p *PlsqlDebug) Abort() error

func (*PlsqlDebug) AddBreakpoint

func (p *PlsqlDebug) AddBreakpoint(objId uint64, subId uint16, lineNo uint32) (uint32, error)

func (*PlsqlDebug) CheckVersion

func (p *PlsqlDebug) CheckVersion(objId uint64, subId uint16, version uint32) error

func (*PlsqlDebug) Close

func (p *PlsqlDebug) Close() error

func (*PlsqlDebug) Continue

func (p *PlsqlDebug) Continue() error

func (*PlsqlDebug) DeleteAllBreakpoint

func (p *PlsqlDebug) DeleteAllBreakpoint() error

func (*PlsqlDebug) DeleteBreakpoint

func (p *PlsqlDebug) DeleteBreakpoint(objId uint64, subId uint16, lineNo uint32) error

func (*PlsqlDebug) GetAllBreakpointAttrs

func (p *PlsqlDebug) GetAllBreakpointAttrs() ([]*PdbgBreakpointAttr, error)

func (*PlsqlDebug) GetAllFrameAttrs

func (p *PlsqlDebug) GetAllFrameAttrs() ([]*PdbgFrameData, error)

func (*PlsqlDebug) GetAllFrames

func (p *PlsqlDebug) GetAllFrames() (uint32, error)

func (*PlsqlDebug) GetAllRunningAttrs

func (p *PlsqlDebug) GetAllRunningAttrs() (*PdbgRunningAttr, error)

func (*PlsqlDebug) GetAllVarAttrs

func (p *PlsqlDebug) GetAllVarAttrs() ([]*PdbgVarAttr, error)

func (*PlsqlDebug) GetAllVars

func (p *PlsqlDebug) GetAllVars() (uint32, error)

func (*PlsqlDebug) GetBindOutValue

func (p *PlsqlDebug) GetBindOutValue() error

func (*PlsqlDebug) GetBreakpointAttrs

func (p *PlsqlDebug) GetBreakpointAttrs(id uint32, attr DebugBpAttr, value interface{}) error

func (*PlsqlDebug) GetBreakpointsCount

func (p *PlsqlDebug) GetBreakpointsCount() (uint32, error)

func (*PlsqlDebug) GetFrameAttrs

func (p *PlsqlDebug) GetFrameAttrs(id uint32, attr DebugFrameAttr, value interface{}) error

func (*PlsqlDebug) GetRunningAttrs

func (p *PlsqlDebug) GetRunningAttrs(attr DebugRunningAttr, value interface{}) error

func (*PlsqlDebug) GetVarAttrs

func (p *PlsqlDebug) GetVarAttrs(id uint32, attr DebugVarAttr, value interface{}) error

func (*PlsqlDebug) GetVarValue

func (p *PlsqlDebug) GetVarValue(id uint32) (string, error)

func (*PlsqlDebug) Start

func (p *PlsqlDebug) Start(objId uint64, subId uint16) error

func (*PlsqlDebug) StepInto

func (p *PlsqlDebug) StepInto() error

func (*PlsqlDebug) StepNext

func (p *PlsqlDebug) StepNext() error

func (*PlsqlDebug) StepOut

func (p *PlsqlDebug) StepOut() error

type YasBaseError

type YasBaseError struct {
	Code int
	Msg  string
}

func ErrDataPathNoExist

func ErrDataPathNoExist(p string) *YasBaseError

func ErrDbFetchEOF

func ErrDbFetchEOF() *YasBaseError

func ErrDbTypeUnsupport

func ErrDbTypeUnsupport(dbType int) *YasBaseError

func ErrDsnNoSet

func ErrDsnNoSet() *YasBaseError

func ErrDsnNoStandard

func ErrDsnNoStandard(dsn string) *YasBaseError

func ErrEnvInit

func ErrEnvInit() *YasBaseError

func ErrNoConnect

func ErrNoConnect() *YasBaseError

func ErrOutputBindValue

func ErrOutputBindValue() *YasBaseError

func ErrStmtInit

func ErrStmtInit() *YasBaseError

func ErrStmtNoOpen

func ErrStmtNoOpen() *YasBaseError

func ErrUnknowType

func ErrUnknowType(v interface{}) *YasBaseError

func (*YasBaseError) Error

func (e *YasBaseError) Error() string

type YasConn

type YasConn struct {
	Env  *C.YapiEnv
	Conn *C.YapiConnect
	// contains filtered or unexported fields
}

func GenYasconn

func GenYasconn(dsnStr string) (*YasConn, error)

func (*YasConn) Begin

func (conn *YasConn) Begin() (driver.Tx, error)

func (*YasConn) BeginTx

func (conn *YasConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

func (*YasConn) Close

func (conn *YasConn) Close() error

func (*YasConn) Ping

func (conn *YasConn) Ping(ctx context.Context) error

func (*YasConn) Prepare

func (conn *YasConn) Prepare(query string) (driver.Stmt, error)

func (*YasConn) PrepareContext

func (conn *YasConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

func (*YasConn) ResetSession

func (conn *YasConn) ResetSession(ctx context.Context) error

type YasConnector

type YasConnector struct {
}

func (*YasConnector) Connect

func (connectot *YasConnector) Connect(ctx context.Context) (driver.Conn, error)

Connect returns a connection to the database.

func (*YasConnector) Driver

func (connector *YasConnector) Driver() driver.Driver

Driver returns the underlying Driver of the Connector, mainly to maintain compatibility with the Driver method on sql.DB.

type YasDBError

type YasDBError struct {
	Code     int
	Msg      string
	SqlState string
	Line     int
	Column   int
}

func (*YasDBError) Error

func (e *YasDBError) Error() string

type YasResult

type YasResult struct {
	// contains filtered or unexported fields
}

func (*YasResult) LastInsertId

func (result *YasResult) LastInsertId() (int64, error)

LastInsertId returns the database's auto-generated ID after, for example, an INSERT into a table with primary key.

func (*YasResult) RowsAffected

func (result *YasResult) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected by the query.

type YasRows

type YasRows struct {
	// contains filtered or unexported fields
}

func (*YasRows) Close

func (r *YasRows) Close() error

Close closes the rows iterator.

func (*YasRows) ColumnTypeDatabaseTypeName

func (r *YasRows) ColumnTypeDatabaseTypeName(index int) string

RowsColumnTypeDatabaseTypeName return the database system type name without the length. Type names should be uppercase.

func (*YasRows) ColumnTypeLength

func (r *YasRows) ColumnTypeLength(index int) (length int64, ok bool)

RowsColumnTypeLength return the length of the column type if the column is a variable length type. If the column is not a variable length type ok should return false. If length is not limited other than system limits, it should return math.MaxInt64.

func (*YasRows) ColumnTypeNullable

func (r *YasRows) ColumnTypeNullable(index int) (nullable, ok bool)

func (*YasRows) ColumnTypePrecisionScale

func (r *YasRows) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool)

func (*YasRows) ColumnTypeScanType

func (r *YasRows) ColumnTypeScanType(index int) reflect.Type

ColumnTypeScanType return the value type that can be used to scan types into. For example, the database column type "bigint" this should return "reflect.TypeOf(int64(0))".

func (*YasRows) Columns

func (r *YasRows) Columns() []string

Columns returns the names of the columns.

func (*YasRows) Next

func (r *YasRows) Next(dest []driver.Value) error

Next is called to populate the next row of data into the provided slice. The provided slice will be the same size as the Columns() are wide.

Next should return io.EOF when there are no more rows.

The dest should not be written to outside of Next. Care should be taken when closing Rows not to modify a buffer held in dest.

type YasStmt

type YasStmt struct {
	Conn *YasConn
	Stmt *C.YapiStmt

	SqlType uint32
	Sqlstr  string

	sync.Mutex
	// contains filtered or unexported fields
}

func GenPdbgStatement

func GenPdbgStatement(dsn string, sql string, args ...any) (*YasStmt, error)

func PrepareContext

func PrepareContext(conn *YasConn, ctx context.Context, query string) (*YasStmt, error)

func (*YasStmt) CheckNamedValue

func (stmt *YasStmt) CheckNamedValue(namedValue *driver.NamedValue) error

CheckNamedValue is called before passing arguments to the driver and is called in place of any ColumnConverter. CheckNamedValue must do type validation and conversion as appropriate for the driver.

func (*YasStmt) Close

func (stmt *YasStmt) Close() error

Close closes the statement.

func (*YasStmt) Exec deprecated

func (stmt *YasStmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

Deprecated: Drivers should implement StmtExecContext instead (or additionally).

func (*YasStmt) ExecContext

func (stmt *YasStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)

ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.

ExecContext must honor the context timeout and return when it is canceled.

func (*YasStmt) NumInput

func (stmt *YasStmt) NumInput() int

NumInput returns the number of placeholder parameters.

func (*YasStmt) Query deprecated

func (stmt *YasStmt) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows, such as a SELECT.

Deprecated: Drivers should implement StmtQueryContext instead (or additionally).

func (*YasStmt) QueryContext

func (stmt *YasStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes a query that may return rows, such as a SELECT.

QueryContext must honor the context timeout and return when it is canceled.

type YasTx

type YasTx struct {
	Conn *YasConn
}

func (*YasTx) Commit

func (tx *YasTx) Commit() error

Commit transaction commit

func (*YasTx) Rollback

func (tx *YasTx) Rollback() error

Rollback transaction rollback

type YasdbDriver

type YasdbDriver struct {
	// contains filtered or unexported fields
}

func (*YasdbDriver) Conn

func (yasDriver *YasdbDriver) Conn() *YasConn

func (*YasdbDriver) Open

func (yasDriver *YasdbDriver) Open(dsnStr string) (driver.Conn, error)

Open returns a new connection to the database.

Directories

Path Synopsis
bind command
blob command
clob command
compat_vector command
context command
date command
emoji command
int command
null command
number command
plsql command
raw command
simple command
sqlout command
xml command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL