Chore: Fix SQL related Go variable naming (#28887)

* Chore: Fix variable naming

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-11-11 06:21:08 +01:00
committed by GitHub
parent 7abf0506b1
commit b5379c5335
68 changed files with 377 additions and 376 deletions

View File

@ -11,38 +11,38 @@ import (
"xorm.io/xorm"
)
type Mysql struct {
type MySQLDialect struct {
BaseDialect
}
func NewMysqlDialect(engine *xorm.Engine) Dialect {
d := Mysql{}
d := MySQLDialect{}
d.BaseDialect.dialect = &d
d.BaseDialect.engine = engine
d.BaseDialect.driverName = MYSQL
d.BaseDialect.driverName = MySQL
return &d
}
func (db *Mysql) SupportEngine() bool {
func (db *MySQLDialect) SupportEngine() bool {
return true
}
func (db *Mysql) Quote(name string) string {
func (db *MySQLDialect) Quote(name string) string {
return "`" + name + "`"
}
func (db *Mysql) AutoIncrStr() string {
func (db *MySQLDialect) AutoIncrStr() string {
return "AUTO_INCREMENT"
}
func (db *Mysql) BooleanStr(value bool) string {
func (db *MySQLDialect) BooleanStr(value bool) string {
if value {
return "1"
}
return "0"
}
func (db *Mysql) SqlType(c *Column) string {
func (db *MySQLDialect) SQLType(c *Column) string {
var res string
switch c.Type {
case DB_Bool:
@ -91,7 +91,7 @@ func (db *Mysql) SqlType(c *Column) string {
return res
}
func (db *Mysql) UpdateTableSql(tableName string, columns []*Column) string {
func (db *MySQLDialect) UpdateTableSQL(tableName string, columns []*Column) string {
var statements = []string{}
statements = append(statements, "DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
@ -103,19 +103,19 @@ func (db *Mysql) UpdateTableSql(tableName string, columns []*Column) string {
return "ALTER TABLE " + db.Quote(tableName) + " " + strings.Join(statements, ", ") + ";"
}
func (db *Mysql) IndexCheckSql(tableName, indexName string) (string, []interface{}) {
func (db *MySQLDialect) IndexCheckSQL(tableName, indexName string) (string, []interface{}) {
args := []interface{}{tableName, indexName}
sql := "SELECT 1 FROM " + db.Quote("INFORMATION_SCHEMA") + "." + db.Quote("STATISTICS") + " WHERE " + db.Quote("TABLE_SCHEMA") + " = DATABASE() AND " + db.Quote("TABLE_NAME") + "=? AND " + db.Quote("INDEX_NAME") + "=?"
return sql, args
}
func (db *Mysql) ColumnCheckSql(tableName, columnName string) (string, []interface{}) {
func (db *MySQLDialect) ColumnCheckSQL(tableName, columnName string) (string, []interface{}) {
args := []interface{}{tableName, columnName}
sql := "SELECT 1 FROM " + db.Quote("INFORMATION_SCHEMA") + "." + db.Quote("COLUMNS") + " WHERE " + db.Quote("TABLE_SCHEMA") + " = DATABASE() AND " + db.Quote("TABLE_NAME") + "=? AND " + db.Quote("COLUMN_NAME") + "=?"
return sql, args
}
func (db *Mysql) CleanDB() error {
func (db *MySQLDialect) CleanDB() error {
tables, err := db.engine.DBMetas()
if err != nil {
return err
@ -140,7 +140,7 @@ func (db *Mysql) CleanDB() error {
// TruncateDBTables truncates all the tables.
// A special case is the dashboard_acl table where we keep the default permissions.
func (db *Mysql) TruncateDBTables() error {
func (db *MySQLDialect) TruncateDBTables() error {
tables, err := db.engine.DBMetas()
if err != nil {
return err
@ -168,7 +168,7 @@ func (db *Mysql) TruncateDBTables() error {
return nil
}
func (db *Mysql) isThisError(err error, errcode uint16) bool {
func (db *MySQLDialect) isThisError(err error, errcode uint16) bool {
if driverErr, ok := err.(*mysql.MySQLError); ok {
if driverErr.Number == errcode {
return true
@ -178,17 +178,17 @@ func (db *Mysql) isThisError(err error, errcode uint16) bool {
return false
}
func (db *Mysql) IsUniqueConstraintViolation(err error) bool {
func (db *MySQLDialect) IsUniqueConstraintViolation(err error) bool {
return db.isThisError(err, mysqlerr.ER_DUP_ENTRY)
}
func (db *Mysql) ErrorMessage(err error) string {
func (db *MySQLDialect) ErrorMessage(err error) string {
if driverErr, ok := err.(*mysql.MySQLError); ok {
return driverErr.Message
}
return ""
}
func (db *Mysql) IsDeadlock(err error) bool {
func (db *MySQLDialect) IsDeadlock(err error) bool {
return db.isThisError(err, mysqlerr.ER_LOCK_DEADLOCK)
}