Merge pull request #664 from xieyinglin/master

fix the tag is placeholder for issue #661
This commit is contained in:
xieyinglin 2019-11-01 13:13:57 +08:00 committed by GitHub
commit 53412e4d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 5 deletions

View File

@ -186,7 +186,7 @@ public class SavedPreparedStatement {
int paramSize = this.middleParamSize + this.valueListSize; int paramSize = this.middleParamSize + this.valueListSize;
String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, this.middleParamSize + this.valueListSize); String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize);
if (parameterIndex < 1 || parameterIndex > paramSize) { if (parameterIndex < 1 || parameterIndex > paramSize) {
throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg)); throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg));
@ -200,13 +200,13 @@ public class SavedPreparedStatement {
parameterIndex = parameterIndex - 1; // start from 0 in param list parameterIndex = parameterIndex - 1; // start from 0 in param list
if (this.middleParamSize != 0 && parameterIndex >= 0 && parameterIndex < this.middleParamSize) { if (this.middleParamSize > 0 && parameterIndex >= 0 && parameterIndex < this.middleParamSize) {
this.initPreparedParam.setMiddleParam(parameterIndex, x); this.initPreparedParam.setMiddleParam(parameterIndex, x);
return; return;
} }
if (this.valueListSize != 0 && parameterIndex >= this.middleParamSize && parameterIndex < paramSize) { if (this.valueListSize > 0 && parameterIndex >= this.middleParamSize && parameterIndex < paramSize) {
this.initPreparedParam.setValueParam(parameterIndex - this.middleParamSize, x); this.initPreparedParam.setValueParam(parameterIndex - this.middleParamSize, x);
return; return;
@ -255,7 +255,6 @@ public class SavedPreparedStatement {
//1. generate batch sql //1. generate batch sql
String sql = generateExecuteSql(); String sql = generateExecuteSql();
//2. execute batch sql //2. execute batch sql
int result = executeSql(sql); int result = executeSql(sql);
@ -279,7 +278,8 @@ public class SavedPreparedStatement {
if (!isTableNameDynamic) { if (!isTableNameDynamic) {
// tablename will not need to be replaced // tablename will not need to be replaced
stringBuilder.append(middle); String middleValue = replaceMiddleListParam(middle, sqlParamList);
stringBuilder.append(middleValue);
stringBuilder.append(" values"); stringBuilder.append(" values");
stringBuilder.append(replaceValueListParam(valueList, sqlParamList)); stringBuilder.append(replaceValueListParam(valueList, sqlParamList));
@ -353,6 +353,26 @@ public class SavedPreparedStatement {
return stringBuilder.toString(); return stringBuilder.toString();
} }
/**
* replace the placeholder of the middle part of sql template with TSDBPreparedParam list
*
* @param template
* @param sqlParamList
* @return
*/
private String replaceMiddleListParam(String template, List<TSDBPreparedParam> sqlParamList) {
if (sqlParamList.size() > 0) {
//becase once the subTableName is static then will be ignore the tag which after the first setTag
return replaceTemplateParam(template, sqlParamList.get(0).getMiddleParamList());
}
return template;
}
/** /**
* replace the placeholder of the template with TSDBPreparedParam list * replace the placeholder of the template with TSDBPreparedParam list
* *