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

Commit dc08e0c

Browse files
authored
export: initial work to support MemSQL/SingleStore (#311)
1 parent f9dd668 commit dc08e0c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ coverage.txt
44
.idea
55
var
66
fix.sql
7+
.vscode/
8+
export-20*/

v4/export/sql.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"strconv"
1313
"strings"
1414

15+
"github.com/go-sql-driver/mysql"
16+
1517
tcontext "github.com/pingcap/dumpling/v4/context"
1618

1719
"github.com/pingcap/errors"
@@ -49,6 +51,13 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) {
4951
}
5052
query := fmt.Sprintf("SHOW CREATE DATABASE `%s`", escapeString(database))
5153
err := simpleQuery(db, query, handleOneRow)
54+
if mysqlErr, ok := errors.Cause(err).(*mysql.MySQLError); ok {
55+
// Falling back to simple create statement for MemSQL/SingleStore, because of this:
56+
// ERROR 1706 (HY000): Feature 'SHOW CREATE DATABASE' is not supported by MemSQL.
57+
if mysqlErr.Number == 1706 {
58+
return fmt.Sprintf("CREATE DATABASE `%s`", escapeString(database)), nil
59+
}
60+
}
5261
if err != nil {
5362
return "", errors.Annotatef(err, "sql: %s", query)
5463
}
@@ -642,7 +651,14 @@ func createConnWithConsistency(ctx context.Context, db *sql.DB) (*sql.Conn, erro
642651
query = "START TRANSACTION /*!40108 WITH CONSISTENT SNAPSHOT */"
643652
_, err = conn.ExecContext(ctx, query)
644653
if err != nil {
645-
return nil, errors.Annotatef(err, "sql: %s", query)
654+
// Some MySQL Compatible databases like Vitess and MemSQL/SingleStore
655+
// are newer than 4.1.8 (the version comment) but don't actually support
656+
// `WITH CONSISTENT SNAPSHOT`. So retry without that if the statement fails.
657+
query = "START TRANSACTION"
658+
_, err = conn.ExecContext(ctx, query)
659+
if err != nil {
660+
return nil, errors.Annotatef(err, "sql: %s", query)
661+
}
646662
}
647663
return conn, nil
648664
}

0 commit comments

Comments
 (0)