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

Commit

Permalink
Initial work to support MemSQL/SingleStore
Browse files Browse the repository at this point in the history
Issue: #309

- `WITH CONSISTENT SNAPSHOT` is not supported by MemSQL (same for
  Vitess).
- `SHOW CREATE DATABASE` is not supported by MemSQL.
  • Loading branch information
dveeden committed Jul 19, 2021
1 parent dc97ee9 commit b529dfb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions v4/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func ShowCreateDatabase(db *sql.Conn, database string) (string, error) {
query := fmt.Sprintf("SHOW CREATE DATABASE `%s`", escapeString(database))
err := simpleQuery(db, query, handleOneRow)
if err != nil {
return "", errors.Annotatef(err, "sql: %s", query)
// Falling back to simple create statement. This can happen
// with MemSQL/SingleStore as MemSQL doesn't support `SHOW CREATE DATABASE`
return fmt.Sprintf("CREATE DATABASE `%s`", escapeString(database)), nil
}
return oneRow[1], nil
}
Expand Down Expand Up @@ -642,7 +644,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 acutally 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

0 comments on commit b529dfb

Please sign in to comment.