mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Upgrade xorm to v1.0.0 (#10646)
* Upgrade xorm to v1.0.0 * small nit * Fix tests * Update xorm * Update xorm * fix go.sum * fix test * Fix bug when dump * Fix bug * update xorm to latest * Fix migration test * update xorm to latest * Fix import order * Use xorm tag
This commit is contained in:
278
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
Normal file
278
vendor/xorm.io/xorm/dialects/dialect.go
generated
vendored
Normal file
@@ -0,0 +1,278 @@
|
||||
// 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) {
|
||||
if uri.DBType == schemas.POSTGRES {
|
||||
uri.Schema = schema
|
||||
}
|
||||
}
|
||||
|
||||
// Dialect represents a kind of database
|
||||
type Dialect interface {
|
||||
Init(*core.DB, *URI) error
|
||||
URI() *URI
|
||||
DB() *core.DB
|
||||
SQLType(*schemas.Column) string
|
||||
FormatBytes(b []byte) string
|
||||
DefaultSchema() string
|
||||
|
||||
IsReserved(string) bool
|
||||
Quoter() schemas.Quoter
|
||||
SetQuotePolicy(quotePolicy QuotePolicy)
|
||||
|
||||
AutoIncrStr() string
|
||||
|
||||
GetIndexes(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(ctx context.Context) ([]*schemas.Table, error)
|
||||
IsTableExist(ctx context.Context, tableName string) (bool, error)
|
||||
CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool)
|
||||
DropTableSQL(tableName string) (string, bool)
|
||||
|
||||
GetColumns(ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error)
|
||||
IsColumnExist(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 {
|
||||
db *core.DB
|
||||
dialect Dialect
|
||||
uri *URI
|
||||
quoter schemas.Quoter
|
||||
}
|
||||
|
||||
func (b *Base) Quoter() schemas.Quoter {
|
||||
return b.quoter
|
||||
}
|
||||
|
||||
func (b *Base) DB() *core.DB {
|
||||
return b.db
|
||||
}
|
||||
|
||||
func (b *Base) DefaultSchema() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (b *Base) Init(db *core.DB, dialect Dialect, uri *URI) error {
|
||||
b.db, b.dialect, b.uri = db, dialect, uri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Base) URI() *URI {
|
||||
return b.uri
|
||||
}
|
||||
|
||||
func (b *Base) DBType() schemas.DBType {
|
||||
return b.uri.DBType
|
||||
}
|
||||
|
||||
// String generate column description string according dialect
|
||||
func (b *Base) String(col *schemas.Column) string {
|
||||
sql := b.dialect.Quoter().Quote(col.Name) + " "
|
||||
|
||||
sql += b.dialect.SQLType(col) + " "
|
||||
|
||||
if col.IsPrimaryKey {
|
||||
sql += "PRIMARY KEY "
|
||||
if col.IsAutoIncrement {
|
||||
sql += b.dialect.AutoIncrStr() + " "
|
||||
}
|
||||
}
|
||||
|
||||
if col.Default != "" {
|
||||
sql += "DEFAULT " + col.Default + " "
|
||||
}
|
||||
|
||||
if col.Nullable {
|
||||
sql += "NULL "
|
||||
} else {
|
||||
sql += "NOT NULL "
|
||||
}
|
||||
|
||||
return sql
|
||||
}
|
||||
|
||||
// StringNoPk generate column description string according dialect without primary keys
|
||||
func (b *Base) StringNoPk(col *schemas.Column) string {
|
||||
sql := b.dialect.Quoter().Quote(col.Name) + " "
|
||||
|
||||
sql += b.dialect.SQLType(col) + " "
|
||||
|
||||
if col.Default != "" {
|
||||
sql += "DEFAULT " + col.Default + " "
|
||||
}
|
||||
|
||||
if col.Nullable {
|
||||
sql += "NULL "
|
||||
} else {
|
||||
sql += "NOT NULL "
|
||||
}
|
||||
|
||||
return sql
|
||||
}
|
||||
|
||||
func (b *Base) FormatBytes(bs []byte) string {
|
||||
return fmt.Sprintf("0x%x", bs)
|
||||
}
|
||||
|
||||
func (db *Base) DropTableSQL(tableName string) (string, bool) {
|
||||
quote := db.dialect.Quoter().Quote
|
||||
return fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName)), true
|
||||
}
|
||||
|
||||
func (db *Base) HasRecords(ctx context.Context, query string, args ...interface{}) (bool, error) {
|
||||
rows, err := db.DB().QueryContext(ctx, query, args...)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
if rows.Next() {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (db *Base) IsColumnExist(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(ctx, query, db.uri.DBName, tableName, colName)
|
||||
}
|
||||
|
||||
func (db *Base) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
return fmt.Sprintf("ALTER TABLE %v ADD %v", db.dialect.Quoter().Quote(tableName),
|
||||
db.String(col))
|
||||
}
|
||||
|
||||
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, ","))
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string {
|
||||
return fmt.Sprintf("alter table %s MODIFY COLUMN %s", tableName, db.StringNoPk(col))
|
||||
}
|
||||
|
||||
func (b *Base) ForUpdateSQL(query string) string {
|
||||
return query + " FOR UPDATE"
|
||||
}
|
||||
|
||||
func (b *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{} }},
|
||||
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
||||
"goracle": {"oracle", func() Driver { return &goracleDriver{} }, 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()
|
||||
}
|
63
vendor/xorm.io/xorm/dialects/driver.go
generated
vendored
Normal file
63
vendor/xorm.io/xorm/dialects/driver.go
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// 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"
|
||||
|
||||
"xorm.io/xorm/core"
|
||||
)
|
||||
|
||||
type Driver interface {
|
||||
Parse(string, string) (*URI, error)
|
||||
}
|
||||
|
||||
var (
|
||||
drivers = map[string]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
|
||||
}
|
||||
|
||||
func QueryDriver(driverName string) Driver {
|
||||
return drivers[driverName]
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
db, err := core.Open(driverName, connstr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dialect.Init(db, uri)
|
||||
|
||||
return dialect, nil
|
||||
}
|
43
vendor/xorm.io/xorm/dialects/filter.go
generated
vendored
Normal file
43
vendor/xorm.io/xorm/dialects/filter.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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 index = start
|
||||
for _, c := range sql {
|
||||
if !beginSingleQuote && c == '?' {
|
||||
buf.WriteString(fmt.Sprintf("%s%v", prefix, index))
|
||||
index++
|
||||
} else {
|
||||
if c == '\'' {
|
||||
beginSingleQuote = !beginSingleQuote
|
||||
}
|
||||
buf.WriteRune(c)
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (s *SeqFilter) Do(sql string) string {
|
||||
return convertQuestionMark(sql, s.Prefix, s.Start)
|
||||
}
|
6
vendor/xorm.io/xorm/dialects/gen_reserved.sh
generated
vendored
Normal file
6
vendor/xorm.io/xorm/dialects/gen_reserved.sh
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
if [ -f $1 ];then
|
||||
cat $1| awk '{printf("\""$1"\":true,\n")}'
|
||||
else
|
||||
echo "argument $1 if not a file!"
|
||||
fi
|
560
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
Normal file
560
vendor/xorm.io/xorm/dialects/mssql.go
generated
vendored
Normal file
@@ -0,0 +1,560 @@
|
||||
// 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"
|
||||
"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{'[', ']', schemas.AlwaysReserve}
|
||||
)
|
||||
|
||||
type mssql struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (db *mssql) Init(d *core.DB, uri *URI) error {
|
||||
db.quoter = mssqlQuoter
|
||||
return db.Base.Init(d, db, uri)
|
||||
}
|
||||
|
||||
func (db *mssql) SQLType(c *schemas.Column) string {
|
||||
var res string
|
||||
switch t := c.SQLType.Name; t {
|
||||
case schemas.Bool:
|
||||
res = schemas.Bit
|
||||
if strings.EqualFold(c.Default, "true") {
|
||||
c.Default = "1"
|
||||
} else if strings.EqualFold(c.Default, "false") {
|
||||
c.Default = "0"
|
||||
}
|
||||
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.Blob, schemas.Binary, schemas.TinyBlob, schemas.MediumBlob, schemas.LongBlob:
|
||||
res = schemas.VarBinary
|
||||
if c.Length == 0 {
|
||||
c.Length = 50
|
||||
}
|
||||
case schemas.TimeStamp:
|
||||
res = schemas.DateTime
|
||||
case schemas.TimeStampz:
|
||||
res = "DATETIMEOFFSET"
|
||||
c.Length = 7
|
||||
case schemas.MediumInt:
|
||||
res = schemas.Int
|
||||
case schemas.Text, schemas.MediumText, schemas.TinyText, schemas.LongText, schemas.Json:
|
||||
res = schemas.Varchar + "(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:
|
||||
res = schemas.BigInt
|
||||
c.Length = 0
|
||||
default:
|
||||
res = t
|
||||
}
|
||||
|
||||
if res == schemas.Int {
|
||||
return schemas.Int
|
||||
}
|
||||
|
||||
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) 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) 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(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(ctx, query, tableName, colName)
|
||||
}
|
||||
|
||||
func (db *mssql) IsTableExist(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(ctx, sql)
|
||||
}
|
||||
|
||||
func (db *mssql) GetColumns(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 := db.DB().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}
|
||||
case "IMAGE":
|
||||
col.SQLType = schemas.SQLType{Name: schemas.VarBinary, DefaultLength: 0, DefaultLength2: 0}
|
||||
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)
|
||||
}
|
||||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *mssql) GetTables(ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
s := `select name from sysobjects where xtype ='U'`
|
||||
|
||||
rows, err := db.DB().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)
|
||||
}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *mssql) GetIndexes(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 := db.DB().QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
indexes := make(map[string]*schemas.Index, 0)
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
return indexes, nil
|
||||
}
|
||||
|
||||
func (db *mssql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
|
||||
var sql string
|
||||
if tableName == "" {
|
||||
tableName = table.Name
|
||||
}
|
||||
|
||||
sql = "IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '" + tableName + "' ) CREATE TABLE "
|
||||
|
||||
sql += db.Quoter().Quote(tableName) + " ("
|
||||
|
||||
pkList := table.PrimaryKeys
|
||||
|
||||
for _, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
if col.IsPrimaryKey && len(pkList) == 1 {
|
||||
sql += db.String(col)
|
||||
} else {
|
||||
sql += db.StringNoPk(col)
|
||||
}
|
||||
sql = strings.TrimSpace(sql)
|
||||
sql += ", "
|
||||
}
|
||||
|
||||
if len(pkList) > 1 {
|
||||
sql += "PRIMARY KEY ( "
|
||||
sql += strings.Join(pkList, ",")
|
||||
sql += " ), "
|
||||
}
|
||||
|
||||
sql = sql[:len(sql)-2] + ")"
|
||||
sql += ";"
|
||||
return []string{sql}, true
|
||||
}
|
||||
|
||||
func (db *mssql) ForUpdateSQL(query string) string {
|
||||
return query
|
||||
}
|
||||
|
||||
func (db *mssql) Filters() []Filter {
|
||||
return []Filter{}
|
||||
}
|
||||
|
||||
type odbcDriver struct {
|
||||
}
|
||||
|
||||
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 {
|
||||
switch strings.ToLower(vv[0]) {
|
||||
case "database":
|
||||
dbName = vv[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if dbName == "" {
|
||||
return nil, errors.New("no db name provided")
|
||||
}
|
||||
return &URI{DBName: dbName, DBType: schemas.MSSQL}, nil
|
||||
}
|
660
vendor/xorm.io/xorm/dialects/mysql.go
generated
vendored
Normal file
660
vendor/xorm.io/xorm/dialects/mysql.go
generated
vendored
Normal file
@@ -0,0 +1,660 @@
|
||||
// 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"
|
||||
"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{'`', '`', 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(d *core.DB, uri *URI) error {
|
||||
db.quoter = mysqlQuoter
|
||||
return db.Base.Init(d, db, uri)
|
||||
}
|
||||
|
||||
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
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (db *mysql) SQLType(c *schemas.Column) string {
|
||||
var res string
|
||||
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
|
||||
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) + ")"
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
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(ctx context.Context, tableName string) (bool, error) {
|
||||
sql := "SELECT `TABLE_NAME` from `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? and `TABLE_NAME`=?"
|
||||
return db.HasRecords(ctx, sql, db.uri.DBName, tableName)
|
||||
}
|
||||
|
||||
func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
|
||||
quoter := db.dialect.Quoter()
|
||||
sql := fmt.Sprintf("ALTER TABLE %v ADD %v", quoter.Quote(tableName),
|
||||
db.String(col))
|
||||
if len(col.Comment) > 0 {
|
||||
sql += " COMMENT '" + col.Comment + "'"
|
||||
}
|
||||
return sql
|
||||
}
|
||||
|
||||
func (db *mysql) GetColumns(ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
|
||||
args := []interface{}{db.uri.DBName, tableName}
|
||||
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
|
||||
" `COLUMN_KEY`, `EXTRA`,`COLUMN_COMMENT` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?"
|
||||
|
||||
rows, err := db.DB().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, isNullable, colType, colKey, extra, comment string
|
||||
var colDefault *string
|
||||
err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
col.Name = strings.Trim(columnName, "` ")
|
||||
col.Comment = comment
|
||||
if "YES" == isNullable {
|
||||
col.Nullable = true
|
||||
}
|
||||
|
||||
if colDefault != nil {
|
||||
col.Default = *colDefault
|
||||
col.DefaultIsEmpty = false
|
||||
} else {
|
||||
col.DefaultIsEmpty = true
|
||||
}
|
||||
|
||||
cts := strings.Split(colType, "(")
|
||||
colName := cts[0]
|
||||
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 colType == "FLOAT UNSIGNED" {
|
||||
colType = "FLOAT"
|
||||
}
|
||||
if colType == "DOUBLE UNSIGNED" {
|
||||
colType = "DOUBLE"
|
||||
}
|
||||
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 col.SQLType.IsText() {
|
||||
col.Default = "'" + col.Default + "'"
|
||||
} else if col.SQLType.IsTime() && col.Default != "CURRENT_TIMESTAMP" {
|
||||
col.Default = "'" + col.Default + "'"
|
||||
}
|
||||
}
|
||||
cols[col.Name] = col
|
||||
colSeq = append(colSeq, col.Name)
|
||||
}
|
||||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *mysql) GetTables(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 := db.DB().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)
|
||||
}
|
||||
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(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 := db.DB().QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
indexes := make(map[string]*schemas.Index, 0)
|
||||
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 "YES" == nonUnique || 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)
|
||||
}
|
||||
return indexes, nil
|
||||
}
|
||||
|
||||
func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
|
||||
var sql = "CREATE TABLE IF NOT EXISTS "
|
||||
if tableName == "" {
|
||||
tableName = table.Name
|
||||
}
|
||||
|
||||
quoter := db.Quoter()
|
||||
|
||||
sql += quoter.Quote(tableName)
|
||||
sql += " ("
|
||||
|
||||
if len(table.ColumnsSeq()) > 0 {
|
||||
pkList := table.PrimaryKeys
|
||||
|
||||
for _, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
if col.IsPrimaryKey && len(pkList) == 1 {
|
||||
sql += db.String(col)
|
||||
} else {
|
||||
sql += db.StringNoPk(col)
|
||||
}
|
||||
sql = strings.TrimSpace(sql)
|
||||
if len(col.Comment) > 0 {
|
||||
sql += " COMMENT '" + col.Comment + "'"
|
||||
}
|
||||
sql += ", "
|
||||
}
|
||||
|
||||
if len(pkList) > 1 {
|
||||
sql += "PRIMARY KEY ( "
|
||||
sql += quoter.Join(pkList, ",")
|
||||
sql += " ), "
|
||||
}
|
||||
|
||||
sql = sql[:len(sql)-2]
|
||||
}
|
||||
sql += ")"
|
||||
|
||||
if table.StoreEngine != "" {
|
||||
sql += " ENGINE=" + table.StoreEngine
|
||||
}
|
||||
|
||||
var charset = table.Charset
|
||||
if len(charset) == 0 {
|
||||
charset = db.URI().Charset
|
||||
}
|
||||
if len(charset) != 0 {
|
||||
sql += " DEFAULT CHARSET " + charset
|
||||
}
|
||||
|
||||
if db.rowFormat != "" {
|
||||
sql += " ROW_FORMAT=" + db.rowFormat
|
||||
}
|
||||
return []string{sql}, true
|
||||
}
|
||||
|
||||
func (db *mysql) Filters() []Filter {
|
||||
return []Filter{}
|
||||
}
|
||||
|
||||
type mymysqlDriver struct {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type mysqlDriver struct {
|
||||
}
|
||||
|
||||
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¶mN=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 {
|
||||
switch splits[0] {
|
||||
case "charset":
|
||||
uri.Charset = splits[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return uri, nil
|
||||
}
|
849
vendor/xorm.io/xorm/dialects/oracle.go
generated
vendored
Normal file
849
vendor/xorm.io/xorm/dialects/oracle.go
generated
vendored
Normal file
@@ -0,0 +1,849 @@
|
||||
// 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"
|
||||
"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{'[', ']', schemas.AlwaysReserve}
|
||||
)
|
||||
|
||||
type oracle struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (db *oracle) Init(d *core.DB, uri *URI) error {
|
||||
db.quoter = oracleQuoter
|
||||
return db.Base.Init(d, db, uri)
|
||||
}
|
||||
|
||||
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) 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 {*/
|
||||
sql += db.StringNoPk(col)
|
||||
// }
|
||||
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(ctx context.Context, tableName string) (bool, error) {
|
||||
return db.HasRecords(ctx, `SELECT table_name FROM user_tables WHERE table_name = :1`, tableName)
|
||||
}
|
||||
|
||||
func (db *oracle) IsColumnExist(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(ctx, query, args...)
|
||||
}
|
||||
|
||||
func (db *oracle) GetColumns(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 := db.DB().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)
|
||||
}
|
||||
|
||||
return colSeq, cols, nil
|
||||
}
|
||||
|
||||
func (db *oracle) GetTables(ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
s := "SELECT table_name FROM user_tables"
|
||||
|
||||
rows, err := db.DB().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)
|
||||
}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *oracle) GetIndexes(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 := db.DB().QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
indexes := make(map[string]*schemas.Index, 0)
|
||||
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)
|
||||
}
|
||||
return indexes, nil
|
||||
}
|
||||
|
||||
func (db *oracle) Filters() []Filter {
|
||||
return []Filter{
|
||||
&SeqFilter{Prefix: ":", Start: 1},
|
||||
}
|
||||
}
|
||||
|
||||
type goracleDriver struct {
|
||||
}
|
||||
|
||||
func (cfg *goracleDriver) 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¶mN=valueN]
|
||||
matches := dsnPattern.FindStringSubmatch(dataSourceName)
|
||||
// tlsConfigRegister := make(map[string]*tls.Config)
|
||||
names := dsnPattern.SubexpNames()
|
||||
|
||||
for i, match := range matches {
|
||||
switch names[i] {
|
||||
case "dbname":
|
||||
db.DBName = match
|
||||
}
|
||||
}
|
||||
if db.DBName == "" {
|
||||
return nil, errors.New("dbname is empty")
|
||||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
type oci8Driver struct {
|
||||
}
|
||||
|
||||
// dataSourceName=user/password@ipv4:port/dbname
|
||||
// dataSourceName=user/password@[ipv6]:port/dbname
|
||||
func (p *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 {
|
||||
switch names[i] {
|
||||
case "dbname":
|
||||
db.DBName = match
|
||||
}
|
||||
}
|
||||
if db.DBName == "" {
|
||||
return nil, errors.New("dbname is empty")
|
||||
}
|
||||
return db, nil
|
||||
}
|
746
vendor/xorm.io/xorm/dialects/pg_reserved.txt
generated
vendored
Normal file
746
vendor/xorm.io/xorm/dialects/pg_reserved.txt
generated
vendored
Normal file
@@ -0,0 +1,746 @@
|
||||
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
|
1321
vendor/xorm.io/xorm/dialects/postgres.go
generated
vendored
Normal file
1321
vendor/xorm.io/xorm/dialects/postgres.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
15
vendor/xorm.io/xorm/dialects/quote.go
generated
vendored
Normal file
15
vendor/xorm.io/xorm/dialects/quote.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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
|
||||
)
|
528
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
Normal file
528
vendor/xorm.io/xorm/dialects/sqlite3.go
generated
vendored
Normal file
@@ -0,0 +1,528 @@
|
||||
// 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{'`', '`', schemas.AlwaysReserve}
|
||||
)
|
||||
|
||||
type sqlite3 struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (db *sqlite3) Init(d *core.DB, uri *URI) error {
|
||||
db.quoter = sqlite3Quoter
|
||||
return db.Base.Init(d, db, uri)
|
||||
}
|
||||
|
||||
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.SmallInt, schemas.MediumInt, schemas.Int, schemas.Integer, schemas.BigInt:
|
||||
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) FormatBytes(bs []byte) string {
|
||||
return fmt.Sprintf("X'%x'", bs)
|
||||
}
|
||||
|
||||
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(ctx context.Context, tableName string) (bool, error) {
|
||||
return db.HasRecords(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) CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool) {
|
||||
var sql string
|
||||
sql = "CREATE TABLE IF NOT EXISTS "
|
||||
if tableName == "" {
|
||||
tableName = table.Name
|
||||
}
|
||||
|
||||
quoter := db.Quoter()
|
||||
sql += quoter.Quote(tableName)
|
||||
sql += " ("
|
||||
|
||||
if len(table.ColumnsSeq()) > 0 {
|
||||
pkList := table.PrimaryKeys
|
||||
|
||||
for _, colName := range table.ColumnsSeq() {
|
||||
col := table.GetColumn(colName)
|
||||
if col.IsPrimaryKey && len(pkList) == 1 {
|
||||
sql += db.String(col)
|
||||
} else {
|
||||
sql += db.StringNoPk(col)
|
||||
}
|
||||
sql = strings.TrimSpace(sql)
|
||||
sql += ", "
|
||||
}
|
||||
|
||||
if len(pkList) > 1 {
|
||||
sql += "PRIMARY KEY ( "
|
||||
sql += quoter.Join(pkList, ",")
|
||||
sql += " ), "
|
||||
}
|
||||
|
||||
sql = sql[:len(sql)-2]
|
||||
}
|
||||
sql += ")"
|
||||
|
||||
return []string{sql}, true
|
||||
}
|
||||
|
||||
func (db *sqlite3) ForUpdateSQL(query string) string {
|
||||
return query
|
||||
}
|
||||
|
||||
func (db *sqlite3) IsColumnExist(ctx context.Context, tableName, colName string) (bool, error) {
|
||||
query := "SELECT * FROM " + tableName + " LIMIT 0"
|
||||
rows, err := db.DB().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(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 := db.DB().QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var name string
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
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(ctx context.Context) ([]*schemas.Table, error) {
|
||||
args := []interface{}{}
|
||||
s := "SELECT name FROM sqlite_master WHERE type='table'"
|
||||
|
||||
rows, err := db.DB().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)
|
||||
}
|
||||
return tables, nil
|
||||
}
|
||||
|
||||
func (db *sqlite3) GetIndexes(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 := db.DB().QueryContext(ctx, s, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
indexes := make(map[string]*schemas.Index, 0)
|
||||
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(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
|
||||
}
|
||||
|
||||
return indexes, nil
|
||||
}
|
||||
|
||||
func (db *sqlite3) Filters() []Filter {
|
||||
return []Filter{}
|
||||
}
|
||||
|
||||
type sqlite3Driver struct {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
90
vendor/xorm.io/xorm/dialects/table_name.go
generated
vendored
Normal file
90
vendor/xorm.io/xorm/dialects/table_name.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
// 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 != "" &&
|
||||
dialect.URI().Schema != dialect.DefaultSchema() &&
|
||||
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
|
||||
}
|
49
vendor/xorm.io/xorm/dialects/time.go
generated
vendored
Normal file
49
vendor/xorm.io/xorm/dialects/time.go
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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 (
|
||||
"time"
|
||||
|
||||
"xorm.io/xorm/schemas"
|
||||
)
|
||||
|
||||
// FormatTime format time as column type
|
||||
func FormatTime(dialect Dialect, sqlTypeName string, t time.Time) (v interface{}) {
|
||||
switch sqlTypeName {
|
||||
case schemas.Time:
|
||||
s := t.Format("2006-01-02 15:04:05") // time.RFC3339
|
||||
v = s[11:19]
|
||||
case schemas.Date:
|
||||
v = t.Format("2006-01-02")
|
||||
case schemas.DateTime, schemas.TimeStamp, schemas.Varchar: // !DarthPestilane! format time when sqlTypeName is schemas.Varchar.
|
||||
v = t.Format("2006-01-02 15:04:05")
|
||||
case schemas.TimeStampz:
|
||||
if dialect.URI().DBType == schemas.MSSQL {
|
||||
v = t.Format("2006-01-02T15:04:05.9999999Z07:00")
|
||||
} else {
|
||||
v = t.Format(time.RFC3339Nano)
|
||||
}
|
||||
case schemas.BigInt, schemas.Int:
|
||||
v = t.Unix()
|
||||
default:
|
||||
v = t
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func FormatColumnTime(dialect Dialect, defaultTimeZone *time.Location, col *schemas.Column, t time.Time) (v interface{}) {
|
||||
if t.IsZero() {
|
||||
if col.Nullable {
|
||||
return nil
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
if col.TimeZone != nil {
|
||||
return FormatTime(dialect, col.SQLType.Name, t.In(col.TimeZone))
|
||||
}
|
||||
return FormatTime(dialect, col.SQLType.Name, t.In(defaultTimeZone))
|
||||
}
|
Reference in New Issue
Block a user