Skip to content
Permalink
Browse files

[CONJ-717] conversion function support for other data type than defau…

…lt MariaDB conversion type.

MariaDB support datatype conversion for :
BINARY
CHAR
DATE
DATETIME
DECIMAL[(M[,D])]
DOUBLE
FLOAT — From MariaDB 10.4.5
INTEGER
TIME

JDBC spec 4.2 support (C.5):
CONVERT(value, SQLtype) value converted to SQLtype where SQLtype may be one of the following SQL
types:
SQL_BIGINT, SQL_BINARY, SQL_BIT, SQL_BLOB, SQL_BOOLEAN,
SQL_CHAR, SQL_CLOB, SQL_DATE, SQL_DECIMAL, SQL_DATALINK,
SQL_DOUBLE, SQL_FLOAT, SQL_INTEGER, SQL_LONGVARBINARY,
SQL_LONGNVARCHAR, SQL_LONGVARCHAR, SQL_NCHAR, SQL_NCLOB, SQL_NUMERIC, SQL_NVARCHAR, SQL_REAL, SQL_ROWID,
SQL_SQLXML, SQL_SMALLINT, SQL_TIME, SQL_TIMESTAMP, SQL_TINYINT, SQL_VARBINARY, or SQL_VARCHAR

MariaDB server support automatic conversion, but datatype must correspond to expected type (i.e convert(2147483648, INTEGER ) Will result in a BIG_INT datatype).
  • Loading branch information...
