1988649 with jdk 1.6 build fails
[csql.git] / src / jdbc / JdbcSqlStatement.java
blobec7174476196a3b34343b842ca1907804105a2e1
1 package csql.jdbc;
2 import java.sql.Connection;
3 import java.sql.Statement;
4 import java.sql.SQLException;
5 import java.sql.ResultSet;
6 import java.sql.SQLWarning;
8 public class JdbcSqlStatement extends JSqlError implements Statement, JSqlErrorType
10 public boolean closedFlag;
11 public boolean isPrepared;
12 public int rowsAffect;
13 public JSqlStatement jniStmt;
14 public JdbcSqlConnection conn;
15 public JdbcSqlResultSet rs;
17 JdbcSqlStatement( Connection con )
19 jniStmt = new JSqlStatement();
20 conn = (JdbcSqlConnection) con;
21 jniStmt.alloc(conn.mode);
22 jniStmt.setConnectionPtr( conn.getConnection().getPtr() );
23 closedFlag = false;
24 isPrepared = false;
25 rowsAffect = 0;
26 rs = new JdbcSqlResultSet();
28 protected void finalize ()
30 try
32 if(!closedFlag)
33 close();
34 jniStmt.free();//praba
36 catch(SQLException e)
38 System.out.println(e);
41 public void prepareInt(String query) throws SQLException
43 int rv = 0;
44 if(isPrepared)
46 if(jniStmt.isSelect()) rs.close();
47 jniStmt.freeStmt();
48 isPrepared = false;
50 rv = jniStmt.prepare(query);
51 if( rv != 0 ) // 0 ->OK
53 throw getException(CSQL_PREPARE_ERR);
55 isPrepared = true;
57 public boolean executeInt() throws SQLException
59 if (!isPrepared) throw getException(CSQL_NOT_PREPARED);
60 boolean isSelect = jniStmt.isSelect();
61 rowsAffect = jniStmt.execute();
62 if( rowsAffect < 0 )
63 throw getException(CSQL_EXECUTE_ERR);
64 if(conn.getAutoCommit())
65 conn.commit();
67 return(isSelect);
70 public void close() throws SQLException
72 if(closedFlag) return;
73 if(isPrepared)
75 if(jniStmt.isSelect() ) rs.close();
76 jniStmt.freeStmt();
77 //jniStmt.free(); Praba. this makes the stmt unusable after close
79 closedFlag = true;
80 return;
83 public void closeScan() throws SQLException
85 if( jniStmt.isSelect()) jniStmt.close();
88 public boolean execute (String query) throws SQLException
90 prepareInt(query);
91 return(executeInt());
94 public ResultSet executeQuery(String query) throws SQLException
96 prepareInt(query);
97 if( !jniStmt.isSelect() ) {
98 jniStmt.freeStmt();
99 isPrepared = false;
100 throw getException(CSQL_NOT_QUERY);
102 boolean hasResult = executeInt();
104 rs.setStmt( this );
105 return( rs );
107 public int executeUpdate (String query) throws SQLException
109 if(execute(query))
110 throw getException(CSQL_NOT_UPDATE);
111 return(rowsAffect);
113 public Connection getConnection() throws SQLException
115 return(conn);
117 public int getFetchDirection() throws SQLException
119 return(ResultSet.FETCH_FORWARD);
121 public int getFetchSize() throws SQLException
123 return 1;
125 public ResultSet getResultSet() throws SQLException
127 if(!jniStmt.isSelect())
128 return (null);
129 //praba:;changed this
130 rs.setStmt(this);
131 return rs;
133 public int getResultSetConcurrency() throws SQLException
135 return(ResultSet.CONCUR_READ_ONLY);
137 public int getResultSetHoldability() throws SQLException
139 return(ResultSet.CLOSE_CURSORS_AT_COMMIT);
141 public int getResultSetType() throws SQLException
143 return(ResultSet.TYPE_FORWARD_ONLY);
145 public int getUpdateCount() throws SQLException
147 if(jniStmt.isSelect())
148 return -1;
149 return rowsAffect;
153 //Unsupported APIs
154 public void addBatch(String sql) throws SQLException
156 throw getException(CSQL_NOT_SUPPORTED);
158 public void cancel() throws SQLException
160 throw getException(CSQL_NOT_SUPPORTED);
162 public void clearBatch() throws SQLException
164 throw getException(CSQL_NOT_SUPPORTED);
166 public void clearWarnings() throws SQLException
168 throw getException(CSQL_NOT_SUPPORTED);
170 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
172 throw getException(CSQL_NOT_SUPPORTED);
174 public boolean execute(String sql, int[] columnIndexes) throws SQLException
176 throw getException(CSQL_NOT_SUPPORTED);
178 public boolean execute(String sql, String[] columnNames) throws SQLException
180 throw getException(CSQL_NOT_SUPPORTED);
182 public int[] executeBatch() throws SQLException
184 throw getException(CSQL_NOT_SUPPORTED);
186 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
188 throw getException(CSQL_NOT_SUPPORTED);
190 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
192 throw getException(CSQL_NOT_SUPPORTED);
194 public int executeUpdate(String sql, String[] columnNames) throws SQLException
196 throw getException(CSQL_NOT_SUPPORTED);
198 public ResultSet getGeneratedKeys() throws SQLException
200 throw getException(CSQL_NOT_SUPPORTED);
202 public int getMaxFieldSize() throws SQLException
204 throw getException(CSQL_NOT_SUPPORTED);
206 public int getMaxRows() throws SQLException
208 throw getException(CSQL_NOT_SUPPORTED);
210 public boolean getMoreResults() throws SQLException
212 throw getException(CSQL_NOT_SUPPORTED);
214 public boolean getMoreResults( int current) throws SQLException
216 throw getException(CSQL_NOT_SUPPORTED);
218 public int getQueryTimeout() throws SQLException
220 throw getException(CSQL_NOT_SUPPORTED);
222 public SQLWarning getWarnings() throws SQLException
224 throw getException(CSQL_NOT_SUPPORTED);
226 public void setCursorName(String name) throws SQLException
228 throw getException(CSQL_NOT_SUPPORTED);
230 public void setEscapeProcessing(boolean enable) throws SQLException
232 throw getException(CSQL_NOT_SUPPORTED);
234 public void setFetchDirection(int direction) throws SQLException
236 throw getException(CSQL_NOT_SUPPORTED);
238 public void setFetchSize(int rows) throws SQLException
240 throw getException(CSQL_NOT_SUPPORTED);
242 public void setMaxFieldSize(int max) throws SQLException
244 throw getException(CSQL_NOT_SUPPORTED);
246 public void setMaxRows(int maxRows) throws SQLException
248 throw getException(CSQL_NOT_SUPPORTED);
250 public void setQueryTimeout(int seconds) throws SQLException
252 throw getException(CSQL_NOT_SUPPORTED);
254 //java 1.6 methods
255 public boolean isPoolable()
257 return false;
259 public void setPoolable(boolean pool)
261 return;
263 public boolean isWrapperFor(Class ifact) throws SQLException
265 throw getException(CSQL_NOT_SUPPORTED);
267 public Class unwrap(Class iface) throws SQLException
269 throw getException(CSQL_NOT_SUPPORTED);
271 public boolean isClosed()
273 return closedFlag;