2
Copyright (C) 2005 MySQL AB
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of version 2 of the GNU General Public License as
6
published by the Free Software Foundation.
8
There are special exceptions to the terms and conditions of the GPL
9
as it is applied to this software. View the full text of the
10
exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11
software distribution.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
package com.mysql.jdbc;
26
import java.sql.ParameterMetaData;
27
import java.sql.SQLException;
28
import java.sql.Types;
30
public class MysqlParameterMetadata implements ParameterMetaData {
31
boolean returnSimpleMetadata = false;
32
ResultSetMetaData metadata = null;
33
int parameterCount = 0;
36
MysqlParameterMetadata(Field[] fieldInfo, int parameterCount) {
37
this.metadata = new ResultSetMetaData(fieldInfo, false);
39
this.parameterCount = parameterCount;
43
* Used for "fake" basic metadata for client-side prepared statements
44
* when we don't know the parameter types.
46
* @param parameterCount
48
MysqlParameterMetadata(int count) {
49
this.parameterCount = count;
50
this.returnSimpleMetadata = true;
53
public int getParameterCount() throws SQLException {
54
return this.parameterCount;
57
public int isNullable(int arg0) throws SQLException {
60
return this.metadata.isNullable(arg0);
63
private void checkAvailable() throws SQLException {
64
if (this.metadata == null || this.metadata.fields == null) {
65
throw SQLError.createSQLException(
66
"Parameter metadata not available for the given statement",
67
SQLError.SQL_STATE_DRIVER_NOT_CAPABLE);
71
public boolean isSigned(int arg0) throws SQLException {
72
if (this.returnSimpleMetadata) {
80
return (this.metadata.isSigned(arg0));
83
public int getPrecision(int arg0) throws SQLException {
84
if (this.returnSimpleMetadata) {
92
return (this.metadata.getPrecision(arg0));
95
public int getScale(int arg0) throws SQLException {
96
if (this.returnSimpleMetadata) {
104
return (this.metadata.getScale(arg0));
107
public int getParameterType(int arg0) throws SQLException {
108
if (this.returnSimpleMetadata) {
111
return Types.VARCHAR;
116
return (this.metadata.getColumnType(arg0));
119
public String getParameterTypeName(int arg0) throws SQLException {
120
if (this.returnSimpleMetadata) {
128
return (this.metadata.getColumnTypeName(arg0));
131
public String getParameterClassName(int arg0) throws SQLException {
132
if (this.returnSimpleMetadata) {
135
return "java.lang.String";
140
return (this.metadata.getColumnClassName(arg0));
143
public int getParameterMode(int arg0) throws SQLException {
144
return parameterModeIn;
147
private void checkBounds(int paramNumber) throws SQLException {
148
if (paramNumber < 1) {
149
throw SQLError.createSQLException("Parameter index of '" + paramNumber +
151
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
154
if (paramNumber > this.parameterCount) {
155
throw SQLError.createSQLException("Parameter index of '" + paramNumber +
156
"' is greater than number of parameters, which is '" +
157
this.parameterCount + "'.",
158
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);