123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package xugu
- import (
- "bytes"
- "context"
- "database/sql/driver"
- "errors"
- "fmt"
- "net"
- "sync"
- )
- type xugusqlConn struct {
- conn net.Conn
-
- affectedRows int
- insertId int
- havePrepare int
- prepareNo int
- 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 {
-
-
-
-
-
-
-
-
-
-
-
-
- return nil
- }
|