Skip to content

Commit 4ca0766

Browse files
authored
Merge pull request #214 from swordqiu/hotfix/qj-dameng-compare-text-varchar-optimize
fix: dameng compare varchar with equal and long text with text_equal
2 parents b98e89d + 1c9b853 commit 4ca0766

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

ascii.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func (c *STableField) IsSearchable() bool {
3131
return c.spec.IsSearchable()
3232
}
3333

34+
func (c *STableField) GetWidth() int {
35+
return c.spec.GetWidth()
36+
}
37+
3438
func getTableField(f IQueryField) *STableField {
3539
if gotypes.IsNil(f) {
3640
return nil
@@ -47,10 +51,10 @@ func getTableField(f IQueryField) *STableField {
4751
}
4852
}
4953

50-
func IsFieldText(f IQueryField) bool {
54+
func IsLongFieldText(f IQueryField) bool {
5155
tf := getTableField(f)
5256
if tf != nil {
53-
return tf.IsText() && tf.IsSearchable()
57+
return tf.IsText() && tf.IsSearchable() && tf.GetWidth() == 0
5458
}
5559
return false
5660
}

backends/dameng/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (t *SDamengEqualsCondition) WhereClause() string {
3232
// Equals filter conditions
3333
func (dameng *SDamengBackend) Equals(f sqlchemy.IQueryField, v interface{}) sqlchemy.ICondition {
3434
// log.Debugf("field %s isFieldText: %v %#v", f.Name(), sqlchemy.IsFieldText(f), f)
35-
if sqlchemy.IsFieldText(f) {
35+
if sqlchemy.IsLongFieldText(f) {
3636
c := SDamengEqualsCondition{sqlchemy.NewTupleCondition(f, v)}
3737
return &c
3838
} else {

backends/dameng/query_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestQuery(t *testing.T) {
4949
t.Run("query selected fields varchar ", func(t *testing.T) {
5050
testReset()
5151
q := testTable.Query(testTable.Field("col0")).Equals("col0", "abce")
52-
want := `SELECT "t1"."col0" AS "col0" FROM "test" AS "t1" WHERE TEXT_EQUAL("t1"."col0" , ? )`
52+
want := `SELECT "t1"."col0" AS "col0" FROM "test" AS "t1" WHERE "t1"."col0" = ? `
5353
testGotWant(t, q.String(), want)
5454
})
5555

0 commit comments

Comments
 (0)