Browse Source

vendor: update github.com/go-xorm/* (#4419)

pull/4551/head
Unknwon 8 years ago
parent
commit
b40dc550ed
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 2
      gogs.go
  2. 2
      templates/.VERSION
  3. 38
      vendor/github.com/go-xorm/builder/cond_in.go
  4. 5
      vendor/github.com/go-xorm/builder/cond_like.go
  5. 49
      vendor/github.com/go-xorm/builder/cond_notin.go
  6. 2
      vendor/github.com/go-xorm/core/column.go
  7. 4
      vendor/github.com/go-xorm/core/dialect.go
  8. 1
      vendor/github.com/go-xorm/core/table.go
  9. 3
      vendor/github.com/go-xorm/xorm/README.md
  10. 3
      vendor/github.com/go-xorm/xorm/README_CN.md
  11. 0
      vendor/github.com/go-xorm/xorm/cache_lru.go
  12. 0
      vendor/github.com/go-xorm/xorm/cache_memory_store.go
  13. 6
      vendor/github.com/go-xorm/xorm/circle.yml
  14. 21
      vendor/github.com/go-xorm/xorm/dialect_mssql.go
  15. 14
      vendor/github.com/go-xorm/xorm/dialect_mysql.go
  16. 18
      vendor/github.com/go-xorm/xorm/dialect_sqlite3.go
  17. 11
      vendor/github.com/go-xorm/xorm/doc.go
  18. 100
      vendor/github.com/go-xorm/xorm/engine.go
  19. 209
      vendor/github.com/go-xorm/xorm/helpers.go
  20. 21
      vendor/github.com/go-xorm/xorm/helpler_time.go
  21. 22
      vendor/github.com/go-xorm/xorm/session.go
  22. 33
      vendor/github.com/go-xorm/xorm/session_convert.go
  23. 5
      vendor/github.com/go-xorm/xorm/session_find.go
  24. 16
      vendor/github.com/go-xorm/xorm/session_insert.go
  25. 173
      vendor/github.com/go-xorm/xorm/session_raw.go
  26. 53
      vendor/github.com/go-xorm/xorm/session_schema.go
  27. 7
      vendor/github.com/go-xorm/xorm/session_sum.go
  28. 14
      vendor/github.com/go-xorm/xorm/session_update.go
  29. 6
      vendor/github.com/go-xorm/xorm/statement.go
  30. 1
      vendor/github.com/go-xorm/xorm/test_mssql.sh
  31. 1
      vendor/github.com/go-xorm/xorm/test_mysql.sh
  32. 1
      vendor/github.com/go-xorm/xorm/test_postgres.sh
  33. 1
      vendor/github.com/go-xorm/xorm/test_sqlite.sh
  34. 8
      vendor/github.com/go-xorm/xorm/xorm.go
  35. 18
      vendor/vendor.json

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/pkg/setting" "github.com/gogits/gogs/pkg/setting"
) )
const APP_VER = "0.11.17.0606" const APP_VER = "0.11.17.0607"
func init() { func init() {
setting.AppVer = APP_VER setting.AppVer = APP_VER

2
templates/.VERSION

@ -1 +1 @@
0.11.17.0606 0.11.17.0607

38
vendor/github.com/go-xorm/builder/cond_in.go generated vendored

@ -22,16 +22,21 @@ func In(col string, values ...interface{}) Cond {
return condIn{col, values} return condIn{col, values}
} }
func (condIn condIn) handleBlank(w Writer) error {
_, err := fmt.Fprint(w, "0=1")
return err
}
func (condIn condIn) WriteTo(w Writer) error { func (condIn condIn) WriteTo(w Writer) error {
if len(condIn.vals) <= 0 { if len(condIn.vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
switch condIn.vals[0].(type) { switch condIn.vals[0].(type) {
case []int8: case []int8:
vals := condIn.vals[0].([]int8) vals := condIn.vals[0].([]int8)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -43,7 +48,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []int16: case []int16:
vals := condIn.vals[0].([]int16) vals := condIn.vals[0].([]int16)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -55,7 +60,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []int: case []int:
vals := condIn.vals[0].([]int) vals := condIn.vals[0].([]int)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -67,7 +72,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []int32: case []int32:
vals := condIn.vals[0].([]int32) vals := condIn.vals[0].([]int32)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -79,7 +84,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []int64: case []int64:
vals := condIn.vals[0].([]int64) vals := condIn.vals[0].([]int64)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -91,7 +96,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []uint8: case []uint8:
vals := condIn.vals[0].([]uint8) vals := condIn.vals[0].([]uint8)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -103,7 +108,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []uint16: case []uint16:
vals := condIn.vals[0].([]uint16) vals := condIn.vals[0].([]uint16)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -115,7 +120,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []uint: case []uint:
vals := condIn.vals[0].([]uint) vals := condIn.vals[0].([]uint)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -127,7 +132,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []uint32: case []uint32:
vals := condIn.vals[0].([]uint32) vals := condIn.vals[0].([]uint32)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -139,7 +144,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []uint64: case []uint64:
vals := condIn.vals[0].([]uint64) vals := condIn.vals[0].([]uint64)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -151,7 +156,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []string: case []string:
vals := condIn.vals[0].([]string) vals := condIn.vals[0].([]string)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -163,7 +168,7 @@ func (condIn condIn) WriteTo(w Writer) error {
case []interface{}: case []interface{}:
vals := condIn.vals[0].([]interface{}) vals := condIn.vals[0].([]interface{})
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoInConditions return condIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -193,13 +198,12 @@ func (condIn condIn) WriteTo(w Writer) error {
return err return err
} }
default: default:
if len(condIn.vals) <= 0 {
return ErrNoInConditions
}
v := reflect.ValueOf(condIn.vals[0]) v := reflect.ValueOf(condIn.vals[0])
if v.Kind() == reflect.Slice { if v.Kind() == reflect.Slice {
l := v.Len() l := v.Len()
if l == 0 {
return condIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", l) questionMark := strings.Repeat("?,", l)
if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s IN (%s)", condIn.col, questionMark[:len(questionMark)-1]); err != nil {

5
vendor/github.com/go-xorm/builder/cond_like.go generated vendored

@ -16,7 +16,12 @@ func (like Like) WriteTo(w Writer) error {
if _, err := fmt.Fprintf(w, "%s LIKE ?", like[0]); err != nil { if _, err := fmt.Fprintf(w, "%s LIKE ?", like[0]); err != nil {
return err return err
} }
// FIXME: if use other regular express, this will be failed. but for compitable, keep this
if like[1][0] == '%' || like[1][len(like[1])-1] == '%' {
w.Append(like[1])
} else {
w.Append("%" + like[1] + "%") w.Append("%" + like[1] + "%")
}
return nil return nil
} }

49
vendor/github.com/go-xorm/builder/cond_notin.go generated vendored

@ -6,6 +6,7 @@ package builder
import ( import (
"fmt" "fmt"
"reflect"
"strings" "strings"
) )
@ -18,16 +19,21 @@ func NotIn(col string, values ...interface{}) Cond {
return condNotIn{col, values} return condNotIn{col, values}
} }
func (condNotIn condNotIn) handleBlank(w Writer) error {
_, err := fmt.Fprint(w, "0=0")
return err
}
func (condNotIn condNotIn) WriteTo(w Writer) error { func (condNotIn condNotIn) WriteTo(w Writer) error {
if len(condNotIn.vals) <= 0 { if len(condNotIn.vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
switch condNotIn.vals[0].(type) { switch condNotIn.vals[0].(type) {
case []int8: case []int8:
vals := condNotIn.vals[0].([]int8) vals := condNotIn.vals[0].([]int8)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -39,7 +45,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int16: case []int16:
vals := condNotIn.vals[0].([]int16) vals := condNotIn.vals[0].([]int16)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -51,7 +57,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int: case []int:
vals := condNotIn.vals[0].([]int) vals := condNotIn.vals[0].([]int)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -63,7 +69,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int32: case []int32:
vals := condNotIn.vals[0].([]int32) vals := condNotIn.vals[0].([]int32)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -75,7 +81,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []int64: case []int64:
vals := condNotIn.vals[0].([]int64) vals := condNotIn.vals[0].([]int64)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -87,7 +93,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint8: case []uint8:
vals := condNotIn.vals[0].([]uint8) vals := condNotIn.vals[0].([]uint8)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -99,7 +105,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint16: case []uint16:
vals := condNotIn.vals[0].([]uint16) vals := condNotIn.vals[0].([]uint16)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -111,7 +117,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint: case []uint:
vals := condNotIn.vals[0].([]uint) vals := condNotIn.vals[0].([]uint)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -123,7 +129,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint32: case []uint32:
vals := condNotIn.vals[0].([]uint32) vals := condNotIn.vals[0].([]uint32)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -135,7 +141,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []uint64: case []uint64:
vals := condNotIn.vals[0].([]uint64) vals := condNotIn.vals[0].([]uint64)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -147,7 +153,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []string: case []string:
vals := condNotIn.vals[0].([]string) vals := condNotIn.vals[0].([]string)
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -159,7 +165,7 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
case []interface{}: case []interface{}:
vals := condNotIn.vals[0].([]interface{}) vals := condNotIn.vals[0].([]interface{})
if len(vals) <= 0 { if len(vals) <= 0 {
return ErrNoNotInConditions return condNotIn.handleBlank(w)
} }
questionMark := strings.Repeat("?,", len(vals)) questionMark := strings.Repeat("?,", len(vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
@ -189,12 +195,29 @@ func (condNotIn condNotIn) WriteTo(w Writer) error {
return err return err
} }
default: default:
v := reflect.ValueOf(condNotIn.vals[0])
if v.Kind() == reflect.Slice {
l := v.Len()
if l == 0 {
return condNotIn.handleBlank(w)
}
questionMark := strings.Repeat("?,", l)
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
return err
}
for i := 0; i < l; i++ {
w.Append(v.Index(i).Interface())
}
} else {
questionMark := strings.Repeat("?,", len(condNotIn.vals)) questionMark := strings.Repeat("?,", len(condNotIn.vals))
if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil { if _, err := fmt.Fprintf(w, "%s NOT IN (%s)", condNotIn.col, questionMark[:len(questionMark)-1]); err != nil {
return err return err
} }
w.Append(condNotIn.vals...) w.Append(condNotIn.vals...)
} }
}
return nil return nil
} }

2
vendor/github.com/go-xorm/core/column.go generated vendored

@ -37,6 +37,7 @@ type Column struct {
SetOptions map[string]int SetOptions map[string]int
DisableTimeZone bool DisableTimeZone bool
TimeZone *time.Location // column specified time zone TimeZone *time.Location // column specified time zone
Comment string
} }
func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column { func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable bool) *Column {
@ -60,6 +61,7 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable
IsVersion: false, IsVersion: false,
DefaultIsEmpty: false, DefaultIsEmpty: false,
EnumOptions: make(map[string]int), EnumOptions: make(map[string]int),
Comment: "",
} }
} }

4
vendor/github.com/go-xorm/core/dialect.go generated vendored

@ -279,9 +279,9 @@ func (b *Base) ForUpdateSql(query string) string {
func (b *Base) LogSQL(sql string, args []interface{}) { func (b *Base) LogSQL(sql string, args []interface{}) {
if b.logger != nil && b.logger.IsShowSQL() { if b.logger != nil && b.logger.IsShowSQL() {
if len(args) > 0 { if len(args) > 0 {
b.logger.Info("[sql]", sql, args) b.logger.Infof("[SQL] %v %v", sql, args)
} else { } else {
b.logger.Info("[sql]", sql) b.logger.Infof("[SQL] %v", sql)
} }
} }
} }

1
vendor/github.com/go-xorm/core/table.go generated vendored

@ -22,6 +22,7 @@ type Table struct {
Cacher Cacher Cacher Cacher
StoreEngine string StoreEngine string
Charset string Charset string
Comment string
} }
func (table *Table) Columns() []*Column { func (table *Table) Columns() []*Column {

3
vendor/github.com/go-xorm/xorm/README.md generated vendored

@ -2,7 +2,8 @@
Xorm is a simple and powerful ORM for Go. Xorm is a simple and powerful ORM for Go.
[![CircleCI](https://circleci.com/gh/go-xorm/xorm/tree/master.svg?style=svg)](https://circleci.com/gh/go-xorm/xorm/tree/master) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-xorm/xorm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![CircleCI](https://circleci.com/gh/go-xorm/xorm.svg?style=shield)](https://circleci.com/gh/go-xorm/xorm) [![codecov](https://codecov.io/gh/go-xorm/xorm/branch/master/graph/badge.svg)](https://codecov.io/gh/go-xorm/xorm)
[![](https://goreportcard.com/badge/github.com/go-xorm/xorm)](https://goreportcard.com/report/github.com/go-xorm/xorm) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-xorm/xorm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
# Notice # Notice

3
vendor/github.com/go-xorm/xorm/README_CN.md generated vendored

@ -4,7 +4,8 @@
xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。 xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。
[![CircleCI](https://circleci.com/gh/go-xorm/xorm/tree/master.svg?style=svg)](https://circleci.com/gh/go-xorm/xorm/tree/master) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-xorm/xorm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![CircleCI](https://circleci.com/gh/go-xorm/xorm.svg?style=shield)](https://circleci.com/gh/go-xorm/xorm) [![codecov](https://codecov.io/gh/go-xorm/xorm/branch/master/graph/badge.svg)](https://codecov.io/gh/go-xorm/xorm)
[![](https://goreportcard.com/badge/github.com/go-xorm/xorm)](https://goreportcard.com/report/github.com/go-xorm/xorm) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-xorm/xorm?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
# 注意 # 注意

0
vendor/github.com/go-xorm/xorm/lru_cacher.go → vendor/github.com/go-xorm/xorm/cache_lru.go generated vendored

0
vendor/github.com/go-xorm/xorm/memory_store.go → vendor/github.com/go-xorm/xorm/cache_memory_store.go generated vendored

6
vendor/github.com/go-xorm/xorm/circle.yml generated vendored

@ -3,6 +3,8 @@ dependencies:
# './...' is a relative pattern which means all subdirectories # './...' is a relative pattern which means all subdirectories
- go get -t -d -v ./... - go get -t -d -v ./...
- go get -t -d -v github.com/go-xorm/tests - go get -t -d -v github.com/go-xorm/tests
- go get -u github.com/go-xorm/core
- go get -u github.com/go-xorm/builder
- go build -v - go build -v
database: database:
@ -19,7 +21,9 @@ database:
test: test:
override: override:
# './...' is a relative pattern which means all subdirectories # './...' is a relative pattern which means all subdirectories
- go test -v -race - go test -v -race -db="sqlite3::mysql::postgres" -conn_str="./test.db::root:@/xorm_test::dbname=xorm_test sslmode=disable" -coverprofile=coverage.txt -covermode=atomic
- cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./sqlite3.sh
- cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./mysql.sh - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./mysql.sh
- cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./postgres.sh - cd /home/ubuntu/.go_workspace/src/github.com/go-xorm/tests && ./postgres.sh
post:
- bash <(curl -s https://codecov.io/bash)

21
vendor/github.com/go-xorm/xorm/dialect_mssql.go generated vendored

@ -215,7 +215,7 @@ 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.Bit
if strings.EqualFold(c.Default, "true") { if strings.EqualFold(c.Default, "true") {
c.Default = "1" c.Default = "1"
} else { } else {
@ -250,6 +250,9 @@ func (db *mssql) SqlType(c *core.Column) string {
case core.Uuid: case core.Uuid:
res = core.Varchar res = core.Varchar
c.Length = 40 c.Length = 40
case core.TinyInt:
res = core.TinyInt
c.Length = 0
default: default:
res = t res = t
} }
@ -335,9 +338,15 @@ func (db *mssql) TableCheckSql(tableName string) (string, []interface{}) {
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 ISNULL(i.is_primary_key, 0)
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
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = a.object_id AND ic.column_id = a.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
where a.object_id=object_id('` + tableName + `')` where a.object_id=object_id('` + tableName + `')`
db.LogSQL(s, args) db.LogSQL(s, args)
@ -352,8 +361,8 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
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, isPK bool
err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &vdefault) err = rows.Scan(&name, &ctype, &maxLen, &precision, &scale, &nullable, &vdefault, &isPK)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -363,6 +372,7 @@ func (db *mssql) GetColumns(tableName string) ([]string, map[string]*core.Column
col.Name = strings.Trim(name, "` ") col.Name = strings.Trim(name, "` ")
col.Nullable = nullable col.Nullable = nullable
col.Default = vdefault col.Default = vdefault
col.IsPrimaryKey = isPK
ct := strings.ToUpper(ctype) ct := strings.ToUpper(ctype)
if ct == "DECIMAL" { if ct == "DECIMAL" {
col.Length = precision col.Length = precision
@ -536,7 +546,6 @@ type odbcDriver struct {
func (p *odbcDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) { func (p *odbcDriver) Parse(driverName, dataSourceName string) (*core.Uri, error) {
kv := strings.Split(dataSourceName, ";") kv := strings.Split(dataSourceName, ";")
var dbName string var dbName string
for _, c := range kv { for _, c := range kv {
vv := strings.Split(strings.TrimSpace(c), "=") vv := strings.Split(strings.TrimSpace(c), "=")
if len(vv) == 2 { if len(vv) == 2 {

14
vendor/github.com/go-xorm/xorm/dialect_mysql.go generated vendored

@ -299,7 +299,7 @@ func (db *mysql) TableCheckSql(tableName string) (string, []interface{}) {
func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) { func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column, error) {
args := []interface{}{db.DbName, tableName} args := []interface{}{db.DbName, tableName}
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," + s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
" `COLUMN_KEY`, `EXTRA` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" " `COLUMN_KEY`, `EXTRA`,`COLUMN_COMMENT` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?"
db.LogSQL(s, args) db.LogSQL(s, args)
rows, err := db.DB().Query(s, args...) rows, err := db.DB().Query(s, args...)
@ -314,13 +314,14 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
col := new(core.Column) col := new(core.Column)
col.Indexes = make(map[string]int) col.Indexes = make(map[string]int)
var columnName, isNullable, colType, colKey, extra string var columnName, isNullable, colType, colKey, extra, comment string
var colDefault *string var colDefault *string
err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra) err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
col.Name = strings.Trim(columnName, "` ") col.Name = strings.Trim(columnName, "` ")
col.Comment = comment
if "YES" == isNullable { if "YES" == isNullable {
col.Nullable = true col.Nullable = true
} }
@ -407,7 +408,7 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column
func (db *mysql) GetTables() ([]*core.Table, error) { func (db *mysql) GetTables() ([]*core.Table, error) {
args := []interface{}{db.DbName} args := []interface{}{db.DbName}
s := "SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT` from " + s := "SELECT `TABLE_NAME`, `ENGINE`, `TABLE_ROWS`, `AUTO_INCREMENT`, `TABLE_COMMENT` from " +
"`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')" "`INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_SCHEMA`=? AND (`ENGINE`='MyISAM' OR `ENGINE` = 'InnoDB' OR `ENGINE` = 'TokuDB')"
db.LogSQL(s, args) db.LogSQL(s, args)
@ -420,14 +421,15 @@ func (db *mysql) GetTables() ([]*core.Table, error) {
tables := make([]*core.Table, 0) tables := make([]*core.Table, 0)
for rows.Next() { for rows.Next() {
table := core.NewEmptyTable() table := core.NewEmptyTable()
var name, engine, tableRows string var name, engine, tableRows, comment string
var autoIncr *string var autoIncr *string
err = rows.Scan(&name, &engine, &tableRows, &autoIncr) err = rows.Scan(&name, &engine, &tableRows, &autoIncr, &comment)
if err != nil { if err != nil {
return nil, err return nil, err
} }
table.Name = name table.Name = name
table.Comment = comment
table.StoreEngine = engine table.StoreEngine = engine
tables = append(tables, table) tables = append(tables, table)
} }

18
vendor/github.com/go-xorm/xorm/dialect_sqlite3.go generated vendored

@ -14,10 +14,6 @@ import (
"github.com/go-xorm/core" "github.com/go-xorm/core"
) )
// func init() {
// RegisterDialect("sqlite3", &sqlite3{})
// }
var ( var (
sqlite3ReservedWords = map[string]bool{ sqlite3ReservedWords = map[string]bool{
"ABORT": true, "ABORT": true,
@ -310,11 +306,25 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu
for _, colStr := range colCreates { for _, colStr := range colCreates {
reg = regexp.MustCompile(`,\s`) reg = regexp.MustCompile(`,\s`)
colStr = reg.ReplaceAllString(colStr, ",") 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
}
fields := strings.Fields(strings.TrimSpace(colStr)) fields := strings.Fields(strings.TrimSpace(colStr))
col := new(core.Column) col := new(core.Column)
col.Indexes = make(map[string]int) col.Indexes = make(map[string]int)
col.Nullable = true col.Nullable = true
col.DefaultIsEmpty = true col.DefaultIsEmpty = true
for idx, field := range fields { for idx, field := range fields {
if idx == 0 { if idx == 0 {
col.Name = strings.Trim(strings.Trim(field, "`[] "), `"`) col.Name = strings.Trim(strings.Trim(field, "`[] "), `"`)

11
vendor/github.com/go-xorm/xorm/doc.go generated vendored

@ -8,7 +8,7 @@ Package xorm is a simple and powerful ORM for Go.
Installation Installation
Make sure you have installed Go 1.1+ and then: Make sure you have installed Go 1.5+ and then:
go get github.com/go-xorm/xorm go get github.com/go-xorm/xorm
@ -51,11 +51,15 @@ There are 8 major ORM methods and many helpful methods to use to operate databas
// INSERT INTO struct1 () values () // INSERT INTO struct1 () values ()
// INSERT INTO struct2 () values (),(),() // INSERT INTO struct2 () values (),(),()
2. Query one record from database 2. Query one record or one variable from database
has, err := engine.Get(&user) has, err := engine.Get(&user)
// SELECT * FROM user LIMIT 1 // SELECT * FROM user LIMIT 1
var id int64
has, err := engine.Table("user").Where("name = ?", name).Get(&id)
// SELECT id FROM user WHERE name = ? LIMIT 1
3. Query multiple records from database 3. Query multiple records from database
var sliceOfStructs []Struct var sliceOfStructs []Struct
@ -99,6 +103,9 @@ another is Rows
counts, err := engine.Count(&user) counts, err := engine.Count(&user)
// SELECT count(*) AS total FROM user // SELECT count(*) AS total FROM user
counts, err := engine.SQL("select count(*) FROM user").Count()
// select count(*) FROM user
8. Sum records 8. Sum records
sumFloat64, err := engine.Sum(&user, "id") sumFloat64, err := engine.Sum(&user, "id")

100
vendor/github.com/go-xorm/xorm/engine.go generated vendored

@ -40,7 +40,7 @@ type Engine struct {
showExecTime bool showExecTime bool
logger core.ILogger logger core.ILogger
TZLocation *time.Location TZLocation *time.Location // The timezone of the application
DatabaseTZ *time.Location // The timezone of the database DatabaseTZ *time.Location // The timezone of the database
disableGlobalCache bool disableGlobalCache bool
@ -143,7 +143,6 @@ func (engine *Engine) Quote(value string) string {
// QuoteTo quotes string and writes into the buffer // QuoteTo quotes string and writes into the buffer
func (engine *Engine) QuoteTo(buf *bytes.Buffer, value string) { func (engine *Engine) QuoteTo(buf *bytes.Buffer, value string) {
if buf == nil { if buf == nil {
return return
} }
@ -196,6 +195,11 @@ func (engine *Engine) SetMaxIdleConns(conns int) {
engine.db.SetMaxIdleConns(conns) engine.db.SetMaxIdleConns(conns)
} }
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
func (engine *Engine) SetConnMaxLifetime(d time.Duration) {
engine.db.SetConnMaxLifetime(d)
}
// SetDefaultCacher set the default cacher. Xorm's default not enable cacher. // SetDefaultCacher set the default cacher. Xorm's default not enable cacher.
func (engine *Engine) SetDefaultCacher(cacher core.Cacher) { func (engine *Engine) SetDefaultCacher(cacher core.Cacher) {
engine.Cacher = cacher engine.Cacher = cacher
@ -781,6 +785,12 @@ func (engine *Engine) Having(conditions string) *Session {
return session.Having(conditions) return session.Having(conditions)
} }
func (engine *Engine) unMapType(t reflect.Type) {
engine.mutex.Lock()
defer engine.mutex.Unlock()
delete(engine.Tables, t)
}
func (engine *Engine) autoMapType(v reflect.Value) (*core.Table, error) { func (engine *Engine) autoMapType(v reflect.Value) (*core.Table, error) {
t := v.Type() t := v.Type()
engine.mutex.Lock() engine.mutex.Lock()
@ -1007,6 +1017,10 @@ func (engine *Engine) mapType(v reflect.Value) (*core.Table, error) {
col = core.NewColumn(engine.ColumnMapper.Obj2Table(t.Field(i).Name), col = core.NewColumn(engine.ColumnMapper.Obj2Table(t.Field(i).Name),
t.Field(i).Name, sqlType, sqlType.DefaultLength, t.Field(i).Name, sqlType, sqlType.DefaultLength,
sqlType.DefaultLength2, true) sqlType.DefaultLength2, true)
if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) {
idFieldColName = col.Name
}
} }
if col.IsAutoIncrement { if col.IsAutoIncrement {
col.Nullable = false col.Nullable = false
@ -1014,9 +1028,6 @@ func (engine *Engine) mapType(v reflect.Value) (*core.Table, error) {
table.AddColumn(col) table.AddColumn(col)
if fieldType.Kind() == reflect.Int64 && (strings.ToUpper(col.FieldName) == "ID" || strings.HasSuffix(strings.ToUpper(col.FieldName), ".ID")) {
idFieldColName = col.Name
}
} // end for } // end for
if idFieldColName != "" && len(table.PrimaryKeys) == 0 { if idFieldColName != "" && len(table.PrimaryKeys) == 0 {
@ -1241,7 +1252,6 @@ func (engine *Engine) Sync(beans ...interface{}) error {
return err return err
} }
if index.Type == core.UniqueType { if index.Type == core.UniqueType {
//isExist, err := session.isIndexExist(table.Name, name, true)
isExist, err := session.isIndexExist2(tableName, index.Cols, true) isExist, err := session.isIndexExist2(tableName, index.Cols, true)
if err != nil { if err != nil {
return err return err
@ -1291,23 +1301,6 @@ func (engine *Engine) Sync2(beans ...interface{}) error {
return s.Sync2(beans...) return s.Sync2(beans...)
} }
// Drop all mapped table
func (engine *Engine) dropAll() error {
session := engine.NewSession()
defer session.Close()
err := session.Begin()
if err != nil {
return err
}
err = session.dropAll()
if err != nil {
session.Rollback()
return err
}
return session.Commit()
}
// CreateTables create tabls according bean // CreateTables create tabls according bean
func (engine *Engine) CreateTables(beans ...interface{}) error { func (engine *Engine) CreateTables(beans ...interface{}) error {
session := engine.NewSession() session := engine.NewSession()
@ -1348,10 +1341,11 @@ func (engine *Engine) DropTables(beans ...interface{}) error {
return session.Commit() return session.Commit()
} }
func (engine *Engine) createAll() error { // DropIndexes drop indexes of a table
func (engine *Engine) DropIndexes(bean interface{}) error {
session := engine.NewSession() session := engine.NewSession()
defer session.Close() defer session.Close()
return session.createAll() return session.DropIndexes(bean)
} }
// Exec raw sql // Exec raw sql
@ -1509,7 +1503,6 @@ func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
results = append(results, result) results = append(results, result)
if err != nil { if err != nil {
return nil, err return nil, err
//lastError = err
} }
} }
} }
@ -1517,49 +1510,28 @@ func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
return results, lastError return results, lastError
} }
// TZTime change one time to xorm time location
func (engine *Engine) TZTime(t time.Time) time.Time {
if !t.IsZero() { // if time is not initialized it's not suitable for Time.In()
return t.In(engine.TZLocation)
}
return t
}
// NowTime return current time
func (engine *Engine) NowTime(sqlTypeName string) interface{} {
t := time.Now()
return engine.FormatTime(sqlTypeName, t)
}
// NowTime2 return current time // NowTime2 return current time
func (engine *Engine) NowTime2(sqlTypeName string) (interface{}, time.Time) { func (engine *Engine) NowTime2(sqlTypeName string) (interface{}, time.Time) {
t := time.Now() t := time.Now()
return engine.FormatTime(sqlTypeName, t), t return engine.formatTime(sqlTypeName, t.In(engine.DatabaseTZ)), t.In(engine.TZLocation)
}
// FormatTime format time
func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{}) {
return engine.formatTime(engine.TZLocation, sqlTypeName, t)
} }
func (engine *Engine) formatColTime(col *core.Column, t time.Time) (v interface{}) { func (engine *Engine) formatColTime(col *core.Column, t time.Time) (v interface{}) {
if col.DisableTimeZone { if t.IsZero() {
return engine.formatTime(nil, col.SQLType.Name, t) if col.Nullable {
} else if col.TimeZone != nil { return nil
return engine.formatTime(col.TimeZone, col.SQLType.Name, t)
} }
return engine.formatTime(engine.TZLocation, col.SQLType.Name, t) return ""
}
func (engine *Engine) formatTime(tz *time.Location, sqlTypeName string, t time.Time) (v interface{}) {
if engine.dialect.DBType() == core.ORACLE {
return t
} }
if tz != nil {
t = t.In(tz) if col.TimeZone != nil {
} else { return engine.formatTime(col.SQLType.Name, t.In(col.TimeZone))
t = engine.TZTime(t)
} }
return engine.formatTime(col.SQLType.Name, t.In(engine.DatabaseTZ))
}
// formatTime format time as column type
func (engine *Engine) formatTime(sqlTypeName string, t time.Time) (v interface{}) {
switch sqlTypeName { switch sqlTypeName {
case core.Time: case core.Time:
s := t.Format("2006-01-02 15:04:05") //time.RFC3339 s := t.Format("2006-01-02 15:04:05") //time.RFC3339
@ -1567,18 +1539,10 @@ func (engine *Engine) formatTime(tz *time.Location, sqlTypeName string, t time.T
case core.Date: case core.Date:
v = t.Format("2006-01-02") v = t.Format("2006-01-02")
case core.DateTime, core.TimeStamp: case core.DateTime, core.TimeStamp:
if engine.dialect.DBType() == "ql" {
v = t
} else if engine.dialect.DBType() == "sqlite3" {
v = t.UTC().Format("2006-01-02 15:04:05")
} else {
v = t.Format("2006-01-02 15:04:05") v = t.Format("2006-01-02 15:04:05")
}
case core.TimeStampz: case core.TimeStampz:
if engine.dialect.DBType() == core.MSSQL { if engine.dialect.DBType() == core.MSSQL {
v = t.Format("2006-01-02T15:04:05.9999999Z07:00") v = t.Format("2006-01-02T15:04:05.9999999Z07:00")
} else if engine.DriverName() == "mssql" {
v = t
} else { } else {
v = t.Format(time.RFC3339Nano) v = t.Format(time.RFC3339Nano)
} }

209
vendor/github.com/go-xorm/xorm/helpers.go generated vendored

@ -196,25 +196,43 @@ func isArrayValueZero(v reflect.Value) bool {
func int64ToIntValue(id int64, tp reflect.Type) reflect.Value { func int64ToIntValue(id int64, tp reflect.Type) reflect.Value {
var v interface{} var v interface{}
switch tp.Kind() { kind := tp.Kind()
if kind == reflect.Ptr {
kind = tp.Elem().Kind()
}
switch kind {
case reflect.Int16: case reflect.Int16:
v = int16(id) temp := int16(id)
v = &temp
case reflect.Int32: case reflect.Int32:
v = int32(id) temp := int32(id)
v = &temp
case reflect.Int: case reflect.Int:
v = int(id) temp := int(id)
v = &temp
case reflect.Int64: case reflect.Int64:
v = id temp := id
v = &temp
case reflect.Uint16: case reflect.Uint16:
v = uint16(id) temp := uint16(id)
v = &temp
case reflect.Uint32: case reflect.Uint32:
v = uint32(id) temp := uint32(id)
v = &temp
case reflect.Uint64: case reflect.Uint64:
v = uint64(id) temp := uint64(id)
v = &temp
case reflect.Uint: case reflect.Uint:
v = uint(id) temp := uint(id)
v = &temp
} }
if tp.Kind() == reflect.Ptr {
return reflect.ValueOf(v).Convert(tp) return reflect.ValueOf(v).Convert(tp)
}
return reflect.ValueOf(v).Elem().Convert(tp)
} }
func int64ToInt(id int64, tp reflect.Type) interface{} { func int64ToInt(id int64, tp reflect.Type) interface{} {
@ -302,175 +320,6 @@ func sliceEq(left, right []string) bool {
return true return true
} }
func reflect2value(rawValue *reflect.Value) (str string, err error) {
aa := reflect.TypeOf((*rawValue).Interface())
vv := reflect.ValueOf((*rawValue).Interface())
switch aa.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
str = strconv.FormatInt(vv.Int(), 10)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
str = strconv.FormatUint(vv.Uint(), 10)
case reflect.Float32, reflect.Float64:
str = strconv.FormatFloat(vv.Float(), 'f', -1, 64)
case reflect.String:
str = vv.String()
case reflect.Array, reflect.Slice:
switch aa.Elem().Kind() {
case reflect.Uint8:
data := rawValue.Interface().([]byte)
str = string(data)
default:
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
// time type
case reflect.Struct:
if aa.ConvertibleTo(core.TimeType) {
str = vv.Convert(core.TimeType).Interface().(time.Time).Format(time.RFC3339Nano)
} else {
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
case reflect.Bool:
str = strconv.FormatBool(vv.Bool())
case reflect.Complex128, reflect.Complex64:
str = fmt.Sprintf("%v", vv.Complex())
/* TODO: unsupported types below
case reflect.Map:
case reflect.Ptr:
case reflect.Uintptr:
case reflect.UnsafePointer:
case reflect.Chan, reflect.Func, reflect.Interface:
*/
default:
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
return
}
func value2Bytes(rawValue *reflect.Value) (data []byte, err error) {
var str string
str, err = reflect2value(rawValue)
if err != nil {
return
}
data = []byte(str)
return
}
func value2String(rawValue *reflect.Value) (data string, err error) {
data, err = reflect2value(rawValue)
if err != nil {
return
}
return
}
func rows2Strings(rows *core.Rows) (resultsSlice []map[string]string, err error) {
fields, err := rows.Columns()
if err != nil {
return nil, err
}
for rows.Next() {
result, err := row2mapStr(rows, fields)
if err != nil {
return nil, err
}
resultsSlice = append(resultsSlice, result)
}
return resultsSlice, nil
}
func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
fields, err := rows.Columns()
if err != nil {
return nil, err
}
for rows.Next() {
result, err := row2map(rows, fields)
if err != nil {
return nil, err
}
resultsSlice = append(resultsSlice, result)
}
return resultsSlice, nil
}
func row2map(rows *core.Rows, fields []string) (resultsMap map[string][]byte, err error) {
result := make(map[string][]byte)
scanResultContainers := make([]interface{}, len(fields))
for i := 0; i < len(fields); i++ {
var scanResultContainer interface{}
scanResultContainers[i] = &scanResultContainer
}
if err := rows.Scan(scanResultContainers...); err != nil {
return nil, err
}
for ii, key := range fields {
rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
//if row is null then ignore
if rawValue.Interface() == nil {
//fmt.Println("ignore ...", key, rawValue)
continue
}
if data, err := value2Bytes(&rawValue); err == nil {
result[key] = data
} else {
return nil, err // !nashtsai! REVIEW, should return err or just error log?
}
}
return result, nil
}
func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string, err error) {
result := make(map[string]string)
scanResultContainers := make([]interface{}, len(fields))
for i := 0; i < len(fields); i++ {
var scanResultContainer interface{}
scanResultContainers[i] = &scanResultContainer
}
if err := rows.Scan(scanResultContainers...); err != nil {
return nil, err
}
for ii, key := range fields {
rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
//if row is null then ignore
if rawValue.Interface() == nil {
//fmt.Println("ignore ...", key, rawValue)
continue
}
if data, err := value2String(&rawValue); err == nil {
result[key] = data
} else {
return nil, err // !nashtsai! REVIEW, should return err or just error log?
}
}
return result, nil
}
func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string]string, error) {
rows, err := tx.Query(sqlStr, params...)
if err != nil {
return nil, err
}
defer rows.Close()
return rows2Strings(rows)
}
func query2(db *core.DB, sqlStr string, params ...interface{}) ([]map[string]string, error) {
rows, err := db.Query(sqlStr, params...)
if err != nil {
return nil, err
}
defer rows.Close()
return rows2Strings(rows)
}
func setColumnInt(bean interface{}, col *core.Column, t int64) { func setColumnInt(bean interface{}, col *core.Column, t int64) {
v, err := col.ValueOf(bean) v, err := col.ValueOf(bean)
if err != nil { if err != nil {
@ -537,6 +386,10 @@ func genCols(table *core.Table, session *Session, bean interface{}, useCol bool,
if len(fieldValue.String()) == 0 { if len(fieldValue.String()) == 0 {
continue continue
} }
case reflect.Ptr:
if fieldValue.Pointer() == 0 {
continue
}
} }
} }

21
vendor/github.com/go-xorm/xorm/helpler_time.go generated vendored

@ -0,0 +1,21 @@
// Copyright 2017 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 xorm
import "time"
const (
zeroTime0 = "0000-00-00 00:00:00"
zeroTime1 = "0001-01-01 00:00:00"
)
func formatTime(t time.Time) string {
return t.Format("2006-01-02 15:04:05")
}
func isTimeZero(t time.Time) bool {
return t.IsZero() || formatTime(t) == zeroTime0 ||
formatTime(t) == zeroTime1
}

22
vendor/github.com/go-xorm/xorm/session.go generated vendored

@ -344,15 +344,6 @@ func (session *Session) row2Bean(rows *core.Rows, fields []string, fieldsCount i
} }
}() }()
dbTZ := session.Engine.DatabaseTZ
if dbTZ == nil {
if session.Engine.dialect.DBType() == core.SQLITE {
dbTZ = time.UTC
} else {
dbTZ = time.Local
}
}
var tempMap = make(map[string]int) var tempMap = make(map[string]int)
var pk core.PK var pk core.PK
for ii, key := range fields { for ii, key := range fields {
@ -528,11 +519,9 @@ func (session *Session) row2Bean(rows *core.Rows, fields []string, fieldsCount i
} }
case reflect.Struct: case reflect.Struct:
if fieldType.ConvertibleTo(core.TimeType) { if fieldType.ConvertibleTo(core.TimeType) {
var tz *time.Location dbTZ := session.Engine.DatabaseTZ
if col.TimeZone == nil { if col.TimeZone != nil {
tz = session.Engine.TZLocation dbTZ = col.TimeZone
} else {
tz = col.TimeZone
} }
if rawValueType == core.TimeType { if rawValueType == core.TimeType {
@ -548,14 +537,13 @@ func (session *Session) row2Bean(rows *core.Rows, fields []string, fieldsCount i
t.Minute(), t.Second(), t.Nanosecond(), dbTZ) t.Minute(), t.Second(), t.Nanosecond(), dbTZ)
} }
// !nashtsai! convert to engine location t = t.In(session.Engine.TZLocation)
t = t.In(tz)
fieldValue.Set(reflect.ValueOf(t).Convert(fieldType)) fieldValue.Set(reflect.ValueOf(t).Convert(fieldType))
} else if rawValueType == core.IntType || rawValueType == core.Int64Type || } else if rawValueType == core.IntType || rawValueType == core.Int64Type ||
rawValueType == core.Int32Type { rawValueType == core.Int32Type {
hasAssigned = true hasAssigned = true
t := time.Unix(vv.Int(), 0).In(tz) t := time.Unix(vv.Int(), 0).In(session.Engine.TZLocation)
fieldValue.Set(reflect.ValueOf(t).Convert(fieldType)) fieldValue.Set(reflect.ValueOf(t).Convert(fieldType))
} else { } else {
if d, ok := vv.Interface().([]uint8); ok { if d, ok := vv.Interface().([]uint8); ok {

33
vendor/github.com/go-xorm/xorm/session_convert.go generated vendored

@ -23,6 +23,11 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
var x time.Time var x time.Time
var err error var err error
var parseLoc = session.Engine.DatabaseTZ
if col.TimeZone != nil {
parseLoc = col.TimeZone
}
if sdata == "0000-00-00 00:00:00" || if sdata == "0000-00-00 00:00:00" ||
sdata == "0001-01-01 00:00:00" { sdata == "0001-01-01 00:00:00" {
} else if !strings.ContainsAny(sdata, "- :") { // !nashtsai! has only found that mymysql driver is using this for time type column } else if !strings.ContainsAny(sdata, "- :") { // !nashtsai! has only found that mymysql driver is using this for time type column
@ -30,33 +35,26 @@ 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 causing Local location being change to CHAT and cause wrong time conversion
if col.TimeZone == nil {
x = x.In(session.Engine.TZLocation)
} else {
x = x.In(col.TimeZone)
}
session.Engine.logger.Debugf("time(0) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(0) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} else { } else {
session.Engine.logger.Debugf("time(0) err key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(0) err key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} }
} else if len(sdata) > 19 && strings.Contains(sdata, "-") { } else if len(sdata) > 19 && strings.Contains(sdata, "-") {
x, err = time.ParseInLocation(time.RFC3339Nano, sdata, session.Engine.TZLocation) x, err = time.ParseInLocation(time.RFC3339Nano, sdata, parseLoc)
session.Engine.logger.Debugf("time(1) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(1) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
if err != nil { if err != nil {
x, err = time.ParseInLocation("2006-01-02 15:04:05.999999999", sdata, session.Engine.TZLocation) x, err = time.ParseInLocation("2006-01-02 15:04:05.999999999", sdata, parseLoc)
session.Engine.logger.Debugf("time(2) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(2) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} }
if err != nil { if err != nil {
x, err = time.ParseInLocation("2006-01-02 15:04:05.9999999 Z07:00", sdata, session.Engine.TZLocation) x, err = time.ParseInLocation("2006-01-02 15:04:05.9999999 Z07:00", sdata, parseLoc)
session.Engine.logger.Debugf("time(3) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(3) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} }
} else if len(sdata) == 19 && strings.Contains(sdata, "-") { } else if len(sdata) == 19 && strings.Contains(sdata, "-") {
x, err = time.ParseInLocation("2006-01-02 15:04:05", sdata, session.Engine.TZLocation) x, err = time.ParseInLocation("2006-01-02 15:04:05", sdata, parseLoc)
session.Engine.logger.Debugf("time(4) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(4) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} else if len(sdata) == 10 && sdata[4] == '-' && sdata[7] == '-' { } else if len(sdata) == 10 && sdata[4] == '-' && sdata[7] == '-' {
x, err = time.ParseInLocation("2006-01-02", sdata, session.Engine.TZLocation) x, err = time.ParseInLocation("2006-01-02", sdata, parseLoc)
session.Engine.logger.Debugf("time(5) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(5) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} else if col.SQLType.Name == core.Time { } else if col.SQLType.Name == core.Time {
if strings.Contains(sdata, " ") { if strings.Contains(sdata, " ") {
@ -70,7 +68,7 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
} }
st := fmt.Sprintf("2006-01-02 %v", sdata) st := fmt.Sprintf("2006-01-02 %v", sdata)
x, err = time.ParseInLocation("2006-01-02 15:04:05", st, session.Engine.TZLocation) x, err = time.ParseInLocation("2006-01-02 15:04:05", st, parseLoc)
session.Engine.logger.Debugf("time(6) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata) session.Engine.logger.Debugf("time(6) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
} else { } else {
outErr = fmt.Errorf("unsupported time format %v", sdata) outErr = fmt.Errorf("unsupported time format %v", sdata)
@ -80,7 +78,7 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
outErr = fmt.Errorf("unsupported time format %v: %v", sdata, err) outErr = fmt.Errorf("unsupported time format %v: %v", sdata, err)
return return
} }
outTime = x outTime = x.In(session.Engine.TZLocation)
return return
} }
@ -588,12 +586,7 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
case reflect.Struct: case reflect.Struct:
if fieldType.ConvertibleTo(core.TimeType) { if fieldType.ConvertibleTo(core.TimeType) {
t := fieldValue.Convert(core.TimeType).Interface().(time.Time) t := fieldValue.Convert(core.TimeType).Interface().(time.Time)
if session.Engine.dialect.DBType() == core.MSSQL { tf := session.Engine.formatColTime(col, t)
if t.IsZero() {
return nil, nil
}
}
tf := session.Engine.FormatTime(col.SQLType.Name, t)
return tf, nil return tf, nil
} }

5
vendor/github.com/go-xorm/xorm/session_find.go generated vendored

@ -122,7 +122,10 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
} }
} }
condSQL, condArgs, _ := builder.ToSQL(session.Statement.cond.And(autoCond)) condSQL, condArgs, err := builder.ToSQL(session.Statement.cond.And(autoCond))
if err != nil {
return err
}
args = append(session.Statement.joinArgs, condArgs...) args = append(session.Statement.joinArgs, condArgs...)
sqlStr = session.Statement.genSelectSQL(columnStr, condSQL) sqlStr = session.Statement.genSelectSQL(columnStr, condSQL)

16
vendor/github.com/go-xorm/xorm/session_insert.go generated vendored

@ -67,7 +67,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
return 0, errors.New("could not insert a empty slice") return 0, errors.New("could not insert a empty slice")
} }
if err := session.Statement.setRefValue(sliceValue.Index(0)); err != nil { if err := session.Statement.setRefValue(reflect.ValueOf(sliceValue.Index(0).Interface())); err != nil {
return 0, err return 0, err
} }
@ -343,15 +343,26 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
if len(exprColVals) > 0 { if len(exprColVals) > 0 {
colPlaces = colPlaces + strings.Join(exprColVals, ", ") colPlaces = colPlaces + strings.Join(exprColVals, ", ")
} else { } else {
if len(colPlaces) > 0 {
colPlaces = colPlaces[0 : len(colPlaces)-2] colPlaces = colPlaces[0 : len(colPlaces)-2]
} }
}
sqlStr := fmt.Sprintf("INSERT INTO %s (%v%v%v) VALUES (%v)", var sqlStr string
if len(colPlaces) > 0 {
sqlStr = fmt.Sprintf("INSERT INTO %s (%v%v%v) VALUES (%v)",
session.Engine.Quote(session.Statement.TableName()), session.Engine.Quote(session.Statement.TableName()),
session.Engine.QuoteStr(), session.Engine.QuoteStr(),
strings.Join(colNames, session.Engine.Quote(", ")), strings.Join(colNames, session.Engine.Quote(", ")),
session.Engine.QuoteStr(), session.Engine.QuoteStr(),
colPlaces) colPlaces)
} else {
if session.Engine.dialect.DBType() == core.MYSQL {
sqlStr = fmt.Sprintf("INSERT INTO %s VALUES ()", session.Engine.Quote(session.Statement.TableName()))
} else {
sqlStr = fmt.Sprintf("INSERT INTO %s DEFAULT VALUES", session.Engine.Quote(session.Statement.TableName()))
}
}
handleAfterInsertProcessorFunc := func(bean interface{}) { handleAfterInsertProcessorFunc := func(bean interface{}) {
if session.IsAutoCommit { if session.IsAutoCommit {
@ -384,7 +395,6 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
// for postgres, many of them didn't implement lastInsertId, so we should // for postgres, many of them didn't implement lastInsertId, so we should
// implemented it ourself. // implemented it ourself.
if session.Engine.dialect.DBType() == core.ORACLE && len(table.AutoIncrement) > 0 { if session.Engine.dialect.DBType() == core.ORACLE && len(table.AutoIncrement) > 0 {
//assert table.AutoIncrement != ""
res, err := session.query("select seq_atable.currval from dual", args...) res, err := session.query("select seq_atable.currval from dual", args...)
if err != nil { if err != nil {
return 0, err return 0, err

173
vendor/github.com/go-xorm/xorm/session_raw.go generated vendored

@ -6,6 +6,10 @@ package xorm
import ( import (
"database/sql" "database/sql"
"fmt"
"reflect"
"strconv"
"time"
"github.com/go-xorm/core" "github.com/go-xorm/core"
) )
@ -59,6 +63,60 @@ func (session *Session) innerQuery(sqlStr string, params ...interface{}) (*core.
return stmt, rows, nil return stmt, rows, nil
} }
func rows2maps(rows *core.Rows) (resultsSlice []map[string][]byte, err error) {
fields, err := rows.Columns()
if err != nil {
return nil, err
}
for rows.Next() {
result, err := row2map(rows, fields)
if err != nil {
return nil, err
}
resultsSlice = append(resultsSlice, result)
}
return resultsSlice, nil
}
func value2Bytes(rawValue *reflect.Value) (data []byte, err error) {
var str string
str, err = reflect2value(rawValue)
if err != nil {
return
}
data = []byte(str)
return
}
func row2map(rows *core.Rows, fields []string) (resultsMap map[string][]byte, err error) {
result := make(map[string][]byte)
scanResultContainers := make([]interface{}, len(fields))
for i := 0; i < len(fields); i++ {
var scanResultContainer interface{}
scanResultContainers[i] = &scanResultContainer
}
if err := rows.Scan(scanResultContainers...); err != nil {
return nil, err
}
for ii, key := range fields {
rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
//if row is null then ignore
if rawValue.Interface() == nil {
//fmt.Println("ignore ...", key, rawValue)
continue
}
if data, err := value2Bytes(&rawValue); err == nil {
result[key] = data
} else {
return nil, err // !nashtsai! REVIEW, should return err or just error log?
}
}
return result, nil
}
func (session *Session) innerQuery2(sqlStr string, params ...interface{}) ([]map[string][]byte, error) { func (session *Session) innerQuery2(sqlStr string, params ...interface{}) ([]map[string][]byte, error) {
_, rows, err := session.innerQuery(sqlStr, params...) _, rows, err := session.innerQuery(sqlStr, params...)
if rows != nil { if rows != nil {
@ -80,6 +138,121 @@ func (session *Session) Query(sqlStr string, paramStr ...interface{}) ([]map[str
return session.query(sqlStr, paramStr...) return session.query(sqlStr, paramStr...)
} }
func rows2Strings(rows *core.Rows) (resultsSlice []map[string]string, err error) {
fields, err := rows.Columns()
if err != nil {
return nil, err
}
for rows.Next() {
result, err := row2mapStr(rows, fields)
if err != nil {
return nil, err
}
resultsSlice = append(resultsSlice, result)
}
return resultsSlice, nil
}
func reflect2value(rawValue *reflect.Value) (str string, err error) {
aa := reflect.TypeOf((*rawValue).Interface())
vv := reflect.ValueOf((*rawValue).Interface())
switch aa.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
str = strconv.FormatInt(vv.Int(), 10)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
str = strconv.FormatUint(vv.Uint(), 10)
case reflect.Float32, reflect.Float64:
str = strconv.FormatFloat(vv.Float(), 'f', -1, 64)
case reflect.String:
str = vv.String()
case reflect.Array, reflect.Slice:
switch aa.Elem().Kind() {
case reflect.Uint8:
data := rawValue.Interface().([]byte)
str = string(data)
default:
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
// time type
case reflect.Struct:
if aa.ConvertibleTo(core.TimeType) {
str = vv.Convert(core.TimeType).Interface().(time.Time).Format(time.RFC3339Nano)
} else {
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
case reflect.Bool:
str = strconv.FormatBool(vv.Bool())
case reflect.Complex128, reflect.Complex64:
str = fmt.Sprintf("%v", vv.Complex())
/* TODO: unsupported types below
case reflect.Map:
case reflect.Ptr:
case reflect.Uintptr:
case reflect.UnsafePointer:
case reflect.Chan, reflect.Func, reflect.Interface:
*/
default:
err = fmt.Errorf("Unsupported struct type %v", vv.Type().Name())
}
return
}
func value2String(rawValue *reflect.Value) (data string, err error) {
data, err = reflect2value(rawValue)
if err != nil {
return
}
return
}
func row2mapStr(rows *core.Rows, fields []string) (resultsMap map[string]string, err error) {
result := make(map[string]string)
scanResultContainers := make([]interface{}, len(fields))
for i := 0; i < len(fields); i++ {
var scanResultContainer interface{}
scanResultContainers[i] = &scanResultContainer
}
if err := rows.Scan(scanResultContainers...); err != nil {
return nil, err
}
for ii, key := range fields {
rawValue := reflect.Indirect(reflect.ValueOf(scanResultContainers[ii]))
//if row is null then ignore
if rawValue.Interface() == nil {
//fmt.Println("ignore ...", key, rawValue)
continue
}
if data, err := value2String(&rawValue); err == nil {
result[key] = data
} else {
return nil, err // !nashtsai! REVIEW, should return err or just error log?
}
}
return result, nil
}
func txQuery2(tx *core.Tx, sqlStr string, params ...interface{}) ([]map[string]string, error) {
rows, err := tx.Query(sqlStr, params...)
if err != nil {
return nil, err
}
defer rows.Close()
return rows2Strings(rows)
}
func query2(db *core.DB, sqlStr string, params ...interface{}) ([]map[string]string, error) {
rows, err := db.Query(sqlStr, params...)
if err != nil {
return nil, err
}
defer rows.Close()
return rows2Strings(rows)
}
// QueryString runs a raw sql and return records as []map[string]string // QueryString runs a raw sql and return records as []map[string]string
func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[string]string, error) { func (session *Session) QueryString(sqlStr string, args ...interface{}) ([]map[string]string, error) {
defer session.resetStatement() defer session.resetStatement()

53
vendor/github.com/go-xorm/xorm/session_schema.go generated vendored

@ -89,24 +89,6 @@ func (session *Session) createOneTable() error {
return err return err
} }
// to be deleted
func (session *Session) createAll() error {
if session.IsAutoClose {
defer session.Close()
}
for _, table := range session.Engine.Tables {
session.Statement.RefTable = table
session.Statement.tableName = table.Name
err := session.createOneTable()
session.resetStatement()
if err != nil {
return err
}
}
return nil
}
// DropIndexes drop indexes // DropIndexes drop indexes
func (session *Session) DropIndexes(bean interface{}) error { func (session *Session) DropIndexes(bean interface{}) error {
v := rValue(bean) v := rValue(bean)
@ -208,22 +190,6 @@ func (session *Session) isTableEmpty(tableName string) (bool, error) {
return total == 0, nil return total == 0, nil
} }
func (session *Session) isIndexExist(tableName, idxName string, unique bool) (bool, error) {
defer session.resetStatement()
if session.IsAutoClose {
defer session.Close()
}
var idx string
if unique {
idx = uniqueName(tableName, idxName)
} else {
idx = indexName(tableName, idxName)
}
sqlStr, args := session.Engine.dialect.IndexCheckSql(tableName, idx)
results, err := session.query(sqlStr, args...)
return len(results) > 0, err
}
// find if index is exist according cols // find if index is exist according cols
func (session *Session) isIndexExist2(tableName string, cols []string, unique bool) (bool, error) { func (session *Session) isIndexExist2(tableName string, cols []string, unique bool) (bool, error) {
defer session.resetStatement() defer session.resetStatement()
@ -282,25 +248,6 @@ func (session *Session) addUnique(tableName, uqeName string) error {
return err return err
} }
// To be deleted
func (session *Session) dropAll() error {
defer session.resetStatement()
if session.IsAutoClose {
defer session.Close()
}
for _, table := range session.Engine.Tables {
session.Statement.Init()
session.Statement.RefTable = table
sqlStr := session.Engine.Dialect().DropTableSql(session.Statement.TableName())
_, err := session.exec(sqlStr)
if err != nil {
return err
}
}
return nil
}
// Sync2 synchronize structs to database tables // Sync2 synchronize structs to database tables
func (session *Session) Sync2(beans ...interface{}) error { func (session *Session) Sync2(beans ...interface{}) error {
engine := session.Engine engine := session.Engine

7
vendor/github.com/go-xorm/xorm/session_sum.go generated vendored

@ -8,7 +8,7 @@ import "database/sql"
// Count counts the records. bean's non-empty fields // Count counts the records. bean's non-empty fields
// are conditions. // are conditions.
func (session *Session) Count(bean interface{}) (int64, error) { func (session *Session) Count(bean ...interface{}) (int64, error) {
defer session.resetStatement() defer session.resetStatement()
if session.IsAutoClose { if session.IsAutoClose {
defer session.Close() defer session.Close()
@ -17,7 +17,10 @@ func (session *Session) Count(bean interface{}) (int64, error) {
var sqlStr string var sqlStr string
var args []interface{} var args []interface{}
if session.Statement.RawSQL == "" { if session.Statement.RawSQL == "" {
sqlStr, args = session.Statement.genCountSQL(bean) if len(bean) == 0 {
return 0, ErrTableNotFound
}
sqlStr, args = session.Statement.genCountSQL(bean[0])
} else { } else {
sqlStr = session.Statement.RawSQL sqlStr = session.Statement.RawSQL
args = session.Statement.RawParams args = session.Statement.RawParams

14
vendor/github.com/go-xorm/xorm/session_update.go generated vendored

@ -298,7 +298,19 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
condSQL = "WHERE " + condSQL condSQL = "WHERE " + condSQL
} }
} else if st.Engine.dialect.DBType() == core.MSSQL { } else if st.Engine.dialect.DBType() == core.MSSQL {
top = fmt.Sprintf("top (%d) ", st.LimitN) if st.OrderStr != "" && st.Engine.dialect.DBType() == core.MSSQL &&
table != nil && len(table.PrimaryKeys) == 1 {
cond = builder.Expr(fmt.Sprintf("%s IN (SELECT TOP (%d) %s FROM %v%v)",
table.PrimaryKeys[0], st.LimitN, table.PrimaryKeys[0],
session.Engine.Quote(session.Statement.TableName()), condSQL), condArgs...)
condSQL, condArgs, _ = builder.ToSQL(cond)
if len(condSQL) > 0 {
condSQL = "WHERE " + condSQL
}
} else {
top = fmt.Sprintf("TOP (%d) ", st.LimitN)
}
} }
} }

6
vendor/github.com/go-xorm/xorm/statement.go generated vendored

@ -376,7 +376,7 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
if !requiredField && (t.IsZero() || !fieldValue.IsValid()) { if !requiredField && (t.IsZero() || !fieldValue.IsValid()) {
continue continue
} }
val = engine.FormatTime(col.SQLType.Name, t) val = engine.formatColTime(col, t)
} else if nulType, ok := fieldValue.Interface().(driver.Valuer); ok { } else if nulType, ok := fieldValue.Interface().(driver.Valuer); ok {
val, _ = nulType.Value() val, _ = nulType.Value()
} else { } else {
@ -612,7 +612,7 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
if !requiredField && (t.IsZero() || !fieldValue.IsValid()) { if !requiredField && (t.IsZero() || !fieldValue.IsValid()) {
continue continue
} }
val = engine.FormatTime(col.SQLType.Name, t) val = engine.formatColTime(col, t)
} else if _, ok := reflect.New(fieldType).Interface().(core.Conversion); ok { } else if _, ok := reflect.New(fieldType).Interface().(core.Conversion); ok {
continue continue
} else if valNul, ok := fieldValue.Interface().(driver.Valuer); ok { } else if valNul, ok := fieldValue.Interface().(driver.Valuer); ok {
@ -1278,7 +1278,7 @@ func (statement *Statement) genSelectSQL(columnStr, condSQL string) (a string) {
} }
// !nashtsai! REVIEW Sprintf is considered slowest mean of string concatnation, better to work with builder pattern // !nashtsai! REVIEW Sprintf is considered slowest mean of string concatnation, better to work with builder pattern
a = fmt.Sprintf("SELECT %v%v%v%v%v", top, distinct, columnStr, fromStr, whereStr) a = fmt.Sprintf("SELECT %v%v%v%v%v", distinct, top, columnStr, fromStr, whereStr)
if len(mssqlCondi) > 0 { if len(mssqlCondi) > 0 {
if len(whereStr) > 0 { if len(whereStr) > 0 {
a += " AND " + mssqlCondi a += " AND " + mssqlCondi

1
vendor/github.com/go-xorm/xorm/test_mssql.sh generated vendored

@ -0,0 +1 @@
go test -db=mssql -conn_str="server=192.168.1.58;user id=sa;password=123456;database=xorm_test"

1
vendor/github.com/go-xorm/xorm/test_mysql.sh generated vendored

@ -0,0 +1 @@
go test -db=mysql -conn_str="root:@/xorm_test"

1
vendor/github.com/go-xorm/xorm/test_postgres.sh generated vendored

@ -0,0 +1 @@
go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable"

1
vendor/github.com/go-xorm/xorm/test_sqlite.sh generated vendored

@ -0,0 +1 @@
go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc"

8
vendor/github.com/go-xorm/xorm/xorm.go generated vendored

@ -17,7 +17,7 @@ import (
const ( const (
// Version show the xorm's version // Version show the xorm's version
Version string = "0.6.2.0412" Version string = "0.6.2.0605"
) )
func regDrvsNDialects() bool { func regDrvsNDialects() bool {
@ -89,6 +89,12 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
tagHandlers: defaultTagHandlers, tagHandlers: defaultTagHandlers,
} }
if uri.DbType == core.SQLITE {
engine.DatabaseTZ = time.UTC
} else {
engine.DatabaseTZ = time.Local
}
logger := NewSimpleLogger(os.Stdout) logger := NewSimpleLogger(os.Stdout)
logger.SetLevel(core.LOG_INFO) logger.SetLevel(core.LOG_INFO)
engine.SetLogger(logger) engine.SetLogger(logger)

18
vendor/vendor.json vendored

@ -153,22 +153,22 @@
"revisionTime": "2016-08-02T11:38:42Z" "revisionTime": "2016-08-02T11:38:42Z"
}, },
{ {
"checksumSHA1": "Fh6Svimt+QyXHbaVxgSV7qwUHL8=", "checksumSHA1": "9SXbj96wb1PgppBZzxMIN0axbFQ=",
"path": "github.com/go-xorm/builder", "path": "github.com/go-xorm/builder",
"revision": "9c357861b643b7dd1023551fdf116b8d42030146", "revision": "c8871c857d2555fbfbd8524f895be5386d3d8836",
"revisionTime": "2017-02-16T03:03:40Z" "revisionTime": "2017-05-19T03:21:30Z"
}, },
{ {
"checksumSHA1": "1BBE89UpNp+qVvrF5oKdRLTaBJc=", "checksumSHA1": "GnWfEqqhYT5MsxzlB6bRESmkDvM=",
"path": "github.com/go-xorm/core", "path": "github.com/go-xorm/core",
"revision": "7daacb215ed03af093a72e0af32a5fe79458613d", "revision": "6c9f9bf3130d143937e4adcef1cf1bb9f6899260",
"revisionTime": "2017-02-06T15:24:21Z" "revisionTime": "2017-05-03T12:16:46Z"
}, },
{ {
"checksumSHA1": "Ka4hFMvc75Fb57ZNLALyYSM7CCE=", "checksumSHA1": "UN8r+3fuSzXJ1tXCe+M8g5eRpOI=",
"path": "github.com/go-xorm/xorm", "path": "github.com/go-xorm/xorm",
"revision": "d52a762fba17a2ed265463c1c7b608c14836eaaf", "revision": "8a877636fdbbb0f7133b158fe5cde3588464b035",
"revisionTime": "2017-04-20T16:02:48Z" "revisionTime": "2017-06-06T06:54:59Z"
}, },
{ {
"checksumSHA1": "1ft/4j5MFa7C9dPI9whL03HSUzk=", "checksumSHA1": "1ft/4j5MFa7C9dPI9whL03HSUzk=",

Loading…
Cancel
Save