Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

export: initial work to support MemSQL/SingleStore (#311) #329

Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ coverage.txt
.idea
var
fix.sql
.vscode/
export-20*/
18 changes: 17 additions & 1 deletion v4/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"strings"

"github.com/go-sql-driver/mysql"

tcontext "github.com/pingcap/dumpling/v4/context"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -49,6 +51,13 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) {
}
query := fmt.Sprintf("SHOW CREATE DATABASE `%s`", escapeString(database))
err := simpleQuery(db, query, handleOneRow)
if mysqlErr, ok := errors.Cause(err).(*mysql.MySQLError); ok {
// Falling back to simple create statement for MemSQL/SingleStore, because of this:
// ERROR 1706 (HY000): Feature 'SHOW CREATE DATABASE' is not supported by MemSQL.
if mysqlErr.Number == 1706 {
return fmt.Sprintf("CREATE DATABASE `%s`", escapeString(database)), nil
}
}
if err != nil {
return "", errors.Annotatef(err, "sql: %s", query)
}
Expand Down Expand Up @@ -642,7 +651,14 @@ func createConnWithConsistency(ctx context.Context, db *sql.DB) (*sql.Conn, erro
query = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"
_, err = conn.ExecContext(ctx, query)
if err != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
// Some MySQL Compatible databases like Vitess and MemSQL/SingleStore
// are newer than 4.1.8 (the version comment) but don't actually support
// `WITH CONSISTENT SNAPSHOT`. So retry without that if the statement fails.
query = "START TRANSACTION"
_, err = conn.ExecContext(ctx, query)
if err != nil {
return nil, errors.Annotatef(err, "sql: %s", query)
}
}
return conn, nil
}
Expand Down