Skip to content

Commit

Permalink
bugfix:error image fro use index null value in insert on duplicate ex…
Browse files Browse the repository at this point in the history
…ecutor
  • Loading branch information
renliangyu857 committed Oct 28, 2022
1 parent e10e36c commit 6128575
Showing 1 changed file with 15 additions and 10 deletions.
Expand Up @@ -44,6 +44,7 @@
import io.seata.rm.datasource.sql.struct.Row;
import io.seata.rm.datasource.sql.struct.TableMeta;
import io.seata.rm.datasource.sql.struct.TableRecords;
import io.seata.rm.datasource.sql.struct.IndexMeta;
import io.seata.rm.datasource.undo.SQLUndoLog;
import io.seata.sqlparser.SQLInsertRecognizer;
import io.seata.sqlparser.SQLRecognizer;
Expand Down Expand Up @@ -297,7 +298,7 @@ public String buildImageSQL(TableMeta tableMeta) {
int finalI = i;
List<Object> paramAppenderTempList = new ArrayList<>();
tableMeta.getAllIndexes().forEach((k, v) -> {
if (!v.isNonUnique()) {
if (!v.isNonUnique() && isIndexValueNotNull(v,imageParameterMap,finalI)) {
boolean columnIsNull = true;
List<String> uniqueList = new ArrayList<>();
for (ColumnMeta m : v.getValues()) {
Expand All @@ -308,15 +309,6 @@ public String buildImageSQL(TableMeta tableMeta) {
columnIsNull = false;
continue;
}
if ((imageParameters == null && m.getColumnDef() == null) || imageParameters.get(finalI) == null || imageParameters.get(finalI) instanceof Null) {
if (!"PRIMARY".equalsIgnoreCase(k)) {
columnIsNull = false;
uniqueList.add(columnName + " is ? ");
paramAppenderTempList.add("NULL");
continue;
}
break;
}
columnIsNull = false;
uniqueList.add(columnName + " = ? ");
paramAppenderTempList.add(imageParameters.get(finalI));
Expand Down Expand Up @@ -389,4 +381,17 @@ public Map<String, ArrayList<Object>> buildImageParameters(SQLInsertRecognizer r
return imageParameterMap;
}

private boolean isIndexValueNotNull(IndexMeta indexMeta, Map<String, ArrayList<Object>> imageParameterMap,int rowIndex) {
for (ColumnMeta columnMeta : indexMeta.getValues()) {
String columnName = columnMeta.getColumnName();
List<Object> imageParameters = imageParameterMap.get(columnName);
if ((imageParameters == null && columnMeta.getColumnDef() == null)
|| imageParameters.get(rowIndex) == null
|| imageParameters.get(rowIndex) instanceof Null) {
return false;
}
}
return true;
}

}

0 comments on commit 6128575

Please sign in to comment.