Pass BOOL values as real types (int/bool) instead of strings to SQL parameters. (#101961)

* Pass BOOL values as real types (int/bool) instead of strings to SQL parameters.

Fixes following integration tests when running with Spanner:
* TestIntegrationDataAccess
    * GetDataSourcesByType/Get_prunable_data_sources
* TestIntegrationUserAuthToken:
    * expires_correctly
    * can_properly_rotate_tokens
    *  keeps_prev_token_valid_for_1_minute_after_it_is_confirmed

* Fix more places where "true" or "false" string was passed as query parameter instead of bool value.

* Removed unit test because it brought unwanted dependencies on xorm into multiple modules.
This commit is contained in:
Peter Štibraný
2025-03-12 15:40:11 +01:00
committed by GitHub
parent d1a1c07bdd
commit f3df64b7f4
17 changed files with 58 additions and 22 deletions
@@ -29,6 +29,10 @@ type Dialect interface {
SupportEngine() bool
LikeStr() string
Default(col *Column) string
// BooleanValue can be used as an argument in SELECT or INSERT statements. For constructing
// raw SQL queries, please use BooleanStr instead.
BooleanValue(bool) any
// BooleanStr should only be used to construct SQL statements (strings). For arguments to queries, use BooleanValue instead.
BooleanStr(bool) string
DateTimeFunc(string) string
BatchSize() int
@@ -9,6 +9,7 @@ import (
"github.com/VividCortex/mysqlerr"
"github.com/go-sql-driver/mysql"
"xorm.io/xorm"
)
@@ -35,6 +36,13 @@ func (db *MySQLDialect) AutoIncrStr() string {
return "AUTO_INCREMENT"
}
func (db *MySQLDialect) BooleanValue(value bool) interface{} {
if value {
return 1
}
return 0
}
func (db *MySQLDialect) BooleanStr(value bool) string {
if value {
return "1"
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/lib/pq"
"xorm.io/xorm"
)
@@ -38,6 +39,10 @@ func (db *PostgresDialect) AutoIncrStr() string {
return ""
}
func (db *PostgresDialect) BooleanValue(value bool) any {
return value
}
func (db *PostgresDialect) BooleanStr(value bool) string {
return strconv.FormatBool(value)
}
@@ -55,6 +55,11 @@ func (s *SpannerDialect) SQLType(col *Column) string {
}
func (s *SpannerDialect) BatchSize() int { return 1000 }
func (s *SpannerDialect) BooleanValue(b bool) any {
return b
}
func (s *SpannerDialect) BooleanStr(b bool) string {
if b {
return "true"
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/mattn/go-sqlite3"
"xorm.io/xorm"
)
@@ -32,6 +33,13 @@ func (db *SQLite3) AutoIncrStr() string {
return "AUTOINCREMENT"
}
func (db *SQLite3) BooleanValue(value bool) any {
if value {
return 1
}
return 0
}
func (db *SQLite3) BooleanStr(value bool) string {
if value {
return "1"