rusher committed Jul 26, 2019
1 parent d8603ee commit c7074aad69e129b97e0e23a7e1c7472df2a924ff
@@ -230,7 +230,7 @@ private static int getImportedKeyAction(String actionKey) {
* @throws ParseException exception
*/
private static ResultSet getImportedKeys(String tableDef, String tableName, String catalog,
MariaDbConnection connection) throws ParseException {
MariaDbConnection connection) throws ParseException {
String[] columnNames = {
"PKTABLE_CAT", "PKTABLE_SCHEM", "PKTABLE_NAME",
"PKCOLUMN_NAME", "FKTABLE_CAT", "FKTABLE_SCHEM",
@@ -628,7 +628,7 @@ private String mapTableTypes(String tableType) {
* @see #getSearchStringEscape
*/
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern,
String[] types)
String[] types)
throws SQLException {

StringBuilder sql =
@@ -737,7 +737,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
* @see #getSearchStringEscape
*/
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern)
String columnNamePattern)
throws SQLException {
Options options = urlParser.getOptions();
String sql = "SELECT TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM, TABLE_NAME, COLUMN_NAME,"
@@ -999,7 +999,7 @@ public ResultSet getImportedKeysUsingShowCreateTable(String catalog, String tabl
* @throws SQLException if a database access error occurs
*/
public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope,
final boolean nullable)
final boolean nullable)
throws SQLException {

if (table == null) {
@@ -1083,7 +1083,7 @@ public boolean generatedKeyAlwaysReturned() {
* @since 1.7
*/
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern) throws SQLException {
String columnNamePattern) throws SQLException {
return connection.createStatement().executeQuery(
"SELECT ' ' TABLE_CAT, ' ' TABLE_SCHEM,"
+ "' ' TABLE_NAME, ' ' COLUMN_NAME, 0 DATA_TYPE, 0 COLUMN_SIZE, 0 DECIMAL_DIGITS,"
@@ -1140,7 +1140,7 @@ public String getDatabaseProductName() throws SQLException {
return "MySQL";
}
if (connection.getProtocol().isServerMariaDb()
&& connection.getProtocol().getServerVersion().toLowerCase(Locale.ROOT).contains("mariadb")) {
&& connection.getProtocol().getServerVersion().toLowerCase(Locale.ROOT).contains("mariadb")) {
return "MariaDB";
}
return "MySQL";
@@ -1314,8 +1314,159 @@ public boolean supportsConvert() {
return true;
}

/**
* Retrieves whether this database supports the JDBC scalar function CONVERT for conversions between the JDBC types
* fromType and toType. The JDBC types are the generic SQL data types defined in java.sql.Types.
*
* @param fromType the type to convert from; one of the type codes from the class java.sql.Types
* @param toType the type to convert to; one of the type codes from the class java.sql.Types
* @return true if so; false otherwise
*/
public boolean supportsConvert(int fromType, int toType) {
return false;
switch (fromType) {
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DECIMAL:
case Types.NUMERIC:
case Types.DOUBLE:
case Types.BIT:
case Types.BOOLEAN:
switch (toType) {
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DECIMAL:
case Types.NUMERIC:
case Types.DOUBLE:
case Types.BIT:
case Types.BOOLEAN:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return true;
default:
return false;
}

case Types.BLOB:
switch (toType) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.REAL:
case Types.FLOAT:
case Types.DECIMAL:
case Types.NUMERIC:
case Types.DOUBLE:
case Types.BIT:
case Types.BOOLEAN:
return true;
default:
return false;
}

case Types.CHAR:
case Types.CLOB:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
switch (toType) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.NUMERIC:
case Types.DECIMAL:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.BLOB:
case Types.CLOB:
case Types.BOOLEAN:
case Types.NCHAR:
case Types.LONGNVARCHAR:
case Types.NCLOB:
return true;
default:
return false;
}

case Types.DATE:
switch (toType) {
case Types.DATE:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return true;

default:
return false;
}

case Types.TIME:
switch (toType) {
case Types.TIME:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
return true;
default:
return false;
}

case Types.TIMESTAMP:
switch (toType) {
case Types.TIMESTAMP:
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.TIME:
case Types.DATE:
return true;
default:
return false;
}
default:
return false;
}
}

public boolean supportsTableCorrelationNames() {
@@ -1331,7 +1482,7 @@ public boolean supportsExpressionsInOrderBy() {
}

public boolean supportsOrderByUnrelated() {
return false;
return true;
}

public boolean supportsGroupBy() {
@@ -1384,24 +1535,24 @@ public boolean supportsANSI92EntryLevelSQL() {

@Override
public boolean supportsANSI92IntermediateSQL() {
return false;
return true;
}

@Override
public boolean supportsANSI92FullSQL() {
return false;
return true;
}

public boolean supportsIntegrityEnhancementFacility() {
return false;
return true;
}

public boolean supportsOuterJoins() {
return true;
}

public boolean supportsFullOuterJoins() {
return false;
return true;
}

public boolean supportsLimitedOuterJoins() {
@@ -1806,8 +1957,8 @@ private boolean haveInformationSchemaParameters() {
* @see #getSearchStringEscape
*/
public ResultSet getProcedureColumns(String catalog, String schemaPattern,
String procedureNamePattern,
String columnNamePattern) throws SQLException {
String procedureNamePattern,
String columnNamePattern) throws SQLException {
String sql;

if (haveInformationSchemaParameters()) {
@@ -1972,14 +2123,14 @@ public ResultSet getProcedureColumns(String catalog, String schemaPattern,
* @param columnNamePattern a parameter name pattern; must match the parameter or column name as
* it is stored in the database
* @return <code>ResultSet</code> - each row describes a user function parameter, column or
* return type
* return type
* @throws SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.6
*/
public ResultSet getFunctionColumns(String catalog, String schemaPattern,
String functionNamePattern,
String columnNamePattern) throws SQLException {
String functionNamePattern,
String columnNamePattern) throws SQLException {

String sql;
if (haveInformationSchemaParameters()) {
@@ -2076,7 +2227,7 @@ public ResultSet getTableTypes() throws SQLException {
* @see #getSearchStringEscape
*/
public ResultSet getColumnPrivileges(String catalog, String schema, String table,
String columnNamePattern) throws SQLException {
String columnNamePattern) throws SQLException {

if (table == null) {
throw new SQLException("'table' parameter must not be null");
@@ -2252,7 +2403,7 @@ public ResultSet getVersionColumns(String catalog, String schema, String table)
* @see #getImportedKeys
*/
public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable,
String foreignCatalog, String foreignSchema, String foreignTable)
String foreignCatalog, String foreignSchema, String foreignTable)
throws SQLException {

String sql =
@@ -2535,7 +2686,7 @@ public ResultSet getTypeInfo() {
* @throws SQLException if a database access error occurs
*/
public ResultSet getIndexInfo(String catalog, String schema, String table,
boolean unique, boolean approximate) throws SQLException {
boolean unique, boolean approximate) throws SQLException {

String sql =
"SELECT TABLE_SCHEMA TABLE_CAT, NULL TABLE_SCHEM, TABLE_NAME, NON_UNIQUE, "
@@ -2681,7 +2832,7 @@ public boolean supportsBatchUpdates() {
*/
@Override
public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern,
int[] types)
int[] types)
throws SQLException {
String sql =
"SELECT ' ' TYPE_CAT, NULL TYPE_SCHEM, ' ' TYPE_NAME, ' ' CLASS_NAME, 0 DATA_TYPE, ' ' REMARKS, 0 BASE_TYPE"
@@ -2738,7 +2889,7 @@ public boolean supportsGetGeneratedKeys() {
* @param schemaPattern a schema name pattern; "" retrieves those without a schema
* @param typeNamePattern a UDT name pattern; may be a fully-qualified name
* @return a <code>ResultSet</code> object in which a row gives information about the designated
* UDT
* UDT
* @throws SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.4
@@ -2857,7 +3008,7 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
* @since 1.4
*/
public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern,
String attributeNamePattern) throws SQLException {
String attributeNamePattern) throws SQLException {

String sql =
"SELECT ' ' TYPE_CAT, ' ' TYPE_SCHEM, ' ' TYPE_NAME, ' ' ATTR_NAME, 0 DATA_TYPE,"
@@ -2981,22 +3132,22 @@ public ResultSet getClientInfoProperties() {
* <P>Each function description has the the following columns:</p>
*
* <OL>
* <li><B>FUNCTION_CAT</B> String {@code =>} function catalog (may be <code>null</code>)</li>
* <li><B>FUNCTION_SCHEM</B> String {@code =>} function schema (may be <code>null</code>)</li>
* <li><B>FUNCTION_NAME</B> String {@code =>} function name. This is the name used to invoke
* the function </li>
* <li><B>REMARKS</B> String {@code =>} explanatory comment on the function</li>
* <li><B>FUNCTION_TYPE</B> short {@code =>} kind of function:
* <UL>
* <li>functionResultUnknown - Cannot determine if a return value or table will be
* returned</li>
* <li> functionNoTable- Does not return a table</li>
* <li> functionReturnsTable - Returns a table</li>
* </UL>
* </li>
* <li><B>SPECIFIC_NAME</B> String {@code =>} the name which uniquely identifies this function
* within its schema. This is a user specified, or DBMS generated, name that may be different
* then the <code>FUNCTION_NAME</code> for example with overload functions</li>
* <li><B>FUNCTION_CAT</B> String {@code =>} function catalog (may be <code>null</code>)</li>
* <li><B>FUNCTION_SCHEM</B> String {@code =>} function schema (may be <code>null</code>)</li>
* <li><B>FUNCTION_NAME</B> String {@code =>} function name. This is the name used to invoke
* the function </li>
* <li><B>REMARKS</B> String {@code =>} explanatory comment on the function</li>
* <li><B>FUNCTION_TYPE</B> short {@code =>} kind of function:
* <UL>
* <li>functionResultUnknown - Cannot determine if a return value or table will be
* returned</li>
* <li> functionNoTable- Does not return a table</li>
* <li> functionReturnsTable - Returns a table</li>
* </UL>
* </li>
* <li><B>SPECIFIC_NAME</B> String {@code =>} the name which uniquely identifies this function
* within its schema. This is a user specified, or DBMS generated, name that may be different
* then the <code>FUNCTION_NAME</code> for example with overload functions</li>
* </OL>
*
* <p>A user may not have

0 comments on commit c7074aa

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