forked from mirror/gitea
Update xorm and fix dump command (#692)
* update xorm and fix dump * catch database init error * still use dumpTables * fix dump bool type * update vendor.json
This commit is contained in:
parent
74ed6dc3ad
commit
a8048c19f3
|
@ -56,7 +56,11 @@ func runDump(ctx *cli.Context) error {
|
||||||
setting.NewContext()
|
setting.NewContext()
|
||||||
setting.NewServices() // cannot access session settings otherwise
|
setting.NewServices() // cannot access session settings otherwise
|
||||||
models.LoadConfigs()
|
models.LoadConfigs()
|
||||||
models.SetEngine()
|
|
||||||
|
err := models.SetEngine()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tmpDir := ctx.String("tempdir")
|
tmpDir := ctx.String("tempdir")
|
||||||
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
|
if _, err := os.Stat(tmpDir); os.IsNotExist(err) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ ORM Methods
|
||||||
|
|
||||||
There are 7 major ORM methods and many helpful methods to use to operate database.
|
There are 7 major ORM methods and many helpful methods to use to operate database.
|
||||||
|
|
||||||
1. Insert one or multipe records to database
|
1. Insert one or multiple records to database
|
||||||
|
|
||||||
affected, err := engine.Insert(&struct)
|
affected, err := engine.Insert(&struct)
|
||||||
// INSERT INTO struct () values ()
|
// INSERT INTO struct () values ()
|
||||||
|
@ -81,7 +81,7 @@ another is Rows
|
||||||
affected, err := engine.Id(...).Update(&user)
|
affected, err := engine.Id(...).Update(&user)
|
||||||
// UPDATE user SET ...
|
// UPDATE user SET ...
|
||||||
|
|
||||||
6. Delete one or more records, Delete MUST has conditon
|
6. Delete one or more records, Delete MUST has condition
|
||||||
|
|
||||||
affected, err := engine.Where(...).Delete(&user)
|
affected, err := engine.Where(...).Delete(&user)
|
||||||
// DELETE FROM user Where ...
|
// DELETE FROM user Where ...
|
||||||
|
|
|
@ -46,7 +46,7 @@ type Engine struct {
|
||||||
disableGlobalCache bool
|
disableGlobalCache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowSQL show SQL statment or not on logger if log level is great than INFO
|
// ShowSQL show SQL statement or not on logger if log level is great than INFO
|
||||||
func (engine *Engine) ShowSQL(show ...bool) {
|
func (engine *Engine) ShowSQL(show ...bool) {
|
||||||
engine.logger.ShowSQL(show...)
|
engine.logger.ShowSQL(show...)
|
||||||
if len(show) == 0 {
|
if len(show) == 0 {
|
||||||
|
@ -56,7 +56,7 @@ func (engine *Engine) ShowSQL(show ...bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowExecTime show SQL statment and execute time or not on logger if log level is great than INFO
|
// ShowExecTime show SQL statement and execute time or not on logger if log level is great than INFO
|
||||||
func (engine *Engine) ShowExecTime(show ...bool) {
|
func (engine *Engine) ShowExecTime(show ...bool) {
|
||||||
if len(show) == 0 {
|
if len(show) == 0 {
|
||||||
engine.showExecTime = true
|
engine.showExecTime = true
|
||||||
|
@ -117,7 +117,7 @@ func (engine *Engine) SupportInsertMany() bool {
|
||||||
return engine.dialect.SupportInsertMany()
|
return engine.dialect.SupportInsertMany()
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuoteStr Engine's database use which charactor as quote.
|
// QuoteStr Engine's database use which character as quote.
|
||||||
// mysql, sqlite use ` and postgres use "
|
// mysql, sqlite use ` and postgres use "
|
||||||
func (engine *Engine) QuoteStr() string {
|
func (engine *Engine) QuoteStr() string {
|
||||||
return engine.dialect.QuoteStr()
|
return engine.dialect.QuoteStr()
|
||||||
|
@ -305,7 +305,7 @@ func (engine *Engine) Sql(querystring string, args ...interface{}) *Session {
|
||||||
return engine.SQL(querystring, args...)
|
return engine.SQL(querystring, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SQL method let's you manualy write raw SQL and operate
|
// SQL method let's you manually write raw SQL and operate
|
||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// engine.SQL("select * from user").Find(&users)
|
// engine.SQL("select * from user").Find(&users)
|
||||||
|
@ -348,8 +348,6 @@ func (engine *Engine) DBMetas() ([]*core.Table, error) {
|
||||||
for _, name := range colSeq {
|
for _, name := range colSeq {
|
||||||
table.AddColumn(cols[name])
|
table.AddColumn(cols[name])
|
||||||
}
|
}
|
||||||
//table.Columns = cols
|
|
||||||
//table.ColumnsSeq = colSeq
|
|
||||||
indexes, err := engine.dialect.GetIndexes(table.Name)
|
indexes, err := engine.dialect.GetIndexes(table.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -370,18 +368,22 @@ func (engine *Engine) DBMetas() ([]*core.Table, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpAllToFile dump database all table structs and data to a file
|
// DumpAllToFile dump database all table structs and data to a file
|
||||||
func (engine *Engine) DumpAllToFile(fp string) error {
|
func (engine *Engine) DumpAllToFile(fp string, tp ...core.DbType) error {
|
||||||
f, err := os.Create(fp)
|
f, err := os.Create(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
return engine.DumpAll(f)
|
return engine.DumpAll(f, tp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpAll dump database all table structs and data to w
|
// DumpAll dump database all table structs and data to w
|
||||||
func (engine *Engine) DumpAll(w io.Writer) error {
|
func (engine *Engine) DumpAll(w io.Writer, tp ...core.DbType) error {
|
||||||
return engine.dumpAll(w, engine.dialect.DBType())
|
tables, err := engine.DBMetas()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return engine.DumpTables(tables, w, tp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DumpTablesToFile dump specified tables to SQL file.
|
// DumpTablesToFile dump specified tables to SQL file.
|
||||||
|
@ -399,140 +401,7 @@ func (engine *Engine) DumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
return engine.dumpTables(tables, w, tp...)
|
return engine.dumpTables(tables, w, tp...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) tableName(beanOrTableName interface{}) (string, error) {
|
// dumpTables dump database all table structs and data to w with specify db type
|
||||||
v := rValue(beanOrTableName)
|
|
||||||
if v.Type().Kind() == reflect.String {
|
|
||||||
return beanOrTableName.(string), nil
|
|
||||||
} else if v.Type().Kind() == reflect.Struct {
|
|
||||||
return engine.tbName(v), nil
|
|
||||||
}
|
|
||||||
return "", errors.New("bean should be a struct or struct's point")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (engine *Engine) tbName(v reflect.Value) string {
|
|
||||||
if tb, ok := v.Interface().(TableName); ok {
|
|
||||||
return tb.TableName()
|
|
||||||
}
|
|
||||||
|
|
||||||
if v.Type().Kind() == reflect.Ptr {
|
|
||||||
if tb, ok := reflect.Indirect(v).Interface().(TableName); ok {
|
|
||||||
return tb.TableName()
|
|
||||||
}
|
|
||||||
} else if v.CanAddr() {
|
|
||||||
if tb, ok := v.Addr().Interface().(TableName); ok {
|
|
||||||
return tb.TableName()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return engine.TableMapper.Obj2Table(reflect.Indirect(v).Type().Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
// DumpAll dump database all table structs and data to w with specify db type
|
|
||||||
func (engine *Engine) dumpAll(w io.Writer, tp ...core.DbType) error {
|
|
||||||
tables, err := engine.DBMetas()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var dialect core.Dialect
|
|
||||||
if len(tp) == 0 {
|
|
||||||
dialect = engine.dialect
|
|
||||||
} else {
|
|
||||||
dialect = core.QueryDialect(tp[0])
|
|
||||||
if dialect == nil {
|
|
||||||
return errors.New("Unsupported database type")
|
|
||||||
}
|
|
||||||
dialect.Init(nil, engine.dialect.URI(), "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = io.WriteString(w, fmt.Sprintf("/*Generated by xorm v%s %s*/\n\n",
|
|
||||||
Version, time.Now().In(engine.TZLocation).Format("2006-01-02 15:04:05")))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, table := range tables {
|
|
||||||
if i > 0 {
|
|
||||||
_, err = io.WriteString(w, "\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_, err = io.WriteString(w, dialect.CreateTableSql(table, "", table.StoreEngine, "")+";\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, index := range table.Indexes {
|
|
||||||
_, err = io.WriteString(w, dialect.CreateIndexSql(table.Name, index)+";\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, err := engine.DB().Query("SELECT * FROM " + engine.Quote(table.Name))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
|
|
||||||
cols, err := rows.Columns()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(cols) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for rows.Next() {
|
|
||||||
dest := make([]interface{}, len(cols))
|
|
||||||
err = rows.ScanSlice(&dest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = io.WriteString(w, "INSERT INTO "+dialect.Quote(table.Name)+" ("+dialect.Quote(strings.Join(cols, dialect.Quote(", ")))+") VALUES (")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var temp string
|
|
||||||
for i, d := range dest {
|
|
||||||
col := table.GetColumn(cols[i])
|
|
||||||
if d == nil {
|
|
||||||
temp += ", NULL"
|
|
||||||
} else if col.SQLType.IsText() || col.SQLType.IsTime() {
|
|
||||||
var v = fmt.Sprintf("%s", d)
|
|
||||||
temp += ", '" + strings.Replace(v, "'", "''", -1) + "'"
|
|
||||||
} else if col.SQLType.IsBlob() {
|
|
||||||
if reflect.TypeOf(d).Kind() == reflect.Slice {
|
|
||||||
temp += fmt.Sprintf(", %s", dialect.FormatBytes(d.([]byte)))
|
|
||||||
} else if reflect.TypeOf(d).Kind() == reflect.String {
|
|
||||||
temp += fmt.Sprintf(", '%s'", d.(string))
|
|
||||||
}
|
|
||||||
} else if col.SQLType.IsNumeric() {
|
|
||||||
switch reflect.TypeOf(d).Kind() {
|
|
||||||
case reflect.Slice:
|
|
||||||
temp += fmt.Sprintf(", %s", string(d.([]byte)))
|
|
||||||
default:
|
|
||||||
temp += fmt.Sprintf(", %v", d)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
s := fmt.Sprintf("%v", d)
|
|
||||||
if strings.Contains(s, ":") || strings.Contains(s, "-") {
|
|
||||||
temp += fmt.Sprintf(", '%s'", s)
|
|
||||||
} else {
|
|
||||||
temp += fmt.Sprintf(", %s", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_, err = io.WriteString(w, temp[2:]+");\n")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DumpAll dump database all table structs and data to w with specify db type
|
|
||||||
func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.DbType) error {
|
func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.DbType) error {
|
||||||
var dialect core.Dialect
|
var dialect core.Dialect
|
||||||
var distDBName string
|
var distDBName string
|
||||||
|
@ -572,19 +441,15 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := engine.DB().Query("SELECT * FROM " + engine.Quote(table.Name))
|
cols := table.ColumnsSeq()
|
||||||
|
colNames := dialect.Quote(strings.Join(cols, dialect.Quote(", ")))
|
||||||
|
|
||||||
|
rows, err := engine.DB().Query("SELECT " + colNames + " FROM " + engine.Quote(table.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
cols, err := rows.Columns()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(cols) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
dest := make([]interface{}, len(cols))
|
dest := make([]interface{}, len(cols))
|
||||||
err = rows.ScanSlice(&dest)
|
err = rows.ScanSlice(&dest)
|
||||||
|
@ -592,7 +457,7 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.WriteString(w, "INSERT INTO "+dialect.Quote(table.Name)+" ("+dialect.Quote(strings.Join(cols, dialect.Quote(", ")))+") VALUES (")
|
_, err = io.WriteString(w, "INSERT INTO "+dialect.Quote(table.Name)+" ("+colNames+") VALUES (")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -600,6 +465,10 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
var temp string
|
var temp string
|
||||||
for i, d := range dest {
|
for i, d := range dest {
|
||||||
col := table.GetColumn(cols[i])
|
col := table.GetColumn(cols[i])
|
||||||
|
if col == nil {
|
||||||
|
return errors.New("unknow column error")
|
||||||
|
}
|
||||||
|
|
||||||
if d == nil {
|
if d == nil {
|
||||||
temp += ", NULL"
|
temp += ", NULL"
|
||||||
} else if col.SQLType.IsText() || col.SQLType.IsTime() {
|
} else if col.SQLType.IsText() || col.SQLType.IsTime() {
|
||||||
|
@ -619,6 +488,18 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
switch reflect.TypeOf(d).Kind() {
|
switch reflect.TypeOf(d).Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
temp += fmt.Sprintf(", %s", string(d.([]byte)))
|
temp += fmt.Sprintf(", %s", string(d.([]byte)))
|
||||||
|
case reflect.Int16, reflect.Int8, reflect.Int32, reflect.Int64, reflect.Int:
|
||||||
|
if col.SQLType.Name == core.Bool {
|
||||||
|
temp += fmt.Sprintf(", %v", strconv.FormatBool(reflect.ValueOf(d).Int() > 0))
|
||||||
|
} else {
|
||||||
|
temp += fmt.Sprintf(", %v", d)
|
||||||
|
}
|
||||||
|
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||||
|
if col.SQLType.Name == core.Bool {
|
||||||
|
temp += fmt.Sprintf(", %v", strconv.FormatBool(reflect.ValueOf(d).Uint() > 0))
|
||||||
|
} else {
|
||||||
|
temp += fmt.Sprintf(", %v", d)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
temp += fmt.Sprintf(", %v", d)
|
temp += fmt.Sprintf(", %v", d)
|
||||||
}
|
}
|
||||||
|
@ -644,6 +525,33 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) tableName(beanOrTableName interface{}) (string, error) {
|
||||||
|
v := rValue(beanOrTableName)
|
||||||
|
if v.Type().Kind() == reflect.String {
|
||||||
|
return beanOrTableName.(string), nil
|
||||||
|
} else if v.Type().Kind() == reflect.Struct {
|
||||||
|
return engine.tbName(v), nil
|
||||||
|
}
|
||||||
|
return "", errors.New("bean should be a struct or struct's point")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) tbName(v reflect.Value) string {
|
||||||
|
if tb, ok := v.Interface().(TableName); ok {
|
||||||
|
return tb.TableName()
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.Type().Kind() == reflect.Ptr {
|
||||||
|
if tb, ok := reflect.Indirect(v).Interface().(TableName); ok {
|
||||||
|
return tb.TableName()
|
||||||
|
}
|
||||||
|
} else if v.CanAddr() {
|
||||||
|
if tb, ok := v.Addr().Interface().(TableName); ok {
|
||||||
|
return tb.TableName()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return engine.TableMapper.Obj2Table(reflect.Indirect(v).Type().Name())
|
||||||
|
}
|
||||||
|
|
||||||
// Cascade use cascade or not
|
// Cascade use cascade or not
|
||||||
func (engine *Engine) Cascade(trueOrFalse ...bool) *Session {
|
func (engine *Engine) Cascade(trueOrFalse ...bool) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
|
@ -716,7 +624,7 @@ func (engine *Engine) Select(str string) *Session {
|
||||||
return session.Select(str)
|
return session.Select(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cols only use the paramters as select or update columns
|
// Cols only use the parameters as select or update columns
|
||||||
func (engine *Engine) Cols(columns ...string) *Session {
|
func (engine *Engine) Cols(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
|
@ -740,15 +648,15 @@ func (engine *Engine) MustCols(columns ...string) *Session {
|
||||||
// UseBool xorm automatically retrieve condition according struct, but
|
// UseBool xorm automatically retrieve condition according struct, but
|
||||||
// if struct has bool field, it will ignore them. So use UseBool
|
// if struct has bool field, it will ignore them. So use UseBool
|
||||||
// to tell system to do not ignore them.
|
// to tell system to do not ignore them.
|
||||||
// If no paramters, it will use all the bool field of struct, or
|
// If no parameters, it will use all the bool field of struct, or
|
||||||
// it will use paramters's columns
|
// it will use parameters's columns
|
||||||
func (engine *Engine) UseBool(columns ...string) *Session {
|
func (engine *Engine) UseBool(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
return session.UseBool(columns...)
|
return session.UseBool(columns...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit only not use the paramters as select or update columns
|
// Omit only not use the parameters as select or update columns
|
||||||
func (engine *Engine) Omit(columns ...string) *Session {
|
func (engine *Engine) Omit(columns ...string) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = true
|
session.IsAutoClose = true
|
||||||
|
|
|
@ -102,7 +102,7 @@ func splitTag(tag string) (tags []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lastIdx < len(tag) {
|
if lastIdx < len(tag) {
|
||||||
tags = append(tags, strings.TrimSpace(tag[lastIdx:len(tag)]))
|
tags = append(tags, strings.TrimSpace(tag[lastIdx:]))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// default log options
|
||||||
const (
|
const (
|
||||||
DEFAULT_LOG_PREFIX = "[xorm]"
|
DEFAULT_LOG_PREFIX = "[xorm]"
|
||||||
DEFAULT_LOG_FLAG = log.Ldate | log.Lmicroseconds
|
DEFAULT_LOG_FLAG = log.Ldate | log.Lmicroseconds
|
||||||
|
|
|
@ -1,528 +1,528 @@
|
||||||
// Copyright 2015 The Xorm Authors. All rights reserved.
|
// Copyright 2015 The Xorm Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package xorm
|
package xorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mssqlReservedWords = map[string]bool{
|
mssqlReservedWords = map[string]bool{
|
||||||
"ADD": true,
|
"ADD": true,
|
||||||
"EXTERNAL": true,
|
"EXTERNAL": true,
|
||||||
"PROCEDURE": true,
|
"PROCEDURE": true,
|
||||||
"ALL": true,
|
"ALL": true,
|
||||||
"FETCH": true,
|
"FETCH": true,
|
||||||
"PUBLIC": true,
|
"PUBLIC": true,
|
||||||
"ALTER": true,
|
"ALTER": true,
|
||||||
"FILE": true,
|
"FILE": true,
|
||||||
"RAISERROR": true,
|
"RAISERROR": true,
|
||||||
"AND": true,
|
"AND": true,
|
||||||
"FILLFACTOR": true,
|
"FILLFACTOR": true,
|
||||||
"READ": true,
|
"READ": true,
|
||||||
"ANY": true,
|
"ANY": true,
|
||||||
"FOR": true,
|
"FOR": true,
|
||||||
"READTEXT": true,
|
"READTEXT": true,
|
||||||
"AS": true,
|
"AS": true,
|
||||||
"FOREIGN": true,
|
"FOREIGN": true,
|
||||||
"RECONFIGURE": true,
|
"RECONFIGURE": true,
|
||||||
"ASC": true,
|
"ASC": true,
|
||||||
"FREETEXT": true,
|
"FREETEXT": true,
|
||||||
"REFERENCES": true,
|
"REFERENCES": true,
|
||||||
"AUTHORIZATION": true,
|
"AUTHORIZATION": true,
|
||||||
"FREETEXTTABLE": true,
|
"FREETEXTTABLE": true,
|
||||||
"REPLICATION": true,
|
"REPLICATION": true,
|
||||||
"BACKUP": true,
|
"BACKUP": true,
|
||||||
"FROM": true,
|
"FROM": true,
|
||||||
"RESTORE": true,
|
"RESTORE": true,
|
||||||
"BEGIN": true,
|
"BEGIN": true,
|
||||||
"FULL": true,
|
"FULL": true,
|
||||||
"RESTRICT": true,
|
"RESTRICT": true,
|
||||||
"BETWEEN": true,
|
"BETWEEN": true,
|
||||||
"FUNCTION": true,
|
"FUNCTION": true,
|
||||||
"RETURN": true,
|
"RETURN": true,
|
||||||
"BREAK": true,
|
"BREAK": true,
|
||||||
"GOTO": true,
|
"GOTO": true,
|
||||||
"REVERT": true,
|
"REVERT": true,
|
||||||
"BROWSE": true,
|
"BROWSE": true,
|
||||||
"GRANT": true,
|
"GRANT": true,
|
||||||
"REVOKE": true,
|
"REVOKE": true,
|
||||||
"BULK": true,
|
"BULK": true,
|
||||||
"GROUP": true,
|
"GROUP": true,
|
||||||
"RIGHT": true,
|
"RIGHT": true,
|
||||||
"BY": true,
|
"BY": true,
|
||||||
"HAVING": true,
|
"HAVING": true,
|
||||||
"ROLLBACK": true,
|
"ROLLBACK": true,
|
||||||
"CASCADE": true,
|
"CASCADE": true,
|
||||||
"HOLDLOCK": true,
|
"HOLDLOCK": true,
|
||||||
"ROWCOUNT": true,
|
"ROWCOUNT": true,
|
||||||
"CASE": true,
|
"CASE": true,
|
||||||
"IDENTITY": true,
|
"IDENTITY": true,
|
||||||
"ROWGUIDCOL": true,
|
"ROWGUIDCOL": true,
|
||||||
"CHECK": true,
|
"CHECK": true,
|
||||||
"IDENTITY_INSERT": true,
|
"IDENTITY_INSERT": true,
|
||||||
"RULE": true,
|
"RULE": true,
|
||||||
"CHECKPOINT": true,
|
"CHECKPOINT": true,
|
||||||
"IDENTITYCOL": true,
|
"IDENTITYCOL": true,
|
||||||
"SAVE": true,
|
"SAVE": true,
|
||||||
"CLOSE": true,
|
"CLOSE": true,
|
||||||
"IF": true,
|
"IF": true,
|
||||||
"SCHEMA": true,
|
"SCHEMA": true,
|
||||||
"CLUSTERED": true,
|
"CLUSTERED": true,
|
||||||
"IN": true,
|
"IN": true,
|
||||||
"SECURITYAUDIT": true,
|
"SECURITYAUDIT": true,
|
||||||
"COALESCE": true,
|
"COALESCE": true,
|
||||||
"INDEX": true,
|
"INDEX": true,
|
||||||
"SELECT": true,
|
"SELECT": true,
|
||||||
"COLLATE": true,
|
"COLLATE": true,
|
||||||
"INNER": true,
|
"INNER": true,
|
||||||
"SEMANTICKEYPHRASETABLE": true,
|
"SEMANTICKEYPHRASETABLE": true,
|
||||||
"COLUMN": true,
|
"COLUMN": true,
|
||||||
"INSERT": true,
|
"INSERT": true,
|
||||||
"SEMANTICSIMILARITYDETAILSTABLE": true,
|
"SEMANTICSIMILARITYDETAILSTABLE": true,
|
||||||
"COMMIT": true,
|
"COMMIT": true,
|
||||||
"INTERSECT": true,
|
"INTERSECT": true,
|
||||||
"SEMANTICSIMILARITYTABLE": true,
|
"SEMANTICSIMILARITYTABLE": true,
|
||||||
"COMPUTE": true,
|
"COMPUTE": true,
|
||||||
"INTO": true,
|
"INTO": true,
|
||||||
"SESSION_USER": true,
|
"SESSION_USER": true,
|
||||||
"CONSTRAINT": true,
|
"CONSTRAINT": true,
|
||||||
"IS": true,
|
"IS": true,
|
||||||
"SET": true,
|
"SET": true,
|
||||||
"CONTAINS": true,
|
"CONTAINS": true,
|
||||||
"JOIN": true,
|
"JOIN": true,
|
||||||
"SETUSER": true,
|
"SETUSER": true,
|
||||||
"CONTAINSTABLE": true,
|
"CONTAINSTABLE": true,
|
||||||
"KEY": true,
|
"KEY": true,
|
||||||
"SHUTDOWN": true,
|
"SHUTDOWN": true,
|
||||||
"CONTINUE": true,
|
"CONTINUE": true,
|
||||||
"KILL": true,
|
"KILL": true,
|
||||||
"SOME": true,
|
"SOME": true,
|
||||||
"CONVERT": true,
|
"CONVERT": true,
|
||||||
"LEFT": true,
|
"LEFT": true,
|
||||||
"STATISTICS": true,
|
"STATISTICS": true,
|
||||||
"CREATE": true,
|
"CREATE": true,
|
||||||
"LIKE": true,
|
"LIKE": true,
|
||||||
"SYSTEM_USER": true,
|
"SYSTEM_USER": true,
|
||||||
"CROSS": true,
|
"CROSS": true,
|
||||||
"LINENO": true,
|
"LINENO": true,
|
||||||
"TABLE": true,
|
"TABLE": true,
|
||||||
"CURRENT": true,
|
"CURRENT": true,
|
||||||
"LOAD": true,
|
"LOAD": true,
|
||||||
"TABLESAMPLE": true,
|
"TABLESAMPLE": true,
|
||||||
"CURRENT_DATE": true,
|
"CURRENT_DATE": true,
|
||||||
"MERGE": true,
|
"MERGE": true,
|
||||||
"TEXTSIZE": true,
|
"TEXTSIZE": true,
|
||||||
"CURRENT_TIME": true,
|
"CURRENT_TIME": true,
|
||||||
"NATIONAL": true,
|
"NATIONAL": true,
|
||||||
"THEN": true,
|
"THEN": true,
|
||||||
"CURRENT_TIMESTAMP": true,
|
"CURRENT_TIMESTAMP": true,
|
||||||
"NOCHECK": true,
|
"NOCHECK": true,
|
||||||
"TO": true,
|
"TO": true,
|
||||||
"CURRENT_USER": true,
|
"CURRENT_USER": true,
|
||||||
"NONCLUSTERED": true,
|
"NONCLUSTERED": true,
|
||||||
"TOP": true,
|
"TOP": true,
|
||||||
"CURSOR": true,
|
"CURSOR": true,
|
||||||
"NOT": true,
|
"NOT": true,
|
||||||
"TRAN": true,
|
"TRAN": true,
|
||||||
"DATABASE": true,
|
"DATABASE": true,
|
||||||
"NULL": true,
|
"NULL": true,
|
||||||
"TRANSACTION": true,
|
"TRANSACTION": true,
|
||||||
"DBCC": true,
|
"DBCC": true,
|
||||||
"NULLIF": true,
|
"NULLIF": true,
|
||||||
"TRIGGER": true,
|
"TRIGGER": true,
|
||||||
"DEALLOCATE": true,
|
"DEALLOCATE": true,
|
||||||
"OF": true,
|
"OF": true,
|
||||||
"TRUNCATE": true,
|
"TRUNCATE": true,
|
||||||
"DECLARE": true,
|
"DECLARE": true,
|
||||||
"OFF": true,
|
"OFF": true,
|
||||||
"TRY_CONVERT": true,
|
"TRY_CONVERT": true,
|
||||||
"DEFAULT": true,
|
"DEFAULT": true,
|
||||||
"OFFSETS": true,
|
"OFFSETS": true,
|
||||||
"TSEQUAL": true,
|
"TSEQUAL": true,
|
||||||
"DELETE": true,
|
"DELETE": true,
|
||||||
"ON": true,
|
"ON": true,
|
||||||
"UNION": true,
|
"UNION": true,
|
||||||
"DENY": true,
|
"DENY": true,
|
||||||
"OPEN": true,
|
"OPEN": true,
|
||||||
"UNIQUE": true,
|
"UNIQUE": true,
|
||||||
"DESC": true,
|
"DESC": true,
|
||||||
"OPENDATASOURCE": true,
|
"OPENDATASOURCE": true,
|
||||||
"UNPIVOT": true,
|
"UNPIVOT": true,
|
||||||
"DISK": true,
|
"DISK": true,
|
||||||
"OPENQUERY": true,
|
"OPENQUERY": true,
|
||||||
"UPDATE": true,
|
"UPDATE": true,
|
||||||
"DISTINCT": true,
|
"DISTINCT": true,
|
||||||
"OPENROWSET": true,
|
"OPENROWSET": true,
|
||||||
"UPDATETEXT": true,
|
"UPDATETEXT": true,
|
||||||
"DISTRIBUTED": true,
|
"DISTRIBUTED": true,
|
||||||
"OPENXML": true,
|
"OPENXML": true,
|
||||||
"USE": true,
|
"USE": true,
|
||||||
"DOUBLE": true,
|
"DOUBLE": true,
|
||||||
"OPTION": true,
|
"OPTION": true,
|
||||||
"USER": true,
|
"USER": true,
|
||||||
"DROP": true,
|
"DROP": true,
|
||||||
"OR": true,
|
"OR": true,
|
||||||
"VALUES": true,
|
"VALUES": true,
|
||||||
"DUMP": true,
|
"DUMP": true,
|
||||||
"ORDER": true,
|
"ORDER": true,
|
||||||
"VARYING": true,
|
"VARYING": true,
|
||||||
"ELSE": true,
|
"ELSE": true,
|
||||||
"OUTER": true,
|
"OUTER": true,
|
||||||
"VIEW": true,
|
"VIEW": true,
|
||||||
"END": true,
|
"END": true,
|
||||||
"OVER": true,
|
"OVER": true,
|
||||||
"WAITFOR": true,
|
"WAITFOR": true,
|
||||||
"ERRLVL": true,
|
"ERRLVL": true,
|
||||||
"PERCENT": true,
|
"PERCENT": true,
|
||||||
"WHEN": true,
|
"WHEN": true,
|
||||||
"ESCAPE": true,
|
"ESCAPE": true,
|
||||||
"PIVOT": true,
|
"PIVOT": true,
|
||||||
"WHERE": true,
|
"WHERE": true,
|
||||||
"EXCEPT": true,
|
"EXCEPT": true,
|
||||||
"PLAN": true,
|
"PLAN": true,
|
||||||
"WHILE": true,
|
"WHILE": true,
|
||||||
"EXEC": true,
|
"EXEC": true,
|
||||||
"PRECISION": true,
|
"PRECISION": true,
|
||||||
"WITH": true,
|
"WITH": true,
|
||||||
"EXECUTE": true,
|
"EXECUTE": true,
|
||||||
"PRIMARY": true,
|
"PRIMARY": true,
|
||||||
"WITHIN": true,
|
"WITHIN": true,
|
||||||
"EXISTS": true,
|
"EXISTS": true,
|
||||||
"PRINT": true,
|
"PRINT": true,
|
||||||
"WRITETEXT": true,
|
"WRITETEXT": true,
|
||||||
"EXIT": true,
|
"EXIT": true,
|
||||||
"PROC": true,
|
"PROC": true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type mssql struct {
|
type mssql struct {
|
||||||
core.Base
|
core.Base
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) Init(d *core.DB, uri *core.Uri, drivername, dataSourceName string) error {
|
func (db *mssql) Init(d *core.DB, uri *core.Uri, drivername, dataSourceName string) error {
|
||||||
return db.Base.Init(d, db, uri, drivername, dataSourceName)
|
return db.Base.Init(d, db, uri, drivername, dataSourceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) SqlType(c *core.Column) string {
|
func (db *mssql) SqlType(c *core.Column) string {
|
||||||
var res string
|
var res string
|
||||||
switch t := c.SQLType.Name; t {
|
switch t := c.SQLType.Name; t {
|
||||||
case core.Bool:
|
case core.Bool:
|
||||||
res = core.TinyInt
|
res = core.TinyInt
|
||||||
if c.Default == "true" {
|
if c.Default == "true" {
|
||||||
c.Default = "1"
|
c.Default = "1"
|
||||||
} else if c.Default == "false" {
|
} else if c.Default == "false" {
|
||||||
c.Default = "0"
|
c.Default = "0"
|
||||||
}
|
}
|
||||||
case core.Serial:
|
case core.Serial:
|
||||||
c.IsAutoIncrement = true
|
c.IsAutoIncrement = true
|
||||||
c.IsPrimaryKey = true
|
c.IsPrimaryKey = true
|
||||||
c.Nullable = false
|
c.Nullable = false
|
||||||
res = core.Int
|
res = core.Int
|
||||||
case core.BigSerial:
|
case core.BigSerial:
|
||||||
c.IsAutoIncrement = true
|
c.IsAutoIncrement = true
|
||||||
c.IsPrimaryKey = true
|
c.IsPrimaryKey = true
|
||||||
c.Nullable = false
|
c.Nullable = false
|
||||||
res = core.BigInt
|
res = core.BigInt
|
||||||
case core.Bytea, core.Blob, core.Binary, core.TinyBlob, core.MediumBlob, core.LongBlob:
|
case core.Bytea, core.Blob, core.Binary, core.TinyBlob, core.MediumBlob, core.LongBlob:
|
||||||
res = core.VarBinary
|
res = core.VarBinary
|
||||||
if c.Length == 0 {
|
if c.Length == 0 {
|
||||||
c.Length = 50
|
c.Length = 50
|
||||||
}
|
}
|
||||||
case core.TimeStamp:
|
case core.TimeStamp:
|
||||||
res = core.DateTime
|
res = core.DateTime
|
||||||
case core.TimeStampz:
|
case core.TimeStampz:
|
||||||
res = "DATETIMEOFFSET"
|
res = "DATETIMEOFFSET"
|
||||||
c.Length = 7
|
c.Length = 7
|
||||||
case core.MediumInt:
|
case core.MediumInt:
|
||||||
res = core.Int
|
res = core.Int
|
||||||
case core.Text, core.MediumText, core.TinyText, core.LongText, core.Json:
|
case core.Text, core.MediumText, core.TinyText, core.LongText, core.Json:
|
||||||
res = core.Varchar + "(MAX)"
|
res = core.Varchar + "(MAX)"
|
||||||
case core.Double:
|
case core.Double:
|
||||||
res = core.Real
|
res = core.Real
|
||||||
case core.Uuid:
|
case core.Uuid:
|
||||||
res = core.Varchar
|
res = core.Varchar
|
||||||
c.Length = 40
|
c.Length = 40
|
||||||
default:
|
default:
|
||||||
res = t
|
res = t
|
||||||
}
|
}
|
||||||
|
|
||||||
if res == core.Int {
|
if res == core.Int {
|
||||||
return core.Int
|
return core.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
hasLen1 := (c.Length > 0)
|
hasLen1 := (c.Length > 0)
|
||||||
hasLen2 := (c.Length2 > 0)
|
hasLen2 := (c.Length2 > 0)
|
||||||
|
|
||||||
if hasLen2 {
|
if hasLen2 {
|
||||||
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")"
|
||||||
} else if hasLen1 {
|
} else if hasLen1 {
|
||||||
res += "(" + strconv.Itoa(c.Length) + ")"
|
res += "(" + strconv.Itoa(c.Length) + ")"
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) SupportInsertMany() bool {
|
func (db *mssql) SupportInsertMany() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) IsReserved(name string) bool {
|
func (db *mssql) IsReserved(name string) bool {
|
||||||
_, ok := mssqlReservedWords[name]
|
_, ok := mssqlReservedWords[name]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) Quote(name string) string {
|
func (db *mssql) Quote(name string) string {
|
||||||
return "\"" + name + "\""
|
return "\"" + name + "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) QuoteStr() string {
|
func (db *mssql) QuoteStr() string {
|
||||||
return "\""
|
return "\""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) SupportEngine() bool {
|
func (db *mssql) SupportEngine() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) AutoIncrStr() string {
|
func (db *mssql) AutoIncrStr() string {
|
||||||
return "IDENTITY"
|
return "IDENTITY"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) DropTableSql(tableName string) string {
|
func (db *mssql) DropTableSql(tableName string) string {
|
||||||
return fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+
|
return fmt.Sprintf("IF EXISTS (SELECT * FROM sysobjects WHERE id = "+
|
||||||
"object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+
|
"object_id(N'%s') and OBJECTPROPERTY(id, N'IsUserTable') = 1) "+
|
||||||
"DROP TABLE \"%s\"", tableName, tableName)
|
"DROP TABLE \"%s\"", tableName, tableName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) SupportCharset() bool {
|
func (db *mssql) SupportCharset() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) IndexOnTable() bool {
|
func (db *mssql) IndexOnTable() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) IndexCheckSql(tableName, idxName string) (string, []interface{}) {
|
func (db *mssql) IndexCheckSql(tableName, idxName string) (string, []interface{}) {
|
||||||
args := []interface{}{idxName}
|
args := []interface{}{idxName}
|
||||||
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
|
sql := "select name from sysindexes where id=object_id('" + tableName + "') and name=?"
|
||||||
return sql, args
|
return sql, args
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func (db *mssql) ColumnCheckSql(tableName, colName string) (string, []interface{}) {
|
/*func (db *mssql) ColumnCheckSql(tableName, colName string) (string, []interface{}) {
|
||||||
args := []interface{}{tableName, colName}
|
args := []interface{}{tableName, colName}
|
||||||
sql := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
|
sql := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
|
||||||
return sql, args
|
return sql, args
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
func (db *mssql) IsColumnExist(tableName, colName string) (bool, error) {
|
func (db *mssql) IsColumnExist(tableName, colName string) (bool, error) {
|
||||||
query := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
|
query := `SELECT "COLUMN_NAME" FROM "INFORMATION_SCHEMA"."COLUMNS" WHERE "TABLE_NAME" = ? AND "COLUMN_NAME" = ?`
|
||||||
|
|
||||||
return db.HasRecords(query, tableName, colName)
|
return db.HasRecords(query, tableName, colName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) TableCheckSql(tableName string) (string, []interface{}) {
|
func (db *mssql) TableCheckSql(tableName string) (string, []interface{}) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
sql := "select * from sysobjects where id = object_id(N'" + tableName + "') and OBJECTPROPERTY(id, N'IsUserTable') = 1"
|
sql := "select * from sysobjects where id = object_id(N'" + tableName + "') and OBJECTPROPERTY(id, N'IsUserTable') = 1"
|
||||||
return sql, args
|
return sql, args
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
|
s := `select a.name as name, b.name as ctype,a.max_length,a.precision,a.scale,a.is_nullable as nullable,
|
||||||
replace(replace(isnull(c.text,''),'(',''),')','') as vdefault
|
replace(replace(isnull(c.text,''),'(',''),')','') as vdefault
|
||||||
from sys.columns a left join sys.types b on a.user_type_id=b.user_type_id
|
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 join sys.syscomments c on a.default_object_id=c.id
|
||||||
where a.object_id=object_id('` + tableName + `')`
|
where a.object_id=object_id('` + tableName + `')`
|
||||||
db.LogSQL(s, args)
|
db.LogSQL(s, args)
|
||||||
|
|
||||||
rows, err := db.DB().Query(s, args...)
|
rows, err := db.DB().Query(s, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
cols := make(map[string]*core.Column)
|
cols := make(map[string]*core.Column)
|
||||||
colSeq := make([]string, 0)
|
colSeq := make([]string, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var name, ctype, vdefault string
|
var name, ctype, vdefault string
|
||||||
var maxLen, precision, scale int
|
var maxLen, precision, scale int
|
||||||
var nullable bool
|
var nullable bool
|
||||||
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &vdefault)
|
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &vdefault)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
col := new(core.Column)
|
col := new(core.Column)
|
||||||
col.Indexes = make(map[string]int)
|
col.Indexes = make(map[string]int)
|
||||||
col.Name = strings.Trim(name, "` ")
|
col.Name = strings.Trim(name, "` ")
|
||||||
col.Nullable = nullable
|
col.Nullable = nullable
|
||||||
col.Default = vdefault
|
col.Default = vdefault
|
||||||
ct := strings.ToUpper(ctype)
|
ct := strings.ToUpper(ctype)
|
||||||
if ct == "DECIMAL" {
|
if ct == "DECIMAL" {
|
||||||
col.Length = precision
|
col.Length = precision
|
||||||
col.Length2 = scale
|
col.Length2 = scale
|
||||||
} else {
|
} else {
|
||||||
col.Length = maxLen
|
col.Length = maxLen
|
||||||
}
|
}
|
||||||
switch ct {
|
switch ct {
|
||||||
case "DATETIMEOFFSET":
|
case "DATETIMEOFFSET":
|
||||||
col.SQLType = core.SQLType{Name: core.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = core.SQLType{Name: core.TimeStampz, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "NVARCHAR":
|
case "NVARCHAR":
|
||||||
col.SQLType = core.SQLType{Name: core.NVarchar, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = core.SQLType{Name: core.NVarchar, DefaultLength: 0, DefaultLength2: 0}
|
||||||
case "IMAGE":
|
case "IMAGE":
|
||||||
col.SQLType = core.SQLType{Name: core.VarBinary, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = core.SQLType{Name: core.VarBinary, DefaultLength: 0, DefaultLength2: 0}
|
||||||
default:
|
default:
|
||||||
if _, ok := core.SqlTypes[ct]; ok {
|
if _, ok := core.SqlTypes[ct]; ok {
|
||||||
col.SQLType = core.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0}
|
col.SQLType = core.SQLType{Name: ct, DefaultLength: 0, DefaultLength2: 0}
|
||||||
} else {
|
} else {
|
||||||
return nil, nil, fmt.Errorf("Unknown colType %v for %v - %v", ct, tableName, col.Name)
|
return nil, nil, fmt.Errorf("Unknown colType %v for %v - %v", ct, tableName, col.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.SQLType.IsText() || col.SQLType.IsTime() {
|
if col.SQLType.IsText() || col.SQLType.IsTime() {
|
||||||
if col.Default != "" {
|
if col.Default != "" {
|
||||||
col.Default = "'" + col.Default + "'"
|
col.Default = "'" + col.Default + "'"
|
||||||
} else {
|
} else {
|
||||||
if col.DefaultIsEmpty {
|
if col.DefaultIsEmpty {
|
||||||
col.Default = "''"
|
col.Default = "''"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cols[col.Name] = col
|
cols[col.Name] = col
|
||||||
colSeq = append(colSeq, col.Name)
|
colSeq = append(colSeq, col.Name)
|
||||||
}
|
}
|
||||||
return colSeq, cols, nil
|
return colSeq, cols, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) GetTables() ([]*core.Table, error) {
|
func (db *mssql) GetTables() ([]*core.Table, error) {
|
||||||
args := []interface{}{}
|
args := []interface{}{}
|
||||||
s := `select name from sysobjects where xtype ='U'`
|
s := `select name from sysobjects where xtype ='U'`
|
||||||
db.LogSQL(s, args)
|
db.LogSQL(s, args)
|
||||||
|
|
||||||
rows, err := db.DB().Query(s, args...)
|
rows, err := db.DB().Query(s, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
tables := make([]*core.Table, 0)
|
tables := make([]*core.Table, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
table := core.NewEmptyTable()
|
table := core.NewEmptyTable()
|
||||||
var name string
|
var name string
|
||||||
err = rows.Scan(&name)
|
err = rows.Scan(&name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
table.Name = strings.Trim(name, "` ")
|
table.Name = strings.Trim(name, "` ")
|
||||||
tables = append(tables, table)
|
tables = append(tables, table)
|
||||||
}
|
}
|
||||||
return tables, nil
|
return tables, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
func (db *mssql) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
||||||
args := []interface{}{tableName}
|
args := []interface{}{tableName}
|
||||||
s := `SELECT
|
s := `SELECT
|
||||||
IXS.NAME AS [INDEX_NAME],
|
IXS.NAME AS [INDEX_NAME],
|
||||||
C.NAME AS [COLUMN_NAME],
|
C.NAME AS [COLUMN_NAME],
|
||||||
IXS.is_unique AS [IS_UNIQUE]
|
IXS.is_unique AS [IS_UNIQUE]
|
||||||
FROM SYS.INDEXES IXS
|
FROM SYS.INDEXES IXS
|
||||||
INNER JOIN SYS.INDEX_COLUMNS IXCS
|
INNER JOIN SYS.INDEX_COLUMNS IXCS
|
||||||
ON IXS.OBJECT_ID=IXCS.OBJECT_ID AND IXS.INDEX_ID = IXCS.INDEX_ID
|
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
|
INNER JOIN SYS.COLUMNS C ON IXS.OBJECT_ID=C.OBJECT_ID
|
||||||
AND IXCS.COLUMN_ID=C.COLUMN_ID
|
AND IXCS.COLUMN_ID=C.COLUMN_ID
|
||||||
WHERE IXS.TYPE_DESC='NONCLUSTERED' and OBJECT_NAME(IXS.OBJECT_ID) =?
|
WHERE IXS.TYPE_DESC='NONCLUSTERED' and OBJECT_NAME(IXS.OBJECT_ID) =?
|
||||||
`
|
`
|
||||||
db.LogSQL(s, args)
|
db.LogSQL(s, args)
|
||||||
|
|
||||||
rows, err := db.DB().Query(s, args...)
|
rows, err := db.DB().Query(s, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
indexes := make(map[string]*core.Index, 0)
|
indexes := make(map[string]*core.Index, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var indexType int
|
var indexType int
|
||||||
var indexName, colName, isUnique string
|
var indexName, colName, isUnique string
|
||||||
|
|
||||||
err = rows.Scan(&indexName, &colName, &isUnique)
|
err = rows.Scan(&indexName, &colName, &isUnique)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
i, err := strconv.ParseBool(isUnique)
|
i, err := strconv.ParseBool(isUnique)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if i {
|
if i {
|
||||||
indexType = core.UniqueType
|
indexType = core.UniqueType
|
||||||
} else {
|
} else {
|
||||||
indexType = core.IndexType
|
indexType = core.IndexType
|
||||||
}
|
}
|
||||||
|
|
||||||
colName = strings.Trim(colName, "` ")
|
colName = strings.Trim(colName, "` ")
|
||||||
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
indexName = indexName[5+len(tableName):]
|
indexName = indexName[5+len(tableName):]
|
||||||
}
|
}
|
||||||
|
|
||||||
var index *core.Index
|
var index *core.Index
|
||||||
var ok bool
|
var ok bool
|
||||||
if index, ok = indexes[indexName]; !ok {
|
if index, ok = indexes[indexName]; !ok {
|
||||||
index = new(core.Index)
|
index = new(core.Index)
|
||||||
index.Type = indexType
|
index.Type = indexType
|
||||||
index.Name = indexName
|
index.Name = indexName
|
||||||
indexes[indexName] = index
|
indexes[indexName] = index
|
||||||
}
|
}
|
||||||
index.AddColumn(colName)
|
index.AddColumn(colName)
|
||||||
}
|
}
|
||||||
return indexes, nil
|
return indexes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) CreateTableSql(table *core.Table, tableName, storeEngine, charset string) string {
|
func (db *mssql) CreateTableSql(table *core.Table, tableName, storeEngine, charset string) string {
|
||||||
var sql string
|
var sql string
|
||||||
if tableName == "" {
|
if tableName == "" {
|
||||||
tableName = table.Name
|
tableName = table.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '" + tableName + "' ) CREATE TABLE "
|
sql = "IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = '" + tableName + "' ) CREATE TABLE "
|
||||||
|
|
||||||
sql += db.QuoteStr() + tableName + db.QuoteStr() + " ("
|
sql += db.QuoteStr() + tableName + db.QuoteStr() + " ("
|
||||||
|
|
||||||
pkList := table.PrimaryKeys
|
pkList := table.PrimaryKeys
|
||||||
|
|
||||||
for _, colName := range table.ColumnsSeq() {
|
for _, colName := range table.ColumnsSeq() {
|
||||||
col := table.GetColumn(colName)
|
col := table.GetColumn(colName)
|
||||||
if col.IsPrimaryKey && len(pkList) == 1 {
|
if col.IsPrimaryKey && len(pkList) == 1 {
|
||||||
sql += col.String(db)
|
sql += col.String(db)
|
||||||
} else {
|
} else {
|
||||||
sql += col.StringNoPk(db)
|
sql += col.StringNoPk(db)
|
||||||
}
|
}
|
||||||
sql = strings.TrimSpace(sql)
|
sql = strings.TrimSpace(sql)
|
||||||
sql += ", "
|
sql += ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pkList) > 1 {
|
if len(pkList) > 1 {
|
||||||
sql += "PRIMARY KEY ( "
|
sql += "PRIMARY KEY ( "
|
||||||
sql += strings.Join(pkList, ",")
|
sql += strings.Join(pkList, ",")
|
||||||
sql += " ), "
|
sql += " ), "
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = sql[:len(sql)-2] + ")"
|
sql = sql[:len(sql)-2] + ")"
|
||||||
sql += ";"
|
sql += ";"
|
||||||
return sql
|
return sql
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) ForUpdateSql(query string) string {
|
func (db *mssql) ForUpdateSql(query string) string {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *mssql) Filters() []core.Filter {
|
func (db *mssql) Filters() []core.Filter {
|
||||||
return []core.Filter{&core.IdFilter{}, &core.QuoteFilter{}}
|
return []core.Filter{&core.IdFilter{}, &core.QuoteFilter{}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -465,7 +465,7 @@ func (db *mysql) GetIndexes(tableName string) (map[string]*core.Index, error) {
|
||||||
colName = strings.Trim(colName, "` ")
|
colName = strings.Trim(colName, "` ")
|
||||||
var isRegular bool
|
var isRegular bool
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
indexName = indexName[5+len(tableName) : len(indexName)]
|
indexName = indexName[5+len(tableName):]
|
||||||
isRegular = true
|
isRegular = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1077,7 +1077,7 @@ func (db *postgres) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")
|
||||||
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
newIdxName := indexName[5+len(tableName) : len(indexName)]
|
newIdxName := indexName[5+len(tableName):]
|
||||||
if newIdxName != "" {
|
if newIdxName != "" {
|
||||||
indexName = newIdxName
|
indexName = newIdxName
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ func (session *Session) resetStatement() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare set a flag to session that should be prepare statment before execute query
|
// Prepare set a flag to session that should be prepare statement before execute query
|
||||||
func (session *Session) Prepare() *Session {
|
func (session *Session) Prepare() *Session {
|
||||||
session.prepareStmt = true
|
session.prepareStmt = true
|
||||||
return session
|
return session
|
||||||
|
@ -250,8 +250,8 @@ func (session *Session) NoCascade() *Session {
|
||||||
// UseBool automatically retrieve condition according struct, but
|
// UseBool automatically retrieve condition according struct, but
|
||||||
// if struct has bool field, it will ignore them. So use UseBool
|
// if struct has bool field, it will ignore them. So use UseBool
|
||||||
// to tell system to do not ignore them.
|
// to tell system to do not ignore them.
|
||||||
// If no paramters, it will use all the bool field of struct, or
|
// If no parameters, it will use all the bool field of struct, or
|
||||||
// it will use paramters's columns
|
// it will use parameters's columns
|
||||||
func (session *Session) UseBool(columns ...string) *Session {
|
func (session *Session) UseBool(columns ...string) *Session {
|
||||||
session.Statement.UseBool(columns...)
|
session.Statement.UseBool(columns...)
|
||||||
return session
|
return session
|
||||||
|
@ -271,7 +271,7 @@ func (session *Session) ForUpdate() *Session {
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit Only not use the paramters as select or update columns
|
// Omit Only not use the parameters as select or update columns
|
||||||
func (session *Session) Omit(columns ...string) *Session {
|
func (session *Session) Omit(columns ...string) *Session {
|
||||||
session.Statement.Omit(columns...)
|
session.Statement.Omit(columns...)
|
||||||
return session
|
return session
|
||||||
|
@ -1005,7 +1005,7 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
|
||||||
sd, err := strconv.ParseInt(sdata, 10, 64)
|
sd, err := strconv.ParseInt(sdata, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
x = time.Unix(sd, 0)
|
x = time.Unix(sd, 0)
|
||||||
// !nashtsai! HACK mymysql driver is casuing Local location being change to CHAT and cause wrong time conversion
|
// !nashtsai! HACK mymysql driver is causing Local location being change to CHAT and cause wrong time conversion
|
||||||
if col.TimeZone == nil {
|
if col.TimeZone == nil {
|
||||||
x = x.In(session.Engine.TZLocation)
|
x = x.In(session.Engine.TZLocation)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -65,7 +65,8 @@ func (session *Session) nocacheGet(bean interface{}, sqlStr string, args ...inte
|
||||||
defer rawRows.Close()
|
defer rawRows.Close()
|
||||||
|
|
||||||
if rawRows.Next() {
|
if rawRows.Next() {
|
||||||
if fields, err := rawRows.Columns(); err == nil {
|
fields, err := rawRows.Columns()
|
||||||
|
if err == nil {
|
||||||
err = session.row2Bean(rawRows, fields, len(fields), bean)
|
err = session.row2Bean(rawRows, fields, len(fields), bean)
|
||||||
}
|
}
|
||||||
return true, err
|
return true, err
|
||||||
|
|
|
@ -406,7 +406,7 @@ func (db *sqlite3) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
|
|
||||||
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
index.Name = indexName[5+len(tableName) : len(indexName)]
|
index.Name = indexName[5+len(tableName):]
|
||||||
} else {
|
} else {
|
||||||
index.Name = indexName
|
index.Name = indexName
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ type Statement struct {
|
||||||
cond builder.Cond
|
cond builder.Cond
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init reset all the statment's fields
|
// Init reset all the statement's fields
|
||||||
func (statement *Statement) Init() {
|
func (statement *Statement) Init() {
|
||||||
statement.RefTable = nil
|
statement.RefTable = nil
|
||||||
statement.Start = 0
|
statement.Start = 0
|
||||||
|
@ -147,12 +147,12 @@ func (statement *Statement) SQL(query interface{}, args ...interface{}) *Stateme
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where add Where statment
|
// Where add Where statement
|
||||||
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement {
|
||||||
return statement.And(query, args...)
|
return statement.And(query, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// And add Where & and statment
|
// And add Where & and statement
|
||||||
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) And(query interface{}, args ...interface{}) *Statement {
|
||||||
switch query.(type) {
|
switch query.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
@ -173,7 +173,7 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Or add Where & Or statment
|
// Or add Where & Or statement
|
||||||
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement {
|
||||||
switch query.(type) {
|
switch query.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
@ -193,7 +193,7 @@ func (statement *Statement) Or(query interface{}, args ...interface{}) *Statemen
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// In generate "Where column IN (?) " statment
|
// In generate "Where column IN (?) " statement
|
||||||
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return statement
|
return statement
|
||||||
|
@ -204,7 +204,7 @@ func (statement *Statement) In(column string, args ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotIn generate "Where column NOT IN (?) " statment
|
// NotIn generate "Where column NOT IN (?) " statement
|
||||||
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
func (statement *Statement) NotIn(column string, args ...interface{}) *Statement {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return statement
|
return statement
|
||||||
|
@ -706,14 +706,14 @@ func (statement *Statement) TableName() string {
|
||||||
return statement.tableName
|
return statement.tableName
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
|
// Id generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
||||||
//
|
//
|
||||||
// Deprecated: use ID instead
|
// Deprecated: use ID instead
|
||||||
func (statement *Statement) Id(id interface{}) *Statement {
|
func (statement *Statement) Id(id interface{}) *Statement {
|
||||||
return statement.ID(id)
|
return statement.ID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"
|
// ID generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
||||||
func (statement *Statement) ID(id interface{}) *Statement {
|
func (statement *Statement) ID(id interface{}) *Statement {
|
||||||
idValue := reflect.ValueOf(id)
|
idValue := reflect.ValueOf(id)
|
||||||
idType := reflect.TypeOf(idValue.Interface())
|
idType := reflect.TypeOf(idValue.Interface())
|
||||||
|
@ -741,7 +741,7 @@ func (statement *Statement) ID(id interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Incr Generate "Update ... Set column = column + arg" statment
|
// Incr Generate "Update ... Set column = column + arg" statement
|
||||||
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
@ -752,7 +752,7 @@ func (statement *Statement) Incr(column string, arg ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decr Generate "Update ... Set column = column - arg" statment
|
// Decr Generate "Update ... Set column = column - arg" statement
|
||||||
func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
|
@ -763,24 +763,24 @@ func (statement *Statement) Decr(column string, arg ...interface{}) *Statement {
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetExpr Generate "Update ... Set column = {expression}" statment
|
// SetExpr Generate "Update ... Set column = {expression}" statement
|
||||||
func (statement *Statement) SetExpr(column string, expression string) *Statement {
|
func (statement *Statement) SetExpr(column string, expression string) *Statement {
|
||||||
k := strings.ToLower(column)
|
k := strings.ToLower(column)
|
||||||
statement.exprColumns[k] = exprParam{column, expression}
|
statement.exprColumns[k] = exprParam{column, expression}
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = column + arg" statment
|
// Generate "Update ... Set column = column + arg" statement
|
||||||
func (statement *Statement) getInc() map[string]incrParam {
|
func (statement *Statement) getInc() map[string]incrParam {
|
||||||
return statement.incrColumns
|
return statement.incrColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = column - arg" statment
|
// Generate "Update ... Set column = column - arg" statement
|
||||||
func (statement *Statement) getDec() map[string]decrParam {
|
func (statement *Statement) getDec() map[string]decrParam {
|
||||||
return statement.decrColumns
|
return statement.decrColumns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate "Update ... Set column = {expression}" statment
|
// Generate "Update ... Set column = {expression}" statement
|
||||||
func (statement *Statement) getExpr() map[string]exprParam {
|
func (statement *Statement) getExpr() map[string]exprParam {
|
||||||
return statement.exprColumns
|
return statement.exprColumns
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package xorm
|
package xorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -243,10 +243,10 @@
|
||||||
"revisionTime": "2016-08-11T02:11:45Z"
|
"revisionTime": "2016-08-11T02:11:45Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "eEVm8NprkjOX2HZVxIJwbOLD5Hg=",
|
"checksumSHA1": "kAy5B68FSqoQNXWGnwdmmzZ0ElQ=",
|
||||||
"path": "github.com/go-xorm/xorm",
|
"path": "github.com/go-xorm/xorm",
|
||||||
"revision": "44b70cccf417e3d4a565aaa3128853b5cd553767",
|
"revision": "c360c20aa58a6dec86084967e93f673c57278da1",
|
||||||
"revisionTime": "2017-01-03T05:31:47Z"
|
"revisionTime": "2017-01-20T02:12:06Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"checksumSHA1": "1ft/4j5MFa7C9dPI9whL03HSUzk=",
|
"checksumSHA1": "1ft/4j5MFa7C9dPI9whL03HSUzk=",
|
||||||
|
|
Loading…
Reference in New Issue