Feature: 1738555
[csql.git] / src / jdbc / JdbcSqlStatement.java
blob16a8be531cfaee54b1e98038fd6d7dca352c4764
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;
7 public class JdbcSqlStatement extends JSqlError implements Statement, JSqlErrorType
9 public boolean isClosed;
10 public boolean isPrepared;
11 public int rowsAffect;
12 public JSqlStatement jniStmt;
13 public JdbcSqlConnection conn;
14 //public JdbcSqlResultSet rs;
16 JdbcSqlStatement(Connection con)
18 jniStmt = new JSqlStatement();
19 jniStmt.alloc();
20 jniStmt.setConnectionPtr(((JdbcSqlConnection)con).getConnection().getPtr());
21 conn = (JdbcSqlConnection)con;
22 isClosed = false;
23 isPrepared = false;
24 rowsAffect = 0;
26 protected void finalize ()
28 try
30 if(!isClosed)
31 close();
33 catch(SQLException e)
35 System.out.println(e);
38 public void prepareInt(String query) throws SQLException
40 int rv = 0;
41 if(isPrepared)
43 jniStmt.freeStmt();
45 rv = jniStmt.prepare(query);
46 if( rv != 0 ) // 0 ->OK
48 throw getException(CSQL_PREPARE_ERR);
50 isPrepared = true;
52 public boolean executeInt() throws SQLException
54 if (!isPrepared) throw getException(CSQL_NOT_PREPARED);
55 boolean isSelect = jniStmt.isSelect();
56 rowsAffect = jniStmt.execute();
57 if( rowsAffect < 0 )
58 throw getException(CSQL_EXECUTE_ERR);
59 if(conn.getAutoCommit())
60 conn.commit();
62 return(isSelect);
65 public void close() throws SQLException
67 if(isClosed) return;
68 if(isPrepared)
70 //rs.close();
71 jniStmt.freeStmt();
72 jniStmt.free();
74 isClosed = true;
75 return;
77 public boolean execute (String query) throws SQLException
79 prepareInt(query);
80 return(executeInt());
83 public ResultSet executeQuery(String query) throws SQLException
85 if(!execute(query))
86 throw getException(CSQL_NOT_QUERY);
87 return(null);
89 public int executeUpdate (String query) throws SQLException
91 if(execute(query))
92 throw getException(CSQL_NOT_UPDATE);
93 return(rowsAffect);
95 public Connection getConnection() throws SQLException
97 return(conn);
99 public int getFetchDirection() throws SQLException
101 return(ResultSet.FETCH_FORWARD);
103 public int getFetchSize() throws SQLException
105 return 1;
107 public ResultSet getResultSet() throws SQLException
109 if(!jniStmt.isSelect())
110 return (null);
112 //TODO::Create ResultSet object
113 return null;
115 public int getResultSetConcurrency() throws SQLException
117 return(ResultSet.CONCUR_READ_ONLY);
119 public int getResultSetHoldability() throws SQLException
121 return(ResultSet.CLOSE_CURSORS_AT_COMMIT);
123 public int getResultSetType() throws SQLException
125 return(ResultSet.TYPE_FORWARD_ONLY);
127 public int getUpdateCount() throws SQLException
129 if(jniStmt.isSelect())
130 return -1;
131 return rowsAffect;
135 //Unsupported APIs
136 public void addBatch(String sql) throws SQLException
138 throw getException(CSQL_NOT_SUPPORTED);
140 public void cancel() throws SQLException
142 throw getException(CSQL_NOT_SUPPORTED);
144 public void clearBatch() throws SQLException
146 throw getException(CSQL_NOT_SUPPORTED);
148 public void clearWarnings() throws SQLException
150 throw getException(CSQL_NOT_SUPPORTED);
152 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException
154 throw getException(CSQL_NOT_SUPPORTED);
156 public boolean execute(String sql, int[] columnIndexes) throws SQLException
158 throw getException(CSQL_NOT_SUPPORTED);
160 public boolean execute(String sql, String[] columnNames) throws SQLException
162 throw getException(CSQL_NOT_SUPPORTED);
164 public int[] executeBatch() throws SQLException
166 throw getException(CSQL_NOT_SUPPORTED);
168 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
170 throw getException(CSQL_NOT_SUPPORTED);
172 public int executeUpdate(String sql, int[] columnIndexes) throws SQLException
174 throw getException(CSQL_NOT_SUPPORTED);
176 public int executeUpdate(String sql, String[] columnNames) throws SQLException
178 throw getException(CSQL_NOT_SUPPORTED);
180 public ResultSet getGeneratedKeys() throws SQLException
182 throw getException(CSQL_NOT_SUPPORTED);
184 public int getMaxFieldSize() throws SQLException
186 throw getException(CSQL_NOT_SUPPORTED);
188 public int getMaxRows() throws SQLException
190 throw getException(CSQL_NOT_SUPPORTED);
192 public boolean getMoreResults() throws SQLException
194 throw getException(CSQL_NOT_SUPPORTED);
196 public boolean getMoreResults( int current) throws SQLException
198 throw getException(CSQL_NOT_SUPPORTED);
200 public int getQueryTimeout() throws SQLException
202 throw getException(CSQL_NOT_SUPPORTED);
204 public SQLWarning getWarnings() throws SQLException
206 throw getException(CSQL_NOT_SUPPORTED);
208 public void setCursorName(String name) throws SQLException
210 throw getException(CSQL_NOT_SUPPORTED);
212 public void setEscapeProcessing(boolean enable) throws SQLException
214 throw getException(CSQL_NOT_SUPPORTED);
216 public void setFetchDirection(int direction) throws SQLException
218 throw getException(CSQL_NOT_SUPPORTED);
220 public void setFetchSize(int rows) throws SQLException
222 throw getException(CSQL_NOT_SUPPORTED);
224 public void setMaxFieldSize(int max) throws SQLException
226 throw getException(CSQL_NOT_SUPPORTED);
228 public void setMaxRows(int maxRows) throws SQLException
230 throw getException(CSQL_NOT_SUPPORTED);
232 public void setQueryTimeout(int seconds) throws SQLException
234 throw getException(CSQL_NOT_SUPPORTED);