mirror of https://github.com/go-gitea/gitea.git
Upgrade xorm to v1.1.1 (#16339)
parent
32fd11395b
commit
760af187ba
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2021 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.
|
||||||
|
|
||||||
|
// +build jsoniter
|
||||||
|
|
||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
DefaultJSONHandler = JSONiter{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSONiter implements JSONInterface via jsoniter
|
||||||
|
type JSONiter struct{}
|
||||||
|
|
||||||
|
// Marshal implements JSONInterface
|
||||||
|
func (JSONiter) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
return jsoniter.Marshal(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unmarshal implements JSONInterface
|
||||||
|
func (JSONiter) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
return jsoniter.Unmarshal(data, v)
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
// Copyright 2019 The Xorm Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package statements
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"xorm.io/builder"
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ErrUnsupportedExprType represents an error with unsupported express type
|
||||||
|
type ErrUnsupportedExprType struct {
|
||||||
|
tp string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrUnsupportedExprType) Error() string {
|
||||||
|
return fmt.Sprintf("Unsupported expression type: %v", err.tp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expr represents an SQL express
|
||||||
|
type Expr struct {
|
||||||
|
ColName string
|
||||||
|
Arg interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteArgs writes args to the writer
|
||||||
|
func (expr *Expr) WriteArgs(w *builder.BytesWriter) error {
|
||||||
|
switch arg := expr.Arg.(type) {
|
||||||
|
case *builder.Builder:
|
||||||
|
if _, err := w.WriteString("("); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := arg.WriteTo(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := w.WriteString(")"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case string:
|
||||||
|
if arg == "" {
|
||||||
|
arg = "''"
|
||||||
|
}
|
||||||
|
if _, err := w.WriteString(fmt.Sprintf("%v", arg)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if _, err := w.WriteString("?"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
w.Append(arg)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type exprParams []Expr
|
||||||
|
|
||||||
|
func (exprs exprParams) ColNames() []string {
|
||||||
|
var cols = make([]string, 0, len(exprs))
|
||||||
|
for _, expr := range exprs {
|
||||||
|
cols = append(cols, expr.ColName)
|
||||||
|
}
|
||||||
|
return cols
|
||||||
|
}
|
||||||
|
|
||||||
|
func (exprs *exprParams) Add(name string, arg interface{}) {
|
||||||
|
*exprs = append(*exprs, Expr{name, arg})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (exprs exprParams) IsColExist(colName string) bool {
|
||||||
|
for _, expr := range exprs {
|
||||||
|
if strings.EqualFold(schemas.CommonQuoter.Trim(expr.ColName), schemas.CommonQuoter.Trim(colName)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (exprs exprParams) WriteArgs(w *builder.BytesWriter) error {
|
||||||
|
for i, expr := range exprs {
|
||||||
|
if err := expr.WriteArgs(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if i != len(exprs)-1 {
|
||||||
|
if _, err := w.WriteString(","); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,127 +0,0 @@
|
|||||||
// Copyright 2019 The Xorm Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package statements
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"xorm.io/builder"
|
|
||||||
"xorm.io/xorm/schemas"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ErrUnsupportedExprType represents an error with unsupported express type
|
|
||||||
type ErrUnsupportedExprType struct {
|
|
||||||
tp string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrUnsupportedExprType) Error() string {
|
|
||||||
return fmt.Sprintf("Unsupported expression type: %v", err.tp)
|
|
||||||
}
|
|
||||||
|
|
||||||
type exprParam struct {
|
|
||||||
colName string
|
|
||||||
arg interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type exprParams struct {
|
|
||||||
ColNames []string
|
|
||||||
Args []interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) Len() int {
|
|
||||||
return len(exprs.ColNames)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) addParam(colName string, arg interface{}) {
|
|
||||||
exprs.ColNames = append(exprs.ColNames, colName)
|
|
||||||
exprs.Args = append(exprs.Args, arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) IsColExist(colName string) bool {
|
|
||||||
for _, name := range exprs.ColNames {
|
|
||||||
if strings.EqualFold(schemas.CommonQuoter.Trim(name), schemas.CommonQuoter.Trim(colName)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) getByName(colName string) (exprParam, bool) {
|
|
||||||
for i, name := range exprs.ColNames {
|
|
||||||
if strings.EqualFold(name, colName) {
|
|
||||||
return exprParam{name, exprs.Args[i]}, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return exprParam{}, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) WriteArgs(w *builder.BytesWriter) error {
|
|
||||||
for i, expr := range exprs.Args {
|
|
||||||
switch arg := expr.(type) {
|
|
||||||
case *builder.Builder:
|
|
||||||
if _, err := w.WriteString("("); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := arg.WriteTo(w); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := w.WriteString(")"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case string:
|
|
||||||
if arg == "" {
|
|
||||||
arg = "''"
|
|
||||||
}
|
|
||||||
if _, err := w.WriteString(fmt.Sprintf("%v", arg)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
if _, err := w.WriteString("?"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
w.Append(arg)
|
|
||||||
}
|
|
||||||
if i != len(exprs.Args)-1 {
|
|
||||||
if _, err := w.WriteString(","); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (exprs *exprParams) writeNameArgs(w *builder.BytesWriter) error {
|
|
||||||
for i, colName := range exprs.ColNames {
|
|
||||||
if _, err := w.WriteString(colName); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := w.WriteString("="); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg := exprs.Args[i].(type) {
|
|
||||||
case *builder.Builder:
|
|
||||||
if _, err := w.WriteString("("); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := arg.WriteTo(w); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := w.WriteString("("); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
w.Append(exprs.Args[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
if i+1 != len(exprs.ColNames) {
|
|
||||||
if _, err := w.WriteString(","); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright 2021 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 (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"xorm.io/xorm/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (engine *Engine) row2mapStr(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string]string, error) {
|
||||||
|
var scanResults = make([]interface{}, len(fields))
|
||||||
|
for i := 0; i < len(fields); i++ {
|
||||||
|
var s sql.NullString
|
||||||
|
scanResults[i] = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Scan(scanResults...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(map[string]string, len(fields))
|
||||||
|
for ii, key := range fields {
|
||||||
|
s := scanResults[ii].(*sql.NullString)
|
||||||
|
result[key] = s.String
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) row2mapBytes(rows *core.Rows, types []*sql.ColumnType, fields []string) (map[string][]byte, error) {
|
||||||
|
var scanResults = make([]interface{}, len(fields))
|
||||||
|
for i := 0; i < len(fields); i++ {
|
||||||
|
var s sql.NullString
|
||||||
|
scanResults[i] = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Scan(scanResults...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make(map[string][]byte, len(fields))
|
||||||
|
for ii, key := range fields {
|
||||||
|
s := scanResults[ii].(*sql.NullString)
|
||||||
|
result[key] = []byte(s.String)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) row2sliceStr(rows *core.Rows, types []*sql.ColumnType, fields []string) ([]string, error) {
|
||||||
|
results := make([]string, 0, len(fields))
|
||||||
|
var scanResults = make([]interface{}, len(fields))
|
||||||
|
for i := 0; i < len(fields); i++ {
|
||||||
|
var s sql.NullString
|
||||||
|
scanResults[i] = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rows.Scan(scanResults...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(fields); i++ {
|
||||||
|
results = append(results, scanResults[i].(*sql.NullString).String)
|
||||||
|
}
|
||||||
|
return results, nil
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2021 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 schemas
|
||||||
|
|
||||||
|
// Version represents a database version
|
||||||
|
type Version struct {
|
||||||
|
Number string // the version number which could be compared
|
||||||
|
Level string
|
||||||
|
Edition string
|
||||||
|
}
|
Loading…
Reference in New Issue