reverting back to 1.20
[csql.git] / src / jdbc / JdbcSqlStatement.java
blob28334a7046e946fefcc4d6f7073a7f4ff9a4f677
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;
16 public boolean isSelect;
18 JdbcSqlStatement( Connection con )
20 jniStmt = new JSqlStatement();
21 conn = (JdbcSqlConnection) con;
22 jniStmt.alloc(conn.mode);
23 jniStmt.setConnectionPtr( conn.getConnection().getPtr() );
24 closedFlag = false;
25 isPrepared = false;
26 rowsAffect = 0;
27 isSelect = false;
28 rs = new JdbcSqlResultSet();
30 protected void finalize ()
32 try
34 if(!closedFlag)
35 close();
36 jniStmt.free();//praba
38 catch(SQLException e)
40 System.out.println(e);
43 public void prepareInt(String query) throws SQLException
45 int rv = 0;
46 if(isPrepared)
48 if(isSelect) rs.close();
49 jniStmt.freeStmt();
50 isPrepared = false;
51 isSelect = false;
53 rv = jniStmt.prepare(query);
54 if( rv != 0 ) // 0 ->OK
56 throw getException(CSQL_PREPARE_ERR);
58 isSelect = jniStmt.isSelect();
59 isPrepared = true;
61 public boolean executeInt() throws SQLException
63 if (!isPrepared) throw getException(CSQL_NOT_PREPARED);
64 rowsAffect = jniStmt.execute();
65 if( rowsAffect < 0 )
66 throw getException(CSQL_EXECUTE_ERR);
67 if(conn.getAutoCommit())
68 conn.commit();
70 return(isSelect);
73 public void close() throws SQLException
75 if(closedFlag) return;
76 if(isPrepared)
78 if(isSelect) rs.close();
79 jniStmt.freeStmt();
80 //jniStmt.free(); Praba. this makes the stmt unusable after close
82 closedFlag = true;
83 return;
86 public void closeScan() throws SQLException
88 if(isSelect) jniStmt.close();
91 public boolean execute (String query) throws SQLException
93 prepareInt(query);
94 return(executeInt());
97 public ResultSet executeQuery(String query) throws SQLException
99 prepareInt(query);
100 if( !isSelect ) {
101 jniStmt.freeStmt();
102 isPrepared = false;
103 throw getException(CSQL_NOT_QUERY);
105 boolean hasResult = executeInt();
107 rs.setStmt( this );
108 return( rs );
110 public int executeUpdate (String query) throws SQLException
112 if(execute(query))
113 throw getException(CSQL_NOT_UPDATE);
114 return(rowsAffect);
116 public Connection getConnection() throws SQLException
118 return(conn);
120 public int getFetchDirection() throws SQLException
122 return(ResultSet.FETCH_FORWARD);
124 public int getFetchSize() throws SQLException
126 return 1;
128 public ResultSet getResultSet() throws SQLException
130 if(!isSelect)
131 return (null);
132 if(closedFlag) throw getException( CSQL_INVALID_STATE );
133 rs.setStmt(this);
134 return rs;
136 public int getResultSetConcurrency() throws SQLException
138 return(ResultSet.CONCUR_READ_ONLY);
140 public int getResultSetHoldability() throws SQLException
142 return(ResultSet.CLOSE_CURSORS_AT_COMMIT);
144 public int getResultSetType() throws SQLException
146 return(ResultSet.TYPE_FORWARD_ONLY);
148 public int getUpdateCount() throws SQLException
150 if(isSelect)
151 return -1;
152 return rowsAffect;
156 //Unsupported APIs
157 public void addBatch(String sql) throws SQLException
159 throw getException(CSQL_NOT_SUPPORTED);
161 public void cancel() throws SQLException
163 throw getException(CSQL_NOT_SUPPORTED);
165 public void clearBatch() throws SQLException
167 throw getException(CSQL_NOT_SUPPORTED);
169 public void clearWarnings() throws SQLException
171 throw getException(CSQL_NOT_SUPPORTED);
173 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
175 throw getException(CSQL_NOT_SUPPORTED);
177 public boolean execute(String sql, int[] columnIndexes) throws SQLException
179 throw getException(CSQL_NOT_SUPPORTED);
181 public boolean execute(String sql, String[] columnNames) throws SQLException
183 throw getException(CSQL_NOT_SUPPORTED);
185 public int[] executeBatch() throws SQLException
187 throw getException(CSQL_NOT_SUPPORTED);
189 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
191 throw getException(CSQL_NOT_SUPPORTED);
193 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
195 throw getException(CSQL_NOT_SUPPORTED);
197 public int executeUpdate(String sql, String[] columnNames) throws SQLException
199 throw getException(CSQL_NOT_SUPPORTED);
201 public ResultSet getGeneratedKeys() throws SQLException
203 throw getException(CSQL_NOT_SUPPORTED);
205 public int getMaxFieldSize() throws SQLException
207 throw getException(CSQL_NOT_SUPPORTED);
209 public int getMaxRows() throws SQLException
211 throw getException(CSQL_NOT_SUPPORTED);
213 public boolean getMoreResults() throws SQLException
215 throw getException(CSQL_NOT_SUPPORTED);
217 public boolean getMoreResults( int current) throws SQLException
219 throw getException(CSQL_NOT_SUPPORTED);
221 public int getQueryTimeout() throws SQLException
223 throw getException(CSQL_NOT_SUPPORTED);
225 public SQLWarning getWarnings() throws SQLException
227 throw getException(CSQL_NOT_SUPPORTED);
229 public void setCursorName(String name) throws SQLException
231 throw getException(CSQL_NOT_SUPPORTED);
233 public void setEscapeProcessing(boolean enable) throws SQLException
235 throw getException(CSQL_NOT_SUPPORTED);
237 public void setFetchDirection(int direction) throws SQLException
239 throw getException(CSQL_NOT_SUPPORTED);
241 public void setFetchSize(int rows) throws SQLException
243 throw getException(CSQL_NOT_SUPPORTED);
245 public void setMaxFieldSize(int max) throws SQLException
247 throw getException(CSQL_NOT_SUPPORTED);
249 public void setMaxRows(int maxRows) throws SQLException
251 throw getException(CSQL_NOT_SUPPORTED);
253 public void setQueryTimeout(int seconds) throws SQLException
255 throw getException(CSQL_NOT_SUPPORTED);
257 //java 1.6 methods
258 public boolean isPoolable()
260 return false;
262 public void setPoolable(boolean pool)
264 return;
266 public boolean isWrapperFor(Class ifact) throws SQLException
268 throw getException(CSQL_NOT_SUPPORTED);
270 public Class unwrap(Class iface) throws SQLException
272 throw getException(CSQL_NOT_SUPPORTED);
274 public boolean isClosed()
276 return closedFlag;