diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml
index 21635a75..99aaa09a 100644
--- a/.github/workflows/pull-request.yml
+++ b/.github/workflows/pull-request.yml
@@ -5,6 +5,7 @@ on:
branches:
- master
- 2201.[0-9]+.x
+ - v1.8.x
jobs:
ubuntu-build:
diff --git a/build-config/spotbugs-exclude.xml b/build-config/spotbugs-exclude.xml
index a16e871b..9e424c12 100644
--- a/build-config/spotbugs-exclude.xml
+++ b/build-config/spotbugs-exclude.xml
@@ -39,13 +39,52 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/changelog.md b/changelog.md
index 1f4340f6..ac0eb54c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -8,9 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+### Changed
+- [Revert Accept escaped backtick as insertions in parameterised query](https://github.com/ballerina-platform/ballerina-standard-library/issues/2056)
+
+## [1.8.0] - 2023-04-10
+
### Changed
- [Improve documentation regard `sql:Column` annotation](https://github.com/ballerina-platform/ballerina-standard-library/issues/4134)
- [Handle null error messages from underlying drivers](https://github.com/ballerina-platform/ballerina-standard-library/issues/4200)
+- [Make `sql:Client` isolated](https://github.com/ballerina-platform/ballerina-standard-library/issues/4455)
## [1.7.1] - 2023-03-09
diff --git a/native/src/main/java/io/ballerina/stdlib/sql/Constants.java b/native/src/main/java/io/ballerina/stdlib/sql/Constants.java
index 5705d35b..26d615d8 100644
--- a/native/src/main/java/io/ballerina/stdlib/sql/Constants.java
+++ b/native/src/main/java/io/ballerina/stdlib/sql/Constants.java
@@ -77,7 +77,6 @@ private Constants() {
public static final String PASSWORD = "password";
public static final String ANNON_RECORD_TYPE_NAME = "record {";
- public static final String BACKTICK = "`";
public static final String DEFAULT_STREAM_CONSTRAINT_NAME = "$stream$anon$constraint$";
public static final String INHERENT_TYPE_VIOLATION = "{ballerina/lang.map}InherentTypeViolation";
/**
diff --git a/native/src/main/java/io/ballerina/stdlib/sql/ParameterizedQuery.java b/native/src/main/java/io/ballerina/stdlib/sql/ParameterizedQuery.java
deleted file mode 100644
index eaddbd39..00000000
--- a/native/src/main/java/io/ballerina/stdlib/sql/ParameterizedQuery.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * WSO2 Inc. licenses this file to you under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package io.ballerina.stdlib.sql;
-
-/**
- * Processed Details from sql:ParameterizedQuery.
- */
-public class ParameterizedQuery {
- private final String sqlQuery;
- private final Object[] insertions;
-
- public ParameterizedQuery(String sqlQuery, Object[] insertions) {
- this.sqlQuery = sqlQuery;
- this.insertions = insertions;
- }
-
- public String getSqlQuery() {
- return sqlQuery;
- }
-
- public Object[] getInsertions() {
- return insertions;
- }
-}
diff --git a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java
index 71b5f74f..190fc14d 100644
--- a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java
+++ b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/CallProcessor.java
@@ -32,7 +32,6 @@
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.runtime.transactions.TransactionResourceManager;
import io.ballerina.stdlib.sql.Constants;
-import io.ballerina.stdlib.sql.ParameterizedQuery;
import io.ballerina.stdlib.sql.datasource.SQLDatasource;
import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.parameterprocessor.AbstractResultParameterProcessor;
@@ -62,6 +61,7 @@
import static io.ballerina.stdlib.sql.datasource.SQLWorkerThreadPool.SQL_EXECUTOR_SERVICE;
import static io.ballerina.stdlib.sql.utils.Utils.getColumnDefinitions;
import static io.ballerina.stdlib.sql.utils.Utils.getDefaultStreamConstraint;
+import static io.ballerina.stdlib.sql.utils.Utils.getSqlQuery;
import static io.ballerina.stdlib.sql.utils.Utils.updateProcedureCallExecutionResult;
/**
@@ -121,13 +121,12 @@ private static Object nativeCallExecutable(BObject client, BObject paramSQLStrin
ResultSet resultSet;
String sqlQuery = null;
try {
- ParameterizedQuery parameterizedQuery = Utils.getParameterizedSQLQuery(paramSQLString);
- sqlQuery = parameterizedQuery.getSqlQuery();
+ sqlQuery = getSqlQuery(paramSQLString);
connection = SQLDatasource.getConnection(isWithinTrxBlock, trxResourceManager, client, sqlDatasource);
statement = connection.prepareCall(sqlQuery);
HashMap outputParamTypes = new HashMap<>();
- setCallParameters(connection, statement, parameterizedQuery.getInsertions(), outputParamTypes,
+ setCallParameters(connection, statement, paramSQLString, outputParamTypes,
statementParameterProcessor);
boolean resultType = statement.execute();
@@ -159,7 +158,7 @@ private static Object nativeCallExecutable(BObject client, BObject paramSQLStrin
updateProcedureCallExecutionResult(statement, procedureCallResult);
}
- populateOutParameters(statement, parameterizedQuery.getInsertions(), outputParamTypes,
+ populateOutParameters(statement, paramSQLString, outputParamTypes,
resultParameterProcessor);
procedureCallResult.addNativeData(STATEMENT_NATIVE_DATA_FIELD, statement);
@@ -182,11 +181,12 @@ private static Object nativeCallExecutable(BObject client, BObject paramSQLStrin
}
private static void setCallParameters(Connection connection, CallableStatement statement,
- Object[] insertions, HashMap outputParamTypes,
+ BObject paramString, HashMap outputParamTypes,
AbstractStatementParameterProcessor statementParameterProcessor)
throws SQLException, ApplicationError {
- for (int i = 0; i < insertions.length; i++) {
- Object object = insertions[i];
+ BArray arrayValue = paramString.getArrayValue(Constants.ParameterizedQueryFields.INSERTIONS);
+ for (int i = 0; i < arrayValue.size(); i++) {
+ Object object = arrayValue.get(i);
int index = i + 1;
if (object instanceof BObject) {
BObject objectValue = (BObject) object;
@@ -225,19 +225,20 @@ private static void setCallParameters(Connection connection, CallableStatement s
}
}
- private static void populateOutParameters(CallableStatement statement, Object[] insertions,
+ private static void populateOutParameters(CallableStatement statement, BObject paramSQLString,
HashMap outputParamTypes,
AbstractResultParameterProcessor resultParameterProcessor)
throws SQLException, ApplicationError {
if (outputParamTypes.size() == 0) {
return;
}
+ BArray arrayValue = paramSQLString.getArrayValue(Constants.ParameterizedQueryFields.INSERTIONS);
for (Map.Entry entry : outputParamTypes.entrySet()) {
int paramIndex = entry.getKey();
int sqlType = entry.getValue();
- BObject parameter = (BObject) insertions[paramIndex - 1];
+ BObject parameter = (BObject) arrayValue.get(paramIndex - 1);
parameter.addNativeData(Constants.ParameterObject.SQL_TYPE_NATIVE_DATA, sqlType);
Object result;
diff --git a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java
index 30ff43d2..a09aacc6 100644
--- a/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java
+++ b/native/src/main/java/io/ballerina/stdlib/sql/nativeimpl/ExecuteProcessor.java
@@ -28,7 +28,6 @@
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.transactions.TransactionResourceManager;
import io.ballerina.stdlib.sql.Constants;
-import io.ballerina.stdlib.sql.ParameterizedQuery;
import io.ballerina.stdlib.sql.datasource.SQLDatasource;
import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.parameterprocessor.AbstractStatementParameterProcessor;
@@ -52,6 +51,7 @@
import static io.ballerina.stdlib.sql.datasource.SQLWorkerThreadPool.SQL_EXECUTOR_SERVICE;
import static io.ballerina.stdlib.sql.utils.Utils.closeResources;
import static io.ballerina.stdlib.sql.utils.Utils.getGeneratedKeys;
+import static io.ballerina.stdlib.sql.utils.Utils.getSqlQuery;
/**
@@ -104,8 +104,7 @@ private static Object nativeExecuteExecutable(BObject client, BObject paramSQLSt
ResultSet resultSet = null;
String sqlQuery = null;
try {
- ParameterizedQuery parameterizedQuery = Utils.getParameterizedSQLQuery(paramSQLString);
- sqlQuery = parameterizedQuery.getSqlQuery();
+ sqlQuery = getSqlQuery(paramSQLString);
connection = SQLDatasource.getConnection(isWithInTrxBlock, trxResourceManager, client, sqlDatasource);
if (sqlDatasource.getExecuteGKFlag()) {
@@ -114,7 +113,7 @@ private static Object nativeExecuteExecutable(BObject client, BObject paramSQLSt
statement = connection.prepareStatement(sqlQuery);
}
- statementParameterProcessor.setParams(connection, statement, parameterizedQuery.getInsertions());
+ statementParameterProcessor.setParams(connection, statement, paramSQLString);
int count = statement.executeUpdate();
Object lastInsertedId = null;
@@ -184,19 +183,20 @@ private static Object nativeBatchExecuteExecutable(BObject client, BArray paramS
Connection connection = null;
PreparedStatement statement = null;
String sqlQuery = null;
- List