Browse Source

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: #1531

Add password for postgres drone image (#1530)

Add password for postgres drone image

Reviewed-on: #1530

format time when sqlTypeName is core.Varchar (#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: #1527

Add tests for table name (#1517)

add tests for table name

Fix test (#1526)

Fix test

Reviewed-on: #1526

Fix test (#1526)

Fix test

Reviewed-on: #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: #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: #1520

For nullable columns, store nil values as NULL (#531)

Merge branch 'master' into jcsalem/fix/nil_ptr_is_nullable

fix bug when buffersize with iterate (#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: #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: #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: #1499

fix vet

fix drone lint

remove go1.10 test on drone

Fix update with Alias (#1455)

Co-authored-by: Guillermo Prandi <guillep2k@noreply.gitea.io>
Reviewed-on: #941

fix update map with version (#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: #1499

fix vet

fix drone lint

remove go1.10 test on drone

Fix update with Alias (#1455)

Reviewed-on: #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: #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: #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: #1499

For nullable columns, store nil values as NULL

fix vet

fix drone lint

remove go1.10 test on drone

Fix update with Alias (#1455)

Improve ci tests (#1477)

Rewrite Engine.QuoteTo() to accept multi-part identifiers (#1476)

Support local sql log (#1338)

Fix go mod and update version (#1460)

Move github.com/go-xorm/xorm to xorm.io/xorm (#1459)

add support custom type Nullfloat64 (#1450)

fix bug when query map condtion with no quote (#1449)

Don't warn when bool column default is 1 but not true (#1447)

* don't warn when bool column default is 1 but not true

* fix default case sensitive

Fix sync2 with custom table name (#1445)

* fix sync2 with custom table name

* fix bug on postgres

* fix bug on postgres

fix bug when update with setexpr (#1446)

add tidb tests on drone ci (#1444)

improve sync2 (#1443)

Fix wrong dbmetas (#1442)

* add tests for db metas

* add more tests

* fix bug on mssql

Fix default value parse bugs (#1437)

* fix default value

* fix default value tags

* fix postgres default

* fix default on postgres

* fix default on postgres

* fix mssql default

fix arg conversion (#1441)

* fix arg conversion

* fix bugs

* fix bug on postgres

* use traditional positional parameters on insert into select

* remove unnecessary tests

upgrade core (#1440)

add tests (#1439)

add go1.13 tests on drone (#1416)

Fix bug on insert where (#1436)

* fix bug on insert where

* fix bug

* fix lint

fix bug when insert multiple...
Reviewed-on: #1528
tags/v0.8.2
Lunny Xiao 1 month ago
parent
commit
9251a5165d
2 changed files with 19 additions and 3 deletions
  1. +10
    -2
      engine_table.go
  2. +9
    -1
      session_query_test.go

+ 10
- 2
engine_table.go View File

@@ -25,13 +25,21 @@ func (engine *Engine) tbNameWithSchema(v string) string {
return v
}

func isSubQuery(tbName string) bool {
const selStr = "select"
if len(tbName) <= len(selStr)+1 {
return false
}

return strings.EqualFold(tbName[:len(selStr)], selStr) || strings.EqualFold(tbName[:len(selStr)+1], "("+selStr)
}

// TableName returns table name with schema prefix if has
func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string {
tbName := engine.tbNameNoSchema(bean)
if len(includeSchema) > 0 && includeSchema[0] {
if len(includeSchema) > 0 && includeSchema[0] && !isSubQuery(tbName) {
tbName = engine.tbNameWithSchema(tbName)
}

return tbName
}



+ 9
- 1
session_query_test.go View File

@@ -371,10 +371,18 @@ func TestJoinWithSubQuery(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

tbName := testEngine.Quote(testEngine.TableName("join_with_sub_query_depart", true))
var querys []JoinWithSubQuery1
err = testEngine.Join("INNER", builder.Select("id").From(testEngine.Quote(testEngine.TableName("join_with_sub_query_depart", true))),
err = testEngine.Join("INNER", builder.Select("id").From(tbName),
"join_with_sub_query_depart.id = join_with_sub_query1.depart_id").Find(&querys)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(querys))
assert.EqualValues(t, q, querys[0])

querys = make([]JoinWithSubQuery1, 0, 1)
err = testEngine.Join("INNER", "(SELECT id FROM "+tbName+") join_with_sub_query_depart", "join_with_sub_query_depart.id = join_with_sub_query1.depart_id").
Find(&querys)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(querys))
assert.EqualValues(t, q, querys[0])
}

Loading…
Cancel
Save