Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: no hack on quote string for MySQL/TiDB (#13341)

h3n4le09c71ec35b6
diff --git a/backend/plugin/schema/mysql/get_design_schema.go b/backend/plugin/schema/mysql/get_design_schema.go
index 9315a1db31..2e3464eaed 100644
--- a/backend/plugin/schema/mysql/get_design_schema.go
+++ b/backend/plugin/schema/mysql/get_design_schema.go
@@ -472,7 +472,7 @@ func (g *mysqlDesignSchemaGenerator) ExitCreateTable(ctx *mysql.CreateTableConte
}
if g.currentTable.comment != "" {
- if _, err := g.result.WriteString(fmt.Sprintf(" COMMENT '%s'", strings.ReplaceAll(g.currentTable.comment, "'", "''"))); err != nil {
+ if _, err := g.result.WriteString(fmt.Sprintf(" COMMENT '%s'", g.currentTable.comment)); err != nil {
g.err = err
return
}
@@ -487,7 +487,7 @@ func (g *mysqlDesignSchemaGenerator) ExitCreateTable(ctx *mysql.CreateTableConte
return
}
if g.currentTable.comment != "" {
- if _, err := g.result.WriteString(fmt.Sprintf(" COMMENT '%s' ", strings.ReplaceAll(g.currentTable.comment, "'", "''"))); err != nil {
+ if _, err := g.result.WriteString(fmt.Sprintf(" COMMENT '%s' ", g.currentTable.comment)); err != nil {
g.err = err
return
}
@@ -598,7 +598,7 @@ func (g *mysqlDesignSchemaGenerator) EnterCreateTableOption(ctx *mysql.CreateTab
return
}
- if _, err := g.tableOptions.WriteString(fmt.Sprintf("'%s'", strings.ReplaceAll(g.currentTable.comment, "'", "''"))); err != nil {
+ if _, err := g.tableOptions.WriteString(fmt.Sprintf("'%s'", g.currentTable.comment)); err != nil {
g.err = err
return
}
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index 6cea7bdf77..2ea91683dd 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -259,7 +259,7 @@ func (t *tableState) toString(buf io.StringWriter) error {
}
if t.comment != "" {
- if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", strings.ReplaceAll(t.comment, "'", "''"))); err != nil {
+ if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", t.comment)); err != nil {
return err
}
}
@@ -1307,7 +1307,7 @@ type defaultValueString struct {
}
func (d *defaultValueString) toString() string {
- return fmt.Sprintf("'%s'", strings.ReplaceAll(d.value, "'", "''"))
+ return fmt.Sprintf("'%s'", d.value)
}
type defaultValueExpression struct {
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
index 91b6254c1f..b6c705b4fd 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/get_design_schema.yaml
@@ -500,8 +500,7 @@
],
"visible": true
}
- ],
- "comment": "this is comment with ' escaped"
+ ]
}
]
}
@@ -559,7 +558,7 @@
UNIQUE KEY `t_c_plus_5_uniq_idx` (((`c` + 5))),
UNIQUE KEY `t_c_uniq_idx` (`c`),
KEY `t_d_fulltext_idx` (`d`)
- ) COMMENT 'this is comment with '' escaped';
+ );
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
@@ -594,7 +593,7 @@
- description: ""
baseline: |-
CREATE TABLE `t1` (
- `a` int primary key
+ `a` varchar(255)
);
CREATE TABLE `t2` (
`a` int AUTO_INCREMENT primary key
@@ -617,7 +616,7 @@
"name": "a",
"nullable": true,
"type": "int",
- "defaultExpression": "AUTO_INCREMENT"
+ "default": "\\'escaped"
},
{
"name": "b",
@@ -658,6 +657,17 @@
"defaultExpression": "1"
}
]
+ },
+ {
+ "name": "t4",
+ "columns": [
+ {
+ "name": "a",
+ "nullable": true,
+ "type": "int",
+ "default": "\\'a\\'"
+ }
+ ]
}
]
}
@@ -665,7 +675,7 @@
}
result: |
CREATE TABLE `t1` (
- `a` int primary key AUTO_INCREMENT,
+ `a` int DEFAULT '\'escaped',
`b` int
);
CREATE TABLE `t2` (
@@ -675,7 +685,7 @@
`a` int AUTO_INCREMENT primary key
);
CREATE TABLE `t4` (
- `a` int DEFAULT 1 primary key
+ `a` int DEFAULT '\'a\'' primary key
);
- description: ""
baseline: |-
diff --git a/backend/plugin/schema/tidb/state.go b/backend/plugin/schema/tidb/state.go
index 0ca4f081df..d76b73f20d 100644
--- a/backend/plugin/schema/tidb/state.go
+++ b/backend/plugin/schema/tidb/state.go
@@ -202,7 +202,7 @@ func (t *tableState) toString(buf *strings.Builder) error {
}
if t.comment != "" {
- if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", strings.ReplaceAll(t.comment, "'", "''"))); err != nil {
+ if _, err := buf.WriteString(fmt.Sprintf(" COMMENT '%s'", t.comment)); err != nil {
return err
}
}
@@ -485,7 +485,7 @@ type defaultValueString struct {
}
func (d *defaultValueString) toString() string {
- return fmt.Sprintf("'%s'", strings.ReplaceAll(d.value, "'", "''"))
+ return fmt.Sprintf("'%s'", d.value)
}
type defaultValueExpression struct {