Changeset: a0e8adf10d41 for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=a0e8adf10d41
Modified Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
Branch: default
Log Message:

Improved ResultSetMetaData methods isAutoIncrement(), getPrecision(), 
getScale(), isNullable().
They could throw an IndexOutOfBoundsException when an invalid column nmber was 
provided. Now it will properly throw an SQLException.

Improved ResultSetMetaData method isCaseSensitive(). It now returns false for 
columns of MonetDB data type: inet or uuid.
Optimised speed of ResultSetMetaData.isSigned() for numerical columns which are 
not mapped to BIGINT.

Improved ParameterMetaData methods isSigned(), getPrecision(), getScale(), 
getParameterType(), getParameterTypeName(), getParameterClassName(), 
isNullable().
They could throw an IndexOutOfBoundsException when an invalid parameter nmber 
was provided. Now it will properly throw an SQLException.


diffs (truncated from 904 to 300 lines):

diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
@@ -8,22 +8,46 @@
 
 package nl.cwi.monetdb.jdbc;
 
-import java.sql.*;
-import java.util.*;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.RoundingMode;
 import java.net.URL;
-import java.io.*;
-import java.nio.*;
-import java.math.*;    // BigDecimal, etc.
+import java.nio.CharBuffer;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.NClob;
+import java.sql.ParameterMetaData;
+import java.sql.PreparedStatement;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLData;
+import java.sql.SQLDataException;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLOutput;
+import java.sql.SQLXML;
+import java.sql.Struct;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
 import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Map;
 
 /**
  * A {@link PreparedStatement} suitable for the MonetDB database.
- * 
+ *
  * This implementation of the PreparedStatement interface uses the
  * capabilities of the MonetDB/SQL backend to prepare and execute
  * queries.  The backend takes care of finding the '?'s in the input and
  * returns the types it expects for them.
- * 
+ *
  * An example of a server response on a prepare query is:
  * <pre>
  * % prepare select name from tables where id &gt; ? and id &lt; ?;
@@ -36,8 +60,8 @@ import java.text.SimpleDateFormat;
  * [ "int",        9,      0       ]
  * </pre>
  *
- * @author Fabian Groffen
- * @version 0.3
+ * @author Fabian Groffen, Martin van Dinther
+ * @version 0.4
  */
 public class MonetPreparedStatement
        extends MonetStatement
@@ -204,7 +228,7 @@ public class MonetPreparedStatement
 
        /**
         * Clears the current parameter values immediately.
-        * 
+        *
         * In general, parameter values remain in force for repeated use of a
         * statement. Setting a parameter value automatically clears its 
previous
         * value. However, in some cases it is useful to immediately release the
@@ -224,7 +248,7 @@ public class MonetPreparedStatement
         * return multiple results; the execute method handles these complex
         * statements as well as the simpler form of statements handled by
         * the methods executeQuery and executeUpdate.
-        * 
+        *
         * The execute method returns a boolean to indicate the form of the
         * first result.  You must call either the method getResultSet or
         * getUpdateCount to retrieve the result; you must call
@@ -331,7 +355,7 @@ public class MonetPreparedStatement
         * Retrieves a ResultSetMetaData object that contains information
         * about the columns of the ResultSet object that will be returned
         * when this PreparedStatement object is executed.
-        * 
+        *
         * Because a PreparedStatement object is precompiled, it is possible
         * to know about the ResultSet object that it will return without
         * having to execute it.  Consequently, it is possible to invoke the
@@ -392,12 +416,20 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public boolean isCaseSensitive(int column) throws 
SQLException {
-                               switch (javaType[getColumnIdx(column)]) {
+                               switch (getColumnType(column)) {
                                        case Types.CHAR:
-                                       case Types.VARCHAR:
                                        case Types.LONGVARCHAR: // MonetDB 
doesn't use type LONGVARCHAR, it's here for completeness
                                        case Types.CLOB:
                                                return true;
+                                       case Types.VARCHAR:
+                                               String monettype = 
getColumnTypeName(column);
+                                               if (monettype != null) {
+                                                       // data of type inet or 
uuid is not case sensitive
+                                                       if 
("inet".equals(monettype)
+                                                        || 
"uuid".equals(monettype))
+                                                               return false;
+                                               }
+                                               return true;
                                }
 
                                return false;
@@ -442,24 +474,25 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public boolean isSigned(int column) throws SQLException 
{
-                               String monettype = getColumnTypeName(column);
-                               if (monettype != null) {
-                                       if ("oid".equals(monettype)
-                                        || "ptr".equals(monettype))
-                                               return false;
-                               }
                                // we can hardcode this, based on the colum type
-                               switch (javaType[getColumnIdx(column)]) {
+                               switch (getColumnType(column)) {
                                        case Types.NUMERIC:
                                        case Types.DECIMAL:
                                        case Types.TINYINT:
                                        case Types.SMALLINT:
                                        case Types.INTEGER:
-                                       case Types.BIGINT:
                                        case Types.REAL:
                                        case Types.FLOAT:
                                        case Types.DOUBLE:
                                                return true;
+                                       case Types.BIGINT:
+                                               String monettype = 
getColumnTypeName(column);
+                                               if (monettype != null) {
+                                                       if 
("oid".equals(monettype)
+                                                        || 
"ptr".equals(monettype))
+                                                               return false;
+                                               }
+                                               return true;
                                        case Types.BIT: // we don't use type 
BIT, it's here for completeness
                                        case Types.BOOLEAN:
                                        case Types.DATE:
@@ -481,7 +514,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public int getColumnDisplaySize(int column) throws 
SQLException {
-                               return digits[getColumnIdx(column)];
+                               try {
+                                       return digits[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -493,7 +530,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public String getSchemaName(int column) throws 
SQLException {
-                               return schema[getColumnIdx(column)];
+                               try {
+                                       return schema[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -503,8 +544,12 @@ public class MonetPreparedStatement
                         * @return table name or "" if not applicable
                         */
                        @Override
