annotate src/main/java/org/monetdb/jdbc/MonetParameterMetaData.java @ 887:674f9ed21308

Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types. Also extended test Test_Interval_Types() to test all 13 interval types, both as result column and as parameter.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 04 Apr 2024 12:56:33 +0200 (13 months ago)
parents e1f00e0e3598
children 549225b7be85
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
1 /*
833
e890195256ac Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents: 758
diff changeset
2 * SPDX-License-Identifier: MPL-2.0
e890195256ac Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents: 758
diff changeset
3 *
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
4 * This Source Code Form is subject to the terms of the Mozilla Public
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
7 *
833
e890195256ac Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents: 758
diff changeset
8 * Copyright 2024 MonetDB Foundation;
e890195256ac Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents: 758
diff changeset
9 * Copyright August 2008 - 2023 MonetDB B.V.;
e890195256ac Update copyright for the new year, move to MonetDB Foundation, add SPDX.
Sjoerd Mullender <sjoerd@acm.org>
parents: 758
diff changeset
10 * Copyright 1997 - July 2008 CWI.
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
11 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
12
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
13 package org.monetdb.jdbc;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
14
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
15 import java.sql.ParameterMetaData;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
16 import java.sql.SQLDataException;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
17 import java.sql.SQLException;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
18 import java.sql.Types;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
19
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
20 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
21 *<pre>
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
22 * A {@link ParameterMetaData} suitable for the MonetDB database.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
23 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
24 * An object that can be used to get information about the types and properties
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
25 * for each parameter marker in a PreparedStatement or CallableStatement object.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
26 *</pre>
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
27 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
28 * @author Martin van Dinther
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
29 * @version 1.0
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
30 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
31 final class MonetParameterMetaData
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
32 extends MonetWrapper
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
33 implements ParameterMetaData
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
34 {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
35 /** The parental Connection object */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
36 private final MonetConnection conn;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
37
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
38 /** The number of parameters, it can be zero !! */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
39 private final int paramCount;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
40
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
41 /** The MonetDB type names of the parameters in the PreparedStatement */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
42 private final String[] monetdbTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
43 /** The JDBC SQL type codes of the parameters in the PreparedStatement */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
44 private final int[] JdbcSQLTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
45 /** The precisions of the parameters in the PreparedStatement */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
46 private final int[] precisions;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
47 /** The scales of the parameters in the PreparedStatement */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
48 private final int[] scales;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
49
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
50 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
51 * Constructor backed by the given connection and metadata arrays.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
52 * It is used by MonetPreparedStatement.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
53 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
54 * @param connection the parent connection
720
99baab703566 Resolve some javac -Xdoclint warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 719
diff changeset
55 * @param paramcount the number of parameters, it can be zero !!
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
56 * @param types the MonetDB type names
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
57 * @param jdbcTypes the JDBC SQL type codes
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
58 * @param precisions the precision for each parameter
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
59 * @param scales the scale for each parameter
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
60 * @throws IllegalArgumentException if called with null for one of the arguments
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
61 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
62 MonetParameterMetaData(
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
63 final MonetConnection connection,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
64 final int paramcount,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
65 final String[] types,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
66 final int[] jdbcTypes,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
67 final int[] precisions,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
68 final int[] scales)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
69 throws IllegalArgumentException
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
70 {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
71 if (connection == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
72 throw new IllegalArgumentException("Connection may not be null!");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
73 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
74 if (types == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
75 throw new IllegalArgumentException("MonetDB Types may not be null!");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
76 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
77 if (jdbcTypes == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
78 throw new IllegalArgumentException("JDBC Types may not be null!");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
79 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
80 if (precisions == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
81 throw new IllegalArgumentException("Precisions may not be null!");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
82 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
83 if (scales == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
84 throw new IllegalArgumentException("Scales may not be null!");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
85 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
86 if (types.length != precisions.length || types.length != (paramcount +1)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
87 throw new IllegalArgumentException("Inconsistent Parameters metadata");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
88 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
89 this.conn = connection;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
90 this.paramCount = paramcount;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
91 this.monetdbTypes = types;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
92 this.JdbcSQLTypes = jdbcTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
93 this.precisions = precisions;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
94 this.scales = scales;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
95 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
96
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
97 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
98 * Retrieves the number of parameters in the PreparedStatement object
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
99 * for which this ParameterMetaData object contains information.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
100 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
101 * @return the number of parameters
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
102 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
103 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
104 public int getParameterCount() {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
105 return paramCount;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
106 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
107
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
108 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
109 * Retrieves whether null values are allowed in the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
110 * designated parameter.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
111 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
112 * This is currently always unknown for MonetDB/SQL.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
113 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
114 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
115 * @return the nullability status of the given parameter;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
116 * one of ParameterMetaData.parameterNoNulls,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
117 * ParameterMetaData.parameterNullable, or
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
118 * ParameterMetaData.parameterNullableUnknown
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
119 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
120 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
121 public int isNullable(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
122 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
123 return ParameterMetaData.parameterNullableUnknown;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
124 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
125
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
126 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
127 * Retrieves whether values for the designated parameter can
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
128 * be signed numbers.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
129 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
130 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
131 * @return true if so; false otherwise
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
132 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
133 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
134 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
135 public boolean isSigned(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
136 // we can hardcode this, based on the parameter type
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
137 switch (getParameterType(param)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
138 case Types.TINYINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
139 case Types.SMALLINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
140 case Types.INTEGER:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
141 case Types.REAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
142 case Types.FLOAT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
143 case Types.DOUBLE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
144 case Types.DECIMAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
145 case Types.NUMERIC:
885
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
146 case Types.DATE: // year can be negative
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
147 case Types.TIMESTAMP: // year can be negative
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
148 case Types.TIMESTAMP_WITH_TIMEZONE:
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
149 return true;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
150 case Types.BIGINT:
885
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
151 {
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
152 final String monettype = getParameterTypeName(param);
885
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
153 // data of type oid or ptr is not signed
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
154 if ("oid".equals(monettype)
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
155 || "ptr".equals(monettype))
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
156 return false;
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
157 return true;
885
e1f00e0e3598 Improve isSigned() information on result columns and parameters of Types.DATE, Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE. These can have a negative year.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 833
diff changeset
158 }
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
159 default:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
160 return false;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
161 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
162 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
163
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
164 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
165 * Retrieves the designated parameter's specified column size.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
166 * The returned value represents the maximum column size for
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
167 * the given parameter.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
168 * For numeric data, this is the maximum precision.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
169 * For character data, this is the length in characters.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
170 * For datetime datatypes, this is the length in characters
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
171 * of the String representation (assuming the maximum allowed
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
172 * precision of the fractional seconds component).
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
173 * For binary data, this is the length in bytes.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
174 * For the ROWID datatype, this is the length in bytes.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
175 * 0 is returned for data types where the column size is not applicable.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
176 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
177 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
178 * @return precision
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
179 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
180 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
181 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
182 public int getPrecision(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
183 switch (getParameterType(param)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
184 case Types.BIGINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
185 return 19;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
186 case Types.INTEGER:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
187 return 10;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
188 case Types.SMALLINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
189 return 5;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
190 case Types.TINYINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
191 return 3;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
192 case Types.REAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
193 return 7;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
194 case Types.FLOAT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
195 case Types.DOUBLE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
196 return 15;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
197 case Types.DECIMAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
198 case Types.NUMERIC:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
199 // these data types have a variable precision (max precision is 38)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
200 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
201 return precisions[param];
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
202 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
203 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
204 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
205 case Types.CHAR:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
206 case Types.VARCHAR:
735
3dd0d43014e8 Disable checks for Types.LONGVARCHAR and Types.LONGVARBINARY as MonetDB server does not support these data types, and no mappings exists to these JDBC Types and thus these cases will never be reached in JDBC Driver.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 720
diff changeset
207 /* case Types.LONGVARCHAR: // MonetDB doesn't use type LONGVARCHAR */
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
208 case Types.CLOB:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
209 // these data types have a variable length
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
210 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
211 return precisions[param];
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
212 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
213 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
214 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
215 case Types.BINARY:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
216 case Types.VARBINARY:
735
3dd0d43014e8 Disable checks for Types.LONGVARCHAR and Types.LONGVARBINARY as MonetDB server does not support these data types, and no mappings exists to these JDBC Types and thus these cases will never be reached in JDBC Driver.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 720
diff changeset
217 /* case Types.LONGVARBINARY: // MonetDB doesn't use type LONGVARBINARY */
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
218 case Types.BLOB:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
219 // these data types have a variable length
735
3dd0d43014e8 Disable checks for Types.LONGVARCHAR and Types.LONGVARBINARY as MonetDB server does not support these data types, and no mappings exists to these JDBC Types and thus these cases will never be reached in JDBC Driver.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 720
diff changeset
220 // It expects number of bytes, not number of hex chars
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
221 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
222 return precisions[param];
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
223 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
224 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
225 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
226 case Types.DATE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
227 return 10; // 2020-10-08
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
228 case Types.TIME:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
229 return 15; // 21:51:34.399753
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
230 case Types.TIME_WITH_TIMEZONE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
231 return 21; // 21:51:34.399753+02:00
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
232 case Types.TIMESTAMP:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
233 return 26; // 2020-10-08 21:51:34.399753
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
234 case Types.TIMESTAMP_WITH_TIMEZONE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
235 return 32; // 2020-10-08 21:51:34.399753+02:00
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
236 case Types.BOOLEAN:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
237 return 1;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
238 default:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
239 // All other types should return 0
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
240 return 0;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
241 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
242 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
243
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
244 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
245 * Retrieves the designated parameter's number of digits to
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
246 * right of the decimal point.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
247 * 0 is returned for data types where the scale is not applicable.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
248 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
249 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
250 * @return scale
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
251 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
252 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
253 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
254 public int getScale(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
255 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
256 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
257 return scales[param];
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
258 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
259 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
260 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
261 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
262
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
263 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
264 * Retrieves the designated parameter's SQL type.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
265 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
266 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
267 * @return SQL type from java.sql.Types
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
268 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
269 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
270 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
271 public int getParameterType(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
272 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
273 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
274 return JdbcSQLTypes[param];
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
275 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
276 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
277 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
278 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
279
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
280 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
281 * Retrieves the designated parameter's database-specific type name.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
282 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
283 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
284 * @return type the name used by the database. If the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
285 * parameter type is a user-defined type, then a
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
286 * fully-qualified type name is returned.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
287 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
288 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
289 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
290 public String getParameterTypeName(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
291 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
292 try {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
293 final String monettype = monetdbTypes[param];
758
37eae5a78c1b Add extra null check to prevent NPE.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 735
diff changeset
294 if (monettype != null && monettype.endsWith("_interval")) {
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
295 /* convert the interval type names to valid SQL data type names */
887
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
296 switch (precisions[param]) {
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
297 case 1: return "interval year";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
298 case 2: return "interval year to month";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
299 case 3: return "interval month";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
300 case 4: return "interval day";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
301 case 5: return "interval day to hour";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
302 case 6: return "interval day to minute";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
303 case 7: return "interval day to second";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
304 case 8: return "interval hour";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
305 case 9: return "interval hour to minute";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
306 case 10: return "interval hour to second";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
307 case 11: return "interval minute";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
308 case 12: return "interval minute to second";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
309 case 13: return "interval second";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
310 default:
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
311 { // fall back to the 3 available monettype names
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
312 if ("day_interval".equals(monettype))
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
313 return "interval day";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
314 if ("month_interval".equals(monettype))
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
315 return "interval month";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
316 if ("sec_interval".equals(monettype))
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
317 return "interval second";
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
318 }
674f9ed21308 Improved ResultSetMetaData.getColumnTypeName() and ParameterMetaData.getParameterTypeName() for interval types. It now returns more precise information for the 13 possible interval data types.
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 885
diff changeset
319 }
719
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
320 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
321 return monettype;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
322 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
323 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
324 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
325 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
326
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
327 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
328 * Retrieves the fully-qualified name of the Java class whose instances
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
329 * should be passed to the method PreparedStatement.setObject.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
330 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
331 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
332 * @return the fully-qualified name of the class in the Java
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
333 * programming language that would be used by the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
334 * method PreparedStatement.setObject to set the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
335 * value in the specified parameter. This is the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
336 * class name used for custom mapping.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
337 * @throws SQLException if a database access error occurs
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
338 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
339 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
340 public String getParameterClassName(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
341 final String MonetDBType = getParameterTypeName(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
342 final java.util.Map<String,Class<?>> map = conn.getTypeMap();
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
343 final Class<?> type;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
344 if (map != null && map.containsKey(MonetDBType)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
345 type = (Class)map.get(MonetDBType);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
346 } else {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
347 type = MonetDriver.getClassForType(getParameterType(param));
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
348 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
349 if (type != null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
350 return type.getCanonicalName();
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
351 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
352 throw new SQLException("parameter type mapping null: " + MonetDBType, "M0M03");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
353 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
354
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
355 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
356 * Retrieves the designated parameter's mode.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
357 * For MonetDB/SQL we currently only support INput parameters.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
358 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
359 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
360 * @return mode of the parameter; one of
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
361 * ParameterMetaData.parameterModeIn,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
362 * ParameterMetaData.parameterModeOut,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
363 * ParameterMetaData.parameterModeInOut or
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
364 * ParameterMetaData.parameterModeUnknown.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
365 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
366 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
367 public int getParameterMode(final int param) throws SQLException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
368 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
369 return ParameterMetaData.parameterModeIn;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
370 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
371
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
372
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
373 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
374 * A private utility method to check validity of parameter index number
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
375 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
376 * @param param - the first parameter is 1, the second is 2, ...
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
377 * @throws SQLDataException when invalid parameter index number
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
378 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
379 private final void checkParameterIndexValidity(final int param) throws SQLDataException {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
380 if (param < 1 || param > paramCount)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
381 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
382 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
383
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
384 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
385 * Small helper method that formats the "Invalid Parameter Index number ..."
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
386 * message and creates a new SQLDataException object whose SQLState is set
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
387 * to "22010": invalid indicator parameter value.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
388 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
389 * @param paramIdx the parameter index number
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
390 * @return a new created SQLDataException object with SQLState 22010
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
391 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
392 private final SQLDataException newSQLInvalidParameterIndexException(final int paramIdx) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
393 return new SQLDataException("Invalid Parameter Index number: " + paramIdx, "22010");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
394 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
395 }