Skip to content
Permalink
Browse files

[CONJ-643] PreparedStatement::getParameterMetaData always returns VAR…

…STRING as type resulting in downstream libraries interpreting values wrongly

(cherry picked from commit 7b0c932)
  • Loading branch information...
rusher committed Sep 5, 2018
1 parent c0ebfda commit c59b2126aee855cdde3c73938e851c45a1d8d336
@@ -53,11 +53,11 @@

package org.mariadb.jdbc;

import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.ColumnInformation;

import java.sql.ParameterMetaData;
import java.sql.SQLException;
import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.ColumnInformation;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;

/**
* Very basic info about the parameterized query, only reliable method is getParameterCount().
@@ -118,9 +118,18 @@ public int getScale(int param) throws SQLException {
return 0;
}

/**
* Parameter type are not sent by server.
*
* See https://jira.mariadb.org/browse/CONJ-568 and https://jira.mariadb.org/browse/MDEV-15031
*
* @param param parameter number
* @return SQL type from java.sql.Types
* @throws SQLException a feature not supported, since server doesn't sent the right information
*/
@Override
public int getParameterType(int param) throws SQLException {
return getParameterInformation(param).getColumnType().getSqlType();
throw ExceptionMapper.getFeatureNotSupportedException("Getting parameter type metadata are not supported");
}

@Override
@@ -52,24 +52,46 @@

package org.mariadb.jdbc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.sun.jna.Platform;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.SQLSyntaxErrorException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mariadb.jdbc.internal.util.DefaultOptions;
import org.mariadb.jdbc.internal.util.constant.HaMode;

import java.math.BigDecimal;
import java.sql.*;
import java.sql.Date;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.*;


public class DriverTest extends BaseTest {

@@ -197,6 +219,21 @@ public void preparedTest() throws SQLException {
assertEquals(2, prepStmt.getParameterMetaData().getParameterCount());
}

@Test
public void parameterMetaDataTypeNotAvailable() throws SQLException {
String query = "SELECT * FROM DriverTestt4 WHERE test = ? and id = ?";
PreparedStatement prepStmt = sharedConnection.prepareStatement(query);
ParameterMetaData parameterMetaData = prepStmt.getParameterMetaData();
assertEquals(2, parameterMetaData.getParameterCount());
try {
parameterMetaData.getParameterType(1);
fail("must have thrown an error");
} catch (SQLException sqle) {
assertTrue( sqle instanceof SQLFeatureNotSupportedException);
}
prepStmt.close();
}

@Test
public void parameterMetaDataNotPreparable() throws SQLException {
Assume.assumeFalse(sharedUsePrepare());

0 comments on commit c59b212

Please sign in to comment.
You can’t perform that action at this time.