xugu_conn.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package xugu
  2. import (
  3. "bytes"
  4. "database/sql/driver"
  5. "errors"
  6. "fmt"
  7. "net"
  8. "sync"
  9. )
  10. type xuguConn struct {
  11. dsnConfig
  12. conn net.Conn
  13. mu sync.Mutex
  14. Type HANDLE_TYPE // 句柄类型
  15. useSSL bool // 是否使用加密
  16. havePrepare int //default 0
  17. bkChar byte
  18. prepareNo int //fashengqi
  19. prepareName string
  20. //presPrepareCata *Result
  21. params *XGCSParam
  22. errStr []byte
  23. sendBuff bytes.Buffer
  24. readBuff buffer
  25. }
  26. type dsnConfig struct {
  27. IP string
  28. Port string
  29. Database string
  30. User string
  31. Password string
  32. Encryptor string //加密库的解密口令
  33. CharSet string //客户端使用的字符集名
  34. TimeZone string
  35. IsoLevel string //事务隔离级别
  36. LockTimeout string //加锁超时
  37. AutoCommit string
  38. StrictCommit string
  39. Result string
  40. ReturnSchema string
  41. ReturnCursorID string
  42. LobRet string
  43. ReturnRowid string
  44. Version string
  45. }
  46. func (xgConn *xuguConn) get_error() error {
  47. return nil
  48. }
  49. func (xgConn *xuguConn) Begin() (driver.Tx, error) {
  50. return nil, nil
  51. }
  52. func (xgConn *xuguConn) Prepare(query string) (driver.Stmt, error) {
  53. fmt.Println(">>>>>(xgConn *xuguConn) Prepare(query string)")
  54. //判断sql类型
  55. switch switchSQLType(query) {
  56. case SQL_PROCEDURE:
  57. return nil, errors.New("Prepare does not support stored procedures")
  58. case SQL_UNKNOWN:
  59. return nil, errors.New("Unknown SQL statement type")
  60. case SQL_CREATE:
  61. return nil, errors.New("Prepare does not support DDL.")
  62. }
  63. stmt := &xuguStmt{
  64. stmt_conn: xgConn,
  65. prepared: true,
  66. prename: make([]byte, 128),
  67. curopend: false,
  68. curname: make([]byte, 128),
  69. param_count: 0,
  70. result: nil,
  71. mysql: query,
  72. }
  73. return stmt, nil
  74. }
  75. func (xgConn *xuguConn) Close() error {
  76. fmt.Println("Close connection")
  77. err := xgConn.conn.Close()
  78. if err != nil {
  79. fmt.Println("Close connection error")
  80. return err
  81. }
  82. return nil
  83. }