diff options
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcCallableStatement.java | 525 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java | 6 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java | 1212 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java | 17 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcObject.java | 650 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java | 279 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java | 717 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java | 105 | ||||
-rw-r--r-- | openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java | 56 |
9 files changed, 1423 insertions, 2144 deletions
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcCallableStatement.java b/openjdk/sun/jdbc/odbc/JdbcOdbcCallableStatement.java index f5c8b99e..6a890c4c 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcCallableStatement.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcCallableStatement.java @@ -31,6 +31,7 @@ import java.sql.*; import java.util.Calendar; import java.util.Map; +import cli.System.Data.ParameterDirection; import cli.System.Data.Common.*; @@ -40,675 +41,597 @@ import cli.System.Data.Common.*; */ public class JdbcOdbcCallableStatement extends JdbcOdbcPreparedStatement implements CallableStatement{ + private final Parameters parameters = new Parameters(); + public JdbcOdbcCallableStatement(JdbcOdbcConnection jdbcConn, DbCommand command, String sql){ super(jdbcConn, command, sql); - // TODO Auto-generated constructor stub } - public Array getArray(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Array getArray(int parameterIndex){ + return parameters.getArray(parameterIndex); } - public Array getArray(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Array getArray(String parameterName) throws SQLException{ + return parameters.getArray(parameterName); } - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException{ + return parameters.getBigDecimal(parameterIndex, scale); } - public BigDecimal getBigDecimal(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final BigDecimal getBigDecimal(int parameterIndex) throws SQLException{ + return parameters.getBigDecimal(parameterIndex); } - public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final BigDecimal getBigDecimal(String parameterName) throws SQLException{ + return parameters.getBigDecimal(parameterName); } - public Blob getBlob(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Blob getBlob(int parameterIndex){ + return parameters.getBlob(parameterIndex); } - public Blob getBlob(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Blob getBlob(String parameterName) throws SQLException{ + return parameters.getBlob(parameterName); } - public boolean getBoolean(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return false; + public final boolean getBoolean(int parameterIndex) throws SQLException{ + return parameters.getBoolean(parameterIndex); } - public boolean getBoolean(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return false; + public final boolean getBoolean(String parameterName) throws SQLException{ + return parameters.getBoolean(parameterName); } - public byte getByte(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final byte getByte(int parameterIndex) throws SQLException{ + return parameters.getByte(parameterIndex); } - public byte getByte(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final byte getByte(String parameterName) throws SQLException{ + return parameters.getByte(parameterName); } - public byte[] getBytes(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final byte[] getBytes(int parameterIndex) throws SQLException{ + return parameters.getBytes(parameterIndex); } - public byte[] getBytes(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final byte[] getBytes(String parameterName) throws SQLException{ + return parameters.getBytes(parameterName); } - public Reader getCharacterStream(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Reader getCharacterStream(int parameterIndex) throws SQLException{ + return parameters.getCharacterStream(parameterIndex); } - public Reader getCharacterStream(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Reader getCharacterStream(String parameterName) throws SQLException{ + return parameters.getCharacterStream(parameterName); } - public Clob getClob(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Clob getClob(int parameterIndex){ + return parameters.getClob(parameterIndex); } - public Clob getClob(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Clob getClob(String parameterName) throws SQLException{ + return parameters.getClob(parameterName); } - public Date getDate(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Date getDate(int parameterIndex, Calendar cal) throws SQLException{ + return parameters.getDate(parameterIndex, cal); } - public Date getDate(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Date getDate(int parameterIndex) throws SQLException{ + return parameters.getDate(parameterIndex); } - public Date getDate(int parameterIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Date getDate(String parameterName, Calendar cal) throws SQLException{ + return parameters.getDate(parameterName, cal); } - public Date getDate(String parameterName, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Date getDate(String parameterName) throws SQLException{ + return parameters.getDate(parameterName); } - public double getDouble(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final double getDouble(int parameterIndex) throws SQLException{ + return parameters.getDouble(parameterIndex); } - public double getDouble(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final double getDouble(String parameterName) throws SQLException{ + return parameters.getDouble(parameterName); } - public float getFloat(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final float getFloat(int parameterIndex) throws SQLException{ + return parameters.getFloat(parameterIndex); } - public float getFloat(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final float getFloat(String parameterName) throws SQLException{ + return parameters.getFloat(parameterName); } - public int getInt(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final int getInt(int parameterIndex) throws SQLException{ + return parameters.getInt(parameterIndex); } - public int getInt(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final int getInt(String parameterName) throws SQLException{ + return parameters.getInt(parameterName); } - public long getLong(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final long getLong(int parameterIndex) throws SQLException{ + return parameters.getLong(parameterIndex); } - public long getLong(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final long getLong(String parameterName) throws SQLException{ + return parameters.getLong(parameterName); } - public Reader getNCharacterStream(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Reader getNCharacterStream(int parameterIndex) throws SQLException{ + return parameters.getNCharacterStream(parameterIndex); } - public Reader getNCharacterStream(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Reader getNCharacterStream(String parameterName) throws SQLException{ + return parameters.getNCharacterStream(parameterName); } - public NClob getNClob(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final NClob getNClob(int parameterIndex){ + return parameters.getNClob(parameterIndex); } - public NClob getNClob(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final NClob getNClob(String parameterName) throws SQLException{ + return parameters.getNClob(parameterName); } - public String getNString(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final String getNString(int parameterIndex) throws SQLException{ + return parameters.getNString(parameterIndex); } - public String getNString(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final String getNString(String parameterName) throws SQLException{ + return parameters.getNString(parameterName); } - public Object getObject(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Object getObject(int parameterIndex, Map<String, Class<?>> map){ + return parameters.getObject(parameterIndex, map); } - public Object getObject(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Object getObject(int parameterIndex) throws SQLException{ + return parameters.getObject(parameterIndex); } - public Object getObject(int parameterIndex, Map<String, Class<?>> map) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException{ + return parameters.getObject(parameterName, map); } - public Object getObject(String parameterName, Map<String, Class<?>> map) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Object getObject(String parameterName) throws SQLException{ + return parameters.getObject(parameterName); } - public Ref getRef(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Ref getRef(int parameterIndex){ + return parameters.getRef(parameterIndex); } - public Ref getRef(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Ref getRef(String parameterName) throws SQLException{ + return parameters.getRef(parameterName); } - public RowId getRowId(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final RowId getRowId(int parameterIndex){ + return parameters.getRowId(parameterIndex); } - public RowId getRowId(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final RowId getRowId(String parameterName) throws SQLException{ + return parameters.getRowId(parameterName); } - public SQLXML getSQLXML(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final short getShort(int parameterIndex) throws SQLException{ + return parameters.getShort(parameterIndex); } - public SQLXML getSQLXML(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final short getShort(String parameterName) throws SQLException{ + return parameters.getShort(parameterName); } - public short getShort(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final SQLXML getSQLXML(int parameterIndex){ + return parameters.getSQLXML(parameterIndex); } - public short getShort(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return 0; + public final SQLXML getSQLXML(String parameterName) throws SQLException{ + return parameters.getSQLXML(parameterName); } - public String getString(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final String getString(int parameterIndex) throws SQLException{ + return parameters.getString(parameterIndex); } - public String getString(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final String getString(String parameterName) throws SQLException{ + return parameters.getString(parameterName); } - public Time getTime(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Time getTime(int parameterIndex, Calendar cal) throws SQLException{ + return parameters.getTime(parameterIndex, cal); } - public Time getTime(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Time getTime(int parameterIndex) throws SQLException{ + return parameters.getTime(parameterIndex); } - public Time getTime(int parameterIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Time getTime(String parameterName, Calendar cal) throws SQLException{ + return parameters.getTime(parameterName, cal); } - public Time getTime(String parameterName, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Time getTime(String parameterName) throws SQLException{ + return parameters.getTime(parameterName); } - public Timestamp getTimestamp(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException{ + return parameters.getTimestamp(parameterIndex, cal); } - public Timestamp getTimestamp(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Timestamp getTimestamp(int parameterIndex) throws SQLException{ + return parameters.getTimestamp(parameterIndex); } - public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException{ + return parameters.getTimestamp(parameterName, cal); } - public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final Timestamp getTimestamp(String parameterName) throws SQLException{ + return parameters.getTimestamp(parameterName); } - public URL getURL(int parameterIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final URL getURL(int parameterIndex){ + return parameters.getURL(parameterIndex); } - public URL getURL(String parameterName) throws SQLException{ - // TODO Auto-generated method stub - return null; + public final URL getURL(String parameterName) throws SQLException{ + return parameters.getURL(parameterName); } - public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException{ - // TODO Auto-generated method stub + public final boolean wasNull(){ + return parameters.wasNull(); + } + + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException{ + DbParameter para = getPara(parameterIndex); + int direction = para.get_Value() == null ? ParameterDirection.Output : ParameterDirection.InputOutput; + para.set_Direction(ParameterDirection.wrap(direction)); + para.set_Size(1999); //TODO the value should depend of the type + //TODO the type should be set } public void registerOutParameter(String parameterName, int sqlType) throws SQLException{ - // TODO Auto-generated method stub - + registerOutParameter(parameters.findColumn(parameterName), sqlType); } public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException{ - // TODO Auto-generated method stub - + DbParameter para = getPara(parameterIndex); + int direction = para.get_Value() == null ? ParameterDirection.Output : ParameterDirection.InputOutput; + para.set_Direction(ParameterDirection.wrap(direction)); + para.set_Scale((byte)scale); + //TODO see above } - public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException{ - // TODO Auto-generated method stub - + public void registerOutParameter(int parameterIndex, int sqlType, String typeName){ + throw new UnsupportedOperationException(); } public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException{ - // TODO Auto-generated method stub - + registerOutParameter(parameters.findColumn(parameterName), sqlType, scale); } public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException{ - // TODO Auto-generated method stub - + registerOutParameter(parameters.findColumn(parameterName), sqlType, typeName); } public void setAsciiStream(String parameterName, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - + setAsciiStream(parameters.findColumn(parameterName), x); } public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - + setAsciiStream(parameters.findColumn(parameterName), x, length); } public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - + setAsciiStream(parameters.findColumn(parameterName), x, length); } public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException{ - // TODO Auto-generated method stub - + setBigDecimal(parameters.findColumn(parameterName), x); } public void setBinaryStream(String parameterName, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - + setBinaryStream(parameters.findColumn(parameterName), x); } public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - + setBinaryStream(parameters.findColumn(parameterName), x, length); } public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - + setBinaryStream(parameters.findColumn(parameterName), x, length); } public void setBlob(String parameterName, Blob x) throws SQLException{ - // TODO Auto-generated method stub - + setBlob(parameters.findColumn(parameterName), x); } - public void setBlob(String parameterName, InputStream inputStream) throws SQLException{ - // TODO Auto-generated method stub - + public void setBlob(String parameterName, InputStream x) throws SQLException{ + setBlob(parameters.findColumn(parameterName), x); } - public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException{ - // TODO Auto-generated method stub - + public void setBlob(String parameterName, InputStream x, long length) throws SQLException{ + setBlob(parameters.findColumn(parameterName), x, length); } public void setBoolean(String parameterName, boolean x) throws SQLException{ - // TODO Auto-generated method stub - + setBoolean(parameters.findColumn(parameterName), x); } public void setByte(String parameterName, byte x) throws SQLException{ - // TODO Auto-generated method stub - + setByte(parameters.findColumn(parameterName), x); } public void setBytes(String parameterName, byte[] x) throws SQLException{ - // TODO Auto-generated method stub - + setBytes(parameters.findColumn(parameterName), x); } - public void setCharacterStream(String parameterName, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + public void setCharacterStream(String parameterName, Reader x) throws SQLException{ + setCharacterStream(parameters.findColumn(parameterName), x); } - public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException{ - // TODO Auto-generated method stub - + public void setCharacterStream(String parameterName, Reader x, int length) throws SQLException{ + setCharacterStream(parameters.findColumn(parameterName), x, length); } - public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + public void setCharacterStream(String parameterName, Reader x, long length) throws SQLException{ + setCharacterStream(parameters.findColumn(parameterName), x, length); } public void setClob(String parameterName, Clob x) throws SQLException{ - // TODO Auto-generated method stub - + setClob(parameters.findColumn(parameterName), x); } - public void setClob(String parameterName, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + public void setClob(String parameterName, Reader x) throws SQLException{ + setClob(parameters.findColumn(parameterName), x); } - public void setClob(String parameterName, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + public void setClob(String parameterName, Reader x, long length) throws SQLException{ + setClob(parameters.findColumn(parameterName), x, length); } public void setDate(String parameterName, Date x) throws SQLException{ - // TODO Auto-generated method stub - + setDate(parameters.findColumn(parameterName), x); } public void setDate(String parameterName, Date x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + setDate(parameters.findColumn(parameterName), x, cal); } public void setDouble(String parameterName, double x) throws SQLException{ - // TODO Auto-generated method stub - + setDouble(parameters.findColumn(parameterName), x); } public void setFloat(String parameterName, float x) throws SQLException{ - // TODO Auto-generated method stub - + setFloat(parameters.findColumn(parameterName), x); } public void setInt(String parameterName, int x) throws SQLException{ - // TODO Auto-generated method stub - + setInt(parameters.findColumn(parameterName), x); } public void setLong(String parameterName, long x) throws SQLException{ - // TODO Auto-generated method stub - + setLong(parameters.findColumn(parameterName), x); } - public void setNCharacterStream(String parameterName, Reader value) throws SQLException{ - // TODO Auto-generated method stub - + public void setNCharacterStream(String parameterName, Reader x) throws SQLException{ + setNCharacterStream(parameters.findColumn(parameterName), x); } - public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException{ - // TODO Auto-generated method stub - + public void setNCharacterStream(String parameterName, Reader x, long length) throws SQLException{ + setNCharacterStream(parameters.findColumn(parameterName), x, length); } - public void setNClob(String parameterName, NClob value) throws SQLException{ - // TODO Auto-generated method stub - + public void setNClob(String parameterName, NClob x) throws SQLException{ + setNClob(parameters.findColumn(parameterName), x); } - public void setNClob(String parameterName, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + public void setNClob(String parameterName, Reader x) throws SQLException{ + setNClob(parameters.findColumn(parameterName), x); } - public void setNClob(String parameterName, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + public void setNClob(String parameterName, Reader x, long length) throws SQLException{ + setNClob(parameters.findColumn(parameterName), x, length); } - public void setNString(String parameterName, String value) throws SQLException{ - // TODO Auto-generated method stub - + public void setNString(String parameterName, String x) throws SQLException{ + setNString(parameters.findColumn(parameterName), x); } public void setNull(String parameterName, int sqlType) throws SQLException{ - // TODO Auto-generated method stub - + setNull(parameters.findColumn(parameterName), sqlType); } public void setNull(String parameterName, int sqlType, String typeName) throws SQLException{ - // TODO Auto-generated method stub - + setNull(parameters.findColumn(parameterName), sqlType, typeName); } public void setObject(String parameterName, Object x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameters.findColumn(parameterName), x); } public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameters.findColumn(parameterName), x, targetSqlType); } - public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException{ - // TODO Auto-generated method stub - + public void setObject(String parameterName, Object x, int targetSqlType, int scaleOrLength) throws SQLException{ + setObject(parameters.findColumn(parameterName), x, targetSqlType, scaleOrLength); } public void setRowId(String parameterName, RowId x) throws SQLException{ - // TODO Auto-generated method stub - + setRowId(parameters.findColumn(parameterName), x); } - public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException{ - // TODO Auto-generated method stub - + public void setSQLXML(String parameterName, SQLXML x) throws SQLException{ + setSQLXML(parameters.findColumn(parameterName), x); } public void setShort(String parameterName, short x) throws SQLException{ - // TODO Auto-generated method stub - + setShort(parameters.findColumn(parameterName), x); } public void setString(String parameterName, String x) throws SQLException{ - // TODO Auto-generated method stub - + setString(parameters.findColumn(parameterName), x); } public void setTime(String parameterName, Time x) throws SQLException{ - // TODO Auto-generated method stub - + setTime(parameters.findColumn(parameterName), x); } public void setTime(String parameterName, Time x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + setTime(parameters.findColumn(parameterName), x, cal); } public void setTimestamp(String parameterName, Timestamp x) throws SQLException{ - // TODO Auto-generated method stub - + setTimestamp(parameters.findColumn(parameterName), x); } public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + setTimestamp(parameters.findColumn(parameterName), x, cal); } - public void setURL(String parameterName, URL val) throws SQLException{ - // TODO Auto-generated method stub - + public void setURL(String parameterName, URL x) throws SQLException{ + setURL(parameters.findColumn(parameterName), x); } + private class Parameters extends JdbcOdbcObject{ - public boolean wasNull() throws SQLException{ - // TODO Auto-generated method stub - return false; - } + @Override + public int findColumn(String parameterName) throws SQLException{ + try{ + DbParameterCollection params = command.get_Parameters(); + for(int i=0; i<params.get_Count();i++){ + DbParameter param = params.get_Item(i); + if(parameterName.equalsIgnoreCase(param.get_ParameterName())){ + return i+1; + } + } + throw new SQLException( "Parameter '"+parameterName+"' not found.", "S0022"); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + @Override + protected Object getObjectImpl(int parameterIndex) throws SQLException{ + return getPara(parameterIndex).get_Value(); + } + + } } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java b/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java index 3870030d..ed769505 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java @@ -351,7 +351,11 @@ public class JdbcOdbcConnection implements Connection{ public void setCatalog(String catalog) throws SQLException{ - netConn.ChangeDatabase(catalog); + try{ + netConn.ChangeDatabase(catalog); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java index 9407eef5..13a253ab 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java @@ -23,1170 +23,232 @@ */ package sun.jdbc.odbc; -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; import java.sql.*; -import java.util.Calendar; -import java.util.Map; import cli.System.Data.*; /** - * This JDBC Driver is a wrapper to the ODBC.NET Data Provider. - * This ResultSet based on DataTable. + * This JDBC Driver is a wrapper to the ODBC.NET Data Provider. This ResultSet based on DataTable. + * It is read only and scrollable. */ -public class JdbcOdbcDTResultSet implements ResultSet{ +public class JdbcOdbcDTResultSet extends JdbcOdbcResultSet{ private final DataTable data; - private final DataRowCollection rows; - private int rowIndex; // row index starting with 0; + + private DataRowCollection rows; + + private int rowIndex; // row index starting with 0; -1 means beforeFirst + private cli.System.Data.DataRow row; + public JdbcOdbcDTResultSet(DataTable data){ + super(null, TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY); this.data = data; this.rows = data.get_Rows(); this.rowIndex = -1; } - public boolean absolute(int row) throws SQLException{ - // TODO Auto-generated method stub - return false; + @Override + public boolean absolute(int rowPosition) throws SQLException{ + if(rowPosition == 0){ + return !isBeforeFirst() && !isAfterLast(); + } + DataRowCollection dataRows = getRows(); + int count = dataRows.get_Count(); + if(rowPosition > 0){ + if(rowPosition > count){ + row = null; + rowIndex = count; + return false; + } + rowIndex = rowPosition - 1; + row = dataRows.get_Item(rowIndex); + return true; + }else{ + if(-rowPosition > count){ + row = null; + rowIndex = -1; + return false; + } + rowIndex = count + rowPosition; + row = dataRows.get_Item(rowIndex); + return true; + } } + @Override public void afterLast() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void beforeFirst() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void cancelRowUpdates() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void clearWarnings() throws SQLException{ - // TODO Auto-generated method stub - + row = null; + rowIndex = getRows().get_Count(); } - public void close() throws SQLException{ - // TODO Auto-generated method stub - + @Override + public void beforeFirst(){ + row = null; + rowIndex = -1; } - public void deleteRow() throws SQLException{ - // TODO Auto-generated method stub - + @Override + public void close(){ + rows = null; } + @Override public int findColumn(String columnLabel) throws SQLException{ - return data.get_Columns().IndexOf(columnLabel) + 1; + getRows(); // Check if ResultSet is closed + int idx = data.get_Columns().IndexOf(columnLabel); + if(idx < 0){ + throw new SQLException("Column '" + columnLabel + "' not found.", "S0022"); + } + return idx + 1; } + @Override public boolean first() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public Array getArray(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Array getArray(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public InputStream getAsciiStream(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public InputStream getAsciiStream(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public InputStream getBinaryStream(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public InputStream getBinaryStream(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Blob getBlob(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Blob getBlob(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public boolean getBoolean(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public boolean getBoolean(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public byte getByte(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public byte getByte(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public byte[] getBytes(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public byte[] getBytes(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Reader getCharacterStream(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Reader getCharacterStream(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Clob getClob(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Clob getClob(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public int getConcurrency() throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public String getCursorName() throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Date getDate(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Date getDate(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Date getDate(int columnIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Date getDate(String columnLabel, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public double getDouble(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public double getDouble(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public int getFetchDirection() throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public int getFetchSize() throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public float getFloat(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public float getFloat(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public int getHoldability() throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public int getInt(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public int getInt(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public long getLong(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public long getLong(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; + beforeFirst(); + return next(); } + @Override public ResultSetMetaData getMetaData(){ - return new JdbcOdbcDTResultSetMetaData(null, data); - } - - - public Reader getNCharacterStream(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Reader getNCharacterStream(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public NClob getNClob(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public NClob getNClob(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public String getNString(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public String getNString(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Object getObject(int columnIndex) throws SQLException{ - if(row == null){ - throw new SQLException("No current row", "S1109"); - } - return row.get_Item(columnIndex - 1); - } - - - public Object getObject(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Ref getRef(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Ref getRef(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public int getRow(){ - return rowIndex < rows.get_Count() ? rowIndex + 1 : 0; - } - - - public RowId getRowId(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public RowId getRowId(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public SQLXML getSQLXML(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public SQLXML getSQLXML(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public short getShort(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public short getShort(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public Statement getStatement() throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public String getString(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public String getString(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Time getTime(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Time getTime(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Time getTime(int columnIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Time getTime(String columnLabel, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Timestamp getTimestamp(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Timestamp getTimestamp(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public int getType() throws SQLException{ - // TODO Auto-generated method stub - return 0; - } - - - public URL getURL(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public URL getURL(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public InputStream getUnicodeStream(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - return null; + return new JdbcOdbcDTResultSetMetaData(data); } - public InputStream getUnicodeStream(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public SQLWarning getWarnings() throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public void insertRow() throws SQLException{ - // TODO Auto-generated method stub - + @Override + public int getRow() throws SQLException{ + return rowIndex < getRows().get_Count() ? rowIndex + 1 : 0; } + @Override public boolean isAfterLast() throws SQLException{ - // TODO Auto-generated method stub - return false; + int count = getRows().get_Count(); + return rowIndex >= count || count == 0; } + @Override public boolean isBeforeFirst() throws SQLException{ - // TODO Auto-generated method stub - return false; + return rowIndex <= -1 || getRows().get_Count() == 0; } - public boolean isClosed() throws SQLException{ - // TODO Auto-generated method stub - return false; + @Override + public boolean isClosed(){ + return rows == null; } + @Override public boolean isFirst() throws SQLException{ - // TODO Auto-generated method stub - return false; + return rowIndex == 0 && getRows().get_Count() > 0; } + @Override public boolean isLast() throws SQLException{ - // TODO Auto-generated method stub - return false; + return rowIndex >= 0 && rowIndex == getRows().get_Count() - 1; } + @Override public boolean last() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public void moveToCurrentRow() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void moveToInsertRow() throws SQLException{ - // TODO Auto-generated method stub - + afterLast(); + return previous(); } + @Override public boolean next() throws SQLException{ - if( rowIndex + 1 < rows.get_Count()){ - rowIndex++; - row = rows.get_Item(rowIndex); + DataRowCollection dataRows = getRows(); + if(rowIndex + 1 < dataRows.get_Count()){ + row = dataRows.get_Item(++rowIndex); return true; }else{ + rowIndex = dataRows.get_Count(); row = null; return false; } } + @Override public boolean previous() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public void refreshRow() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public boolean relative(int rows) throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public boolean rowDeleted() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public boolean rowInserted() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public boolean rowUpdated() throws SQLException{ - // TODO Auto-generated method stub - return false; - } - - - public void setFetchDirection(int direction) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void setFetchSize(int rows) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateArray(int columnIndex, Array x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateArray(String columnLabel, Array x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(int columnIndex, Blob x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(String columnLabel, Blob x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBoolean(int columnIndex, boolean x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBoolean(String columnLabel, boolean x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateByte(int columnIndex, byte x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateByte(String columnLabel, byte x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBytes(int columnIndex, byte[] x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateBytes(String columnLabel, byte[] x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(int columnIndex, Reader x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(int columnIndex, Clob x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(String columnLabel, Clob x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(int columnIndex, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(String columnLabel, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(int columnIndex, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateClob(String columnLabel, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateDate(int columnIndex, Date x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateDate(String columnLabel, Date x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateDouble(int columnIndex, double x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateDouble(String columnLabel, double x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateFloat(int columnIndex, float x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateFloat(String columnLabel, float x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateInt(int columnIndex, int x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateInt(String columnLabel, int x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateLong(int columnIndex, long x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateLong(String columnLabel, long x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(int columnIndex, NClob clob) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(String columnLabel, NClob clob) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(int columnIndex, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNClob(String columnLabel, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNString(int columnIndex, String string) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNString(String columnLabel, String string) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNull(int columnIndex) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateNull(String columnLabel) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateObject(int columnIndex, Object x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateObject(String columnLabel, Object x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateRef(int columnIndex, Ref x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateRef(String columnLabel, Ref x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateRow() throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateRowId(int columnIndex, RowId x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateRowId(String columnLabel, RowId x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateShort(int columnIndex, short x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateShort(String columnLabel, short x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateString(int columnIndex, String x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateString(String columnLabel, String x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateTime(int columnIndex, Time x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateTime(String columnLabel, Time x) throws SQLException{ - // TODO Auto-generated method stub - - } - - - public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException{ - // TODO Auto-generated method stub - + if(rowIndex > 0){ + row = getRows().get_Item(--rowIndex); + return true; + }else{ + rowIndex = -1; + row = null; + return false; + } } - public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException{ - // TODO Auto-generated method stub - + @Override + public void refreshRow(){ + // ignore it } - public boolean wasNull() throws SQLException{ - // TODO Auto-generated method stub - return false; + @Override + public boolean relative(int rowPositions) throws SQLException{ + DataRowCollection dataRows = getRows(); + int newRowIndex = rowIndex + rowPositions; + if(newRowIndex < 0){ + rowIndex = -1; + row = null; + return false; + } + int count = dataRows.get_Count(); + if(newRowIndex >= dataRows.get_Count()){ + rowIndex = count; + row = null; + return false; + } + rowIndex = newRowIndex; + row = getRows().get_Item(newRowIndex); + return true; } - public boolean isWrapperFor(Class<?> iface) throws SQLException{ - // TODO Auto-generated method stub - return false; + /** + * {@inheritDoc} + */ + @Override + protected Object getObjectImpl(int columnIndex) throws SQLException{ + getRows(); // checks if ResultSet is closed + if(row == null){ + throw new SQLException("No current row", "S1109"); + } + try{ + return row.get_Item(columnIndex - 1); + }catch(ArrayIndexOutOfBoundsException ex){ + throw new SQLException( "Invalid column number ("+columnIndex+"). A number between 1 and "+data.get_Columns().get_Count()+" is valid.", "S1002"); + } } - public <T>T unwrap(Class<T> iface) throws SQLException{ - // TODO Auto-generated method stub - return null; + /** + * Check if this ResultSet is closed before access to the DataRowCollection + * + * @return the local rows object + * @throws SQLException + * If the ResultSet is closed. + */ + private DataRowCollection getRows() throws SQLException{ + if(rows == null){ + throw new SQLException("ResultSet is closed.", "24000"); + } + return rows; } - } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java index c2e543b4..25c15fb9 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java @@ -26,20 +26,16 @@ package sun.jdbc.odbc; import java.sql.*; import cli.System.Data.*; -import cli.System.Data.Common.*; -import cli.System.Data.Odbc.*; /** * This JDBC Driver is a wrapper to the ODBC.NET Data Provider */ public class JdbcOdbcDTResultSetMetaData implements ResultSetMetaData{ - private final DbDataReader reader; private final DataTable table; - public JdbcOdbcDTResultSetMetaData(DbDataReader reader, DataTable table){ - this.reader = reader; + public JdbcOdbcDTResultSetMetaData(DataTable table){ this.table = table; } @@ -50,8 +46,8 @@ public class JdbcOdbcDTResultSetMetaData implements ResultSetMetaData{ public String getColumnClassName(int column){ - cli.System.Type type = getDataColumn(column).get_DataType(); - return type.get_FullName(); + String type = getDataColumn(column).get_DataType().toString(); + return JdbcOdbcUtils.getJavaClassName(type); } @@ -84,7 +80,7 @@ public class JdbcOdbcDTResultSetMetaData implements ResultSetMetaData{ public String getColumnTypeName(int column) throws SQLException{ - return reader != null ? reader.GetDataTypeName(column - 1) : ""; + return ""; } @@ -173,6 +169,11 @@ public class JdbcOdbcDTResultSetMetaData implements ResultSetMetaData{ } + /** + * Get a DataColumn from the DataTable + * @param column the JDBC column index starting with 1 + * @return the DataColumn + */ private DataColumn getDataColumn(int column){ return table.get_Columns().get_Item(column - 1); } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcObject.java b/openjdk/sun/jdbc/odbc/JdbcOdbcObject.java new file mode 100644 index 00000000..a4a72bd2 --- /dev/null +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcObject.java @@ -0,0 +1,650 @@ +/* + Copyright (C) 2009 Volker Berlin (i-net software) + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jeroen Frijters + jeroen@frijters.net + + */ +package sun.jdbc.odbc; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; +import java.util.Map; + +import cli.System.Convert; +import cli.System.DBNull; +import cli.System.IConvertible; +import cli.System.Int16; +import cli.System.Int32; +import cli.System.Int64; +import cli.System.Single; + +/** + * @author Volker Berlin + */ +public abstract class JdbcOdbcObject{ + + private boolean wasNull; + + + /** + * Maps the given ResultSet column label to its ResultSet column index or the given CallableStatment parameter name + * to the parameter index. + * + * @param columnLabel + * the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, + * then the label is the name of the column + * @return the column index of the given column name + * @throws SQLException + * if the ResultSet object does not contain a column labeled columnLabel, a database access error occurs + * or this method is called on a closed result set + */ + public abstract int findColumn(String columnLabel) throws SQLException; + + + /** + * Read an Object from the current row store at the current row on the given column. + * + * @param columnIndex + * a JDBC column index starting with 1 + * @return a .NET Object, DBNull or null + * @throws SQLException + * if the result is closed or any other error occur. + */ + protected abstract Object getObjectImpl(int columnIndex) throws SQLException; + + + /** + * Read an Object from the current row store at the current row on the given column. Set the flag wasNull. + * + * @param columnIndex + * a JDBC column index starting with 1 + * @return a .NET Object or null + * @throws SQLException + * if the result is closed or any other error occur. + */ + private final Object getObjectSetWasNull(int columnIndex) throws SQLException{ + Object obj = getObjectImpl(columnIndex); + if(obj == null || obj == DBNull.Value){ + wasNull = true; + return null; + } + wasNull = false; + return obj; + } + + + public final Array getArray(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final Array getArray(String columnLabel) throws SQLException{ + return getArray(findColumn(columnLabel)); + } + + + public final InputStream getAsciiStream(int columnIndex) throws SQLException{ + try{ + String str = getString(columnIndex); + if(str == null){ + return null; + } + return new ByteArrayInputStream(str.getBytes("Ascii")); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final InputStream getAsciiStream(String columnLabel) throws SQLException{ + return getAsciiStream(findColumn(columnLabel)); + } + + + public final BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException{ + BigDecimal dec = getBigDecimal(columnIndex); + if(dec == null){ + return null; + } + if(dec.scale() != scale){ + return dec.setScale(scale, BigDecimal.ROUND_HALF_EVEN); + } + return dec; + } + + + public final BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException{ + return getBigDecimal(findColumn(columnLabel), scale); + } + + + public final BigDecimal getBigDecimal(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + String str = obj.toString(); + return new BigDecimal(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final BigDecimal getBigDecimal(String columnLabel) throws SQLException{ + return getBigDecimal(findColumn(columnLabel)); + } + + + public final InputStream getBinaryStream(int columnIndex) throws SQLException{ + byte[] data = getBytes(columnIndex); + if(data == null){ + return null; + } + return new ByteArrayInputStream(data); + } + + + public final InputStream getBinaryStream(String columnLabel) throws SQLException{ + return getBinaryStream(findColumn(columnLabel)); + } + + + public final Blob getBlob(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final Blob getBlob(String columnLabel) throws SQLException{ + return getBlob(findColumn(columnLabel)); + } + + + public final boolean getBoolean(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return false; + } + if(obj instanceof IConvertible){ + return Convert.ToBoolean(obj); + } + String str = obj.toString(); + if(str.length() > 0){ + // special handling for boolean representation in old databases + char ch = str.charAt(0); + if(ch == 'T' || ch == 't'){ + return true; + } + if(ch == 'F' || ch == 'f'){ + return true; + } + } + return cli.System.Boolean.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final boolean getBoolean(String columnLabel) throws SQLException{ + return getBoolean(findColumn(columnLabel)); + } + + + public final byte getByte(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToByte(obj); + } + String str = obj.toString(); + return cli.System.Byte.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final byte getByte(String columnLabel) throws SQLException{ + return getByte(findColumn(columnLabel)); + } + + + public final byte[] getBytes(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + if(obj instanceof byte[]){ + return (byte[])obj; + } + String str = obj.toString(); + return str.getBytes(); // which encoding? + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final byte[] getBytes(String columnLabel) throws SQLException{ + return getBytes(findColumn(columnLabel)); + } + + + public final Reader getCharacterStream(int columnIndex) throws SQLException{ + String str = getString(columnIndex); + if(str == null){ + return null; + } + return new StringReader(str); + } + + + public final Reader getCharacterStream(String columnLabel) throws SQLException{ + return getCharacterStream(findColumn(columnLabel)); + } + + + public final Clob getClob(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final Clob getClob(String columnLabel) throws SQLException{ + return getClob(findColumn(columnLabel)); + } + + + public final Date getDate(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + if(obj instanceof cli.System.DateTime){ + cli.System.DateTime dt = (cli.System.DateTime)obj; + return new Date(dt.get_Year() - 1900, dt.get_Month() - 1, dt.get_Day()); + } + String str = obj.toString(); + return Date.valueOf(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final Date getDate(String columnLabel) throws SQLException{ + return getDate(findColumn(columnLabel)); + } + + + public final Date getDate(int columnIndex, Calendar cal) throws SQLException{ + Date date = getDate(columnIndex); + JdbcOdbcUtils.convertLocalToCalendarDate(date, cal); + return date; + } + + + public final Date getDate(String columnLabel, Calendar cal) throws SQLException{ + return getDate(findColumn(columnLabel), cal); + } + + + public final double getDouble(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToDouble(obj); + } + String str = obj.toString(); + return cli.System.Double.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final double getDouble(String columnLabel) throws SQLException{ + return getDouble(findColumn(columnLabel)); + } + + + public final float getFloat(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToSingle(obj); + } + String str = obj.toString(); + return Single.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final float getFloat(String columnLabel) throws SQLException{ + return getFloat(findColumn(columnLabel)); + } + + + public final int getInt(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToInt32(obj); + } + String str = obj.toString(); + return Int32.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final int getInt(String columnLabel) throws SQLException{ + return getInt(findColumn(columnLabel)); + } + + + public final long getLong(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToInt64(obj); + } + String str = obj.toString(); + return Int64.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final long getLong(String columnLabel) throws SQLException{ + return getLong(findColumn(columnLabel)); + } + + + public final Reader getNCharacterStream(int columnIndex) throws SQLException{ + return getCharacterStream(columnIndex); + } + + + public final Reader getNCharacterStream(String columnLabel) throws SQLException{ + return getCharacterStream(columnLabel); + } + + + public final NClob getNClob(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final NClob getNClob(String columnLabel) throws SQLException{ + return getNClob(findColumn(columnLabel)); + } + + + public final String getNString(int columnIndex) throws SQLException{ + return getString(columnIndex); + } + + + public final String getNString(String columnLabel) throws SQLException{ + return getString(columnLabel); + } + + + public final Object getObject(int columnIndex) throws SQLException{ + return JdbcOdbcUtils.convertNet2Java(getObjectSetWasNull(columnIndex)); + } + + + public final Object getObject(String columnLabel) throws SQLException{ + return getObject(findColumn(columnLabel)); + } + + + public final Object getObject(int columnIndex, Map<String, Class<?>> map){ + throw new UnsupportedOperationException(); + } + + + public final Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException{ + return getObject(findColumn(columnLabel), map); + } + + + public final Ref getRef(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final Ref getRef(String columnLabel) throws SQLException{ + return getRef(findColumn(columnLabel)); + } + + + public final RowId getRowId(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final RowId getRowId(String columnLabel) throws SQLException{ + return getRowId(findColumn(columnLabel)); + } + + + public final SQLXML getSQLXML(int columnIndex){ + throw new UnsupportedOperationException(); + } + + + public final SQLXML getSQLXML(String columnLabel) throws SQLException{ + return getSQLXML(findColumn(columnLabel)); + } + + + public final short getShort(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return 0; + } + if(obj instanceof IConvertible){ + return Convert.ToInt16(obj); + } + String str = obj.toString(); + return Int16.Parse(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final short getShort(String columnLabel) throws SQLException{ + return getShort(findColumn(columnLabel)); + } + + + public final String getString(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + return obj.toString(); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final String getString(String columnLabel) throws SQLException{ + return getString(findColumn(columnLabel)); + } + + + public final Time getTime(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + if(obj instanceof cli.System.DateTime){ + cli.System.DateTime dt = (cli.System.DateTime)obj; + return new Time(dt.get_Hour(), dt.get_Minute() - 1, dt.get_Second()); + } + if(obj instanceof cli.System.TimeSpan){ + cli.System.TimeSpan ts = (cli.System.TimeSpan)obj; + return new Time(ts.get_Hours(), ts.get_Minutes() - 1, ts.get_Seconds()); + } + String str = obj.toString(); + return Time.valueOf(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final Time getTime(String columnLabel) throws SQLException{ + return getTime(findColumn(columnLabel)); + } + + + public final Time getTime(int columnIndex, Calendar cal) throws SQLException{ + Time time = getTime(columnIndex); + JdbcOdbcUtils.convertLocalToCalendarDate(time, cal); + return time; + } + + + public final Time getTime(String columnLabel, Calendar cal) throws SQLException{ + return getTime(findColumn(columnLabel), cal); + } + + + public final Timestamp getTimestamp(int columnIndex) throws SQLException{ + try{ + Object obj = getObjectSetWasNull(columnIndex); + if(wasNull){ + return null; + } + if(obj instanceof cli.System.DateTime){ + cli.System.DateTime dt = (cli.System.DateTime)obj; + return new Timestamp(JdbcOdbcUtils.getJavaMillis(dt)); + } + String str = obj.toString(); + return Timestamp.valueOf(str); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final Timestamp getTimestamp(String columnLabel) throws SQLException{ + return getTimestamp(findColumn(columnLabel)); + } + + + public final Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException{ + Timestamp ts = getTimestamp(columnIndex); + JdbcOdbcUtils.convertLocalToCalendarDate(ts, cal); + return ts; + } + + + public final Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException{ + return getTimestamp(findColumn(columnLabel), cal); + } + + + public final URL getURL(int columnIndex) throws SQLException{ + try{ + String url = getString(columnIndex); + if(wasNull){ + return null; + } + return new URL(url); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final URL getURL(String columnLabel) throws SQLException{ + return getURL(findColumn(columnLabel)); + } + + + public final InputStream getUnicodeStream(int columnIndex) throws SQLException{ + try{ + return new ByteArrayInputStream(getString(columnIndex).getBytes("UTF16")); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } + } + + + public final InputStream getUnicodeStream(String columnLabel) throws SQLException{ + return getUnicodeStream(findColumn(columnLabel)); + } + + + public final boolean wasNull(){ + return wasNull; + } + +} diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java b/openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java index d9a2254d..26d96426 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcPreparedStatement.java @@ -42,11 +42,14 @@ import java.sql.SQLException; import java.sql.SQLXML; import java.sql.Time; import java.sql.Timestamp; +import java.sql.Types; import java.util.Calendar; +import cli.System.DBNull; +import cli.System.Data.ParameterDirection; import cli.System.Data.Common.DbCommand; - - +import cli.System.Data.Common.DbParameter; +import cli.System.Data.Common.DbParameterCollection; /** * @author Volker Berlin @@ -56,281 +59,315 @@ public class JdbcOdbcPreparedStatement extends JdbcOdbcStatement implements Prep public JdbcOdbcPreparedStatement(JdbcOdbcConnection jdbcConn, DbCommand command, String sql){ super(jdbcConn, command); command.set_CommandText(sql); + command.Prepare(); } + public void addBatch() throws SQLException{ // TODO Auto-generated method stub - + } + public void clearParameters() throws SQLException{ // TODO Auto-generated method stub - + } + public boolean execute() throws SQLException{ - // TODO Auto-generated method stub - return false; + return super.execute(null); } + public ResultSet executeQuery() throws SQLException{ - // TODO Auto-generated method stub - return null; + return super.executeQuery(null); } + public int executeUpdate() throws SQLException{ - // TODO Auto-generated method stub - return 0; + return super.executeUpdate(null); } + public ResultSetMetaData getMetaData() throws SQLException{ // TODO Auto-generated method stub return null; } + public ParameterMetaData getParameterMetaData() throws SQLException{ - // TODO Auto-generated method stub - return null; + throw new UnsupportedOperationException(); } + public void setArray(int parameterIndex, Array x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.ARRAY); } + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARCHAR); } + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARCHAR, length); } + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length); } + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.DECIMAL); } + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARBINARY); } + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARBINARY, length); } + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGVARBINARY, (int)length); } + public void setBlob(int parameterIndex, Blob x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.BLOB); } - public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException{ - // TODO Auto-generated method stub - + + public void setBlob(int parameterIndex, InputStream x) throws SQLException{ + setObject(parameterIndex, x, Types.BLOB); } - public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException{ + setObject(parameterIndex, x, Types.BLOB, (int)length); } + public void setBoolean(int parameterIndex, boolean x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Boolean.valueOf(x), Types.BOOLEAN); } + public void setByte(int parameterIndex, byte x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Byte.valueOf(x), Types.TINYINT); } + public void setBytes(int parameterIndex, byte[] x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.BINARY); } - public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + + public void setCharacterStream(int parameterIndex, Reader x) throws SQLException{ + setObject(parameterIndex, x, Types.LONGVARCHAR); } - public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException{ + setObject(parameterIndex, x, Types.NCLOB, length); } - public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{ + setObject(parameterIndex, x, Types.LONGVARCHAR, (int)length); } + public void setClob(int parameterIndex, Clob x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.CLOB); } - public void setClob(int parameterIndex, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + + public void setClob(int parameterIndex, Reader x) throws SQLException{ + setObject(parameterIndex, x, Types.CLOB); } - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setClob(int parameterIndex, Reader x, long length) throws SQLException{ + setObject(parameterIndex, x, Types.CLOB, (int)length); } + public void setDate(int parameterIndex, Date x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.DATE); } + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + JdbcOdbcUtils.convertCalendarToLocalDate(x, cal); + setObject(parameterIndex, x, Types.DATE); } + public void setDouble(int parameterIndex, double x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Double.valueOf(x), Types.DOUBLE); } + public void setFloat(int parameterIndex, float x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Float.valueOf(x), Types.FLOAT); } + public void setInt(int parameterIndex, int x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Integer.valueOf(x), Types.INTEGER); } + public void setLong(int parameterIndex, long x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Long.valueOf(x), Types.BIGINT); } - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException{ + setObject(parameterIndex, x, Types.LONGNVARCHAR); } - public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException{ + setObject(parameterIndex, x, Types.LONGNVARCHAR, (int)length); } - public void setNClob(int parameterIndex, NClob value) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNClob(int parameterIndex, NClob x) throws SQLException{ + setObject(parameterIndex, x, Types.NCLOB); } - public void setNClob(int parameterIndex, Reader reader) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNClob(int parameterIndex, Reader x) throws SQLException{ + setObject(parameterIndex, x, Types.NCLOB); } - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNClob(int parameterIndex, Reader x, long length) throws SQLException{ + setObject(parameterIndex, x, Types.NCLOB, (int)length); } - public void setNString(int parameterIndex, String value) throws SQLException{ - // TODO Auto-generated method stub - + + public void setNString(int parameterIndex, String x) throws SQLException{ + setObject(parameterIndex, x, Types.NVARCHAR); } + public void setNull(int parameterIndex, int sqlType) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, null, sqlType); } + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, null, sqlType); } + public void setObject(int parameterIndex, Object x) throws SQLException{ - // TODO Auto-generated method stub - + DbParameter para = getPara(parameterIndex); + para.set_Value(x == null ? DBNull.Value : x); + if(para.get_Direction().Value == ParameterDirection.Output){ + para.set_Direction(ParameterDirection.wrap(ParameterDirection.InputOutput)); + } } + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException{ // TODO Auto-generated method stub - + setObject(parameterIndex, x); } + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException{ // TODO Auto-generated method stub - + setObject(parameterIndex, x); } + public void setRef(int parameterIndex, Ref x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.REF); } + public void setRowId(int parameterIndex, RowId x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.ROWID); } - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException{ - // TODO Auto-generated method stub - + + public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException{ + setObject(parameterIndex, x, Types.SQLXML); } + public void setShort(int parameterIndex, short x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, Short.valueOf(x), Types.SMALLINT); } + public void setString(int parameterIndex, String x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.VARCHAR); } + public void setTime(int parameterIndex, Time x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.TIME); } + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + JdbcOdbcUtils.convertCalendarToLocalDate(x, cal); + setObject(parameterIndex, x, Types.TIME); } + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.TIMESTAMP); } + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - + JdbcOdbcUtils.convertCalendarToLocalDate(x, cal); + setObject(parameterIndex, x, Types.TIMESTAMP); } + public void setURL(int parameterIndex, URL x) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.DATALINK); } + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException{ - // TODO Auto-generated method stub - + setObject(parameterIndex, x, Types.LONGNVARCHAR, length); + } + + + /** + * Get the DbParameter from the current command. If the parameter does not exits in the collection then add it. + * + * @param parameterIndex + * The JDBC parameter index starting with 1 + * @return the DbParameter for the index. + * @throws SQLException + * If any error occur. + */ + protected DbParameter getPara(int parameterIndex) throws SQLException{ + try{ + DbParameterCollection params = command.get_Parameters(); + while(params.get_Count() < parameterIndex){ + params.Add(command.CreateParameter()); + } + return params.get_Item(parameterIndex - 1); + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } } - } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java index 5c8b2923..2db8cf22 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java @@ -23,43 +23,22 @@ */ package sun.jdbc.odbc; -import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.Reader; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; import java.math.BigDecimal; -import java.net.URL; import java.sql.*; -import java.util.Calendar; -import java.util.Map; - -import cli.System.Convert; -import cli.System.DBNull; -import cli.System.IConvertible; -import cli.System.Int16; -import cli.System.Int32; -import cli.System.Int64; -import cli.System.OverflowException; -import cli.System.Single; -import cli.System.TimeSpan; -import cli.System.Data.DataTable; -import cli.System.Data.SchemaType; -import cli.System.Data.Common.DbDataAdapter; -import cli.System.Data.Common.DbDataReader; -import cli.System.Data.Odbc.OdbcDataAdapter; + +import cli.System.Data.Common.*; /** * This JDBC Driver is a wrapper to the ODBC.NET Data Provider. This ResultSet based on a DataReader. */ -public class JdbcOdbcResultSet implements ResultSet{ +public class JdbcOdbcResultSet extends JdbcOdbcObject implements ResultSet{ - private final DbDataReader reader; + private DbDataReader reader; private final JdbcOdbcStatement statement; - private boolean wasNull; - private final int holdability; private final int concurrency; @@ -70,29 +49,60 @@ public class JdbcOdbcResultSet implements ResultSet{ private final int resultSetType; + private ResultSetMetaData metaData; + + /** + * Create a ResultSet that based on a DbDataReader + * + * @param statement + * the statement for getStatement(), can be null + * @param reader + * the reader for the data access, if it null then the resultset is closed. + */ public JdbcOdbcResultSet(JdbcOdbcStatement statement, DbDataReader reader){ this.statement = statement; this.reader = reader; - holdability = HOLD_CURSORS_OVER_COMMIT; - concurrency = CONCUR_READ_ONLY; - resultSetType = TYPE_FORWARD_ONLY; + this.resultSetType = TYPE_FORWARD_ONLY; + this.concurrency = CONCUR_READ_ONLY; + this.holdability = HOLD_CURSORS_OVER_COMMIT; + } + + + /** + * A constructor for extended classes. All methods that use the reader must be overridden if you use this + * constructor. + * + * @param statement + * the statement for getStatement(), can be null + * @param resultSetType + * a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or + * ResultSet.TYPE_SCROLL_SENSITIVE + * @param concurrency + * a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE + */ + protected JdbcOdbcResultSet(JdbcOdbcStatement statement, int resultSetType, int concurrency){ + this.statement = statement; + this.reader = null; + this.resultSetType = resultSetType; + this.concurrency = concurrency; + this.holdability = HOLD_CURSORS_OVER_COMMIT; } - public boolean absolute(int row) throws SQLException{ - throwReadOnly(); + public boolean absolute(int rowPosition) throws SQLException{ + throwForwardOnly(); return false; // for Compiler } public void afterLast() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); } public void beforeFirst() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); } @@ -107,9 +117,9 @@ public class JdbcOdbcResultSet implements ResultSet{ } - public void close() throws SQLException{ - // TODO Auto-generated method stub - + public void close(){ + reader = null; + statement.closeReaderIfPossible(); } @@ -118,202 +128,19 @@ public class JdbcOdbcResultSet implements ResultSet{ } + @Override public int findColumn(String columnLabel) throws SQLException{ - return reader.GetOrdinal(columnLabel) + 1; - } - - - public boolean first() throws SQLException{ - throwReadOnly(); - return false; // for compiler - } - - - public Array getArray(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public Array getArray(String columnLabel) throws SQLException{ - return getArray(findColumn(columnLabel)); - } - - - public InputStream getAsciiStream(int columnIndex) throws SQLException{ try{ - String str = getString(columnIndex); - if(str == null){ - return null; - } - return new ByteArrayInputStream(str.getBytes("Ascii")); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); + return getReader().GetOrdinal(columnLabel) + 1; + }catch(ArrayIndexOutOfBoundsException ex){ + throw new SQLException("Column '" + columnLabel + "' not found.", "S0022", ex); } } - public InputStream getAsciiStream(String columnLabel) throws SQLException{ - return getAsciiStream(findColumn(columnLabel)); - } - - - public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException{ - BigDecimal dec = getBigDecimal(columnIndex); - if(dec == null){ - return null; - } - if(dec.scale() != scale){ - return dec.setScale(scale, BigDecimal.ROUND_HALF_EVEN); - } - return dec; - } - - - public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException{ - return getBigDecimal(findColumn(columnLabel), scale); - } - - - public BigDecimal getBigDecimal(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - String str = obj.toString(); - return new BigDecimal(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public BigDecimal getBigDecimal(String columnLabel) throws SQLException{ - return getBigDecimal(findColumn(columnLabel)); - } - - - public InputStream getBinaryStream(int columnIndex) throws SQLException{ - byte[] data = getBytes(columnIndex); - if(data == null){ - return null; - } - return new ByteArrayInputStream(data); - } - - - public InputStream getBinaryStream(String columnLabel) throws SQLException{ - return getBinaryStream(findColumn(columnLabel)); - } - - - public Blob getBlob(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public Blob getBlob(String columnLabel) throws SQLException{ - return getBlob(findColumn(columnLabel)); - } - - - public boolean getBoolean(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return false; - } - if(obj instanceof IConvertible){ - return Convert.ToBoolean(obj); - } - String str = obj.toString(); - if(str.length() > 0){ - // special handling for boolean representation in old databases - char ch = str.charAt(0); - if(ch == 'T' || ch == 't'){ - return true; - } - if(ch == 'F' || ch == 'f'){ - return true; - } - } - return cli.System.Boolean.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public boolean getBoolean(String columnLabel) throws SQLException{ - return getBoolean(findColumn(columnLabel)); - } - - - public byte getByte(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToByte(obj); - } - String str = obj.toString(); - return cli.System.Byte.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public byte getByte(String columnLabel) throws SQLException{ - return getByte(findColumn(columnLabel)); - } - - - public byte[] getBytes(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - if(obj instanceof byte[]){ - return (byte[])obj; - } - String str = obj.toString(); - return str.getBytes(); // which encoding? - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public byte[] getBytes(String columnLabel) throws SQLException{ - return getBytes(findColumn(columnLabel)); - } - - - public Reader getCharacterStream(int columnIndex) throws SQLException{ - String str = getString(columnIndex); - if(str == null){ - return null; - } - return new StringReader(str); - } - - - public Reader getCharacterStream(String columnLabel) throws SQLException{ - return getCharacterStream(findColumn(columnLabel)); - } - - - public Clob getClob(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public Clob getClob(String columnLabel) throws SQLException{ - return getClob(findColumn(columnLabel)); + public boolean first() throws SQLException{ + throwForwardOnly(); + return false; // for compiler } @@ -328,77 +155,6 @@ public class JdbcOdbcResultSet implements ResultSet{ } - public Date getDate(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - if(obj instanceof cli.System.DateTime){ - cli.System.DateTime dt = (cli.System.DateTime)obj; - return new Date(dt.get_Year() - 1900, dt.get_Month() - 1, dt.get_Day()); - } - String str = obj.toString(); - return Date.valueOf(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public Date getDate(String columnLabel) throws SQLException{ - return getDate(findColumn(columnLabel)); - } - - - public Date getDate(int columnIndex, Calendar cal) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - if(obj instanceof cli.System.DateTime){ - cal.setTimeInMillis(JdbcOdbcUtils.getJavaMillis((cli.System.DateTime)obj)); - int year = cal.get(Calendar.YEAR) - 1900; - int month = cal.get(Calendar.MONTH) - 1; - int day = cal.get(Calendar.DAY_OF_MONTH); - return new Date(year, month, day); - } - String str = obj.toString(); - return Date.valueOf(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public Date getDate(String columnLabel, Calendar cal) throws SQLException{ - return getDate(findColumn(columnLabel), cal); - } - - - public double getDouble(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToDouble(obj); - } - String str = obj.toString(); - return cli.System.Double.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public double getDouble(String columnLabel) throws SQLException{ - return getDouble(findColumn(columnLabel)); - } - - public int getFetchDirection(){ return FETCH_UNKNOWN; } @@ -409,313 +165,35 @@ public class JdbcOdbcResultSet implements ResultSet{ } - public float getFloat(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToSingle(obj); - } - String str = obj.toString(); - return Single.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public float getFloat(String columnLabel) throws SQLException{ - return getFloat(findColumn(columnLabel)); - } - - public int getHoldability(){ return holdability; } - public int getInt(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToInt32(obj); - } - String str = obj.toString(); - return Int32.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public int getInt(String columnLabel) throws SQLException{ - return getInt(findColumn(columnLabel)); - } - - - public long getLong(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToInt64(obj); - } - String str = obj.toString(); - return Int64.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); + public ResultSetMetaData getMetaData() throws SQLException{ + if(metaData == null){ + metaData = new JdbcOdbcResultSetMetaData(getReader()); } + return metaData; } - public long getLong(String columnLabel) throws SQLException{ - return getLong(findColumn(columnLabel)); - } - - - public ResultSetMetaData getMetaData(){ - return new JdbcOdbcResultSetMetaData(reader); - } - - - public Reader getNCharacterStream(int columnIndex) throws SQLException{ - return getCharacterStream(columnIndex); - } - - - public Reader getNCharacterStream(String columnLabel) throws SQLException{ - return getCharacterStream(columnLabel); - } - - - public NClob getNClob(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public NClob getNClob(String columnLabel) throws SQLException{ - return getNClob(findColumn(columnLabel)); - } - - - public String getNString(int columnIndex) throws SQLException{ - return getString(columnIndex); - } - - - public String getNString(String columnLabel) throws SQLException{ - return getString(columnLabel); - } - - - public Object getObject(int columnIndex) throws SQLException{ - return JdbcOdbcUtils.convertNet2Java(getObjectImpl(columnIndex)); - } - - - public Object getObject(String columnLabel) throws SQLException{ - return getObject(findColumn(columnLabel)); - } - - - public Object getObject(int columnIndex, Map<String, Class<?>> map){ - throw new UnsupportedOperationException(); - } - - - public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException{ - return getObject(findColumn(columnLabel), map); - } - - - public Ref getRef(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public Ref getRef(String columnLabel) throws SQLException{ - return getRef(findColumn(columnLabel)); - } - - - public int getRow(){ + public int getRow() throws SQLException{ + getReader(); // checking for is closed return row; } - public RowId getRowId(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public RowId getRowId(String columnLabel) throws SQLException{ - return getRowId(findColumn(columnLabel)); - } - - - public SQLXML getSQLXML(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public SQLXML getSQLXML(String columnLabel) throws SQLException{ - return getSQLXML(findColumn(columnLabel)); - } - - - public short getShort(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return 0; - } - if(obj instanceof IConvertible){ - return Convert.ToInt16(obj); - } - String str = obj.toString(); - return Int16.Parse(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public short getShort(String columnLabel) throws SQLException{ - return getShort(findColumn(columnLabel)); - } - - public Statement getStatement(){ return statement; } - public String getString(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - return obj.toString(); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public String getString(String columnLabel) throws SQLException{ - return getString(findColumn(columnLabel)); - } - - - public Time getTime(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - if(obj instanceof cli.System.DateTime){ - cli.System.DateTime dt = (cli.System.DateTime)obj; - return new Time(dt.get_Hour(), dt.get_Minute() - 1, dt.get_Second()); - } - if(obj instanceof cli.System.TimeSpan){ - cli.System.TimeSpan ts = (cli.System.TimeSpan)obj; - return new Time(ts.get_Hours(), ts.get_Minutes() - 1, ts.get_Seconds()); - } - String str = obj.toString(); - return Time.valueOf(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public Time getTime(String columnLabel) throws SQLException{ - return getTime(findColumn(columnLabel)); - } - - - public Time getTime(int columnIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Time getTime(String columnLabel, Calendar cal) throws SQLException{ - return getTime(findColumn(columnLabel), cal); - } - - - public Timestamp getTimestamp(int columnIndex) throws SQLException{ - try{ - Object obj = getObjectImpl(columnIndex); - if(wasNull){ - return null; - } - if(obj instanceof cli.System.DateTime){ - cli.System.DateTime dt = (cli.System.DateTime)obj; - return new Timestamp(JdbcOdbcUtils.getJavaMillis(dt)); - } - String str = obj.toString(); - return Timestamp.valueOf(str); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public Timestamp getTimestamp(String columnLabel) throws SQLException{ - return getTimestamp(findColumn(columnLabel)); - } - - - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException{ - // TODO Auto-generated method stub - return null; - } - - - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException{ - return getTimestamp(findColumn(columnLabel), cal); - } - - public int getType(){ return resultSetType; } - public URL getURL(int columnIndex){ - throw new UnsupportedOperationException(); - } - - - public URL getURL(String columnLabel) throws SQLException{ - return getURL(findColumn(columnLabel)); - } - - - public InputStream getUnicodeStream(int columnIndex) throws SQLException{ - try{ - return new ByteArrayInputStream(getString(columnIndex).getBytes("UTF16")); - }catch(Throwable th){ - throw JdbcOdbcUtils.createSQLException(th); - } - } - - - public InputStream getUnicodeStream(String columnLabel) throws SQLException{ - return getUnicodeStream(findColumn(columnLabel)); - } - - public SQLWarning getWarnings() throws SQLException{ // TODO Auto-generated method stub return null; @@ -728,37 +206,36 @@ public class JdbcOdbcResultSet implements ResultSet{ public boolean isAfterLast() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } public boolean isBeforeFirst() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } - public boolean isClosed() throws SQLException{ - // TODO Auto-generated method stub - return false; + public boolean isClosed(){ + return reader == null; } public boolean isFirst() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } public boolean isLast() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } public boolean last() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } @@ -774,28 +251,33 @@ public class JdbcOdbcResultSet implements ResultSet{ public boolean next() throws SQLException{ - if(reader.Read()){ + DbDataReader dataReader = getReader(); + //if we after the last row then we close the reader + //to prevent an error on repeating call of next() after the end + //that we check also get_IsClosed() + if(!dataReader.get_IsClosed() && dataReader.Read()){ row++; return true; } row = 0; + statement.closeReaderIfPossible(); return false; } public boolean previous() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); return false; // only for compiler } public void refreshRow() throws SQLException{ - throwReadOnly(); + throwForwardOnly(); } - public boolean relative(int rows) throws SQLException{ - throwReadOnly(); + public boolean relative(int rowPositions) throws SQLException{ + throwForwardOnly(); return false; // only for compiler } @@ -1243,11 +725,6 @@ public class JdbcOdbcResultSet implements ResultSet{ } - public boolean wasNull(){ - return wasNull; - } - - public boolean isWrapperFor(Class<?> iface){ return iface.isAssignableFrom(this.getClass()); } @@ -1261,23 +738,45 @@ public class JdbcOdbcResultSet implements ResultSet{ } + private void throwForwardOnly() throws SQLException{ + throw new SQLException("ResultSet is forward only.", "24000"); + } + + + private void throwReadOnly() throws SQLException{ + throw new SQLException("ResultSet is read only.", "24000"); + } + + + /** + * Check if this ResultSet is closed before access to the DbDataReader + * + * @return + * @throws SQLException + */ + private DbDataReader getReader() throws SQLException{ + if(reader == null){ + throw new SQLException("ResultSet is closed.", "24000"); + } + return reader; + } + + + /** + * {@inheritDoc} + */ + @Override protected Object getObjectImpl(int columnIndex) throws SQLException{ try{ - columnIndex--; - Object obj = reader.get_Item(columnIndex); - if(obj == null || obj == DBNull.Value){ - wasNull = true; - return null; + DbDataReader datareader = getReader(); + try{ + return datareader.get_Item(columnIndex-1); + }catch(ArrayIndexOutOfBoundsException aioobe){ + throw new SQLException( "Invalid column number ("+columnIndex+"). A number between 1 and "+datareader.get_FieldCount()+" is valid.", "S1002"); } - return obj; }catch(Throwable ex){ throw JdbcOdbcUtils.createSQLException(ex); } } - - private void throwReadOnly() throws SQLException{ - throw new SQLException("ResultSet is read only."); - } - } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java b/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java index 6906647b..1dcce738 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java @@ -34,8 +34,17 @@ public class JdbcOdbcStatement implements Statement{ private final JdbcOdbcConnection jdbcConn; - private final DbCommand command; - + protected final DbCommand command; + + private DbDataReader reader; + + private ResultSet rs; + + private int updateCount; + + private boolean isClosed; + + private ResultSet moreResults; public JdbcOdbcStatement(JdbcOdbcConnection jdbcConn, DbCommand command){ this.jdbcConn = jdbcConn; @@ -70,33 +79,42 @@ public class JdbcOdbcStatement implements Statement{ } - public void close(){ + public void close() throws SQLException{ + isClosed = true; + if(rs != null){ + rs.close(); + } + if(reader != null){ + reader.Close(); + } command.Dispose(); } public boolean execute(String sql) throws SQLException{ try{ - command.set_CommandText(sql); - DbDataReader reader = command.ExecuteReader(); - return reader != null; + if(sql != null){ + command.set_CommandText(sql); + } + command.ExecuteNonQuery(); + return false; }catch(Throwable ex){ throw JdbcOdbcUtils.createSQLException(ex); } } - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException{ + public boolean execute(String sql, int autoGeneratedKeys){ throw new UnsupportedOperationException(); } - public boolean execute(String sql, int[] columnIndexes) throws SQLException{ + public boolean execute(String sql, int[] columnIndexes){ throw new UnsupportedOperationException(); } - public boolean execute(String sql, String[] columnNames) throws SQLException{ + public boolean execute(String sql, String[] columnNames){ throw new UnsupportedOperationException(); } @@ -109,8 +127,12 @@ public class JdbcOdbcStatement implements Statement{ public ResultSet executeQuery(String sql) throws SQLException{ try{ - command.set_CommandText(sql); - return new JdbcOdbcResultSet(this, command.ExecuteReader()); + if(sql != null){ + command.set_CommandText(sql); + } + reader = command.ExecuteReader(); + rs = new JdbcOdbcResultSet(this, reader); + return rs; }catch(Throwable ex){ throw JdbcOdbcUtils.createSQLException(ex); } @@ -119,8 +141,11 @@ public class JdbcOdbcStatement implements Statement{ public int executeUpdate(String sql) throws SQLException{ try{ - command.set_CommandText(sql); - return command.ExecuteNonQuery(); + if(sql != null){ + command.set_CommandText(sql); + } + updateCount = command.ExecuteNonQuery(); + return updateCount; }catch(Throwable ex){ throw JdbcOdbcUtils.createSQLException(ex); } @@ -177,8 +202,22 @@ public class JdbcOdbcStatement implements Statement{ public boolean getMoreResults() throws SQLException{ - // TODO Auto-generated method stub - return false; + try{ + if(moreResults != null){ + rs = moreResults; + moreResults = null; + return true; + } + boolean isNext = reader.NextResult(); + if(isNext){ + rs = new JdbcOdbcResultSet(this, reader); + return true; + } + rs = null; + return false; + }catch(Throwable th){ + throw JdbcOdbcUtils.createSQLException(th); + } } @@ -193,9 +232,8 @@ public class JdbcOdbcStatement implements Statement{ } - public ResultSet getResultSet() throws SQLException{ - // TODO Auto-generated method stub - return null; + public ResultSet getResultSet(){ + return rs; } @@ -217,9 +255,8 @@ public class JdbcOdbcStatement implements Statement{ } - public int getUpdateCount() throws SQLException{ - // TODO Auto-generated method stub - return 0; + public int getUpdateCount(){ + return updateCount; } @@ -229,9 +266,8 @@ public class JdbcOdbcStatement implements Statement{ } - public boolean isClosed() throws SQLException{ - // TODO Auto-generated method stub - return false; + public boolean isClosed(){ + return isClosed; } @@ -299,5 +335,26 @@ public class JdbcOdbcStatement implements Statement{ } throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000"); } + + /** + * Close the DbDataReader if there are no more results. + * This give some blocking free without calling close() explicit. + * If there are more results then we need to save it. + */ + void closeReaderIfPossible(){ + ResultSet currentRs = rs; + boolean isMoreResults; + try{ + isMoreResults = getMoreResults(); + }catch(SQLException ex){ + isMoreResults = false; + } + if(!isMoreResults){ + reader.Close(); //this give the ODBC cursor free + }else{ + moreResults = rs; + } + rs = currentRs; + } } diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java b/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java index 2958cc45..8ef74913 100644 --- a/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java +++ b/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java @@ -27,6 +27,7 @@ import ikvm.lang.CIL; import java.math.BigDecimal; import java.sql.*; +import java.util.Calendar; import java.util.HashMap; import cli.System.Data.Common.DbException; @@ -46,7 +47,7 @@ public class JdbcOdbcUtils{ classNameMap.put("System.Double", "java.lang.Double"); classNameMap.put("System.Decimal", "java.math.BigDecimal"); classNameMap.put("System.DateTime", "java.sql.Timestamp"); - classNameMap.put("System.TimeSpan", "java.sql.Time"); + classNameMap.put("System.TimeSpan", "java.sql.Time"); } @@ -97,19 +98,64 @@ public class JdbcOdbcUtils{ return obj; } + /** * Get the milliseconds in the Java range from a .NET DateTime object. - * @param dt the DateTime object + * + * @param dt + * the DateTime object * @return the milliseconds since 1970-01-01 */ public static long getJavaMillis(cli.System.DateTime dt){ - //calculation copied from System.currentTimeMillis() + // calculation copied from System.currentTimeMillis() long january_1st_1970 = 62135596800000L; return dt.get_Ticks() / 10000L - january_1st_1970; } - + + + /** + * Convert a local (current default) Date to a Date in the time zone of the given calendar. Do nothing if date or + * calendar is null. + * + * @param date + * the converting Date + * @param cal + * the Calendar with the time zone + */ + public static void convertLocalToCalendarDate(java.util.Date date, Calendar cal){ + if(date == null || cal == null){ + return; + } + cal.set(date.getYear() + 1900, date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date + .getSeconds()); + long millis = cal.getTimeInMillis() / 1000 * 1000 + date.getTime() % 1000; + date.setTime(millis); + } + + + /** + * Convert a Date in the calendar time zone to a date in the local (current default) time zone. Do nothing if date + * or calendar is null. + * + * @param date + * @param cal + */ + public static void convertCalendarToLocalDate(java.util.Date date, Calendar cal){ + if(date == null || cal == null){ + return; + } + cal.setTimeInMillis(date.getTime()); + date.setYear(cal.get(Calendar.YEAR)-1900); + date.setMonth(cal.get(Calendar.MONTH)); + date.setDate(cal.get(Calendar.DAY_OF_MONTH)); + date.setHours(cal.get(Calendar.HOUR_OF_DAY)); + date.setMinutes(cal.get(Calendar.MINUTE)); + date.setSeconds(cal.get(Calendar.SECOND)); + } + + /** - * The only valid Exception for JDBC is a SQLException. + * The only valid Exception for JDBC is a SQLException. Here we create one based on the real exception. * * @param th * any Throwable that occur |