qrz/vendor/xorm.io/xorm/internal/statements/args.go

57 lines
1.2 KiB
Go
Raw Normal View History

2020-07-19 19:32:22 +02:00
// 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 (
"xorm.io/builder"
"xorm.io/xorm/schemas"
)
2021-08-30 19:45:06 +02:00
// WriteArg writes an arg
2020-07-19 19:32:22 +02:00
func (statement *Statement) WriteArg(w *builder.BytesWriter, arg interface{}) error {
switch argv := arg.(type) {
case *builder.Builder:
if _, err := w.WriteString("("); err != nil {
return err
}
if err := argv.WriteTo(w); err != nil {
return err
}
if _, err := w.WriteString(")"); err != nil {
return err
}
default:
2022-07-16 11:43:41 +02:00
if err := w.WriteByte('?'); err != nil {
return err
}
if v, ok := arg.(bool); ok && statement.dialect.URI().DBType == schemas.MSSQL {
if v {
w.Append(1)
2020-07-19 19:32:22 +02:00
} else {
2022-07-16 11:43:41 +02:00
w.Append(0)
2020-07-19 19:32:22 +02:00
}
} else {
2022-07-16 11:43:41 +02:00
w.Append(arg)
2020-07-19 19:32:22 +02:00
}
}
return nil
}
2021-08-30 19:45:06 +02:00
// WriteArgs writes args
2020-07-19 19:32:22 +02:00
func (statement *Statement) WriteArgs(w *builder.BytesWriter, args []interface{}) error {
for i, arg := range args {
if err := statement.WriteArg(w, arg); err != nil {
return err
}
if i+1 != len(args) {
if _, err := w.WriteString(","); err != nil {
return err
}
}
}
return nil
}