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

Handle unsupported array type gracefully #856

Merged
merged 4 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerinax"
name = "mysql"
version = "1.7.0"
version = "1.7.1"
authors = ["Ballerina"]
keywords = ["database", "client", "network", "SQL", "RDBMS", "MySQL"]
repository = "https://github.com/ballerina-platform/module-ballerinax-mysql"
Expand All @@ -12,8 +12,8 @@ distribution = "2201.4.0"
[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "mysql-native"
version = "1.7.0"
path = "../native/build/libs/mysql-native-1.7.0.jar"
version = "1.7.1"
path = "../native/build/libs/mysql-native-1.7.1-SNAPSHOT.jar"

[[platform.java11.dependency]]
groupId = "io.ballerina.stdlib"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "mysql-compiler-plugin"
class = "io.ballerina.stdlib.mysql.compiler.MySQLCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/mysql-compiler-plugin-1.7.0.jar"
path = "../compiler-plugin/build/libs/mysql-compiler-plugin-1.7.1-SNAPSHOT.jar"
7 changes: 4 additions & 3 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,15 @@ dependencies = [
[[package]]
org = "ballerina"
name = "oauth2"
version = "2.6.0"
version = "2.6.1"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "cache"},
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "log"},
{org = "ballerina", name = "time"}
{org = "ballerina", name = "time"},
{org = "ballerina", name = "url"}
]

[[package]]
Expand Down Expand Up @@ -391,7 +392,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "mysql"
version = "1.7.0"
version = "1.7.1"
dependencies = [
{org = "ballerina", name = "crypto"},
{org = "ballerina", name = "file"},
Expand Down
13 changes: 13 additions & 0 deletions ballerina/tests/error.bal
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,16 @@ function TestInsertedValueTooLarge() returns error? {
"INSERT INTO test(A) VALUES ('123'). Data truncation: Data too long for column 'A' at row 1."),
sqlerror.message());
}

@test:Config {
groups: ["error"]
}
function TestArrayDataType() returns error? {
string[] stringArray = [];
Client dbClient = check new (host, user, password, errorDB, port);
string|error err = dbClient->queryRow(`SELECT * from DataTable WHERE ROW_ID = ${stringArray}`);
check dbClient.close();
test:assertTrue(err is sql:DataError);
sql:DataError sqlerror = <sql:DataError>err;
test:assertTrue(strings:includes(sqlerror.message(), "MySQL does not support ARRAY data type."), sqlerror.message());
}
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- [Handle unsupported array type gracefully](https://github.com/ballerina-platform/ballerina-standard-library/issues/4201)

## [1.7.0] - 2023-02-20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.mysql.parameterprocessor.MysqlResultParameterProcessor;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessor;
import io.ballerina.stdlib.mysql.parameterprocessor.MysqlStatementParameterProcessor;

/**
* This class holds the utility methods involved with executing the call statements.
Expand All @@ -35,7 +35,7 @@ private CallProcessor() {

public static Object nativeCall(Environment env, BObject client, BObject paramSQLString, BArray recordTypes) {
return io.ballerina.stdlib.sql.nativeimpl.CallProcessor.nativeCall(env, client, paramSQLString,
recordTypes, DefaultStatementParameterProcessor.getInstance(),
recordTypes, MysqlStatementParameterProcessor.getInstance(),
MysqlResultParameterProcessor.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessor;
import io.ballerina.stdlib.mysql.parameterprocessor.MysqlStatementParameterProcessor;

/**
* This class contains methods for executing SQL queries.
Expand All @@ -34,11 +34,11 @@ private ExecuteProcessor() {

public static Object nativeExecute(Environment env, BObject client, BObject paramSQLString) {
return io.ballerina.stdlib.sql.nativeimpl.ExecuteProcessor.nativeExecute(env, client, paramSQLString,
DefaultStatementParameterProcessor.getInstance());
MysqlStatementParameterProcessor.getInstance());
}

public static Object nativeBatchExecute(Environment env, BObject client, BArray paramSQLStrings) {
return io.ballerina.stdlib.sql.nativeimpl.ExecuteProcessor.nativeBatchExecute(env, client, paramSQLStrings,
DefaultStatementParameterProcessor.getInstance());
MysqlStatementParameterProcessor.getInstance());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.ballerina.runtime.api.values.BStream;
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.stdlib.mysql.parameterprocessor.MysqlResultParameterProcessor;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessor;
import io.ballerina.stdlib.mysql.parameterprocessor.MysqlStatementParameterProcessor;

/**
* This class provides the methods for query processing which executes sql queries.
Expand All @@ -36,15 +36,15 @@ private QueryProcessor() {

public static BStream nativeQuery(Environment env, BObject client, BObject paramSQLString,
BTypedesc recordType) {
DefaultStatementParameterProcessor statementParametersProcessor = DefaultStatementParameterProcessor
MysqlStatementParameterProcessor statementParametersProcessor = MysqlStatementParameterProcessor
.getInstance();
MysqlResultParameterProcessor resultParametersProcessor = MysqlResultParameterProcessor.getInstance();
return io.ballerina.stdlib.sql.nativeimpl.QueryProcessor.nativeQuery(env, client, paramSQLString, recordType,
statementParametersProcessor, resultParametersProcessor);
}

public static Object nativeQueryRow(Environment env, BObject client, BObject paramSQLString, BTypedesc recordType) {
DefaultStatementParameterProcessor statementParametersProcessor = DefaultStatementParameterProcessor
MysqlStatementParameterProcessor statementParametersProcessor = MysqlStatementParameterProcessor
.getInstance();
MysqlResultParameterProcessor resultParametersProcessor = MysqlResultParameterProcessor.getInstance();
return io.ballerina.stdlib.sql.nativeimpl.QueryProcessor.nativeQueryRow(env, client, paramSQLString, recordType,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 LLC. 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.mysql.parameterprocessor;

import io.ballerina.stdlib.sql.exception.DataError;
import io.ballerina.stdlib.sql.parameterprocessor.DefaultStatementParameterProcessor;

import java.sql.Connection;
import java.sql.PreparedStatement;

/**
* This class has implementation of methods required process the MySQL Prepared Statement.
* Setters are used to set designated parameters to the PreparedStatement.
*/
public class MysqlStatementParameterProcessor extends DefaultStatementParameterProcessor {
private static final MysqlStatementParameterProcessor instance = new MysqlStatementParameterProcessor();

private MysqlStatementParameterProcessor(){
}

public static MysqlStatementParameterProcessor getInstance() {
return instance;
}

@Override
protected void setVarcharArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setCharArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setNVarcharArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setBitArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setBooleanArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setIntegerArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setBigIntArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setSmallIntArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setFloatArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setRealArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setDoubleArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setNumericArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setDecimalArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setBinaryArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setVarBinaryArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setDateTimeArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setTimestampArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setDateArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}

@Override
protected void setTimeArray(Connection conn, PreparedStatement preparedStatement, int index, Object value)
throws DataError {
throw new DataError("MySQL does not support ARRAY data type.");
}
}