Merge pull request 'updated dependencies - fosdem 2024 commit' (#5) from develop into master
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

Reviewed-on: #5
This commit is contained in:
Paul 2024-02-03 15:24:43 +01:00
commit 45f86d5598
28 changed files with 434 additions and 151 deletions

8
go.mod
View File

@ -5,9 +5,9 @@ go 1.21
require (
github.com/labstack/echo/v4 v4.11.4
github.com/lib/pq v1.10.9
golang.org/x/net v0.19.0
golang.org/x/net v0.20.0
gopkg.in/ini.v1 v1.67.0
xorm.io/xorm v1.3.4
xorm.io/xorm v1.3.7
)
require (
@ -25,8 +25,8 @@ require (
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
xorm.io/builder v0.3.13 // indirect
)

8
go.sum
View File

@ -464,6 +464,8 @@ golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@ -507,6 +509,8 @@ golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -569,6 +573,8 @@ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@ -800,3 +806,5 @@ xorm.io/xorm v1.3.3 h1:L5/GOhvgMcwJYYRjzPf3lTTTf6JcaTd1Mb9A/Iqvccw=
xorm.io/xorm v1.3.3/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
xorm.io/xorm v1.3.4 h1:vWFKzR3DhGUDl5b4srhUjhDwjxkZAc4C7BFszpu0swI=
xorm.io/xorm v1.3.4/go.mod h1:qFJGFoVYbbIdnz2vaL5OxSQ2raleMpyRRalnq3n9OJo=
xorm.io/xorm v1.3.7 h1:mLceAGu0b87r9pD4qXyxGHxifOXIIrAdVcA6k95/osw=
xorm.io/xorm v1.3.7/go.mod h1:LsCCffeeYp63ssk0pKumP6l96WZcHix7ChpurcLNuMw=

View File

@ -248,6 +248,7 @@ struct ltchars {
#include <linux/module.h>
#include <linux/mount.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nf_tables.h>
#include <linux/netlink.h>
#include <linux/net_namespace.h>
#include <linux/nfc.h>
@ -283,10 +284,6 @@ struct ltchars {
#include <asm/termbits.h>
#endif
#ifndef MSG_FASTOPEN
#define MSG_FASTOPEN 0x20000000
#endif
#ifndef PTRACE_GETREGS
#define PTRACE_GETREGS 0xc
#endif
@ -295,14 +292,6 @@ struct ltchars {
#define PTRACE_SETREGS 0xd
#endif
#ifndef SOL_NETLINK
#define SOL_NETLINK 270
#endif
#ifndef SOL_SMC
#define SOL_SMC 286
#endif
#ifdef SOL_BLUETOOTH
// SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h
// but it is already in bluetooth_linux.go
@ -319,10 +308,23 @@ struct ltchars {
#undef TIPC_WAIT_FOREVER
#define TIPC_WAIT_FOREVER 0xffffffff
// Copied from linux/l2tp.h
// Including linux/l2tp.h here causes conflicts between linux/in.h
// and netinet/in.h included via net/route.h above.
#define IPPROTO_L2TP 115
// Copied from linux/netfilter/nf_nat.h
// Including linux/netfilter/nf_nat.h here causes conflicts between linux/in.h
// and netinet/in.h.
#define NF_NAT_RANGE_MAP_IPS (1 << 0)
#define NF_NAT_RANGE_PROTO_SPECIFIED (1 << 1)
#define NF_NAT_RANGE_PROTO_RANDOM (1 << 2)
#define NF_NAT_RANGE_PERSISTENT (1 << 3)
#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4)
#define NF_NAT_RANGE_PROTO_OFFSET (1 << 5)
#define NF_NAT_RANGE_NETMAP (1 << 6)
#define NF_NAT_RANGE_PROTO_RANDOM_ALL \
(NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY)
#define NF_NAT_RANGE_MASK \
(NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \
NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \
NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET | \
NF_NAT_RANGE_NETMAP)
// Copied from linux/hid.h.
// Keep in sync with the size of the referenced fields.
@ -603,6 +605,9 @@ ccflags="$@"
$2 ~ /^FSOPT_/ ||
$2 ~ /^WDIO[CFS]_/ ||
$2 ~ /^NFN/ ||
$2 !~ /^NFT_META_IIFTYPE/ &&
$2 ~ /^NFT_/ ||
$2 ~ /^NF_NAT_/ ||
$2 ~ /^XDP_/ ||
$2 ~ /^RWF_/ ||
$2 ~ /^(HDIO|WIN|SMART)_/ ||

View File

@ -2127,6 +2127,60 @@ const (
NFNL_SUBSYS_QUEUE = 0x3
NFNL_SUBSYS_ULOG = 0x4
NFS_SUPER_MAGIC = 0x6969
NFT_CHAIN_FLAGS = 0x7
NFT_CHAIN_MAXNAMELEN = 0x100
NFT_CT_MAX = 0x17
NFT_DATA_RESERVED_MASK = 0xffffff00
NFT_DATA_VALUE_MAXLEN = 0x40
NFT_EXTHDR_OP_MAX = 0x4
NFT_FIB_RESULT_MAX = 0x3
NFT_INNER_MASK = 0xf
NFT_LOGLEVEL_MAX = 0x8
NFT_NAME_MAXLEN = 0x100
NFT_NG_MAX = 0x1
NFT_OBJECT_CONNLIMIT = 0x5
NFT_OBJECT_COUNTER = 0x1
NFT_OBJECT_CT_EXPECT = 0x9
NFT_OBJECT_CT_HELPER = 0x3
NFT_OBJECT_CT_TIMEOUT = 0x7
NFT_OBJECT_LIMIT = 0x4
NFT_OBJECT_MAX = 0xa
NFT_OBJECT_QUOTA = 0x2
NFT_OBJECT_SECMARK = 0x8
NFT_OBJECT_SYNPROXY = 0xa
NFT_OBJECT_TUNNEL = 0x6
NFT_OBJECT_UNSPEC = 0x0
NFT_OBJ_MAXNAMELEN = 0x100
NFT_OSF_MAXGENRELEN = 0x10
NFT_QUEUE_FLAG_BYPASS = 0x1
NFT_QUEUE_FLAG_CPU_FANOUT = 0x2
NFT_QUEUE_FLAG_MASK = 0x3
NFT_REG32_COUNT = 0x10
NFT_REG32_SIZE = 0x4
NFT_REG_MAX = 0x4
NFT_REG_SIZE = 0x10
NFT_REJECT_ICMPX_MAX = 0x3
NFT_RT_MAX = 0x4
NFT_SECMARK_CTX_MAXLEN = 0x100
NFT_SET_MAXNAMELEN = 0x100
NFT_SOCKET_MAX = 0x3
NFT_TABLE_F_MASK = 0x3
NFT_TABLE_MAXNAMELEN = 0x100
NFT_TRACETYPE_MAX = 0x3
NFT_TUNNEL_F_MASK = 0x7
NFT_TUNNEL_MAX = 0x1
NFT_TUNNEL_MODE_MAX = 0x2
NFT_USERDATA_MAXLEN = 0x100
NFT_XFRM_KEY_MAX = 0x6
NF_NAT_RANGE_MAP_IPS = 0x1
NF_NAT_RANGE_MASK = 0x7f
NF_NAT_RANGE_NETMAP = 0x40
NF_NAT_RANGE_PERSISTENT = 0x8
NF_NAT_RANGE_PROTO_OFFSET = 0x20
NF_NAT_RANGE_PROTO_RANDOM = 0x4
NF_NAT_RANGE_PROTO_RANDOM_ALL = 0x14
NF_NAT_RANGE_PROTO_RANDOM_FULLY = 0x10
NF_NAT_RANGE_PROTO_SPECIFIED = 0x2
NILFS_SUPER_MAGIC = 0x3434
NL0 = 0x0
NL1 = 0x100

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

View File

@ -2297,5 +2297,3 @@ func unveil(path *byte, flags *byte) (err error) {
var libc_unveil_trampoline_addr uintptr
//go:cgo_import_dynamic libc_unveil unveil "libc.so"

10
vendor/modules.txt vendored
View File

@ -65,11 +65,11 @@ github.com/valyala/bytebufferpool
# github.com/valyala/fasttemplate v1.2.2
## explicit; go 1.12
github.com/valyala/fasttemplate
# golang.org/x/crypto v0.17.0
# golang.org/x/crypto v0.18.0
## explicit; go 1.18
golang.org/x/crypto/acme
golang.org/x/crypto/acme/autocert
# golang.org/x/net v0.19.0
# golang.org/x/net v0.20.0
## explicit; go 1.18
golang.org/x/net/http/httpguts
golang.org/x/net/http2
@ -77,7 +77,7 @@ golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/websocket
# golang.org/x/sys v0.15.0
# golang.org/x/sys v0.16.0
## explicit; go 1.18
golang.org/x/sys/unix
# golang.org/x/text v0.14.0
@ -92,8 +92,8 @@ gopkg.in/ini.v1
# xorm.io/builder v0.3.13
## explicit; go 1.11
xorm.io/builder
# xorm.io/xorm v1.3.4
## explicit; go 1.16
# xorm.io/xorm v1.3.7
## explicit; go 1.18
xorm.io/xorm
xorm.io/xorm/caches
xorm.io/xorm/contexts

2
vendor/xorm.io/xorm/Makefile generated vendored
View File

@ -25,6 +25,7 @@ TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
TEST_MSSQL_DEFAULT_VARCHAR ?= varchar
TEST_MSSQL_DEFAULT_CHAR ?= char
TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST ?= true
TEST_MSSQL_COLLATION ?=
TEST_MYSQL_HOST ?= mysql:3306
TEST_MYSQL_CHARSET ?= utf8
@ -153,6 +154,7 @@ test-mssql: go-check
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
-default_varchar=$(TEST_MSSQL_DEFAULT_VARCHAR) -default_char=$(TEST_MSSQL_DEFAULT_CHAR) \
-do_nvarchar_override_test=$(TEST_MSSQL_DO_NVARCHAR_OVERRIDE_TEST) \
-collation=$(TEST_MSSQL_COLLATION) \
-coverprofile=mssql.$(TEST_QUOTE_POLICY).$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic -timeout=20m
.PNONY: test-mssql\#%

4
vendor/xorm.io/xorm/README.md generated vendored
View File

@ -1,6 +1,6 @@
# xorm
[中文](https://gitea.com/xorm/xorm/src/branch/master/README_CN.md)
[中文](https://gitea.com/xorm/xorm/src/branch/v1/README_CN.md)
Xorm is a simple and powerful ORM for Go.
@ -48,7 +48,7 @@ Drivers for Go's sql package which currently support database/sql includes:
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite)
* MsSql
- [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
* Oracle
- [github.com/godror/godror](https://github.com/godror/godror) (experiment)

4
vendor/xorm.io/xorm/README_CN.md generated vendored
View File

@ -1,6 +1,6 @@
# xorm
[English](https://gitea.com/xorm/xorm/src/branch/master/README.md)
[English](https://gitea.com/xorm/xorm/src/branch/v1/README.md)
xorm 是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作非常简便。
@ -47,7 +47,7 @@ v1.0.0 相对于 v0.8.2 有以下不兼容的变更:
- [modernc.org/sqlite](https://gitlab.com/cznic/sqlite)
* MsSql
- [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb)
- [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb)
* Oracle
- [github.com/godror/godror](https://github.com/godror/godror) (试验性支持)

View File

@ -586,10 +586,10 @@ func (db *mssql) GetIndexes(queryer core.Queryer, ctx context.Context, tableName
IXS.NAME AS [INDEX_NAME],
C.NAME AS [COLUMN_NAME],
IXS.is_unique AS [IS_UNIQUE]
FROM SYS.INDEXES IXS
INNER JOIN SYS.INDEX_COLUMNS IXCS
FROM sys.indexes IXS
INNER JOIN sys.index_columns IXCS
ON IXS.OBJECT_ID=IXCS.OBJECT_ID AND IXS.INDEX_ID = IXCS.INDEX_ID
INNER JOIN SYS.COLUMNS C ON IXS.OBJECT_ID=C.OBJECT_ID
INNER JOIN sys.columns C ON IXS.OBJECT_ID=C.OBJECT_ID
AND IXCS.COLUMN_ID=C.COLUMN_ID
WHERE IXS.TYPE_DESC='NONCLUSTERED' and OBJECT_NAME(IXS.OBJECT_ID) =?
`

View File

@ -11,6 +11,7 @@ import (
"fmt"
"regexp"
"strings"
"unicode"
"xorm.io/xorm/core"
"xorm.io/xorm/schemas"
@ -320,7 +321,7 @@ func splitColStr(colStr string) []string {
var lastIdx int
var hasC, hasQuote bool
for i, c := range colStr {
if c == ' ' && !hasQuote {
if unicode.IsSpace(c) && !hasQuote {
if hasC {
results = append(results, colStr[lastIdx:i])
hasC = false
@ -350,7 +351,7 @@ func parseString(colStr string) (*schemas.Column, error) {
for idx, field := range fields {
if idx == 0 {
col.Name = strings.Trim(strings.Trim(field, "`[] "), `"`)
col.Name = strings.Trim(strings.TrimSpace(field), "`[]'\"")
continue
} else if idx == 1 {
col.SQLType = schemas.SQLType{Name: field, DefaultLength: 0, DefaultLength2: 0}
@ -400,6 +401,8 @@ func (db *sqlite3) GetColumns(queryer core.Queryer, ctx context.Context, tableNa
return nil, nil, errors.New("no table named " + tableName)
}
name = strings.ReplaceAll(name, "\n", " ")
nStart := strings.Index(name, "(")
nEnd := strings.LastIndex(name, ")")
reg := regexp.MustCompile(`[^\(,\)]*(\([^\(]*\))?`)
@ -483,7 +486,7 @@ func (db *sqlite3) GetIndexes(queryer core.Queryer, ctx context.Context, tableNa
if !tmpSQL.Valid {
continue
}
sql := tmpSQL.String
sql := strings.ReplaceAll(tmpSQL.String, "\n", " ")
index := new(schemas.Index)
nNStart := strings.Index(sql, "INDEX")

15
vendor/xorm.io/xorm/engine.go generated vendored
View File

@ -51,7 +51,7 @@ type Engine struct {
// NewEngine new a db manager according to the parameter. Currently support four
// drivers
func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
func NewEngine(driverName string, dataSourceName string, driverOptions ...func(db *sql.DB) error) (*Engine, error) {
dialect, err := dialects.OpenDialect(driverName, dataSourceName)
if err != nil {
return nil, err
@ -62,6 +62,12 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
return nil, err
}
for _, driverOption := range driverOptions {
if err := driverOption(db.DB); err != nil {
return nil, err
}
}
return newEngine(driverName, dataSourceName, dialect, db)
}
@ -1433,3 +1439,10 @@ func (engine *Engine) Transaction(f func(*Session) (interface{}, error)) (interf
return result, nil
}
func (engine *Engine) IndexHint(op, forType, indexerOrColName string) *Session {
session := engine.NewSession()
session.isAutoClose = true
session.statement.LastError = session.statement.IndexHint(op, forType, indexerOrColName)
return session
}

64
vendor/xorm.io/xorm/internal/statements/index.go generated vendored Normal file
View File

@ -0,0 +1,64 @@
// Copyright 2023 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 (
"strings"
"xorm.io/builder"
"xorm.io/xorm/schemas"
)
type ErrInvalidIndexHintOperator struct {
Op string
}
func (e ErrInvalidIndexHintOperator) Error() string {
return "invalid index hint operator: " + e.Op
}
func (statement *Statement) IndexHint(op, forType, indexName string) error {
op = strings.ToUpper(op)
statement.indexHints = append(statement.indexHints, indexHint{
op: op,
forType: forType,
indexName: indexName,
})
return nil
}
func (statement *Statement) writeIndexHints(w *builder.BytesWriter) error {
if len(statement.indexHints) == 0 {
return nil
}
switch statement.dialect.URI().DBType {
case schemas.MYSQL:
return statement.writeIndexHintsMySQL(w)
default:
return ErrNotImplemented
}
}
func (statement *Statement) writeIndexHintsMySQL(w *builder.BytesWriter) error {
for _, hint := range statement.indexHints {
if hint.op != "USE" && hint.op != "FORCE" && hint.op != "IGNORE" {
return ErrInvalidIndexHintOperator{Op: hint.op}
}
if err := statement.writeStrings(" ", hint.op, " INDEX")(w); err != nil {
return err
}
if hint.forType != "" {
if err := statement.writeStrings(" FOR ", hint.forType)(w); err != nil {
return err
}
}
if err := statement.writeStrings("(", hint.indexName, ")")(w); err != nil {
return err
}
}
return nil
}

View File

@ -34,13 +34,7 @@ func (statement *Statement) writeJoins(w *builder.BytesWriter) error {
return nil
}
func (statement *Statement) writeJoin(buf *builder.BytesWriter, join join) error {
// write join operator
if _, err := fmt.Fprint(buf, " ", join.op, " JOIN"); err != nil {
return err
}
// write join table or subquery
func (statement *Statement) writeJoinTable(buf *builder.BytesWriter, join join) error {
switch tp := join.table.(type) {
case builder.Builder:
if _, err := fmt.Fprintf(buf, " ("); err != nil {
@ -87,6 +81,19 @@ func (statement *Statement) writeJoin(buf *builder.BytesWriter, join join) error
return err
}
}
return nil
}
func (statement *Statement) writeJoin(buf *builder.BytesWriter, join join) error {
// write join operator
if _, err := fmt.Fprint(buf, " ", join.op, " JOIN"); err != nil {
return err
}
// write join table or subquery
if err := statement.writeJoinTable(buf, join); err != nil {
return err
}
// write on condition
if _, err := fmt.Fprint(buf, " ON "); err != nil {
@ -109,3 +116,14 @@ func (statement *Statement) writeJoin(buf *builder.BytesWriter, join join) error
return nil
}
func (statement *Statement) convertJoinCondition(join join) (builder.Cond, error) {
switch condTp := join.condition.(type) {
case string:
return builder.Expr(statement.ReplaceQuote(condTp), join.args...), nil
case builder.Cond:
return condTp, nil
default:
return nil, fmt.Errorf("unsupported join condition type: %v", condTp)
}
}

View File

@ -10,11 +10,12 @@ import (
"xorm.io/builder"
"xorm.io/xorm/internal/utils"
"xorm.io/xorm/schemas"
)
func (statement *Statement) writePagination(bw *builder.BytesWriter) error {
dbType := statement.dialect.URI().DBType
if dbType == "mssql" || dbType == "oracle" {
if dbType == schemas.MSSQL || dbType == schemas.ORACLE {
return statement.writeOffsetFetch(bw)
}
return statement.writeLimitOffset(bw)
@ -50,15 +51,15 @@ func (statement *Statement) writeOffsetFetch(w builder.Writer) error {
}
func (statement *Statement) writeWhereWithMssqlPagination(w *builder.BytesWriter) error {
if !statement.cond.IsValid() {
return statement.writeMssqlPaginationCond(w)
}
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
return err
}
if err := statement.cond.WriteTo(statement.QuoteReplacer(w)); err != nil {
return err
if statement.cond.IsValid() {
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
return err
}
if err := statement.cond.WriteTo(statement.QuoteReplacer(w)); err != nil {
return err
}
}
return statement.writeMssqlPaginationCond(w)
}
@ -115,15 +116,8 @@ func (statement *Statement) writeMssqlPaginationCond(w *builder.BytesWriter) err
if _, err := fmt.Fprint(subWriter, "))"); err != nil {
return err
}
if statement.cond.IsValid() {
if _, err := fmt.Fprint(w, " AND "); err != nil {
return err
}
} else {
if _, err := fmt.Fprint(w, " WHERE "); err != nil {
return err
}
if err := statement.writeWhereOrAnd(w, statement.cond.IsValid()); err != nil {
return err
}
return utils.WriteBuilder(w, subWriter)

View File

@ -184,6 +184,7 @@ func (statement *Statement) writeFrom(w *builder.BytesWriter) error {
statement.writeStrings(" FROM "),
statement.writeTableName,
statement.writeAlias,
statement.writeIndexHints,
statement.writeJoins,
)
}

View File

@ -41,6 +41,12 @@ type join struct {
args []interface{}
}
type indexHint struct {
op string
forType string
indexName string
}
// Statement save all the sql info for executing SQL
type Statement struct {
RefTable *schemas.Table
@ -84,6 +90,7 @@ type Statement struct {
BufferSize int
Context contexts.ContextCache
LastError error
indexHints []indexHint
}
// NewStatement creates a new statement

View File

@ -341,12 +341,59 @@ func (statement *Statement) writeUpdateTableName(updateWriter *builder.BytesWrit
}
}
func (statement *Statement) writeUpdateFrom(updateWriter *builder.BytesWriter) error {
if statement.dialect.URI().DBType != schemas.MSSQL || statement.TableAlias == "" {
return nil
func (statement *Statement) writeUpdateFrom(updateWriter *builder.BytesWriter) (builder.Cond, error) {
if statement.dialect.URI().DBType == schemas.MSSQL {
if _, err := fmt.Fprint(updateWriter, " FROM"); err != nil {
return nil, err
}
if _, err := fmt.Fprint(updateWriter, " ", statement.quote(statement.TableName())); err != nil {
return nil, err
}
if statement.TableAlias != "" {
if _, err := fmt.Fprint(updateWriter, " ", statement.TableAlias); err != nil {
return nil, err
}
}
}
_, err := fmt.Fprint(updateWriter, " FROM ", statement.quote(statement.TableName()), " ", statement.TableAlias)
if len(statement.joins) == 0 {
return builder.NewCond(), nil
}
if statement.dialect.URI().DBType != schemas.MSSQL {
if _, err := fmt.Fprint(updateWriter, " FROM"); err != nil {
return nil, err
}
}
cond := builder.NewCond()
for i, join := range statement.joins {
if statement.dialect.URI().DBType == schemas.MSSQL || i > 0 {
if _, err := fmt.Fprint(updateWriter, ","); err != nil {
return nil, err
}
}
if err := statement.writeJoinTable(updateWriter, join); err != nil {
return nil, err
}
joinCond, err := statement.convertJoinCondition(join)
if err != nil {
return nil, err
}
cond = cond.And(joinCond)
}
return cond, nil
}
func (statement *Statement) writeWhereOrAnd(updateWriter *builder.BytesWriter, hasConditions bool) error {
if hasConditions {
_, err := fmt.Fprint(updateWriter, " AND ")
return err
}
_, err := fmt.Fprint(updateWriter, " WHERE ")
return err
}
@ -364,14 +411,8 @@ func (statement *Statement) writeUpdateLimit(updateWriter *builder.BytesWriter,
_, err := fmt.Fprintf(updateWriter, " LIMIT %d", limitValue)
return err
case schemas.SQLITE:
if cond.IsValid() {
if _, err := fmt.Fprint(updateWriter, " AND "); err != nil {
return err
}
} else {
if _, err := fmt.Fprint(updateWriter, " WHERE "); err != nil {
return err
}
if err := statement.writeWhereOrAnd(updateWriter, cond.IsValid()); err != nil {
return err
}
if _, err := fmt.Fprint(updateWriter, "rowid IN (SELECT rowid FROM ", statement.quote(tableName)); err != nil {
return err
@ -385,14 +426,8 @@ func (statement *Statement) writeUpdateLimit(updateWriter *builder.BytesWriter,
_, err := fmt.Fprintf(updateWriter, " LIMIT %d)", limitValue)
return err
case schemas.POSTGRES:
if cond.IsValid() {
if _, err := fmt.Fprint(updateWriter, " AND "); err != nil {
return err
}
} else {
if _, err := fmt.Fprint(updateWriter, " WHERE "); err != nil {
return err
}
if err := statement.writeWhereOrAnd(updateWriter, cond.IsValid()); err != nil {
return err
}
if _, err := fmt.Fprint(updateWriter, "CTID IN (SELECT CTID FROM ", statement.quote(tableName)); err != nil {
return err
@ -477,9 +512,9 @@ func (statement *Statement) writeVersionIncrSet(w builder.Writer, v reflect.Valu
return nil
}
func (statement *Statement) writeIncrSets(w builder.Writer, hasPreviousSet bool) error {
func (statement *Statement) writeIncrSets(w builder.Writer, hasPreviousSets bool) error {
for i, expr := range statement.IncrColumns {
if i > 0 || hasPreviousSet {
if i > 0 || hasPreviousSets {
if _, err := fmt.Fprint(w, ", "); err != nil {
return err
}
@ -492,10 +527,10 @@ func (statement *Statement) writeIncrSets(w builder.Writer, hasPreviousSet bool)
return nil
}
func (statement *Statement) writeDecrSets(w builder.Writer, hasPreviousSet bool) error {
func (statement *Statement) writeDecrSets(w builder.Writer, hasPreviousSets bool) error {
// for update action to like "column = column - ?"
for i, expr := range statement.DecrColumns {
if i > 0 || hasPreviousSet {
if i > 0 || hasPreviousSets {
if _, err := fmt.Fprint(w, ", "); err != nil {
return err
}
@ -508,10 +543,10 @@ func (statement *Statement) writeDecrSets(w builder.Writer, hasPreviousSet bool)
return nil
}
func (statement *Statement) writeExprSets(w *builder.BytesWriter, hasPreviousSet bool) error {
func (statement *Statement) writeExprSets(w *builder.BytesWriter, hasPreviousSets bool) error {
// for update action to like "column = expression"
for i, expr := range statement.ExprColumns {
if i > 0 || hasPreviousSet {
if i > 0 || hasPreviousSets {
if _, err := fmt.Fprint(w, ", "); err != nil {
return err
}
@ -544,41 +579,114 @@ func (statement *Statement) writeExprSets(w *builder.BytesWriter, hasPreviousSet
return nil
}
func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Value, colNames []string, args []interface{}) error {
previousLen := w.Len()
for i, colName := range colNames {
if i > 0 {
if _, err := fmt.Fprint(w, ", "); err != nil {
return err
func (statement *Statement) writeSetColumns(colNames []string, args []interface{}) func(w *builder.BytesWriter) error {
return func(w *builder.BytesWriter) error {
if len(colNames) == 0 {
return nil
}
if len(colNames) != len(args) {
return fmt.Errorf("columns elements %d but args elements %d", len(colNames), len(args))
}
for i, colName := range colNames {
if i > 0 {
if _, err := fmt.Fprint(w, ", "); err != nil {
return err
}
}
if statement.dialect.URI().DBType != schemas.SQLITE && statement.dialect.URI().DBType != schemas.POSTGRES && len(statement.joins) > 0 {
tbName := statement.TableAlias
if tbName == "" {
tbName = statement.TableName()
}
if _, err := fmt.Fprint(w, tbName, ".", colName); err != nil {
return err
}
} else {
if _, err := fmt.Fprint(w, colName); err != nil {
return err
}
}
}
if _, err := fmt.Fprint(w, colName); err != nil {
return err
}
w.Append(args...)
return nil
}
w.Append(args...)
}
if err := statement.writeIncrSets(w, w.Len() > previousLen); err != nil {
func (statement *Statement) writeUpdateSets(w *builder.BytesWriter, v reflect.Value, colNames []string, args []interface{}) error {
// write set
if _, err := fmt.Fprint(w, " SET "); err != nil {
return err
}
previousLen := w.Len()
if err := statement.writeSetColumns(colNames, args)(w); err != nil {
return err
}
if err := statement.writeDecrSets(w, w.Len() > previousLen); err != nil {
setNumber := len(colNames)
if err := statement.writeIncrSets(w, setNumber > 0); err != nil {
return err
}
if err := statement.writeExprSets(w, w.Len() > previousLen); err != nil {
setNumber += len(statement.IncrColumns)
if err := statement.writeDecrSets(w, setNumber > 0); err != nil {
return err
}
if err := statement.writeVersionIncrSet(w, v, w.Len() > previousLen); err != nil {
setNumber += len(statement.DecrColumns)
if err := statement.writeExprSets(w, setNumber > 0); err != nil {
return err
}
setNumber += len(statement.ExprColumns)
if err := statement.writeVersionIncrSet(w, v, setNumber > 0); err != nil {
return err
}
// if no columns to be updated, return error
if previousLen == w.Len() {
return ErrNoColumnsTobeUpdated
}
return nil
}
var ErrNoColumnsTobeUpdated = errors.New("no columns found to be updated")
func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
switch statement.dialect.URI().DBType {
case schemas.MYSQL:
return statement.writeUpdateMySQL(updateWriter, cond, v, colNames, args)
case schemas.MSSQL:
return statement.writeUpdateMSSQL(updateWriter, cond, v, colNames, args)
default:
return statement.writeUpdateCommon(updateWriter, cond, v, colNames, args)
}
}
func (statement *Statement) writeUpdateMySQL(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
if _, err := fmt.Fprintf(updateWriter, "UPDATE"); err != nil {
return err
}
if err := statement.writeUpdateTableName(updateWriter); err != nil {
return err
}
if err := statement.writeJoins(updateWriter); err != nil {
return err
}
if err := statement.writeUpdateSets(updateWriter, v, colNames, args); err != nil {
return err
}
// write where
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
return err
}
if err := statement.writeOrderBys(updateWriter); err != nil {
return err
}
return statement.writeUpdateLimit(updateWriter, cond)
}
func (statement *Statement) writeUpdateMSSQL(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
if _, err := fmt.Fprintf(updateWriter, "UPDATE"); err != nil {
return err
}
@ -591,47 +699,56 @@ func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond
return err
}
// write set
if _, err := fmt.Fprint(updateWriter, " SET "); err != nil {
if err := statement.writeUpdateSets(updateWriter, v, colNames, args); err != nil {
return err
}
// write from
joinConds, err := statement.writeUpdateFrom(updateWriter)
if err != nil {
return err
}
table := statement.RefTable
if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 {
} else {
// write where
if err := statement.writeWhereCond(updateWriter, cond.And(joinConds)); err != nil {
return err
}
}
return statement.writeUpdateLimit(updateWriter, cond.And(joinConds))
}
// writeUpdateCommon write update sql for non mysql && non mssql
func (statement *Statement) writeUpdateCommon(updateWriter *builder.BytesWriter, cond builder.Cond, v reflect.Value, colNames []string, args []interface{}) error {
if _, err := fmt.Fprintf(updateWriter, "UPDATE"); err != nil {
return err
}
if err := statement.writeUpdateTop(updateWriter); err != nil {
return err
}
if err := statement.writeUpdateTableName(updateWriter); err != nil {
return err
}
previousLen := updateWriter.Len()
if err := statement.writeUpdateSets(updateWriter, v, colNames, args); err != nil {
return err
}
// if no columns to be updated, return error
if previousLen == updateWriter.Len() {
return ErrNoColumnsTobeUpdated
}
// write from
if err := statement.writeUpdateFrom(updateWriter); err != nil {
joinConds, err := statement.writeUpdateFrom(updateWriter)
if err != nil {
return err
}
if statement.dialect.URI().DBType == schemas.MSSQL {
table := statement.RefTable
if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 {
} else {
// write where
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
return err
}
}
} else {
// write where
if err := statement.writeWhereCond(updateWriter, cond); err != nil {
return err
}
// write where
if err := statement.writeWhereCond(updateWriter, cond.And(joinConds)); err != nil {
return err
}
if statement.dialect.URI().DBType == schemas.MYSQL {
if err := statement.writeOrderBys(updateWriter); err != nil {
return err
}
}
return statement.writeUpdateLimit(updateWriter, cond)
return statement.writeUpdateLimit(updateWriter, cond.And(joinConds))
}

4
vendor/xorm.io/xorm/session_get.go generated vendored
View File

@ -240,7 +240,7 @@ func (session *Session) getSlice(rows *core.Rows, types []*sql.ColumnType, field
}
return nil
default:
return fmt.Errorf("unspoorted slice type: %t", t)
return fmt.Errorf("unsupported slice type: %t", t)
}
}
@ -269,7 +269,7 @@ func (session *Session) getMap(rows *core.Rows, types []*sql.ColumnType, fields
}
return nil
default:
return fmt.Errorf("unspoorted map type: %t", t)
return fmt.Errorf("unsupported map type: %t", t)
}
}

View File

@ -27,6 +27,12 @@ func (session *Session) Iterate(bean interface{}, fun IterFunc) error {
defer session.Close()
}
session.autoResetStatement = false
defer func() {
session.autoResetStatement = true
session.resetStatement()
}()
if session.statement.LastError != nil {
return session.statement.LastError
}
@ -64,15 +70,15 @@ func (session *Session) BufferSize(size int) *Session {
}
func (session *Session) bufferIterate(bean interface{}, fun IterFunc) error {
var bufferSize = session.statement.BufferSize
var pLimitN = session.statement.LimitN
bufferSize := session.statement.BufferSize
pLimitN := session.statement.LimitN
if pLimitN != nil && bufferSize > *pLimitN {
bufferSize = *pLimitN
}
var start = session.statement.Start
start := session.statement.Start
v := utils.ReflectValue(bean)
sliceType := reflect.SliceOf(v.Type())
var idx = 0
idx := 0
session.autoResetStatement = false
defer func() {
session.autoResetStatement = true

View File

@ -311,3 +311,8 @@ func (session *Session) Import(r io.Reader) ([]sql.Result, error) {
return results, lastError
}
func (session *Session) IndexHint(op, forType, indexerOrColName string) *Session {
session.statement.IndexHint(op, forType, indexerOrColName)
return session
}