Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions identifier_quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,49 @@ func TestSqliteDialectEscapesIdentifierQuotes(t *testing.T) {
}
}

func TestSqlForCreateQuotesSchemaIdentifier(t *testing.T) {
tests := []struct {
name string
dialect Dialect
schema string
want string
}{
{
name: "postgres",
dialect: PostgresDialect{},
schema: `Mixed"Case`,
want: `create schema "Mixed""Case";create table ` +
`"Mixed""Case"."security_rows" ("ID" bigint) ;`,
},
{
name: "mysql",
dialect: MySQLDialect{
Engine: "InnoDB",
Encoding: "UTF8",
},
schema: "Mixed`Case",
want: "create schema `Mixed``Case`;create table " +
"`Mixed``Case`.`security_rows` (`ID` bigint) engine=InnoDB charset=UTF8;",
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
dbmap := &DbMap{Dialect: tc.dialect}
table := dbmap.AddTableWithNameAndSchema(
identifierIndexedRow{},
tc.schema,
"security_rows",
)

got := table.SqlForCreate(false)
if got != tc.want {
t.Fatalf("SqlForCreate() = %q, want %q", got, tc.want)
}
})
}
}

func TestSqliteQuotedTableNameCannotRewriteUpdateTarget(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (t *TableMap) SqlForCreate(ifNotExists bool) string {
} else {
s.WriteString(schemaCreate)
}
s.WriteString(fmt.Sprintf(" %s;", t.SchemaName))
s.WriteString(fmt.Sprintf(" %s;", dialect.QuoteField(t.SchemaName)))
}

tableCreate := "create table"
Expand Down
Loading