mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-08 15:06:08 +02:00
Adds escaping when normalizing table names for MySQL on DB helpers (#4653)
Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
parent
d8e1fb4832
commit
1fff221da9
@ -319,7 +319,7 @@ func (s *SQLStore) GetTemplateHelperFuncs() template.FuncMap {
|
|||||||
|
|
||||||
func (s *SQLStore) genAddColumnIfNeeded(tableName, columnName, datatype, constraint string) (string, error) {
|
func (s *SQLStore) genAddColumnIfNeeded(tableName, columnName, datatype, constraint string) (string, error) {
|
||||||
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
||||||
normTableName := normalizeTablename(s.schemaName, tableName)
|
normTableName := s.normalizeTablename(tableName)
|
||||||
|
|
||||||
switch s.dbType {
|
switch s.dbType {
|
||||||
case model.SqliteDBType:
|
case model.SqliteDBType:
|
||||||
@ -358,7 +358,7 @@ func (s *SQLStore) genAddColumnIfNeeded(tableName, columnName, datatype, constra
|
|||||||
|
|
||||||
func (s *SQLStore) genDropColumnIfNeeded(tableName, columnName string) (string, error) {
|
func (s *SQLStore) genDropColumnIfNeeded(tableName, columnName string) (string, error) {
|
||||||
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
||||||
normTableName := normalizeTablename(s.schemaName, tableName)
|
normTableName := s.normalizeTablename(tableName)
|
||||||
|
|
||||||
switch s.dbType {
|
switch s.dbType {
|
||||||
case model.SqliteDBType:
|
case model.SqliteDBType:
|
||||||
@ -395,7 +395,7 @@ func (s *SQLStore) genDropColumnIfNeeded(tableName, columnName string) (string,
|
|||||||
func (s *SQLStore) genCreateIndexIfNeeded(tableName, columns string) (string, error) {
|
func (s *SQLStore) genCreateIndexIfNeeded(tableName, columns string) (string, error) {
|
||||||
indexName := getIndexName(tableName, columns)
|
indexName := getIndexName(tableName, columns)
|
||||||
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
||||||
normTableName := normalizeTablename(s.schemaName, tableName)
|
normTableName := s.normalizeTablename(tableName)
|
||||||
|
|
||||||
switch s.dbType {
|
switch s.dbType {
|
||||||
case model.SqliteDBType:
|
case model.SqliteDBType:
|
||||||
@ -435,7 +435,7 @@ func (s *SQLStore) genRenameTableIfNeeded(oldTableName, newTableName string) (st
|
|||||||
oldTableName = addPrefixIfNeeded(oldTableName, s.tablePrefix)
|
oldTableName = addPrefixIfNeeded(oldTableName, s.tablePrefix)
|
||||||
newTableName = addPrefixIfNeeded(newTableName, s.tablePrefix)
|
newTableName = addPrefixIfNeeded(newTableName, s.tablePrefix)
|
||||||
|
|
||||||
normOldTableName := normalizeTablename(s.schemaName, oldTableName)
|
normOldTableName := s.normalizeTablename(oldTableName)
|
||||||
|
|
||||||
vars := map[string]string{
|
vars := map[string]string{
|
||||||
"schema": s.schemaName,
|
"schema": s.schemaName,
|
||||||
@ -482,7 +482,7 @@ func (s *SQLStore) genRenameTableIfNeeded(oldTableName, newTableName string) (st
|
|||||||
|
|
||||||
func (s *SQLStore) genRenameColumnIfNeeded(tableName, oldColumnName, newColumnName, dataType string) (string, error) {
|
func (s *SQLStore) genRenameColumnIfNeeded(tableName, oldColumnName, newColumnName, dataType string) (string, error) {
|
||||||
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
||||||
normTableName := normalizeTablename(s.schemaName, tableName)
|
normTableName := s.normalizeTablename(tableName)
|
||||||
|
|
||||||
vars := map[string]string{
|
vars := map[string]string{
|
||||||
"schema": s.schemaName,
|
"schema": s.schemaName,
|
||||||
@ -620,7 +620,7 @@ func (s *SQLStore) doesColumnExist(tableName, columnName string) (bool, error) {
|
|||||||
|
|
||||||
func (s *SQLStore) genAddConstraintIfNeeded(tableName, constraintName, constraintType, constraintDefinition string) (string, error) {
|
func (s *SQLStore) genAddConstraintIfNeeded(tableName, constraintName, constraintType, constraintDefinition string) (string, error) {
|
||||||
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
tableName = addPrefixIfNeeded(tableName, s.tablePrefix)
|
||||||
normTableName := normalizeTablename(s.schemaName, tableName)
|
normTableName := s.normalizeTablename(tableName)
|
||||||
|
|
||||||
var query string
|
var query string
|
||||||
|
|
||||||
@ -686,8 +686,12 @@ func addPrefixIfNeeded(s, prefix string) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeTablename(schemaName, tableName string) string {
|
func (s *SQLStore) normalizeTablename(tableName string) string {
|
||||||
if schemaName != "" && !strings.HasPrefix(tableName, schemaName+".") {
|
if s.schemaName != "" && !strings.HasPrefix(tableName, s.schemaName+".") {
|
||||||
|
schemaName := s.schemaName
|
||||||
|
if s.dbType == model.MysqlDBType {
|
||||||
|
schemaName = "`" + schemaName + "`"
|
||||||
|
}
|
||||||
tableName = schemaName + "." + tableName
|
tableName = schemaName + "." + tableName
|
||||||
}
|
}
|
||||||
return tableName
|
return tableName
|
||||||
|
Loading…
Reference in New Issue
Block a user