github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/sqlparse/tidbparser/dependency/mysql/const.go (about) 1 // Copyright 2017 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package mysql 15 16 import ( 17 "fmt" 18 "strings" 19 ) 20 21 func newInvalidModeErr(s string) error { 22 return NewErr(ErrWrongValueForVar, "sql_mode", s) 23 } 24 25 // Version information. 26 var ( 27 // TiDBReleaseVersion is initialized by (git describe --tags) in Makefile. 28 TiDBReleaseVersion = "None" 29 30 // ServerVersion is the version information of this tidb-server in MySQL's format. 31 ServerVersion = fmt.Sprintf("5.7.1-TiDB-%s", TiDBReleaseVersion) 32 ) 33 34 // Header information. 35 const ( 36 OKHeader byte = 0x00 37 ErrHeader byte = 0xff 38 EOFHeader byte = 0xfe 39 LocalInFileHeader byte = 0xfb 40 ) 41 42 // Server information. 43 const ( 44 ServerStatusInTrans uint16 = 0x0001 45 ServerStatusAutocommit uint16 = 0x0002 46 ServerMoreResultsExists uint16 = 0x0008 47 ServerStatusNoGoodIndexUsed uint16 = 0x0010 48 ServerStatusNoIndexUsed uint16 = 0x0020 49 ServerStatusCursorExists uint16 = 0x0040 50 ServerStatusLastRowSend uint16 = 0x0080 51 ServerStatusDBDropped uint16 = 0x0100 52 ServerStatusNoBackslashEscaped uint16 = 0x0200 53 ServerStatusMetadataChanged uint16 = 0x0400 54 ServerStatusWasSlow uint16 = 0x0800 55 ServerPSOutParams uint16 = 0x1000 56 ) 57 58 // Identifier length limitations. 59 // See https://dev.mysql.com/doc/refman/5.7/en/identifiers.html 60 const ( 61 // MaxPayloadLen is the max packet payload length. 62 MaxPayloadLen = 1<<24 - 1 63 // MaxTableNameLength is max length of table name identifier. 64 MaxTableNameLength = 64 65 // MaxDatabaseNameLength is max length of database name identifier. 66 MaxDatabaseNameLength = 64 67 // MaxColumnNameLength is max length of column name identifier. 68 MaxColumnNameLength = 64 69 // MaxKeyParts is max length of key parts. 70 MaxKeyParts = 16 71 // MaxIndexIdentifierLen is max length of index identifier. 72 MaxIndexIdentifierLen = 64 73 // MaxConstraintIdentifierLen is max length of constrain identifier. 74 MaxConstraintIdentifierLen = 64 75 // MaxViewIdentifierLen is max length of view identifier. 76 MaxViewIdentifierLen = 64 77 // MaxAliasIdentifierLen is max length of alias identifier. 78 MaxAliasIdentifierLen = 256 79 // MaxUserDefinedVariableLen is max length of user-defined variable. 80 MaxUserDefinedVariableLen = 64 81 ) 82 83 // ErrTextLength error text length limit. 84 const ErrTextLength = 80 85 86 // Command information. 87 const ( 88 ComSleep byte = iota 89 ComQuit 90 ComInitDB 91 ComQuery 92 ComFieldList 93 ComCreateDB 94 ComDropDB 95 ComRefresh 96 ComShutdown 97 ComStatistics 98 ComProcessInfo 99 ComConnect 100 ComProcessKill 101 ComDebug 102 ComPing 103 ComTime 104 ComDelayedInsert 105 ComChangeUser 106 ComBinlogDump 107 ComTableDump 108 ComConnectOut 109 ComRegisterSlave 110 ComStmtPrepare 111 ComStmtExecute 112 ComStmtSendLongData 113 ComStmtClose 114 ComStmtReset 115 ComSetOption 116 ComStmtFetch 117 ComDaemon 118 ComBinlogDumpGtid 119 ComResetConnection 120 ) 121 122 // Client information. 123 const ( 124 ClientLongPassword uint32 = 1 << iota 125 ClientFoundRows 126 ClientLongFlag 127 ClientConnectWithDB 128 ClientNoSchema 129 ClientCompress 130 ClientODBC 131 ClientLocalFiles 132 ClientIgnoreSpace 133 ClientProtocol41 134 ClientInteractive 135 ClientSSL 136 ClientIgnoreSigpipe 137 ClientTransactions 138 ClientReserved 139 ClientSecureConnection 140 ClientMultiStatements 141 ClientMultiResults 142 ClientPSMultiResults 143 ClientPluginAuth 144 ClientConnectAtts 145 ClientPluginAuthLenencClientData 146 ) 147 148 // Cache type information. 149 const ( 150 TypeNoCache byte = 0xff 151 ) 152 153 // Auth name information. 154 const ( 155 AuthName = "mysql_native_password" 156 ) 157 158 // MySQL database and tables. 159 const ( 160 // SystemDB is the name of system database. 161 SystemDB = "mysql" 162 // UserTable is the table in system db contains user info. 163 UserTable = "User" 164 // DBTable is the table in system db contains db scope privilege info. 165 DBTable = "DB" 166 // TablePrivTable is the table in system db contains table scope privilege info. 167 TablePrivTable = "Tables_priv" 168 // ColumnPrivTable is the table in system db contains column scope privilege info. 169 ColumnPrivTable = "Columns_priv" 170 // GlobalVariablesTable is the table contains global system variables. 171 GlobalVariablesTable = "GLOBAL_VARIABLES" 172 // GlobalStatusTable is the table contains global status variables. 173 GlobalStatusTable = "GLOBAL_STATUS" 174 // TiDBTable is the table contains tidb info. 175 TiDBTable = "tidb" 176 ) 177 178 // PrivilegeType privilege 179 type PrivilegeType uint32 180 181 const ( 182 _ PrivilegeType = 1 << iota 183 // CreatePriv is the privilege to create schema/table. 184 CreatePriv 185 // SelectPriv is the privilege to read from table. 186 SelectPriv 187 // InsertPriv is the privilege to insert data into table. 188 InsertPriv 189 // UpdatePriv is the privilege to update data in table. 190 UpdatePriv 191 // DeletePriv is the privilege to delete data from table. 192 DeletePriv 193 // ShowDBPriv is the privilege to run show databases statement. 194 ShowDBPriv 195 // SuperPriv enables many operations and server behaviors. 196 SuperPriv 197 // CreateUserPriv is the privilege to create user. 198 CreateUserPriv 199 // TriggerPriv is not checked yet. 200 TriggerPriv 201 // DropPriv is the privilege to drop schema/table. 202 DropPriv 203 // ProcessPriv pertains to display of information about the threads executing within the server. 204 ProcessPriv 205 // GrantPriv is the privilege to grant privilege to user. 206 GrantPriv 207 // ReferencesPriv is not checked yet. 208 ReferencesPriv 209 // AlterPriv is the privilege to run alter statement. 210 AlterPriv 211 // ExecutePriv is the privilege to run execute statement. 212 ExecutePriv 213 // IndexPriv is the privilege to create/drop index. 214 IndexPriv 215 // AllPriv is the privilege for all actions. 216 AllPriv 217 ) 218 219 // AllPrivMask is the mask for PrivilegeType with all bits set to 1. 220 const AllPrivMask = AllPriv - 1 221 222 // MySQL type maximum length. 223 const ( 224 // For arguments that have no fixed number of decimals, the decimals value is set to 31, 225 // which is 1 more than the maximum number of decimals permitted for the DECIMAL, FLOAT, and DOUBLE data types. 226 NotFixedDec = 31 227 228 MaxIntWidth = 20 229 MaxRealWidth = 23 230 MaxDecimalScale = 30 231 MaxDecimalWidth = 65 232 MaxDateWidth = 10 // YYYY-MM-DD. 233 MaxDatetimeWidthNoFsp = 19 // YYYY-MM-DD HH:MM:SS 234 MaxDatetimeWidthWithFsp = 26 // YYYY-MM-DD HH:MM:SS[.fraction] 235 MaxDatetimeFullWidth = 29 // YYYY-MM-DD HH:MM:SS.###### AM 236 MaxDurationWidthNoFsp = 10 // HH:MM:SS 237 MaxDurationWidthWithFsp = 15 // HH:MM:SS[.fraction] 238 MaxBlobWidth = 16777216 239 ) 240 241 // MySQL max type field length. 242 const ( 243 MaxFieldCharLength = 255 244 MaxFieldVarCharLength = 65535 245 ) 246 247 // MySQL precision. 248 const ( 249 PrecisionForDouble = 53 250 PrecisionForFloat = 24 251 ) 252 253 // MaxTypeSetMembers is the number of set members. 254 const MaxTypeSetMembers = 64 255 256 // PWDHashLen is the length of password's hash. 257 const PWDHashLen = 40 258 259 // Priv2UserCol is the privilege to mysql.user table column name. 260 var Priv2UserCol = map[PrivilegeType]string{ 261 CreatePriv: "Create_priv", 262 SelectPriv: "Select_priv", 263 InsertPriv: "Insert_priv", 264 UpdatePriv: "Update_priv", 265 DeletePriv: "Delete_priv", 266 ShowDBPriv: "Show_db_priv", 267 SuperPriv: "Super_priv", 268 CreateUserPriv: "Create_user_priv", 269 TriggerPriv: "Trigger_priv", 270 DropPriv: "Drop_priv", 271 ProcessPriv: "Process_priv", 272 GrantPriv: "Grant_priv", 273 ReferencesPriv: "References_priv", 274 AlterPriv: "Alter_priv", 275 ExecutePriv: "Execute_priv", 276 IndexPriv: "Index_priv", 277 } 278 279 // Col2PrivType is the privilege tables column name to privilege type. 280 var Col2PrivType = map[string]PrivilegeType{ 281 "Create_priv": CreatePriv, 282 "Select_priv": SelectPriv, 283 "Insert_priv": InsertPriv, 284 "Update_priv": UpdatePriv, 285 "Delete_priv": DeletePriv, 286 "Show_db_priv": ShowDBPriv, 287 "Super_priv": SuperPriv, 288 "Create_user_priv": CreateUserPriv, 289 "Trigger_priv": TriggerPriv, 290 "Drop_priv": DropPriv, 291 "Process_priv": ProcessPriv, 292 "Grant_priv": GrantPriv, 293 "References_priv": ReferencesPriv, 294 "Alter_priv": AlterPriv, 295 "Execute_priv": ExecutePriv, 296 "Index_priv": IndexPriv, 297 } 298 299 // AllGlobalPrivs is all the privileges in global scope. 300 var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, GrantPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv} 301 302 // Priv2Str is the map for privilege to string. 303 var Priv2Str = map[PrivilegeType]string{ 304 CreatePriv: "Create", 305 SelectPriv: "Select", 306 InsertPriv: "Insert", 307 UpdatePriv: "Update", 308 DeletePriv: "Delete", 309 ShowDBPriv: "Show Databases", 310 SuperPriv: "Super", 311 CreateUserPriv: "Create User", 312 TriggerPriv: "Trigger", 313 DropPriv: "Drop", 314 ProcessPriv: "Process", 315 GrantPriv: "Grant Option", 316 ReferencesPriv: "References", 317 AlterPriv: "Alter", 318 ExecutePriv: "Execute", 319 IndexPriv: "Index", 320 } 321 322 // Priv2SetStr is the map for privilege to string. 323 var Priv2SetStr = map[PrivilegeType]string{ 324 CreatePriv: "Create", 325 SelectPriv: "Select", 326 InsertPriv: "Insert", 327 UpdatePriv: "Update", 328 DeletePriv: "Delete", 329 DropPriv: "Drop", 330 GrantPriv: "Grant", 331 AlterPriv: "Alter", 332 ExecutePriv: "Execute", 333 IndexPriv: "Index", 334 } 335 336 // SetStr2Priv is the map for privilege set string to privilege type. 337 var SetStr2Priv = map[string]PrivilegeType{ 338 "Create": CreatePriv, 339 "Select": SelectPriv, 340 "Insert": InsertPriv, 341 "Update": UpdatePriv, 342 "Delete": DeletePriv, 343 "Drop": DropPriv, 344 "Grant": GrantPriv, 345 "Alter": AlterPriv, 346 "Execute": ExecutePriv, 347 "Index": IndexPriv, 348 } 349 350 // AllDBPrivs is all the privileges in database scope. 351 var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, ExecutePriv, IndexPriv} 352 353 // AllTablePrivs is all the privileges in table scope. 354 var AllTablePrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, IndexPriv} 355 356 // AllColumnPrivs is all the privileges in column scope. 357 var AllColumnPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv} 358 359 // AllPrivilegeLiteral is the string literal for All Privilege. 360 const AllPrivilegeLiteral = "ALL PRIVILEGES" 361 362 // DefaultSQLMode for GLOBAL_VARIABLES 363 const DefaultSQLMode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION" 364 365 // DefaultLengthOfMysqlTypes is the map for default physical length of MySQL data types. 366 // See http://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html 367 var DefaultLengthOfMysqlTypes = map[byte]int{ 368 TypeYear: 1, 369 TypeDate: 3, 370 TypeDuration: 3, 371 TypeDatetime: 8, 372 TypeTimestamp: 4, 373 374 TypeTiny: 1, 375 TypeShort: 2, 376 TypeInt24: 3, 377 TypeLong: 4, 378 TypeLonglong: 8, 379 TypeFloat: 4, 380 TypeDouble: 8, 381 382 TypeEnum: 2, 383 TypeString: 1, 384 TypeSet: 8, 385 } 386 387 // DefaultLengthOfTimeFraction is the map for default physical length of time fractions. 388 var DefaultLengthOfTimeFraction = map[int]int{ 389 0: 0, 390 391 1: 1, 392 2: 1, 393 394 3: 2, 395 4: 2, 396 397 5: 3, 398 6: 3, 399 } 400 401 // SQLMode is the type for MySQL sql_mode. 402 // See https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html 403 type SQLMode int 404 405 // HasNoZeroDateMode detects if 'NO_ZERO_DATE' mode is set in SQLMode 406 func (m SQLMode) HasNoZeroDateMode() bool { 407 return m&ModeNoZeroDate == ModeNoZeroDate 408 } 409 410 // HasNoZeroInDateMode detects if 'NO_ZERO_IN_DATE' mode is set in SQLMode 411 func (m SQLMode) HasNoZeroInDateMode() bool { 412 return m&ModeNoZeroInDate == ModeNoZeroInDate 413 } 414 415 // HasErrorForDivisionByZeroMode detects if 'ERROR_FOR_DIVISION_BY_ZERO' mode is set in SQLMode 416 func (m SQLMode) HasErrorForDivisionByZeroMode() bool { 417 return m&ModeErrorForDivisionByZero == ModeErrorForDivisionByZero 418 } 419 420 // HasOnlyFullGroupBy detects if 'ONLY_FULL_GROUP_BY' mode is set in SQLMode 421 func (m SQLMode) HasOnlyFullGroupBy() bool { 422 return m&ModeOnlyFullGroupBy == ModeOnlyFullGroupBy 423 } 424 425 // HasStrictMode detects if 'STRICT_TRANS_TABLES' or 'STRICT_ALL_TABLES' mode is set in SQLMode 426 func (m SQLMode) HasStrictMode() bool { 427 return m&ModeStrictTransTables == ModeStrictTransTables || m&ModeStrictAllTables == ModeStrictAllTables 428 } 429 430 // HasPipesAsConcatMode detects if 'PIPES_AS_CONCAT' mode is set in SQLMode 431 func (m SQLMode) HasPipesAsConcatMode() bool { 432 return m&ModePipesAsConcat == ModePipesAsConcat 433 } 434 435 // HasNoUnsignedSubtractionMode detects if 'NO_UNSIGNED_SUBTRACTION' mode is set in SQLMode 436 func (m SQLMode) HasNoUnsignedSubtractionMode() bool { 437 return m&ModeNoUnsignedSubtraction == ModeNoUnsignedSubtraction 438 } 439 440 // HasHighNotPrecedenceMode detects if 'HIGH_NOT_PRECEDENCE' mode is set in SQLMode 441 func (m SQLMode) HasHighNotPrecedenceMode() bool { 442 return m&ModeHighNotPrecedence == ModeHighNotPrecedence 443 } 444 445 // HasANSIQuotesMode detects if 'ANSI_QUOTES' mode is set in SQLMode 446 func (m SQLMode) HasANSIQuotesMode() bool { 447 return m&ModeANSIQuotes == ModeANSIQuotes 448 } 449 450 // HasRealAsFloatMode detects if 'REAL_AS_FLOAT' mode is set in SQLMode 451 func (m SQLMode) HasRealAsFloatMode() bool { 452 return m&ModeRealAsFloat == ModeRealAsFloat 453 } 454 455 // HasPadCharToFullLengthMode detects if 'PAD_CHAR_TO_FULL_LENGTH' mode is set in SQLMode 456 func (m SQLMode) HasPadCharToFullLengthMode() bool { 457 return m&ModePadCharToFullLength == ModePadCharToFullLength 458 } 459 460 // HasNoBackslashEscapesMode detects if 'NO_BACKSLASH_ESCAPES' mode is set in SQLMode 461 func (m SQLMode) HasNoBackslashEscapesMode() bool { 462 return m&ModeNoBackslashEscapes == ModeNoBackslashEscapes 463 } 464 465 // HasIgnoreSpaceMode detects if 'IGNORE_SPACE' mode is set in SQLMode 466 func (m SQLMode) HasIgnoreSpaceMode() bool { 467 return m&ModeIgnoreSpace == ModeIgnoreSpace 468 } 469 470 // consts for sql modes. 471 const ( 472 ModeNone SQLMode = 0 473 ModeRealAsFloat SQLMode = 1 << iota 474 ModePipesAsConcat 475 ModeANSIQuotes 476 ModeIgnoreSpace 477 ModeNotUsed 478 ModeOnlyFullGroupBy 479 ModeNoUnsignedSubtraction 480 ModeNoDirInCreate 481 ModePostgreSQL 482 ModeOracle 483 ModeMsSQL 484 ModeDb2 485 ModeMaxdb 486 ModeNoKeyOptions 487 ModeNoTableOptions 488 ModeNoFieldOptions 489 ModeMySQL323 490 ModeMySQL40 491 ModeANSI 492 ModeNoAutoValueOnZero 493 ModeNoBackslashEscapes 494 ModeStrictTransTables 495 ModeStrictAllTables 496 ModeNoZeroInDate 497 ModeNoZeroDate 498 ModeInvalidDates 499 ModeErrorForDivisionByZero 500 ModeTraditional 501 ModeNoAutoCreateUser 502 ModeHighNotPrecedence 503 ModeNoEngineSubstitution 504 ModePadCharToFullLength 505 ) 506 507 // FormatSQLModeStr re-format 'SQL_MODE' variable. 508 func FormatSQLModeStr(s string) string { 509 s = strings.ToUpper(strings.TrimRight(s, " ")) 510 parts := strings.Split(s, ",") 511 var nonEmptyParts []string 512 existParts := make(map[string]string) 513 for _, part := range parts { 514 if len(part) == 0 { 515 continue 516 } 517 if modeParts, ok := CombinationSQLMode[part]; ok { 518 for _, modePart := range modeParts { 519 if _, exist := existParts[modePart]; !exist { 520 nonEmptyParts = append(nonEmptyParts, modePart) 521 existParts[modePart] = modePart 522 } 523 } 524 } 525 if _, exist := existParts[part]; !exist { 526 nonEmptyParts = append(nonEmptyParts, part) 527 existParts[part] = part 528 } 529 } 530 return strings.Join(nonEmptyParts, ",") 531 } 532 533 // GetSQLMode gets the sql mode for string literal. SQL_mode is a list of different modes separated by commas. 534 // The input string must be formatted by 'FormatSQLModeStr' 535 func GetSQLMode(s string) (SQLMode, error) { 536 strs := strings.Split(s, ",") 537 var sqlMode SQLMode 538 for i, length := 0, len(strs); i < length; i++ { 539 mode, ok := Str2SQLMode[strs[i]] 540 if !ok && strs[i] != "" { 541 return sqlMode, newInvalidModeErr(strs[i]) 542 } 543 sqlMode = sqlMode | mode 544 } 545 return sqlMode, nil 546 } 547 548 // Str2SQLMode is the string represent of sql_mode to sql_mode map. 549 var Str2SQLMode = map[string]SQLMode{ 550 "REAL_AS_FLOAT": ModeRealAsFloat, 551 "PIPES_AS_CONCAT": ModePipesAsConcat, 552 "ANSI_QUOTES": ModeANSIQuotes, 553 "IGNORE_SPACE": ModeIgnoreSpace, 554 "NOT_USED": ModeNotUsed, 555 "ONLY_FULL_GROUP_BY": ModeOnlyFullGroupBy, 556 "NO_UNSIGNED_SUBTRACTION": ModeNoUnsignedSubtraction, 557 "NO_DIR_IN_CREATE": ModeNoDirInCreate, 558 "POSTGRESQL": ModePostgreSQL, 559 "ORACLE": ModeOracle, 560 "MSSQL": ModeMsSQL, 561 "DB2": ModeDb2, 562 "MAXDB": ModeMaxdb, 563 "NO_KEY_OPTIONS": ModeNoKeyOptions, 564 "NO_TABLE_OPTIONS": ModeNoTableOptions, 565 "NO_FIELD_OPTIONS": ModeNoFieldOptions, 566 "MYSQL323": ModeMySQL323, 567 "MYSQL40": ModeMySQL40, 568 "ANSI": ModeANSI, 569 "NO_AUTO_VALUE_ON_ZERO": ModeNoAutoValueOnZero, 570 "NO_BACKSLASH_ESCAPES": ModeNoBackslashEscapes, 571 "STRICT_TRANS_TABLES": ModeStrictTransTables, 572 "STRICT_ALL_TABLES": ModeStrictAllTables, 573 "NO_ZERO_IN_DATE": ModeNoZeroInDate, 574 "NO_ZERO_DATE": ModeNoZeroDate, 575 "INVALID_DATES": ModeInvalidDates, 576 "ERROR_FOR_DIVISION_BY_ZERO": ModeErrorForDivisionByZero, 577 "TRADITIONAL": ModeTraditional, 578 "NO_AUTO_CREATE_USER": ModeNoAutoCreateUser, 579 "HIGH_NOT_PRECEDENCE": ModeHighNotPrecedence, 580 "NO_ENGINE_SUBSTITUTION": ModeNoEngineSubstitution, 581 "PAD_CHAR_TO_FULL_LENGTH": ModePadCharToFullLength, 582 } 583 584 // CombinationSQLMode is the special modes that provided as shorthand for combinations of mode values. 585 // See https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-combo. 586 var CombinationSQLMode = map[string][]string{ 587 "ANSI": {"REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "ONLY_FULL_GROUP_BY"}, 588 "DB2": {"PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS"}, 589 "MAXDB": {"PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "NO_AUTO_CREATE_USER"}, 590 "MSSQL": {"PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS"}, 591 "MYSQL323": {"MYSQL323", "HIGH_NOT_PRECEDENCE"}, 592 "MYSQL40": {"MYSQL40", "HIGH_NOT_PRECEDENCE"}, 593 "ORACLE": {"PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "NO_AUTO_CREATE_USER"}, 594 "POSTGRESQL": {"PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", "NO_KEY_OPTIONS", "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS"}, 595 "TRADITIONAL": {"STRICT_TRANS_TABLES", "STRICT_ALL_TABLES", "NO_ZERO_IN_DATE", "NO_ZERO_DATE", "ERROR_FOR_DIVISION_BY_ZERO", "NO_AUTO_CREATE_USER", "NO_ENGINE_SUBSTITUTION"}, 596 } 597 598 // FormatFunc is the locale format function signature. 599 type FormatFunc func(string, string) (string, error) 600 601 // GetLocaleFormatFunction get the format function for sepcific locale. 602 func GetLocaleFormatFunction(loc string) FormatFunc { 603 locale, exist := locale2FormatFunction[loc] 604 if !exist { 605 return formatNotSupport 606 } 607 return locale 608 } 609 610 // locale2FormatFunction is the string represent of locale format function. 611 var locale2FormatFunction = map[string]FormatFunc{ 612 "en_US": formatENUS, 613 "zh_CN": formatZHCN, 614 } 615 616 // PriorityEnum is defined for Priority const values. 617 type PriorityEnum int 618 619 // Priority const values. 620 // See https://dev.mysql.com/doc/refman/5.7/en/insert.html 621 const ( 622 NoPriority PriorityEnum = iota 623 LowPriority 624 HighPriority 625 DelayedPriority 626 ) 627 628 // PrimaryKeyName defines primary key name. 629 const ( 630 PrimaryKeyName = "PRIMARY" 631 )