2
Copyright (C) 2009, 2011 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.jdbc.odbc;
28
import cli.System.Data.*;
29
import cli.System.Data.Common.*;
30
import cli.System.Data.Odbc.*;
33
* This JDBC Driver is a wrapper to the ODBC.NET Data Provider.
35
public class JdbcOdbcStatement implements Statement{
37
private final JdbcOdbcConnection jdbcConn;
39
protected final OdbcCommand command;
41
private final int resultSetType;
43
private final int resultSetConcurrency;
45
private DbDataReader reader;
49
private int updateCount;
51
private boolean isClosed;
53
private ResultSet moreResults;
55
public JdbcOdbcStatement(JdbcOdbcConnection jdbcConn, OdbcCommand command, int resultSetType, int resultSetConcurrency){
56
this.jdbcConn = jdbcConn;
57
this.command = command;
58
this.resultSetType = resultSetType;
59
this.resultSetConcurrency = resultSetConcurrency;
63
public void addBatch(String sql) throws SQLException{
64
// TODO Auto-generated method stub
69
public void cancel() throws SQLException{
73
throw JdbcOdbcUtils.createSQLException(ex);
78
public void clearBatch() throws SQLException{
79
// TODO Auto-generated method stub
84
public void clearWarnings() throws SQLException{
85
// TODO Auto-generated method stub
90
public void close() throws SQLException{
102
public boolean execute(String sql) throws SQLException{
105
command.set_CommandText(sql);
107
command.ExecuteNonQuery();
109
}catch(Throwable ex){
110
throw JdbcOdbcUtils.createSQLException(ex);
115
public boolean execute(String sql, int autoGeneratedKeys){
116
throw new UnsupportedOperationException();
120
public boolean execute(String sql, int[] columnIndexes){
121
throw new UnsupportedOperationException();
125
public boolean execute(String sql, String[] columnNames){
126
throw new UnsupportedOperationException();
130
public int[] executeBatch() throws SQLException{
131
// TODO Auto-generated method stub
136
public ResultSet executeQuery(String sql) throws SQLException{
139
command.set_CommandText(sql);
141
if(resultSetConcurrency == ResultSet.CONCUR_UPDATABLE){
142
rs = new JdbcOdbcUpdateableResultSet(command);
144
if(resultSetType == ResultSet.TYPE_FORWARD_ONLY){
145
reader = command.ExecuteReader();
146
rs = new JdbcOdbcResultSet(this, reader);
148
OdbcDataAdapter da = new OdbcDataAdapter(command);
149
DataTable dt = new DataTable();
151
rs = new JdbcOdbcDTResultSet(dt);
155
}catch(Throwable ex){
156
throw JdbcOdbcUtils.createSQLException(ex);
161
public int executeUpdate(String sql) throws SQLException{
164
command.set_CommandText(sql);
166
updateCount = command.ExecuteNonQuery();
168
}catch(Throwable ex){
169
throw JdbcOdbcUtils.createSQLException(ex);
174
public int executeUpdate(String sql, int autoGeneratedKeys){
175
throw new UnsupportedOperationException();
179
public int executeUpdate(String sql, int[] columnIndexes){
180
throw new UnsupportedOperationException();
184
public int executeUpdate(String sql, String[] columnNames){
185
throw new UnsupportedOperationException();
189
public Connection getConnection(){
194
public int getFetchDirection(){
195
return ResultSet.FETCH_UNKNOWN;
199
public int getFetchSize(){
204
public ResultSet getGeneratedKeys(){
205
throw new UnsupportedOperationException();
209
public int getMaxFieldSize() throws SQLException{
210
// TODO Auto-generated method stub
215
public int getMaxRows() throws SQLException{
216
// TODO Auto-generated method stub
221
public boolean getMoreResults() throws SQLException{
223
if(moreResults != null){
228
boolean isNext = reader.NextResult();
230
rs = new JdbcOdbcResultSet(this, reader);
235
}catch(Throwable th){
236
throw JdbcOdbcUtils.createSQLException(th);
241
public boolean getMoreResults(int current) throws SQLException{
242
// TODO Auto-generated method stub
247
public int getQueryTimeout(){
248
return command.get_CommandTimeout();
252
public ResultSet getResultSet(){
257
public int getResultSetConcurrency(){
258
return resultSetConcurrency;
262
public int getResultSetHoldability() throws SQLException{
263
// TODO Auto-generated method stub
268
public int getResultSetType(){
269
return resultSetType;
273
public int getUpdateCount(){
278
public SQLWarning getWarnings() throws SQLException{
279
// TODO Auto-generated method stub
284
public boolean isClosed(){
289
public void setCursorName(String name) throws SQLException{
290
// TODO Auto-generated method stub
295
public void setEscapeProcessing(boolean enable) throws SQLException{
296
// TODO Auto-generated method stub
301
public void setFetchDirection(int direction){
306
public void setFetchSize(int rows){
311
public void setMaxFieldSize(int max) throws SQLException{
312
// TODO Auto-generated method stub
317
public void setMaxRows(int max) throws SQLException{
318
// TODO Auto-generated method stub
323
public boolean isPoolable(){
328
public void setPoolable(boolean poolable) throws SQLException{
333
public void setQueryTimeout(int seconds){
334
command.set_CommandTimeout(seconds);
338
public boolean isWrapperFor(Class<?> iface){
339
return iface.isAssignableFrom(this.getClass());
343
public <T>T unwrap(Class<T> iface) throws SQLException{
344
if(isWrapperFor(iface)){
347
throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
351
* Close the DbDataReader if there are no more results.
352
* This give some blocking free without calling close() explicit.
353
* If there are more results then we need to save it.
355
void closeReaderIfPossible(){
356
ResultSet currentRs = rs;
357
boolean isMoreResults;
359
isMoreResults = getMoreResults();
360
}catch(SQLException ex){
361
isMoreResults = false;
364
reader.Close(); //this give the ODBC cursor free
375
public void closeOnCompletion() throws SQLException {
382
public boolean isCloseOnCompletion() throws SQLException {