annotate src/main/java/org/monetdb/jdbc/MonetParameterMetaData.java @ 758:37eae5a78c1b

Add extra null check to prevent NPE.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 29 Jun 2023 14:08:44 +0200 (22 months ago)
parents 3dd0d43014e8
children e890195256ac
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 /*
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
2 * 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
3 * 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
4 * 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
5 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2023 MonetDB B.V.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
7 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
8
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
9 package org.monetdb.jdbc;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
10
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
11 import java.sql.ParameterMetaData;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
12 import java.sql.SQLDataException;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
13 import java.sql.SQLException;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
14 import java.sql.Types;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
15
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
16 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
17 *<pre>
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
18 * 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
19 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
20 * 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
21 * 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
22 *</pre>
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 * @author Martin van Dinther
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
25 * @version 1.0
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
26 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
27 final class MonetParameterMetaData
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
28 extends MonetWrapper
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
29 implements ParameterMetaData
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 /** The parental Connection object */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
32 private final MonetConnection conn;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
33
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
34 /** 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
35 private final int paramCount;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
36
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
37 /** 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
38 private final String[] monetdbTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
39 /** 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
40 private final int[] JdbcSQLTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
41 /** 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
42 private final int[] precisions;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
43 /** 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
44 private final int[] scales;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
45
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
46 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
47 * 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
48 * It is used by MonetPreparedStatement.
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 * @param connection the parent connection
720
99baab703566 Resolve some javac -Xdoclint warnings
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents: 719
diff changeset
51 * @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
52 * @param types the MonetDB type names
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
53 * @param jdbcTypes the JDBC SQL type codes
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
54 * @param precisions the precision for each parameter
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
55 * @param scales the scale for each parameter
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
56 * @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
57 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
58 MonetParameterMetaData(
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
59 final MonetConnection connection,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
60 final int paramcount,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
61 final String[] types,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
62 final int[] jdbcTypes,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
63 final int[] precisions,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
64 final int[] scales)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
65 throws IllegalArgumentException
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
66 {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
67 if (connection == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
68 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
69 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
70 if (types == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
71 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
72 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
73 if (jdbcTypes == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
74 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
75 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
76 if (precisions == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
77 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
78 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
79 if (scales == null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
80 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
81 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
82 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
83 throw new IllegalArgumentException("Inconsistent Parameters metadata");
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
84 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
85 this.conn = connection;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
86 this.paramCount = paramcount;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
87 this.monetdbTypes = types;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
88 this.JdbcSQLTypes = jdbcTypes;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
89 this.precisions = precisions;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
90 this.scales = scales;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
91 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
92
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
93 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
94 * 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
95 * for which this ParameterMetaData object contains information.
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 * @return the number of parameters
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
98 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
99 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
100 public int getParameterCount() {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
101 return paramCount;
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
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
104 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
105 * 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
106 * designated parameter.
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 * 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
109 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
110 * @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
111 * @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
112 * one of ParameterMetaData.parameterNoNulls,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
113 * ParameterMetaData.parameterNullable, or
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
114 * ParameterMetaData.parameterNullableUnknown
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
115 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
116 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
117 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
118 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
119 return ParameterMetaData.parameterNullableUnknown;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
120 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
121
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
122 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
123 * 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
124 * be signed numbers.
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 * @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
127 * @return true if so; false otherwise
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
128 * @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
129 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
130 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
131 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
132 // 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
133 switch (getParameterType(param)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
134 case Types.TINYINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
135 case Types.SMALLINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
136 case Types.INTEGER:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
137 case Types.REAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
138 case Types.FLOAT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
139 case Types.DOUBLE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
140 case Types.DECIMAL:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
141 case Types.NUMERIC:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
142 return true;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
143 case Types.BIGINT:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
144 final String monettype = getParameterTypeName(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
145 if (monettype != null && monettype.length() == 3) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
146 // data of type oid or ptr is not signed
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
147 if ("oid".equals(monettype)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
148 || "ptr".equals(monettype))
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
149 return false;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
150 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
151 return true;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
152 // All other types should return false
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
153 // case Types.BOOLEAN:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
154 // case Types.DATE: // can year be negative?
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
155 // case Types.TIME: // can time be negative?
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
156 // case Types.TIME_WITH_TIMEZONE:
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
157 // case Types.TIMESTAMP: // can year be negative?
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
158 // case Types.TIMESTAMP_WITH_TIMEZONE:
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 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
296 if ("day_interval".equals(monettype))
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
297 return "interval day";
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
298 if ("month_interval".equals(monettype))
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
299 return "interval month";
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
300 if ("sec_interval".equals(monettype))
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
301 return "interval second";
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
302 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
303 return monettype;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
304 } catch (IndexOutOfBoundsException e) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
305 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
306 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
307 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
308
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
309 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
310 * 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
311 * 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
312 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
313 * @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
314 * @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
315 * 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
316 * method PreparedStatement.setObject to set the
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
317 * 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
318 * class name used for custom mapping.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
319 * @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
320 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
321 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
322 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
323 final String MonetDBType = getParameterTypeName(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
324 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
325 final Class<?> type;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
326 if (map != null && map.containsKey(MonetDBType)) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
327 type = (Class)map.get(MonetDBType);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
328 } else {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
329 type = MonetDriver.getClassForType(getParameterType(param));
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 if (type != null) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
332 return type.getCanonicalName();
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
333 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
334 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
335 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
336
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
337 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
338 * Retrieves the designated parameter's mode.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
339 * 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
340 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
341 * @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
342 * @return mode of the parameter; one of
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
343 * ParameterMetaData.parameterModeIn,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
344 * ParameterMetaData.parameterModeOut,
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
345 * ParameterMetaData.parameterModeInOut or
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
346 * ParameterMetaData.parameterModeUnknown.
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
347 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
348 @Override
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
349 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
350 checkParameterIndexValidity(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
351 return ParameterMetaData.parameterModeIn;
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
352 }
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 * 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
357 *
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
358 * @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
359 * @throws SQLDataException when invalid parameter index number
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
360 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
361 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
362 if (param < 1 || param > paramCount)
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
363 throw newSQLInvalidParameterIndexException(param);
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
364 }
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 /**
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
367 * 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
368 * 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
369 * to "22010": invalid indicator parameter value.
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 * @param paramIdx the parameter index number
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
372 * @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
373 */
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
374 private final SQLDataException newSQLInvalidParameterIndexException(final int paramIdx) {
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
375 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
376 }
2f42195e9c58 Improved implementation of PreparedStatement.getParameterMetaData().
Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
parents:
diff changeset
377 }