consts.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. package native
  2. import "strconv"
  3. // Client caps - borrowed from GoMySQL
  4. const (
  5. _CLIENT_LONG_PASSWORD = 1 << iota // new more secure passwords
  6. _CLIENT_FOUND_ROWS // Found instead of affected rows
  7. _CLIENT_LONG_FLAG // Get all column flags
  8. _CLIENT_CONNECT_WITH_DB // One can specify db on connect
  9. _CLIENT_NO_SCHEMA // Don't allow database.table.column
  10. _CLIENT_COMPRESS // Can use compression protocol
  11. _CLIENT_ODBC // Odbc client
  12. _CLIENT_LOCAL_FILES // Can use LOAD DATA LOCAL
  13. _CLIENT_IGNORE_SPACE // Ignore spaces before '('
  14. _CLIENT_PROTOCOL_41 // New 4.1 protocol
  15. _CLIENT_INTERACTIVE // This is an interactive client
  16. _CLIENT_SSL // Switch to SSL after handshake
  17. _CLIENT_IGNORE_SIGPIPE // IGNORE sigpipes
  18. _CLIENT_TRANSACTIONS // Client knows about transactions
  19. _CLIENT_RESERVED // Old flag for 4.1 protocol
  20. _CLIENT_SECURE_CONN // New 4.1 authentication
  21. _CLIENT_MULTI_STATEMENTS // Enable/disable multi-stmt support
  22. _CLIENT_MULTI_RESULTS // Enable/disable multi-results
  23. )
  24. // Commands - borrowed from GoMySQL
  25. const (
  26. _COM_QUIT = 0x01
  27. _COM_INIT_DB = 0x02
  28. _COM_QUERY = 0x03
  29. _COM_FIELD_LIST = 0x04
  30. _COM_CREATE_DB = 0x05
  31. _COM_DROP_DB = 0x06
  32. _COM_REFRESH = 0x07
  33. _COM_SHUTDOWN = 0x08
  34. _COM_STATISTICS = 0x09
  35. _COM_PROCESS_INFO = 0x0a
  36. _COM_CONNECT = 0x0b
  37. _COM_PROCESS_KILL = 0x0c
  38. _COM_DEBUG = 0x0d
  39. _COM_PING = 0x0e
  40. _COM_TIME = 0x0f
  41. _COM_DELAYED_INSERT = 0x10
  42. _COM_CHANGE_USER = 0x11
  43. _COM_BINLOG_DUMP = 0x12
  44. _COM_TABLE_DUMP = 0x13
  45. _COM_CONNECT_OUT = 0x14
  46. _COM_REGISTER_SLAVE = 0x15
  47. _COM_STMT_PREPARE = 0x16
  48. _COM_STMT_EXECUTE = 0x17
  49. _COM_STMT_SEND_LONG_DATA = 0x18
  50. _COM_STMT_CLOSE = 0x19
  51. _COM_STMT_RESET = 0x1a
  52. _COM_SET_OPTION = 0x1b
  53. _COM_STMT_FETCH = 0x1c
  54. )
  55. // MySQL protocol types.
  56. //
  57. // mymysql uses only some of them for send data to the MySQL server. Used
  58. // MySQL types are marked with a comment contains mymysql type that uses it.
  59. const (
  60. MYSQL_TYPE_DECIMAL = 0x00
  61. MYSQL_TYPE_TINY = 0x01 // int8, uint8, bool
  62. MYSQL_TYPE_SHORT = 0x02 // int16, uint16
  63. MYSQL_TYPE_LONG = 0x03 // int32, uint32
  64. MYSQL_TYPE_FLOAT = 0x04 // float32
  65. MYSQL_TYPE_DOUBLE = 0x05 // float64
  66. MYSQL_TYPE_NULL = 0x06 // nil
  67. MYSQL_TYPE_TIMESTAMP = 0x07 // Timestamp
  68. MYSQL_TYPE_LONGLONG = 0x08 // int64, uint64
  69. MYSQL_TYPE_INT24 = 0x09
  70. MYSQL_TYPE_DATE = 0x0a // Date
  71. MYSQL_TYPE_TIME = 0x0b // Time
  72. MYSQL_TYPE_DATETIME = 0x0c // time.Time
  73. MYSQL_TYPE_YEAR = 0x0d
  74. MYSQL_TYPE_NEWDATE = 0x0e
  75. MYSQL_TYPE_VARCHAR = 0x0f
  76. MYSQL_TYPE_BIT = 0x10
  77. MYSQL_TYPE_NEWDECIMAL = 0xf6
  78. MYSQL_TYPE_ENUM = 0xf7
  79. MYSQL_TYPE_SET = 0xf8
  80. MYSQL_TYPE_TINY_BLOB = 0xf9
  81. MYSQL_TYPE_MEDIUM_BLOB = 0xfa
  82. MYSQL_TYPE_LONG_BLOB = 0xfb
  83. MYSQL_TYPE_BLOB = 0xfc // Blob
  84. MYSQL_TYPE_VAR_STRING = 0xfd // []byte
  85. MYSQL_TYPE_STRING = 0xfe // string
  86. MYSQL_TYPE_GEOMETRY = 0xff
  87. MYSQL_UNSIGNED_MASK = uint16(1 << 15)
  88. )
  89. // Mapping of MySQL types to (prefered) protocol types. Use it if you create
  90. // your own Raw value.
  91. //
  92. // Comments contains corresponding types used by mymysql. string type may be
  93. // replaced by []byte type and vice versa. []byte type is native for sending
  94. // on a network, so any string is converted to it before sending. Than for
  95. // better preformance use []byte.
  96. const (
  97. // Client send and receive, mymysql representation for send / receive
  98. TINYINT = MYSQL_TYPE_TINY // int8 / int8
  99. SMALLINT = MYSQL_TYPE_SHORT // int16 / int16
  100. INT = MYSQL_TYPE_LONG // int32 / int32
  101. BIGINT = MYSQL_TYPE_LONGLONG // int64 / int64
  102. FLOAT = MYSQL_TYPE_FLOAT // float32 / float32
  103. DOUBLE = MYSQL_TYPE_DOUBLE // float64 / float32
  104. TIME = MYSQL_TYPE_TIME // Time / Time
  105. DATE = MYSQL_TYPE_DATE // Date / Date
  106. DATETIME = MYSQL_TYPE_DATETIME // time.Time / time.Time
  107. TIMESTAMP = MYSQL_TYPE_TIMESTAMP // Timestamp / time.Time
  108. CHAR = MYSQL_TYPE_STRING // string / []byte
  109. BLOB = MYSQL_TYPE_BLOB // Blob / []byte
  110. NULL = MYSQL_TYPE_NULL // nil
  111. // Client send only, mymysql representation for send
  112. OUT_TEXT = MYSQL_TYPE_STRING // string
  113. OUT_VARCHAR = MYSQL_TYPE_STRING // string
  114. OUT_BINARY = MYSQL_TYPE_BLOB // Blob
  115. OUT_VARBINARY = MYSQL_TYPE_BLOB // Blob
  116. // Client receive only, mymysql representation for receive
  117. IN_MEDIUMINT = MYSQL_TYPE_LONG // int32
  118. IN_YEAR = MYSQL_TYPE_SHORT // int16
  119. IN_BINARY = MYSQL_TYPE_STRING // []byte
  120. IN_VARCHAR = MYSQL_TYPE_VAR_STRING // []byte
  121. IN_VARBINARY = MYSQL_TYPE_VAR_STRING // []byte
  122. IN_TINYBLOB = MYSQL_TYPE_TINY_BLOB // []byte
  123. IN_TINYTEXT = MYSQL_TYPE_TINY_BLOB // []byte
  124. IN_TEXT = MYSQL_TYPE_BLOB // []byte
  125. IN_MEDIUMBLOB = MYSQL_TYPE_MEDIUM_BLOB // []byte
  126. IN_MEDIUMTEXT = MYSQL_TYPE_MEDIUM_BLOB // []byte
  127. IN_LONGBLOB = MYSQL_TYPE_LONG_BLOB // []byte
  128. IN_LONGTEXT = MYSQL_TYPE_LONG_BLOB // []byte
  129. // MySQL 5.x specific
  130. IN_DECIMAL = MYSQL_TYPE_NEWDECIMAL // TODO
  131. IN_BIT = MYSQL_TYPE_BIT // []byte
  132. )
  133. // Flags - borrowed from GoMySQL
  134. const (
  135. _FLAG_NOT_NULL = 1 << iota
  136. _FLAG_PRI_KEY
  137. _FLAG_UNIQUE_KEY
  138. _FLAG_MULTIPLE_KEY
  139. _FLAG_BLOB
  140. _FLAG_UNSIGNED
  141. _FLAG_ZEROFILL
  142. _FLAG_BINARY
  143. _FLAG_ENUM
  144. _FLAG_AUTO_INCREMENT
  145. _FLAG_TIMESTAMP
  146. _FLAG_SET
  147. _FLAG_NO_DEFAULT_VALUE
  148. )
  149. var (
  150. _SIZE_OF_INT int
  151. _INT_TYPE uint16
  152. )
  153. func init() {
  154. switch strconv.IntSize {
  155. case 32:
  156. _INT_TYPE = MYSQL_TYPE_LONG
  157. _SIZE_OF_INT = 4
  158. case 64:
  159. _INT_TYPE = MYSQL_TYPE_LONGLONG
  160. _SIZE_OF_INT = 8
  161. default:
  162. panic("bad int size")
  163. }
  164. }