123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package xugu
- import (
- "bytes"
- "context"
- "database/sql/driver"
- "errors"
- "fmt"
- "net"
- "sync"
- )
- type xugusqlConn struct {
- conn net.Conn
- /* xugusqlResult */
- affectedRows int
- insertId int
- havePrepare int //default 0
- prepareNo int //fashengqi
- params *XGCSParam
- prepareName string
- presPrepareCata *Result
- mu sync.Mutex
- useSSL bool
- turingDataR interface{} // 加密相关的数据,具体类型根据实际情况定义
- errStr []byte
- dsnConfig
- Conn_Attrs
- }
- type Conn_Attrs struct {
- bkChar byte
- sendBuff bytes.Buffer
- }
- type dsnConfig struct {
- IP string
- Port string
- Database string
- User string
- Password string
- Encryptor string //加密库的解密口令
- CharSet string //客户端使用的字符集名
- TimeZone string
- IsoLevel string //事务隔离级别
- LockTimeout string //加锁超时
- AutoCommit string
- StrictCommit string
- Result string
- ReturnSchema string
- ReturnCursorID string
- LobRet string
- ReturnRowid string
- Version string
- }
- func (xgConn *xugusqlConn) get_error() error {
- return nil
- }
- func (xgConn *xugusqlConn) Begin() (driver.Tx, error) {
- err := xgConn.exec("set auto_commit off;")
- if err != nil {
- return nil, xgConn.get_error()
- }
- return &xugusqlTx{tconn: xgConn}, nil
- }
- func (xgConn *xugusqlConn) exec(query string) error {
- return nil
- }
- func (xgConn *xugusqlConn) Prepare(query string) (driver.Stmt, error) {
- switch xgSqlType(query) {
- case SQL_PROCEDURE:
- return nil, errors.New("Prepare does not support stored procedures")
- case SQL_UNKNOWN:
- return nil, errors.New("Unknown SQL statement type")
- case SQL_CREATE:
- return nil, errors.New("Prepare does not support DDL.")
- }
- stmt := &xugusqlStmt{
- stmt_conn: xgConn.conn,
- prepared: false,
- prename: "",
- curopend: false,
- curname: "",
- param_count: 0,
- result: nil,
- mysql: query,
- }
- var sql string
- re, err := xgSockPrepare2(xgConn, sql, &xgConn.prepareName)
- if re < 0 || err != nil {
- return nil, xgConn.get_error()
- }
- stmt.prepared = true
- return stmt, nil
- }
- func (xgConn *xugusqlConn) Close() error {
- fmt.Println("Close connection")
- err := xgConn.conn.Close()
- if err != nil {
- fmt.Println("Close connection error")
- return err
- }
- return nil
- }
- func (xgConn *xugusqlConn) Ping(ctx context.Context) error {
- // sql := C.CString("select count(*) from dual;")
- // defer func() {
- // cgo_c_free(unsafe.Pointer(sql))
- // }()
- // var fieldCount, effectCount C.int
- // var rowCount C.longlong
- // var result unsafe.Pointer
- // re := cgo_xgc_exec_with_reader(&self.conn, sql, &result,
- // &fieldCount, &rowCount, &effectCount)
- // if re < 0 {
- // return self.get_error()
- // }
- return nil
- }
|