mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
quote table name on DESCRIBE statement (#7)
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/7 avoid conflicting with reserved words (e.g. "groups" became reserved word in MySQL 8.x) Reviewed By: alexsn Differential Revision: D15957279 fbshipit-source-id: b6944752c7e5f6ec37119b11cc0ab8a0d7d3a7ff
This commit is contained in:
committed by
Facebook Github Bot
parent
5ca9494121
commit
0e605681b2
@@ -131,7 +131,8 @@ func (d *MySQL) exist(ctx context.Context, tx dialect.Tx, query string, args ...
|
||||
// table loads the current table description from the database.
|
||||
func (d *MySQL) table(ctx context.Context, tx dialect.Tx, name string) (*Table, error) {
|
||||
rows := &sql.Rows{}
|
||||
if err := tx.Query(ctx, "DESCRIBE "+name, []interface{}{}, rows); err != nil {
|
||||
query, args := sql.Describe(name).Query()
|
||||
if err := tx.Query(ctx, query, args, rows); err != nil {
|
||||
return nil, fmt.Errorf("dialect/mysql: reading table description %v", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
@@ -151,7 +151,7 @@ func TestMySQL_Create(t *testing.T) {
|
||||
AND TABLE_NAME = ?`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(1))
|
||||
mock.ExpectQuery("DESCRIBE users").
|
||||
mock.ExpectQuery("DESCRIBE `users`").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"Field", "Type", "Null", "Key", "Default", "Extra"}).
|
||||
AddRow("id", "int(11)", "NO", "PRI", "NULL", "auto_increment").
|
||||
AddRow("name", "varchar(255)", "NO", "YES", "NULL", ""))
|
||||
@@ -194,7 +194,7 @@ func TestMySQL_Create(t *testing.T) {
|
||||
AND TABLE_NAME = ?`)).
|
||||
WithArgs("users").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(1))
|
||||
mock.ExpectQuery("DESCRIBE users").
|
||||
mock.ExpectQuery("DESCRIBE `users`").
|
||||
WillReturnRows(sqlmock.NewRows([]string{"Field", "Type", "Null", "Key", "Default", "Extra"}).
|
||||
AddRow("id", "int(11)", "NO", "PRI", "NULL", "auto_increment").
|
||||
AddRow("name", "varchar(255)", "NO", "YES", "NULL", ""))
|
||||
|
||||
Reference in New Issue
Block a user