Skip to content

Commit

Permalink
Test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonRoehl committed Feb 1, 2019
1 parent 123b8ce commit d22e068
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ func (data *metaData) updateServerVersion(db *sql.DB) (err error) {

func (data *Data) createTable(name string) (*table, error) {
var err error
t := &table{Name: fmt.Sprintf("`%s`", name)}
t := &table{Name: "`" + name + "`"}

if t.SQL, err = data.createTableSQL(t.Name); err != nil {
if t.SQL, err = data.createTableSQL(name); err != nil {
return nil, err
}

if t.Values, err = data.createTableValues(t.Name); err != nil {
if t.Values, err = data.createTableValues(name); err != nil {
return nil, err
}

Expand All @@ -248,7 +248,7 @@ func (data *Data) createTable(name string) (*table, error) {

func (data *Data) createTableSQL(name string) (string, error) {
var tableReturn, tableSQL sql.NullString
err := data.Connection.QueryRow("SHOW CREATE TABLE "+name).Scan(&tableReturn, &tableSQL)
err := data.Connection.QueryRow("SHOW CREATE TABLE `"+name+"`").Scan(&tableReturn, &tableSQL)

if err != nil {
return "", err
Expand All @@ -261,7 +261,7 @@ func (data *Data) createTableSQL(name string) (string, error) {
}

func (data *Data) createTableValues(name string) (string, error) {
rows, err := data.Connection.Query("SELECT * FROM " + name)
rows, err := data.Connection.Query("SELECT * FROM `" + name + "`")
if err != nil {
return "", err
}
Expand Down
10 changes: 5 additions & 5 deletions dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestCreateTableSQLOk(t *testing.T) {
rows := sqlmock.NewRows([]string{"Table", "Create Table"}).
AddRow("Test_Table", "CREATE TABLE 'Test_Table' (`id` int(11) NOT NULL AUTO_INCREMENT,`s` char(60) DEFAULT NULL, PRIMARY KEY (`id`))ENGINE=InnoDB DEFAULT CHARSET=latin1")

mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(rows)
mock.ExpectQuery("^SHOW CREATE TABLE `Test_Table`$").WillReturnRows(rows)

data := Data{
Connection: db,
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestCreateTableValuesOk(t *testing.T) {
AddRow(1, "[email protected]", "Test Name 1").
AddRow(2, "[email protected]", "Test Name 2")

mock.ExpectQuery("^SELECT (.+) FROM test$").WillReturnRows(rows)
mock.ExpectQuery("^SELECT (.+) FROM `test`$").WillReturnRows(rows)

data := Data{
Connection: db,
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestCreateTableValuesNil(t *testing.T) {
AddRow(2, "[email protected]", "Test Name 2").
AddRow(3, "", "Test Name 3")

mock.ExpectQuery("^SELECT (.+) FROM test$").WillReturnRows(rows)
mock.ExpectQuery("^SELECT (.+) FROM `test`$").WillReturnRows(rows)

data := Data{
Connection: db,
Expand Down Expand Up @@ -266,8 +266,8 @@ func TestCreateTableOk(t *testing.T) {
AddRow(1, nil, "Test Name 1").
AddRow(2, "[email protected]", "Test Name 2")

mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM Test_Table$").WillReturnRows(createTableValueRows)
mock.ExpectQuery("^SHOW CREATE TABLE `Test_Table`$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM `Test_Table`$").WillReturnRows(createTableValueRows)

data := Data{
Connection: db,
Expand Down
4 changes: 2 additions & 2 deletions mysqldump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestDumpOk(t *testing.T) {

mock.ExpectQuery("^SELECT version()").WillReturnRows(serverVersionRows)
mock.ExpectQuery("^SHOW TABLES$").WillReturnRows(showTablesRows)
mock.ExpectQuery("^SHOW CREATE TABLE Test_Table$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM Test_Table$").WillReturnRows(createTableValueRows)
mock.ExpectQuery("^SHOW CREATE TABLE `Test_Table`$").WillReturnRows(createTableRows)
mock.ExpectQuery("^SELECT (.+) FROM `Test_Table`$").WillReturnRows(createTableValueRows)

buf := new(bytes.Buffer)
err = Dump(db, buf)
Expand Down

0 comments on commit d22e068

Please sign in to comment.