Commits

Shantanu Kumar committed a25cf68

improved support for MS-Excel workbooks via JDBC-ODBC bridge driver

Comments (0)

Files changed (4)

 
 ## 0.6 / 2011-Dec-??
 
+- Improved support for MS-Excel workbooks via JDBC-ODBC bridge driver
 - [TODO] properties support in DataSource JDBC URL
-- [TODO] layered .jdbc.properties file
-         - clj-dbcp.properties
-         - jdbc.properties
 - [TODO] protocols for memory-connect, file-connect, net-connect
 - [TODO] MonetDB support
 - [TODO] MckoiDDB support

src/main/java/org/bituf/clj_dbcp/ConnectionWrapper.java

     }
 
     public PreparedStatement prepareStatement(String sql) throws SQLException {
-        return conn.prepareStatement(sql);
+        return new PreparedStatementWrapper(this, conn.prepareStatement(sql));
     }
 
     public CallableStatement prepareCall(String sql) throws SQLException {

src/main/java/org/bituf/clj_dbcp/PreparedStatementWrapper.java

+package org.bituf.clj_dbcp;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.Date;
+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.SQLException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+
+public class PreparedStatementWrapper implements PreparedStatement {
+
+	public final Connection conn;
+	public final PreparedStatement orig;
+	
+	public PreparedStatementWrapper(Connection conn, PreparedStatement orig) {
+		this.conn = conn;
+		this.orig = orig;
+	}
+	
+	public ResultSet executeQuery(String sql) throws SQLException {
+		return orig.executeQuery(sql);
+	}
+
+	public int executeUpdate(String sql) throws SQLException {
+		return orig.executeUpdate(sql);
+	}
+
+	public void close() throws SQLException {
+		orig.close();
+	}
+
+	public int getMaxFieldSize() throws SQLException {
+		return orig.getMaxFieldSize();
+	}
+
+	public void setMaxFieldSize(int max) throws SQLException {
+		orig.setMaxFieldSize(max);
+	}
+
+	public int getMaxRows() throws SQLException {
+		return orig.getMaxRows();
+	}
+
+	public void setMaxRows(int max) throws SQLException {
+		orig.setMaxRows(max);
+	}
+
+	public void setEscapeProcessing(boolean enable) throws SQLException {
+		orig.setEscapeProcessing(enable);
+	}
+
+	public int getQueryTimeout() throws SQLException {
+		return orig.getQueryTimeout();
+	}
+
+	public void setQueryTimeout(int seconds) throws SQLException {
+		orig.setQueryTimeout(seconds);
+	}
+
+	public void cancel() throws SQLException {
+		orig.cancel();
+	}
+
+	public SQLWarning getWarnings() throws SQLException {
+		return orig.getWarnings();
+	}
+
+	public void clearWarnings() throws SQLException {
+		orig.clearWarnings();
+	}
+
+	public void setCursorName(String name) throws SQLException {
+		orig.setCursorName(name);
+	}
+
+	public boolean execute(String sql) throws SQLException {
+		return orig.execute(sql);
+	}
+
+	public ResultSet getResultSet() throws SQLException {
+		return orig.getResultSet();
+	}
+
+	public int getUpdateCount() throws SQLException {
+		return orig.getUpdateCount();
+	}
+
+	public boolean getMoreResults() throws SQLException {
+		return orig.getMoreResults();
+	}
+
+	public void setFetchDirection(int direction) throws SQLException {
+		orig.setFetchDirection(direction);
+	}
+
+	public int getFetchDirection() throws SQLException {
+		return orig.getFetchDirection();
+	}
+
+	public void setFetchSize(int rows) throws SQLException {
+		orig.setFetchSize(rows);
+	}
+
+	public int getFetchSize() throws SQLException {
+		return orig.getFetchSize();
+	}
+
+	public int getResultSetConcurrency() throws SQLException {
+		return orig.getResultSetConcurrency();
+	}
+
+	public int getResultSetType() throws SQLException {
+		return orig.getResultSetType();
+	}
+
+	public void addBatch(String sql) throws SQLException {
+		orig.addBatch(sql);
+	}
+
+	public void clearBatch() throws SQLException {
+		orig.clearBatch();
+	}
+
+	public int[] executeBatch() throws SQLException {
+		return orig.executeBatch();
+	}
+
+	public Connection getConnection() throws SQLException {
+		return conn;
+	}
+
+	public boolean getMoreResults(int current) throws SQLException {
+		return orig.getMoreResults(current);
+	}
+
+	public ResultSet getGeneratedKeys() throws SQLException {
+		return orig.getGeneratedKeys();
+	}
+
+	public int executeUpdate(String sql, int autoGeneratedKeys)
+			throws SQLException {
+		return orig.executeUpdate(sql, autoGeneratedKeys);
+	}
+
+	public int executeUpdate(String sql, int[] columnIndexes)
+			throws SQLException {
+		return orig.executeUpdate(sql, columnIndexes);
+	}
+
+	public int executeUpdate(String sql, String[] columnNames)
+			throws SQLException {
+		return orig.executeUpdate(sql, columnNames);
+	}
+
+	public boolean execute(String sql, int autoGeneratedKeys)
+			throws SQLException {
+		return orig.execute(sql, autoGeneratedKeys);
+	}
+
+	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
+		return orig.execute(sql, columnIndexes);
+	}
+
+	public boolean execute(String sql, String[] columnNames)
+			throws SQLException {
+		return orig.execute(sql, columnNames);
+	}
+
+	public int getResultSetHoldability() throws SQLException {
+		return orig.getResultSetHoldability();
+	}
+
+	public boolean isClosed() throws SQLException {
+		return orig.isClosed();
+	}
+
+	public void setPoolable(boolean poolable) throws SQLException {
+		orig.setPoolable(poolable);
+	}
+
+	public boolean isPoolable() throws SQLException {
+		return orig.isPoolable();
+	}
+
+	public void closeOnCompletion() throws SQLException {
+		orig.closeOnCompletion();
+	}
+
+	public boolean isCloseOnCompletion() throws SQLException {
+		return orig.isCloseOnCompletion();
+	}
+
+	public <T> T unwrap(Class<T> iface) throws SQLException {
+		return orig.unwrap(iface);
+	}
+
+	public boolean isWrapperFor(Class<?> iface) throws SQLException {
+		return orig.isWrapperFor(iface);
+	}
+
+	public ResultSet executeQuery() throws SQLException {
+		return orig.executeQuery();
+	}
+
+	public int executeUpdate() throws SQLException {
+		return orig.executeUpdate();
+	}
+
+	public void setNull(int parameterIndex, int sqlType) throws SQLException {
+		orig.setNull(parameterIndex, sqlType);
+	}
+
+	public void setBoolean(int parameterIndex, boolean x) throws SQLException {
+		orig.setBoolean(parameterIndex, x);
+	}
+
+	public void setByte(int parameterIndex, byte x) throws SQLException {
+		orig.setByte(parameterIndex, x);
+	}
+
+	public void setShort(int parameterIndex, short x) throws SQLException {
+		orig.setShort(parameterIndex, x);
+	}
+
+	public void setInt(int parameterIndex, int x) throws SQLException {
+		orig.setInt(parameterIndex, x);
+	}
+
+	public void setLong(int parameterIndex, long x) throws SQLException {
+		orig.setLong(parameterIndex, x);
+	}
+
+	public void setFloat(int parameterIndex, float x) throws SQLException {
+		orig.setFloat(parameterIndex, x);
+	}
+
+	public void setDouble(int parameterIndex, double x) throws SQLException {
+		orig.setDouble(parameterIndex, x);
+	}
+
+	public void setBigDecimal(int parameterIndex, BigDecimal x)
+			throws SQLException {
+		orig.setBigDecimal(parameterIndex, x);
+	}
+
+	public void setString(int parameterIndex, String x) throws SQLException {
+		orig.setString(parameterIndex, x);
+	}
+
+	public void setBytes(int parameterIndex, byte[] x) throws SQLException {
+		orig.setBytes(parameterIndex, x);
+	}
+
+	public void setDate(int parameterIndex, Date x) throws SQLException {
+		orig.setDate(parameterIndex, x);
+	}
+
+	public void setTime(int parameterIndex, Time x) throws SQLException {
+		orig.setTime(parameterIndex, x);
+	}
+
+	public void setTimestamp(int parameterIndex, Timestamp x)
+			throws SQLException {
+		orig.setTimestamp(parameterIndex, x);
+	}
+
+	public void setAsciiStream(int parameterIndex, InputStream x, int length)
+			throws SQLException {
+		orig.setAsciiStream(parameterIndex, x, length);
+	}
+
+	@SuppressWarnings("deprecation")
+	public void setUnicodeStream(int parameterIndex, InputStream x, int length)
+			throws SQLException {
+		orig.setUnicodeStream(parameterIndex, x, length);
+	}
+
+	public void setBinaryStream(int parameterIndex, InputStream x, int length)
+			throws SQLException {
+		orig.setBinaryStream(parameterIndex, x, length);
+	}
+
+	public void clearParameters() throws SQLException {
+		orig.clearParameters();
+	}
+
+	public void setObject(int parameterIndex, Object x, int targetSqlType)
+			throws SQLException {
+		orig.setObject(parameterIndex, x, targetSqlType);
+	}
+
+	protected static boolean isOfni(Exception e) {
+		return e.getMessage().contains("Optional feature not implemented");
+	}
+	
+	public void setObject(int parameterIndex, Object x) throws SQLException {
+		try {
+			orig.setObject(parameterIndex, x);
+		} catch (SQLException e) {
+			if (isOfni(e)) {
+				if (x == null) {
+					throw e;
+				} else if (x.getClass().isArray()) {
+					orig.setArray(parameterIndex, (Array) x);
+				} else if (x instanceof Boolean) {
+					orig.setBoolean(parameterIndex, (Boolean) x);
+				} else if (x instanceof Byte) {
+					orig.setByte(parameterIndex, (Byte) x);
+				} else if (x instanceof Integer) {
+					orig.setInt(parameterIndex, (Integer) x);
+				} else if (x instanceof Long) {
+					final Long v = (Long) x;
+					try {
+						orig.setLong(parameterIndex, v);
+					} catch (SQLException se) {
+						if (isOfni(se) && v <= Integer.MAX_VALUE) {
+							orig.setInt(parameterIndex, v.intValue());
+						} else {
+							throw se;
+						}
+					}
+				} else if (x instanceof Float) {
+					orig.setFloat(parameterIndex, (Float) x);
+				} else if (x instanceof Double) {
+					orig.setDouble(parameterIndex, (Double) x);
+				} else if (x instanceof BigDecimal) {
+					orig.setBigDecimal(parameterIndex, (BigDecimal) x);
+				} else if (x instanceof String) {
+					orig.setString(parameterIndex, (String) x);
+				} else if (x instanceof Date) {
+					orig.setDate(parameterIndex, (Date) x);
+				} else {
+					throw e;
+				}
+			} else {
+				throw e;
+			}
+		}
+	}
+
+	public boolean execute() throws SQLException {
+		return orig.execute();
+	}
+
+	public void addBatch() throws SQLException {
+		orig.addBatch();
+	}
+
+	public void setCharacterStream(int parameterIndex, Reader reader, int length)
+			throws SQLException {
+		orig.setCharacterStream(parameterIndex, reader, length);
+	}
+
+	public void setRef(int parameterIndex, Ref x) throws SQLException {
+		orig.setRef(parameterIndex, x);
+	}
+
+	public void setBlob(int parameterIndex, Blob x) throws SQLException {
+		orig.setBlob(parameterIndex, x);
+	}
+
+	public void setClob(int parameterIndex, Clob x) throws SQLException {
+		orig.setClob(parameterIndex, x);
+	}
+
+	public void setArray(int parameterIndex, Array x) throws SQLException {
+		orig.setArray(parameterIndex, x);
+	}
+
+	public ResultSetMetaData getMetaData() throws SQLException {
+		return orig.getMetaData();
+	}
+
+	public void setDate(int parameterIndex, Date x, Calendar cal)
+			throws SQLException {
+		orig.setDate(parameterIndex, x, cal);
+	}
+
+	public void setTime(int parameterIndex, Time x, Calendar cal)
+			throws SQLException {
+		orig.setTime(parameterIndex, x, cal);
+	}
+
+	public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
+			throws SQLException {
+		orig.setTimestamp(parameterIndex, x, cal);
+	}
+
+	public void setNull(int parameterIndex, int sqlType, String typeName)
+			throws SQLException {
+		orig.setNull(parameterIndex, sqlType, typeName);
+	}
+
+	public void setURL(int parameterIndex, URL x) throws SQLException {
+		orig.setURL(parameterIndex, x);
+	}
+
+	public ParameterMetaData getParameterMetaData() throws SQLException {
+		return orig.getParameterMetaData();
+	}
+
+	public void setRowId(int parameterIndex, RowId x) throws SQLException {
+		orig.setRowId(parameterIndex, x);
+	}
+
+	public void setNString(int parameterIndex, String value)
+			throws SQLException {
+		orig.setNString(parameterIndex, value);
+	}
+
+	public void setNCharacterStream(int parameterIndex, Reader value,
+			long length) throws SQLException {
+		orig.setNCharacterStream(parameterIndex, value, length);
+	}
+
+	public void setNClob(int parameterIndex, NClob value) throws SQLException {
+		orig.setNClob(parameterIndex, value);
+	}
+
+	public void setClob(int parameterIndex, Reader reader, long length)
+			throws SQLException {
+		orig.setClob(parameterIndex, reader, length);
+	}
+
+	public void setBlob(int parameterIndex, InputStream inputStream, long length)
+			throws SQLException {
+		orig.setBlob(parameterIndex, inputStream, length);
+	}
+
+	public void setNClob(int parameterIndex, Reader reader, long length)
+			throws SQLException {
+		orig.setNClob(parameterIndex, reader, length);
+	}
+
+	public void setSQLXML(int parameterIndex, SQLXML xmlObject)
+			throws SQLException {
+		orig.setSQLXML(parameterIndex, xmlObject);
+	}
+
+	public void setObject(int parameterIndex, Object x, int targetSqlType,
+			int scaleOrLength) throws SQLException {
+		orig.setObject(parameterIndex, x, targetSqlType, scaleOrLength);
+	}
+
+	public void setAsciiStream(int parameterIndex, InputStream x, long length)
+			throws SQLException {
+		orig.setAsciiStream(parameterIndex, x, length);
+	}
+
+	public void setBinaryStream(int parameterIndex, InputStream x, long length)
+			throws SQLException {
+		orig.setBinaryStream(parameterIndex, x, length);
+	}
+
+	public void setCharacterStream(int parameterIndex, Reader reader,
+			long length) throws SQLException {
+		orig.setCharacterStream(parameterIndex, reader, length);
+	}
+
+	public void setAsciiStream(int parameterIndex, InputStream x)
+			throws SQLException {
+		orig.setAsciiStream(parameterIndex, x);
+	}
+
+	public void setBinaryStream(int parameterIndex, InputStream x)
+			throws SQLException {
+		orig.setBinaryStream(parameterIndex, x);
+	}
+
+	public void setCharacterStream(int parameterIndex, Reader reader)
+			throws SQLException {
+		orig.setCharacterStream(parameterIndex, reader);
+	}
+
+	public void setNCharacterStream(int parameterIndex, Reader value)
+			throws SQLException {
+		orig.setNCharacterStream(parameterIndex, value);
+	}
+
+	public void setClob(int parameterIndex, Reader reader) throws SQLException {
+		orig.setClob(parameterIndex, reader);
+	}
+
+	public void setBlob(int parameterIndex, InputStream inputStream)
+			throws SQLException {
+		orig.setBlob(parameterIndex, inputStream);
+	}
+
+	public void setNClob(int parameterIndex, Reader reader) throws SQLException {
+		orig.setNClob(parameterIndex, reader);
+	}
+
+}

