Repository: go-gorm/gorm
Pull request #4615 (2021-08-16 07:11:25)

Bump gorm.io/driver/mysql from 1.1.1 to 1.1.2 in /tests
Bumps [gorm.io/driver/mysql](https://github.com/go-gorm/mysql) from 1.1.1 to 1.1.2.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/go-gorm/mysql/commit/7ed9f9437521c412ad555b0d266e998951bf54ac"><code>7ed9f94</code></a> optimize DataTypeOf func and other code optimize for mysql package (<a href="https://github-redirect.dependabot.com/go-gorm/mysql/issues/43">#43</a>)</li>
<li><a href="https://github.com/go-gorm/mysql/commit/99d7c92bd703b320e02d655c9f84b3ea1049688e"><code>99d7c92</code></a> Bump gorm.io/gorm from 1.21.9 to 1.21.12 (<a href="https://github-redirect.dependabot.com/go-gorm/mysql/issues/40">#40</a>)</li>
<li><a href="https://github.com/go-gorm/mysql/commit/6b49f8ee5f74d26519c960fe0b36f2435336fa33"><code>6b49f8e</code></a> Refactor QuoteTo</li>
<li><a href="https://github.com/go-gorm/mysql/commit/23717574f4cf0886dfe17bf0cc12f942e350d6a3"><code>2371757</code></a> feat: escape backticks (<a href="https://github-redirect.dependabot.com/go-gorm/mysql/issues/42">#42</a>)</li>
<li><a href="https://github.com/go-gorm/mysql/commit/231fa72aaee3e36a38ae1c7292877aa276e74f2b"><code>231fa72</code></a> Update README</li>
<li>See full diff in <a href="https://github.com/go-gorm/mysql/compare/v1.1.1...v1.1.2">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=gorm.io/driver/mysql&package-manager=go_modules&previous-version=1.1.1&new-version=1.1.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/finisher_api.go b/finisher_api.go
index 537c955..34e1596 100644
--- a/finisher_api.go
+++ b/finisher_api.go
@@ -390,7 +390,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
 		if len(tx.Statement.Selects) == 1 {
 			dbName := tx.Statement.Selects[0]
 			fields := strings.FieldsFunc(dbName, utils.IsValidDBNameChar)
-			if len(fields) == 1 || (len(fields) == 3 && strings.ToUpper(fields[1]) == "AS") {
+			if len(fields) == 1 || (len(fields) == 3 && (strings.ToUpper(fields[1]) == "AS" || fields[1] == ".")) {
 				if tx.Statement.Parse(tx.Statement.Model) == nil {
 					if f := tx.Statement.Schema.LookUpField(dbName); f != nil {
 						dbName = f.DBName
diff --git a/statement.go b/statement.go
index 8b682c8..93b78c1 100644
--- a/statement.go
+++ b/statement.go
@@ -129,6 +129,8 @@ func (stmt *Statement) QuoteTo(writer clause.Writer, field interface{}) {
 			stmt.QuoteTo(writer, d)
 		}
 		writer.WriteByte(')')
+	case clause.Expr:
+		v.Build(stmt)
 	case string:
 		stmt.DB.Dialector.QuoteTo(writer, v)
 	case []string:


Test patch:
diff --git a/clause/expression_test.go b/clause/expression_test.go
index 0ccd077..0507486 100644
--- a/clause/expression_test.go
+++ b/clause/expression_test.go
@@ -156,6 +156,18 @@ func TestExpression(t *testing.T) {
 		},
 		ExpectedVars: []interface{}{"a", "b"},
 		Result:       "`column-name` NOT IN (?,?)",
+	}, {
+		Expressions: []clause.Expression{
+			clause.Eq{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Name: "id"}}}, Value: 100},
+		},
+		ExpectedVars: []interface{}{100},
+		Result:       "SUM(`id`) = ?",
+	}, {
+		Expressions: []clause.Expression{
+			clause.Gte{Column: clause.Expr{SQL: "SUM(?)", Vars: []interface{}{clause.Column{Table: "users", Name: "id"}}}, Value: 100},
+		},
+		ExpectedVars: []interface{}{100},
+		Result:       "SUM(`users`.`id`) >= ?",
 	}}
 
 	for idx, result := range results {
diff --git a/tests/go.mod b/tests/go.mod
index b623b36..278ad5b 100644
--- a/tests/go.mod
+++ b/tests/go.mod
@@ -6,11 +6,11 @@ require (
 	github.com/google/uuid v1.3.0
 	github.com/jinzhu/now v1.1.2
 	github.com/lib/pq v1.10.2
-	gorm.io/driver/mysql v1.1.1
+	gorm.io/driver/mysql v1.1.2
 	gorm.io/driver/postgres v1.1.0
 	gorm.io/driver/sqlite v1.1.4
 	gorm.io/driver/sqlserver v1.0.7
-	gorm.io/gorm v1.21.12
+	gorm.io/gorm v1.21.13
 )
 
 replace gorm.io/gorm => ../