let quote optional
This commit is contained in:
parent
6dd1a9db58
commit
91e61f3049
27
engine.go
27
engine.go
|
@ -23,6 +23,16 @@ import (
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// QuoteMode describes quote handle mode
|
||||||
|
type QuoteMode int
|
||||||
|
|
||||||
|
// All QuoteModes
|
||||||
|
const (
|
||||||
|
QuoteAddAlways QuoteMode = iota
|
||||||
|
QuoteNoAdd
|
||||||
|
//QuoteAddNonReserved
|
||||||
|
)
|
||||||
|
|
||||||
// Engine is the major struct of xorm, it means a database manager.
|
// Engine is the major struct of xorm, it means a database manager.
|
||||||
// Commonly, an application only need one engine
|
// Commonly, an application only need one engine
|
||||||
type Engine struct {
|
type Engine struct {
|
||||||
|
@ -45,8 +55,8 @@ type Engine struct {
|
||||||
DatabaseTZ *time.Location // The timezone of the database
|
DatabaseTZ *time.Location // The timezone of the database
|
||||||
|
|
||||||
disableGlobalCache bool
|
disableGlobalCache bool
|
||||||
|
|
||||||
tagHandlers map[string]tagHandler
|
tagHandlers map[string]tagHandler
|
||||||
|
QuoteMode QuoteMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowSQL show SQL statement or not on logger if log level is great than INFO
|
// ShowSQL show SQL statement or not on logger if log level is great than INFO
|
||||||
|
@ -123,6 +133,9 @@ func (engine *Engine) SupportInsertMany() bool {
|
||||||
// QuoteStr Engine's database use which character as quote.
|
// QuoteStr Engine's database use which character as quote.
|
||||||
// mysql, sqlite use ` and postgres use "
|
// mysql, sqlite use ` and postgres use "
|
||||||
func (engine *Engine) QuoteStr() string {
|
func (engine *Engine) QuoteStr() string {
|
||||||
|
if engine.QuoteMode == QuoteNoAdd {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return engine.dialect.QuoteStr()
|
return engine.dialect.QuoteStr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +150,9 @@ func (engine *Engine) Quote(value string) string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
value = strings.Replace(value, ".", engine.dialect.QuoteStr()+"."+engine.dialect.QuoteStr(), -1)
|
value = strings.Replace(value, ".", engine.QuoteStr()+"."+engine.QuoteStr(), -1)
|
||||||
|
|
||||||
return engine.dialect.QuoteStr() + value + engine.dialect.QuoteStr()
|
return engine.QuoteStr() + value + engine.QuoteStr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuoteTo quotes string and writes into the buffer
|
// QuoteTo quotes string and writes into the buffer
|
||||||
|
@ -158,15 +171,15 @@ func (engine *Engine) QuoteTo(buf *bytes.Buffer, value string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
value = strings.Replace(value, ".", engine.dialect.QuoteStr()+"."+engine.dialect.QuoteStr(), -1)
|
value = strings.Replace(value, ".", engine.QuoteStr()+"."+engine.QuoteStr(), -1)
|
||||||
|
|
||||||
buf.WriteString(engine.dialect.QuoteStr())
|
buf.WriteString(engine.QuoteStr())
|
||||||
buf.WriteString(value)
|
buf.WriteString(value)
|
||||||
buf.WriteString(engine.dialect.QuoteStr())
|
buf.WriteString(engine.QuoteStr())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) quote(sql string) string {
|
func (engine *Engine) quote(sql string) string {
|
||||||
return engine.dialect.QuoteStr() + sql + engine.dialect.QuoteStr()
|
return engine.QuoteStr() + sql + engine.QuoteStr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SqlType will be depracated, please use SQLType instead
|
// SqlType will be depracated, please use SQLType instead
|
||||||
|
|
|
@ -45,7 +45,6 @@ func TestColumnsStringGeneration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := statement.genColumnStr()
|
actual := statement.genColumnStr()
|
||||||
|
|
||||||
if actual != testCase.expected {
|
if actual != testCase.expected {
|
||||||
t.Errorf("[test #%d] Unexpected columns string:\nwant:\t%s\nhave:\t%s", ndx, testCase.expected, actual)
|
t.Errorf("[test #%d] Unexpected columns string:\nwant:\t%s\nhave:\t%s", ndx, testCase.expected, actual)
|
||||||
}
|
}
|
||||||
|
|
1
xorm.go
1
xorm.go
|
@ -86,6 +86,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||||
mutex: &sync.RWMutex{},
|
mutex: &sync.RWMutex{},
|
||||||
TagIdentifier: "xorm",
|
TagIdentifier: "xorm",
|
||||||
TZLocation: time.Local,
|
TZLocation: time.Local,
|
||||||
|
QuoteMode: QuoteAddAlways,
|
||||||
tagHandlers: defaultTagHandlers,
|
tagHandlers: defaultTagHandlers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue