Skip to content

Commit a90b7a4

Browse files
committed
Fix mssql quote (#1535)
Fix some quotes Fix mssql quote Merge core package back into the main repository and split into serval sub packages. (#1543) Fix test Improve fmt update go.mod Move core as a sub package Reviewed-on: https://gitea.com/xorm/xorm/pulls/1543 Fix int time deleted bug (#1539) Fix panic Fix test Fix test for mssql time Add sql type check on deleted cond Fix int time deleted bug Reviewed-on: https://gitea.com/xorm/xorm/pulls/1539 Add test for mysql8.0 (#1538) Fix pk order on test Add test for mysql8.0 Reviewed-on: https://gitea.com/xorm/xorm/pulls/1538 Add test for join limit (#1536) Add test for join limit Reviewed-on: https://gitea.com/xorm/xorm/pulls/1536 Improve drone (#1537) Fix drone Improve drone * use traditional positional parameters on inser... Reviewed-on: https://gitea.com/xorm/xorm/pulls/1537 Fix slice of struct not cache bug (go-xorm#895) Fix failure caused by nil bean Judge both type of struct and pointer in case of out-of-range Fix issue go-xorm#894 Add test for join subquery (#1528) Fix test Fix subquery with schema Add test for join subquery Add makefile (#1531) Fix drone Fix ci Add deps Improve drone Fix envs Add makefile Reviewed-on: https://gitea.com/xorm/xorm/pulls/1531 Add password for postgres drone image (#1530) Add password for postgres drone image Reviewed-on: https://gitea.com/xorm/xorm/pulls/1530 format time when sqlTypeName is core.Varchar (go-xorm#1026) fix time test add test for time format sign codes according to contributing rules. format time when sqlTypeName is core.Varchar. Same with core.DateTime or core.TimeStamp Add test for second insert error (#1527) Add test for second insert error Reviewed-on: https://gitea.com/xorm/xorm/pulls/1527 Add tests for table name (#1517) add tests for table name Fix test (#1526) Fix test Reviewed-on: https://gitea.com/xorm/xorm/pulls/1526 Fix test (#1526) Fix test Reviewed-on: https://gitea.com/xorm/xorm/pulls/1526 Fix wrong warning log on autoincrement column when sync table (#1525) improve doc Fix wrong warning log on autoincrement column when sync table Reviewed-on: https://gitea.com/xorm/xorm/pulls/1525 Fixed Join strings on func Exist (#1520) fix test fixed Join strings on func Exist Co-authored-by: Tomofumi Kusana <[email protected]> Reviewed-on: https://gitea.com/xorm/xorm/pulls/1520 For nullable columns, store nil values as NULL (go-xorm#531) Merge branch 'master' into jcsalem/fix/nil_ptr_is_nullable fix bug when buffersize with iterate (go-xorm#941) Merge branch 'master' into lunny/fix_buffer_iterate Exclude schema from index name (#1505) Merge branch 'master' into fix-schema-idx SetExpr support more go types (#1499) Improve tests SetExpr support more go types fix vet fix drone lint remove go1.10 test on drone Reviewed-on: https://gitea.com/xorm/xorm/pulls/1499 fix vet fix drone lint remove go1.10 test on drone Exclude schema from the index name Co-authored-by: Guillermo Prandi <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Reviewed-on: https://gitea.com/xorm/xorm/pulls/1505 fix test fix bug fix bug when buffersize with iterate SetExpr support more go types (#1499) Improve tests SetExpr support more go types fix vet fix drone lint remove go1.10 test on drone Reviewed-on: https://gitea.com/xorm/xorm/pulls/1499 fix vet fix drone lint remove go1.10 test on drone Fix update with Alias (go-xorm#1455) Co-authored-by: Guillermo Prandi <[email protected]> Reviewed-on: https://gitea.com/xorm/xorm/pulls/941 fix update map with version (go-xorm#1448) fix test fix update map with version SetExpr support more go types (#1499) Improve tests SetExpr support more go types fix vet fix drone lint remove go1.10 test on drone Reviewed-on: https://gitea.com/xorm/xorm/pulls/1499 fix vet fix drone lint remove go1.10 test on drone Fix update with Alias (go-xorm#1455) Reviewed-on: https://gitea.com/xorm/xorm/pulls/1448 Exclude schema from index name (#1505) Merge branch 'master' into fix-schema-idx SetExpr support more go types (#1499) Improve tests SetExpr support more go types fix vet fix drone lint remove go1.10 test on drone Reviewed-on: https://gitea.com/xorm/xorm/pulls/1499 fix vet fix drone lint remove go1.10 test on drone Exclude schema from the index name Co-authored-by: Guillermo Prandi <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Reviewed-on: https://gitea.com/xorm/xorm/pulls/1505 SetExpr support more go types (#1499) Improve tests SetExpr support more go types fix vet fix drone lint remove go1.10 test on drone Reviewed-on: https://gitea.com/xorm/xorm/pulls/1499 For nullable columns, store nil values as NULL fix vet fix drone lint remove go1.10 test on drone Fix update with Alias (go-xorm#1455) Improve ci tests (#1477) Rewrite Engine.QuoteTo() to accept multi-part identifiers (#1476) Support local sql log (go-xorm#1338) Fix go mod and update version (go-xorm#1460) Move github.com/go-xorm/xorm to xorm.io/xorm (go-xorm#1459) add support custom type Nullfloat64 (go-xorm#1450) fix bug when query map condtion with no quo... Reviewed-on: https://gitea.com/xorm/xorm/pulls/1535
1 parent bf25a77 commit a90b7a4

File tree

7 files changed

+31
-28
lines changed

7 files changed

+31
-28
lines changed

dialects/dialect.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func (db *Base) CreateTableIfNotExists(table *Table, tableName, storeEngine, cha
263263
}*/
264264

265265
func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string {
266+
quotes := db.dialect.Quote("")
266267
quote := db.dialect.Quote
267268
var unique string
268269
var idxName string
@@ -272,7 +273,7 @@ func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string {
272273
idxName = index.XName(tableName)
273274
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
274275
quote(idxName), quote(tableName),
275-
quote(strings.Join(index.Cols, quote(","))))
276+
quote(strings.Join(index.Cols, fmt.Sprintf("%c,%c", quotes[1], quotes[0]))))
276277
}
277278

278279
func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string {
@@ -300,6 +301,8 @@ func (b *Base) CreateTableSQL(table *schemas.Table, tableName, storeEngine, char
300301
sql += b.dialect.Quote(tableName)
301302
sql += " ("
302303

304+
quotes := b.dialect.Quote("")
305+
303306
if len(table.ColumnsSeq()) > 0 {
304307
pkList := table.PrimaryKeys
305308

@@ -319,7 +322,7 @@ func (b *Base) CreateTableSQL(table *schemas.Table, tableName, storeEngine, char
319322

320323
if len(pkList) > 1 {
321324
sql += "PRIMARY KEY ( "
322-
sql += b.dialect.Quote(strings.Join(pkList, b.dialect.Quote(",")))
325+
sql += b.dialect.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
323326
sql += " ), "
324327
}
325328

dialects/mssql.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func (db *mssql) IsReserved(name string) bool {
287287
}
288288

289289
func (db *mssql) Quote(name string) string {
290-
return "\"" + name + "\""
290+
return "[" + name + "]"
291291
}
292292

293293
func (db *mssql) SupportEngine() bool {

dialects/mysql.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,13 @@ func (db *mysql) GetIndexes(tableName string) (map[string]*schemas.Index, error)
507507
}
508508

509509
func (db *mysql) CreateTableSQL(table *schemas.Table, tableName, storeEngine, charset string) string {
510-
var sql string
511-
sql = "CREATE TABLE IF NOT EXISTS "
510+
var sql = "CREATE TABLE IF NOT EXISTS "
512511
if tableName == "" {
513512
tableName = table.Name
514513
}
515514

515+
quotes := db.Quote("")
516+
516517
sql += db.Quote(tableName)
517518
sql += " ("
518519

@@ -535,7 +536,7 @@ func (db *mysql) CreateTableSQL(table *schemas.Table, tableName, storeEngine, ch
535536

536537
if len(pkList) > 1 {
537538
sql += "PRIMARY KEY ( "
538-
sql += db.Quote(strings.Join(pkList, db.Quote(",")))
539+
sql += db.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
539540
sql += " ), "
540541
}
541542

dialects/oracle.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,7 @@ func (db *oracle) DropTableSQL(tableName string) string {
577577
}
578578

579579
func (db *oracle) CreateTableSQL(table *schemas.Table, tableName, storeEngine, charset string) string {
580-
var sql string
581-
sql = "CREATE TABLE "
580+
var sql = "CREATE TABLE "
582581
if tableName == "" {
583582
tableName = table.Name
584583
}
@@ -598,9 +597,11 @@ func (db *oracle) CreateTableSQL(table *schemas.Table, tableName, storeEngine, c
598597
sql += ", "
599598
}
600599

600+
quotes := db.Quote("")
601+
601602
if len(pkList) > 0 {
602603
sql += "PRIMARY KEY ( "
603-
sql += db.Quote(strings.Join(pkList, db.Quote(",")))
604+
sql += db.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
604605
sql += " ), "
605606
}
606607

schemas/index.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ type Index struct {
2323
Cols []string
2424
}
2525

26+
// NewIndex new an index object
27+
func NewIndex(name string, indexType int) *Index {
28+
return &Index{true, name, indexType, make([]string, 0)}
29+
}
30+
2631
func (index *Index) XName(tableName string) string {
2732
if !strings.HasPrefix(index.Name, "UQE_") &&
2833
!strings.HasPrefix(index.Name, "IDX_") {
@@ -65,8 +70,3 @@ func (index *Index) Equal(dst *Index) bool {
6570
}
6671
return true
6772
}
68-
69-
// NewIndex new an index object
70-
func NewIndex(name string, indexType int) *Index {
71-
return &Index{true, name, indexType, make([]string, 0)}
72-
}

schemas/table.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ type Table struct {
3030
Comment string
3131
}
3232

33-
func (table *Table) Columns() []*Column {
34-
return table.columns
35-
}
36-
37-
func (table *Table) ColumnsSeq() []string {
38-
return table.columnsSeq
39-
}
40-
4133
func NewEmptyTable() *Table {
4234
return NewTable("", nil)
4335
}
@@ -54,9 +46,16 @@ func NewTable(name string, t reflect.Type) *Table {
5446
}
5547
}
5648

49+
func (table *Table) Columns() []*Column {
50+
return table.columns
51+
}
52+
53+
func (table *Table) ColumnsSeq() []string {
54+
return table.columnsSeq
55+
}
56+
5757
func (table *Table) columnsByName(name string) []*Column {
5858
n := len(name)
59-
6059
for k := range table.columnsMap {
6160
if len(k) != n {
6261
continue
@@ -69,9 +68,7 @@ func (table *Table) columnsByName(name string) []*Column {
6968
}
7069

7170
func (table *Table) GetColumn(name string) *Column {
72-
7371
cols := table.columnsByName(name)
74-
7572
if cols != nil {
7673
return cols[0]
7774
}
@@ -81,7 +78,6 @@ func (table *Table) GetColumn(name string) *Column {
8178

8279
func (table *Table) GetColumnIdx(name string, idx int) *Column {
8380
cols := table.columnsByName(name)
84-
8581
if cols != nil && idx < len(cols) {
8682
return cols[idx]
8783
}

session_find_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ func TestJoinLimit(t *testing.T) {
6464

6565
func assertSync(t *testing.T, beans ...interface{}) {
6666
for _, bean := range beans {
67-
assert.NoError(t, testEngine.DropTables(bean))
68-
assert.NoError(t, testEngine.Sync2(bean))
67+
t.Run(testEngine.TableName(bean, true), func(t *testing.T) {
68+
assert.NoError(t, testEngine.DropTables(bean))
69+
assert.NoError(t, testEngine.Sync2(bean))
70+
})
6971
}
7072
}
7173

0 commit comments

Comments
 (0)