summaryrefslogtreecommitdiffstats
path: root/vendor/xorm.io/xorm/dialects/mysql.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-09-03 09:58:04 +0800
committerGitHub <noreply@github.com>2020-09-03 02:58:04 +0100
commit514201af5d2e81182c86306f414ced27c8602eb6 (patch)
tree346e37b7b1ac5531dcd7bb50a5a58b4f1d375a01 /vendor/xorm.io/xorm/dialects/mysql.go
parent702e98c5ec7b11f3c988d61dccbec71e1e69a8bd (diff)
downloadgitea-514201af5d2e81182c86306f414ced27c8602eb6.tar.gz
gitea-514201af5d2e81182c86306f414ced27c8602eb6.zip
Upgrade xorm to v1.0.4 (#12694)
Diffstat (limited to 'vendor/xorm.io/xorm/dialects/mysql.go')
-rw-r--r--vendor/xorm.io/xorm/dialects/mysql.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/vendor/xorm.io/xorm/dialects/mysql.go b/vendor/xorm.io/xorm/dialects/mysql.go
index f9a2e9434d..32e18a17cc 100644
--- a/vendor/xorm.io/xorm/dialects/mysql.go
+++ b/vendor/xorm.io/xorm/dialects/mysql.go
@@ -307,9 +307,17 @@ func (db *mysql) AddColumnSQL(tableName string, col *schemas.Column) string {
func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error) {
args := []interface{}{db.uri.DBName, tableName}
+ alreadyQuoted := "(INSTR(VERSION(), 'maria') > 0 && " +
+ "(SUBSTRING_INDEX(VERSION(), '.', 1) > 10 || " +
+ "(SUBSTRING_INDEX(VERSION(), '.', 1) = 10 && " +
+ "(SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) > 2 || " +
+ "(SUBSTRING_INDEX(SUBSTRING(VERSION(), 4), '.', 1) = 2 && " +
+ "SUBSTRING_INDEX(SUBSTRING(VERSION(), 6), '-', 1) >= 7)))))"
s := "SELECT `COLUMN_NAME`, `IS_NULLABLE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`," +
- " `COLUMN_KEY`, `EXTRA`,`COLUMN_COMMENT` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
- " ORDER BY `INFORMATION_SCHEMA`.`COLUMNS`.ORDINAL_POSITION"
+ " `COLUMN_KEY`, `EXTRA`, `COLUMN_COMMENT`, " +
+ alreadyQuoted + " AS NEEDS_QUOTE " +
+ "FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?" +
+ " ORDER BY `COLUMNS`.ORDINAL_POSITION"
rows, err := queryer.QueryContext(ctx, s, args...)
if err != nil {
@@ -324,8 +332,9 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
col.Indexes = make(map[string]int)
var columnName, isNullable, colType, colKey, extra, comment string
+ var alreadyQuoted bool
var colDefault *string
- err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment)
+ err = rows.Scan(&columnName, &isNullable, &colDefault, &colType, &colKey, &extra, &comment, &alreadyQuoted)
if err != nil {
return nil, nil, err
}
@@ -335,7 +344,7 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
col.Nullable = true
}
- if colDefault != nil {
+ if colDefault != nil && (!alreadyQuoted || *colDefault != "NULL") {
col.Default = *colDefault
col.DefaultIsEmpty = false
} else {
@@ -404,9 +413,9 @@ func (db *mysql) GetColumns(queryer core.Queryer, ctx context.Context, tableName
}
if !col.DefaultIsEmpty {
- if col.SQLType.IsText() {
+ if !alreadyQuoted && col.SQLType.IsText() {
col.Default = "'" + col.Default + "'"
- } else if col.SQLType.IsTime() && col.Default != "CURRENT_TIMESTAMP" {
+ } else if col.SQLType.IsTime() && !alreadyQuoted && col.Default != "CURRENT_TIMESTAMP" {
col.Default = "'" + col.Default + "'"
}
}