src/test/clj/org/bituf/test_clj_dbcp.clj

         drop-table  #(sql/do-commands "DROP TABLE emp")
         retrieve-fn #(sql/with-query-results rows
                       ["SELECT * FROM emp WHERE id=?" 1]
-                      (first rows))]
+                      (first rows))
+        as-int-num #(reduce into {}
+                            (map (fn [[k v]] (if (number? v)
+                                               {k (int v)}
+                                               {k v})) %))]
     (sql/with-connection dbspec
       ;; drop table if pre-exists
       (try (drop-table)
       ;; insert
       (sql/insert-values table (keys orig-record) (vals orig-record))
       ;; retrieve-check
-      (is (= orig-record (retrieve-fn)))
+      (is (= orig-record (as-int-num (retrieve-fn))))
       ;; update
       (sql/update-values table ["id=?" 1] updt-record)
       ;; retrieve-check
-      (is (= updt-record (retrieve-fn)))
+      (is (= updt-record (as-int-num (retrieve-fn))))
       ;; delete
       ;; drop table
       (drop-table))))
 
 
 (defn test-ns-hook []
-  ;(test-odbc)
-  ;(test-derby)
+  (test-odbc)
+  (test-derby)
   (test-h2)
-  ;(test-hsql)
-  ;(test-sqlite)
-  ;(test-firebird)
-  ;(test-mysql)
-  ;(test-cubrid)
-  ;(test-pgsql)
-  ;(smoketest-untested-datasources)
-  ;(test-jndi)
-  ;(test-custom-datasource-parameters)
+  (test-hsql)
+  (test-sqlite)
+  (test-firebird)
+  (test-mysql)
+  (test-cubrid)
+  (test-pgsql)
+  (smoketest-untested-datasources)
+  (test-jndi)
+  (test-custom-datasource-parameters)
   (test-datasource-from-properties-file))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.