Skip to content

Commit

Permalink
Fix mssql quote (#1535)
Browse files Browse the repository at this point in the history
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 <tkusana@morisawa.co.jp>
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 <guillep2k@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
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 <guillep2k@noreply.gitea.io>
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 <guillep2k@users.noreply.github.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
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
  • Loading branch information
lunny committed Feb 24, 2020
1 parent bf25a77 commit a90b7a4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
7 changes: 5 additions & 2 deletions dialects/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (db *Base) CreateTableIfNotExists(table *Table, tableName, storeEngine, cha
}*/

func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string {
quotes := db.dialect.Quote("")
quote := db.dialect.Quote
var unique string
var idxName string
Expand All @@ -272,7 +273,7 @@ func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string {
idxName = index.XName(tableName)
return fmt.Sprintf("CREATE%s INDEX %v ON %v (%v)", unique,
quote(idxName), quote(tableName),
quote(strings.Join(index.Cols, quote(","))))
quote(strings.Join(index.Cols, fmt.Sprintf("%c,%c", quotes[1], quotes[0]))))
}

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

quotes := b.dialect.Quote("")

if len(table.ColumnsSeq()) > 0 {
pkList := table.PrimaryKeys

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

if len(pkList) > 1 {
sql += "PRIMARY KEY ( "
sql += b.dialect.Quote(strings.Join(pkList, b.dialect.Quote(",")))
sql += b.dialect.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
sql += " ), "
}

Expand Down
2 changes: 1 addition & 1 deletion dialects/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (db *mssql) IsReserved(name string) bool {
}

func (db *mssql) Quote(name string) string {
return "\"" + name + "\""
return "[" + name + "]"
}

func (db *mssql) SupportEngine() bool {
Expand Down
7 changes: 4 additions & 3 deletions dialects/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,13 @@ func (db *mysql) GetIndexes(tableName string) (map[string]*schemas.Index, error)
}

func (db *mysql) CreateTableSQL(table *schemas.Table, tableName, storeEngine, charset string) string {
var sql string
sql = "CREATE TABLE IF NOT EXISTS "
var sql = "CREATE TABLE IF NOT EXISTS "
if tableName == "" {
tableName = table.Name
}

quotes := db.Quote("")

sql += db.Quote(tableName)
sql += " ("

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

if len(pkList) > 1 {
sql += "PRIMARY KEY ( "
sql += db.Quote(strings.Join(pkList, db.Quote(",")))
sql += db.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
sql += " ), "
}

Expand Down
7 changes: 4 additions & 3 deletions dialects/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,7 @@ func (db *oracle) DropTableSQL(tableName string) string {
}

func (db *oracle) CreateTableSQL(table *schemas.Table, tableName, storeEngine, charset string) string {
var sql string
sql = "CREATE TABLE "
var sql = "CREATE TABLE "
if tableName == "" {
tableName = table.Name
}
Expand All @@ -598,9 +597,11 @@ func (db *oracle) CreateTableSQL(table *schemas.Table, tableName, storeEngine, c
sql += ", "
}

quotes := db.Quote("")

if len(pkList) > 0 {
sql += "PRIMARY KEY ( "
sql += db.Quote(strings.Join(pkList, db.Quote(",")))
sql += db.Quote(strings.Join(pkList, fmt.Sprintf("%c,%c", quotes[1], quotes[0])))
sql += " ), "
}

Expand Down
10 changes: 5 additions & 5 deletions schemas/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type Index struct {
Cols []string
}

// NewIndex new an index object
func NewIndex(name string, indexType int) *Index {
return &Index{true, name, indexType, make([]string, 0)}
}

func (index *Index) XName(tableName string) string {
if !strings.HasPrefix(index.Name, "UQE_") &&
!strings.HasPrefix(index.Name, "IDX_") {
Expand Down Expand Up @@ -65,8 +70,3 @@ func (index *Index) Equal(dst *Index) bool {
}
return true
}

// NewIndex new an index object
func NewIndex(name string, indexType int) *Index {
return &Index{true, name, indexType, make([]string, 0)}
}
20 changes: 8 additions & 12 deletions schemas/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ type Table struct {
Comment string
}

func (table *Table) Columns() []*Column {
return table.columns
}

func (table *Table) ColumnsSeq() []string {
return table.columnsSeq
}

func NewEmptyTable() *Table {
return NewTable("", nil)
}
Expand All @@ -54,9 +46,16 @@ func NewTable(name string, t reflect.Type) *Table {
}
}

func (table *Table) Columns() []*Column {
return table.columns
}

func (table *Table) ColumnsSeq() []string {
return table.columnsSeq
}

func (table *Table) columnsByName(name string) []*Column {
n := len(name)

for k := range table.columnsMap {
if len(k) != n {
continue
Expand All @@ -69,9 +68,7 @@ func (table *Table) columnsByName(name string) []*Column {
}

func (table *Table) GetColumn(name string) *Column {

cols := table.columnsByName(name)

if cols != nil {
return cols[0]
}
Expand All @@ -81,7 +78,6 @@ func (table *Table) GetColumn(name string) *Column {

func (table *Table) GetColumnIdx(name string, idx int) *Column {
cols := table.columnsByName(name)

if cols != nil && idx < len(cols) {
return cols[idx]
}
Expand Down
6 changes: 4 additions & 2 deletions session_find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func TestJoinLimit(t *testing.T) {

func assertSync(t *testing.T, beans ...interface{}) {
for _, bean := range beans {
assert.NoError(t, testEngine.DropTables(bean))
assert.NoError(t, testEngine.Sync2(bean))
t.Run(testEngine.TableName(bean, true), func(t *testing.T) {
assert.NoError(t, testEngine.DropTables(bean))
assert.NoError(t, testEngine.Sync2(bean))
})
}
}

Expand Down

0 comments on commit a90b7a4

Please sign in to comment.