-                       public String getTableName(int col) throws SQLException 
{
-                               return table[getColumnIdx(col)];
+                       public String getTableName(int column) throws 
SQLException {
+                               try {
+                                       return table[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -519,7 +564,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public int getPrecision(int column) throws SQLException 
{
-                               return digits[getColumnIdx(column)];
+                               try {
+                                       return digits[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -534,7 +583,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public int getScale(int column) throws SQLException {
-                               return scale[getColumnIdx(column)];
+                               try {
+                                       return scale[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -619,7 +672,7 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public String getColumnClassName(int column) throws 
SQLException {
-                               return 
MonetResultSet.getClassForType(javaType[getColumnIdx(column)]).getName();
+                               return 
MonetResultSet.getClassForType(getColumnType(column)).getName();
                        }
 
                        /**
@@ -644,8 +697,12 @@ public class MonetPreparedStatement
                         * @throws SQLException if there is no such column
                         */
                        @Override
-                       public String getColumnName(int col) throws 
SQLException {
-                               return column[getColumnIdx(col)];
+                       public String getColumnName(int colnr) throws 
SQLException {
+                               try {
+                                       return column[getColumnIdx(colnr)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(colnr);
+                               }
                        }
 
                        /**
@@ -657,7 +714,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public int getColumnType(int column) throws 
SQLException {
-                               return javaType[getColumnIdx(column)];
+                               try {
+                                       return javaType[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
 
                        /**
@@ -671,7 +732,11 @@ public class MonetPreparedStatement
                         */
                        @Override
                        public String getColumnTypeName(int column) throws 
SQLException {
-                               return monetdbType[getColumnIdx(column)];
+                               try {
+                                       return 
monetdbType[getColumnIdx(column)];
+                               } catch (IndexOutOfBoundsException e) {
+                                       throw 
MonetResultSet.newSQLInvalidColumnIndexException(column);
+                               }
                        }
                };
        }
@@ -713,14 +778,14 @@ public class MonetPreparedStatement
                        /**
                         * Retrieves whether null values are allowed in the
                         * designated parameter.
-                        * 
+                        *
                         * This is currently always unknown for MonetDB/SQL.
                         *
-                        * @param param the first parameter is 1, the second is 
2, ... 
+                        * @param param the first parameter is 1, the second is 
2, ...
                         * @return the nullability status of the given 
parameter;
                         *         one of ParameterMetaData.parameterNoNulls,
                         *         ParameterMetaData.parameterNullable, or
-                        *         ParameterMetaData.parameterNullableUnknown 
+                        *         ParameterMetaData.parameterNullableUnknown
                         * @throws SQLException if a database access error 
occurs
                         */
                        @Override
@@ -732,15 +797,14 @@ public class MonetPreparedStatement
                         * Retrieves whether values for the designated 
parameter can
                         * be signed numbers.
                         *
-                        * @param param the first parameter is 1, the second is 
2, ... 
-                        * @return true if so; false otherwise 
+                        * @param param the first parameter is 1, the second is 
2, ...
+                        * @return true if so; false otherwise
                         * @throws SQLException if a database access error 
occurs
                         */
                        @Override
                        public boolean isSigned(int param) throws SQLException {
                                // we can hardcode this, based on the colum type
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to