Skip to content

Commit

Permalink
fix _ #340-1: do not use prepare for ddl
Browse files Browse the repository at this point in the history
  • Loading branch information
ffffwh committed Oct 25, 2018
1 parent 56e5da9 commit 8cfef1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
12 changes: 10 additions & 2 deletions internal/client/driver/mysql/applier.go
Expand Up @@ -859,14 +859,17 @@ func (a *Applier) initDBConnections() (err error) {
a.logger.Errorf("mysql.applier: Unexpected error on validateGrants, got %v", err)
return err
}
a.logger.Debugf("mysql.applier. after validateGrants")
if err := a.validateAndReadTimeZone(); err != nil {
return err
}
a.logger.Debugf("mysql.applier. after validateAndReadTimeZone")

if a.mysqlContext.ApproveHeterogeneous {
if err := a.createTableGtidExecutedV2(); err != nil {
return err
}
a.logger.Debugf("mysql.applier. after createTableGtidExecutedV2")

for i := range a.dbs {
a.dbs[i].PsDeleteExecutedGtid, err = a.dbs[i].Db.PrepareContext(context.Background(), fmt.Sprintf("delete from %v.%v where job_uuid = unhex('%s') and source_uuid = ?",
Expand All @@ -884,6 +887,7 @@ func (a *Applier) initDBConnections() (err error) {
}

}
a.logger.Debugf("mysql.applier. after prepare stmt for gtid_executed table")
}
/*if err := a.readCurrentBinlogCoordinates(); err != nil {
return err
Expand Down Expand Up @@ -986,12 +990,15 @@ func (a *Applier) createTableGtidExecutedV2() error {
g.DtleSchemaName, g.GtidExecutedTableV2)); nil == err && len(result) > 0 {
return nil
}
a.logger.Debugf("mysql.applier. after show gtid_executed table")

query := fmt.Sprintf(`
CREATE DATABASE IF NOT EXISTS %v;
`, g.DtleSchemaName)
if _, err := sql.Exec(a.db, query); err != nil {
if _, err := a.db.Exec(query); err != nil {
return err
}
a.logger.Debugf("mysql.applier. after create dtle schema")

query = fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %v.%v (
Expand All @@ -1000,9 +1007,10 @@ func (a *Applier) createTableGtidExecutedV2() error {
interval_gtid text NOT NULL COMMENT 'number of interval.'
);
`, g.DtleSchemaName, g.GtidExecutedTableV2)
if _, err := sql.Exec(a.db, query); err != nil {
if _, err := a.db.Exec(query); err != nil {
return err
}
a.logger.Debugf("mysql.applier. after create gtid_executed table")

return nil
}
Expand Down
31 changes: 0 additions & 31 deletions internal/client/driver/mysql/sql/sqlutils.go
Expand Up @@ -328,37 +328,6 @@ func ExecNoPrepare(db *gosql.Conn, query string, args ...interface{}) (gosql.Res
return res, err
}

// ExecQuery executes given query using given args on given DB. It will safele prepare, execute and close
// the statement.
func execInternal(silent bool, db *gosql.DB, query string, args ...interface{}) (gosql.Result, error) {
var err error
defer func() {
if derr := recover(); derr != nil {
err = errors.New(fmt.Sprintf("execInternal unexpected error: %+v", derr))
}
}()

stmt, err := db.Prepare(query)
if err != nil {
return nil, err
}
defer stmt.Close()
var res gosql.Result
res, err = stmt.Exec(args...)
return res, err
}

// Exec executes given query using given args on given DB. It will safele prepare, execute and close
// the statement.
func Exec(db *gosql.DB, query string, args ...interface{}) (gosql.Result, error) {
return execInternal(false, db, query, args...)
}

// ExecSilently acts like Exec but does not report any error
func ExecSilently(db *gosql.DB, query string, args ...interface{}) (gosql.Result, error) {
return execInternal(true, db, query, args...)
}

func InClauseStringValues(terms []string) string {
quoted := []string{}
for _, s := range terms {
Expand Down

0 comments on commit 8cfef1b

Please sign in to comment.