@@ -330,7 +330,7 @@ func (e *Extractor) Run() {
330330 } else { // no full copy
331331 // Will not get consistent table meta-info for an incremental only job.
332332 // https://github.com/actiontech/dtle/issues/321#issuecomment-441191534
333- if err := e .getSchemaTablesAndMeta (); err != nil {
333+ if err := e .getSchemaTablesAndMeta (e . db ); err != nil {
334334 e .onError (common .TaskStateDead , err )
335335 return
336336 }
@@ -380,9 +380,9 @@ func (e *Extractor) initiateInspector() (err error) {
380380 return nil
381381}
382382
383- func (e * Extractor ) inspectTables () (err error ) {
383+ func (e * Extractor ) inspectTables (db sql. QueryAble ) (err error ) {
384384 // Creates a MYSQL Dump based on the options supplied through the dumper.
385- dbsExisted , err := sql .ShowDatabases (e . db )
385+ dbsExisted , err := sql .ShowDatabases (db )
386386 if err != nil {
387387 return err
388388 }
@@ -434,11 +434,11 @@ func (e *Extractor) inspectTables() (err error) {
434434 schemaCtx .TableSchemaRename = doDb .TableSchemaRename
435435 e .replicateDoDb [doDb .TableSchema ] = schemaCtx
436436
437- schemaCtx .CreateSchemaString , err = sql .ShowCreateSchema (e .ctx , e . db , doDb .TableSchema )
437+ schemaCtx .CreateSchemaString , err = sql .ShowCreateSchema (e .ctx , db , doDb .TableSchema )
438438 if err != nil {
439439 return err
440440 }
441- existedTables , err := sql .ShowTables (e . db , doDb .TableSchema , e .mysqlContext .ExpandSyntaxSupport )
441+ existedTables , err := sql .ShowTables (db , doDb .TableSchema , e .mysqlContext .ExpandSyntaxSupport )
442442 if err != nil {
443443 return err
444444 }
@@ -534,12 +534,12 @@ func (e *Extractor) inspectTables() (err error) {
534534 schemaCtx := common .NewSchemaContext (dbName )
535535 e .replicateDoDb [dbName ] = schemaCtx
536536
537- schemaCtx .CreateSchemaString , err = sql .ShowCreateSchema (e .ctx , e . db , dbName )
537+ schemaCtx .CreateSchemaString , err = sql .ShowCreateSchema (e .ctx , db , dbName )
538538 if err != nil {
539539 return err
540540 }
541541
542- tbs , err := sql .ShowTables (e . db , dbName , e .mysqlContext .ExpandSyntaxSupport )
542+ tbs , err := sql .ShowTables (db , dbName , e .mysqlContext .ExpandSyntaxSupport )
543543 if err != nil {
544544 return err
545545 }
@@ -753,8 +753,8 @@ func (e *Extractor) initDBConnections() (err error) {
753753 return nil
754754}
755755
756- func (e * Extractor ) getSchemaTablesAndMeta () error {
757- if err := e .inspectTables (); err != nil {
756+ func (e * Extractor ) getSchemaTablesAndMeta (queryable sql. QueryAble ) error {
757+ if err := e .inspectTables (queryable ); err != nil {
758758 return err
759759 }
760760
@@ -774,7 +774,7 @@ func (e *Extractor) getSchemaTablesAndMeta() error {
774774 continue
775775 }
776776
777- stmt , err := base .ShowCreateTable (e . db , db .TableSchema , tb .TableName )
777+ stmt , err := base .ShowCreateTable (queryable , db .TableSchema , tb .TableName )
778778 if err != nil {
779779 e .logger .Error ("error at ShowCreateTable." , "err" , err )
780780 return err
@@ -856,15 +856,14 @@ func (e *Extractor) setInitialBinlogCoordinates() error {
856856}
857857
858858// CountTableRows counts exact number of rows on the original table
859- func (e * Extractor ) CountTableRows (table * common.Table ) (int64 , error ) {
859+ func (e * Extractor ) CountTableRows (db sql. QueryAble , table * common.Table ) (int64 , error ) {
860860 //e.logger.Debug("As instructed, I'm issuing a SELECT COUNT(*) on the table. This may take a while")
861861
862862 var query string
863863 // It only requires select privilege on target table to select its information_schema item.
864- query = fmt .Sprintf (`select table_rows from information_schema.tables where table_schema = '%s' and table_name = '%s'` ,
865- sql .EscapeValue (table .TableSchema ), sql .EscapeValue (table .TableName ))
864+ query = fmt .Sprintf (`select table_rows from information_schema.tables where table_schema = ? and table_name = ?` )
866865 var rowsEstimate int64
867- err := e . db .QueryRow (query ).Scan (& rowsEstimate )
866+ err := db .QueryRow (query , table . TableSchema , table . TableName ).Scan (& rowsEstimate )
868867 if err != nil {
869868 e .logger .Error ("error when getting estimated row number (using information_schema)" , "err" , err ,
870869 "schema" , table .TableSchema , "table" , table .TableName )
@@ -1295,7 +1294,7 @@ func (e *Extractor) mysqlDump() (retErr error) {
12951294 // we are reading the database names from the database and not taking them from the user ...
12961295 e .logger .Info ("Step: read list of available tables in each database" , "n" , step )
12971296
1298- err = e .getSchemaTablesAndMeta ()
1297+ err = e .getSchemaTablesAndMeta (tx )
12991298 if err != nil {
13001299 return err
13011300 }
@@ -1328,7 +1327,7 @@ func (e *Extractor) mysqlDump() (retErr error) {
13281327 // Create the tables.
13291328 for _ , tbCtx := range db .TableMap {
13301329 tb := tbCtx .Table
1331- tb .Counter , err = e .CountTableRows (tb )
1330+ tb .Counter , err = e .CountTableRows (tx , tb )
13321331 if err != nil {
13331332 return errors .Wrapf (err , "CountTableRows %v.%v" , tb .TableSchema , tb .TableName )
13341333 }
@@ -1345,7 +1344,7 @@ func (e *Extractor) mysqlDump() (retErr error) {
13451344 return err
13461345 }*/
13471346 } else {
1348- ctStmt , err := base .ShowCreateTable (e . singletonDB , tb .TableSchema , tb .TableName )
1347+ ctStmt , err := base .ShowCreateTable (tx , tb .TableSchema , tb .TableName )
13491348 if err != nil {
13501349 return err
13511350 }
0 commit comments