Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: when tableName is keyword, the insert operation will get afterImage fail #2053

Merged
merged 9 commits into from
Dec 18, 2019
Prev Previous commit
Next Next commit
bugfix: when tableName is keyword, the insert operation will get afte…
…rImage fail.

Signed-off-by: slievrly <slievrly@163.com>
  • Loading branch information
slievrly committed Dec 17, 2019
commit 66c438854fe55e9d9b464ac3edb7fff8aa533b80
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*/
package io.seata.rm.datasource.exec;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.core.context.RootContext;
Expand All @@ -29,16 +37,9 @@
import io.seata.rm.datasource.sql.struct.TableMeta;
import io.seata.rm.datasource.sql.struct.TableMetaCacheFactory;
import io.seata.rm.datasource.sql.struct.TableRecords;
import io.seata.rm.datasource.undo.KeywordCheckerFactory;
import io.seata.rm.datasource.undo.SQLUndoLog;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

/**
* The type Base transactional executor.
*
Expand Down Expand Up @@ -346,7 +347,10 @@ protected TableRecords buildTableRecords(TableMeta tableMeta, String selectSQL,
protected TableRecords buildTableRecords(List<Object> pkValues) throws SQLException {
TableRecords afterImage;
String pk = getTableMeta().getPkName();
StringJoiner pkValuesJoiner = new StringJoiner(" , ", "SELECT * FROM " + getTableMeta().getTableName() + " WHERE " + pk + " in (", ")");
String tableName = KeywordCheckerFactory.getKeywordChecker(getDbType()).checkAndReplace(
getTableMeta().getTableName());
StringJoiner pkValuesJoiner = new StringJoiner(" , ", "SELECT * FROM " + tableName + " WHERE " + pk + " in (",
")");
for (Object pkValue : pkValues) {
pkValuesJoiner.add("?");
}
Expand Down