From d37b75442d894f5aadebcce60c0b57a75690f0f3 Mon Sep 17 00:00:00 2001 From: houseme Date: Mon, 7 Nov 2022 17:52:25 +0800 Subject: [PATCH] feat: modify sql count value int64 (#2266) --- database/gdb/gdb.go | 2 +- database/gdb/gdb_core.go | 4 ++-- database/gdb/gdb_core_transaction.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index 5e18cf220..a74f5fd56 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -118,7 +118,7 @@ type DB interface { GetOne(ctx context.Context, sql string, args ...interface{}) (Record, error) // See Core.GetOne. GetValue(ctx context.Context, sql string, args ...interface{}) (Value, error) // See Core.GetValue. GetArray(ctx context.Context, sql string, args ...interface{}) ([]Value, error) // See Core.GetArray. - GetCount(ctx context.Context, sql string, args ...interface{}) (int, error) // See Core.GetCount. + GetCount(ctx context.Context, sql string, args ...interface{}) (int64, error) // See Core.GetCount. GetScan(ctx context.Context, objPointer interface{}, sql string, args ...interface{}) error // See Core.GetScan. Union(unions ...*Model) *Model // See Core.Union. UnionAll(unions ...*Model) *Model // See Core.UnionAll. diff --git a/database/gdb/gdb_core.go b/database/gdb/gdb_core.go index 481da701e..2ca306318 100644 --- a/database/gdb/gdb_core.go +++ b/database/gdb/gdb_core.go @@ -241,7 +241,7 @@ func (c *Core) GetValue(ctx context.Context, sql string, args ...interface{}) (V } // GetCount queries and returns the count from database. -func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (int, error) { +func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (int64, error) { // If the query fields do not contain function "COUNT", // it replaces the sql string and adds the "COUNT" function to the fields. if !gregex.IsMatchString(`(?i)SELECT\s+COUNT\(.+\)\s+FROM`, sql) { @@ -251,7 +251,7 @@ func (c *Core) GetCount(ctx context.Context, sql string, args ...interface{}) (i if err != nil { return 0, err } - return value.Int(), nil + return value.Int64(), nil } // Union does "(SELECT xxx FROM xxx) UNION (SELECT xxx FROM xxx) ..." statement. diff --git a/database/gdb/gdb_core_transaction.go b/database/gdb/gdb_core_transaction.go index bf2d58f23..7d1539ffc 100644 --- a/database/gdb/gdb_core_transaction.go +++ b/database/gdb/gdb_core_transaction.go @@ -382,7 +382,7 @@ func (tx *TX) GetValue(sql string, args ...interface{}) (Value, error) { } // GetCount queries and returns the count from database. -func (tx *TX) GetCount(sql string, args ...interface{}) (int, error) { +func (tx *TX) GetCount(sql string, args ...interface{}) (int64, error) { if !gregex.IsMatchString(`(?i)SELECT\s+COUNT\(.+\)\s+FROM`, sql) { sql, _ = gregex.ReplaceString(`(?i)(SELECT)\s+(.+)\s+(FROM)`, `$1 COUNT($2) $3`, sql) } @@ -390,7 +390,7 @@ func (tx *TX) GetCount(sql string, args ...interface{}) (int, error) { if err != nil { return 0, err } - return value.Int(), nil + return value.Int64(), nil } // Insert does "INSERT INTO ..." statement for the table.