1 | /* ============================================================= |
2 | * SmallSQL : a free Java DBMS library for the Java(tm) platform |
3 | * ============================================================= |
4 | * |
5 | * (C) Copyright 2004-2006, by Volker Berlin. |
6 | * |
7 | * Project Info: http://www.smallsql.de/ |
8 | * |
9 | * This library is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU Lesser General Public License as published by |
11 | * the Free Software Foundation; either version 2.1 of the License, or |
12 | * (at your option) any later version. |
13 | * |
14 | * This library is distributed in the hope that it will be useful, but |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
17 | * License for more details. |
18 | * |
19 | * You should have received a copy of the GNU Lesser General Public |
20 | * License along with this library; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
22 | * USA. |
23 | * |
24 | * [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
25 | * in the United States and other countries.] |
26 | * |
27 | * --------------- |
28 | * SSResultSet.java |
29 | * --------------- |
30 | * Author: Volker Berlin |
31 | * |
32 | */ |
33 | package smallsql.database; |
34 | |
35 | import java.sql.*; |
36 | import java.math.*; |
37 | import java.io.InputStream; |
38 | import java.io.Reader; |
39 | import java.util.Map; |
40 | import java.util.Calendar; |
41 | import java.net.URL; |
42 | |
43 | |
44 | public class SSResultSet implements ResultSet { |
45 | |
46 | SSResultSetMetaData metaData = new SSResultSetMetaData(); |
47 | private CommandSelect cmd; |
48 | private boolean wasNull; |
49 | SSStatement st; |
50 | private boolean isUpdatable; |
51 | private boolean isInsertRow; |
52 | private ExpressionValue[] values; |
53 | private int fetchDirection; |
54 | private int fetchSize; |
55 | |
56 | SSResultSet( SSStatement st, CommandSelect cmd ){ |
57 | this.st = st; |
58 | metaData.columns = cmd.columnExpressions; |
59 | this.cmd = cmd; |
60 | isUpdatable = st != null && st.rsConcurrency == CONCUR_UPDATABLE && !cmd.isGroupResult(); |
61 | } |
62 | |
63 | /*============================================================================== |
64 | |
65 | Public Interface |
66 | |
67 | ==============================================================================*/ |
68 | |
69 | public void close() throws SQLException { |
70 | st.con.log.println("ResultSet.close"); |
71 | cmd = null; |
72 | } |
73 | public boolean wasNull() throws SQLException { |
74 | return wasNull; |
75 | } |
76 | public String getString(int columnIndex) throws SQLException { |
77 | try{ |
78 | String obj = getValue(columnIndex).getString(); |
79 | wasNull = obj == null; |
80 | return obj; |
81 | }catch(Exception e){ |
82 | throw Utils.createSQLException( e ); |
83 | } |
84 | } |
85 | public boolean getBoolean(int columnIndex) throws SQLException { |
86 | try{ |
87 | Expression expr = getValue(columnIndex); |
88 | wasNull = expr.isNull(); |
89 | return expr.getBoolean(); |
90 | }catch(Exception e){ |
91 | throw Utils.createSQLException( e ); |
92 | } |
93 | } |
94 | public byte getByte(int columnIndex) throws SQLException { |
95 | return (byte)getInt( columnIndex ); |
96 | } |
97 | public short getShort(int columnIndex) throws SQLException { |
98 | return (short)getInt( columnIndex ); |
99 | } |
100 | public int getInt(int columnIndex) throws SQLException { |
101 | try{ |
102 | Expression expr = getValue(columnIndex); |
103 | wasNull = expr.isNull(); |
104 | return expr.getInt(); |
105 | }catch(Exception e){ |
106 | throw Utils.createSQLException( e ); |
107 | } |
108 | } |
109 | public long getLong(int columnIndex) throws SQLException { |
110 | try{ |
111 | Expression expr = getValue(columnIndex); |
112 | wasNull = expr.isNull(); |
113 | return expr.getLong(); |
114 | }catch(Exception e){ |
115 | throw Utils.createSQLException( e ); |
116 | } |
117 | } |
118 | public float getFloat(int columnIndex) throws SQLException { |
119 | try{ |
120 | Expression expr = getValue(columnIndex); |
121 | wasNull = expr.isNull(); |
122 | return expr.getFloat(); |
123 | }catch(Exception e){ |
124 | throw Utils.createSQLException( e ); |
125 | } |
126 | } |
127 | public double getDouble(int columnIndex) throws SQLException { |
128 | try{ |
129 | Expression expr = getValue(columnIndex); |
130 | wasNull = expr.isNull(); |
131 | return expr.getDouble(); |
132 | }catch(Exception e){ |
133 | throw Utils.createSQLException( e ); |
134 | } |
135 | } |
136 | public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { |
137 | try{ |
138 | MutableNumeric obj = getValue(columnIndex).getNumeric(); |
139 | if(wasNull = obj == null) return null; |
140 | return obj.toBigDecimal(scale); |
141 | }catch(Exception e){ |
142 | throw Utils.createSQLException( e ); |
143 | } |
144 | } |
145 | public byte[] getBytes(int columnIndex) throws SQLException { |
146 | try{ |
147 | byte[] obj = getValue(columnIndex).getBytes(); |
148 | wasNull = obj == null; |
149 | return obj; |
150 | }catch(Exception e){ |
151 | throw Utils.createSQLException( e ); |
152 | } |
153 | } |
154 | public Date getDate(int columnIndex) throws SQLException { |
155 | try{ |
156 | Expression expr = getValue(columnIndex); |
157 | if(wasNull = expr.isNull()) return null; |
158 | return DateTime.getDate( expr.getLong() ); |
159 | }catch(Exception e){ |
160 | throw Utils.createSQLException( e ); |
161 | } |
162 | } |
163 | public Time getTime(int columnIndex) throws SQLException { |
164 | try{ |
165 | Expression expr = getValue(columnIndex); |
166 | if(wasNull = expr.isNull()) return null; |
167 | return DateTime.getTime( expr.getLong() ); |
168 | }catch(Exception e){ |
169 | throw Utils.createSQLException( e ); |
170 | } |
171 | } |
172 | public Timestamp getTimestamp(int columnIndex) throws SQLException { |
173 | try{ |
174 | Expression expr = getValue(columnIndex); |
175 | if(wasNull = expr.isNull()) return null; |
176 | return DateTime.getTimestamp( expr.getLong() ); |
177 | }catch(Exception e){ |
178 | throw Utils.createSQLException( e ); |
179 | } |
180 | } |
181 | public InputStream getAsciiStream(int columnIndex) throws SQLException { |
182 | /**@todo: Implement this java.sql.ResultSet method*/ |
183 | throw new java.lang.UnsupportedOperationException("Method getAsciiStream() not yet implemented."); |
184 | } |
185 | public InputStream getUnicodeStream(int columnIndex) throws SQLException { |
186 | /**@todo: Implement this java.sql.ResultSet method*/ |
187 | throw new java.lang.UnsupportedOperationException("Method getUnicodeStream() not yet implemented."); |
188 | } |
189 | public InputStream getBinaryStream(int columnIndex) throws SQLException { |
190 | /**@todo: Implement this java.sql.ResultSet method*/ |
191 | throw new java.lang.UnsupportedOperationException("Method getBinaryStream() not yet implemented."); |
192 | } |
193 | public String getString(String columnName) throws SQLException { |
194 | return getString( findColumn( columnName ) ); |
195 | } |
196 | public boolean getBoolean(String columnName) throws SQLException { |
197 | return getBoolean( findColumn( columnName ) ); |
198 | } |
199 | public byte getByte(String columnName) throws SQLException { |
200 | return getByte( findColumn( columnName ) ); |
201 | } |
202 | public short getShort(String columnName) throws SQLException { |
203 | return getShort( findColumn( columnName ) ); |
204 | } |
205 | public int getInt(String columnName) throws SQLException { |
206 | return getInt( findColumn( columnName ) ); |
207 | } |
208 | public long getLong(String columnName) throws SQLException { |
209 | return getLong( findColumn( columnName ) ); |
210 | } |
211 | public float getFloat(String columnName) throws SQLException { |
212 | return getFloat( findColumn( columnName ) ); |
213 | } |
214 | public double getDouble(String columnName) throws SQLException { |
215 | return getDouble( findColumn( columnName ) ); |
216 | } |
217 | public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException { |
218 | return getBigDecimal( findColumn( columnName ), scale ); |
219 | } |
220 | public byte[] getBytes(String columnName) throws SQLException { |
221 | return getBytes( findColumn( columnName ) ); |
222 | } |
223 | public Date getDate(String columnName) throws SQLException { |
224 | return getDate( findColumn( columnName ) ); |
225 | } |
226 | public Time getTime(String columnName) throws SQLException { |
227 | return getTime( findColumn( columnName ) ); |
228 | } |
229 | public Timestamp getTimestamp(String columnName) throws SQLException { |
230 | return getTimestamp( findColumn( columnName ) ); |
231 | } |
232 | public InputStream getAsciiStream(String columnName) throws SQLException { |
233 | return getAsciiStream( findColumn( columnName ) ); |
234 | } |
235 | public InputStream getUnicodeStream(String columnName) throws SQLException { |
236 | return getUnicodeStream( findColumn( columnName ) ); |
237 | } |
238 | public InputStream getBinaryStream(String columnName) throws SQLException { |
239 | return getBinaryStream( findColumn( columnName ) ); |
240 | } |
241 | public SQLWarning getWarnings() throws SQLException { |
242 | return null; |
243 | } |
244 | public void clearWarnings() throws SQLException { |
245 | } |
246 | public String getCursorName() throws SQLException { |
247 | /**@todo: Implement this java.sql.ResultSet method*/ |
248 | throw new java.lang.UnsupportedOperationException("Method getCursorName() not yet implemented."); |
249 | } |
250 | public ResultSetMetaData getMetaData() throws SQLException { |
251 | return metaData; |
252 | } |
253 | public Object getObject(int columnIndex) throws SQLException { |
254 | try{ |
255 | Object obj = getValue(columnIndex).getApiObject(); |
256 | wasNull = obj == null; |
257 | return obj; |
258 | }catch(Exception e){ |
259 | throw Utils.createSQLException( e ); |
260 | } |
261 | } |
262 | public Object getObject(String columnName) throws SQLException { |
263 | return getObject( findColumn( columnName ) ); |
264 | } |
265 | |
266 | |
267 | public int findColumn(String columnName) throws SQLException { |
268 | return getCmd().findColumn(columnName) + 1; |
269 | } |
270 | |
271 | |
272 | public Reader getCharacterStream(int columnIndex) throws SQLException { |
273 | /**@todo: Implement this java.sql.ResultSet method*/ |
274 | throw new java.lang.UnsupportedOperationException("Method getCharacterStream() not yet implemented."); |
275 | } |
276 | public Reader getCharacterStream(String columnName) throws SQLException { |
277 | return getCharacterStream( findColumn( columnName ) ); |
278 | } |
279 | public BigDecimal getBigDecimal(int columnIndex) throws SQLException { |
280 | try{ |
281 | MutableNumeric obj = getValue(columnIndex).getNumeric(); |
282 | if(wasNull = obj == null) return null; |
283 | return obj.toBigDecimal(); |
284 | }catch(Exception e){ |
285 | throw Utils.createSQLException( e ); |
286 | } |
287 | } |
288 | public BigDecimal getBigDecimal(String columnName) throws SQLException { |
289 | return getBigDecimal( findColumn( columnName ) ); |
290 | } |
291 | public boolean isBeforeFirst() throws SQLException { |
292 | return getCmd().isBeforeFirst(); |
293 | } |
294 | |
295 | |
296 | public boolean isAfterLast() throws SQLException { |
297 | try{ |
298 | return getCmd().isAfterLast(); |
299 | }catch(Exception e){ |
300 | throw Utils.createSQLException(e); |
301 | } |
302 | } |
303 | |
304 | |
305 | public boolean isFirst() throws SQLException { |
306 | return getCmd().isFirst(); |
307 | } |
308 | |
309 | |
310 | public boolean isLast() throws SQLException { |
311 | try{ |
312 | return getCmd().isLast(); |
313 | }catch(Exception e){ |
314 | throw Utils.createSQLException(e); |
315 | } |
316 | } |
317 | |
318 | |
319 | public void beforeFirst() throws SQLException { |
320 | try{ |
321 | moveToCurrentRow(); |
322 | getCmd().beforeFirst(); |
323 | }catch(Exception e){ |
324 | throw Utils.createSQLException(e); |
325 | } |
326 | } |
327 | |
328 | |
329 | public boolean first() throws SQLException { |
330 | try{ |
331 | if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only."); |
332 | moveToCurrentRow(); |
333 | return getCmd().first(); |
334 | }catch(Exception e){ |
335 | throw Utils.createSQLException(e); |
336 | } |
337 | } |
338 | |
339 | |
340 | public boolean previous() throws SQLException { |
341 | try{ |
342 | moveToCurrentRow(); |
343 | return getCmd().previous(); |
344 | }catch(Exception e){ |
345 | throw Utils.createSQLException(e); |
346 | } |
347 | } |
348 | |
349 | |
350 | public boolean next() throws SQLException { |
351 | try{ |
352 | moveToCurrentRow(); |
353 | return getCmd().next(); |
354 | }catch(Exception e){ |
355 | throw Utils.createSQLException(e); |
356 | } |
357 | } |
358 | |
359 | |
360 | public boolean last() throws SQLException { |
361 | try{ |
362 | moveToCurrentRow(); |
363 | return getCmd().last(); |
364 | }catch(Exception e){ |
365 | throw Utils.createSQLException(e); |
366 | } |
367 | } |
368 | |
369 | |
370 | public void afterLast() throws SQLException { |
371 | try{ |
372 | if(st.rsType == ResultSet.TYPE_FORWARD_ONLY) throw Utils.createSQLException("ResultSet is forward only."); |
373 | moveToCurrentRow(); |
374 | getCmd().afterLast(); |
375 | }catch(Exception e){ |
376 | throw Utils.createSQLException(e); |
377 | } |
378 | } |
379 | |
380 | |
381 | public boolean absolute(int row) throws SQLException { |
382 | try{ |
383 | moveToCurrentRow(); |
384 | return getCmd().absolute(row); |
385 | }catch(Exception e){ |
386 | throw Utils.createSQLException(e); |
387 | } |
388 | } |
389 | |
390 | |
391 | public boolean relative(int rows) throws SQLException { |
392 | try{ |
393 | moveToCurrentRow(); |
394 | return getCmd().relative(rows); |
395 | }catch(Exception e){ |
396 | throw Utils.createSQLException(e); |
397 | } |
398 | } |
399 | |
400 | |
401 | public int getRow() throws SQLException { |
402 | try{ |
403 | return getCmd().getRow(); |
404 | }catch(Exception e){ |
405 | throw Utils.createSQLException(e); |
406 | } |
407 | } |
408 | |
409 | |
410 | public void setFetchDirection(int direction) throws SQLException { |
411 | fetchDirection = direction; |
412 | } |
413 | |
414 | |
415 | public int getFetchDirection() throws SQLException { |
416 | return fetchDirection; |
417 | } |
418 | |
419 | |
420 | public void setFetchSize(int rows) throws SQLException { |
421 | fetchSize = rows; |
422 | } |
423 | |
424 | |
425 | public int getFetchSize() throws SQLException { |
426 | return fetchSize; |
427 | } |
428 | |
429 | |
430 | public int getType() throws SQLException { |
431 | return getCmd().join.isScrollable() ? ResultSet.TYPE_SCROLL_SENSITIVE : ResultSet.TYPE_FORWARD_ONLY; |
432 | } |
433 | |
434 | |
435 | public int getConcurrency() throws SQLException { |
436 | return isUpdatable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY; |
437 | } |
438 | |
439 | |
440 | public boolean rowUpdated() throws SQLException { |
441 | return false; |
442 | } |
443 | |
444 | |
445 | public boolean rowInserted() throws SQLException { |
446 | return getCmd().join.rowInserted(); |
447 | } |
448 | |
449 | |
450 | public boolean rowDeleted() throws SQLException { |
451 | return getCmd().join.rowDeleted(); |
452 | } |
453 | |
454 | |
455 | public void updateNull(int columnIndex) throws SQLException { |
456 | updateValue( columnIndex, null, SQLTokenizer.NULL); |
457 | } |
458 | public void updateBoolean(int columnIndex, boolean x) throws SQLException { |
459 | updateValue( columnIndex, x ? Boolean.TRUE : Boolean.FALSE, SQLTokenizer.BOOLEAN); |
460 | } |
461 | public void updateByte(int columnIndex, byte x) throws SQLException { |
462 | updateValue( columnIndex, Utils.getShort(x), SQLTokenizer.TINYINT); |
463 | } |
464 | public void updateShort(int columnIndex, short x) throws SQLException { |
465 | updateValue( columnIndex, Utils.getShort(x), SQLTokenizer.SMALLINT); |
466 | } |
467 | public void updateInt(int columnIndex, int x) throws SQLException { |
468 | updateValue( columnIndex, Utils.getInteger(x), SQLTokenizer.INT); |
469 | } |
470 | public void updateLong(int columnIndex, long x) throws SQLException { |
471 | updateValue( columnIndex, new Long(x), SQLTokenizer.BIGINT); |
472 | } |
473 | public void updateFloat(int columnIndex, float x) throws SQLException { |
474 | updateValue( columnIndex, new Float(x), SQLTokenizer.REAL); |
475 | } |
476 | public void updateDouble(int columnIndex, double x) throws SQLException { |
477 | updateValue( columnIndex, new Double(x), SQLTokenizer.DOUBLE); |
478 | } |
479 | public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { |
480 | updateValue( columnIndex, x, SQLTokenizer.DECIMAL); |
481 | } |
482 | public void updateString(int columnIndex, String x) throws SQLException { |
483 | updateValue( columnIndex, x, SQLTokenizer.VARCHAR); |
484 | } |
485 | public void updateBytes(int columnIndex, byte[] x) throws SQLException { |
486 | updateValue( columnIndex, x, SQLTokenizer.VARBINARY); |
487 | } |
488 | public void updateDate(int columnIndex, Date x) throws SQLException { |
489 | updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.DATE); |
490 | } |
491 | public void updateTime(int columnIndex, Time x) throws SQLException { |
492 | updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.TIME); |
493 | } |
494 | public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { |
495 | updateValue( columnIndex, DateTime.valueOf(x), SQLTokenizer.TIMESTAMP); |
496 | } |
497 | public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { |
498 | updateValue( columnIndex, x, SQLTokenizer.LONGVARCHAR, length); |
499 | } |
500 | public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { |
501 | updateValue( columnIndex, x, SQLTokenizer.LONGVARBINARY, length); |
502 | } |
503 | public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { |
504 | /**@todo: Implement this java.sql.ResultSet method*/ |
505 | throw new java.lang.UnsupportedOperationException("Method updateCharacterStream() not yet implemented."); |
506 | } |
507 | public void updateObject(int columnIndex, Object x, int scale) throws SQLException { |
508 | //TODO scale to consider |
509 | updateValue( columnIndex, x, -1); |
510 | } |
511 | public void updateObject(int columnIndex, Object x) throws SQLException { |
512 | updateValue( columnIndex, x, -1); |
513 | } |
514 | public void updateNull(String columnName) throws SQLException { |
515 | updateNull( findColumn( columnName ) ); |
516 | } |
517 | public void updateBoolean(String columnName, boolean x) throws SQLException { |
518 | updateBoolean( findColumn( columnName ), x ); |
519 | } |
520 | public void updateByte(String columnName, byte x) throws SQLException { |
521 | updateByte( findColumn( columnName ), x ); |
522 | } |
523 | public void updateShort(String columnName, short x) throws SQLException { |
524 | updateShort( findColumn( columnName ), x ); |
525 | } |
526 | public void updateInt(String columnName, int x) throws SQLException { |
527 | updateInt( findColumn( columnName ), x ); |
528 | } |
529 | public void updateLong(String columnName, long x) throws SQLException { |
530 | updateLong( findColumn( columnName ), x ); |
531 | } |
532 | public void updateFloat(String columnName, float x) throws SQLException { |
533 | updateFloat( findColumn( columnName ), x ); |
534 | } |
535 | public void updateDouble(String columnName, double x) throws SQLException { |
536 | updateDouble( findColumn( columnName ), x ); |
537 | } |
538 | public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { |
539 | updateBigDecimal( findColumn( columnName ), x ); |
540 | } |
541 | public void updateString(String columnName, String x) throws SQLException { |
542 | updateString( findColumn( columnName ), x ); |
543 | } |
544 | public void updateBytes(String columnName, byte[] x) throws SQLException { |
545 | updateBytes( findColumn( columnName ), x ); |
546 | } |
547 | public void updateDate(String columnName, Date x) throws SQLException { |
548 | updateDate( findColumn( columnName ), x ); |
549 | } |
550 | public void updateTime(String columnName, Time x) throws SQLException { |
551 | updateTime( findColumn( columnName ), x ); |
552 | } |
553 | public void updateTimestamp(String columnName, Timestamp x) throws SQLException { |
554 | updateTimestamp( findColumn( columnName ), x ); |
555 | } |
556 | public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException { |
557 | updateAsciiStream( findColumn( columnName ), x, length ); |
558 | } |
559 | public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException { |
560 | updateBinaryStream( findColumn( columnName ), x, length ); |
561 | } |
562 | public void updateCharacterStream(String columnName, Reader x, int length) throws SQLException { |
563 | updateCharacterStream( findColumn( columnName ), x, length ); |
564 | } |
565 | public void updateObject(String columnName, Object x, int scale) throws SQLException { |
566 | updateObject( findColumn( columnName ), x, scale ); |
567 | } |
568 | public void updateObject(String columnName, Object x) throws SQLException { |
569 | updateObject( findColumn( columnName ), x ); |
570 | } |
571 | public void insertRow() throws SQLException { |
572 | st.con.log.println("insertRow()"); |
573 | getCmd().insertRow( st.con, values); |
574 | cancelRowUpdates(); |
575 | } |
576 | |
577 | |
578 | public void updateRow() throws SQLException { |
579 | try { |
580 | if(values == null) return; |
581 | st.con.log.println("updateRow()"); |
582 | final CommandSelect command = getCmd(); |
583 | command.updateRow( st.con, values); |
584 | command.relative(0); //refresh the row |
585 | cancelRowUpdates(); |
586 | } catch (Exception e) { |
587 | throw Utils.createSQLException(e); |
588 | } |
589 | } |
590 | |
591 | |
592 | public void deleteRow() throws SQLException { |
593 | st.con.log.println("deleteRow()"); |
594 | getCmd().deleteRow(st.con); |
595 | cancelRowUpdates(); |
596 | } |
597 | public void refreshRow() throws SQLException { |
598 | relative(0); |
599 | } |
600 | |
601 | |
602 | public void cancelRowUpdates() { |
603 | if(values != null){ |
604 | for(int i=values.length-1; i>=0; i--){ |
605 | values[i].clear(); |
606 | } |
607 | } |
608 | } |
609 | |
610 | |
611 | public void moveToInsertRow() throws SQLException { |
612 | if(isUpdatable){ |
613 | isInsertRow = true; |
614 | }else{ |
615 | throw Utils.createSQLException("ResultSet is read only."); |
616 | } |
617 | } |
618 | |
619 | |
620 | public void moveToCurrentRow(){ |
621 | isInsertRow = false; |
622 | cancelRowUpdates(); |
623 | } |
624 | |
625 | |
626 | public Statement getStatement() { |
627 | return st; |
628 | } |
629 | |
630 | |
631 | public Object getObject(int i, Map map) throws SQLException { |
632 | return getObject( i ); |
633 | } |
634 | public Ref getRef(int i) throws SQLException { |
635 | /**@todo: Implement this java.sql.ResultSet method*/ |
636 | throw new java.lang.UnsupportedOperationException("Method getRef() not yet implemented."); |
637 | } |
638 | public Blob getBlob(int i) throws SQLException { |
639 | /**@todo: Implement this java.sql.ResultSet method*/ |
640 | throw new java.lang.UnsupportedOperationException("Method getBlob() not yet implemented."); |
641 | } |
642 | public Clob getClob(int i) throws SQLException { |
643 | /**@todo: Implement this java.sql.ResultSet method*/ |
644 | throw new java.lang.UnsupportedOperationException("Method getClob() not yet implemented."); |
645 | } |
646 | public Array getArray(int i) throws SQLException { |
647 | /**@todo: Implement this java.sql.ResultSet method*/ |
648 | throw new java.lang.UnsupportedOperationException("Method getArray() not yet implemented."); |
649 | } |
650 | public Object getObject(String columnName, Map map) throws SQLException { |
651 | return getObject( columnName ); |
652 | } |
653 | public Ref getRef(String columnName) throws SQLException { |
654 | return getRef( findColumn( columnName ) ); |
655 | } |
656 | public Blob getBlob(String columnName) throws SQLException { |
657 | return getBlob( findColumn( columnName ) ); |
658 | } |
659 | public Clob getClob(String columnName) throws SQLException { |
660 | return getClob( findColumn( columnName ) ); |
661 | } |
662 | public Array getArray(String columnName) throws SQLException { |
663 | return getArray( findColumn( columnName ) ); |
664 | } |
665 | public Date getDate(int columnIndex, Calendar cal) throws SQLException { |
666 | /**@todo: Implement this java.sql.ResultSet method*/ |
667 | throw new java.lang.UnsupportedOperationException("Method getDate() not yet implemented."); |
668 | } |
669 | public Date getDate(String columnName, Calendar cal) throws SQLException { |
670 | return getDate( findColumn( columnName ), cal ); |
671 | } |
672 | public Time getTime(int columnIndex, Calendar cal) throws SQLException { |
673 | /**@todo: Implement this java.sql.ResultSet method*/ |
674 | throw new java.lang.UnsupportedOperationException("Method getTime() not yet implemented."); |
675 | } |
676 | public Time getTime(String columnName, Calendar cal) throws SQLException { |
677 | return getTime( findColumn( columnName ), cal ); |
678 | } |
679 | public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { |
680 | /**@todo: Implement this java.sql.ResultSet method*/ |
681 | throw new java.lang.UnsupportedOperationException("Method getTimestamp() not yet implemented."); |
682 | } |
683 | public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { |
684 | return getTimestamp( findColumn( columnName ), cal ); |
685 | } |
686 | public URL getURL(int columnIndex) throws SQLException { |
687 | /**@todo: Implement this java.sql.ResultSet method*/ |
688 | throw new java.lang.UnsupportedOperationException("Method getURL() not yet implemented."); |
689 | } |
690 | public URL getURL(String columnName) throws SQLException { |
691 | return getURL( findColumn( columnName ) ); |
692 | } |
693 | public void updateRef(int columnIndex, Ref x) throws SQLException { |
694 | /**@todo: Implement this java.sql.ResultSet method*/ |
695 | throw new java.lang.UnsupportedOperationException("Method updateRef() not yet implemented."); |
696 | } |
697 | public void updateRef(String columnName, Ref x) throws SQLException { |
698 | updateRef( findColumn( columnName ), x ); |
699 | } |
700 | public void updateBlob(int columnIndex, Blob x) throws SQLException { |
701 | /**@todo: Implement this java.sql.ResultSet method*/ |
702 | throw new java.lang.UnsupportedOperationException("Method updateBlob() not yet implemented."); |
703 | } |
704 | public void updateBlob(String columnName, Blob x) throws SQLException { |
705 | updateBlob( findColumn( columnName ), x ); |
706 | } |
707 | public void updateClob(int columnIndex, Clob x) throws SQLException { |
708 | /**@todo: Implement this java.sql.ResultSet method*/ |
709 | throw new java.lang.UnsupportedOperationException("Method updateClob() not yet implemented."); |
710 | } |
711 | public void updateClob(String columnName, Clob x) throws SQLException { |
712 | updateClob( findColumn( columnName ), x ); |
713 | } |
714 | public void updateArray(int columnIndex, Array x) throws SQLException { |
715 | /**@todo: Implement this java.sql.ResultSet method*/ |
716 | throw new java.lang.UnsupportedOperationException("Method updateArray() not yet implemented."); |
717 | } |
718 | public void updateArray(String columnName, Array x) throws SQLException { |
719 | updateArray( findColumn( columnName ), x ); |
720 | } |
721 | |
722 | /*======================================================== |
723 | |
724 | private methods |
725 | |
726 | =========================================================*/ |
727 | |
728 | /** |
729 | * Get the expression of a column. |
730 | * This expression can be used to request a value of the current row. |
731 | */ |
732 | final private Expression getValue(int columnIndex) throws SQLException{ |
733 | if(values != null){ |
734 | ExpressionValue value = values[ metaData.getColumnIdx( columnIndex ) ]; |
735 | if(!value.isEmpty()) |
736 | return value; |
737 | } |
738 | return metaData.getColumnExpression(columnIndex); |
739 | } |
740 | |
741 | |
742 | final private ExpressionValue getUpdateValue(int columnIndex) throws SQLException{ |
743 | if(values == null){ |
744 | int count = metaData.getColumnCount(); |
745 | values = new ExpressionValue[count]; |
746 | while(count-- > 0){ |
747 | values[count] = new ExpressionValue(); |
748 | } |
749 | } |
750 | return values[ metaData.getColumnIdx( columnIndex ) ]; |
751 | } |
752 | |
753 | |
754 | final private void updateValue(int columnIndex, Object x, int dataType) throws SQLException{ |
755 | getUpdateValue( columnIndex ).set( x, dataType ); |
756 | if(st.con.log.isLogging()){ |
757 | |
758 | st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType); |
759 | } |
760 | } |
761 | |
762 | |
763 | final private void updateValue(int columnIndex, Object x, int dataType, int length) throws SQLException{ |
764 | getUpdateValue( columnIndex ).set( x, dataType, length ); |
765 | if(st.con.log.isLogging()){ |
766 | st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType+"; length="+length); |
767 | } |
768 | } |
769 | |
770 | |
771 | final private CommandSelect getCmd() throws SQLException { |
772 | if(cmd == null) throw Utils.createSQLException("ResultSet is closed."); |
773 | return cmd; |
774 | } |
775 | } |