consts.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. // Server status
  56. const (
  57. _SERVER_STATUS_IN_TRANS = 0x01 // Transaction has started
  58. _SERVER_STATUS_AUTOCOMMIT = 0x02 // Server in auto_commit mode
  59. _SERVER_STATUS_MORE_RESULTS = 0x04
  60. _SERVER_MORE_RESULTS_EXISTS = 0x08 // Multi query - next query exists
  61. _SERVER_QUERY_NO_GOOD_INDEX_USED = 0x10
  62. _SERVER_QUERY_NO_INDEX_USED = 0x20
  63. // Server opened a read-only non-scrollable cursor for a query
  64. _SERVER_STATUS_CURSOR_EXISTS = 0x40
  65. _SERVER_STATUS_LAST_ROW_SENT = 0x80
  66. _SERVER_STATUS_DB_DROPPED = 0x100
  67. _SERVER_STATUS_NO_BACKSLASH_ESCAPES = 0x200
  68. )
  69. // MySQL protocol types.
  70. //
  71. // mymysql uses only some of them for send data to the MySQL server. Used
  72. // MySQL types are marked with a comment contains mymysql type that uses it.
  73. const (
  74. MYSQL_TYPE_DECIMAL = 0x00
  75. MYSQL_TYPE_TINY = 0x01 // int8, uint8, bool
  76. MYSQL_TYPE_SHORT = 0x02 // int16, uint16
  77. MYSQL_TYPE_LONG = 0x03 // int32, uint32
  78. MYSQL_TYPE_FLOAT = 0x04 // float32
  79. MYSQL_TYPE_DOUBLE = 0x05 // float64
  80. MYSQL_TYPE_NULL = 0x06 // nil
  81. MYSQL_TYPE_TIMESTAMP = 0x07 // Timestamp
  82. MYSQL_TYPE_LONGLONG = 0x08 // int64, uint64
  83. MYSQL_TYPE_INT24 = 0x09
  84. MYSQL_TYPE_DATE = 0x0a // Date
  85. MYSQL_TYPE_TIME = 0x0b // Time
  86. MYSQL_TYPE_DATETIME = 0x0c // time.Time
  87. MYSQL_TYPE_YEAR = 0x0d
  88. MYSQL_TYPE_NEWDATE = 0x0e
  89. MYSQL_TYPE_VARCHAR = 0x0f
  90. MYSQL_TYPE_BIT = 0x10
  91. MYSQL_TYPE_NEWDECIMAL = 0xf6
  92. MYSQL_TYPE_ENUM = 0xf7
  93. MYSQL_TYPE_SET = 0xf8
  94. MYSQL_TYPE_TINY_BLOB = 0xf9
  95. MYSQL_TYPE_MEDIUM_BLOB = 0xfa
  96. MYSQL_TYPE_LONG_BLOB = 0xfb
  97. MYSQL_TYPE_BLOB = 0xfc // Blob
  98. MYSQL_TYPE_VAR_STRING = 0xfd // []byte
  99. MYSQL_TYPE_STRING = 0xfe // string
  100. MYSQL_TYPE_GEOMETRY = 0xff
  101. MYSQL_UNSIGNED_MASK = uint16(1 << 15)
  102. )
  103. // Mapping of MySQL types to (prefered) protocol types. Use it if you create
  104. // your own Raw value.
  105. //
  106. // Comments contains corresponding types used by mymysql. string type may be
  107. // replaced by []byte type and vice versa. []byte type is native for sending
  108. // on a network, so any string is converted to it before sending. Than for
  109. // better preformance use []byte.
  110. const (
  111. // Client send and receive, mymysql representation for send / receive
  112. TINYINT = MYSQL_TYPE_TINY // int8 / int8
  113. SMALLINT = MYSQL_TYPE_SHORT // int16 / int16
  114. INT = MYSQL_TYPE_LONG // int32 / int32
  115. BIGINT = MYSQL_TYPE_LONGLONG // int64 / int64
  116. FLOAT = MYSQL_TYPE_FLOAT // float32 / float32
  117. DOUBLE = MYSQL_TYPE_DOUBLE // float64 / float32
  118. TIME = MYSQL_TYPE_TIME // Time / Time
  119. DATE = MYSQL_TYPE_DATE // Date / Date
  120. DATETIME = MYSQL_TYPE_DATETIME // time.Time / time.Time
  121. TIMESTAMP = MYSQL_TYPE_TIMESTAMP // Timestamp / time.Time
  122. CHAR = MYSQL_TYPE_STRING // string / []byte
  123. BLOB = MYSQL_TYPE_BLOB // Blob / []byte
  124. NULL = MYSQL_TYPE_NULL // nil
  125. // Client send only, mymysql representation for send
  126. OUT_TEXT = MYSQL_TYPE_STRING // string
  127. OUT_VARCHAR = MYSQL_TYPE_STRING // string
  128. OUT_BINARY = MYSQL_TYPE_BLOB // Blob
  129. OUT_VARBINARY = MYSQL_TYPE_BLOB // Blob
  130. // Client receive only, mymysql representation for receive
  131. IN_MEDIUMINT = MYSQL_TYPE_LONG // int32
  132. IN_YEAR = MYSQL_TYPE_SHORT // int16
  133. IN_BINARY = MYSQL_TYPE_STRING // []byte
  134. IN_VARCHAR = MYSQL_TYPE_VAR_STRING // []byte
  135. IN_VARBINARY = MYSQL_TYPE_VAR_STRING // []byte
  136. IN_TINYBLOB = MYSQL_TYPE_TINY_BLOB // []byte
  137. IN_TINYTEXT = MYSQL_TYPE_TINY_BLOB // []byte
  138. IN_TEXT = MYSQL_TYPE_BLOB // []byte
  139. IN_MEDIUMBLOB = MYSQL_TYPE_MEDIUM_BLOB // []byte
  140. IN_MEDIUMTEXT = MYSQL_TYPE_MEDIUM_BLOB // []byte
  141. IN_LONGBLOB = MYSQL_TYPE_LONG_BLOB // []byte
  142. IN_LONGTEXT = MYSQL_TYPE_LONG_BLOB // []byte
  143. // MySQL 5.x specific
  144. IN_DECIMAL = MYSQL_TYPE_NEWDECIMAL // TODO
  145. IN_BIT = MYSQL_TYPE_BIT // []byte
  146. )
  147. // Flags - borrowed from GoMySQL
  148. const (
  149. _FLAG_NOT_NULL = 1 << iota
  150. _FLAG_PRI_KEY
  151. _FLAG_UNIQUE_KEY
  152. _FLAG_MULTIPLE_KEY
  153. _FLAG_BLOB
  154. _FLAG_UNSIGNED
  155. _FLAG_ZEROFILL
  156. _FLAG_BINARY
  157. _FLAG_ENUM
  158. _FLAG_AUTO_INCREMENT
  159. _FLAG_TIMESTAMP
  160. _FLAG_SET
  161. _FLAG_NO_DEFAULT_VALUE
  162. )
  163. var (
  164. _SIZE_OF_INT int
  165. _INT_TYPE uint16
  166. )
  167. func init() {
  168. switch strconv.IntSize {
  169. case 32:
  170. _INT_TYPE = MYSQL_TYPE_LONG
  171. _SIZE_OF_INT = 4
  172. case 64:
  173. _INT_TYPE = MYSQL_TYPE_LONGLONG
  174. _SIZE_OF_INT = 8
  175. default:
  176. panic("bad int size")
  177. }
  178. }