summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/dialects
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2022-01-14 18:16:05 -0500
committerGitHub <noreply@github.com>2022-01-14 18:16:05 -0500
commit84145e45c50130922fae9055535ab5ea0378e1d4 (patch)
treefce077a5ae462840bb876ace79aca42abab29ed7 /vendor/xorm.io/xorm/dialects
parent2b16ca7c773de278ba01f122dc6f9f43d7534c52 (diff)
downloadgitea-84145e45c50130922fae9055535ab5ea0378e1d4.tar.gz
gitea-84145e45c50130922fae9055535ab5ea0378e1d4.zip
Remove golang vendored directory (#18277)
* rm go vendor * fix drone yaml * add to gitignore
Diffstat (limited to 'vendor/xorm.io/xorm/dialects')
-rw-r--r--vendor/xorm.io/xorm/dialects/dialect.go330
-rw-r--r--vendor/xorm.io/xorm/dialects/driver.go85
-rw-r--r--vendor/xorm.io/xorm/dialects/filter.go76
-rw-r--r--vendor/xorm.io/xorm/dialects/gen_reserved.sh6
-rw-r--r--vendor/xorm.io/xorm/dialects/mssql.go727
-rw-r--r--vendor/xorm.io/xorm/dialects/mysql.go814
-rw-r--r--vendor/xorm.io/xorm/dialects/oracle.go928
-rw-r--r--vendor/xorm.io/xorm/dialects/pg_reserved.txt746
-rw-r--r--vendor/xorm.io/xorm/dialects/postgres.go1495
-rw-r--r--vendor/xorm.io/xorm/dialects/quote.go15
-rw-r--r--vendor/xorm.io/xorm/dialects/sqlite3.go572
-rw-r--r--vendor/xorm.io/xorm/dialects/table_name.go89
-rw-r--r--vendor/xorm.io/xorm/dialects/time.go61
13 files changed, 0 insertions, 5944 deletions
diff --git a/vendor/xorm.io/xorm/dialects/dialect.go b/vendor/xorm.io/xorm/dialects/dialect.go
deleted file mode 100644
index c234f19a2f..0000000000
--- a/vendor/xorm.io/xorm/dialects/dialect.go
+++ /dev/null
@@ -1,330 +0,0 @@
-// Copyright 2019 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "fmt"
- "strings"
- "time"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-// URI represents an uri to visit database
-type URI struct {
- DBType schemas.DBType
- Proto string
- Host string
- Port string
- DBName string
- User string
- Passwd string
- Charset string
- Laddr string
- Raddr string
- Timeout time.Duration
- Schema string
-}
-
-// SetSchema set schema
-func (uri *URI) SetSchema(schema string) {
- // hack me
- if uri.DBType == schemas.POSTGRES {
- uri.Schema = strings.TrimSpace(schema)
- }
-}
-
-// Dialect represents a kind of database
-type Dialect interface {
- Init(*URI) error
- URI() *URI
- Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error)
-
- SQLType(*schemas.Column) string
- Alias(string) string // return what a sql type's alias of
- ColumnTypeKind(string) int // database column type kind
-
- IsReserved(string) bool
- Quoter() schemas.Quoter
- SetQuotePolicy(quotePolicy QuotePolicy)
-
- AutoIncrStr() string
-
- GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error)
- IndexCheckSQL(tableName, idxName string) (string, []interface{})
- CreateIndexSQL(tableName string, index *schemas.Index) string
- DropIndexSQL(tableName string, index *schemas.Index) string
-
- GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error)
- IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error)
- CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool)
- DropTableSQL(tableName string) (string, bool)
-
- GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error)
- IsColumnExist(queryer core.Queryer, ctx context.Context, tableName string, colName string) (bool, error)
- AddColumnSQL(tableName string, col *schemas.Column) string
- ModifyColumnSQL(tableName string, col *schemas.Column) string
-
- ForUpdateSQL(query string) string
-
- Filters() []Filter
- SetParams(params map[string]string)
-}
-
-// Base represents a basic dialect and all real dialects could embed this struct
-type Base struct {
- dialect Dialect
- uri *URI
- quoter schemas.Quoter
-}
-
-// Alias returned col itself
-func (db *Base) Alias(col string) string {
- return col
-}
-
-// Quoter returns the current database Quoter
-func (db *Base) Quoter() schemas.Quoter {
- return db.quoter
-}
-
-// Init initialize the dialect
-func (db *Base) Init(dialect Dialect, uri *URI) error {
- db.dialect, db.uri = dialect, uri
- return nil
-}
-
-// URI returns the uri of database
-func (db *Base) URI() *URI {
- return db.uri
-}
-
-// CreateTableSQL implements Dialect
-func (db *Base) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
- if tableName == "" {
- tableName = table.Name
- }
-
- quoter := db.dialect.Quoter()
- var b strings.Builder
- b.WriteString("CREATE TABLE IF NOT EXISTS ")
- quoter.QuoteTo(&b, tableName)
- b.WriteString(" (")
-
- for i, colName := range table.ColumnsSeq() {
- col := table.GetColumn(colName)
- s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
- b.WriteString(s)
-
- if i != len(table.ColumnsSeq())-1 {
- b.WriteString(", ")
- }
- }
-
- if len(table.PrimaryKeys) > 1 {
- b.WriteString(", PRIMARY KEY (")
- b.WriteString(quoter.Join(table.PrimaryKeys, ","))
- b.WriteString(")")
- }
-
- b.WriteString(")")
-
- return []string{b.String()}, false
-}
-
-// DropTableSQL returns drop table SQL
-func (db *Base) DropTableSQL(tableName string) (string, bool) {
- quote := db.dialect.Quoter().Quote
- return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName)), true
-}
-
-// HasRecords returns true if the SQL has records returned
-func (db *Base) HasRecords(queryer core.Queryer, ctx context.Context, query string, args ...interface{}) (bool, error) {
- rows, err := queryer.QueryContext(ctx, query, args...)
- if err != nil {
- return false, err
- }
- defer rows.Close()
-
- if rows.Next() {
- return true, nil
- }
- return false, rows.Err()
-}
-
-// IsColumnExist returns true if the column of the table exist
-func (db *Base) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
- quote := db.dialect.Quoter().Quote
- query := fmt.Sprintf(
- "SELECT %v FROM %v.%v WHERE %v = ? AND %v = ? AND %v = ?",
- quote("COLUMN_NAME"),
- quote("INFORMATION_SCHEMA"),
- quote("COLUMNS"),
- quote("TABLE_SCHEMA"),
- quote("TABLE_NAME"),
- quote("COLUMN_NAME"),
- )
- return db.HasRecords(queryer, ctx, query, db.uri.DBName, tableName, colName)
-}
-
-// AddColumnSQL returns a SQL to add a column
-func (db *Base) AddColumnSQL(tableName string, col *schemas.Column) string {
- s, _ := ColumnString(db.dialect, col, true)
- return fmt.Sprintf("ALTER TABLE %v ADD %v", db.dialect.Quoter().Quote(tableName), s)
-}
-
-// CreateIndexSQL returns a SQL to create index
-func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string {
- quoter := db.dialect.Quoter()
- var unique string
- var idxName string
- if index.Type == schemas.UniqueType {
- unique = " UNIQUE"
- }
- idxName = index.XName(tableName)
- return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
- quoter.Quote(idxName), quoter.Quote(tableName),
- quoter.Join(index.Cols, ","))
-}
-
-// DropIndexSQL returns a SQL to drop index
-func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
- quote := db.dialect.Quoter().Quote
- var name string
- if index.IsRegular {
- name = index.XName(tableName)
- } else {
- name = index.Name
- }
- return fmt.Sprintf("DROP INDEX %v ON %s", quote(name), quote(tableName))
-}
-
-// ModifyColumnSQL returns a SQL to modify SQL
-func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
- s, _ := ColumnString(db.dialect, col, false)
- return fmt.Sprintf("ALTER TABLE %s MODIFY COLUMN %s", db.quoter.Quote(tableName), s)
-}
-
-// ForUpdateSQL returns for updateSQL
-func (db *Base) ForUpdateSQL(query string) string {
- return query + " FOR UPDATE"
-}
-
-// SetParams set params
-func (db *Base) SetParams(params map[string]string) {
-}
-
-var (
- dialects = map[string]func() Dialect{}
-)
-
-// RegisterDialect register database dialect
-func RegisterDialect(dbName schemas.DBType, dialectFunc func() Dialect) {
- if dialectFunc == nil {
- panic("core: Register dialect is nil")
- }
- dialects[strings.ToLower(string(dbName))] = dialectFunc // !nashtsai! allow override dialect
-}
-
-// QueryDialect query if registered database dialect
-func QueryDialect(dbName schemas.DBType) Dialect {
- if d, ok := dialects[strings.ToLower(string(dbName))]; ok {
- return d()
- }
- return nil
-}
-
-func regDrvsNDialects() bool {
- providedDrvsNDialects := map[string]struct {
- dbType schemas.DBType
- getDriver func() Driver
- getDialect func() Dialect
- }{
- "mssql": {"mssql", func() Driver { return &odbcDriver{} }, func() Dialect { return &mssql{} }},
- "odbc": {"mssql", func() Driver { return &odbcDriver{} }, func() Dialect { return &mssql{} }}, // !nashtsai! TODO change this when supporting MS Access
- "mysql": {"mysql", func() Driver { return &mysqlDriver{} }, func() Dialect { return &mysql{} }},
- "mymysql": {"mysql", func() Driver { return &mymysqlDriver{} }, func() Dialect { return &mysql{} }},
- "postgres": {"postgres", func() Driver { return &pqDriver{} }, func() Dialect { return &postgres{} }},
- "pgx": {"postgres", func() Driver { return &pqDriverPgx{} }, func() Dialect { return &postgres{} }},
- "sqlite3": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
- "sqlite": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
- "oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
- "godror": {"oracle", func() Driver { return &godrorDriver{} }, func() Dialect { return &oracle{} }},
- }
-
- for driverName, v := range providedDrvsNDialects {
- if driver := QueryDriver(driverName); driver == nil {
- RegisterDriver(driverName, v.getDriver())
- RegisterDialect(v.dbType, v.getDialect)
- }
- }
- return true
-}
-
-func init() {
- regDrvsNDialects()
-}
-
-// ColumnString generate column description string according dialect
-func ColumnString(dialect Dialect, col *schemas.Column, includePrimaryKey bool) (string, error) {
- bd := strings.Builder{}
-
- if err := dialect.Quoter().QuoteTo(&bd, col.Name); err != nil {
- return "", err
- }
-
- if err := bd.WriteByte(' '); err != nil {
- return "", err
- }
-
- if _, err := bd.WriteString(dialect.SQLType(col)); err != nil {
- return "", err
- }
-
- if err := bd.WriteByte(' '); err != nil {
- return "", err
- }
-
- if includePrimaryKey && col.IsPrimaryKey {
- if _, err := bd.WriteString("PRIMARY KEY "); err != nil {
- return "", err
- }
-
- if col.IsAutoIncrement {
- if _, err := bd.WriteString(dialect.AutoIncrStr()); err != nil {
- return "", err
- }
- if err := bd.WriteByte(' '); err != nil {
- return "", err
- }
- }
- }
-
- if col.Default != "" {
- if _, err := bd.WriteString("DEFAULT "); err != nil {
- return "", err
- }
- if _, err := bd.WriteString(col.Default); err != nil {
- return "", err
- }
- if err := bd.WriteByte(' '); err != nil {
- return "", err
- }
- }
-
- if col.Nullable {
- if _, err := bd.WriteString("NULL "); err != nil {
- return "", err
- }
- } else {
- if _, err := bd.WriteString("NOT NULL "); err != nil {
- return "", err
- }
- }
-
- return bd.String(), nil
-}
diff --git a/vendor/xorm.io/xorm/dialects/driver.go b/vendor/xorm.io/xorm/dialects/driver.go
deleted file mode 100644
index c63dbfa3f9..0000000000
--- a/vendor/xorm.io/xorm/dialects/driver.go
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2019 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "database/sql"
- "fmt"
- "time"
-
- "xorm.io/xorm/core"
-)
-
-// ScanContext represents a context when Scan
-type ScanContext struct {
- DBLocation *time.Location
- UserLocation *time.Location
-}
-
-// DriverFeatures represents driver feature
-type DriverFeatures struct {
- SupportReturnInsertedID bool
-}
-
-// Driver represents a database driver
-type Driver interface {
- Parse(string, string) (*URI, error)
- Features() *DriverFeatures
- GenScanResult(string) (interface{}, error) // according given column type generating a suitable scan interface
- Scan(*ScanContext, *core.Rows, []*sql.ColumnType, ...interface{}) error
-}
-
-var (
- drivers = map[string]Driver{}
-)
-
-// RegisterDriver register a driver
-func RegisterDriver(driverName string, driver Driver) {
- if driver == nil {
- panic("core: Register driver is nil")
- }
- if _, dup := drivers[driverName]; dup {
- panic("core: Register called twice for driver " + driverName)
- }
- drivers[driverName] = driver
-}
-
-// QueryDriver query a driver with name
-func QueryDriver(driverName string) Driver {
- return drivers[driverName]
-}
-
-// RegisteredDriverSize returned all drivers's length
-func RegisteredDriverSize() int {
- return len(drivers)
-}
-
-// OpenDialect opens a dialect via driver name and connection string
-func OpenDialect(driverName, connstr string) (Dialect, error) {
- driver := QueryDriver(driverName)
- if driver == nil {
- return nil, fmt.Errorf("unsupported driver name: %v", driverName)
- }
-
- uri, err := driver.Parse(driverName, connstr)
- if err != nil {
- return nil, err
- }
-
- dialect := QueryDialect(uri.DBType)
- if dialect == nil {
- return nil, fmt.Errorf("unsupported dialect type: %v", uri.DBType)
- }
-
- dialect.Init(uri)
-
- return dialect, nil
-}
-
-type baseDriver struct{}
-
-func (b *baseDriver) Scan(ctx *ScanContext, rows *core.Rows, types []*sql.ColumnType, v ...interface{}) error {
- return rows.Scan(v...)
-}
diff --git a/vendor/xorm.io/xorm/dialects/filter.go b/vendor/xorm.io/xorm/dialects/filter.go
deleted file mode 100644
index bfe2e93ebc..0000000000
--- a/vendor/xorm.io/xorm/dialects/filter.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2019 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "fmt"
- "strings"
-)
-
-// Filter is an interface to filter SQL
-type Filter interface {
- Do(sql string) string
-}
-
-// SeqFilter filter SQL replace ?, ? ... to $1, $2 ...
-type SeqFilter struct {
- Prefix string
- Start int
-}
-
-func convertQuestionMark(sql, prefix string, start int) string {
- var buf strings.Builder
- var beginSingleQuote bool
- var isLineComment bool
- var isComment bool
- var isMaybeLineComment bool
- var isMaybeComment bool
- var isMaybeCommentEnd bool
- var index = start
- for _, c := range sql {
- if !beginSingleQuote && !isLineComment && !isComment && c == '?' {
- buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
- index++
- } else {
- if isMaybeLineComment {
- if c == '-' {
- isLineComment = true
- }
- isMaybeLineComment = false
- } else if isMaybeComment {
- if c == '*' {
- isComment = true
- }
- isMaybeComment = false
- } else if isMaybeCommentEnd {
- if c == '/' {
- isComment = false
- }
- isMaybeCommentEnd = false
- } else if isLineComment {
- if c == '\n' {
- isLineComment = false
- }
- } else if isComment {
- if c == '*' {
- isMaybeCommentEnd = true
- }
- } else if !beginSingleQuote && c == '-' {
- isMaybeLineComment = true
- } else if !beginSingleQuote && c == '/' {
- isMaybeComment = true
- } else if c == '\'' {
- beginSingleQuote = !beginSingleQuote
- }
- buf.WriteRune(c)
- }
- }
- return buf.String()
-}
-
-// Do implements Filter
-func (s *SeqFilter) Do(sql string) string {
- return convertQuestionMark(sql, s.Prefix, s.Start)
-}
diff --git a/vendor/xorm.io/xorm/dialects/gen_reserved.sh b/vendor/xorm.io/xorm/dialects/gen_reserved.sh
deleted file mode 100644
index 434a1bfcb0..0000000000
--- a/vendor/xorm.io/xorm/dialects/gen_reserved.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-if [ -f $1 ];then
- cat $1| awk '{printf("\""$1"\":true,\n")}'
-else
- echo "argument $1 if not a file!"
-fi
diff --git a/vendor/xorm.io/xorm/dialects/mssql.go b/vendor/xorm.io/xorm/dialects/mssql.go
deleted file mode 100644
index 323c2b8065..0000000000
--- a/vendor/xorm.io/xorm/dialects/mssql.go
+++ /dev/null
@@ -1,727 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "database/sql"
- "errors"
- "fmt"
- "net/url"
- "strconv"
- "strings"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-var (
- mssqlReservedWords = map[string]bool{
- "ADD": true,
- "EXTERNAL": true,
- "PROCEDURE": true,
- "ALL": true,
- "FETCH": true,
- "PUBLIC": true,
- "ALTER": true,
- "FILE": true,
- "RAISERROR": true,
- "AND": true,
- "FILLFACTOR": true,
- "READ": true,
- "ANY": true,
- "FOR": true,
- "READTEXT": true,
- "AS": true,
- "FOREIGN": true,
- "RECONFIGURE": true,
- "ASC": true,
- "FREETEXT": true,
- "REFERENCES": true,
- "AUTHORIZATION": true,
- "FREETEXTTABLE": true,
- "REPLICATION": true,
- "BACKUP": true,
- "FROM": true,
- "RESTORE": true,
- "BEGIN": true,
- "FULL": true,
- "RESTRICT": true,
- "BETWEEN": true,
- "FUNCTION": true,
- "RETURN": true,
- "BREAK": true,
- "GOTO": true,
- "REVERT": true,
- "BROWSE": true,
- "GRANT": true,
- "REVOKE": true,
- "BULK": true,
- "GROUP": true,
- "RIGHT": true,
- "BY": true,
- "HAVING": true,
- "ROLLBACK": true,
- "CASCADE": true,
- "HOLDLOCK": true,
- "ROWCOUNT": true,
- "CASE": true,
- "IDENTITY": true,
- "ROWGUIDCOL": true,
- "CHECK": true,
- "IDENTITY_INSERT": true,
- "RULE": true,
- "CHECKPOINT": true,
- "IDENTITYCOL": true,
- "SAVE": true,
- "CLOSE": true,
- "IF": true,
- "SCHEMA": true,
- "CLUSTERED": true,
- "IN": true,
- "SECURITYAUDIT": true,
- "COALESCE": true,
- "INDEX": true,
- "SELECT": true,
- "COLLATE": true,
- "INNER": true,
- "SEMANTICKEYPHRASETABLE": true,
- "COLUMN": true,
- "INSERT": true,
- "SEMANTICSIMILARITYDETAILSTABLE": true,
- "COMMIT": true,
- "INTERSECT": true,
- "SEMANTICSIMILARITYTABLE": true,
- "COMPUTE": true,
- "INTO": true,
- "SESSION_USER": true,
- "CONSTRAINT": true,
- "IS": true,
- "SET": true,
- "CONTAINS": true,
- "JOIN": true,
- "SETUSER": true,
- "CONTAINSTABLE": true,
- "KEY": true,
- "SHUTDOWN": true,
- "CONTINUE": true,
- "KILL": true,
- "SOME": true,
- "CONVERT": true,
- "LEFT": true,
- "STATISTICS": true,
- "CREATE": true,
- "LIKE": true,
- "SYSTEM_USER": true,
- "CROSS": true,
- "LINENO": true,
- "TABLE": true,
- "CURRENT": true,
- "LOAD": true,
- "TABLESAMPLE": true,
- "CURRENT_DATE": true,
- "MERGE": true,
- "TEXTSIZE": true,
- "CURRENT_TIME": true,
- "NATIONAL": true,
- "THEN": true,
- "CURRENT_TIMESTAMP": true,
- "NOCHECK": true,
- "TO": true,
- "CURRENT_USER": true,
- "NONCLUSTERED": true,
- "TOP": true,
- "CURSOR": true,
- "NOT": true,
- "TRAN": true,
- "DATABASE": true,
- "NULL": true,
- "TRANSACTION": true,
- "DBCC": true,
- "NULLIF": true,
- "TRIGGER": true,
- "DEALLOCATE": true,
- "OF": true,
- "TRUNCATE": true,
- "DECLARE": true,
- "OFF": true,
- "TRY_CONVERT": true,
- "DEFAULT": true,
- "OFFSETS": true,
- "TSEQUAL": true,
- "DELETE": true,
- "ON": true,
- "UNION": true,
- "DENY": true,
- "OPEN": true,
- "UNIQUE": true,
- "DESC": true,
- "OPENDATASOURCE": true,
- "UNPIVOT": true,
- "DISK": true,
- "OPENQUERY": true,
- "UPDATE": true,
- "DISTINCT": true,
- "OPENROWSET": true,
- "UPDATETEXT": true,
- "DISTRIBUTED": true,
- "OPENXML": true,
- "USE": true,
- "DOUBLE": true,
- "OPTION": true,
- "USER": true,
- "DROP": true,
- "OR": true,
- "VALUES": true,
- "DUMP": true,
- "ORDER": true,
- "VARYING": true,
- "ELSE": true,
- "OUTER": true,
- "VIEW": true,
- "END": true,
- "OVER": true,
- "WAITFOR": true,
- "ERRLVL": true,
- "PERCENT": true,
- "WHEN": true,
- "ESCAPE": true,
- "PIVOT": true,
- "WHERE": true,
- "EXCEPT": true,
- "PLAN": true,
- "WHILE": true,
- "EXEC": true,
- "PRECISION": true,
- "WITH": true,
- "EXECUTE": true,
- "PRIMARY": true,
- "WITHIN": true,
- "EXISTS": true,
- "PRINT": true,
- "WRITETEXT": true,
- "EXIT": true,
- "PROC": true,
- }
-
- mssqlQuoter = schemas.Quoter{
- Prefix: '[',
- Suffix: ']',
- IsReserved: schemas.AlwaysReserve,
- }
-)
-
-type mssql struct {
- Base
- defaultVarchar string
- defaultChar string
-}
-
-func (db *mssql) Init(uri *URI) error {
- db.quoter = mssqlQuoter
- db.defaultChar = "CHAR"
- db.defaultVarchar = "VARCHAR"
- return db.Base.Init(db, uri)
-}
-
-func (db *mssql) SetParams(params map[string]string) {
- defaultVarchar, ok := params["DEFAULT_VARCHAR"]
- if ok {
- var t = strings.ToUpper(defaultVarchar)
- switch t {
- case "NVARCHAR", "VARCHAR":
- db.defaultVarchar = t
- default:
- db.defaultVarchar = "VARCHAR"
- }
- } else {
- db.defaultVarchar = "VARCHAR"
- }
-
- defaultChar, ok := params["DEFAULT_CHAR"]
- if ok {
- var t = strings.ToUpper(defaultChar)
- switch t {
- case "NCHAR", "CHAR":
- db.defaultChar = t
- default:
- db.defaultChar = "CHAR"
- }
- } else {
- db.defaultChar = "CHAR"
- }
-}
-
-func (db *mssql) Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) {
- rows, err := queryer.QueryContext(ctx,
- "SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel') AS ProductLevel, SERVERPROPERTY ('edition') AS ProductEdition")
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- var version, level, edition string
- if !rows.Next() {
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return nil, errors.New("unknow version")
- }
-
- if err := rows.Scan(&version, &level, &edition); err != nil {
- return nil, err
- }
-
- // MSSQL: Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) Nov 30 2018 12:57:58 Copyright (C) 2017 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 16.04.5 LTS)
- return &schemas.Version{
- Number: version,
- Level: level,
- Edition: edition,
- }, nil
-}
-
-func (db *mssql) SQLType(c *schemas.Column) string {
- var res string
- switch t := c.SQLType.Name; t {
- case schemas.Bool, schemas.Boolean:
- res = schemas.Bit
- if strings.EqualFold(c.Default, "true") {
- c.Default = "1"
- } else if strings.EqualFold(c.Default, "false") {
- c.Default = "0"
- }
- return res
- case schemas.Serial:
- c.IsAutoIncrement = true
- c.IsPrimaryKey = true
- c.Nullable = false
- res = schemas.Int
- case schemas.BigSerial:
- c.IsAutoIncrement = true
- c.IsPrimaryKey = true
- c.Nullable = false
- res = schemas.BigInt
- case schemas.Bytea, schemas.Binary:
- res = schemas.VarBinary
- if c.Length == 0 {
- c.Length = 50
- }
- case schemas.Blob, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob:
- res = schemas.VarBinary
- if c.Length == 0 {
- res += "(MAX)"
- }
- case schemas.TimeStamp, schemas.DateTime:
- if c.Length > 3 {
- res = "DATETIME2"
- } else {
- return schemas.DateTime
- }
- case schemas.TimeStampz:
- res = "DATETIMEOFFSET"
- c.Length = 7
- case schemas.MediumInt, schemas.TinyInt, schemas.SmallInt, schemas.UnsignedMediumInt, schemas.UnsignedTinyInt, schemas.UnsignedSmallInt:
- res = schemas.Int
- case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
- res = db.defaultVarchar + "(MAX)"
- case schemas.Double:
- res = schemas.Real
- case schemas.Uuid:
- res = schemas.Varchar
- c.Length = 40
- case schemas.TinyInt:
- res = schemas.TinyInt
- c.Length = 0
- case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
- res = schemas.BigInt
- c.Length = 0
- case schemas.NVarchar:
- res = t
- if c.Length == -1 {
- res += "(MAX)"
- }
- case schemas.Varchar:
- res = db.defaultVarchar
- if c.Length == -1 {
- res += "(MAX)"
- }
- case schemas.Char:
- res = db.defaultChar
- if c.Length == -1 {
- res += "(MAX)"
- }
- case schemas.NChar:
- res = t
- if c.Length == -1 {
- res += "(MAX)"
- }
- default:
- res = t
- }
-
- if res == schemas.Int || res == schemas.Bit {
- return res
- }
-
- hasLen1 := (c.Length > 0)
- hasLen2 := (c.Length2 > 0)
-
- if hasLen2 {
- res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
- } else if hasLen1 {
- res += "(" + strconv.Itoa(c.Length) + ")"
- }
- return res
-}
-
-func (db *mssql) ColumnTypeKind(t string) int {
- switch strings.ToUpper(t) {
- case "DATE", "DATETIME", "DATETIME2", "TIME":
- return schemas.TIME_TYPE
- case "VARCHAR", "TEXT", "CHAR", "NVARCHAR", "NCHAR", "NTEXT":
- return schemas.TEXT_TYPE
- case "FLOAT", "REAL", "BIGINT", "DATETIMEOFFSET", "TINYINT", "SMALLINT", "INT":
- return schemas.NUMERIC_TYPE
- default:
- return schemas.UNKNOW_TYPE
- }
-}
-
-func (db *mssql) IsReserved(name string) bool {
- _, ok := mssqlReservedWords[strings.ToUpper(name)]
- return ok
-}
-
-func (db *mssql) SetQuotePolicy(quotePolicy QuotePolicy) {
- switch quotePolicy {
- case QuotePolicyNone:
- var q = mssqlQuoter
- q.IsReserved = schemas.AlwaysNoReserve
- db.quoter = q
- case QuotePolicyReserved:
- var q = mssqlQuoter
- q.IsReserved = db.IsReserved
- db.quoter = q
- case QuotePolicyAlways:
- fallthrough
- default:
- db.quoter = mssqlQuoter
- }
-}
-
-func (db *mssql) AutoIncrStr() string {
- return "IDENTITY"
-}
-
-func (db *mssql) DropTableSQL(tableName string) (string, bool) {
- return fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+
- "object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+
- "DROP TABLE \"%s\"", tableName, tableName), true
-}
-
-func (db *mssql) ModifyColumnSQL(tableName string, col *schemas.Column) string {
- s, _ := ColumnString(db.dialect, col, false)
- return fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s", db.quoter.Quote(tableName), s)
-}
-
-func (db *mssql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
- args := []interface{}{idxName}
- sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
- return sql, args
-}
-
-func (db *mssql) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
- query := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
-
- return db.HasRecords(queryer, ctx, query, tableName, colName)
-}
-
-func (db *mssql) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
- sql := "select * from sysobjects where id = object_id(N'" + tableName + "') and OBJECTPROPERTY(id, N'IsUserTable') = 1"
- return db.HasRecords(queryer, ctx, sql)
-}
-
-func (db *mssql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
- args := []interface{}{}
- s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
- "default_is_null" = (CASE WHEN c.text is null THEN 1 ELSE 0 END),
- replace(replace(isnull(c.text,''),'(',''),')','') as vdefault,
- ISNULL(p.is_primary_key, 0), a.is_identity as is_identity
- from sys.columns a
- left join sys.types b on a.user_type_id=b.user_type_id
- left join sys.syscomments c on a.default_object_id=c.id
- LEFT OUTER JOIN (SELECT i.object_id, ic.column_id, i.is_primary_key
- FROM sys.indexes i
- LEFT JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
- WHERE i.is_primary_key = 1
- ) as p on p.object_id = a.object_id AND p.column_id = a.column_id
- where a.object_id=object_id('` + tableName + `')`
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, nil, err
- }
- defer rows.Close()
-
- cols := make(map[string]*schemas.Column)
- colSeq := make([]string, 0)
- for rows.Next() {
- var name, ctype, vdefault string
- var maxLen, precision, scale int
- var nullable, isPK, defaultIsNull, isIncrement bool
- err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &defaultIsNull, &vdefault, &isPK, &isIncrement)
- if err != nil {
- return nil, nil, err
- }
-
- col := new(schemas.Column)
- col.Indexes = make(map[string]int)
- col.Name = strings.Trim(name, "` ")
- col.Nullable = nullable
- col.DefaultIsEmpty = defaultIsNull
- if !defaultIsNull {
- col.Default = vdefault
- }
- col.IsPrimaryKey = isPK
- col.IsAutoIncrement = isIncrement
- ct := strings.ToUpper(ctype)
- if ct == "DECIMAL" {
- col.Length = precision
- col.Length2 = scale
- } else {
- col.Length = maxLen
- }
- switch ct {
- case "DATETIMEOFFSET":
- col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
- case "NVARCHAR":
- col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: 0, DefaultLength2: 0}
- if col.Length > 0 {
- col.Length /= 2
- col.Length2 /= 2
- }
- case "DATETIME2":
- col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 7, DefaultLength2: 0}
- col.Length = scale
- case "DATETIME":
- col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 3, DefaultLength2: 0}
- col.Length = scale
- case "IMAGE":
- col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0}
- case "NCHAR":
- if col.Length > 0 {
- col.Length /= 2
- col.Length2 /= 2
- }
- fallthrough
- default:
- if _, ok := schemas.SqlTypes[ct]; ok {
- col.SQLType = schemas.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0}
- } else {
- return nil, nil, fmt.Errorf("Unknown colType %v for %v - %v", ct, tableName, col.Name)
- }
- }
-
- cols[col.Name] = col
- colSeq = append(colSeq, col.Name)
- }
- if rows.Err() != nil {
- return nil, nil, rows.Err()
- }
- return colSeq, cols, nil
-}
-
-func (db *mssql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
- args := []interface{}{}
- s := `select name from sysobjects where xtype ='U'`
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- tables := make([]*schemas.Table, 0)
- for rows.Next() {
- table := schemas.NewEmptyTable()
- var name string
- err = rows.Scan(&name)
- if err != nil {
- return nil, err
- }
- table.Name = strings.Trim(name, "` ")
- tables = append(tables, table)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return tables, nil
-}
-
-func (db *mssql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
- args := []interface{}{tableName}
- s := `SELECT
-IXS.NAME AS [INDEX_NAME],
-C.NAME AS [COLUMN_NAME],
-IXS.is_unique AS [IS_UNIQUE]
-FROM SYS.INDEXES IXS
-INNER JOIN SYS.INDEX_COLUMNS IXCS
-ON IXS.OBJECT_ID=IXCS.OBJECT_ID AND IXS.INDEX_ID = IXCS.INDEX_ID
-INNER JOIN SYS.COLUMNS C ON IXS.OBJECT_ID=C.OBJECT_ID
-AND IXCS.COLUMN_ID=C.COLUMN_ID
-WHERE IXS.TYPE_DESC='NONCLUSTERED' and OBJECT_NAME(IXS.OBJECT_ID) =?
-`
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- indexes := make(map[string]*schemas.Index)
- for rows.Next() {
- var indexType int
- var indexName, colName, isUnique string
-
- err = rows.Scan(&indexName, &colName, &isUnique)
- if err != nil {
- return nil, err
- }
-
- i, err := strconv.ParseBool(isUnique)
- if err != nil {
- return nil, err
- }
-
- if i {
- indexType = schemas.UniqueType
- } else {
- indexType = schemas.IndexType
- }
-
- colName = strings.Trim(colName, "` ")
- var isRegular bool
- if (strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName)) && len(indexName) > (5+len(tableName)) {
- indexName = indexName[5+len(tableName):]
- isRegular = true
- }
-
- var index *schemas.Index
- var ok bool
- if index, ok = indexes[indexName]; !ok {
- index = new(schemas.Index)
- index.Type = indexType
- index.Name = indexName
- index.IsRegular = isRegular
- indexes[indexName] = index
- }
- index.AddColumn(colName)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return indexes, nil
-}
-
-func (db *mssql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
- if tableName == "" {
- tableName = table.Name
- }
-
- quoter := db.dialect.Quoter()
- var b strings.Builder
- b.WriteString("IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '")
- quoter.QuoteTo(&b, tableName)
- b.WriteString("' ) CREATE TABLE ")
- quoter.QuoteTo(&b, tableName)
- b.WriteString(" (")
-
- for i, colName := range table.ColumnsSeq() {
- col := table.GetColumn(colName)
- s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
- b.WriteString(s)
-
- if i != len(table.ColumnsSeq())-1 {
- b.WriteString(", ")
- }
- }
-
- if len(table.PrimaryKeys) > 1 {
- b.WriteString(", PRIMARY KEY (")
- b.WriteString(quoter.Join(table.PrimaryKeys, ","))
- b.WriteString(")")
- }
-
- b.WriteString(")")
-
- return []string{b.String()}, true
-}
-
-func (db *mssql) ForUpdateSQL(query string) string {
- return query
-}
-
-func (db *mssql) Filters() []Filter {
- return []Filter{}
-}
-
-type odbcDriver struct {
- baseDriver
-}
-
-func (p *odbcDriver) Features() *DriverFeatures {
- return &DriverFeatures{
- SupportReturnInsertedID: false,
- }
-}
-
-func (p *odbcDriver) Parse(driverName, dataSourceName string) (*URI, error) {
- var dbName string
-
- if strings.HasPrefix(dataSourceName, "sqlserver://") {
- u, err := url.Parse(dataSourceName)
- if err != nil {
- return nil, err
- }
- dbName = u.Query().Get("database")
- } else {
- kv := strings.Split(dataSourceName, ";")
- for _, c := range kv {
- vv := strings.Split(strings.TrimSpace(c), "=")
- if len(vv) == 2 {
- if strings.ToLower(vv[0]) == "database" {
- dbName = vv[1]
- }
- }
- }
- }
- if dbName == "" {
- return nil, errors.New("no db name provided")
- }
- return &URI{DBName: dbName, DBType: schemas.MSSQL}, nil
-}
-
-func (p *odbcDriver) GenScanResult(colType string) (interface{}, error) {
- switch colType {
- case "VARCHAR", "TEXT", "CHAR", "NVARCHAR", "NCHAR", "NTEXT":
- fallthrough
- case "DATE", "DATETIME", "DATETIME2", "TIME":
- var s sql.NullString
- return &s, nil
- case "FLOAT", "REAL":
- var s sql.NullFloat64
- return &s, nil
- case "BIGINT", "DATETIMEOFFSET":
- var s sql.NullInt64
- return &s, nil
- case "TINYINT", "SMALLINT", "INT":
- var s sql.NullInt32
- return &s, nil
-
- default:
- var r sql.RawBytes
- return &r, nil
- }
-}
diff --git a/vendor/xorm.io/xorm/dialects/mysql.go b/vendor/xorm.io/xorm/dialects/mysql.go
deleted file mode 100644
index 0489904ae2..0000000000
--- a/vendor/xorm.io/xorm/dialects/mysql.go
+++ /dev/null
@@ -1,814 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "crypto/tls"
- "database/sql"
- "errors"
- "fmt"
- "regexp"
- "strconv"
- "strings"
- "time"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-var (
- mysqlReservedWords = map[string]bool{
- "ADD": true,
- "ALL": true,
- "ALTER": true,
- "ANALYZE": true,
- "AND": true,
- "AS": true,
- "ASC": true,
- "ASENSITIVE": true,
- "BEFORE": true,
- "BETWEEN": true,
- "BIGINT": true,
- "BINARY": true,
- "BLOB": true,
- "BOTH": true,
- "BY": true,
- "CALL": true,
- "CASCADE": true,
- "CASE": true,
- "CHANGE": true,
- "CHAR": true,
- "CHARACTER": true,
- "CHECK": true,
- "COLLATE": true,
- "COLUMN": true,
- "CONDITION": true,
- "CONNECTION": true,
- "CONSTRAINT": true,
- "CONTINUE": true,
- "CONVERT": true,
- "CREATE": true,
- "CROSS": true,
- "CURRENT_DATE": true,
- "CURRENT_TIME": true,
- "CURRENT_TIMESTAMP": true,
- "CURRENT_USER": true,
- "CURSOR": true,
- "DATABASE": true,
- "DATABASES": true,
- "DAY_HOUR": true,
- "DAY_MICROSECOND": true,
- "DAY_MINUTE": true,
- "DAY_SECOND": true,
- "DEC": true,
- "DECIMAL": true,
- "DECLARE": true,
- "DEFAULT": true,
- "DELAYED": true,
- "DELETE": true,
- "DESC": true,
- "DESCRIBE": true,
- "DETERMINISTIC": true,
- "DISTINCT": true,
- "DISTINCTROW": true,
- "DIV": true,
- "DOUBLE": true,
- "DROP": true,
- "DUAL": true,
- "EACH": true,
- "ELSE": true,
- "ELSEIF": true,
- "ENCLOSED": true,
- "ESCAPED": true,
- "EXISTS": true,
- "EXIT": true,
- "EXPLAIN": true,
- "FALSE": true,
- "FETCH": true,
- "FLOAT": true,
- "FLOAT4": true,
- "FLOAT8": true,
- "FOR": true,
- "FORCE": true,
- "FOREIGN": true,
- "FROM": true,
- "FULLTEXT": true,
- "GOTO": true,
- "GRANT": true,
- "GROUP": true,
- "HAVING": true,
- "HIGH_PRIORITY": true,
- "HOUR_MICROSECOND": true,
- "HOUR_MINUTE": true,
- "HOUR_SECOND": true,
- "IF": true,
- "IGNORE": true,
- "IN": true, "INDEX": true,
- "INFILE": true, "INNER": true, "INOUT": true,
- "INSENSITIVE": true, "INSERT": true, "INT": true,
- "INT1": true, "INT2": true, "INT3": true,
- "INT4": true, "INT8": true, "INTEGER": true,
- "INTERVAL": true, "INTO": true, "IS": true,
- "ITERATE": true, "JOIN": true, "KEY": true,
- "KEYS": true, "KILL": true, "LABEL": true,
- "LEADING": true, "LEAVE": true, "LEFT": true,
- "LIKE": true, "LIMIT": true, "LINEAR": true,
- "LINES": true, "LOAD": true, "LOCALTIME": true,
- "LOCALTIMESTAMP": true, "LOCK": true, "LONG": true,
- "LONGBLOB": true, "LONGTEXT": true, "LOOP": true,
- "LOW_PRIORITY": true, "MATCH": true, "MEDIUMBLOB": true,
- "MEDIUMINT": true, "MEDIUMTEXT": true, "MIDDLEINT": true,
- "MINUTE_MICROSECOND": true, "MINUTE_SECOND": true, "MOD": true,
- "MODIFIES": true, "NATURAL": true, "NOT": true,
- "NO_WRITE_TO_BINLOG": true, "NULL": true, "NUMERIC": true,
- "ON OPTIMIZE": true, "OPTION": true,
- "OPTIONALLY": true, "OR": true, "ORDER": true,
- "OUT": true, "OUTER": true, "OUTFILE": true,
- "PRECISION": true, "PRIMARY": true, "PROCEDURE": true,
- "PURGE": true, "RAID0": true, "RANGE": true,
- "READ": true, "READS": true, "REAL": true,
- "REFERENCES": true, "REGEXP": true, "RELEASE": true,
- "RENAME": true, "REPEAT": true, "REPLACE": true,
- "REQUIRE": true, "RESTRICT": true, "RETURN": true,
- "REVOKE": true, "RIGHT": true, "RLIKE": true,
- "SCHEMA": true, "SCHEMAS": true, "SECOND_MICROSECOND": true,
- "SELECT": true, "SENSITIVE": true, "SEPARATOR": true,
- "SET": true, "SHOW": true, "SMALLINT": true,
- "SPATIAL": true, "SPECIFIC": true, "SQL": true,
- "SQLEXCEPTION": true, "SQLSTATE": true, "SQLWARNING": true,
- "SQL_BIG_RESULT": true, "SQL_CALC_FOUND_ROWS": true, "SQL_SMALL_RESULT": true,
- "SSL": true, "STARTING": true, "STRAIGHT_JOIN": true,
- "TABLE": true, "TERMINATED": true, "THEN": true,
- "TINYBLOB": true, "TINYINT": true, "TINYTEXT": true,
- "TO": true, "TRAILING": true, "TRIGGER": true,
- "TRUE": true, "UNDO": true, "UNION": true,
- "UNIQUE": true, "UNLOCK": true, "UNSIGNED": true,
- "UPDATE": true, "USAGE": true, "USE": true,
- "USING": true, "UTC_DATE": true, "UTC_TIME": true,
- "UTC_TIMESTAMP": true, "VALUES": true, "VARBINARY": true,
- "VARCHAR": true,
- "VARCHARACTER": true,
- "VARYING": true,
- "WHEN": true,
- "WHERE": true,
- "WHILE": true,
- "WITH": true,
- "WRITE": true,
- "X509": true,
- "XOR": true,
- "YEAR_MONTH": true,
- "ZEROFILL": true,
- }
-
- mysqlQuoter = schemas.Quoter{
- Prefix: '`',
- Suffix: '`',
- IsReserved: schemas.AlwaysReserve,
- }
-)
-
-type mysql struct {
- Base
- net string
- addr string
- params map[string]string
- loc *time.Location
- timeout time.Duration
- tls *tls.Config
- allowAllFiles bool
- allowOldPasswords bool
- clientFoundRows bool
- rowFormat string
-}
-
-func (db *mysql) Init(uri *URI) error {
- db.quoter = mysqlQuoter
- return db.Base.Init(db, uri)
-}
-
-var (
- mysqlColAliases = map[string]string{
- "numeric": "decimal",
- }
-)
-
-// Alias returns a alias of column
-func (db *mysql) Alias(col string) string {
- v, ok := mysqlColAliases[strings.ToLower(col)]
- if ok {
- return v
- }
- return col
-}
-
-func (db *mysql) Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) {
- rows, err := queryer.QueryContext(ctx, "SELECT @@VERSION")
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- var version string
- if !rows.Next() {
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return nil, errors.New("unknow version")
- }
-
- if err := rows.Scan(&version); err != nil {
- return nil, err
- }
-
- fields := strings.Split(version, "-")
- if len(fields) == 3 && fields[1] == "TiDB" {
- // 5.7.25-TiDB-v3.0.3
- return &schemas.Version{
- Number: strings.TrimPrefix(fields[2], "v"),
- Level: fields[0],
- Edition: fields[1],
- }, nil
- }
-
- var edition string
- if len(fields) == 2 {
- edition = fields[1]
- }
-
- return &schemas.Version{
- Number: fields[0],
- Edition: edition,
- }, nil
-}
-
-func (db *mysql) SetParams(params map[string]string) {
- rowFormat, ok := params["rowFormat"]
- if ok {
- var t = strings.ToUpper(rowFormat)
- switch t {
- case "COMPACT":
- fallthrough
- case "REDUNDANT":
- fallthrough
- case "DYNAMIC":
- fallthrough
- case "COMPRESSED":
- db.rowFormat = t
- }
- }
-}
-
-func (db *mysql) SQLType(c *schemas.Column) string {
- var res string
- var isUnsigned bool
- switch t := c.SQLType.Name; t {
- case schemas.Bool:
- res = schemas.TinyInt
- c.Length = 1
- case schemas.Serial:
- c.IsAutoIncrement = true
- c.IsPrimaryKey = true
- c.Nullable = false
- res = schemas.Int
- case schemas.BigSerial:
- c.IsAutoIncrement = true
- c.IsPrimaryKey = true
- c.Nullable = false
- res = schemas.BigInt
- case schemas.Bytea:
- res = schemas.Blob
- case schemas.TimeStampz:
- res = schemas.Char
- c.Length = 64
- case schemas.Enum: // mysql enum
- res = schemas.Enum
- res += "("
- opts := ""
- for v := range c.EnumOptions {
- opts += fmt.Sprintf(",'%v'", v)
- }
- res += strings.TrimLeft(opts, ",")
- res += ")"
- case schemas.Set: // mysql set
- res = schemas.Set
- res += "("
- opts := ""
- for v := range c.SetOptions {
- opts += fmt.Sprintf(",'%v'", v)
- }
- res += strings.TrimLeft(opts, ",")
- res += ")"
- case schemas.NVarchar:
- res = schemas.Varchar
- case schemas.Uuid:
- res = schemas.Varchar
- c.Length = 40
- case schemas.Json:
- res = schemas.Text
- case schemas.UnsignedInt:
- res = schemas.Int
- isUnsigned = true
- case schemas.UnsignedBigInt:
- res = schemas.BigInt
- isUnsigned = true
- case schemas.UnsignedMediumInt:
- res = schemas.MediumInt
- isUnsigned = true
- case schemas.UnsignedSmallInt:
- res = schemas.SmallInt
- isUnsigned = true
- case schemas.UnsignedTinyInt:
- res = schemas.TinyInt
- isUnsigned = true
- default:
- res = t
- }
-
- hasLen1 := (c.Length > 0)
- hasLen2 := (c.Length2 > 0)
-
- if res == schemas.BigInt && !hasLen1 && !hasLen2 {
- c.Length = 20
- hasLen1 = true
- }
-
- if hasLen2 {
- res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
- } else if hasLen1 {
- res += "(" + strconv.Itoa(c.Length) + ")"
- }
-
- if isUnsigned {
- res += " UNSIGNED"
- }
-
- return res
-}
-
-func (db *mysql) ColumnTypeKind(t string) int {
- switch strings.ToUpper(t) {
- case "DATETIME":
- return schemas.TIME_TYPE
- case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "ENUM", "SET":
- return schemas.TEXT_TYPE
- case "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INT", "FLOAT", "REAL", "DOUBLE PRECISION", "DECIMAL", "NUMERIC", "BIT":
- return schemas.NUMERIC_TYPE
- case "BINARY", "VARBINARY", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB":
- return schemas.BLOB_TYPE
- default:
- return schemas.UNKNOW_TYPE
- }
-}
-
-func (db *mysql) IsReserved(name string) bool {
- _, ok := mysqlReservedWords[strings.ToUpper(name)]
- return ok
-}
-
-func (db *mysql) AutoIncrStr() string {
- return "AUTO_INCREMENT"
-}
-
-func (db *mysql) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
- args := []interface{}{db.uri.DBName, tableName, idxName}
- sql := "SELECT `INDEX_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS`"
- sql += " WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ? AND `INDEX_NAME`=?"
- return sql, args
-}
-
-func (db *mysql) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
- sql := "SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
- return db.HasRecords(queryer, ctx, sql, db.uri.DBName, tableName)
-}
-
-func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
- quoter := db.dialect.Quoter()
- s, _ := ColumnString(db, col, true)
- sql := fmt.Sprintf("ALTER TABLE %v ADD %v", quoter.Quote(tableName), s)
- if len(col.Comment) > 0 {
- sql += " COMMENT '" + col.Comment + "'"
- }
- return sql
-}
-
-func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
- args := []interface{}{db.uri.DBName, tableName}
- alreadyQuoted := "(INSTR(VERSION(), 'maria') > 0 && " +
- "(SUBSTRING_INDEX(VERSION(), '.', 1) > 10 || " +
- "(SUBSTRING_INDEX(VERSION(), '.', 1) = 10 && " +
- "(SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) > 2 || " +
- "(SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) = 2 && " +
- "SUBSTRING_INDEX(SUBSTRING(VERSION(), 6), '-', 1) >= 7)))))"
- s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
- " `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, " +
- alreadyQuoted + " AS NEEDS_QUOTE " +
- "FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
- " ORDER BY `COLUMNS`.ORDINAL_POSITION"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, nil, err
- }
- defer rows.Close()
-
- cols := make(map[string]*schemas.Column)
- colSeq := make([]string, 0)
- for rows.Next() {
- col := new(schemas.Column)
- col.Indexes = make(map[string]int)
-
- var columnName, nullableStr, colType, colKey, extra, comment string
- var alreadyQuoted, isUnsigned bool
- var colDefault *string
- err = rows.Scan(&columnName, &nullableStr, &colDefault, &colType, &colKey, &extra, &comment, &alreadyQuoted)
- if err != nil {
- return nil, nil, err
- }
- col.Name = strings.Trim(columnName, "` ")
- col.Comment = comment
- if nullableStr == "YES" {
- col.Nullable = true
- }
-
- if colDefault != nil && (!alreadyQuoted || *colDefault != "NULL") {
- col.Default = *colDefault
- col.DefaultIsEmpty = false
- } else {
- col.DefaultIsEmpty = true
- }
-
- fields := strings.Fields(colType)
- if len(fields) == 2 && fields[1] == "unsigned" {
- isUnsigned = true
- }
- colType = fields[0]
- cts := strings.Split(colType, "(")
- colName := cts[0]
- // Remove the /* mariadb-5.3 */ suffix from coltypes
- colName = strings.TrimSuffix(colName, "/* mariadb-5.3 */")
- colType = strings.ToUpper(colName)
- var len1, len2 int
- if len(cts) == 2 {
- idx := strings.Index(cts[1], ")")
- if colType == schemas.Enum && cts[1][0] == '\'' { // enum
- options := strings.Split(cts[1][0:idx], ",")
- col.EnumOptions = make(map[string]int)
- for k, v := range options {
- v = strings.TrimSpace(v)
- v = strings.Trim(v, "'")
- col.EnumOptions[v] = k
- }
- } else if colType == schemas.Set && cts[1][0] == '\'' {
- options := strings.Split(cts[1][0:idx], ",")
- col.SetOptions = make(map[string]int)
- for k, v := range options {
- v = strings.TrimSpace(v)
- v = strings.Trim(v, "'")
- col.SetOptions[v] = k
- }
- } else {
- lens := strings.Split(cts[1][0:idx], ",")
- len1, err = strconv.Atoi(strings.TrimSpace(lens[0]))
- if err != nil {
- return nil, nil, err
- }
- if len(lens) == 2 {
- len2, err = strconv.Atoi(lens[1])
- if err != nil {
- return nil, nil, err
- }
- }
- }
- }
- if isUnsigned {
- colType = "UNSIGNED " + colType
- }
- col.Length = len1
- col.Length2 = len2
- if _, ok := schemas.SqlTypes[colType]; ok {
- col.SQLType = schemas.SQLType{Name: colType, DefaultLength: len1, DefaultLength2: len2}
- } else {
- return nil, nil, fmt.Errorf("Unknown colType %v", colType)
- }
-
- if colKey == "PRI" {
- col.IsPrimaryKey = true
- }
- if colKey == "UNI" {
- // col.is
- }
-
- if extra == "auto_increment" {
- col.IsAutoIncrement = true
- }
-
- if !col.DefaultIsEmpty {
- if !alreadyQuoted && col.SQLType.IsText() {
- col.Default = "'" + col.Default + "'"
- } else if col.SQLType.IsTime() && !alreadyQuoted && col.Default != "CURRENT_TIMESTAMP" {
- col.Default = "'" + col.Default + "'"
- }
- }
- cols[col.Name] = col
- colSeq = append(colSeq, col.Name)
- }
- if rows.Err() != nil {
- return nil, nil, rows.Err()
- }
- return colSeq, cols, nil
-}
-
-func (db *mysql) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
- args := []interface{}{db.uri.DBName}
- s := "SELECT `TABLE_NAME`, `ENGINE`, `AUTO_INCREMENT`, `TABLE_COMMENT` from " +
- "`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- tables := make([]*schemas.Table, 0)
- for rows.Next() {
- table := schemas.NewEmptyTable()
- var name, engine string
- var autoIncr, comment *string
- err = rows.Scan(&name, &engine, &autoIncr, &comment)
- if err != nil {
- return nil, err
- }
-
- table.Name = name
- if comment != nil {
- table.Comment = *comment
- }
- table.StoreEngine = engine
- tables = append(tables, table)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return tables, nil
-}
-
-func (db *mysql) SetQuotePolicy(quotePolicy QuotePolicy) {
- switch quotePolicy {
- case QuotePolicyNone:
- var q = mysqlQuoter
- q.IsReserved = schemas.AlwaysNoReserve
- db.quoter = q
- case QuotePolicyReserved:
- var q = mysqlQuoter
- q.IsReserved = db.IsReserved
- db.quoter = q
- case QuotePolicyAlways:
- fallthrough
- default:
- db.quoter = mysqlQuoter
- }
-}
-
-func (db *mysql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
- args := []interface{}{db.uri.DBName, tableName}
- s := "SELECT `INDEX_NAME`, `NON_UNIQUE`, `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`STATISTICS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- indexes := make(map[string]*schemas.Index)
- for rows.Next() {
- var indexType int
- var indexName, colName, nonUnique string
- err = rows.Scan(&indexName, &nonUnique, &colName)
- if err != nil {
- return nil, err
- }
-
- if indexName == "PRIMARY" {
- continue
- }
-
- if nonUnique == "YES" || nonUnique == "1" {
- indexType = schemas.IndexType
- } else {
- indexType = schemas.UniqueType
- }
-
- colName = strings.Trim(colName, "` ")
- var isRegular bool
- if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
- indexName = indexName[5+len(tableName):]
- isRegular = true
- }
-
- var index *schemas.Index
- var ok bool
- if index, ok = indexes[indexName]; !ok {
- index = new(schemas.Index)
- index.IsRegular = isRegular
- index.Type = indexType
- index.Name = indexName
- indexes[indexName] = index
- }
- index.AddColumn(colName)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return indexes, nil
-}
-
-func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
- if tableName == "" {
- tableName = table.Name
- }
-
- quoter := db.dialect.Quoter()
- var b strings.Builder
- b.WriteString("CREATE TABLE IF NOT EXISTS ")
- quoter.QuoteTo(&b, tableName)
- b.WriteString(" (")
-
- for i, colName := range table.ColumnsSeq() {
- col := table.GetColumn(colName)
- s, _ := ColumnString(db.dialect, col, col.IsPrimaryKey && len(table.PrimaryKeys) == 1)
- b.WriteString(s)
-
- if len(col.Comment) > 0 {
- b.WriteString(" COMMENT '")
- b.WriteString(col.Comment)
- b.WriteString("'")
- }
-
- if i != len(table.ColumnsSeq())-1 {
- b.WriteString(", ")
- }
- }
-
- if len(table.PrimaryKeys) > 1 {
- b.WriteString(", PRIMARY KEY (")
- b.WriteString(quoter.Join(table.PrimaryKeys, ","))
- b.WriteString(")")
- }
-
- b.WriteString(")")
-
- if table.StoreEngine != "" {
- b.WriteString(" ENGINE=")
- b.WriteString(table.StoreEngine)
- }
-
- var charset = table.Charset
- if len(charset) == 0 {
- charset = db.URI().Charset
- }
- if len(charset) != 0 {
- b.WriteString(" DEFAULT CHARSET ")
- b.WriteString(charset)
- }
-
- if db.rowFormat != "" {
- b.WriteString(" ROW_FORMAT=")
- b.WriteString(db.rowFormat)
- }
- return []string{b.String()}, true
-}
-
-func (db *mysql) Filters() []Filter {
- return []Filter{}
-}
-
-type mysqlDriver struct {
- baseDriver
-}
-
-func (p *mysqlDriver) Features() *DriverFeatures {
- return &DriverFeatures{
- SupportReturnInsertedID: true,
- }
-}
-
-func (p *mysqlDriver) Parse(driverName, dataSourceName string) (*URI, error) {
- dsnPattern := regexp.MustCompile(
- `^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
- `(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
- `\/(?P<dbname>.*?)` + // /dbname
- `(?:\?(?P<params>[^\?]*))?$`) // [?param1=value1&paramN=valueN]
- matches := dsnPattern.FindStringSubmatch(dataSourceName)
- // tlsConfigRegister := make(map[string]*tls.Config)
- names := dsnPattern.SubexpNames()
-
- uri := &URI{DBType: schemas.MYSQL}
-
- for i, match := range matches {
- switch names[i] {
- case "dbname":
- uri.DBName = match
- case "params":
- if len(match) > 0 {
- kvs := strings.Split(match, "&")
- for _, kv := range kvs {
- splits := strings.Split(kv, "=")
- if len(splits) == 2 {
- if splits[0] == "charset" {
- uri.Charset = splits[1]
- }
- }
- }
- }
- }
- }
- return uri, nil
-}
-
-func (p *mysqlDriver) GenScanResult(colType string) (interface{}, error) {
- switch colType {
- case "CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "ENUM", "SET":
- var s sql.NullString
- return &s, nil
- case "BIGINT":
- var s sql.NullInt64
- return &s, nil
- case "TINYINT", "SMALLINT", "MEDIUMINT", "INT":
- var s sql.NullInt32
- return &s, nil
- case "FLOAT", "REAL", "DOUBLE PRECISION", "DOUBLE":
- var s sql.NullFloat64
- return &s, nil
- case "DECIMAL", "NUMERIC":
- var s sql.NullString
- return &s, nil
- case "DATETIME", "TIMESTAMP":
- var s sql.NullTime
- return &s, nil
- case "BIT":
- var s sql.RawBytes
- return &s, nil
- case "BINARY", "VARBINARY", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB":
- var r sql.RawBytes
- return &r, nil
- default:
- var r sql.RawBytes
- return &r, nil
- }
-}
-
-type mymysqlDriver struct {
- mysqlDriver
-}
-
-func (p *mymysqlDriver) Parse(driverName, dataSourceName string) (*URI, error) {
- uri := &URI{DBType: schemas.MYSQL}
-
- pd := strings.SplitN(dataSourceName, "*", 2)
- if len(pd) == 2 {
- // Parse protocol part of URI
- p := strings.SplitN(pd[0], ":", 2)
- if len(p) != 2 {
- return nil, errors.New("Wrong protocol part of URI")
- }
- uri.Proto = p[0]
- options := strings.Split(p[1], ",")
- uri.Raddr = options[0]
- for _, o := range options[1:] {
- kv := strings.SplitN(o, "=", 2)
- var k, v string
- if len(kv) == 2 {
- k, v = kv[0], kv[1]
- } else {
- k, v = o, "true"
- }
- switch k {
- case "laddr":
- uri.Laddr = v
- case "timeout":
- to, err := time.ParseDuration(v)
- if err != nil {
- return nil, err
- }
- uri.Timeout = to
- default:
- return nil, errors.New("Unknown option: " + k)
- }
- }
- // Remove protocol part
- pd = pd[1:]
- }
- // Parse database part of URI
- dup := strings.SplitN(pd[0], "/", 3)
- if len(dup) != 3 {
- return nil, errors.New("Wrong database part of URI")
- }
- uri.DBName = dup[0]
- uri.User = dup[1]
- uri.Passwd = dup[2]
-
- return uri, nil
-}
diff --git a/vendor/xorm.io/xorm/dialects/oracle.go b/vendor/xorm.io/xorm/dialects/oracle.go
deleted file mode 100644
index 11a6653b1b..0000000000
--- a/vendor/xorm.io/xorm/dialects/oracle.go
+++ /dev/null
@@ -1,928 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "database/sql"
- "errors"
- "fmt"
- "regexp"
- "strconv"
- "strings"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-var (
- oracleReservedWords = map[string]bool{
- "ACCESS": true,
- "ACCOUNT": true,
- "ACTIVATE": true,
- "ADD": true,
- "ADMIN": true,
- "ADVISE": true,
- "AFTER": true,
- "ALL": true,
- "ALL_ROWS": true,
- "ALLOCATE": true,
- "ALTER": true,
- "ANALYZE": true,
- "AND": true,
- "ANY": true,
- "ARCHIVE": true,
- "ARCHIVELOG": true,
- "ARRAY": true,
- "AS": true,
- "ASC": true,
- "AT": true,
- "AUDIT": true,
- "AUTHENTICATED": true,
- "AUTHORIZATION": true,
- "AUTOEXTEND": true,
- "AUTOMATIC": true,
- "BACKUP": true,
- "BECOME": true,
- "BEFORE": true,
- "BEGIN": true,
- "BETWEEN": true,
- "BFILE": true,
- "BITMAP": true,
- "BLOB": true,
- "BLOCK": true,
- "BODY": true,
- "BY": true,
- "CACHE": true,
- "CACHE_INSTANCES": true,
- "CANCEL": true,
- "CASCADE": true,
- "CAST": true,
- "CFILE": true,
- "CHAINED": true,
- "CHANGE": true,
- "CHAR": true,
- "CHAR_CS": true,
- "CHARACTER": true,
- "CHECK": true,
- "CHECKPOINT": true,
- "CHOOSE": true,
- "CHUNK": true,
- "CLEAR": true,
- "CLOB": true,
- "CLONE": true,
- "CLOSE": true,
- "CLOSE_CACHED_OPEN_CURSORS": true,
- "CLUSTER": true,
- "COALESCE": true,
- "COLUMN": true,
- "COLUMNS": true,
- "COMMENT": true,
- "COMMIT": true,
- "COMMITTED": true,
- "COMPATIBILITY": true,
- "COMPILE": true,
- "COMPLETE": true,
- "COMPOSITE_LIMIT": true,
- "COMPRESS": true,
- "COMPUTE": true,
- "CONNECT": true,
- "CONNECT_TIME": true,
- "CONSTRAINT": true,
- "CONSTRAINTS": true,
- "CONTENTS": true,
- "CONTINUE": true,
- "CONTROLFILE": true,
- "CONVERT": true,
- "COST": true,
- "CPU_PER_CALL": true,
- "CPU_PER_SESSION": true,
- "CREATE": true,
- "CURRENT": true,
- "CURRENT_SCHEMA": true,
- "CURREN_USER": true,
- "CURSOR": true,
- "CYCLE": true,
- "DANGLING": true,
- "DATABASE": true,
- "DATAFILE": true,
- "DATAFILES": true,
- "DATAOBJNO": true,
- "DATE": true,
- "DBA": true,
- "DBHIGH": true,
- "DBLOW": true,
- "DBMAC": true,
- "DEALLOCATE": true,
- "DEBUG": true,
- "DEC": true,
- "DECIMAL": true,
- "DECLARE": true,
- "DEFAULT": true,
- "DEFERRABLE": true,
- "DEFERRED": true,
- "DEGREE": true,
- "DELETE": true,
- "DEREF": true,
- "DESC": true,
- "DIRECTORY": true,
- "DISABLE": true,
- "DISCONNECT": true,
- "DISMOUNT": true,
- "DISTINCT": true,
- "DISTRIBUTED": true,
- "DML": true,
- "DOUBLE": true,
- "DROP": true,
- "DUMP": true,
- "EACH": true,
- "ELSE": true,
- "ENABLE": true,
- "END": true,
- "ENFORCE": true,
- "ENTRY": true,
- "ESCAPE": true,
- "EXCEPT": true,
- "EXCEPTIONS": true,
- "EXCHANGE": true,
- "EXCLUDING": true,
- "EXCLUSIVE": true,
- "EXECUTE": true,
- "EXISTS": true,
- "EXPIRE": true,
- "EXPLAIN": true,
- "EXTENT": true,
- "EXTENTS": true,
- "EXTERNALLY": true,
- "FAILED_LOGIN_ATTEMPTS": true,
- "FALSE": true,
- "FAST": true,
- "FILE": true,
- "FIRST_ROWS": true,
- "FLAGGER": true,
- "FLOAT": true,
- "FLOB": true,
- "FLUSH": true,
- "FOR": true,
- "FORCE": true,
- "FOREIGN": true,
- "FREELIST": true,
- "FREELISTS": true,
- "FROM": true,
- "FULL": true,
- "FUNCTION": true,
- "GLOBAL": true,
- "GLOBALLY": true,
- "GLOBAL_NAME": true,
- "GRANT": true,
- "GROUP": true,
- "GROUPS": true,
- "HASH": true,
- "HASHKEYS": true,
- "HAVING": true,
- "HEADER": true,
- "HEAP": true,
- "IDENTIFIED": true,
- "IDGENERATORS": true,
- "IDLE_TIME": true,
- "IF": true,
- "IMMEDIATE": true,
- "IN": true,
- "INCLUDING": true,
- "INCREMENT": true,
- "INDEX": true,
- "INDEXED": true,
- "INDEXES": true,
- "INDICATOR": true,
- "IND_PARTITION": true,
- "INITIAL": true,
- "INITIALLY": true,
- "INITRANS": true,
- "INSERT": true,
- "INSTANCE": true,
- "INSTANCES": true,
- "INSTEAD": true,
- "INT": true,
- "INTEGER": true,
- "INTERMEDIATE": true,
- "INTERSECT": true,
- "INTO": true,
- "IS": true,
- "ISOLATION": true,
- "ISOLATION_LEVEL": true,
- "KEEP": true,
- "KEY": true,
- "KILL": true,
- "LABEL": true,
- "LAYER": true,
- "LESS": true,
- "LEVEL": true,
- "LIBRARY": true,
- "LIKE": true,
- "LIMIT": true,
- "LINK": true,
- "LIST": true,
- "LOB": true,
- "LOCAL": true,
- "LOCK": true,
- "LOCKED": true,
- "LOG": true,
- "LOGFILE": true,
- "LOGGING": true,
- "LOGICAL_READS_PER_CALL": true,
- "LOGICAL_READS_PER_SESSION": true,
- "LONG": true,
- "MANAGE": true,
- "MASTER": true,
- "MAX": true,
- "MAXARCHLOGS": true,
- "MAXDATAFILES": true,
- "MAXEXTENTS": true,
- "MAXINSTANCES": true,
- "MAXLOGFILES": true,
- "MAXLOGHISTORY": true,
- "MAXLOGMEMBERS": true,
- "MAXSIZE": true,
- "MAXTRANS": true,
- "MAXVALUE": true,
- "MIN": true,
- "MEMBER": true,
- "MINIMUM": true,
- "MINEXTENTS": true,
- "MINUS": true,
- "MINVALUE": true,
- "MLSLABEL": true,
- "MLS_LABEL_FORMAT": true,
- "MODE": true,
- "MODIFY": true,
- "MOUNT": true,
- "MOVE": true,
- "MTS_DISPATCHERS": true,
- "MULTISET": true,
- "NATIONAL": true,
- "NCHAR": true,
- "NCHAR_CS": true,
- "NCLOB": true,
- "NEEDED": true,
- "NESTED": true,
- "NETWORK": true,
- "NEW": true,
- "NEXT": true,
- "NOARCHIVELOG": true,
- "NOAUDIT": true,
- "NOCACHE": true,
- "NOCOMPRESS": true,
- "NOCYCLE": true,
- "NOFORCE": true,
- "NOLOGGING": true,
- "NOMAXVALUE": true,
- "NOMINVALUE": true,
- "NONE": true,
- "NOORDER": true,
- "NOOVERRIDE": true,
- "NOPARALLEL": true,
- "NOREVERSE": true,
- "NORMAL": true,
- "NOSORT": true,
- "NOT": true,
- "NOTHING": true,
- "NOWAIT": true,
- "NULL": true,
- "NUMBER": true,
- "NUMERIC": true,
- "NVARCHAR2": true,
- "OBJECT": true,
- "OBJNO": true,
- "OBJNO_REUSE": true,
- "OF": true,
- "OFF": true,
- "OFFLINE": true,
- "OID": true,
- "OIDINDEX": true,
- "OLD": true,
- "ON": true,
- "ONLINE": true,
- "ONLY": true,
- "OPCODE": true,
- "OPEN": true,
- "OPTIMAL": true,
- "OPTIMIZER_GOAL": true,
- "OPTION": true,
- "OR": true,
- "ORDER": true,
- "ORGANIZATION": true,
- "OSLABEL": true,
- "OVERFLOW": true,
- "OWN": true,
- "PACKAGE": true,
- "PARALLEL": true,
- "PARTITION": true,
- "PASSWORD": true,
- "PASSWORD_GRACE_TIME": true,
- "PASSWORD_LIFE_TIME": true,
- "PASSWORD_LOCK_TIME": true,
- "PASSWORD_REUSE_MAX": true,
- "PASSWORD_REUSE_TIME": true,
- "PASSWORD_VERIFY_FUNCTION": true,
- "PCTFREE": true,
- "PCTINCREASE": true,
- "PCTTHRESHOLD": true,
- "PCTUSED": true,
- "PCTVERSION": true,
- "PERCENT": true,
- "PERMANENT": true,
- "PLAN": true,
- "PLSQL_DEBUG": true,
- "POST_TRANSACTION": true,
- "PRECISION": true,
- "PRESERVE": true,
- "PRIMARY": true,
- "PRIOR": true,
- "PRIVATE": true,
- "PRIVATE_SGA": true,
- "PRIVILEGE": true,
- "PRIVILEGES": true,
- "PROCEDURE": true,
- "PROFILE": true,
- "PUBLIC": true,
- "PURGE": true,
- "QUEUE": true,
- "QUOTA": true,
- "RANGE": true,
- "RAW": true,
- "RBA": true,
- "READ": true,
- "READUP": true,
- "REAL": true,
- "REBUILD": true,
- "RECOVER": true,
- "RECOVERABLE": true,
- "RECOVERY": true,
- "REF": true,
- "REFERENCES": true,
- "REFERENCING": true,
- "REFRESH": true,
- "RENAME": true,
- "REPLACE": true,
- "RESET": true,
- "RESETLOGS": true,
- "RESIZE": true,
- "RESOURCE": true,
- "RESTRICTED": true,
- "RETURN": true,
- "RETURNING": true,
- "REUSE": true,
- "REVERSE": true,
- "REVOKE": true,
- "ROLE": true,
- "ROLES": true,
- "ROLLBACK": true,
- "ROW": true,
- "ROWID": true,
- "ROWNUM": true,
- "ROWS": true,
- "RULE": true,
- "SAMPLE": true,
- "SAVEPOINT": true,
- "SB4": true,
- "SCAN_INSTANCES": true,
- "SCHEMA": true,
- "SCN": true,
- "SCOPE": true,
- "SD_ALL": true,
- "SD_INHIBIT": true,
- "SD_SHOW": true,
- "SEGMENT": true,
- "SEG_BLOCK": true,
- "SEG_FILE": true,
- "SELECT": true,
- "SEQUENCE": true,
- "SERIALIZABLE": true,
- "SESSION": true,
- "SESSION_CACHED_CURSORS": true,
- "SESSIONS_PER_USER": true,
- "SET": true,
- "SHARE": true,
- "SHARED": true,
- "SHARED_POOL": true,
- "SHRINK": true,
- "SIZE": true,
- "SKIP": true,
- "SKIP_UNUSABLE_INDEXES": true,
- "SMALLINT": true,
- "SNAPSHOT": true,
- "SOME": true,
- "SORT": true,
- "SPECIFICATION": true,
- "SPLIT": true,
- "SQL_TRACE": true,
- "STANDBY": true,
- "START": true,
- "STATEMENT_ID": true,
- "STATISTICS": true,
- "STOP": true,
- "STORAGE": true,
- "STORE": true,
- "STRUCTURE": true,
- "SUCCESSFUL": true,
- "SWITCH": true,
- "SYS_OP_ENFORCE_NOT_NULL$": true,
- "SYS_OP_NTCIMG$": true,
- "SYNONYM": true,
- "SYSDATE": true,
- "SYSDBA": true,
- "SYSOPER": true,
- "SYSTEM": true,
- "TABLE": true,
- "TABLES": true,
- "TABLESPACE": true,
- "TABLESPACE_NO": true,
- "TABNO": true,
- "TEMPORARY": true,
- "THAN": true,
- "THE": true,
- "THEN": true,
- "THREAD": true,
- "TIMESTAMP": true,
- "TIME": true,
- "TO": true,
- "TOPLEVEL": true,
- "TRACE": true,
- "TRACING": true,
- "TRANSACTION": true,
- "TRANSITIONAL": true,
- "TRIGGER": true,
- "TRIGGERS": true,
- "TRUE": true,
- "TRUNCATE": true,
- "TX": true,
- "TYPE": true,
- "UB2": true,
- "UBA": true,
- "UID": true,
- "UNARCHIVED": true,
- "UNDO": true,
- "UNION": true,
- "UNIQUE": true,
- "UNLIMITED": true,
- "UNLOCK": true,
- "UNRECOVERABLE": true,
- "UNTIL": true,
- "UNUSABLE": true,
- "UNUSED": true,
- "UPDATABLE": true,
- "UPDATE": true,
- "USAGE": true,
- "USE": true,
- "USER": true,
- "USING": true,
- "VALIDATE": true,
- "VALIDATION": true,
- "VALUE": true,
- "VALUES": true,
- "VARCHAR": true,
- "VARCHAR2": true,
- "VARYING": true,
- "VIEW": true,
- "WHEN": true,
- "WHENEVER": true,
- "WHERE": true,
- "WITH": true,
- "WITHOUT": true,
- "WORK": true,
- "WRITE": true,
- "WRITEDOWN": true,
- "WRITEUP": true,
- "XID": true,
- "YEAR": true,
- "ZONE": true,
- }
-
- oracleQuoter = schemas.Quoter{
- Prefix: '"',
- Suffix: '"',
- IsReserved: schemas.AlwaysReserve,
- }
-)
-
-type oracle struct {
- Base
-}
-
-func (db *oracle) Init(uri *URI) error {
- db.quoter = oracleQuoter
- return db.Base.Init(db, uri)
-}
-
-func (db *oracle) Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) {
- rows, err := queryer.QueryContext(ctx, "select * from v$version where banner like 'Oracle%'")
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- var version string
- if !rows.Next() {
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return nil, errors.New("unknow version")
- }
-
- if err := rows.Scan(&version); err != nil {
- return nil, err
- }
- return &schemas.Version{
- Number: version,
- }, nil
-}
-
-func (db *oracle) SQLType(c *schemas.Column) string {
- var res string
- switch t := c.SQLType.Name; t {
- case schemas.Bit, schemas.TinyInt, schemas.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt, schemas.Bool, schemas.Serial, schemas.BigSerial:
- res = "NUMBER"
- case schemas.Binary, schemas.VarBinary, schemas.Blob, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob, schemas.Bytea:
- return schemas.Blob
- case schemas.Time, schemas.DateTime, schemas.TimeStamp:
- res = schemas.TimeStamp
- case schemas.TimeStampz:
- res = "TIMESTAMP WITH TIME ZONE"
- case schemas.Float, schemas.Double, schemas.Numeric, schemas.Decimal:
- res = "NUMBER"
- case schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json:
- res = "CLOB"
- case schemas.Char, schemas.Varchar, schemas.TinyText:
- res = "VARCHAR2"
- default:
- res = t
- }
-
- hasLen1 := (c.Length > 0)
- hasLen2 := (c.Length2 > 0)
-
- if hasLen2 {
- res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
- } else if hasLen1 {
- res += "(" + strconv.Itoa(c.Length) + ")"
- }
- return res
-}
-
-func (db *oracle) ColumnTypeKind(t string) int {
- switch strings.ToUpper(t) {
- case "DATE":
- return schemas.TIME_TYPE
- case "CHAR", "NCHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "LONG", "CLOB", "NCLOB":
- return schemas.TEXT_TYPE
- case "NUMBER":
- return schemas.NUMERIC_TYPE
- case "BLOB":
- return schemas.BLOB_TYPE
- default:
- return schemas.UNKNOW_TYPE
- }
-}
-
-func (db *oracle) AutoIncrStr() string {
- return "AUTO_INCREMENT"
-}
-
-func (db *oracle) IsReserved(name string) bool {
- _, ok := oracleReservedWords[strings.ToUpper(name)]
- return ok
-}
-
-func (db *oracle) DropTableSQL(tableName string) (string, bool) {
- return fmt.Sprintf("DROP TABLE `%s`", tableName), false
-}
-
-func (db *oracle) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
- var sql = "CREATE TABLE "
- if tableName == "" {
- tableName = table.Name
- }
-
- quoter := db.Quoter()
- sql += quoter.Quote(tableName) + " ("
-
- pkList := table.PrimaryKeys
-
- for _, colName := range table.ColumnsSeq() {
- col := table.GetColumn(colName)
- /*if col.IsPrimaryKey && len(pkList) == 1 {
- sql += col.String(b.dialect)
- } else {*/
- s, _ := ColumnString(db, col, false)
- sql += s
- // }
- sql = strings.TrimSpace(sql)
- sql += ", "
- }
-
- if len(pkList) > 0 {
- sql += "PRIMARY KEY ( "
- sql += quoter.Join(pkList, ",")
- sql += " ), "
- }
-
- sql = sql[:len(sql)-2] + ")"
- return []string{sql}, false
-}
-
-func (db *oracle) SetQuotePolicy(quotePolicy QuotePolicy) {
- switch quotePolicy {
- case QuotePolicyNone:
- var q = oracleQuoter
- q.IsReserved = schemas.AlwaysNoReserve
- db.quoter = q
- case QuotePolicyReserved:
- var q = oracleQuoter
- q.IsReserved = db.IsReserved
- db.quoter = q
- case QuotePolicyAlways:
- fallthrough
- default:
- db.quoter = oracleQuoter
- }
-}
-
-func (db *oracle) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
- args := []interface{}{tableName, idxName}
- return `SELECT INDEX_NAME FROM USER_INDEXES ` +
- `WHERE TABLE_NAME = :1 AND INDEX_NAME = :2`, args
-}
-
-func (db *oracle) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
- return db.HasRecords(queryer, ctx, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
-}
-
-func (db *oracle) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
- args := []interface{}{tableName, colName}
- query := "SELECT column_name FROM USER_TAB_COLUMNS WHERE table_name = :1" +
- " AND column_name = :2"
- return db.HasRecords(queryer, ctx, query, args...)
-}
-
-func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
- args := []interface{}{tableName}
- s := "SELECT column_name,data_default,data_type,data_length,data_precision,data_scale," +
- "nullable FROM USER_TAB_COLUMNS WHERE table_name = :1"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, nil, err
- }
- defer rows.Close()
-
- cols := make(map[string]*schemas.Column)
- colSeq := make([]string, 0)
- for rows.Next() {
- col := new(schemas.Column)
- col.Indexes = make(map[string]int)
-
- var colName, colDefault, nullable, dataType, dataPrecision, dataScale *string
- var dataLen int
-
- err = rows.Scan(&colName, &colDefault, &dataType, &dataLen, &dataPrecision,
- &dataScale, &nullable)
- if err != nil {
- return nil, nil, err
- }
-
- col.Name = strings.Trim(*colName, `" `)
- if colDefault != nil {
- col.Default = *colDefault
- col.DefaultIsEmpty = false
- }
-
- if *nullable == "Y" {
- col.Nullable = true
- } else {
- col.Nullable = false
- }
-
- var ignore bool
-
- var dt string
- var len1, len2 int
- dts := strings.Split(*dataType, "(")
- dt = dts[0]
- if len(dts) > 1 {
- lens := strings.Split(dts[1][:len(dts[1])-1], ",")
- if len(lens) > 1 {
- len1, _ = strconv.Atoi(lens[0])
- len2, _ = strconv.Atoi(lens[1])
- } else {
- len1, _ = strconv.Atoi(lens[0])
- }
- }
-
- switch dt {
- case "VARCHAR2":
- col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: len1, DefaultLength2: len2}
- case "NVARCHAR2":
- col.SQLType = schemas.SQLType{Name: schemas.NVarchar, DefaultLength: len1, DefaultLength2: len2}
- case "TIMESTAMP WITH TIME ZONE":
- col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
- case "NUMBER":
- col.SQLType = schemas.SQLType{Name: schemas.Double, DefaultLength: len1, DefaultLength2: len2}
- case "LONG", "LONG RAW":
- col.SQLType = schemas.SQLType{Name: schemas.Text, DefaultLength: 0, DefaultLength2: 0}
- case "RAW":
- col.SQLType = schemas.SQLType{Name: schemas.Binary, DefaultLength: 0, DefaultLength2: 0}
- case "ROWID":
- col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 18, DefaultLength2: 0}
- case "AQ$_SUBSCRIBERS":
- ignore = true
- default:
- col.SQLType = schemas.SQLType{Name: strings.ToUpper(dt), DefaultLength: len1, DefaultLength2: len2}
- }
-
- if ignore {
- continue
- }
-
- if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok {
- return nil, nil, fmt.Errorf("Unknown colType %v %v", *dataType, col.SQLType)
- }
-
- col.Length = dataLen
-
- if col.SQLType.IsText() || col.SQLType.IsTime() {
- if !col.DefaultIsEmpty {
- col.Default = "'" + col.Default + "'"
- }
- }
- cols[col.Name] = col
- colSeq = append(colSeq, col.Name)
- }
- if rows.Err() != nil {
- return nil, nil, rows.Err()
- }
-
- return colSeq, cols, nil
-}
-
-func (db *oracle) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
- args := []interface{}{}
- s := "SELECT table_name FROM user_tables"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- tables := make([]*schemas.Table, 0)
- for rows.Next() {
- table := schemas.NewEmptyTable()
- err = rows.Scan(&table.Name)
- if err != nil {
- return nil, err
- }
-
- tables = append(tables, table)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return tables, nil
-}
-
-func (db *oracle) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
- args := []interface{}{tableName}
- s := "SELECT t.column_name,i.uniqueness,i.index_name FROM user_ind_columns t,user_indexes i " +
- "WHERE t.index_name = i.index_name and t.table_name = i.table_name and t.table_name =:1"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- indexes := make(map[string]*schemas.Index)
- for rows.Next() {
- var indexType int
- var indexName, colName, uniqueness string
-
- err = rows.Scan(&colName, &uniqueness, &indexName)
- if err != nil {
- return nil, err
- }
-
- indexName = strings.Trim(indexName, `" `)
-
- var isRegular bool
- if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
- indexName = indexName[5+len(tableName):]
- isRegular = true
- }
-
- if uniqueness == "UNIQUE" {
- indexType = schemas.UniqueType
- } else {
- indexType = schemas.IndexType
- }
-
- var index *schemas.Index
- var ok bool
- if index, ok = indexes[indexName]; !ok {
- index = new(schemas.Index)
- index.Type = indexType
- index.Name = indexName
- index.IsRegular = isRegular
- indexes[indexName] = index
- }
- index.AddColumn(colName)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return indexes, nil
-}
-
-func (db *oracle) Filters() []Filter {
- return []Filter{
- &SeqFilter{Prefix: ":", Start: 1},
- }
-}
-
-type godrorDriver struct {
- baseDriver
-}
-
-func (g *godrorDriver) Features() *DriverFeatures {
- return &DriverFeatures{
- SupportReturnInsertedID: false,
- }
-}
-
-func (g *godrorDriver) Parse(driverName, dataSourceName string) (*URI, error) {
- db := &URI{DBType: schemas.ORACLE}
- dsnPattern := regexp.MustCompile(
- `^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
- `(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
- `\/(?P<dbname>.*?)` + // /dbname
- `(?:\?(?P<params>[^\?]*))?$`) // [?param1=value1&paramN=valueN]
- matches := dsnPattern.FindStringSubmatch(dataSourceName)
- // tlsConfigRegister := make(map[string]*tls.Config)
- names := dsnPattern.SubexpNames()
-
- for i, match := range matches {
- if names[i] == "dbname" {
- db.DBName = match
- }
- }
- if db.DBName == "" {
- return nil, errors.New("dbname is empty")
- }
- return db, nil
-}
-
-func (g *godrorDriver) GenScanResult(colType string) (interface{}, error) {
- switch colType {
- case "CHAR", "NCHAR", "VARCHAR", "VARCHAR2", "NVARCHAR2", "LONG", "CLOB", "NCLOB":
- var s sql.NullString
- return &s, nil
- case "NUMBER":
- var s sql.NullString
- return &s, nil
- case "DATE":
- var s sql.NullTime
- return &s, nil
- case "BLOB":
- var r sql.RawBytes
- return &r, nil
- default:
- var r sql.RawBytes
- return &r, nil
- }
-}
-
-type oci8Driver struct {
- godrorDriver
-}
-
-// dataSourceName=user/password@ipv4:port/dbname
-// dataSourceName=user/password@[ipv6]:port/dbname
-func (o *oci8Driver) Parse(driverName, dataSourceName string) (*URI, error) {
- db := &URI{DBType: schemas.ORACLE}
- dsnPattern := regexp.MustCompile(
- `^(?P<user>.*)\/(?P<password>.*)@` + // user:password@
- `(?P<net>.*)` + // ip:port
- `\/(?P<dbname>.*)`) // dbname
- matches := dsnPattern.FindStringSubmatch(dataSourceName)
- names := dsnPattern.SubexpNames()
- for i, match := range matches {
- if names[i] == "dbname" {
- db.DBName = match
- }
- }
- if db.DBName == "" && len(matches) != 0 {
- return nil, errors.New("dbname is empty")
- }
- return db, nil
-}
diff --git a/vendor/xorm.io/xorm/dialects/pg_reserved.txt b/vendor/xorm.io/xorm/dialects/pg_reserved.txt
deleted file mode 100644
index 720ed377ba..0000000000
--- a/vendor/xorm.io/xorm/dialects/pg_reserved.txt
+++ /dev/null
@@ -1,746 +0,0 @@
-A non-reserved non-reserved
-ABORT non-reserved
-ABS reserved reserved
-ABSENT non-reserved non-reserved
-ABSOLUTE non-reserved non-reserved non-reserved reserved
-ACCESS non-reserved
-ACCORDING non-reserved non-reserved
-ACTION non-reserved non-reserved non-reserved reserved
-ADA non-reserved non-reserved non-reserved
-ADD non-reserved non-reserved non-reserved reserved
-ADMIN non-reserved non-reserved non-reserved
-AFTER non-reserved non-reserved non-reserved
-AGGREGATE non-reserved
-ALL reserved reserved reserved reserved
-ALLOCATE reserved reserved reserved
-ALSO non-reserved
-ALTER non-reserved reserved reserved reserved
-ALWAYS non-reserved non-reserved non-reserved
-ANALYSE reserved
-ANALYZE reserved
-AND reserved reserved reserved reserved
-ANY reserved reserved reserved reserved
-ARE reserved reserved reserved
-ARRAY reserved reserved reserved
-ARRAY_AGG reserved reserved
-ARRAY_MAX_CARDINALITY reserved
-AS reserved reserved reserved reserved
-ASC reserved non-reserved non-reserved reserved
-ASENSITIVE reserved reserved
-ASSERTION non-reserved non-reserved non-reserved reserved
-ASSIGNMENT non-reserved non-reserved non-reserved
-ASYMMETRIC reserved reserved reserved
-AT non-reserved reserved reserved reserved
-ATOMIC reserved reserved
-ATTRIBUTE non-reserved non-reserved non-reserved
-ATTRIBUTES non-reserved non-reserved
-AUTHORIZATION reserved (can be function or type) reserved reserved reserved
-AVG reserved reserved reserved
-BACKWARD non-reserved
-BASE64 non-reserved non-reserved
-BEFORE non-reserved non-reserved non-reserved
-BEGIN non-reserved reserved reserved reserved
-BEGIN_FRAME reserved
-BEGIN_PARTITION reserved
-BERNOULLI non-reserved non-reserved
-BETWEEN non-reserved (cannot be function or type) reserved reserved reserved
-BIGINT non-reserved (cannot be function or type) reserved reserved
-BINARY reserved (can be function or type) reserved reserved
-BIT non-reserved (cannot be function or type) reserved
-BIT_LENGTH reserved
-BLOB reserved reserved
-BLOCKED non-reserved non-reserved
-BOM non-reserved non-reserved
-BOOLEAN non-reserved (cannot be function or type) reserved reserved
-BOTH reserved reserved reserved reserved
-BREADTH non-reserved non-reserved
-BY non-reserved reserved reserved reserved
-C non-reserved non-reserved non-reserved
-CACHE non-reserved
-CALL reserved reserved
-CALLED non-reserved reserved reserved
-CARDINALITY reserved reserved
-CASCADE non-reserved non-reserved non-reserved reserved
-CASCADED non-reserved reserved reserved reserved
-CASE reserved reserved reserved reserved
-CAST reserved reserved reserved reserved
-CATALOG non-reserved non-reserved non-reserved reserved
-CATALOG_NAME non-reserved non-reserved non-reserved
-CEIL reserved reserved
-CEILING reserved reserved
-CHAIN non-reserved non-reserved non-reserved
-CHAR non-reserved (cannot be function or type) reserved reserved reserved
-CHARACTER non-reserved (cannot be function or type) reserved reserved reserved
-CHARACTERISTICS non-reserved non-reserved non-reserved
-CHARACTERS non-reserved non-reserved
-CHARACTER_LENGTH reserved reserved reserved
-CHARACTER_SET_CATALOG non-reserved non-reserved non-reserved
-CHARACTER_SET_NAME non-reserved non-reserved non-reserved
-CHARACTER_SET_SCHEMA non-reserved non-reserved non-reserved
-CHAR_LENGTH reserved reserved reserved
-CHECK reserved reserved reserved reserved
-CHECKPOINT non-reserved
-CLASS non-reserved
-CLASS_ORIGIN non-reserved non-reserved non-reserved
-CLOB reserved reserved
-CLOSE non-reserved reserved reserved reserved
-CLUSTER non-reserved
-COALESCE non-reserved (cannot be function or type) reserved reserved reserved
-COBOL non-reserved non-reserved non-reserved
-COLLATE reserved reserved reserved reserved
-COLLATION reserved (can be function or type) non-reserved non-reserved reserved
-COLLATION_CATALOG non-reserved non-reserved non-reserved
-COLLATION_NAME non-reserved non-reserved non-reserved
-COLLATION_SCHEMA non-reserved non-reserved non-reserved
-COLLECT reserved reserved
-COLUMN reserved reserved reserved reserved
-COLUMNS non-reserved non-reserved
-COLUMN_NAME non-reserved non-reserved non-reserved
-COMMAND_FUNCTION non-reserved non-reserved non-reserved
-COMMAND_FUNCTION_CODE non-reserved non-reserved
-COMMENT non-reserved
-COMMENTS non-reserved
-COMMIT non-reserved reserved reserved reserved
-COMMITTED non-reserved non-reserved non-reserved non-reserved
-CONCURRENTLY reserved (can be function or type)
-CONDITION reserved reserved
-CONDITION_NUMBER non-reserved non-reserved non-reserved
-CONFIGURATION non-reserved
-CONNECT reserved reserved reserved
-CONNECTION non-reserved non-reserved non-reserved reserved
-CONNECTION_NAME non-reserved non-reserved non-reserved
-CONSTRAINT reserved reserved reserved reserved
-CONSTRAINTS non-reserved non-reserved non-reserved reserved
-CONSTRAINT_CATALOG non-reserved non-reserved non-reserved
-CONSTRAINT_NAME non-reserved non-reserved non-reserved
-CONSTRAINT_SCHEMA non-reserved non-reserved non-reserved
-CONSTRUCTOR non-reserved non-reserved
-CONTAINS reserved non-reserved
-CONTENT non-reserved non-reserved non-reserved
-CONTINUE non-reserved non-reserved non-reserved reserved
-CONTROL non-reserved non-reserved
-CONVERSION non-reserved
-CONVERT reserved reserved reserved
-COPY non-reserved
-CORR reserved reserved
-CORRESPONDING reserved reserved reserved
-COST non-reserved
-COUNT reserved reserved reserved
-COVAR_POP reserved reserved
-COVAR_SAMP reserved reserved
-CREATE reserved reserved reserved reserved
-CROSS reserved (can be function or type) reserved reserved reserved
-CSV non-reserved
-CUBE reserved reserved
-CUME_DIST reserved reserved
-CURRENT non-reserved reserved reserved reserved
-CURRENT_CATALOG reserved reserved reserved
-CURRENT_DATE reserved reserved reserved reserved
-CURRENT_DEFAULT_TRANSFORM_GROUP reserved reserved
-CURRENT_PATH reserved reserved
-CURRENT_ROLE reserved reserved reserved
-CURRENT_ROW reserved
-CURRENT_SCHEMA reserved (can be function or type) reserved reserved
-CURRENT_TIME reserved reserved reserved reserved
-CURRENT_TIMESTAMP reserved reserved reserved reserved
-CURRENT_TRANSFORM_GROUP_FOR_TYPE reserved reserved
-CURRENT_USER reserved reserved reserved reserved
-CURSOR non-reserved reserved reserved reserved
-CURSOR_NAME non-reserved non-reserved non-reserved
-CYCLE non-reserved reserved reserved
-DATA non-reserved non-reserved non-reserved non-reserved
-DATABASE non-reserved
-DATALINK reserved reserved
-DATE reserved reserved reserved
-DATETIME_INTERVAL_CODE non-reserved non-reserved non-reserved
-DATETIME_INTERVAL_PRECISION non-reserved non-reserved non-reserved
-DAY non-reserved reserved reserved reserved
-DB non-reserved non-reserved
-DEALLOCATE non-reserved reserved reserved reserved
-DEC non-reserved (cannot be function or type) reserved reserved reserved
-DECIMAL non-reserved (cannot be function or type) reserved reserved reserved
-DECLARE non-reserved reserved reserved reserved
-DEFAULT reserved reserved reserved reserved
-DEFAULTS non-reserved non-reserved non-reserved
-DEFERRABLE reserved non-reserved non-reserved reserved
-DEFERRED non-reserved non-reserved non-reserved reserved
-DEFINED non-reserved non-reserved
-DEFINER non-reserved non-reserved non-reserved
-DEGREE non-reserved non-reserved
-DELETE non-reserved reserved reserved reserved
-DELIMITER non-reserved
-DELIMITERS non-reserved
-DENSE_RANK reserved reserved
-DEPTH non-reserved non-reserved
-DEREF reserved reserved
-DERIVED non-reserved non-reserved
-DESC reserved non-reserved non-reserved reserved
-DESCRIBE reserved reserved reserved
-DESCRIPTOR non-reserved non-reserved reserved
-DETERMINISTIC reserved reserved
-DIAGNOSTICS non-reserved non-reserved reserved
-DICTIONARY non-reserved
-DISABLE non-reserved
-DISCARD non-reserved
-DISCONNECT reserved reserved reserved
-DISPATCH non-reserved non-reserved
-DISTINCT reserved reserved reserved reserved
-DLNEWCOPY reserved reserved
-DLPREVIOUSCOPY reserved reserved
-DLURLCOMPLETE reserved reserved
-DLURLCOMPLETEONLY reserved reserved
-DLURLCOMPLETEWRITE reserved reserved
-DLURLPATH reserved reserved
-DLURLPATHONLY reserved reserved
-DLURLPATHWRITE reserved reserved
-DLURLSCHEME reserved reserved
-DLURLSERVER reserved reserved
-DLVALUE reserved reserved
-DO reserved
-DOCUMENT non-reserved non-reserved non-reserved
-DOMAIN non-reserved non-reserved non-reserved reserved
-DOUBLE non-reserved reserved reserved reserved
-DROP non-reserved reserved reserved reserved
-DYNAMIC reserved reserved
-DYNAMIC_FUNCTION non-reserved non-reserved non-reserved
-DYNAMIC_FUNCTION_CODE non-reserved non-reserved
-EACH non-reserved reserved reserved
-ELEMENT reserved reserved
-ELSE reserved reserved reserved reserved
-EMPTY non-reserved non-reserved
-ENABLE non-reserved
-ENCODING non-reserved non-reserved non-reserved
-ENCRYPTED non-reserved
-END reserved reserved reserved reserved
-END-EXEC reserved reserved reserved
-END_FRAME reserved
-END_PARTITION reserved
-ENFORCED non-reserved
-ENUM non-reserved
-EQUALS reserved non-reserved
-ESCAPE non-reserved reserved reserved reserved
-EVENT non-reserved
-EVERY reserved reserved
-EXCEPT reserved reserved reserved reserved
-EXCEPTION reserved
-EXCLUDE non-reserved non-reserved non-reserved
-EXCLUDING non-reserved non-reserved non-reserved
-EXCLUSIVE non-reserved
-EXEC reserved reserved reserved
-EXECUTE non-reserved reserved reserved reserved
-EXISTS non-reserved (cannot be function or type) reserved reserved reserved
-EXP reserved reserved
-EXPLAIN non-reserved
-EXPRESSION non-reserved
-EXTENSION non-reserved
-EXTERNAL non-reserved reserved reserved reserved
-EXTRACT non-reserved (cannot be function or type) reserved reserved reserved
-FALSE reserved reserved reserved reserved
-FAMILY non-reserved
-FETCH reserved reserved reserved reserved
-FILE non-reserved non-reserved
-FILTER reserved reserved
-FINAL non-reserved non-reserved
-FIRST non-reserved non-reserved non-reserved reserved
-FIRST_VALUE reserved reserved
-FLAG non-reserved non-reserved
-FLOAT non-reserved (cannot be function or type) reserved reserved reserved
-FLOOR reserved reserved
-FOLLOWING non-reserved non-reserved non-reserved
-FOR reserved reserved reserved reserved
-FORCE non-reserved
-FOREIGN reserved reserved reserved reserved
-FORTRAN non-reserved non-reserved non-reserved
-FORWARD non-reserved
-FOUND non-reserved non-reserved reserved
-FRAME_ROW reserved
-FREE reserved reserved
-FREEZE reserved (can be function or type)
-FROM reserved reserved reserved reserved
-FS non-reserved non-reserved
-FULL reserved (can be function or type) reserved reserved reserved
-FUNCTION non-reserved reserved reserved
-FUNCTIONS non-reserved
-FUSION reserved reserved
-G non-reserved non-reserved
-GENERAL non-reserved non-reserved
-GENERATED non-reserved non-reserved
-GET reserved reserved reserved
-GLOBAL non-reserved reserved reserved reserved
-GO non-reserved non-reserved reserved
-GOTO non-reserved non-reserved reserved
-GRANT reserved reserved reserved reserved
-GRANTED non-reserved non-reserved non-reserved
-GREATEST non-reserved (cannot be function or type)
-GROUP reserved reserved reserved reserved
-GROUPING reserved reserved
-GROUPS reserved
-HANDLER non-reserved
-HAVING reserved reserved reserved reserved
-HEADER non-reserved
-HEX non-reserved non-reserved
-HIERARCHY non-reserved non-reserved
-HOLD non-reserved reserved reserved
-HOUR non-reserved reserved reserved reserved
-ID non-reserved non-reserved
-IDENTITY non-reserved reserved reserved reserved
-IF non-reserved
-IGNORE non-reserved non-reserved
-ILIKE reserved (can be function or type)
-IMMEDIATE non-reserved non-reserved non-reserved reserved
-IMMEDIATELY non-reserved
-IMMUTABLE non-reserved
-IMPLEMENTATION non-reserved non-reserved
-IMPLICIT non-reserved
-IMPORT reserved reserved
-IN reserved reserved reserved reserved
-INCLUDING non-reserved non-reserved non-reserved
-INCREMENT non-reserved non-reserved non-reserved
-INDENT non-reserved non-reserved
-INDEX non-reserved
-INDEXES non-reserved
-INDICATOR reserved reserved reserved
-INHERIT non-reserved
-INHERITS non-reserved
-INITIALLY reserved non-reserved non-reserved reserved
-INLINE non-reserved
-INNER reserved (can be function or type) reserved reserved reserved
-INOUT non-reserved (cannot be function or type) reserved reserved
-INPUT non-reserved non-reserved non-reserved reserved
-INSENSITIVE non-reserved reserved reserved reserved
-INSERT non-reserved reserved reserved reserved
-INSTANCE non-reserved non-reserved
-INSTANTIABLE non-reserved non-reserved
-INSTEAD non-reserved non-reserved non-reserved
-INT non-reserved (cannot be function or type) reserved reserved reserved
-INTEGER non-reserved (cannot be function or type) reserved reserved reserved
-INTEGRITY non-reserved non-reserved
-INTERSECT reserved reserved reserved reserved
-INTERSECTION reserved reserved
-INTERVAL non-reserved (cannot be function or type) reserved reserved reserved
-INTO reserved reserved reserved reserved
-INVOKER non-reserved non-reserved non-reserved
-IS reserved (can be function or type) reserved reserved reserved
-ISNULL reserved (can be function or type)
-ISOLATION non-reserved non-reserved non-reserved reserved
-JOIN reserved (can be function or type) reserved reserved reserved
-K non-reserved non-reserved
-KEY non-reserved non-reserved non-reserved reserved
-KEY_MEMBER non-reserved non-reserved
-KEY_TYPE non-reserved non-reserved
-LABEL non-reserved
-LAG reserved reserved
-LANGUAGE non-reserved reserved reserved reserved
-LARGE non-reserved reserved reserved
-LAST non-reserved non-reserved non-reserved reserved
-LAST_VALUE reserved reserved
-LATERAL reserved reserved reserved
-LC_COLLATE non-reserved
-LC_CTYPE non-reserved
-LEAD reserved reserved
-LEADING reserved reserved reserved reserved
-LEAKPROOF non-reserved
-LEAST non-reserved (cannot be function or type)
-LEFT reserved (can be function or type) reserved reserved reserved
-LENGTH non-reserved non-reserved non-reserved
-LEVEL non-reserved non-reserved non-reserved reserved
-LIBRARY non-reserved non-reserved
-LIKE reserved (can be function or type) reserved reserved reserved
-LIKE_REGEX reserved reserved
-LIMIT reserved non-reserved non-reserved
-LINK non-reserved non-reserved
-LISTEN non-reserved
-LN reserved reserved
-LOAD non-reserved
-LOCAL non-reserved reserved reserved reserved
-LOCALTIME reserved reserved reserved
-LOCALTIMESTAMP reserved reserved reserved
-LOCATION non-reserved non-reserved non-reserved
-LOCATOR non-reserved non-reserved
-LOCK non-reserved
-LOWER reserved reserved reserved
-M non-reserved non-reserved
-MAP non-reserved non-reserved
-MAPPING non-reserved non-reserved non-reserved
-MATCH non-reserved reserved reserved reserved
-MATCHED non-reserved non-reserved
-MATERIALIZED non-reserved
-MAX reserved reserved reserved
-MAXVALUE non-reserved non-reserved non-reserved
-MAX_CARDINALITY reserved
-MEMBER reserved reserved
-MERGE reserved reserved
-MESSAGE_LENGTH non-reserved non-reserved non-reserved
-MESSAGE_OCTET_LENGTH non-reserved non-reserved non-reserved
-MESSAGE_TEXT non-reserved non-reserved non-reserved
-METHOD reserved reserved
-MIN reserved reserved reserved
-MINUTE non-reserved reserved reserved reserved
-MINVALUE non-reserved non-reserved non-reserved
-MOD reserved reserved
-MODE non-reserved
-MODIFIES reserved reserved
-MODULE reserved reserved reserved
-MONTH non-reserved reserved reserved reserved
-MORE non-reserved non-reserved non-reserved
-MOVE non-reserved
-MULTISET reserved reserved
-MUMPS non-reserved non-reserved non-reserved
-NAME non-reserved non-reserved non-reserved non-reserved
-NAMES non-reserved non-reserved non-reserved reserved
-NAMESPACE non-reserved non-reserved
-NATIONAL non-reserved (cannot be function or type) reserved reserved reserved
-NATURAL reserved (can be function or type) reserved reserved reserved
-NCHAR non-reserved (cannot be function or type) reserved reserved reserved
-NCLOB reserved reserved
-NESTING non-reserved non-reserved
-NEW reserved reserved
-NEXT non-reserved non-reserved non-reserved reserved
-NFC non-reserved non-reserved
-NFD non-reserved non-reserved
-NFKC non-reserved non-reserved
-NFKD non-reserved non-reserved
-NIL non-reserved non-reserved
-NO non-reserved reserved reserved reserved
-NONE non-reserved (cannot be function or type) reserved reserved
-NORMALIZE reserved reserved
-NORMALIZED non-reserved non-reserved
-NOT reserved reserved reserved reserved
-NOTHING non-reserved
-NOTIFY non-reserved
-NOTNULL reserved (can be function or type)
-NOWAIT non-reserved
-NTH_VALUE reserved reserved
-NTILE reserved reserved
-NULL reserved reserved reserved reserved
-NULLABLE non-reserved non-reserved non-reserved
-NULLIF non-reserved (cannot be function or type) reserved reserved reserved
-NULLS non-reserved non-reserved non-reserved
-NUMBER non-reserved non-reserved non-reserved
-NUMERIC non-reserved (cannot be function or type) reserved reserved reserved
-OBJECT non-reserved non-reserved non-reserved
-OCCURRENCES_REGEX reserved reserved
-OCTETS non-reserved non-reserved
-OCTET_LENGTH reserved reserved reserved
-OF non-reserved reserved reserved reserved
-OFF non-reserved non-reserved non-reserved
-OFFSET reserved reserved reserved
-OIDS non-reserved
-OLD reserved reserved
-ON reserved reserved reserved reserved
-ONLY reserved reserved reserved reserved
-OPEN reserved reserved reserved
-OPERATOR non-reserved
-OPTION non-reserved non-reserved non-reserved reserved
-OPTIONS non-reserved non-reserved non-reserved
-OR reserved reserved reserved reserved
-ORDER reserved reserved reserved reserved
-ORDERING non-reserved non-reserved
-ORDINALITY non-reserved non-reserved
-OTHERS non-reserved non-reserved
-OUT non-reserved (cannot be function or type) reserved reserved
-OUTER reserved (can be function or type) reserved reserved reserved
-OUTPUT non-reserved non-reserved reserved
-OVER reserved (can be function or type) reserved reserved
-OVERLAPS reserved (can be function or type) reserved reserved reserved
-OVERLAY non-reserved (cannot be function or type) reserved reserved
-OVERRIDING non-reserved non-reserved
-OWNED non-reserved
-OWNER non-reserved
-P non-reserved non-reserved
-PAD non-reserved non-reserved reserved
-PARAMETER reserved reserved
-PARAMETER_MODE non-reserved non-reserved
-PARAMETER_NAME non-reserved non-reserved
-PARAMETER_ORDINAL_POSITION non-reserved non-reserved
-PARAMETER_SPECIFIC_CATALOG non-reserved non-reserved
-PARAMETER_SPECIFIC_NAME non-reserved non-reserved
-PARAMETER_SPECIFIC_SCHEMA non-reserved non-reserved
-PARSER non-reserved
-PARTIAL non-reserved non-reserved non-reserved reserved
-PARTITION non-reserved reserved reserved
-PASCAL non-reserved non-reserved non-reserved
-PASSING non-reserved non-reserved non-reserved
-PASSTHROUGH non-reserved non-reserved
-PASSWORD non-reserved
-PATH non-reserved non-reserved
-PERCENT reserved
-PERCENTILE_CONT reserved reserved
-PERCENTILE_DISC reserved reserved
-PERCENT_RANK reserved reserved
-PERIOD reserved
-PERMISSION non-reserved non-reserved
-PLACING reserved non-reserved non-reserved
-PLANS non-reserved
-PLI non-reserved non-reserved non-reserved
-PORTION reserved
-POSITION non-reserved (cannot be function or type) reserved reserved reserved
-POSITION_REGEX reserved reserved
-POWER reserved reserved
-PRECEDES reserved
-PRECEDING non-reserved non-reserved non-reserved
-PRECISION non-reserved (cannot be function or type) reserved reserved reserved
-PREPARE non-reserved reserved reserved reserved
-PREPARED non-reserved
-PRESERVE non-reserved non-reserved non-reserved reserved
-PRIMARY reserved reserved reserved reserved
-PRIOR non-reserved non-reserved non-reserved reserved
-PRIVILEGES non-reserved non-reserved non-reserved reserved
-PROCEDURAL non-reserved
-PROCEDURE non-reserved reserved reserved reserved
-PROGRAM non-reserved
-PUBLIC non-reserved non-reserved reserved
-QUOTE non-reserved
-RANGE non-reserved reserved reserved
-RANK reserved reserved
-READ non-reserved non-reserved non-reserved reserved
-READS reserved reserved
-REAL non-reserved (cannot be function or type) reserved reserved reserved
-REASSIGN non-reserved
-RECHECK non-reserved
-RECOVERY non-reserved non-reserved
-RECURSIVE non-reserved reserved reserved
-REF non-reserved reserved reserved
-REFERENCES reserved reserved reserved reserved
-REFERENCING reserved reserved
-REFRESH non-reserved
-REGR_AVGX reserved reserved
-REGR_AVGY reserved reserved
-REGR_COUNT reserved reserved
-REGR_INTERCEPT reserved reserved
-REGR_R2 reserved reserved
-REGR_SLOPE reserved reserved
-REGR_SXX reserved reserved
-REGR_SXY reserved reserved
-REGR_SYY reserved reserved
-REINDEX non-reserved
-RELATIVE non-reserved non-reserved non-reserved reserved
-RELEASE non-reserved reserved reserved
-RENAME non-reserved
-REPEATABLE non-reserved non-reserved non-reserved non-reserved
-REPLACE non-reserved
-REPLICA non-reserved
-REQUIRING non-reserved non-reserved
-RESET non-reserved
-RESPECT non-reserved non-reserved
-RESTART non-reserved non-reserved non-reserved
-RESTORE non-reserved non-reserved
-RESTRICT non-reserved non-reserved non-reserved reserved
-RESULT reserved reserved
-RETURN reserved reserved
-RETURNED_CARDINALITY non-reserved non-reserved
-RETURNED_LENGTH non-reserved non-reserved non-reserved
-RETURNED_OCTET_LENGTH non-reserved non-reserved non-reserved
-RETURNED_SQLSTATE non-reserved non-reserved non-reserved
-RETURNING reserved non-reserved non-reserved
-RETURNS non-reserved reserved reserved
-REVOKE non-reserved reserved reserved reserved
-RIGHT reserved (can be function or type) reserved reserved reserved
-ROLE non-reserved non-reserved non-reserved
-ROLLBACK non-reserved reserved reserved reserved
-ROLLUP reserved reserved
-ROUTINE non-reserved non-reserved
-ROUTINE_CATALOG non-reserved non-reserved
-ROUTINE_NAME non-reserved non-reserved
-ROUTINE_SCHEMA non-reserved non-reserved
-ROW non-reserved (cannot be function or type) reserved reserved
-ROWS non-reserved reserved reserved reserved
-ROW_COUNT non-reserved non-reserved non-reserved
-ROW_NUMBER reserved reserved
-RULE non-reserved
-SAVEPOINT non-reserved reserved reserved
-SCALE non-reserved non-reserved non-reserved
-SCHEMA non-reserved non-reserved non-reserved reserved
-SCHEMA_NAME non-reserved non-reserved non-reserved
-SCOPE reserved reserved
-SCOPE_CATALOG non-reserved non-reserved
-SCOPE_NAME non-reserved non-reserved
-SCOPE_SCHEMA non-reserved non-reserved
-SCROLL non-reserved reserved reserved reserved
-SEARCH non-reserved reserved reserved
-SECOND non-reserved reserved reserved reserved
-SECTION non-reserved non-reserved reserved
-SECURITY non-reserved non-reserved non-reserved
-SELECT reserved reserved reserved reserved
-SELECTIVE non-reserved non-reserved
-SELF non-reserved non-reserved
-SENSITIVE reserved reserved
-SEQUENCE non-reserved non-reserved non-reserved
-SEQUENCES non-reserved
-SERIALIZABLE non-reserved non-reserved non-reserved non-reserved
-SERVER non-reserved non-reserved non-reserved
-SERVER_NAME non-reserved non-reserved non-reserved
-SESSION non-reserved non-reserved non-reserved reserved
-SESSION_USER reserved reserved reserved reserved
-SET non-reserved reserved reserved reserved
-SETOF non-reserved (cannot be function or type)
-SETS non-reserved non-reserved
-SHARE non-reserved
-SHOW non-reserved
-SIMILAR reserved (can be function or type) reserved reserved
-SIMPLE non-reserved non-reserved non-reserved
-SIZE non-reserved non-reserved reserved
-SMALLINT non-reserved (cannot be function or type) reserved reserved reserved
-SNAPSHOT non-reserved
-SOME reserved reserved reserved reserved
-SOURCE non-reserved non-reserved
-SPACE non-reserved non-reserved reserved
-SPECIFIC reserved reserved
-SPECIFICTYPE reserved reserved
-SPECIFIC_NAME non-reserved non-reserved
-SQL reserved reserved reserved
-SQLCODE reserved
-SQLERROR reserved
-SQLEXCEPTION reserved reserved
-SQLSTATE reserved reserved reserved
-SQLWARNING reserved reserved
-SQRT reserved reserved
-STABLE non-reserved
-STANDALONE non-reserved non-reserved non-reserved
-START non-reserved reserved reserved
-STATE non-reserved non-reserved
-STATEMENT non-reserved non-reserved non-reserved
-STATIC reserved reserved
-STATISTICS non-reserved
-STDDEV_POP reserved reserved
-STDDEV_SAMP reserved reserved
-STDIN non-reserved
-STDOUT non-reserved
-STORAGE non-reserved
-STRICT non-reserved
-STRIP non-reserved non-reserved non-reserved
-STRUCTURE non-reserved non-reserved
-STYLE non-reserved non-reserved
-SUBCLASS_ORIGIN non-reserved non-reserved non-reserved
-SUBMULTISET reserved reserved
-SUBSTRING non-reserved (cannot be function or type) reserved reserved reserved
-SUBSTRING_REGEX reserved reserved
-SUCCEEDS reserved
-SUM reserved reserved reserved
-SYMMETRIC reserved reserved reserved
-SYSID non-reserved
-SYSTEM non-reserved reserved reserved
-SYSTEM_TIME reserved
-SYSTEM_USER reserved reserved reserved
-T non-reserved non-reserved
-TABLE reserved reserved reserved reserved
-TABLES non-reserved
-TABLESAMPLE reserved reserved
-TABLESPACE non-reserved
-TABLE_NAME non-reserved non-reserved non-reserved
-TEMP non-reserved
-TEMPLATE non-reserved
-TEMPORARY non-reserved non-reserved non-reserved reserved
-TEXT non-reserved
-THEN reserved reserved reserved reserved
-TIES non-reserved non-reserved
-TIME non-reserved (cannot be function or type) reserved reserved reserved
-TIMESTAMP non-reserved (cannot be function or type) reserved reserved reserved
-TIMEZONE_HOUR reserved reserved reserved
-TIMEZONE_MINUTE reserved reserved reserved
-TO reserved reserved reserved reserved
-TOKEN non-reserved non-reserved
-TOP_LEVEL_COUNT non-reserved non-reserved
-TRAILING reserved reserved reserved reserved
-TRANSACTION non-reserved non-reserved non-reserved reserved
-TRANSACTIONS_COMMITTED non-reserved non-reserved
-TRANSACTIONS_ROLLED_BACK non-reserved non-reserved
-TRANSACTION_ACTIVE non-reserved non-reserved
-TRANSFORM non-reserved non-reserved
-TRANSFORMS non-reserved non-reserved
-TRANSLATE reserved reserved reserved
-TRANSLATE_REGEX reserved reserved
-TRANSLATION reserved reserved reserved
-TREAT non-reserved (cannot be function or type) reserved reserved
-TRIGGER non-reserved reserved reserved
-TRIGGER_CATALOG non-reserved non-reserved
-TRIGGER_NAME non-reserved non-reserved
-TRIGGER_SCHEMA non-reserved non-reserved
-TRIM non-reserved (cannot be function or type) reserved reserved reserved
-TRIM_ARRAY reserved reserved
-TRUE reserved reserved reserved reserved
-TRUNCATE non-reserved reserved reserved
-TRUSTED non-reserved
-TYPE non-reserved non-reserved non-reserved non-reserved
-TYPES non-reserved
-UESCAPE reserved reserved
-UNBOUNDED non-reserved non-reserved non-reserved
-UNCOMMITTED non-reserved non-reserved non-reserved non-reserved
-UNDER non-reserved non-reserved
-UNENCRYPTED non-reserved
-UNION reserved reserved reserved reserved
-UNIQUE reserved reserved reserved reserved
-UNKNOWN non-reserved reserved reserved reserved
-UNLINK non-reserved non-reserved
-UNLISTEN non-reserved
-UNLOGGED non-reserved
-UNNAMED non-reserved non-reserved non-reserved
-UNNEST reserved reserved
-UNTIL non-reserved
-UNTYPED non-reserved non-reserved
-UPDATE non-reserved reserved reserved reserved
-UPPER reserved reserved reserved
-URI non-reserved non-reserved
-USAGE non-reserved non-reserved reserved
-USER reserved reserved reserved reserved
-USER_DEFINED_TYPE_CATALOG non-reserved non-reserved
-USER_DEFINED_TYPE_CODE non-reserved non-reserved
-USER_DEFINED_TYPE_NAME non-reserved non-reserved
-USER_DEFINED_TYPE_SCHEMA non-reserved non-reserved
-USING reserved reserved reserved reserved
-VACUUM non-reserved
-VALID non-reserved non-reserved non-reserved
-VALIDATE non-reserved
-VALIDATOR non-reserved
-VALUE non-reserved reserved reserved reserved
-VALUES non-reserved (cannot be function or type) reserved reserved reserved
-VALUE_OF reserved
-VARBINARY reserved reserved
-VARCHAR non-reserved (cannot be function or type) reserved reserved reserved
-VARIADIC reserved
-VARYING non-reserved reserved reserved reserved
-VAR_POP reserved reserved
-VAR_SAMP reserved reserved
-VERBOSE reserved (can be function or type)
-VERSION non-reserved non-reserved non-reserved
-VERSIONING reserved
-VIEW non-reserved non-reserved non-reserved reserved
-VOLATILE non-reserved
-WHEN reserved reserved reserved reserved
-WHENEVER reserved reserved reserved
-WHERE reserved reserved reserved reserved
-WHITESPACE non-reserved non-reserved non-reserved
-WIDTH_BUCKET reserved reserved
-WINDOW reserved reserved reserved
-WITH reserved reserved reserved reserved
-WITHIN reserved reserved
-WITHOUT non-reserved reserved reserved
-WORK non-reserved non-reserved non-reserved reserved
-WRAPPER non-reserved non-reserved non-reserved
-WRITE non-reserved non-reserved non-reserved reserved
-XML non-reserved reserved reserved
-XMLAGG reserved reserved
-XMLATTRIBUTES non-reserved (cannot be function or type) reserved reserved
-XMLBINARY reserved reserved
-XMLCAST reserved reserved
-XMLCOMMENT reserved reserved
-XMLCONCAT non-reserved (cannot be function or type) reserved reserved
-XMLDECLARATION non-reserved non-reserved
-XMLDOCUMENT reserved reserved
-XMLELEMENT non-reserved (cannot be function or type) reserved reserved
-XMLEXISTS non-reserved (cannot be function or type) reserved reserved
-XMLFOREST non-reserved (cannot be function or type) reserved reserved
-XMLITERATE reserved reserved
-XMLNAMESPACES reserved reserved
-XMLPARSE non-reserved (cannot be function or type) reserved reserved
-XMLPI non-reserved (cannot be function or type) reserved reserved
-XMLQUERY reserved reserved
-XMLROOT non-reserved (cannot be function or type)
-XMLSCHEMA non-reserved non-reserved
-XMLSERIALIZE non-reserved (cannot be function or type) reserved reserved
-XMLTABLE reserved reserved
-XMLTEXT reserved reserved
-XMLVALIDATE reserved reserved
-YEAR non-reserved reserved reserved reserved
-YES non-reserved non-reserved non-reserved
-ZONE non-reserved non-reserved non-reserved reserved \ No newline at end of file
diff --git a/vendor/xorm.io/xorm/dialects/postgres.go b/vendor/xorm.io/xorm/dialects/postgres.go
deleted file mode 100644
index 2cc46371ed..0000000000
--- a/vendor/xorm.io/xorm/dialects/postgres.go
+++ /dev/null
@@ -1,1495 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "database/sql"
- "errors"
- "fmt"
- "net/url"
- "strconv"
- "strings"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-// from http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html
-var (
- postgresReservedWords = map[string]bool{
- "A": true,
- "ABORT": true,
- "ABS": true,
- "ABSENT": true,
- "ABSOLUTE": true,
- "ACCESS": true,
- "ACCORDING": true,
- "ACTION": true,
- "ADA": true,
- "ADD": true,
- "ADMIN": true,
- "AFTER": true,
- "AGGREGATE": true,
- "ALL": true,
- "ALLOCATE": true,
- "ALSO": true,
- "ALTER": true,
- "ALWAYS": true,
- "ANALYSE": true,
- "ANALYZE": true,
- "AND": true,
- "ANY": true,
- "ARE": true,
- "ARRAY": true,
- "ARRAY_AGG": true,
- "ARRAY_MAX_CARDINALITY": true,
- "AS": true,
- "ASC": true,
- "ASENSITIVE": true,
- "ASSERTION": true,
- "ASSIGNMENT": true,
- "ASYMMETRIC": true,
- "AT": true,
- "ATOMIC": true,
- "ATTRIBUTE": true,
- "ATTRIBUTES": true,
- "AUTHORIZATION": true,
- "AVG": true,
- "BACKWARD": true,
- "BASE64": true,
- "BEFORE": true,
- "BEGIN": true,
- "BEGIN_FRAME": true,
- "BEGIN_PARTITION": true,
- "BERNOULLI": true,
- "BETWEEN": true,
- "BIGINT": true,
- "BINARY": true,
- "BIT": true,
- "BIT_LENGTH": true,
- "BLOB": true,
- "BLOCKED": true,
- "BOM": true,
- "BOOLEAN": true,
- "BOTH": true,
- "BREADTH": true,
- "BY": true,
- "C": true,
- "CACHE": true,
- "CALL": true,
- "CALLED": true,
- "CARDINALITY": true,
- "CASCADE": true,
- "CASCADED": true,
- "CASE": true,
- "CAST": true,
- "CATALOG": true,
- "CATALOG_NAME": true,
- "CEIL": true,
- "CEILING": true,
- "CHAIN": true,
- "CHAR": true,
- "CHARACTER": true,
- "CHARACTERISTICS": true,
- "CHARACTERS": true,
- "CHARACTER_LENGTH": true,
- "CHARACTER_SET_CATALOG": true,
- "CHARACTER_SET_NAME": true,
- "CHARACTER_SET_SCHEMA": true,
- "CHAR_LENGTH": true,
- "CHECK": true,
- "CHECKPOINT": true,
- "CLASS": true,
- "CLASS_ORIGIN": true,
- "CLOB": true,
- "CLOSE": true,
- "CLUSTER": true,
- "COALESCE": true,
- "COBOL": true,
- "COLLATE": true,
- "COLLATION": true,
- "COLLATION_CATALOG": true,
- "COLLATION_NAME": true,
- "COLLATION_SCHEMA": true,
- "COLLECT": true,
- "COLUMN": true,
- "COLUMNS": true,
- "COLUMN_NAME": true,
- "COMMAND_FUNCTION": true,
- "COMMAND_FUNCTION_CODE": true,
- "COMMENT": true,
- "COMMENTS": true,
- "COMMIT": true,
- "COMMITTED": true,
- "CONCURRENTLY": true,
- "CONDITION": true,
- "CONDITION_NUMBER": true,
- "CONFIGURATION": true,
- "CONNECT": true,
- "CONNECTION": true,
- "CONNECTION_NAME": true,
- "CONSTRAINT": true,
- "CONSTRAINTS": true,
- "CONSTRAINT_CATALOG": true,
- "CONSTRAINT_NAME": true,
- "CONSTRAINT_SCHEMA": true,
- "CONSTRUCTOR": true,
- "CONTAINS": true,
- "CONTENT": true,
- "CONTINUE": true,
- "CONTROL": true,
- "CONVERSION": true,
- "CONVERT": true,
- "COPY": true,
- "CORR": true,
- "CORRESPONDING": true,
- "COST": true,
- "COUNT": true,
- "COVAR_POP": true,
- "COVAR_SAMP": true,
- "CREATE": true,
- "CROSS": true,
- "CSV": true,
- "CUBE": true,
- "CUME_DIST": true,
- "CURRENT": true,
- "CURRENT_CATALOG": true,
- "CURRENT_DATE": true,
- "CURRENT_DEFAULT_TRANSFORM_GROUP": true,
- "CURRENT_PATH": true,
- "CURRENT_ROLE": true,
- "CURRENT_ROW": true,
- "CURRENT_SCHEMA": true,
- "CURRENT_TIME": true,
- "CURRENT_TIMESTAMP": true,
- "CURRENT_TRANSFORM_GROUP_FOR_TYPE": true,
- "CURRENT_USER": true,
- "CURSOR": true,
- "CURSOR_NAME": true,
- "CYCLE": true,
- "DATA": true,
- "DATABASE": true,
- "DATALINK": true,
- "DATE": true,
- "DATETIME_INTERVAL_CODE": true,
- "DATETIME_INTERVAL_PRECISION": true,
- "DAY": true,
- "DB": true,
- "DEALLOCATE": true,
- "DEC": true,
- "DECIMAL": true,
- "DECLARE": true,
- "DEFAULT": true,
- "DEFAULTS": true,
- "DEFERRABLE": true,
- "DEFERRED": true,
- "DEFINED": true,
- "DEFINER": true,
- "DEGREE": true,
- "DELETE": true,
- "DELIMITER": true,
- "DELIMITERS": true,
- "DENSE_RANK": true,
- "DEPTH": true,
- "DEREF": true,
- "DERIVED": true,
- "DESC": true,
- "DESCRIBE": true,
- "DESCRIPTOR": true,
- "DETERMINISTIC": true,
- "DIAGNOSTICS": true,
- "DICTIONARY": true,
- "DISABLE": true,
- "DISCARD": true,
- "DISCONNECT": true,
- "DISPATCH": true,
- "DISTINCT": true,
- "DLNEWCOPY": true,
- "DLPREVIOUSCOPY": true,
- "DLURLCOMPLETE": true,
- "DLURLCOMPLETEONLY": true,
- "DLURLCOMPLETEWRITE": true,
- "DLURLPATH": true,
- "DLURLPATHONLY": true,
- "DLURLPATHWRITE": true,
- "DLURLSCHEME": true,
- "DLURLSERVER": true,
- "DLVALUE": true,
- "DO": true,
- "DOCUMENT": true,
- "DOMAIN": true,
- "DOUBLE": true,
- "DROP": true,
- "DYNAMIC": true,
- "DYNAMIC_FUNCTION": true,
- "DYNAMIC_FUNCTION_CODE": true,
- "EACH": true,
- "ELEMENT": true,
- "ELSE": true,
- "EMPTY": true,
- "ENABLE": true,
- "ENCODING": true,
- "ENCRYPTED": true,
- "END": true,
- "END-EXEC": true,
- "END_FRAME": true,
- "END_PARTITION": true,
- "ENFORCED": true,
- "ENUM": true,
- "EQUALS": true,
- "ESCAPE": true,
- "EVENT": true,
- "EVERY": true,
- "EXCEPT": true,
- "EXCEPTION": true,
- "EXCLUDE": true,
- "EXCLUDING": true,
- "EXCLUSIVE": true,
- "EXEC": true,
- "EXECUTE": true,
- "EXISTS": true,
- "EXP": true,
- "EXPLAIN": true,
- "EXPRESSION": true,
- "EXTENSION": true,
- "EXTERNAL": true,
- "EXTRACT": true,
- "FALSE": true,
- "FAMILY": true,
- "FETCH": true,
- "FILE": true,
- "FILTER": true,
- "FINAL": true,
- "FIRST": true,
- "FIRST_VALUE": true,
- "FLAG": true,
- "FLOAT": true,
- "FLOOR": true,
- "FOLLOWING": true,
- "FOR": true,
- "FORCE": true,
- "FOREIGN": true,
- "FORTRAN": true,
- "FORWARD": true,
- "FOUND": true,
- "FRAME_ROW": true,
- "FREE": true,
- "FREEZE": true,
- "FROM": true,
- "FS": true,
- "FULL": true,
- "FUNCTION": true,
- "FUNCTIONS": true,
- "FUSION": true,
- "G": true,
- "GENERAL": true,
- "GENERATED": true,
- "GET": true,
- "GLOBAL": true,
- "GO": true,
- "GOTO": true,
- "GRANT": true,
- "GRANTED": true,
- "GREATEST": true,
- "GROUP": true,
- "GROUPING": true,
- "GROUPS": true,
- "HANDLER": true,
- "HAVING": true,
- "HEADER": true,
- "HEX": true,
- "HIERARCHY": true,
- "HOLD": true,
- "HOUR": true,
- "ID": true,
- "IDENTITY": true,
- "IF": true,
- "IGNORE": true,
- "ILIKE": true,
- "IMMEDIATE": true,
- "IMMEDIATELY": true,
- "IMMUTABLE": true,
- "IMPLEMENTATION": true,
- "IMPLICIT": true,
- "IMPORT": true,
- "IN": true,
- "INCLUDING": true,
- "INCREMENT": true,
- "INDENT": true,
- "INDEX": true,
- "INDEXES": true,
- "INDICATOR": true,
- "INHERIT": true,
- "INHERITS": true,
- "INITIALLY": true,
- "INLINE": true,
- "INNER": true,
- "INOUT": true,
- "INPUT": true,
- "INSENSITIVE": true,
- "INSERT": true,
- "INSTANCE": true,
- "INSTANTIABLE": true,
- "INSTEAD": true,
- "INT": true,
- "INTEGER": true,
- "INTEGRITY": true,
- "INTERSECT": true,
- "INTERSECTION": true,
- "INTERVAL": true,
- "INTO": true,
- "INVOKER": true,
- "IS": true,
- "ISNULL": true,
- "ISOLATION": true,
- "JOIN": true,
- "K": true,
- "KEY": true,
- "KEY_MEMBER": true,
- "KEY_TYPE": true,
- "LABEL": true,
- "LAG": true,
- "LANGUAGE": true,
- "LARGE": true,
- "LAST": true,
- "LAST_VALUE": true,
- "LATERAL": true,
- "LC_COLLATE": true,
- "LC_CTYPE": true,
- "LEAD": true,
- "LEADING": true,
- "LEAKPROOF": true,
- "LEAST": true,
- "LEFT": true,
- "LENGTH": true,
- "LEVEL": true,
- "LIBRARY": true,
- "LIKE": true,
- "LIKE_REGEX": true,
- "LIMIT": true,
- "LINK": true,
- "LISTEN": true,
- "LN": true,
- "LOAD": true,
- "LOCAL": true,
- "LOCALTIME": true,
- "LOCALTIMESTAMP": true,
- "LOCATION": true,
- "LOCATOR": true,
- "LOCK": true,
- "LOWER": true,
- "M": true,
- "MAP": true,
- "MAPPING": true,
- "MATCH": true,
- "MATCHED": true,
- "MATERIALIZED": true,
- "MAX": true,
- "MAXVALUE": true,
- "MAX_CARDINALITY": true,
- "MEMBER": true,
- "MERGE": true,
- "MESSAGE_LENGTH": true,
- "MESSAGE_OCTET_LENGTH": true,
- "MESSAGE_TEXT": true,
- "METHOD": true,
- "MIN": true,
- "MINUTE": true,
- "MINVALUE": true,
- "MOD": true,
- "MODE": true,
- "MODIFIES": true,
- "MODULE": true,
- "MONTH": true,
- "MORE": true,
- "MOVE": true,
- "MULTISET": true,
- "MUMPS": true,
- "NAME": true,
- "NAMES": true,
- "NAMESPACE": true,
- "NATIONAL": true,
- "NATURAL": true,
- "NCHAR": true,
- "NCLOB": true,
- "NESTING": true,
- "NEW": true,
- "NEXT": true,
- "NFC": true,
- "NFD": true,
- "NFKC": true,
- "NFKD": true,
- "NIL": true,
- "NO": true,
- "NONE": true,
- "NORMALIZE": true,
- "NORMALIZED": true,
- "NOT": true,
- "NOTHING": true,
- "NOTIFY": true,
- "NOTNULL": true,
- "NOWAIT": true,
- "NTH_VALUE": true,
- "NTILE": true,
- "NULL": true,
- "NULLABLE": true,
- "NULLIF": true,
- "NULLS": true,
- "NUMBER": true,
- "NUMERIC": true,
- "OBJECT": true,
- "OCCURRENCES_REGEX": true,
- "OCTETS": true,
- "OCTET_LENGTH": true,
- "OF": true,
- "OFF": true,
- "OFFSET": true,
- "OIDS": true,
- "OLD": true,
- "ON": true,
- "ONLY": true,
- "OPEN": true,
- "OPERATOR": true,
- "OPTION": true,
- "OPTIONS": true,
- "OR": true,
- "ORDER": true,
- "ORDERING": true,
- "ORDINALITY": true,
- "OTHERS": true,
- "OUT": true,
- "OUTER": true,
- "OUTPUT": true,
- "OVER": true,
- "OVERLAPS": true,
- "OVERLAY": true,
- "OVERRIDING": true,
- "OWNED": true,
- "OWNER": true,
- "P": true,
- "PAD": true,
- "PARAMETER": true,
- "PARAMETER_MODE": true,
- "PARAMETER_NAME": true,
- "PARAMETER_ORDINAL_POSITION": true,
- "PARAMETER_SPECIFIC_CATALOG": true,
- "PARAMETER_SPECIFIC_NAME": true,
- "PARAMETER_SPECIFIC_SCHEMA": true,
- "PARSER": true,
- "PARTIAL": true,
- "PARTITION": true,
- "PASCAL": true,
- "PASSING": true,
- "PASSTHROUGH": true,
- "PASSWORD": true,
- "PATH": true,
- "PERCENT": true,
- "PERCENTILE_CONT": true,
- "PERCENTILE_DISC": true,
- "PERCENT_RANK": true,
- "PERIOD": true,
- "PERMISSION": true,
- "PLACING": true,
- "PLANS": true,
- "PLI": true,
- "PORTION": true,
- "POSITION": true,
- "POSITION_REGEX": true,
- "POWER": true,
- "PRECEDES": true,
- "PRECEDING": true,
- "PRECISION": true,
- "PREPARE": true,
- "PREPARED": true,
- "PRESERVE": true,
- "PRIMARY": true,
- "PRIOR": true,
- "PRIVILEGES": true,
- "PROCEDURAL": true,
- "PROCEDURE": true,
- "PROGRAM": true,
- "PUBLIC": true,
- "QUOTE": true,
- "RANGE": true,
- "RANK": true,
- "READ": true,
- "READS": true,
- "REAL": true,
- "REASSIGN": true,
- "RECHECK": true,
- "RECOVERY": true,
- "RECURSIVE": true,
- "REF": true,
- "REFERENCES": true,
- "REFERENCING": true,
- "REFRESH": true,
- "REGR_AVGX": true,
- "REGR_AVGY": true,
- "REGR_COUNT": true,
- "REGR_INTERCEPT": true,
- "REGR_R2": true,
- "REGR_SLOPE": true,
- "REGR_SXX": true,
- "REGR_SXY": true,
- "REGR_SYY": true,
- "REINDEX": true,
- "RELATIVE": true,
- "RELEASE": true,
- "RENAME": true,
- "REPEATABLE": true,
- "REPLACE": true,
- "REPLICA": true,
- "REQUIRING": true,
- "RESET": true,
- "RESPECT": true,
- "RESTART": true,
- "RESTORE": true,
- "RESTRICT": true,
- "RESULT": true,
- "RETURN": true,
- "RETURNED_CARDINALITY": true,
- "RETURNED_LENGTH": true,
- "RETURNED_OCTET_LENGTH": true,
- "RETURNED_SQLSTATE": true,
- "RETURNING": true,
- "RETURNS": true,
- "REVOKE": true,
- "RIGHT": true,
- "ROLE": true,
- "ROLLBACK": true,
- "ROLLUP": true,
- "ROUTINE": true,
- "ROUTINE_CATALOG": true,
- "ROUTINE_NAME": true,
- "ROUTINE_SCHEMA": true,
- "ROW": true,
- "ROWS": true,
- "ROW_COUNT": true,
- "ROW_NUMBER": true,
- "RULE": true,
- "SAVEPOINT": true,
- "SCALE": true,
- "SCHEMA": true,
- "SCHEMA_NAME": true,
- "SCOPE": true,
- "SCOPE_CATALOG": true,
- "SCOPE_NAME": true,
- "SCOPE_SCHEMA": true,
- "SCROLL": true,
- "SEARCH": true,
- "SECOND": true,
- "SECTION": true,
- "SECURITY": true,
- "SELECT": true,
- "SELECTIVE": true,
- "SELF": true,
- "SENSITIVE": true,
- "SEQUENCE": true,
- "SEQUENCES": true,
- "SERIALIZABLE": true,
- "SERVER": true,
- "SERVER_NAME": true,
- "SESSION": true,
- "SESSION_USER": true,
- "SET": true,
- "SETOF": true,
- "SETS": true,
- "SHARE": true,
- "SHOW": true,
- "SIMILAR": true,
- "SIMPLE": true,
- "SIZE": true,
- "SMALLINT": true,
- "SNAPSHOT": true,
- "SOME": true,
- "SOURCE": true,
- "SPACE": true,
- "SPECIFIC": true,
- "SPECIFICTYPE": true,
- "SPECIFIC_NAME": true,
- "SQL": true,
- "SQLCODE": true,
- "SQLERROR": true,
- "SQLEXCEPTION": true,
- "SQLSTATE": true,
- "SQLWARNING": true,
- "SQRT": true,
- "STABLE": true,
- "STANDALONE": true,
- "START": true,
- "STATE": true,
- "STATEMENT": true,
- "STATIC": true,
- "STATISTICS": true,
- "STDDEV_POP": true,
- "STDDEV_SAMP": true,
- "STDIN": true,
- "STDOUT": true,
- "STORAGE": true,
- "STRICT": true,
- "STRIP": true,
- "STRUCTURE": true,
- "STYLE": true,
- "SUBCLASS_ORIGIN": true,
- "SUBMULTISET": true,
- "SUBSTRING": true,
- "SUBSTRING_REGEX": true,
- "SUCCEEDS": true,
- "SUM": true,
- "SYMMETRIC": true,
- "SYSID": true,
- "SYSTEM": true,
- "SYSTEM_TIME": true,
- "SYSTEM_USER": true,
- "T": true,
- "TABLE": true,
- "TABLES": true,
- "TABLESAMPLE": true,
- "TABLESPACE": true,
- "TABLE_NAME": true,
- "TEMP": true,
- "TEMPLATE": true,
- "TEMPORARY": true,
- "TEXT": true,
- "THEN": true,
- "TIES": true,
- "TIME": true,
- "TIMESTAMP": true,
- "TIMEZONE_HOUR": true,
- "TIMEZONE_MINUTE": true,
- "TO": true,
- "TOKEN": true,
- "TOP_LEVEL_COUNT": true,
- "TRAILING": true,
- "TRANSACTION": true,
- "TRANSACTIONS_COMMITTED": true,
- "TRANSACTIONS_ROLLED_BACK": true,
- "TRANSACTION_ACTIVE": true,
- "TRANSFORM": true,
- "TRANSFORMS": true,
- "TRANSLATE": true,
- "TRANSLATE_REGEX": true,
- "TRANSLATION": true,
- "TREAT": true,
- "TRIGGER": true,
- "TRIGGER_CATALOG": true,
- "TRIGGER_NAME": true,
- "TRIGGER_SCHEMA": true,
- "TRIM": true,
- "TRIM_ARRAY": true,
- "TRUE": true,
- "TRUNCATE": true,
- "TRUSTED": true,
- "TYPE": true,
- "TYPES": true,
- "UESCAPE": true,
- "UNBOUNDED": true,
- "UNCOMMITTED": true,
- "UNDER": true,
- "UNENCRYPTED": true,
- "UNION": true,
- "UNIQUE": true,
- "UNKNOWN": true,
- "UNLINK": true,
- "UNLISTEN": true,
- "UNLOGGED": true,
- "UNNAMED": true,
- "UNNEST": true,
- "UNTIL": true,
- "UNTYPED": true,
- "UPDATE": true,
- "UPPER": true,
- "URI": true,
- "USAGE": true,
- "USER": true,
- "USER_DEFINED_TYPE_CATALOG": true,
- "USER_DEFINED_TYPE_CODE": true,
- "USER_DEFINED_TYPE_NAME": true,
- "USER_DEFINED_TYPE_SCHEMA": true,
- "USING": true,
- "VACUUM": true,
- "VALID": true,
- "VALIDATE": true,
- "VALIDATOR": true,
- "VALUE": true,
- "VALUES": true,
- "VALUE_OF": true,
- "VARBINARY": true,
- "VARCHAR": true,
- "VARIADIC": true,
- "VARYING": true,
- "VAR_POP": true,
- "VAR_SAMP": true,
- "VERBOSE": true,
- "VERSION": true,
- "VERSIONING": true,
- "VIEW": true,
- "VOLATILE": true,
- "WHEN": true,
- "WHENEVER": true,
- "WHERE": true,
- "WHITESPACE": true,
- "WIDTH_BUCKET": true,
- "WINDOW": true,
- "WITH": true,
- "WITHIN": true,
- "WITHOUT": true,
- "WORK": true,
- "WRAPPER": true,
- "WRITE": true,
- "XML": true,
- "XMLAGG": true,
- "XMLATTRIBUTES": true,
- "XMLBINARY": true,
- "XMLCAST": true,
- "XMLCOMMENT": true,
- "XMLCONCAT": true,
- "XMLDECLARATION": true,
- "XMLDOCUMENT": true,
- "XMLELEMENT": true,
- "XMLEXISTS": true,
- "XMLFOREST": true,
- "XMLITERATE": true,
- "XMLNAMESPACES": true,
- "XMLPARSE": true,
- "XMLPI": true,
- "XMLQUERY": true,
- "XMLROOT": true,
- "XMLSCHEMA": true,
- "XMLSERIALIZE": true,
- "XMLTABLE": true,
- "XMLTEXT": true,
- "XMLVALIDATE": true,
- "YEAR": true,
- "YES": true,
- "ZONE": true,
- }
-
- postgresQuoter = schemas.Quoter{
- Prefix: '"',
- Suffix: '"',
- IsReserved: schemas.AlwaysReserve,
- }
-)
-
-var (
- // DefaultPostgresSchema default postgres schema
- DefaultPostgresSchema = "public"
- postgresColAliases = map[string]string{
- "numeric": "decimal",
- }
-)
-
-type postgres struct {
- Base
-}
-
-// Alias returns a alias of column
-func (db *postgres) Alias(col string) string {
- v, ok := postgresColAliases[strings.ToLower(col)]
- if ok {
- return v
- }
- return col
-}
-
-func (db *postgres) Init(uri *URI) error {
- db.quoter = postgresQuoter
- return db.Base.Init(db, uri)
-}
-
-func (db *postgres) Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) {
- rows, err := queryer.QueryContext(ctx, "SELECT version()")
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- var version string
- if !rows.Next() {
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return nil, errors.New("unknow version")
- }
-
- if err := rows.Scan(&version); err != nil {
- return nil, err
- }
-
- // Postgres: 9.5.22 on x86_64-pc-linux-gnu (Debian 9.5.22-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit
- // CockroachDB CCL v19.2.4 (x86_64-unknown-linux-gnu, built
- if strings.HasPrefix(version, "CockroachDB") {
- versions := strings.Split(strings.TrimPrefix(version, "CockroachDB CCL "), " ")
- return &schemas.Version{
- Number: strings.TrimPrefix(versions[0], "v"),
- Edition: "CockroachDB",
- }, nil
- } else if strings.HasPrefix(version, "PostgreSQL") {
- versions := strings.Split(strings.TrimPrefix(version, "PostgreSQL "), " on ")
- return &schemas.Version{
- Number: versions[0],
- Level: versions[1],
- Edition: "PostgreSQL",
- }, nil
- }
-
- return nil, errors.New("unknow database version")
-}
-
-func (db *postgres) getSchema() string {
- if db.uri.Schema != "" {
- return db.uri.Schema
- }
- return DefaultPostgresSchema
-}
-
-func (db *postgres) needQuote(name string) bool {
- if db.IsReserved(name) {
- return true
- }
- for _, c := range name {
- if c >= 'A' && c <= 'Z' {
- return true
- }
- }
- return false
-}
-
-func (db *postgres) SetQuotePolicy(quotePolicy QuotePolicy) {
- switch quotePolicy {
- case QuotePolicyNone:
- var q = postgresQuoter
- q.IsReserved = schemas.AlwaysNoReserve
- db.quoter = q
- case QuotePolicyReserved:
- var q = postgresQuoter
- q.IsReserved = db.needQuote
- db.quoter = q
- case QuotePolicyAlways:
- fallthrough
- default:
- db.quoter = postgresQuoter
- }
-}
-
-func (db *postgres) SQLType(c *schemas.Column) string {
- var res string
- switch t := c.SQLType.Name; t {
- case schemas.TinyInt, schemas.UnsignedTinyInt:
- res = schemas.SmallInt
- return res
- case schemas.Bit:
- res = schemas.Boolean
- return res
- case schemas.MediumInt, schemas.Int, schemas.Integer, schemas.UnsignedMediumInt, schemas.UnsignedSmallInt:
- if c.IsAutoIncrement {
- return schemas.Serial
- }
- return schemas.Integer
- case schemas.BigInt, schemas.UnsignedBigInt, schemas.UnsignedInt:
- if c.IsAutoIncrement {
- return schemas.BigSerial
- }
- return schemas.BigInt
- case schemas.Serial, schemas.BigSerial:
- c.IsAutoIncrement = true
- c.Nullable = false
- res = t
- case schemas.Binary, schemas.VarBinary:
- return schemas.Bytea
- case schemas.DateTime:
- res = schemas.TimeStamp
- case schemas.TimeStampz:
- return "timestamp with time zone"
- case schemas.Float:
- res = schemas.Real
- case schemas.TinyText, schemas.MediumText, schemas.LongText:
- res = schemas.Text
- case schemas.NChar:
- res = schemas.Char
- case schemas.NVarchar:
- res = schemas.Varchar
- case schemas.Uuid:
- return schemas.Uuid
- case schemas.Blob, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob:
- return schemas.Bytea
- case schemas.Double:
- return "DOUBLE PRECISION"
- default:
- if c.IsAutoIncrement {
- return schemas.Serial
- }
- res = t
- }
-
- if strings.EqualFold(res, "bool") {
- // for bool, we don't need length information
- return res
- }
- hasLen1 := (c.Length > 0)
- hasLen2 := (c.Length2 > 0)
-
- if hasLen2 {
- res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
- } else if hasLen1 {
- res += "(" + strconv.Itoa(c.Length) + ")"
- }
- return res
-}
-
-func (db *postgres) ColumnTypeKind(t string) int {
- switch strings.ToUpper(t) {
- case "DATETIME", "TIMESTAMP":
- return schemas.TIME_TYPE
- case "VARCHAR", "TEXT":
- return schemas.TEXT_TYPE
- case "BIGINT", "BIGSERIAL", "SMALLINT", "INT", "INT8", "INT4", "INTEGER", "SERIAL", "FLOAT", "FLOAT4", "REAL", "DOUBLE PRECISION":
- return schemas.NUMERIC_TYPE
- case "BOOL":
- return schemas.BOOL_TYPE
- default:
- return schemas.UNKNOW_TYPE
- }
-}
-
-func (db *postgres) IsReserved(name string) bool {
- _, ok := postgresReservedWords[strings.ToUpper(name)]
- return ok
-}
-
-func (db *postgres) AutoIncrStr() string {
- return ""
-}
-
-func (db *postgres) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
- if len(db.getSchema()) == 0 {
- args := []interface{}{tableName, idxName}
- return `SELECT indexname FROM pg_indexes WHERE tablename = ? AND indexname = ?`, args
- }
-
- args := []interface{}{db.getSchema(), tableName, idxName}
- return `SELECT indexname FROM pg_indexes ` +
- `WHERE schemaname = ? AND tablename = ? AND indexname = ?`, args
-}
-
-func (db *postgres) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
- if len(db.getSchema()) == 0 {
- return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE tablename = $1`, tableName)
- }
-
- return db.HasRecords(queryer, ctx, `SELECT tablename FROM pg_tables WHERE schemaname = $1 AND tablename = $2`,
- db.getSchema(), tableName)
-}
-
-func (db *postgres) ModifyColumnSQL(tableName string, col *schemas.Column) string {
- if len(db.getSchema()) == 0 || strings.Contains(tableName, ".") {
- return fmt.Sprintf("alter table %s ALTER COLUMN %s TYPE %s",
- db.quoter.Quote(tableName), db.quoter.Quote(col.Name), db.SQLType(col))
- }
- return fmt.Sprintf("alter table %s.%s ALTER COLUMN %s TYPE %s",
- db.quoter.Quote(db.getSchema()), db.quoter.Quote(tableName), db.quoter.Quote(col.Name), db.SQLType(col))
-}
-
-func (db *postgres) DropIndexSQL(tableName string, index *schemas.Index) string {
- idxName := index.Name
-
- tableParts := strings.Split(strings.Replace(tableName, `"`, "", -1), ".")
- tableName = tableParts[len(tableParts)-1]
-
- if !strings.HasPrefix(idxName, "UQE_") &&
- !strings.HasPrefix(idxName, "IDX_") {
- if index.Type == schemas.UniqueType {
- idxName = fmt.Sprintf("UQE_%v_%v", tableName, index.Name)
- } else {
- idxName = fmt.Sprintf("IDX_%v_%v", tableName, index.Name)
- }
- }
- if db.getSchema() != "" {
- idxName = db.getSchema() + "." + idxName
- }
- return fmt.Sprintf("DROP INDEX %v", db.Quoter().Quote(idxName))
-}
-
-func (db *postgres) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
- args := []interface{}{db.getSchema(), tableName, colName}
- query := "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = $1 AND table_name = $2" +
- " AND column_name = $3"
- if len(db.getSchema()) == 0 {
- args = []interface{}{tableName, colName}
- query = "SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = $1" +
- " AND column_name = $2"
- }
-
- rows, err := queryer.QueryContext(ctx, query, args...)
- if err != nil {
- return false, err
- }
- defer rows.Close()
-
- if rows.Next() {
- return true, nil
- }
- return false, rows.Err()
-}
-
-func (db *postgres) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
- args := []interface{}{tableName}
- s := `SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, description,
- CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
- CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
-FROM pg_attribute f
- JOIN pg_class c ON c.oid = f.attrelid JOIN pg_type t ON t.oid = f.atttypid
- LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
- LEFT JOIN pg_description de ON f.attrelid=de.objoid AND f.attnum=de.objsubid
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
- LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
- LEFT JOIN pg_class AS g ON p.confrelid = g.oid
- LEFT JOIN INFORMATION_SCHEMA.COLUMNS s ON s.column_name=f.attname AND c.relname=s.table_name
-WHERE n.nspname= s.table_schema AND c.relkind = 'r'::char AND c.relname = $1%s AND f.attnum > 0 ORDER BY f.attnum;`
-
- schema := db.getSchema()
- if schema != "" {
- s = fmt.Sprintf(s, " AND s.table_schema = $2")
- args = append(args, schema)
- } else {
- s = fmt.Sprintf(s, "")
- }
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, nil, err
- }
- defer rows.Close()
-
- cols := make(map[string]*schemas.Column)
- colSeq := make([]string, 0)
-
- for rows.Next() {
- col := new(schemas.Column)
- col.Indexes = make(map[string]int)
-
- var colName, isNullable, dataType string
- var maxLenStr, colDefault, description *string
- var isPK, isUnique bool
- err = rows.Scan(&colName, &colDefault, &isNullable, &dataType, &maxLenStr, &description, &isPK, &isUnique)
- if err != nil {
- return nil, nil, err
- }
-
- var maxLen int
- if maxLenStr != nil {
- maxLen, err = strconv.Atoi(*maxLenStr)
- if err != nil {
- return nil, nil, err
- }
- }
-
- if colDefault != nil && *colDefault == "unique_rowid()" { // ignore the system column added by cockroach
- continue
- }
-
- col.Name = strings.Trim(colName, `" `)
-
- if colDefault != nil {
- var theDefault = *colDefault
- // cockroach has type with the default value with :::
- // and postgres with ::, we should remove them before store them
- idx := strings.Index(theDefault, ":::")
- if idx == -1 {
- idx = strings.Index(theDefault, "::")
- }
- if idx > -1 {
- theDefault = theDefault[:idx]
- }
-
- if strings.HasSuffix(theDefault, "+00:00'") {
- theDefault = theDefault[:len(theDefault)-7] + "'"
- }
-
- col.Default = theDefault
- col.DefaultIsEmpty = false
- if strings.HasPrefix(col.Default, "nextval(") {
- col.IsAutoIncrement = true
- col.Default = ""
- col.DefaultIsEmpty = true
- }
- } else {
- col.DefaultIsEmpty = true
- }
-
- if description != nil {
- col.Comment = *description
- }
-
- if isPK {
- col.IsPrimaryKey = true
- }
-
- col.Nullable = (isNullable == "YES")
-
- switch strings.ToLower(dataType) {
- case "character varying", "string":
- col.SQLType = schemas.SQLType{Name: schemas.Varchar, DefaultLength: 0, DefaultLength2: 0}
- case "character":
- col.SQLType = schemas.SQLType{Name: schemas.Char, DefaultLength: 0, DefaultLength2: 0}
- case "timestamp without time zone":
- col.SQLType = schemas.SQLType{Name: schemas.DateTime, DefaultLength: 0, DefaultLength2: 0}
- case "timestamp with time zone":
- col.SQLType = schemas.SQLType{Name: schemas.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
- case "double precision":
- col.SQLType = schemas.SQLType{Name: schemas.Double, DefaultLength: 0, DefaultLength2: 0}
- case "boolean":
- col.SQLType = schemas.SQLType{Name: schemas.Bool, DefaultLength: 0, DefaultLength2: 0}
- case "time without time zone":
- col.SQLType = schemas.SQLType{Name: schemas.Time, DefaultLength: 0, DefaultLength2: 0}
- case "bytes":
- col.SQLType = schemas.SQLType{Name: schemas.Binary, DefaultLength: 0, DefaultLength2: 0}
- case "oid":
- col.SQLType = schemas.SQLType{Name: schemas.BigInt, DefaultLength: 0, DefaultLength2: 0}
- case "array":
- col.SQLType = schemas.SQLType{Name: schemas.Array, DefaultLength: 0, DefaultLength2: 0}
- default:
- startIdx := strings.Index(strings.ToLower(dataType), "string(")
- if startIdx != -1 && strings.HasSuffix(dataType, ")") {
- length := dataType[startIdx+8 : len(dataType)-1]
- l, _ := strconv.Atoi(length)
- col.SQLType = schemas.SQLType{Name: "STRING", DefaultLength: l, DefaultLength2: 0}
- } else {
- col.SQLType = schemas.SQLType{Name: strings.ToUpper(dataType), DefaultLength: 0, DefaultLength2: 0}
- }
- }
- if _, ok := schemas.SqlTypes[col.SQLType.Name]; !ok {
- return nil, nil, fmt.Errorf("unknown colType: %s - %s", dataType, col.SQLType.Name)
- }
-
- col.Length = maxLen
-
- if !col.DefaultIsEmpty {
- if col.SQLType.IsText() {
- if strings.HasSuffix(col.Default, "::character varying") {
- col.Default = strings.TrimSuffix(col.Default, "::character varying")
- } else if !strings.HasPrefix(col.Default, "'") {
- col.Default = "'" + col.Default + "'"
- }
- } else if col.SQLType.IsTime() {
- if strings.HasSuffix(col.Default, "::timestamp without time zone") {
- col.Default = strings.TrimSuffix(col.Default, "::timestamp without time zone")
- }
- }
- }
- cols[col.Name] = col
- colSeq = append(colSeq, col.Name)
- }
- if rows.Err() != nil {
- return nil, nil, rows.Err()
- }
-
- return colSeq, cols, nil
-}
-
-func (db *postgres) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
- args := []interface{}{}
- s := "SELECT tablename FROM pg_tables"
- schema := db.getSchema()
- if schema != "" {
- args = append(args, schema)
- s = s + " WHERE schemaname = $1"
- }
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- tables := make([]*schemas.Table, 0)
- for rows.Next() {
- table := schemas.NewEmptyTable()
- var name string
- err = rows.Scan(&name)
- if err != nil {
- return nil, err
- }
- table.Name = name
- tables = append(tables, table)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return tables, nil
-}
-
-func getIndexColName(indexdef string) []string {
- var colNames []string
-
- cs := strings.Split(indexdef, "(")
- for _, v := range strings.Split(strings.Split(cs[1], ")")[0], ",") {
- colNames = append(colNames, strings.Split(strings.TrimLeft(v, " "), " ")[0])
- }
-
- return colNames
-}
-
-func (db *postgres) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
- args := []interface{}{tableName}
- s := "SELECT indexname, indexdef FROM pg_indexes WHERE tablename=$1"
- if len(db.getSchema()) != 0 {
- args = append(args, db.getSchema())
- s = s + " AND schemaname=$2"
- }
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- indexes := make(map[string]*schemas.Index)
- for rows.Next() {
- var indexType int
- var indexName, indexdef string
- var colNames []string
- err = rows.Scan(&indexName, &indexdef)
- if err != nil {
- return nil, err
- }
-
- if indexName == "primary" {
- continue
- }
- indexName = strings.Trim(indexName, `" `)
- // ignore primary index
- if strings.HasSuffix(indexName, "_pkey") || strings.EqualFold(indexName, "primary") {
- continue
- }
- if strings.HasPrefix(indexdef, "CREATE UNIQUE INDEX") {
- indexType = schemas.UniqueType
- } else {
- indexType = schemas.IndexType
- }
- colNames = getIndexColName(indexdef)
- var isRegular bool
- if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
- newIdxName := indexName[5+len(tableName):]
- isRegular = true
- if newIdxName != "" {
- indexName = newIdxName
- }
- }
-
- index := &schemas.Index{Name: indexName, Type: indexType, Cols: make([]string, 0)}
- for _, colName := range colNames {
- col := strings.TrimSpace(strings.Replace(colName, `"`, "", -1))
- fields := strings.Split(col, " ")
- index.Cols = append(index.Cols, fields[0])
- }
- index.IsRegular = isRegular
- indexes[index.Name] = index
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return indexes, nil
-}
-
-func (db *postgres) Filters() []Filter {
- return []Filter{&SeqFilter{Prefix: "$", Start: 1}}
-}
-
-type pqDriver struct {
- baseDriver
-}
-
-type values map[string]string
-
-func parseURL(connstr string) (string, error) {
- u, err := url.Parse(connstr)
- if err != nil {
- return "", err
- }
-
- if u.Scheme != "postgresql" && u.Scheme != "postgres" {
- return "", fmt.Errorf("invalid connection protocol: %s", u.Scheme)
- }
-
- escaper := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`)
-
- if u.Path != "" {
- return escaper.Replace(u.Path[1:]), nil
- }
-
- return "", nil
-}
-
-func parseOpts(urlStr string, o values) error {
- if len(urlStr) == 0 {
- return fmt.Errorf("invalid options: %s", urlStr)
- }
-
- urlStr = strings.TrimSpace(urlStr)
-
- var (
- inQuote bool
- state int // 0 key, 1 space, 2 value, 3 equal
- start int
- key string
- )
- for i, c := range urlStr {
- switch c {
- case ' ':
- if !inQuote {
- if state == 2 {
- state = 1
- v := urlStr[start:i]
- if strings.HasPrefix(v, "'") && strings.HasSuffix(v, "'") {
- v = v[1 : len(v)-1]
- } else if strings.HasPrefix(v, "'") || strings.HasSuffix(v, "'") {
- return fmt.Errorf("wrong single quote in %d of %s", i, urlStr)
- }
- o[key] = v
- } else if state != 1 {
- return fmt.Errorf("wrong format: %v", urlStr)
- }
- }
- case '\'':
- if state == 3 {
- state = 2
- start = i
- } else if state != 2 {
- return fmt.Errorf("wrong format: %v", urlStr)
- }
- inQuote = !inQuote
- case '=':
- if !inQuote {
- if state != 0 {
- return fmt.Errorf("wrong format: %v", urlStr)
- }
- key = urlStr[start:i]
- state = 3
- }
- default:
- if state == 3 {
- state = 2
- start = i
- } else if state == 1 {
- state = 0
- start = i
- }
- }
-
- if i == len(urlStr)-1 {
- if state != 2 {
- return errors.New("no value matched key")
- }
- v := urlStr[start : i+1]
- if strings.HasPrefix(v, "'") && strings.HasSuffix(v, "'") {
- v = v[1 : len(v)-1]
- } else if strings.HasPrefix(v, "'") || strings.HasSuffix(v, "'") {
- return fmt.Errorf("wrong single quote in %d of %s", i, urlStr)
- }
- o[key] = v
- }
- }
-
- return nil
-}
-
-func (p *pqDriver) Features() *DriverFeatures {
- return &DriverFeatures{
- SupportReturnInsertedID: false,
- }
-}
-
-func (p *pqDriver) Parse(driverName, dataSourceName string) (*URI, error) {
- db := &URI{DBType: schemas.POSTGRES}
-
- var err error
- if strings.Contains(dataSourceName, "://") {
- if !strings.HasPrefix(dataSourceName, "postgresql://") && !strings.HasPrefix(dataSourceName, "postgres://") {
- return nil, fmt.Errorf("unsupported protocol %v", dataSourceName)
- }
-
- db.DBName, err = parseURL(dataSourceName)
- if err != nil {
- return nil, err
- }
- } else {
- o := make(values)
- err = parseOpts(dataSourceName, o)
- if err != nil {
- return nil, err
- }
-
- db.DBName = o["dbname"]
- }
-
- if db.DBName == "" {
- return nil, errors.New("dbname is empty")
- }
-
- return db, nil
-}
-
-func (p *pqDriver) GenScanResult(colType string) (interface{}, error) {
- switch colType {
- case "VARCHAR", "TEXT":
- var s sql.NullString
- return &s, nil
- case "BIGINT", "BIGSERIAL":
- var s sql.NullInt64
- return &s, nil
- case "SMALLINT", "INT", "INT8", "INT4", "INTEGER", "SERIAL":
- var s sql.NullInt32
- return &s, nil
- case "FLOAT", "FLOAT4", "REAL", "DOUBLE PRECISION":
- var s sql.NullFloat64
- return &s, nil
- case "DATETIME", "TIMESTAMP":
- var s sql.NullTime
- return &s, nil
- case "BOOL":
- var s sql.NullBool
- return &s, nil
- default:
- var r sql.RawBytes
- return &r, nil
- }
-}
-
-type pqDriverPgx struct {
- pqDriver
-}
-
-func (pgx *pqDriverPgx) Parse(driverName, dataSourceName string) (*URI, error) {
- // Remove the leading characters for driver to work
- if len(dataSourceName) >= 9 && dataSourceName[0] == 0 {
- dataSourceName = dataSourceName[9:]
- }
- return pgx.pqDriver.Parse(driverName, dataSourceName)
-}
-
-// QueryDefaultPostgresSchema returns the default postgres schema
-func QueryDefaultPostgresSchema(ctx context.Context, queryer core.Queryer) (string, error) {
- rows, err := queryer.QueryContext(ctx, "SHOW SEARCH_PATH")
- if err != nil {
- return "", err
- }
- defer rows.Close()
- if rows.Next() {
- var defaultSchema string
- if err = rows.Scan(&defaultSchema); err != nil {
- return "", err
- }
- parts := strings.Split(defaultSchema, ",")
- return strings.TrimSpace(parts[len(parts)-1]), nil
- }
- if rows.Err() != nil {
- return "", rows.Err()
- }
-
- return "", errors.New("no default schema")
-}
diff --git a/vendor/xorm.io/xorm/dialects/quote.go b/vendor/xorm.io/xorm/dialects/quote.go
deleted file mode 100644
index da4e0dd609..0000000000
--- a/vendor/xorm.io/xorm/dialects/quote.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2020 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-// QuotePolicy describes quote handle policy
-type QuotePolicy int
-
-// All QuotePolicies
-const (
- QuotePolicyAlways QuotePolicy = iota
- QuotePolicyNone
- QuotePolicyReserved
-)
diff --git a/vendor/xorm.io/xorm/dialects/sqlite3.go b/vendor/xorm.io/xorm/dialects/sqlite3.go
deleted file mode 100644
index 4eba8dad9f..0000000000
--- a/vendor/xorm.io/xorm/dialects/sqlite3.go
+++ /dev/null
@@ -1,572 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "context"
- "database/sql"
- "errors"
- "fmt"
- "regexp"
- "strings"
-
- "xorm.io/xorm/core"
- "xorm.io/xorm/schemas"
-)
-
-var (
- sqlite3ReservedWords = map[string]bool{
- "ABORT": true,
- "ACTION": true,
- "ADD": true,
- "AFTER": true,
- "ALL": true,
- "ALTER": true,
- "ANALYZE": true,
- "AND": true,
- "AS": true,
- "ASC": true,
- "ATTACH": true,
- "AUTOINCREMENT": true,
- "BEFORE": true,
- "BEGIN": true,
- "BETWEEN": true,
- "BY": true,
- "CASCADE": true,
- "CASE": true,
- "CAST": true,
- "CHECK": true,
- "COLLATE": true,
- "COLUMN": true,
- "COMMIT": true,
- "CONFLICT": true,
- "CONSTRAINT": true,
- "CREATE": true,
- "CROSS": true,
- "CURRENT_DATE": true,
- "CURRENT_TIME": true,
- "CURRENT_TIMESTAMP": true,
- "DATABASE": true,
- "DEFAULT": true,
- "DEFERRABLE": true,
- "DEFERRED": true,
- "DELETE": true,
- "DESC": true,
- "DETACH": true,
- "DISTINCT": true,
- "DROP": true,
- "EACH": true,
- "ELSE": true,
- "END": true,
- "ESCAPE": true,
- "EXCEPT": true,
- "EXCLUSIVE": true,
- "EXISTS": true,
- "EXPLAIN": true,
- "FAIL": true,
- "FOR": true,
- "FOREIGN": true,
- "FROM": true,
- "FULL": true,
- "GLOB": true,
- "GROUP": true,
- "HAVING": true,
- "IF": true,
- "IGNORE": true,
- "IMMEDIATE": true,
- "IN": true,
- "INDEX": true,
- "INDEXED": true,
- "INITIALLY": true,
- "INNER": true,
- "INSERT": true,
- "INSTEAD": true,
- "INTERSECT": true,
- "INTO": true,
- "IS": true,
- "ISNULL": true,
- "JOIN": true,
- "KEY": true,
- "LEFT": true,
- "LIKE": true,
- "LIMIT": true,
- "MATCH": true,
- "NATURAL": true,
- "NO": true,
- "NOT": true,
- "NOTNULL": true,
- "NULL": true,
- "OF": true,
- "OFFSET": true,
- "ON": true,
- "OR": true,
- "ORDER": true,
- "OUTER": true,
- "PLAN": true,
- "PRAGMA": true,
- "PRIMARY": true,
- "QUERY": true,
- "RAISE": true,
- "RECURSIVE": true,
- "REFERENCES": true,
- "REGEXP": true,
- "REINDEX": true,
- "RELEASE": true,
- "RENAME": true,
- "REPLACE": true,
- "RESTRICT": true,
- "RIGHT": true,
- "ROLLBACK": true,
- "ROW": true,
- "SAVEPOINT": true,
- "SELECT": true,
- "SET": true,
- "TABLE": true,
- "TEMP": true,
- "TEMPORARY": true,
- "THEN": true,
- "TO": true,
- "TRANSACTI": true,
- "TRIGGER": true,
- "UNION": true,
- "UNIQUE": true,
- "UPDATE": true,
- "USING": true,
- "VACUUM": true,
- "VALUES": true,
- "VIEW": true,
- "VIRTUAL": true,
- "WHEN": true,
- "WHERE": true,
- "WITH": true,
- "WITHOUT": true,
- }
-
- sqlite3Quoter = schemas.Quoter{
- Prefix: '`',
- Suffix: '`',
- IsReserved: schemas.AlwaysReserve,
- }
-)
-
-type sqlite3 struct {
- Base
-}
-
-func (db *sqlite3) Init(uri *URI) error {
- db.quoter = sqlite3Quoter
- return db.Base.Init(db, uri)
-}
-
-func (db *sqlite3) Version(ctx context.Context, queryer core.Queryer) (*schemas.Version, error) {
- rows, err := queryer.QueryContext(ctx, "SELECT sqlite_version()")
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- var version string
- if !rows.Next() {
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return nil, errors.New("unknow version")
- }
-
- if err := rows.Scan(&version); err != nil {
- return nil, err
- }
- return &schemas.Version{
- Number: version,
- Edition: "sqlite",
- }, nil
-}
-
-func (db *sqlite3) SetQuotePolicy(quotePolicy QuotePolicy) {
- switch quotePolicy {
- case QuotePolicyNone:
- var q = sqlite3Quoter
- q.IsReserved = schemas.AlwaysNoReserve
- db.quoter = q
- case QuotePolicyReserved:
- var q = sqlite3Quoter
- q.IsReserved = db.IsReserved
- db.quoter = q
- case QuotePolicyAlways:
- fallthrough
- default:
- db.quoter = sqlite3Quoter
- }
-}
-
-func (db *sqlite3) SQLType(c *schemas.Column) string {
- switch t := c.SQLType.Name; t {
- case schemas.Bool:
- if c.Default == "true" {
- c.Default = "1"
- } else if c.Default == "false" {
- c.Default = "0"
- }
- return schemas.Integer
- case schemas.Date, schemas.DateTime, schemas.TimeStamp, schemas.Time:
- return schemas.DateTime
- case schemas.TimeStampz:
- return schemas.Text
- case schemas.Char, schemas.Varchar, schemas.NVarchar, schemas.TinyText,
- schemas.Text, schemas.MediumText, schemas.LongText, schemas.Json:
- return schemas.Text
- case schemas.Bit, schemas.TinyInt, schemas.UnsignedTinyInt, schemas.SmallInt,
- schemas.UnsignedSmallInt, schemas.MediumInt, schemas.Int, schemas.UnsignedInt,
- schemas.BigInt, schemas.UnsignedBigInt, schemas.Integer:
- return schemas.Integer
- case schemas.Float, schemas.Double, schemas.Real:
- return schemas.Real
- case schemas.Decimal, schemas.Numeric:
- return schemas.Numeric
- case schemas.TinyBlob, schemas.Blob, schemas.MediumBlob, schemas.LongBlob, schemas.Bytea, schemas.Binary, schemas.VarBinary:
- return schemas.Blob
- case schemas.Serial, schemas.BigSerial:
- c.IsPrimaryKey = true
- c.IsAutoIncrement = true
- c.Nullable = false
- return schemas.Integer
- default:
- return t
- }
-}
-
-func (db *sqlite3) ColumnTypeKind(t string) int {
- switch strings.ToUpper(t) {
- case "DATETIME":
- return schemas.TIME_TYPE
- case "TEXT":
- return schemas.TEXT_TYPE
- case "INTEGER", "REAL", "NUMERIC", "DECIMAL":
- return schemas.NUMERIC_TYPE
- case "BLOB":
- return schemas.BLOB_TYPE
- default:
- return schemas.UNKNOW_TYPE
- }
-}
-
-func (db *sqlite3) IsReserved(name string) bool {
- _, ok := sqlite3ReservedWords[strings.ToUpper(name)]
- return ok
-}
-
-func (db *sqlite3) AutoIncrStr() string {
- return "AUTOINCREMENT"
-}
-
-func (db *sqlite3) IndexCheckSQL(tableName, idxName string) (string, []interface{}) {
- args := []interface{}{idxName}
- return "SELECT name FROM sqlite_master WHERE type='index' and name = ?", args
-}
-
-func (db *sqlite3) IsTableExist(queryer core.Queryer, ctx context.Context, tableName string) (bool, error) {
- return db.HasRecords(queryer, ctx, "SELECT name FROM sqlite_master WHERE type='table' and name = ?", tableName)
-}
-
-func (db *sqlite3) DropIndexSQL(tableName string, index *schemas.Index) string {
- // var unique string
- idxName := index.Name
-
- if !strings.HasPrefix(idxName, "UQE_") &&
- !strings.HasPrefix(idxName, "IDX_") {
- if index.Type == schemas.UniqueType {
- idxName = fmt.Sprintf("UQE_%v_%v", tableName, index.Name)
- } else {
- idxName = fmt.Sprintf("IDX_%v_%v", tableName, index.Name)
- }
- }
- return fmt.Sprintf("DROP INDEX %v", db.Quoter().Quote(idxName))
-}
-
-func (db *sqlite3) ForUpdateSQL(query string) string {
- return query
-}
-
-func (db *sqlite3) IsColumnExist(queryer core.Queryer, ctx context.Context, tableName, colName string) (bool, error) {
- query := "SELECT * FROM " + tableName + " LIMIT 0"
- rows, err := queryer.QueryContext(ctx, query)
- if err != nil {
- return false, err
- }
- defer rows.Close()
-
- cols, err := rows.Columns()
- if err != nil {
- return false, err
- }
-
- for _, col := range cols {
- if strings.EqualFold(col, colName) {
- return true, nil
- }
- }
-
- return false, nil
-}
-
-// splitColStr splits a sqlite col strings as fields
-func splitColStr(colStr string) []string {
- colStr = strings.TrimSpace(colStr)
- var results = make([]string, 0, 10)
- var lastIdx int
- var hasC, hasQuote bool
- for i, c := range colStr {
- if c == ' ' && !hasQuote {
- if hasC {
- results = append(results, colStr[lastIdx:i])
- hasC = false
- }
- } else {
- if c == '\'' {
- hasQuote = !hasQuote
- }
- if !hasC {
- lastIdx = i
- }
- hasC = true
- if i == len(colStr)-1 {
- results = append(results, colStr[lastIdx:i+1])
- }
- }
- }
- return results
-}
-
-func parseString(colStr string) (*schemas.Column, error) {
- fields := splitColStr(colStr)
- col := new(schemas.Column)
- col.Indexes = make(map[string]int)
- col.Nullable = true
- col.DefaultIsEmpty = true
-
- for idx, field := range fields {
- if idx == 0 {
- col.Name = strings.Trim(strings.Trim(field, "`[] "), `"`)
- continue
- } else if idx == 1 {
- col.SQLType = schemas.SQLType{Name: field, DefaultLength: 0, DefaultLength2: 0}
- continue
- }
- switch field {
- case "PRIMARY":
- col.IsPrimaryKey = true
- case "AUTOINCREMENT":
- col.IsAutoIncrement = true
- case "NULL":
- if fields[idx-1] == "NOT" {
- col.Nullable = false
- } else {
- col.Nullable = true
- }
- case "DEFAULT":
- col.Default = fields[idx+1]
- col.DefaultIsEmpty = false
- }
- }
- return col, nil
-}
-
-func (db *sqlite3) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
- args := []interface{}{tableName}
- s := "SELECT sql FROM sqlite_master WHERE type='table' and name = ?"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, nil, err
- }
- defer rows.Close()
-
- var name string
- if rows.Next() {
- err = rows.Scan(&name)
- if err != nil {
- return nil, nil, err
- }
- }
- if rows.Err() != nil {
- return nil, nil, rows.Err()
- }
-
- if name == "" {
- return nil, nil, errors.New("no table named " + tableName)
- }
-
- nStart := strings.Index(name, "(")
- nEnd := strings.LastIndex(name, ")")
- reg := regexp.MustCompile(`[^\(,\)]*(\([^\(]*\))?`)
- colCreates := reg.FindAllString(name[nStart+1:nEnd], -1)
- cols := make(map[string]*schemas.Column)
- colSeq := make([]string, 0)
-
- for _, colStr := range colCreates {
- reg = regexp.MustCompile(`,\s`)
- colStr = reg.ReplaceAllString(colStr, ",")
- if strings.HasPrefix(strings.TrimSpace(colStr), "PRIMARY KEY") {
- parts := strings.Split(strings.TrimSpace(colStr), "(")
- if len(parts) == 2 {
- pkCols := strings.Split(strings.TrimRight(strings.TrimSpace(parts[1]), ")"), ",")
- for _, pk := range pkCols {
- if col, ok := cols[strings.Trim(strings.TrimSpace(pk), "`")]; ok {
- col.IsPrimaryKey = true
- }
- }
- }
- continue
- }
-
- col, err := parseString(colStr)
- if err != nil {
- return colSeq, cols, err
- }
-
- cols[col.Name] = col
- colSeq = append(colSeq, col.Name)
- }
- return colSeq, cols, nil
-}
-
-func (db *sqlite3) GetTables(queryer core.Queryer, ctx context.Context) ([]*schemas.Table, error) {
- args := []interface{}{}
- s := "SELECT name FROM sqlite_master WHERE type='table'"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- tables := make([]*schemas.Table, 0)
- for rows.Next() {
- table := schemas.NewEmptyTable()
- err = rows.Scan(&table.Name)
- if err != nil {
- return nil, err
- }
- if table.Name == "sqlite_sequence" {
- continue
- }
- tables = append(tables, table)
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
- return tables, nil
-}
-
-func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableName string) (map[string]*schemas.Index, error) {
- args := []interface{}{tableName}
- s := "SELECT sql FROM sqlite_master WHERE type='index' and tbl_name = ?"
-
- rows, err := queryer.QueryContext(ctx, s, args...)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- indexes := make(map[string]*schemas.Index)
- for rows.Next() {
- var tmpSQL sql.NullString
- err = rows.Scan(&tmpSQL)
- if err != nil {
- return nil, err
- }
-
- if !tmpSQL.Valid {
- continue
- }
- sql := tmpSQL.String
-
- index := new(schemas.Index)
- nNStart := strings.Index(sql, "INDEX")
- nNEnd := strings.Index(sql, "ON")
- if nNStart == -1 || nNEnd == -1 {
- continue
- }
-
- indexName := strings.Trim(strings.TrimSpace(sql[nNStart+6:nNEnd]), "`[]'\"")
- var isRegular bool
- if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
- index.Name = indexName[5+len(tableName):]
- isRegular = true
- } else {
- index.Name = indexName
- }
-
- if strings.HasPrefix(sql, "CREATE UNIQUE INDEX") {
- index.Type = schemas.UniqueType
- } else {
- index.Type = schemas.IndexType
- }
-
- nStart := strings.Index(sql, "(")
- nEnd := strings.Index(sql, ")")
- colIndexes := strings.Split(sql[nStart+1:nEnd], ",")
-
- index.Cols = make([]string, 0)
- for _, col := range colIndexes {
- index.Cols = append(index.Cols, strings.Trim(col, "` []"))
- }
- index.IsRegular = isRegular
- indexes[index.Name] = index
- }
- if rows.Err() != nil {
- return nil, rows.Err()
- }
-
- return indexes, nil
-}
-
-func (db *sqlite3) Filters() []Filter {
- return []Filter{}
-}
-
-type sqlite3Driver struct {
- baseDriver
-}
-
-func (p *sqlite3Driver) Features() *DriverFeatures {
- return &DriverFeatures{
- SupportReturnInsertedID: true,
- }
-}
-
-func (p *sqlite3Driver) Parse(driverName, dataSourceName string) (*URI, error) {
- if strings.Contains(dataSourceName, "?") {
- dataSourceName = dataSourceName[:strings.Index(dataSourceName, "?")]
- }
-
- return &URI{DBType: schemas.SQLITE, DBName: dataSourceName}, nil
-}
-
-func (p *sqlite3Driver) GenScanResult(colType string) (interface{}, error) {
- switch colType {
- case "TEXT":
- var s sql.NullString
- return &s, nil
- case "INTEGER":
- var s sql.NullInt64
- return &s, nil
- case "DATETIME":
- var s sql.NullTime
- return &s, nil
- case "REAL":
- var s sql.NullFloat64
- return &s, nil
- case "NUMERIC", "DECIMAL":
- var s sql.NullString
- return &s, nil
- case "BLOB":
- var s sql.RawBytes
- return &s, nil
- default:
- var r sql.NullString
- return &r, nil
- }
-}
diff --git a/vendor/xorm.io/xorm/dialects/table_name.go b/vendor/xorm.io/xorm/dialects/table_name.go
deleted file mode 100644
index e190cd4bfa..0000000000
--- a/vendor/xorm.io/xorm/dialects/table_name.go
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "fmt"
- "reflect"
- "strings"
-
- "xorm.io/xorm/internal/utils"
- "xorm.io/xorm/names"
-)
-
-// TableNameWithSchema will add schema prefix on table name if possible
-func TableNameWithSchema(dialect Dialect, tableName string) string {
- // Add schema name as prefix of table name.
- // Only for postgres database.
- if dialect.URI().Schema != "" &&
- strings.Index(tableName, ".") == -1 {
- return fmt.Sprintf("%s.%s", dialect.URI().Schema, tableName)
- }
- return tableName
-}
-
-// TableNameNoSchema returns table name with given tableName
-func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface{}) string {
- quote := dialect.Quoter().Quote
- switch tableName.(type) {
- case []string:
- t := tableName.([]string)
- if len(t) > 1 {
- return fmt.Sprintf("%v AS %v", quote(t[0]), quote(t[1]))
- } else if len(t) == 1 {
- return quote(t[0])
- }
- case []interface{}:
- t := tableName.([]interface{})
- l := len(t)
- var table string
- if l > 0 {
- f := t[0]
- switch f.(type) {
- case string:
- table = f.(string)
- case names.TableName:
- table = f.(names.TableName).TableName()
- default:
- v := utils.ReflectValue(f)
- t := v.Type()
- if t.Kind() == reflect.Struct {
- table = names.GetTableName(mapper, v)
- } else {
- table = quote(fmt.Sprintf("%v", f))
- }
- }
- }
- if l > 1 {
- return fmt.Sprintf("%v AS %v", quote(table), quote(fmt.Sprintf("%v", t[1])))
- } else if l == 1 {
- return quote(table)
- }
- case names.TableName:
- return tableName.(names.TableName).TableName()
- case string:
- return tableName.(string)
- case reflect.Value:
- v := tableName.(reflect.Value)
- return names.GetTableName(mapper, v)
- default:
- v := utils.ReflectValue(tableName)
- t := v.Type()
- if t.Kind() == reflect.Struct {
- return names.GetTableName(mapper, v)
- }
- return quote(fmt.Sprintf("%v", tableName))
- }
- return ""
-}
-
-// FullTableName returns table name with quote and schema according parameter
-func FullTableName(dialect Dialect, mapper names.Mapper, bean interface{}, includeSchema ...bool) string {
- tbName := TableNameNoSchema(dialect, mapper, bean)
- if len(includeSchema) > 0 && includeSchema[0] && !utils.IsSubQuery(tbName) {
- tbName = TableNameWithSchema(dialect, tbName)
- }
- return tbName
-}
diff --git a/vendor/xorm.io/xorm/dialects/time.go b/vendor/xorm.io/xorm/dialects/time.go
deleted file mode 100644
index f0bbb76518..0000000000
--- a/vendor/xorm.io/xorm/dialects/time.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2015 The Xorm Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package dialects
-
-import (
- "strings"
- "time"
-
- "xorm.io/xorm/schemas"
-)
-
-// FormatColumnTime format column time
-func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.Column, t time.Time) (interface{}, error) {
- if t.IsZero() {
- if col.Nullable {
- return nil, nil
- }
-
- if col.SQLType.IsNumeric() {
- return 0, nil
- }
- }
-
- var tmZone = dbLocation
- if col.TimeZone != nil {
- tmZone = col.TimeZone
- }
-
- t = t.In(tmZone)
-
- switch col.SQLType.Name {
- case schemas.Date:
- return t.Format("2006-01-02"), nil
- case schemas.Time:
- var layout = "15:04:05"
- if col.Length > 0 {
- layout += "." + strings.Repeat("0", col.Length)
- }
- return t.Format(layout), nil
- case schemas.DateTime, schemas.TimeStamp:
- var layout = "2006-01-02 15:04:05"
- if col.Length > 0 {
- layout += "." + strings.Repeat("0", col.Length)
- }
- return t.Format(layout), nil
- case schemas.Varchar:
- return t.Format("2006-01-02 15:04:05"), nil
- case schemas.TimeStampz:
- if dialect.URI().DBType == schemas.MSSQL {
- return t.Format("2006-01-02T15:04:05.9999999Z07:00"), nil
- } else {
- return t.Format(time.RFC3339Nano), nil
- }
- case schemas.BigInt, schemas.Int:
- return t.Unix(), nil
- default:
- return t, nil
- }
-}