Adding new tool cacheverify to the build system
[csql.git] / src / jdbc / JdbcSqlResultSet.java
blob9a54f77dbaebb4280de748fa6ed870dff69c790b
2 package csql.jdbc;
4 import java.math.BigDecimal;
5 import java.net.URL;
7 import java.sql.Connection;
8 import java.sql.Statement;
9 import java.sql.SQLException;
10 import java.sql.ResultSet;
11 import java.sql.ResultSetMetaData;
12 import java.sql.SQLWarning;
14 import java.io.InputStream;
15 import java.io.InputStreamReader;
16 import java.io.StringBufferInputStream;
18 import java.sql.Clob;
19 import java.sql.Blob;
20 import java.sql.Ref;
21 import java.sql.Array;
22 import java.sql.Types;
24 public class JdbcSqlResultSet extends JSqlError implements ResultSet, JSqlErrorType
26 public JdbcSqlStatement stmt; // This guy creates me
27 public JdbcSqlResultSetMetaData rsmd;
29 public boolean isClosed;
30 long curRow;
33 JdbcSqlResultSet()
35 rsmd = new JdbcSqlResultSetMetaData();
36 isClosed = false;
37 curRow = -1;
39 void setStmt( JdbcSqlStatement jdbcStmt )
41 stmt = jdbcStmt;
42 rsmd.setStmt( jdbcStmt );
43 isClosed = false;
44 curRow = -1;
46 protected void finalize ()
48 try
50 if(!isClosed) close();
52 catch(SQLException e)
54 System.out.println(e);
58 // API's
59 public void close() throws SQLException
61 if( isClosed ) return;
63 isClosed = true;
64 curRow = -1;
65 //rsmd.close(); //commented by praba
66 //after close the app can reexecute.
67 if (stmt != null) stmt.closeScan();
68 return;
71 // Move to next tuple
72 public boolean next () throws SQLException
74 if( isClosed ) throw getException( CSQL_INVALID_STATE );
76 if( 0 == stmt.jniStmt.next() )
78 curRow = -2;
79 return( false );
81 curRow += 1;
83 return( true );
85 public ResultSetMetaData getMetaData () throws SQLException
87 if( isClosed ) throw getException( CSQL_INVALID_STATE );
88 return( rsmd );
90 public SQLWarning getWarnings() throws SQLException
92 return( null );
94 public void clearWarnings() throws SQLException
96 return;
98 public int findColumn (String colName) throws SQLException
100 if( isClosed ) throw getException( CSQL_INVALID_STATE );
102 int colnum = stmt.jniStmt.findColumn( colName );
103 return( colnum );
105 public int getType() throws SQLException
107 return( ResultSet.TYPE_FORWARD_ONLY );
109 public int getConcurrency() throws SQLException
111 return( ResultSet.CONCUR_READ_ONLY );
113 public Statement getStatement() throws SQLException
115 if( isClosed ) throw getException( CSQL_INVALID_STATE );
116 return( stmt );
118 public boolean isFirst() throws SQLException
120 if( isClosed ) throw getException( CSQL_INVALID_STATE );
122 if( curRow == 0 )
123 return( true );
125 return( false );
127 public boolean isBeforeFirst() throws SQLException
129 if( isClosed ) throw getException( CSQL_INVALID_STATE );
131 if( curRow == -1 )
132 return( true );
134 return( false );
136 public boolean isAfterLast() throws SQLException
138 if( isClosed ) throw getException( CSQL_INVALID_STATE );
140 if( curRow == -2 )
141 return( true );
143 return( false );
146 // Provide data to application
147 // SHORT
148 public short getShort (int colNum ) throws SQLException
150 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
152 short out = stmt.jniStmt.getShort( colNum - 1 );
153 if( false ) throw new SQLException();
154 return out;
156 public short getShort (String colName ) throws SQLException
158 if( isClosed ) throw getException( CSQL_INVALID_STATE );
159 return( getShort( findColumn( colName ) ) );
162 // INTEGER
163 public int getInt (int colNum ) throws SQLException
165 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
167 int out = stmt.jniStmt.getInt( colNum - 1 );
168 if( false ) throw new SQLException();
169 return out;
171 public int getInt (String colName) throws SQLException
173 if( isClosed ) throw getException( CSQL_INVALID_STATE );
174 return( getInt( findColumn( colName ) ) );
177 // LONG
178 public long getLong (int colNum) throws SQLException
180 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
182 long out = stmt.jniStmt.getLong( colNum-1 );
183 if( false ) throw new SQLException();
184 return out;
186 public long getLong (String colName) throws SQLException
188 if( isClosed ) throw getException( CSQL_INVALID_STATE );
189 return( getLong( findColumn( colName ) ) );
192 // BYTE
193 public byte getByte (int colNum) throws SQLException
195 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
197 byte out = stmt.jniStmt.getByte( colNum-1 );
198 if( false ) throw new SQLException();
199 return out;
201 public byte getByte (String colName) throws SQLException
203 if( isClosed ) throw getException( CSQL_INVALID_STATE );
204 return( getByte( findColumn( colName ) ) );
207 // FLOAT
208 public float getFloat (int colNum) throws SQLException
210 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
212 float out = stmt.jniStmt.getFloat( colNum-1 );
213 if( false ) throw new SQLException();
214 return out;
216 public float getFloat (String colName) throws SQLException
218 if( isClosed ) throw getException( CSQL_INVALID_STATE );
219 return( getFloat( findColumn( colName ) ) );
222 // DOUBLE
223 public double getDouble (int colNum) throws SQLException
225 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
227 double out = stmt.jniStmt.getDouble( colNum-1 );
228 if( false ) throw new SQLException();
229 return out;
231 public double getDouble (String colName) throws SQLException
233 if( isClosed ) throw getException( CSQL_INVALID_STATE );
234 return( getDouble( findColumn( colName ) ) );
237 // DECIMAL
238 public BigDecimal getBigDecimal( int colNum )
239 throws SQLException
241 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
243 throw getException( CSQL_NOT_SUPPORTED );
245 // TODO
246 // BigDecimal out = new BigDecimal( stmt.jniStmt.getBigDecimal( colNum-1 ) );
247 //return out;
249 public BigDecimal getBigDecimal(String colName)
250 throws SQLException
252 if( isClosed ) throw getException( CSQL_INVALID_STATE );
253 return( getBigDecimal( findColumn( colName ) ) );
255 public BigDecimal getBigDecimal (int colNum, int scale)
256 throws SQLException
258 return( getBigDecimal( colNum ) );
260 public BigDecimal getBigDecimal (String colName, int scale)
261 throws SQLException
263 return( getBigDecimal( colName ) );
266 // STRING/VARSTRING
267 public String getString(int colNum) throws SQLException
269 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
271 // Get value
272 String out = stmt.jniStmt.getString( colNum-1 );
274 return out;
276 public String getString (String colName) throws SQLException
278 return( getString( findColumn( colName ) ) );
280 public InputStream getAsciiStream(int colNum) throws SQLException
282 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
284 String out = stmt.jniStmt.getString( colNum-1 );
286 return( new StringBufferInputStream( out ) );
288 public java.io.InputStream getAsciiStream (String colName) throws SQLException
290 return( getAsciiStream( findColumn( colName ) ) );
292 public java.io.Reader getCharacterStream(int colNum)
293 throws SQLException
295 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
297 InputStream iS = getAsciiStream( colNum );
298 if( iS == null )
299 return( null );
301 return( new InputStreamReader( iS ) );
303 public java.io.Reader getCharacterStream(String colName)
304 throws SQLException
306 return( getCharacterStream( findColumn( colName ) ) );
309 // BOOLEAN
310 public boolean getBoolean (int colNum) throws SQLException
312 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
314 boolean out = stmt.jniStmt.getBoolean( colNum-1 );
316 return out;
318 public boolean getBoolean (String colName) throws SQLException
320 return( getBoolean( findColumn( colName ) ) );
323 // BINARY/VARBINARY
324 public byte [] getBytes(int colNum) throws SQLException
326 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
328 throw getException( CSQL_NOT_SUPPORTED );
329 //byte[] out = stmt.jniStmt.getBytes( colNum-1 );
330 //return out;
332 public byte[] getBytes (String colName) throws SQLException
334 return( getBytes( findColumn( colName ) ) );
337 // DATE
338 public java.sql.Date getDate (int colNum) throws SQLException
340 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
342 java.sql.Date out = stmt.jniStmt.getDate( colNum-1 );
344 return out;
346 public java.sql.Date getDate(int colNum, java.util.Calendar cal)
347 throws SQLException
349 return( getDate( colNum ) );
351 public java.sql.Date getDate (String colNum) throws SQLException
353 return( getDate( findColumn( colNum ) ) );
355 public java.sql.Date getDate(String colName, java.util.Calendar cal)
356 throws SQLException
358 return( getDate( colName ) );
361 // TIME
362 public java.sql.Time getTime (int colNum) throws SQLException
364 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
366 // Get value
367 java.sql.Time out = stmt.jniStmt.getTime( colNum-1 );
369 return out;
371 public java.sql.Time getTime(int colNum, java.util.Calendar cal)
372 throws SQLException
374 return( getTime( colNum ) );
376 public java.sql.Time getTime (String colName) throws SQLException
378 return( getTime( findColumn( colName ) ) );
380 public java.sql.Time getTime(String colName, java.util.Calendar cal)
381 throws SQLException
383 return( getTime( colName ) );
386 // TIMESTAMP
387 public java.sql.Timestamp getTimestamp (int colNum)
388 throws SQLException
390 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
392 java.sql.Timestamp out = stmt.jniStmt.getTimestamp( colNum-1 );
394 return out;
396 public java.sql.Timestamp getTimestamp(int colNum,
397 java.util.Calendar cal) throws SQLException
399 return( getTimestamp( colNum ) );
401 public java.sql.Timestamp getTimestamp (String colName)
402 throws SQLException
404 return( getTimestamp( findColumn( colName ) ) );
406 public java.sql.Timestamp getTimestamp(String colName,
407 java.util.Calendar cal) throws SQLException
409 return( getTimestamp( colName ) );
412 public Object getObject(int colNum) throws SQLException
414 Object obj = new String("no obj");
416 if( isClosed || curRow < 0 ) throw getException( CSQL_INVALID_STATE );
418 switch ( rsmd.getColumnType( colNum ) )
420 case Types.DOUBLE:
421 obj = new Double( getDouble( colNum ) ); break;
422 case Types.FLOAT:
423 obj = new Float( getFloat( colNum ) ); break;
424 case Types.DECIMAL:
425 case Types.NUMERIC:
426 obj = getBigDecimal( colNum ); break;
428 case Types.BIGINT:
429 obj = new Long( getLong( colNum ) ); break;
430 case Types.INTEGER:
431 obj = new Integer( getInt( colNum ) ); break;
432 case Types.SMALLINT:
433 obj = new Short( getShort( colNum ) ); break;
434 case Types.TINYINT:
435 obj = new Byte( getByte( colNum ) ); break;
436 case Types.BIT:
437 obj = new Boolean( getBoolean( colNum ) ); break;
439 case Types.DATE:
440 obj = getDate( colNum ); break;
441 case Types.TIME:
442 obj = getTime( colNum ); break;
443 case Types.TIMESTAMP:
444 obj = getTimestamp( colNum ); break;
446 case Types.CHAR:
447 obj = getString( colNum ); break;
448 case Types.VARCHAR:
449 obj = getString( colNum ); break;
450 case Types.BINARY:
451 case Types.VARBINARY:
452 obj = getBytes( colNum ); break;
454 default: throw getException( CSQL_INVALID_DATATYPE );
456 // Return null if value read is null //TODO
457 //if( wasNull() )
458 // return( null );
460 return( obj );
462 public Object getObject (String colName) throws SQLException
464 return( getObject( findColumn( colName ) ) );
466 public Object getObject(int i, java.util.Map map) throws SQLException
468 return( getObject( i ) );
470 public Object getObject(String colName, java.util.Map map)
471 throws SQLException
473 return( getObject( colName ) );
476 public int getRow() throws SQLException
478 if( curRow < 0 )
479 return( 0 );
481 return( (int) curRow + 1 );
484 // UN-SUPPORTED API's
485 public boolean wasNull () throws SQLException // TODO
487 if( isClosed ) throw getException( CSQL_INVALID_STATE );
488 throw getException( CSQL_NOT_SUPPORTED );
489 //return( stmt.jniStmt.wasNull() );
491 public String getCursorName () throws SQLException
493 throw getException( CSQL_NOT_SUPPORTED );
495 public boolean absolute( int row ) throws SQLException
497 throw getException( CSQL_NOT_SUPPORTED );
499 public void beforeFirst() throws SQLException
501 throw getException( CSQL_NOT_SUPPORTED );
503 public void afterLast() throws SQLException
505 throw getException( CSQL_NOT_SUPPORTED );
507 public boolean first() throws SQLException
509 throw getException( CSQL_NOT_SUPPORTED );
511 public boolean last() throws SQLException
513 throw getException( CSQL_NOT_SUPPORTED );
515 public boolean relative( int rows ) throws SQLException
517 throw getException( CSQL_NOT_SUPPORTED );
519 public boolean previous() throws SQLException
521 throw getException( CSQL_NOT_SUPPORTED );
523 public void setFetchDirection(int direction) throws SQLException
525 throw getException( CSQL_NOT_SUPPORTED );
527 public int getFetchDirection() throws SQLException
529 throw getException( CSQL_NOT_SUPPORTED );
531 public void setFetchSize(int rows) throws SQLException
533 throw getException( CSQL_NOT_SUPPORTED );
535 public int getFetchSize() throws SQLException
537 throw getException( CSQL_NOT_SUPPORTED );
539 public InputStream getUnicodeStream(int colNum) throws SQLException
541 throw getException( CSQL_NOT_SUPPORTED );
543 public InputStream getBinaryStream(int colNum) throws SQLException
545 throw getException( CSQL_NOT_SUPPORTED );
547 public java.io.InputStream getUnicodeStream (String colName) throws SQLException
549 throw getException( CSQL_NOT_SUPPORTED );
551 public java.io.InputStream getBinaryStream (String colName) throws SQLException
553 throw getException( CSQL_NOT_SUPPORTED );
555 public void setMaxRows(int maxRows) throws SQLException
557 throw getException( CSQL_NOT_SUPPORTED );
559 public void setMaxFieldSize(int maxFieldSize) throws SQLException
561 throw getException( CSQL_NOT_SUPPORTED );
563 public boolean rowUpdated() throws SQLException
565 throw getException( CSQL_NOT_SUPPORTED );
567 public boolean rowInserted() throws SQLException
569 throw getException( CSQL_NOT_SUPPORTED );
571 public boolean rowDeleted() throws SQLException
573 throw getException( CSQL_NOT_SUPPORTED );
575 public void updateNull(int colNum) throws SQLException
577 throw getException( CSQL_NOT_SUPPORTED );
579 public void updateBoolean(int colNum, boolean x) throws SQLException
581 throw getException( CSQL_NOT_SUPPORTED );
583 public void updateByte(int colNum, byte x) throws SQLException
585 throw getException( CSQL_NOT_SUPPORTED );
587 public void updateShort(int colNum, short x) throws SQLException
589 throw getException( CSQL_NOT_SUPPORTED );
591 public void updateInt(int colNum, int x) throws SQLException
593 throw getException( CSQL_NOT_SUPPORTED );
595 public void updateLong(int colNum, long x) throws SQLException
597 throw getException( CSQL_NOT_SUPPORTED );
599 public void updateFloat(int colNum, float x) throws SQLException
601 throw getException( CSQL_NOT_SUPPORTED );
603 public void updateDouble(int colNum, double x) throws SQLException
605 throw getException( CSQL_NOT_SUPPORTED );
607 public void updateBigDecimal(int colNum, BigDecimal x) throws SQLException
609 throw getException( CSQL_NOT_SUPPORTED );
611 public void updateString(int colNum, String x) throws SQLException
613 throw getException( CSQL_NOT_SUPPORTED );
615 public void updateBytes(int colNum, byte x[]) throws SQLException
617 throw getException( CSQL_NOT_SUPPORTED );
619 public void updateDate(int colNum, java.sql.Date x) throws SQLException
621 throw getException( CSQL_NOT_SUPPORTED );
623 public void updateTime(int colNum, java.sql.Time x) throws SQLException
625 throw getException( CSQL_NOT_SUPPORTED );
627 public void updateTimestamp(int colNum, java.sql.Timestamp x)
628 throws SQLException
630 throw getException( CSQL_NOT_SUPPORTED );
632 public void updateAsciiStream(int colNum,
633 java.io.InputStream x, int length) throws SQLException
635 throw getException( CSQL_NOT_SUPPORTED );
637 public void updateBinaryStream(int colNum,
638 java.io.InputStream x, int length) throws SQLException
640 throw getException( CSQL_NOT_SUPPORTED );
642 public void updateCharacterStream(int colNum,
643 java.io.Reader x, int length) throws SQLException
645 throw getException( CSQL_NOT_SUPPORTED );
647 public void updateNull(String colName) throws SQLException
649 throw getException( CSQL_NOT_SUPPORTED );
651 public void updateBoolean(String colName, boolean x) throws SQLException
653 throw getException( CSQL_NOT_SUPPORTED );
655 public void updateByte(String colName, byte x) throws SQLException
657 throw getException( CSQL_NOT_SUPPORTED );
659 public void updateShort(String colName, short x) throws SQLException
661 throw getException( CSQL_NOT_SUPPORTED );
663 public void updateInt(String colName, int x) throws SQLException
665 throw getException( CSQL_NOT_SUPPORTED );
667 public void updateLong(String colName, long x) throws SQLException
669 throw getException( CSQL_NOT_SUPPORTED );
671 public void updateFloat(String colName, float x) throws SQLException
673 throw getException( CSQL_NOT_SUPPORTED );
675 public void updateDouble(String colName, double x) throws SQLException
677 throw getException( CSQL_NOT_SUPPORTED );
679 public void updateBigDecimal(String colName, BigDecimal x)
680 throws SQLException
682 throw getException( CSQL_NOT_SUPPORTED );
684 public void updateString(String colName, String x) throws SQLException
686 throw getException( CSQL_NOT_SUPPORTED );
688 public void updateBytes(String colName, byte x[]) throws SQLException
690 throw getException( CSQL_NOT_SUPPORTED );
692 public void updateDate(String colName, java.sql.Date x) throws SQLException
694 throw getException( CSQL_NOT_SUPPORTED );
696 public void updateTime(String colName, java.sql.Time x) throws SQLException
698 throw getException( CSQL_NOT_SUPPORTED );
700 public void updateTimestamp(String colName, java.sql.Timestamp x)
701 throws SQLException
703 throw getException( CSQL_NOT_SUPPORTED );
705 public void updateAsciiStream(String colName,
706 java.io.InputStream x, int length) throws SQLException
708 throw getException( CSQL_NOT_SUPPORTED );
710 public void updateBinaryStream(String colName,
711 java.io.InputStream x, int length) throws SQLException
713 throw getException( CSQL_NOT_SUPPORTED );
715 public void updateCharacterStream(String colName,
716 java.io.Reader reader, int length) throws SQLException
718 throw getException( CSQL_NOT_SUPPORTED );
720 public void updateObject(int colNum, Object x, int scale)
721 throws SQLException
723 throw getException( CSQL_NOT_SUPPORTED );
725 public void updateObject(int colNum, Object x) throws SQLException
727 throw getException( CSQL_NOT_SUPPORTED );
729 public void insertRow() throws SQLException
731 throw getException( CSQL_NOT_SUPPORTED );
733 public void updateRow() throws SQLException
735 throw getException( CSQL_NOT_SUPPORTED );
737 public void deleteRow() throws SQLException
739 throw getException( CSQL_NOT_SUPPORTED );
741 public void refreshRow() throws SQLException
743 throw getException( CSQL_NOT_SUPPORTED );
745 public void cancelRowUpdates() throws SQLException
747 throw getException( CSQL_NOT_SUPPORTED );
749 public void moveToInsertRow() throws SQLException
751 throw getException( CSQL_NOT_SUPPORTED );
753 public void moveToCurrentRow() throws SQLException
755 throw getException( CSQL_NOT_SUPPORTED );
757 public Ref getRef(int i) throws SQLException
759 throw getException( CSQL_NOT_SUPPORTED );
761 public Blob getBlob(int i) throws SQLException
763 throw getException( CSQL_NOT_SUPPORTED );
765 public Clob getClob(int i) throws SQLException
767 throw getException( CSQL_NOT_SUPPORTED );
769 public Array getArray(int i) throws SQLException
771 throw getException( CSQL_NOT_SUPPORTED );
773 public Ref getRef(String colName) throws SQLException
775 throw getException( CSQL_NOT_SUPPORTED );
777 public Blob getBlob(String colName) throws SQLException
779 throw getException( CSQL_NOT_SUPPORTED );
781 public Clob getClob(String colName) throws SQLException
783 throw getException( CSQL_NOT_SUPPORTED );
785 public Array getArray(String colName) throws SQLException
787 throw getException( CSQL_NOT_SUPPORTED );
789 public boolean isLast() throws SQLException
791 throw getException( CSQL_NOT_SUPPORTED );
793 public void updateObject(String colName, Object x) throws SQLException
795 throw getException( CSQL_NOT_SUPPORTED );
797 public void updateObject(String colName, Object x, int scale)
798 throws SQLException
800 throw getException( CSQL_NOT_SUPPORTED );
802 public URL getURL(int colNum)
803 throws SQLException
805 throw getException( CSQL_NOT_SUPPORTED );
807 public URL getURL(String colName)
808 throws SQLException
810 throw getException( CSQL_NOT_SUPPORTED );
812 public void updateRef(int colNum, Ref x)
813 throws SQLException
815 throw getException( CSQL_NOT_SUPPORTED );
817 public void updateRef(String colName, Ref x)
818 throws SQLException
820 throw getException( CSQL_NOT_SUPPORTED );
822 public void updateBlob(int colNum, Blob x)
823 throws SQLException
825 throw getException( CSQL_NOT_SUPPORTED );
827 public void updateBlob(String colName, Blob x)
828 throws SQLException
830 throw getException( CSQL_NOT_SUPPORTED );
832 public void updateClob(int colNum, Clob x)
833 throws SQLException
835 throw getException( CSQL_NOT_SUPPORTED );
837 public void updateClob(String colName, Clob x)
838 throws SQLException
840 throw getException( CSQL_NOT_SUPPORTED );
842 public void updateArray(int colNum, Array x)
843 throws SQLException
845 throw getException( CSQL_NOT_SUPPORTED );
847 public void updateArray(String colName, Array x)
848 throws SQLException
850 throw getException( CSQL_NOT_SUPPORTED );