fix for trie index
[csql.git] / src / jdbc / JdbcSqlStatement.java
blob418eee1a2578379eacb6700d8b8ef78d4dc1e249
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;
17 public boolean isFirstExecute;
18 public int rowLimit;
19 JdbcSqlStatement( Connection con )
21 jniStmt = new JSqlStatement();
22 isFirstExecute = false;
23 conn = (JdbcSqlConnection) con;
24 jniStmt.alloc(conn.mode);
25 jniStmt.setConnectionPtr( conn.getConnection().getPtr() );
26 closedFlag = false;
27 isPrepared = false;
28 rowsAffect = 0;
29 isSelect = false;
30 rs = new JdbcSqlResultSet();
32 protected void finalize ()
34 try
36 if(!closedFlag)
37 close();
38 jniStmt.free();//praba
40 catch(SQLException e)
42 System.out.println(e);
45 public void prepareInt(String query) throws SQLException
47 int rv = 0;
48 if(isPrepared)
50 if(isSelect) rs.close();
51 jniStmt.freeStmt();
52 isPrepared = false;
53 isFirstExecute = false;
54 isSelect = false;
56 rv = jniStmt.prepare(query);
57 if( rv != 0 ) // 0 ->OK
59 throw getException(CSQL_PREPARE_ERR);
61 isSelect = jniStmt.isSelect();
62 isPrepared = true;
63 isFirstExecute = true;
65 public boolean executeInt() throws SQLException
67 if (!isPrepared) throw getException(CSQL_NOT_PREPARED);
68 rowsAffect = jniStmt.execute();
69 if( rowsAffect < 0 )
70 throw getException(CSQL_EXECUTE_ERR);
71 if(conn.getAutoCommit())
72 conn.commit();
74 return(isSelect);
77 public void close() throws SQLException
79 if(closedFlag) return;
80 if(isPrepared)
82 if(isSelect) rs.close();
83 jniStmt.freeStmt();
84 //jniStmt.free(); Praba. this makes the stmt unusable after close
86 closedFlag = true;
87 return;
90 public void closeScan() throws SQLException
92 if(isSelect) jniStmt.close();
95 public boolean execute (String query) throws SQLException
97 prepareInt(query);
98 return(executeInt());
101 public ResultSet executeQuery(String query) throws SQLException
103 prepareInt(query);
104 if( !isSelect ) {
105 jniStmt.freeStmt();
106 isPrepared = false;
107 isFirstExecute = false;
108 throw getException(CSQL_NOT_QUERY);
110 boolean hasResult = executeInt();
112 rs.setStmt( this );
113 rs.setProjField();
114 return( rs );
116 public int executeUpdate (String query) throws SQLException
118 if(execute(query))
119 throw getException(CSQL_NOT_UPDATE);
120 return(rowsAffect);
122 public Connection getConnection() throws SQLException
124 return(conn);
126 public int getFetchDirection() throws SQLException
128 return(ResultSet.FETCH_FORWARD);
130 public int getFetchSize() throws SQLException
132 return 1;
134 public ResultSet getResultSet() throws SQLException
136 if(!isSelect)
137 return (null);
138 if(closedFlag) throw getException( CSQL_INVALID_STATE );
139 rs.setStmt(this);
140 return rs;
142 public int getResultSetConcurrency() throws SQLException
144 return(ResultSet.CONCUR_READ_ONLY);
146 public int getResultSetHoldability() throws SQLException
148 return(ResultSet.CLOSE_CURSORS_AT_COMMIT);
150 public int getResultSetType() throws SQLException
152 return(ResultSet.TYPE_FORWARD_ONLY);
154 public int getUpdateCount() throws SQLException
156 // if(isSelect)
157 return -1;
158 // return rowsAffect;
162 //Unsupported APIs
163 public void addBatch(String sql) throws SQLException
165 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::addBatch called");
166 throw getException(CSQL_NOT_SUPPORTED);
168 public void cancel() throws SQLException
170 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::cancel called");
171 throw getException(CSQL_NOT_SUPPORTED);
173 public void clearBatch() throws SQLException
175 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::clearBatch called");
176 throw getException(CSQL_NOT_SUPPORTED);
178 public void clearWarnings() throws SQLException
180 //TODO
181 return;
183 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
185 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::execute called");
186 throw getException(CSQL_NOT_SUPPORTED);
188 public boolean execute(String sql, int[] columnIndexes) throws SQLException
190 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::execute called");
191 throw getException(CSQL_NOT_SUPPORTED);
193 public boolean execute(String sql, String[] columnNames) throws SQLException
195 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::execute called");
196 throw getException(CSQL_NOT_SUPPORTED);
198 public int[] executeBatch() throws SQLException
200 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::executeBatch called");
201 throw getException(CSQL_NOT_SUPPORTED);
203 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
205 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::executeUpdate called");
206 throw getException(CSQL_NOT_SUPPORTED);
208 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
210 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::executeUpdate called");
211 throw getException(CSQL_NOT_SUPPORTED);
213 public int executeUpdate(String sql, String[] columnNames) throws SQLException
215 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::executeUpdate called");
216 throw getException(CSQL_NOT_SUPPORTED);
218 public ResultSet getGeneratedKeys() throws SQLException
220 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::getGeneratedKeys called");
221 throw getException(CSQL_NOT_SUPPORTED);
223 public int getMaxFieldSize() throws SQLException
225 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::getMaxFieldSize called");
226 throw getException(CSQL_NOT_SUPPORTED);
228 public int getMaxRows() throws SQLException
230 //TODO:
231 return rowLimit;
232 //if (JSqlError.isDebug) System.out.println("JdbcSqlStatement:;getMaxRows called");
233 //throw getException(CSQL_NOT_SUPPORTED);
235 public boolean getMoreResults() throws SQLException
237 // if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::getMoreResults called");
238 //throw getException(CSQL_NOT_SUPPORTED);
239 return false;
241 public boolean getMoreResults( int current) throws SQLException
243 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::getMoreResults(int) called");
244 throw getException(CSQL_NOT_SUPPORTED);
246 public int getQueryTimeout() throws SQLException
248 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::getQueryTimeout called");
249 throw getException(CSQL_NOT_SUPPORTED);
251 public SQLWarning getWarnings() throws SQLException
253 //TODO information present in Action Item
254 return null;
256 public void setCursorName(String name) throws SQLException
258 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setCursorName called");
259 throw getException(CSQL_NOT_SUPPORTED);
261 public void setEscapeProcessing(boolean enable) throws SQLException
263 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setEscapeProcessing called");
264 throw getException(CSQL_NOT_SUPPORTED);
266 public void setFetchDirection(int direction) throws SQLException
268 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setFetchDirection called");
269 throw getException(CSQL_NOT_SUPPORTED);
271 public void setFetchSize(int rows) throws SQLException
273 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setFetchSize called");
274 throw getException(CSQL_NOT_SUPPORTED);
276 public void setMaxFieldSize(int max) throws SQLException
278 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setMaxFieldSize called");
279 throw getException(CSQL_NOT_SUPPORTED);
281 public void setMaxRows(int maxRows) throws SQLException
283 //TODO:
284 rowLimit = maxRows;
285 // if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setMaxRows called");
286 //throw getException(CSQL_NOT_SUPPORTED);
288 public void setQueryTimeout(int seconds) throws SQLException
290 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::setQueryTimeout called");
291 throw getException(CSQL_NOT_SUPPORTED);
293 //java 1.6 methods
294 public boolean isPoolable()
296 return false;
298 public void setPoolable(boolean pool)
300 return;
302 public boolean isWrapperFor(Class ifact) throws SQLException
304 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::isWrapperFor called");
305 throw getException(CSQL_NOT_SUPPORTED);
307 public Class unwrap(Class iface) throws SQLException
309 if (JSqlError.isDebug) System.out.println("JdbcSqlStatement::unwrap called");
310 throw getException(CSQL_NOT_SUPPORTED);
312 public boolean isClosed()
314 return closedFlag;