Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmallsql <smallsql>2009-01-19 00:47:51 +0300
committersmallsql <smallsql>2009-01-19 00:47:51 +0300
commit479417eefc21377331e7e6504e53ca860700fd6b (patch)
tree084e652125f727ef6f9fef2a46025460ecb70518 /openjdk/sun/jdbc
parent3b9b7e6c72f237425ec0699c9eefcde186a47e94 (diff)
JDBC-ODBC-Bridge Step 2
Diffstat (limited to 'openjdk/sun/jdbc')
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java56
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java (renamed from openjdk/sun/jdbc/odbc/JdbcOdbcMetaResultSet.java)12
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java179
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcDatabaseMetaData.java2
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java822
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcResultSetMetaData.java182
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java28
-rw-r--r--openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java146
8 files changed, 947 insertions, 480 deletions
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java b/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java
index e49f508d..3870030d 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcConnection.java
@@ -44,26 +44,30 @@ public class JdbcOdbcConnection implements Connection{
JdbcOdbcConnection(String connectString, Properties info) throws SQLException{
- boolean isDSN = connectString.indexOf('=') < 0;
- StringBuilder connStr = new StringBuilder();
- if(isDSN){
- connStr.append("DSN=");
- }
- connStr.append(connectString);
+ try{
+ boolean isDSN = connectString.indexOf('=') < 0;
+ StringBuilder connStr = new StringBuilder();
+ if(isDSN){
+ connStr.append("DSN=");
+ }
+ connStr.append(connectString);
- String uid = info.getProperty("user");
- String pwd = info.getProperty("password");
+ String uid = info.getProperty("user");
+ String pwd = info.getProperty("password");
- if(uid != null){
- connStr.append(";UID=").append(uid);
- }
- if(pwd != null){
- connStr.append(";PWD=").append(pwd);
- }
+ if(uid != null){
+ connStr.append(";UID=").append(uid);
+ }
+ if(pwd != null){
+ connStr.append(";PWD=").append(pwd);
+ }
- netConn = new OdbcConnection(connStr.toString());
+ netConn = new OdbcConnection(connStr.toString());
- netConn.Open();
+ netConn.Open();
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
+ }
}
@@ -76,8 +80,8 @@ public class JdbcOdbcConnection implements Connection{
public void close() throws SQLException{
try{
netConn.Close();
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -115,8 +119,8 @@ public class JdbcOdbcConnection implements Connection{
public Statement createStatement() throws SQLException{
try{
return new JdbcOdbcStatement(this, netConn.CreateCommand());
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -171,8 +175,8 @@ public class JdbcOdbcConnection implements Connection{
transaction.Commit();
transaction = null;
}
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -190,8 +194,8 @@ public class JdbcOdbcConnection implements Connection{
}
transaction.Commit();
transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -204,8 +208,8 @@ public class JdbcOdbcConnection implements Connection{
}
transaction.Rollback();
transaction = netConn.BeginTransaction(transaction.get_IsolationLevel());
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcMetaResultSet.java b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java
index bf4090ec..9407eef5 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcMetaResultSet.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSet.java
@@ -34,16 +34,17 @@ import java.util.Map;
import cli.System.Data.*;
/**
- * @author Volker Berlin
+ * This JDBC Driver is a wrapper to the ODBC.NET Data Provider.
+ * This ResultSet based on DataTable.
*/
-public class JdbcOdbcMetaResultSet implements ResultSet{
+public class JdbcOdbcDTResultSet implements ResultSet{
private final DataTable data;
private final DataRowCollection rows;
private int rowIndex; // row index starting with 0;
private cli.System.Data.DataRow row;
- public JdbcOdbcMetaResultSet(DataTable data){
+ public JdbcOdbcDTResultSet(DataTable data){
this.data = data;
this.rows = data.get_Rows();
this.rowIndex = -1;
@@ -93,8 +94,7 @@ public class JdbcOdbcMetaResultSet implements ResultSet{
public int findColumn(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ return data.get_Columns().IndexOf(columnLabel) + 1;
}
@@ -339,7 +339,7 @@ public class JdbcOdbcMetaResultSet implements ResultSet{
public ResultSetMetaData getMetaData(){
- return new JdbcOdbcResultSetMetaData(null, data);
+ return new JdbcOdbcDTResultSetMetaData(null, data);
}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java
new file mode 100644
index 00000000..c2e543b4
--- /dev/null
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcDTResultSetMetaData.java
@@ -0,0 +1,179 @@
+/*
+ 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.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;
+ this.table = table;
+ }
+
+
+ public String getCatalogName(int column){
+ return "";
+ }
+
+
+ public String getColumnClassName(int column){
+ cli.System.Type type = getDataColumn(column).get_DataType();
+ return type.get_FullName();
+ }
+
+
+ public int getColumnCount(){
+ return table.get_Columns().get_Count();
+ }
+
+
+ public int getColumnDisplaySize(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+
+ public String getColumnLabel(int column) throws SQLException{
+ return getDataColumn(column).get_Caption();
+ }
+
+
+ public String getColumnName(int column) throws SQLException{
+ return getDataColumn(column).get_ColumnName();
+ }
+
+
+ public int getColumnType(int column) throws SQLException{
+ cli.System.Type type = getDataColumn(column).get_DataType();
+ // TODO Auto-generated method stub
+ return Types.OTHER;
+ }
+
+
+ public String getColumnTypeName(int column) throws SQLException{
+ return reader != null ? reader.GetDataTypeName(column - 1) : "";
+ }
+
+
+ public int getPrecision(int column) throws SQLException{
+ return getDataColumn(column).get_MaxLength();
+ }
+
+
+ public int getScale(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+
+ public String getSchemaName(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public String getTableName(int column) throws SQLException{
+ return table.get_TableName();
+ }
+
+
+ public boolean isAutoIncrement(int column) throws SQLException{
+ return getDataColumn(column).get_AutoIncrement();
+ }
+
+
+ public boolean isCaseSensitive(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public boolean isCurrency(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public boolean isDefinitelyWritable(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public int isNullable(int column) throws SQLException{
+ return getDataColumn(column).get_AllowDBNull() ? columnNullable : columnNoNulls;
+ }
+
+
+ public boolean isReadOnly(int column) throws SQLException{
+ return getDataColumn(column).get_ReadOnly();
+ }
+
+
+ public boolean isSearchable(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public boolean isSigned(int column) throws SQLException{
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+ public boolean isWritable(int column) throws SQLException{
+ return !getDataColumn(column).get_ReadOnly();
+ }
+
+
+ public boolean isWrapperFor(Class<?> iface){
+ return iface.isAssignableFrom(this.getClass());
+ }
+
+
+ public <T>T unwrap(Class<T> iface) throws SQLException{
+ if(isWrapperFor(iface)){
+ return (T)this;
+ }
+ throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
+ }
+
+
+ private DataColumn getDataColumn(int column){
+ return table.get_Columns().get_Item(column - 1);
+ }
+}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcDatabaseMetaData.java b/openjdk/sun/jdbc/odbc/JdbcOdbcDatabaseMetaData.java
index 48e08525..24a106e6 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcDatabaseMetaData.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcDatabaseMetaData.java
@@ -413,7 +413,7 @@ public class JdbcOdbcDatabaseMetaData implements DatabaseMetaData{
// the description of the restrictions can you request with GetSchema("Restrictions")
String[] restrictions = new String[]{catalog, schemaPattern, procedureNamePattern};
DataTable data = netConn.GetSchema(OdbcMetaDataCollectionNames.Procedures, restrictions);
- return new JdbcOdbcMetaResultSet(data);
+ return new JdbcOdbcDTResultSet(data);
}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java
index 45ba0416..5c8b2923 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSet.java
@@ -23,18 +23,34 @@
*/
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;
/**
- * This JDBC Driver is a wrapper to the ODBC.NET Data Provider
+ * This JDBC Driver is a wrapper to the ODBC.NET Data Provider. This ResultSet based on a DataReader.
*/
public class JdbcOdbcResultSet implements ResultSet{
@@ -44,34 +60,44 @@ public class JdbcOdbcResultSet implements ResultSet{
private boolean wasNull;
+ private final int holdability;
+
+ private final int concurrency;
+
+ private int fetchSize;
+
+ private int row;
+
+ private final int resultSetType;
+
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;
}
public boolean absolute(int row) throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // for Compiler
}
public void afterLast() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void beforeFirst() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void cancelRowUpdates() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
@@ -88,8 +114,7 @@ public class JdbcOdbcResultSet implements ResultSet{
public void deleteRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
@@ -99,105 +124,144 @@ public class JdbcOdbcResultSet implements ResultSet{
public boolean first() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // for compiler
}
- public Array getArray(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public Array getArray(int columnIndex){
+ throw new UnsupportedOperationException();
}
public Array getArray(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getArray(findColumn(columnLabel));
}
public InputStream getAsciiStream(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ try{
+ String str = getString(columnIndex);
+ if(str == null){
+ return null;
+ }
+ return new ByteArrayInputStream(str.getBytes("Ascii"));
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
+ }
}
public InputStream getAsciiStream(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getAsciiStream(findColumn(columnLabel));
}
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getBigDecimal(findColumn(columnLabel), scale);
}
public BigDecimal getBigDecimal(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getBigDecimal(findColumn(columnLabel));
}
public InputStream getBinaryStream(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ byte[] data = getBytes(columnIndex);
+ if(data == null){
+ return null;
+ }
+ return new ByteArrayInputStream(data);
}
public InputStream getBinaryStream(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getBinaryStream(findColumn(columnLabel));
}
- public Blob getBlob(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public Blob getBlob(int columnIndex){
+ throw new UnsupportedOperationException();
}
public Blob getBlob(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getBlob(findColumn(columnLabel));
}
public boolean getBoolean(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ 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{
- // TODO Auto-generated method stub
- return false;
+ return getBoolean(findColumn(columnLabel));
}
public byte getByte(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetByte(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ 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);
}
}
@@ -209,17 +273,17 @@ public class JdbcOdbcResultSet implements ResultSet{
public byte[] getBytes(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return null;
}
- int count = (int)reader.GetBytes(columnIndex, 0, null, 0, 0);
- byte[] buffer = new byte[count];
- reader.GetBytes(columnIndex, 0, buffer, 0, buffer.length);
- return buffer;
- }catch(Exception ex){
- throw new SQLException(ex);
+ if(obj instanceof byte[]){
+ return (byte[])obj;
+ }
+ String str = obj.toString();
+ return str.getBytes(); // which encoding?
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
}
}
@@ -230,32 +294,31 @@ public class JdbcOdbcResultSet implements ResultSet{
public Reader getCharacterStream(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ String str = getString(columnIndex);
+ if(str == null){
+ return null;
+ }
+ return new StringReader(str);
}
public Reader getCharacterStream(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getCharacterStream(findColumn(columnLabel));
}
- public Clob getClob(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public Clob getClob(int columnIndex){
+ throw new UnsupportedOperationException();
}
public Clob getClob(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getClob(findColumn(columnLabel));
}
- public int getConcurrency() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getConcurrency(){
+ return concurrency;
}
@@ -266,39 +329,67 @@ public class JdbcOdbcResultSet implements ResultSet{
public Date getDate(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getDate(findColumn(columnLabel));
}
public Date getDate(int columnIndex, Calendar cal) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getDate(findColumn(columnLabel), cal);
}
public double getDouble(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetDouble(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ 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);
}
}
@@ -308,28 +399,29 @@ public class JdbcOdbcResultSet implements ResultSet{
}
- public int getFetchDirection() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getFetchDirection(){
+ return FETCH_UNKNOWN;
}
- public int getFetchSize() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getFetchSize(){
+ return fetchSize;
}
public float getFloat(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetFloat(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ if(obj instanceof IConvertible){
+ return Convert.ToSingle(obj);
+ }
+ String str = obj.toString();
+ return Single.Parse(str);
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
}
}
@@ -339,22 +431,24 @@ public class JdbcOdbcResultSet implements ResultSet{
}
- public int getHoldability() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getHoldability(){
+ return holdability;
}
public int getInt(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetInt32(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ if(obj instanceof IConvertible){
+ return Convert.ToInt32(obj);
+ }
+ String str = obj.toString();
+ return Int32.Parse(str);
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
}
}
@@ -366,14 +460,17 @@ public class JdbcOdbcResultSet implements ResultSet{
public long getLong(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetInt64(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ if(obj instanceof IConvertible){
+ return Convert.ToInt64(obj);
+ }
+ String str = obj.toString();
+ return Int64.Parse(str);
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
}
}
@@ -384,122 +481,108 @@ public class JdbcOdbcResultSet implements ResultSet{
public ResultSetMetaData getMetaData(){
- return new JdbcOdbcResultSetMetaData(reader, reader.GetSchemaTable());
+ return new JdbcOdbcResultSetMetaData(reader);
}
public Reader getNCharacterStream(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getCharacterStream(columnIndex);
}
public Reader getNCharacterStream(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getCharacterStream(columnLabel);
}
- public NClob getNClob(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public NClob getNClob(int columnIndex){
+ throw new UnsupportedOperationException();
}
public NClob getNClob(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getNClob(findColumn(columnLabel));
}
public String getNString(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getString(columnIndex);
}
public String getNString(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getString(columnLabel);
}
public Object getObject(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return JdbcOdbcUtils.convertNet2Java(getObjectImpl(columnIndex));
}
public Object getObject(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getObject(findColumn(columnLabel));
}
- public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public Object getObject(int columnIndex, Map<String, Class<?>> map){
+ throw new UnsupportedOperationException();
}
public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getObject(findColumn(columnLabel), map);
}
- public Ref getRef(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public Ref getRef(int columnIndex){
+ throw new UnsupportedOperationException();
}
public Ref getRef(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getRef(findColumn(columnLabel));
}
- public int getRow() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getRow(){
+ return row;
}
- public RowId getRowId(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public RowId getRowId(int columnIndex){
+ throw new UnsupportedOperationException();
}
public RowId getRowId(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getRowId(findColumn(columnLabel));
}
- public SQLXML getSQLXML(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public SQLXML getSQLXML(int columnIndex){
+ throw new UnsupportedOperationException();
}
public SQLXML getSQLXML(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getSQLXML(findColumn(columnLabel));
}
public short getShort(int columnIndex) throws SQLException{
try{
- columnIndex--;
- if(reader.IsDBNull(columnIndex)){
- wasNull = true;
+ Object obj = getObjectImpl(columnIndex);
+ if(wasNull){
return 0;
}
- return reader.GetInt16(columnIndex);
- }catch(Exception ex){
- throw new SQLException(ex);
+ if(obj instanceof IConvertible){
+ return Convert.ToInt16(obj);
+ }
+ String str = obj.toString();
+ return Int16.Parse(str);
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
}
}
@@ -515,26 +598,47 @@ public class JdbcOdbcResultSet implements ResultSet{
public String getString(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getString(findColumn(columnLabel));
}
public Time getTime(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getTime(findColumn(columnLabel));
}
@@ -545,20 +649,30 @@ public class JdbcOdbcResultSet implements ResultSet{
public Time getTime(String columnLabel, Calendar cal) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getTime(findColumn(columnLabel), cal);
}
public Timestamp getTimestamp(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ 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{
- // TODO Auto-generated method stub
- return null;
+ return getTimestamp(findColumn(columnLabel));
}
@@ -569,38 +683,36 @@ public class JdbcOdbcResultSet implements ResultSet{
public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getTimestamp(findColumn(columnLabel), cal);
}
- public int getType() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getType(){
+ return resultSetType;
}
- public URL getURL(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ public URL getURL(int columnIndex){
+ throw new UnsupportedOperationException();
}
public URL getURL(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getURL(findColumn(columnLabel));
}
public InputStream getUnicodeStream(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ try{
+ return new ByteArrayInputStream(getString(columnIndex).getBytes("UTF16"));
+ }catch(Throwable th){
+ throw JdbcOdbcUtils.createSQLException(th);
+ }
}
public InputStream getUnicodeStream(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ return getUnicodeStream(findColumn(columnLabel));
}
@@ -611,20 +723,19 @@ public class JdbcOdbcResultSet implements ResultSet{
public void insertRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public boolean isAfterLast() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean isBeforeFirst() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
@@ -635,583 +746,500 @@ public class JdbcOdbcResultSet implements ResultSet{
public boolean isFirst() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean isLast() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean last() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public void moveToCurrentRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void moveToInsertRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public boolean next() throws SQLException{
- return reader.Read();
+ if(reader.Read()){
+ row++;
+ return true;
+ }
+ row = 0;
+ return false;
}
public boolean previous() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public void refreshRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public boolean relative(int rows) throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean rowDeleted() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean rowInserted() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
public boolean rowUpdated() throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ throwReadOnly();
+ return false; // only for compiler
}
- public void setFetchDirection(int direction) throws SQLException{
- // TODO Auto-generated method stub
-
+ public void setFetchDirection(int direction){
+ // ignore it
}
- public void setFetchSize(int rows) throws SQLException{
- // TODO Auto-generated method stub
-
+ public void setFetchSize(int rows){
+ // ignore it
}
public void updateArray(int columnIndex, Array x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateArray(String columnLabel, Array x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(int columnIndex, Blob x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(String columnLabel, Blob x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBoolean(int columnIndex, boolean x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBoolean(String columnLabel, boolean x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateByte(int columnIndex, byte x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateByte(String columnLabel, byte x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBytes(int columnIndex, byte[] x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateBytes(String columnLabel, byte[] x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(int columnIndex, Reader x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(int columnIndex, Clob x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(String columnLabel, Clob x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(int columnIndex, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(String columnLabel, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(int columnIndex, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateClob(String columnLabel, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateDate(int columnIndex, Date x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateDate(String columnLabel, Date x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateDouble(int columnIndex, double x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateDouble(String columnLabel, double x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateFloat(int columnIndex, float x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateFloat(String columnLabel, float x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateInt(int columnIndex, int x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateInt(String columnLabel, int x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateLong(int columnIndex, long x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateLong(String columnLabel, long x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(int columnIndex, NClob clob) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(String columnLabel, NClob clob) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(int columnIndex, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNClob(String columnLabel, Reader reader) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNString(int columnIndex, String string) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNString(String columnLabel, String string) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNull(int columnIndex) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateNull(String columnLabel) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateObject(int columnIndex, Object x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateObject(String columnLabel, Object x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateRef(int columnIndex, Ref x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateRef(String columnLabel, Ref x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateRow() throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateRowId(int columnIndex, RowId x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateRowId(String columnLabel, RowId x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateShort(int columnIndex, short x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateShort(String columnLabel, short x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateString(int columnIndex, String x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateString(String columnLabel, String x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateTime(int columnIndex, Time x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateTime(String columnLabel, Time x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException{
- // TODO Auto-generated method stub
-
+ throwReadOnly();
}
@@ -1232,4 +1260,24 @@ public class JdbcOdbcResultSet implements ResultSet{
throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
}
+
+ 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;
+ }
+ 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/JdbcOdbcResultSetMetaData.java b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSetMetaData.java
index 8f75f868..e3908b06 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcResultSetMetaData.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcResultSetMetaData.java
@@ -23,139 +23,227 @@
*/
package sun.jdbc.odbc;
-import java.sql.*;
+import ikvm.lang.CIL;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import cli.System.Convert;
+import cli.System.DBNull;
import cli.System.Data.*;
import cli.System.Data.Common.*;
/**
- * This JDBC Driver is a wrapper to the ODBC.NET Data Provider
+ * This JDBC Driver is a wrapper to the ODBC.NET Data Provider.
*/
public class JdbcOdbcResultSetMetaData implements ResultSetMetaData{
private final DbDataReader reader;
- private final DataTable table;
-
-
- public JdbcOdbcResultSetMetaData(DbDataReader reader, DataTable table){
+
+ private final DataTable schema;
+
+ JdbcOdbcResultSetMetaData(DbDataReader reader){
this.reader = reader;
- this.table = table;
+ schema = reader.GetSchemaTable();
}
-
-
- public String getCatalogName(int column){
- return "";
+
+ public String getCatalogName(int column) throws SQLException{
+ Object obj = getColumnMeta(column, "BaseCatalogName");
+ if(obj == null || obj == DBNull.Value){
+ return "";
+ }
+ return obj.toString();
}
- public String getColumnClassName(int column){
- cli.System.Type type = getDataColumn(column).get_DataType();
- return type.get_FullName();
+ public String getColumnClassName(int column) throws SQLException{
+ String type = getColumnMeta(column, "DataType").toString();
+ return JdbcOdbcUtils.getJavaClassName(type);
}
public int getColumnCount(){
- return table.get_Columns().get_Count();
+ return schema.get_Rows().get_Count();
}
public int getColumnDisplaySize(int column) throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ int precision = getPrecision(column);
+ int type = CIL.unbox_int( getColumnMeta(column, "ProviderType") );
+ switch(type){
+ case DbType.Decimal:
+ case DbType.Currency:
+ case DbType.VarNumeric:
+ return precision + (getScale(column) > 0 ? 2 : 1); // + sign and comma
+ }
+ return precision;
}
public String getColumnLabel(int column) throws SQLException{
- return getDataColumn(column).get_Caption();
+ return getColumnMeta(column, "ColumnName").toString();
}
public String getColumnName(int column) throws SQLException{
- return getDataColumn(column).get_ColumnName();
+ return getColumnMeta(column, "ColumnName").toString();
}
public int getColumnType(int column) throws SQLException{
- cli.System.Type type = getDataColumn(column).get_DataType();
- // TODO Auto-generated method stub
+ int type = CIL.unbox_int( getColumnMeta(column, "ProviderType") );
+ switch(type){
+ case DbType.AnsiString:
+ return Types.VARCHAR;
+ case DbType.AnsiStringFixedLength:
+ return Types.CHAR;
+ case DbType.Binary:
+ return Types.BINARY;
+ case DbType.Boolean:
+ return Types.BOOLEAN;
+ case DbType.Byte:
+ case DbType.SByte:
+ return Types.TINYINT;
+ case DbType.Date:
+ return Types.DATE;
+ case DbType.DateTime:
+ case DbType.DateTime2:
+ case DbType.DateTimeOffset:
+ return Types.TIMESTAMP;
+ case DbType.Decimal:
+ case DbType.Currency:
+ return Types.DECIMAL;
+ case DbType.Double:
+ return Types.DOUBLE;
+ case DbType.Guid:
+ return Types.ROWID;
+ case DbType.Int16:
+ case DbType.UInt16:
+ return Types.SMALLINT;
+ case DbType.Int32:
+ case DbType.UInt32:
+ return Types.INTEGER;
+ case DbType.Int64:
+ case DbType.UInt64:
+ return Types.BIGINT;
+ case DbType.Single:
+ return Types.FLOAT;
+ case DbType.String:
+ return Types.NVARCHAR;
+ case DbType.StringFixedLength:
+ return Types.NCHAR;
+ case DbType.Time:
+ return Types.TIME;
+ case DbType.VarNumeric:
+ return Types.NUMERIC;
+ case DbType.Xml:
+ return Types.SQLXML;
+ }
return Types.OTHER;
}
public String getColumnTypeName(int column) throws SQLException{
- return reader != null ? reader.GetDataTypeName(column - 1) : "";
+ try{
+ return reader.GetDataTypeName(column - 1);
+ }catch(ArrayIndexOutOfBoundsException ex){
+ throw new SQLException("Invalid column number ("+column+"). A number between 1 and "+schema.get_Rows().get_Count()+" is valid.", "S1002");
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
+ }
}
public int getPrecision(int column) throws SQLException{
- return getDataColumn(column).get_MaxLength();
+ Object obj = getColumnMeta(column, "NumericPrecision");
+ return Convert.ToInt32(obj);
}
public int getScale(int column) throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ Object obj = getColumnMeta(column, "NumericScale");
+ return Convert.ToInt32(obj);
}
public String getSchemaName(int column) throws SQLException{
- // TODO Auto-generated method stub
- return null;
+ Object obj = getColumnMeta(column, "BaseSchemaName");
+ if(obj == null || obj == DBNull.Value){
+ return "";
+ }
+ return obj.toString();
}
public String getTableName(int column) throws SQLException{
- return table.get_TableName();
+ Object obj = getColumnMeta(column, "BaseTableName");
+ if(obj == null || obj == DBNull.Value){
+ return "";
+ }
+ return obj.toString();
}
public boolean isAutoIncrement(int column) throws SQLException{
- return getDataColumn(column).get_AutoIncrement();
+ Object obj = getColumnMeta(column, "IsAutoIncrement");
+ return Convert.ToBoolean(obj);
}
- public boolean isCaseSensitive(int column) throws SQLException{
- // TODO Auto-generated method stub
+ public boolean isCaseSensitive(int column){
return false;
}
public boolean isCurrency(int column) throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ return CIL.unbox_int( getColumnMeta(column, "ProviderType") ) == DbType.Currency;
}
- public boolean isDefinitelyWritable(int column) throws SQLException{
- // TODO Auto-generated method stub
+ public boolean isDefinitelyWritable(int column){
return false;
}
public int isNullable(int column) throws SQLException{
- return getDataColumn(column).get_AllowDBNull() ? columnNullable : columnNoNulls;
+ Object obj = getColumnMeta(column, "AllowDBNull");
+ return Convert.ToBoolean(obj) ? columnNullable : columnNoNulls;
}
public boolean isReadOnly(int column) throws SQLException{
- return getDataColumn(column).get_ReadOnly();
+ Object obj = getColumnMeta(column, "IsReadOnly");
+ return Convert.ToBoolean(obj);
}
public boolean isSearchable(int column) throws SQLException{
- // TODO Auto-generated method stub
- return false;
+ return !CIL.unbox_boolean( getColumnMeta(column, "IsLong") );
}
public boolean isSigned(int column) throws SQLException{
- // TODO Auto-generated method stub
+ int type = CIL.unbox_int( getColumnMeta(column, "ProviderType") );
+ switch(type){
+ case DbType.Currency:
+ case DbType.Decimal:
+ case DbType.Double:
+ case DbType.Int16:
+ case DbType.Int32:
+ case DbType.Int64:
+ case DbType.SByte:
+ case DbType.Single:
+ case DbType.VarNumeric:
+ return true;
+ }
return false;
}
public boolean isWritable(int column) throws SQLException{
- return !getDataColumn(column).get_ReadOnly();
+ Object obj = getColumnMeta(column, "IsReadOnly");
+ return !Convert.ToBoolean(obj);
}
@@ -170,9 +258,13 @@ public class JdbcOdbcResultSetMetaData implements ResultSetMetaData{
}
throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
}
-
-
- private DataColumn getDataColumn(int column){
- return table.get_Columns().get_Item(column - 1);
+
+ private Object getColumnMeta(int column, String metaKey) throws SQLException{
+ try{
+ DataRow columnMeta = schema.get_Rows().get_Item(column-1);
+ return columnMeta.get_Item(metaKey);
+ }catch(ArrayIndexOutOfBoundsException ex){
+ throw new SQLException("Invalid column number ("+column+"). A number between 1 and "+schema.get_Rows().get_Count()+" is valid.", "S1002");
+ }
}
}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java b/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java
index d71609dc..6906647b 100644
--- a/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcStatement.java
@@ -28,7 +28,7 @@ import java.sql.*;
import cli.System.Data.Common.*;
/**
- * This JDBC Driver is a wrapper to the ODBC.NET Data Provider
+ * This JDBC Driver is a wrapper to the ODBC.NET Data Provider.
*/
public class JdbcOdbcStatement implements Statement{
@@ -52,8 +52,8 @@ public class JdbcOdbcStatement implements Statement{
public void cancel() throws SQLException{
try{
command.Cancel();
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -80,8 +80,8 @@ public class JdbcOdbcStatement implements Statement{
command.set_CommandText(sql);
DbDataReader reader = command.ExecuteReader();
return reader != null;
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -111,8 +111,8 @@ public class JdbcOdbcStatement implements Statement{
try{
command.set_CommandText(sql);
return new JdbcOdbcResultSet(this, command.ExecuteReader());
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -121,8 +121,8 @@ public class JdbcOdbcStatement implements Statement{
try{
command.set_CommandText(sql);
return command.ExecuteNonQuery();
- }catch(Exception ex){
- throw new SQLException(ex);
+ }catch(Throwable ex){
+ throw JdbcOdbcUtils.createSQLException(ex);
}
}
@@ -188,9 +188,8 @@ public class JdbcOdbcStatement implements Statement{
}
- public int getQueryTimeout() throws SQLException{
- // TODO Auto-generated method stub
- return 0;
+ public int getQueryTimeout(){
+ return command.get_CommandTimeout();
}
@@ -284,9 +283,8 @@ public class JdbcOdbcStatement implements Statement{
}
- public void setQueryTimeout(int seconds) throws SQLException{
- // TODO Auto-generated method stub
-
+ public void setQueryTimeout(int seconds){
+ command.set_CommandTimeout(seconds);
}
diff --git a/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java b/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java
new file mode 100644
index 00000000..2958cc45
--- /dev/null
+++ b/openjdk/sun/jdbc/odbc/JdbcOdbcUtils.java
@@ -0,0 +1,146 @@
+/*
+ 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 ikvm.lang.CIL;
+
+import java.math.BigDecimal;
+import java.sql.*;
+import java.util.HashMap;
+
+import cli.System.Data.Common.DbException;
+import cli.System.Data.Odbc.*;
+
+/**
+ * @author Volker Berlin
+ */
+public class JdbcOdbcUtils{
+
+ private static final HashMap<String, String> classNameMap = new HashMap<String, String>();
+ static{
+ classNameMap.put("System.String", "java.lang.String");
+ classNameMap.put("System.Int16", "java.lang.Short");
+ classNameMap.put("System.Int32", "java.lang.Integer");
+ classNameMap.put("System.Int64", "java.lang.Long");
+ 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");
+ }
+
+
+ /**
+ * Solve a mapping between .NET class names and the equivalent Java class names for
+ * ResultSetMetaData.getColumnClassName
+ *
+ * @param netClassName
+ * the .NET class name
+ * @return the Java class name
+ */
+ public static String getJavaClassName(String netClassName){
+ String javaClassName = classNameMap.get(netClassName);
+ if(javaClassName != null){
+ return javaClassName;
+ }
+ return "java.lang.Object";
+ }
+
+
+ /**
+ * Convert a .NET Object in the equals Java Object.
+ *
+ * @param obj
+ * the .NET Object
+ * @return a Java Object
+ */
+ public static java.lang.Object convertNet2Java(java.lang.Object obj){
+ if(obj instanceof cli.System.Int32){
+ return Integer.valueOf(CIL.unbox_int(obj));
+ }
+ if(obj instanceof cli.System.Int16){
+ return Short.valueOf(CIL.unbox_short(obj));
+ }
+ if(obj instanceof cli.System.Byte){
+ return Byte.valueOf(CIL.unbox_byte(obj));
+ }
+ if(obj instanceof cli.System.Decimal){
+ return new BigDecimal(((cli.System.Decimal)obj).toString());
+ }
+ if(obj instanceof cli.System.DateTime){
+ return new Timestamp(getJavaMillis((cli.System.DateTime)obj));
+ }
+ 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());
+ }
+ return obj;
+ }
+
+ /**
+ * Get the milliseconds in the Java range from a .NET 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()
+ long january_1st_1970 = 62135596800000L;
+ return dt.get_Ticks() / 10000L - january_1st_1970;
+ }
+
+ /**
+ * The only valid Exception for JDBC is a SQLException.
+ *
+ * @param th
+ * any Throwable that occur
+ * @return a SQLException, never null
+ */
+ public static SQLException createSQLException(Throwable th){
+ if(th instanceof SQLException){
+ return (SQLException)th;
+ }
+ if(th instanceof OdbcException){
+ SQLException sqlEx = null;
+ OdbcErrorCollection errors = ((OdbcException)th).get_Errors();
+ for(int e = 0; e < errors.get_Count(); e++){
+ OdbcError err = errors.get_Item(e);
+ SQLException newEx = new SQLException(err.get_Message(), err.get_SQLState(), err.get_NativeError());
+ if(sqlEx == null){
+ sqlEx = newEx;
+ }else{
+ sqlEx.setNextException(newEx);
+ }
+ }
+ if(sqlEx != null){
+ sqlEx.initCause(th);
+ return sqlEx;
+ }
+ }
+ if(th instanceof DbException){
+ DbException dbEx = (DbException)th;
+ return new SQLException(dbEx.get_Message(), "S1000", dbEx.get_ErrorCode(), th);
+ }
+ return new SQLException(th);
+ }
+
+}