const.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. package mysql
  9. import "runtime"
  10. const (
  11. defaultAuthPlugin = "mysql_native_password"
  12. defaultMaxAllowedPacket = 64 << 20 // 64 MiB. See https://github.com/go-sql-driver/mysql/issues/1355
  13. minProtocolVersion = 10
  14. maxPacketSize = 1<<24 - 1
  15. timeFormat = "2006-01-02 15:04:05.999999"
  16. // Connection attributes
  17. // See https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html#performance-schema-connection-attributes-available
  18. connAttrClientName = "_client_name"
  19. connAttrClientNameValue = "Go-MySQL-Driver"
  20. connAttrOS = "_os"
  21. connAttrOSValue = runtime.GOOS
  22. connAttrPlatform = "_platform"
  23. connAttrPlatformValue = runtime.GOARCH
  24. connAttrPid = "_pid"
  25. connAttrServerHost = "_server_host"
  26. )
  27. // MySQL constants documentation:
  28. // http://dev.mysql.com/doc/internals/en/client-server-protocol.html
  29. const (
  30. iOK byte = 0x00
  31. iAuthMoreData byte = 0x01
  32. iLocalInFile byte = 0xfb
  33. iEOF byte = 0xfe
  34. iERR byte = 0xff
  35. )
  36. // https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags
  37. type clientFlag uint32
  38. const (
  39. clientLongPassword clientFlag = 1 << iota
  40. clientFoundRows
  41. clientLongFlag
  42. clientConnectWithDB
  43. clientNoSchema
  44. clientCompress
  45. clientODBC
  46. clientLocalFiles
  47. clientIgnoreSpace
  48. clientProtocol41
  49. clientInteractive
  50. clientSSL
  51. clientIgnoreSIGPIPE
  52. clientTransactions
  53. clientReserved
  54. clientSecureConn
  55. clientMultiStatements
  56. clientMultiResults
  57. clientPSMultiResults
  58. clientPluginAuth
  59. clientConnectAttrs
  60. clientPluginAuthLenEncClientData
  61. clientCanHandleExpiredPasswords
  62. clientSessionTrack
  63. clientDeprecateEOF
  64. )
  65. const (
  66. comQuit byte = iota + 1
  67. comInitDB
  68. comQuery
  69. comFieldList
  70. comCreateDB
  71. comDropDB
  72. comRefresh
  73. comShutdown
  74. comStatistics
  75. comProcessInfo
  76. comConnect
  77. comProcessKill
  78. comDebug
  79. comPing
  80. comTime
  81. comDelayedInsert
  82. comChangeUser
  83. comBinlogDump
  84. comTableDump
  85. comConnectOut
  86. comRegisterSlave
  87. comStmtPrepare
  88. comStmtExecute
  89. comStmtSendLongData
  90. comStmtClose
  91. comStmtReset
  92. comSetOption
  93. comStmtFetch
  94. )
  95. // https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
  96. type fieldType byte
  97. const (
  98. fieldTypeDecimal fieldType = iota
  99. fieldTypeTiny
  100. fieldTypeShort
  101. fieldTypeLong
  102. fieldTypeFloat
  103. fieldTypeDouble
  104. fieldTypeNULL
  105. fieldTypeTimestamp
  106. fieldTypeLongLong
  107. fieldTypeInt24
  108. fieldTypeDate
  109. fieldTypeTime
  110. fieldTypeDateTime
  111. fieldTypeYear
  112. fieldTypeNewDate
  113. fieldTypeVarChar
  114. fieldTypeBit
  115. )
  116. const (
  117. fieldTypeJSON fieldType = iota + 0xf5
  118. fieldTypeNewDecimal
  119. fieldTypeEnum
  120. fieldTypeSet
  121. fieldTypeTinyBLOB
  122. fieldTypeMediumBLOB
  123. fieldTypeLongBLOB
  124. fieldTypeBLOB
  125. fieldTypeVarString
  126. fieldTypeString
  127. fieldTypeGeometry
  128. )
  129. type fieldFlag uint16
  130. const (
  131. flagNotNULL fieldFlag = 1 << iota
  132. flagPriKey
  133. flagUniqueKey
  134. flagMultipleKey
  135. flagBLOB
  136. flagUnsigned
  137. flagZeroFill
  138. flagBinary
  139. flagEnum
  140. flagAutoIncrement
  141. flagTimestamp
  142. flagSet
  143. flagUnknown1
  144. flagUnknown2
  145. flagUnknown3
  146. flagUnknown4
  147. )
  148. // http://dev.mysql.com/doc/internals/en/status-flags.html
  149. type statusFlag uint16
  150. const (
  151. statusInTrans statusFlag = 1 << iota
  152. statusInAutocommit
  153. statusReserved // Not in documentation
  154. statusMoreResultsExists
  155. statusNoGoodIndexUsed
  156. statusNoIndexUsed
  157. statusCursorExists
  158. statusLastRowSent
  159. statusDbDropped
  160. statusNoBackslashEscapes
  161. statusMetadataChanged
  162. statusQueryWasSlow
  163. statusPsOutParams
  164. statusInTransReadonly
  165. statusSessionStateChanged
  166. )
  167. const (
  168. cachingSha2PasswordRequestPublicKey = 2
  169. cachingSha2PasswordFastAuthSuccess = 3
  170. cachingSha2PasswordPerformFullAuthentication = 4
  171. )