@@ -177,6 +177,7 @@ func (engine *Engine) SupportInsertMany() bool {
177
177
178
178
// QuoteStr Engine's database use which character as quote.
179
179
// mysql, sqlite use ` and postgres use "
180
+ // Deprecated, use Quote() instead
180
181
func (engine * Engine ) QuoteStr () string {
181
182
return engine .dialect .QuoteStr ()
182
183
}
@@ -196,13 +197,23 @@ func (engine *Engine) Quote(value string) string {
196
197
return value
197
198
}
198
199
199
- if string (value [0 ]) == engine .dialect .QuoteStr () || value [0 ] == '`' {
200
+ dummy := engine .dialect .Quote ("" )
201
+ prefix , suffix := dummy [0 ], dummy [1 ]
202
+
203
+ if len (dummy ) != 2 || value [0 ] == prefix || value [0 ] == '`' { // no quote
200
204
return value
205
+ } else {
206
+ raw := []byte {prefix }
207
+ for i := 0 ; i < len (value ); i ++ {
208
+ if value [i ] == '.' {
209
+ raw = append (raw , suffix , '.' , prefix )
210
+ } else {
211
+ raw = append (raw , value [i ])
212
+ }
213
+ }
214
+ raw = append (raw , suffix )
215
+ return string (raw )
201
216
}
202
-
203
- value = strings .Replace (value , "." , engine .dialect .QuoteStr ()+ "." + engine .dialect .QuoteStr (), - 1 )
204
-
205
- return engine .dialect .QuoteStr () + value + engine .dialect .QuoteStr ()
206
217
}
207
218
208
219
// QuoteTo quotes string and writes into the buffer
@@ -216,20 +227,29 @@ func (engine *Engine) QuoteTo(buf *builder.StringBuilder, value string) {
216
227
return
217
228
}
218
229
219
- if string (value [0 ]) == engine .dialect .QuoteStr () || value [0 ] == '`' {
220
- buf .WriteString (value )
230
+ dummy := engine .dialect .Quote ("" )
231
+ prefix , suffix := dummy [0 ], dummy [1 ]
232
+
233
+ if len (dummy ) != 2 || value [0 ] == prefix || value [0 ] == '`' { // no quote
234
+ _ , _ = buf .WriteString (value )
221
235
return
236
+ } else {
237
+ _ = buf .WriteByte (prefix )
238
+ for i := 0 ; i < len (value ); i ++ {
239
+ if value [i ] == '.' {
240
+ _ = buf .WriteByte (suffix )
241
+ _ = buf .WriteByte ('.' )
242
+ _ = buf .WriteByte (prefix )
243
+ } else {
244
+ _ = buf .WriteByte (value [i ])
245
+ }
246
+ }
247
+ _ = buf .WriteByte (suffix )
222
248
}
223
-
224
- value = strings .Replace (value , "." , engine .dialect .QuoteStr ()+ "." + engine .dialect .QuoteStr (), - 1 )
225
-
226
- buf .WriteString (engine .dialect .QuoteStr ())
227
- buf .WriteString (value )
228
- buf .WriteString (engine .dialect .QuoteStr ())
229
249
}
230
250
231
251
func (engine * Engine ) quote (sql string ) string {
232
- return engine .dialect .QuoteStr () + sql + engine . dialect . QuoteStr ( )
252
+ return engine .dialect .Quote ( sql )
233
253
}
234
254
235
255
// SqlType will be deprecated, please use SQLType instead
@@ -1581,7 +1601,7 @@ func (engine *Engine) formatColTime(col *core.Column, t time.Time) (v interface{
1581
1601
func (engine * Engine ) formatTime (sqlTypeName string , t time.Time ) (v interface {}) {
1582
1602
switch sqlTypeName {
1583
1603
case core .Time :
1584
- s := t .Format ("2006-01-02 15:04:05" ) //time.RFC3339
1604
+ s := t .Format ("2006-01-02 15:04:05" ) // time.RFC3339
1585
1605
v = s [11 :19 ]
1586
1606
case core .Date :
1587
1607
v = t .Format ("2006-01-02" )
0 commit comments