xugu_conn.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. //判断sql类型
  54. switch switchSQLType(query) {
  55. case SQL_PROCEDURE:
  56. return nil, errors.New("Prepare does not support stored procedures")
  57. case SQL_UNKNOWN:
  58. return nil, errors.New("Unknown SQL statement type")
  59. case SQL_CREATE:
  60. return nil, errors.New("Prepare does not support DDL.")
  61. }
  62. stmt := &xuguStmt{
  63. stmt_conn: xgConn,
  64. prepared: true,
  65. prename: make([]byte, 128),
  66. curopend: false,
  67. curname: make([]byte, 128),
  68. param_count: 0,
  69. result: nil,
  70. mysql: query,
  71. }
  72. return stmt, nil
  73. }
  74. func (xgConn *xuguConn) Close() error {
  75. fmt.Println("Close connection")
  76. err := xgConn.conn.Close()
  77. if err != nil {
  78. fmt.Println("Close connection error")
  79. return err
  80. }
  81. return nil
  82. }