File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\jdbc\JdbcResultSet.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.jdbc;
8
9 import java.io.InputStream;
10 import java.io.Reader;
11 import java.math.BigDecimal;
12 import java.net.URL;
13 import java.sql.Array;
14 import java.sql.Blob;
15 import java.sql.Clob;
16 import java.sql.Date;
17 import java.sql.Ref;
18 import java.sql.ResultSet;
19 import java.sql.ResultSetMetaData;
20 import java.sql.SQLException;
21 import java.sql.SQLWarning;
22 import java.sql.Statement;
23 import java.sql.Time;
24 import java.sql.Timestamp;
25 import java.util.Calendar;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 //## Java 1.6 ##
30 import java.sql.NClob;
31 import java.sql.RowId;
32 import java.sql.SQLXML;
33 //*/
34
35 import org.h2.constant.ErrorCode;
36 import org.h2.constant.SysProperties;
37 import org.h2.message.DbException;
38 import org.h2.message.TraceObject;
39 import org.h2.result.ResultInterface;
40 import org.h2.result.UpdatableRow;
41 import org.h2.util.DateTimeUtils;
42 import org.h2.util.IOUtils;
43 import org.h2.util.MathUtils;
44 import org.h2.util.New;
45 import org.h2.util.StringUtils;
46 import org.h2.value.CompareMode;
47 import org.h2.value.DataType;
48 import org.h2.value.Value;
49 import org.h2.value.ValueBoolean;
50 import org.h2.value.ValueByte;
51 import org.h2.value.ValueBytes;
52 import org.h2.value.ValueDate;
53 import org.h2.value.ValueDecimal;
54 import org.h2.value.ValueDouble;
55 import org.h2.value.ValueFloat;
56 import org.h2.value.ValueInt;
57 import org.h2.value.ValueLong;
58 import org.h2.value.ValueNull;
59 import org.h2.value.ValueShort;
60 import org.h2.value.ValueString;
61 import org.h2.value.ValueTime;
62 import org.h2.value.ValueTimestamp;
63
64 /**
65 * <p>
66 * Represents a result set.
67 * </p>
68 * <p>
69 * Column labels are case-insensitive, quotes are not supported. The first column
70 * has the column index 1.
71 * </p>
72 * <p>
73 * Updatable result sets:
74 * Result sets are updatable when the result only contains columns from one
75 * table, and if it contains all columns of a unique index (primary key or
76 * other) of this table. Key columns may not contain NULL (because multiple rows
77 * with NULL could exist). In updatable result sets, own changes are visible,
78 * but not own inserts and deletes.
79 * </p>
80 */
81 public class JdbcResultSet extends TraceObject implements ResultSet {
82 private final boolean closeStatement;
83 private final boolean scrollable;
84 private final boolean updatable;
85 private ResultInterface result;
86 private JdbcConnection conn;
87 private JdbcStatement stat;
88 private int columnCount;
89 private boolean wasNull;
90 private Value[] insertRow;
91 private Value[] updateRow;
92 private HashMap<String, Integer> columnLabelMap;
93 private HashMap<Integer, Value[]> patchedRows;
94 private JdbcPreparedStatement preparedStatement;
95
96 JdbcResultSet(JdbcConnection conn, JdbcStatement stat, ResultInterface result, int id,
97 boolean closeStatement, boolean scrollable, boolean updatable) {
98 setTrace(conn.getSession().getTrace(), TraceObject.RESULT_SET, id);
99 this.conn = conn;
100 this.stat = stat;
101 this.result = result;
102 columnCount = result.getVisibleColumnCount();
103 this.closeStatement = closeStatement;
104 this.scrollable = scrollable;
105 this.updatable = updatable;
106 }
107
108 JdbcResultSet(JdbcConnection conn, JdbcPreparedStatement preparedStatement, ResultInterface result, int id,
109 boolean closeStatement, boolean scrollable, boolean updatable, HashMap<String, Integer> columnLabelMap) {
110 this(conn, preparedStatement, result, id, closeStatement, scrollable, updatable);
111 this.columnLabelMap = columnLabelMap;
112 this.preparedStatement = preparedStatement;
113 }
114
115 /**
116 * Moves the cursor to the next row of the result set.
117 *
118 * @return true if successful, false if there are no more rows
119 */
120 public boolean next() throws SQLException {
121 try {
122 debugCodeCall("next");
123 checkClosed();
124 return nextRow();
125 } catch (Exception e) {
126 throw logAndConvert(e);
127 }
128 }
129
130 /**
131 * Gets the meta data of this result set.
132 *
133 * @return the meta data
134 */
135 public ResultSetMetaData getMetaData() throws SQLException {
136 try {
137 int id = getNextId(TraceObject.RESULT_SET_META_DATA);
138 if (isDebugEnabled()) {
139 debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
140 }
141 checkClosed();
142 String catalog = conn.getCatalog();
143 JdbcResultSetMetaData meta = new JdbcResultSetMetaData(this, null, result, catalog, conn.getSession().getTrace(), id);
144 return meta;
145 } catch (Exception e) {
146 throw logAndConvert(e);
147 }
148 }
149
150 /**
151 * Returns whether the last column accessed was null.
152 *
153 * @return true if the last column accessed was null
154 */
155 public boolean wasNull() throws SQLException {
156 try {
157 debugCodeCall("wasNull");
158 checkClosed();
159 return wasNull;
160 } catch (Exception e) {
161 throw logAndConvert(e);
162 }
163 }
164
165 /**
166 * Searches for a specific column in the result set. A case-insensitive
167 * search is made.
168 *
169 * @param columnLabel the column label
170 * @return the column index (1,2,...)
171 * @throws SQLException if the column is not found or if the result set is
172 * closed
173 */
174 public int findColumn(String columnLabel) throws SQLException {
175 try {
176 debugCodeCall("findColumn", columnLabel);
177 return getColumnIndex(columnLabel);
178 } catch (Exception e) {
179 throw logAndConvert(e);
180 }
181 }
182
183 /**
184 * Closes the result set.
185 */
186 public void close() throws SQLException {
187 try {
188 debugCodeCall("close");
189 closeInternal();
190 } catch (Exception e) {
191 throw logAndConvert(e);
192 }
193 }
194
195 /**
196 * Close the result set. This method also closes the statement if required.
197 */
198 void closeInternal() throws SQLException {
199 if (result != null) {
200 try {
201 result.close();
202 if (closeStatement && stat != null) {
203 stat.close();
204 }
205 } finally {
206 columnCount = 0;
207 result = null;
208 stat = null;
209 conn = null;
210 insertRow = null;
211 updateRow = null;
212 }
213 }
214 }
215
216 /**
217 * Returns the statement that created this object.
218 *
219 * @return the statement or prepared statement, or null if created by a
220 * DatabaseMetaData call.
221 */
222 public Statement getStatement() throws SQLException {
223 try {
224 debugCodeCall("getStatement");
225 checkClosed();
226 if (closeStatement) {
227 // if the result set was opened by a DatabaseMetaData call
228 return null;
229 }
230 return stat;
231 } catch (Exception e) {
232 throw logAndConvert(e);
233 }
234 }
235
236 /**
237 * Gets the first warning reported by calls on this object.
238 *
239 * @return null
240 */
241 public SQLWarning getWarnings() throws SQLException {
242 try {
243 debugCodeCall("getWarnings");
244 checkClosed();
245 return null;
246 } catch (Exception e) {
247 throw logAndConvert(e);
248 }
249 }
250
251 /**
252 * Clears all warnings.
253 */
254 public void clearWarnings() throws SQLException {
255 try {
256 debugCodeCall("clearWarnings");
257 checkClosed();
258 } catch (Exception e) {
259 throw logAndConvert(e);
260 }
261 }
262
263 // =============================================================
264
265 /**
266 * Returns the value of the specified column as a String.
267 *
268 * @param columnIndex (1,2,...)
269 * @return the value
270 * @throws SQLException if the column is not found or if the result set is closed
271 */
272 public String getString(int columnIndex) throws SQLException {
273 try {
274 debugCodeCall("getString", columnIndex);
275 return get(columnIndex).getString();
276 } catch (Exception e) {
277 throw logAndConvert(e);
278 }
279 }
280
281 /**
282 * Returns the value of the specified column as a String.
283 *
284 * @param columnLabel the column label
285 * @return the value
286 * @throws SQLException if the column is not found or if the result set is closed
287 */
288 public String getString(String columnLabel) throws SQLException {
289 try {
290 debugCodeCall("getString", columnLabel);
291 return get(columnLabel).getString();
292 } catch (Exception e) {
293 throw logAndConvert(e);
294 }
295 }
296
297 /**
298 * Returns the value of the specified column as an int.
299 *
300 * @param columnIndex (1,2,...)
301 * @return the value
302 * @throws SQLException if the column is not found or if the result set is closed
303 */
304 public int getInt(int columnIndex) throws SQLException {
305 try {
306 debugCodeCall("getInt", columnIndex);
307 return get(columnIndex).getInt();
308 } catch (Exception e) {
309 throw logAndConvert(e);
310 }
311 }
312
313 /**
314 * Returns the value of the specified column as an int.
315 *
316 * @param columnLabel the column label
317 * @return the value
318 * @throws SQLException if the column is not found or if the result set is closed
319 */
320 public int getInt(String columnLabel) throws SQLException {
321 try {
322 debugCodeCall("getInt", columnLabel);
323 return get(columnLabel).getInt();
324 } catch (Exception e) {
325 throw logAndConvert(e);
326 }
327 }
328
329 /**
330 * Returns the value of the specified column as a BigDecimal.
331 *
332 * @param columnIndex (1,2,...)
333 * @return the value
334 * @throws SQLException if the column is not found or if the result set is closed
335 */
336 public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
337 try {
338 debugCodeCall("getBigDecimal", columnIndex);
339 return get(columnIndex).getBigDecimal();
340 } catch (Exception e) {
341 throw logAndConvert(e);
342 }
343 }
344
345 /**
346 * Returns the value of the specified column as a java.sql.Date.
347 *
348 * @param columnIndex (1,2,...)
349 * @return the value
350 * @throws SQLException if the column is not found or if the result set is closed
351 */
352 public Date getDate(int columnIndex) throws SQLException {
353 try {
354 debugCodeCall("getDate", columnIndex);
355 return get(columnIndex).getDate();
356 } catch (Exception e) {
357 throw logAndConvert(e);
358 }
359 }
360
361 /**
362 * Returns the value of the specified column as a java.sql.Time.
363 *
364 * @param columnIndex (1,2,...)
365 * @return the value
366 * @throws SQLException if the column is not found or if the result set is closed
367 */
368 public Time getTime(int columnIndex) throws SQLException {
369 try {
370 debugCodeCall("getTime", columnIndex);
371 return get(columnIndex).getTime();
372 } catch (Exception e) {
373 throw logAndConvert(e);
374 }
375 }
376
377 /**
378 * Returns the value of the specified column as a java.sql.Timestamp.
379 *
380 * @param columnIndex (1,2,...)
381 * @return the value
382 * @throws SQLException if the column is not found or if the result set is closed
383 */
384 public Timestamp getTimestamp(int columnIndex) throws SQLException {
385 try {
386 debugCodeCall("getTimestamp", columnIndex);
387 return get(columnIndex).getTimestamp();
388 } catch (Exception e) {
389 throw logAndConvert(e);
390 }
391 }
392
393 /**
394 * Returns the value of the specified column as a BigDecimal.
395 *
396 * @param columnLabel the column label
397 * @return the value
398 * @throws SQLException if the column is not found or if the result set is
399 * closed
400 */
401 public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
402 try {
403 debugCodeCall("getBigDecimal", columnLabel);
404 return get(columnLabel).getBigDecimal();
405 } catch (Exception e) {
406 throw logAndConvert(e);
407 }
408 }
409
410 /**
411 * Returns the value of the specified column as a java.sql.Date.
412 *
413 * @param columnLabel the column label
414 * @return the value
415 * @throws SQLException if the column is not found or if the result set is closed
416 */
417 public Date getDate(String columnLabel) throws SQLException {
418 try {
419 debugCodeCall("getDate", columnLabel);
420 return get(columnLabel).getDate();
421 } catch (Exception e) {
422 throw logAndConvert(e);
423 }
424 }
425
426 /**
427 * Returns the value of the specified column as a java.sql.Time.
428 *
429 * @param columnLabel the column label
430 * @return the value
431 * @throws SQLException if the column is not found or if the result set is
432 * closed
433 */
434 public Time getTime(String columnLabel) throws SQLException {
435 try {
436 debugCodeCall("getTime", columnLabel);
437 return get(columnLabel).getTime();
438 } catch (Exception e) {
439 throw logAndConvert(e);
440 }
441 }
442
443 /**
444 * Returns the value of the specified column as a java.sql.Timestamp.
445 *
446 * @param columnLabel the column label
447 * @return the value
448 * @throws SQLException if the column is not found or if the result set is
449 * closed
450 */
451 public Timestamp getTimestamp(String columnLabel) throws SQLException {
452 try {
453 debugCodeCall("getTimestamp", columnLabel);
454 return get(columnLabel).getTimestamp();
455 } catch (Exception e) {
456 throw logAndConvert(e);
457 }
458 }
459
460 /**
461 * Returns a column value as a Java object. The data is
462 * de-serialized into a Java object (on the client side).
463 *
464 * @param columnIndex (1,2,...)
465 * @return the value or null
466 * @throws SQLException if the column is not found or if the result set is
467 * closed
468 */
469 public Object getObject(int columnIndex) throws SQLException {
470 try {
471 debugCodeCall("getObject", columnIndex);
472 Value v = get(columnIndex);
473 return conn.convertToDefaultObject(v);
474 } catch (Exception e) {
475 throw logAndConvert(e);
476 }
477 }
478
479 /**
480 * Returns a column value as a Java object. The data is
481 * de-serialized into a Java object (on the client side).
482 *
483 * @param columnLabel the column label
484 * @return the value or null
485 * @throws SQLException if the column is not found or if the result set is
486 * closed
487 */
488 public Object getObject(String columnLabel) throws SQLException {
489 try {
490 debugCodeCall("getObject", columnLabel);
491 Value v = get(columnLabel);
492 return conn.convertToDefaultObject(v);
493 } catch (Exception e) {
494 throw logAndConvert(e);
495 }
496 }
497
498 /**
499 * Returns the value of the specified column as a boolean.
500 *
501 * @param columnIndex (1,2,...)
502 * @return the value
503 * @throws SQLException if the column is not found or if the result set is
504 * closed
505 */
506 public boolean getBoolean(int columnIndex) throws SQLException {
507 try {
508 debugCodeCall("getBoolean", columnIndex);
509 Boolean v = get(columnIndex).getBoolean();
510 return v == null ? false : v.booleanValue();
511 } catch (Exception e) {
512 throw logAndConvert(e);
513 }
514 }
515
516 /**
517 * Returns the value of the specified column as a boolean.
518 *
519 * @param columnLabel the column label
520 * @return the value
521 * @throws SQLException if the column is not found or if the result set is
522 * closed
523 */
524 public boolean getBoolean(String columnLabel) throws SQLException {
525 try {
526 debugCodeCall("getBoolean", columnLabel);
527 Boolean v = get(columnLabel).getBoolean();
528 return v == null ? false : v.booleanValue();
529 } catch (Exception e) {
530 throw logAndConvert(e);
531 }
532 }
533
534 /**
535 * Returns the value of the specified column as a byte.
536 *
537 * @param columnIndex (1,2,...)
538 * @return the value
539 * @throws SQLException if the column is not found or if the result set is
540 * closed
541 */
542 public byte getByte(int columnIndex) throws SQLException {
543 try {
544 debugCodeCall("getByte", columnIndex);
545 return get(columnIndex).getByte();
546 } catch (Exception e) {
547 throw logAndConvert(e);
548 }
549 }
550
551 /**
552 * Returns the value of the specified column as a byte.
553 *
554 * @param columnLabel the column label
555 * @return the value
556 * @throws SQLException if the column is not found or if the result set is
557 * closed
558 */
559 public byte getByte(String columnLabel) throws SQLException {
560 try {
561 debugCodeCall("getByte", columnLabel);
562 return get(columnLabel).getByte();
563 } catch (Exception e) {
564 throw logAndConvert(e);
565 }
566 }
567
568 /**
569 * Returns the value of the specified column as a short.
570 *
571 * @param columnIndex (1,2,...)
572 * @return the value
573 * @throws SQLException if the column is not found or if the result set is
574 * closed
575 */
576 public short getShort(int columnIndex) throws SQLException {
577 try {
578 debugCodeCall("getShort", columnIndex);
579 return get(columnIndex).getShort();
580 } catch (Exception e) {
581 throw logAndConvert(e);
582 }
583 }
584
585 /**
586 * Returns the value of the specified column as a short.
587 *
588 * @param columnLabel the column label
589 * @return the value
590 * @throws SQLException if the column is not found or if the result set is
591 * closed
592 */
593 public short getShort(String columnLabel) throws SQLException {
594 try {
595 debugCodeCall("getShort", columnLabel);
596 return get(columnLabel).getShort();
597 } catch (Exception e) {
598 throw logAndConvert(e);
599 }
600 }
601
602 /**
603 * Returns the value of the specified column as a long.
604 *
605 * @param columnIndex (1,2,...)
606 * @return the value
607 * @throws SQLException if the column is not found or if the result set is
608 * closed
609 */
610 public long getLong(int columnIndex) throws SQLException {
611 try {
612 debugCodeCall("getLong", columnIndex);
613 return get(columnIndex).getLong();
614 } catch (Exception e) {
615 throw logAndConvert(e);
616 }
617 }
618
619 /**
620 * Returns the value of the specified column as a long.
621 *
622 * @param columnLabel the column label
623 * @return the value
624 * @throws SQLException if the column is not found or if the result set is
625 * closed
626 */
627 public long getLong(String columnLabel) throws SQLException {
628 try {
629 debugCodeCall("getLong", columnLabel);
630 return get(columnLabel).getLong();
631 } catch (Exception e) {
632 throw logAndConvert(e);
633 }
634 }
635
636 /**
637 * Returns the value of the specified column as a float.
638 *
639 * @param columnIndex (1,2,...)
640 * @return the value
641 * @throws SQLException if the column is not found or if the result set is
642 * closed
643 */
644 public float getFloat(int columnIndex) throws SQLException {
645 try {
646 debugCodeCall("getFloat", columnIndex);
647 return get(columnIndex).getFloat();
648 } catch (Exception e) {
649 throw logAndConvert(e);
650 }
651 }
652
653 /**
654 * Returns the value of the specified column as a float.
655 *
656 * @param columnLabel the column label
657 * @return the value
658 * @throws SQLException if the column is not found or if the result set is
659 * closed
660 */
661 public float getFloat(String columnLabel) throws SQLException {
662 try {
663 debugCodeCall("getFloat", columnLabel);
664 return get(columnLabel).getFloat();
665 } catch (Exception e) {
666 throw logAndConvert(e);
667 }
668 }
669
670 /**
671 * Returns the value of the specified column as a double.
672 *
673 * @param columnIndex (1,2,...)
674 * @return the value
675 * @throws SQLException if the column is not found or if the result set is
676 * closed
677 */
678 public double getDouble(int columnIndex) throws SQLException {
679 try {
680 debugCodeCall("getDouble", columnIndex);
681 return get(columnIndex).getDouble();
682 } catch (Exception e) {
683 throw logAndConvert(e);
684 }
685 }
686
687 /**
688 * Returns the value of the specified column as a double.
689 *
690 * @param columnLabel the column label
691 * @return the value
692 * @throws SQLException if the column is not found or if the result set is
693 * closed
694 */
695 public double getDouble(String columnLabel) throws SQLException {
696 try {
697 debugCodeCall("getDouble", columnLabel);
698 return get(columnLabel).getDouble();
699 } catch (Exception e) {
700 throw logAndConvert(e);
701 }
702 }
703
704 /**
705 * Returns the value of the specified column as a BigDecimal.
706 *
707 * @deprecated use {@link #getBigDecimal(String)}
708 *
709 * @param columnLabel the column label
710 * @param scale the scale of the returned value
711 * @return the value
712 * @throws SQLException if the column is not found or if the result set is
713 * closed
714 */
715 public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
716 try {
717 if (isDebugEnabled()) {
718 debugCode("getBigDecimal(" + StringUtils.quoteJavaString(columnLabel)+", "+scale+");");
719 }
720 if (scale < 0) {
721 throw DbException.getInvalidValueException("scale", scale);
722 }
723 BigDecimal bd = get(columnLabel).getBigDecimal();
724 return bd == null ? null : MathUtils.setScale(bd, scale);
725 } catch (Exception e) {
726 throw logAndConvert(e);
727 }
728 }
729
730 /**
731 * Returns the value of the specified column as a BigDecimal.
732 *
733 * @deprecated use {@link #getBigDecimal(int)}
734 *
735 * @param columnIndex (1,2,...)
736 * @param scale the scale of the returned value
737 * @return the value
738 * @throws SQLException if the column is not found or if the result set is
739 * closed
740 */
741 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
742 try {
743 if (isDebugEnabled()) {
744 debugCode("getBigDecimal(" + columnIndex + ", " + scale + ");");
745 }
746 if (scale < 0) {
747 throw DbException.getInvalidValueException("scale", scale);
748 }
749 BigDecimal bd = get(columnIndex).getBigDecimal();
750 return bd == null ? null : MathUtils.setScale(bd, scale);
751 } catch (Exception e) {
752 throw logAndConvert(e);
753 }
754 }
755
756 /**
757 * [Not supported]
758 * @deprecated since JDBC 2.0, use getCharacterStream
759 */
760 public InputStream getUnicodeStream(int columnIndex) throws SQLException {
761 throw unsupported("unicodeStream");
762 }
763
764 /**
765 * [Not supported]
766 * @deprecated since JDBC 2.0, use setCharacterStream
767 */
768 public InputStream getUnicodeStream(String columnLabel) throws SQLException {
769 throw unsupported("unicodeStream");
770 }
771
772 /**
773 * [Not supported] Gets a column as a object using the specified type
774 * mapping.
775 */
776 public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
777 throw unsupported("map");
778 }
779
780 /**
781 * [Not supported] Gets a column as a object using the specified type
782 * mapping.
783 */
784 public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
785 throw unsupported("map");
786 }
787
788 /**
789 * [Not supported] Gets a column as a reference.
790 */
791 public Ref getRef(int columnIndex) throws SQLException {
792 throw unsupported("ref");
793 }
794
795 /**
796 * [Not supported] Gets a column as a reference.
797 */
798 public Ref getRef(String columnLabel) throws SQLException {
799 throw unsupported("ref");
800 }
801
802 /**
803 * Returns the value of the specified column as a java.sql.Date using a
804 * specified time zone.
805 *
806 * @param columnIndex (1,2,...)
807 * @param calendar the calendar
808 * @return the value
809 * @throws SQLException if the column is not found or if the result set is
810 * closed
811 */
812 public Date getDate(int columnIndex, Calendar calendar) throws SQLException {
813 try {
814 if (isDebugEnabled()) {
815 debugCode("getDate(" + columnIndex + ", calendar)");
816 }
817 return DateTimeUtils.convertDate(get(columnIndex), calendar);
818 } catch (Exception e) {
819 throw logAndConvert(e);
820 }
821 }
822
823 /**
824 * Returns the value of the specified column as a java.sql.Date using a
825 * specified time zone.
826 *
827 * @param columnLabel the column label
828 * @param calendar the calendar
829 * @return the value
830 * @throws SQLException if the column is not found or if the result set is
831 * closed
832 */
833 public Date getDate(String columnLabel, Calendar calendar) throws SQLException {
834 try {
835 if (isDebugEnabled()) {
836 debugCode("getDate(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
837 }
838 return DateTimeUtils.convertDate(get(columnLabel), calendar);
839 } catch (Exception e) {
840 throw logAndConvert(e);
841 }
842 }
843
844 /**
845 * Returns the value of the specified column as a java.sql.Time using a
846 * specified time zone.
847 *
848 * @param columnIndex (1,2,...)
849 * @param calendar the calendar
850 * @return the value
851 * @throws SQLException if the column is not found or if the result set is
852 * closed
853 */
854 public Time getTime(int columnIndex, Calendar calendar) throws SQLException {
855 try {
856 if (isDebugEnabled()) {
857 debugCode("getTime(" + columnIndex + ", calendar)");
858 }
859 return DateTimeUtils.convertTime(get(columnIndex), calendar);
860 } catch (Exception e) {
861 throw logAndConvert(e);
862 }
863 }
864
865 /**
866 * Returns the value of the specified column as a java.sql.Time using a
867 * specified time zone.
868 *
869 * @param columnLabel the column label
870 * @param calendar the calendar
871 * @return the value
872 * @throws SQLException if the column is not found or if the result set is
873 * closed
874 */
875 public Time getTime(String columnLabel, Calendar calendar) throws SQLException {
876 try {
877 if (isDebugEnabled()) {
878 debugCode("getTime(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
879 }
880 return DateTimeUtils.convertTime(get(columnLabel), calendar);
881 } catch (Exception e) {
882 throw logAndConvert(e);
883 }
884 }
885
886 /**
887 * Returns the value of the specified column as a java.sql.Timestamp using a
888 * specified time zone.
889 *
890 * @param columnIndex (1,2,...)
891 * @param calendar the calendar
892 * @return the value
893 * @throws SQLException if the column is not found or if the result set is
894 * closed
895 */
896 public Timestamp getTimestamp(int columnIndex, Calendar calendar) throws SQLException {
897 try {
898 if (isDebugEnabled()) {
899 debugCode("getTimestamp(" + columnIndex + ", calendar)");
900 }
901 Value value = get(columnIndex);
902 return DateTimeUtils.convertTimestamp(value, calendar);
903 } catch (Exception e) {
904 throw logAndConvert(e);
905 }
906 }
907
908 /**
909 * Returns the value of the specified column as a java.sql.Timestamp.
910 *
911 * @param columnLabel the column label
912 * @param calendar the calendar
913 * @return the value
914 * @throws SQLException if the column is not found or if the result set is
915 * closed
916 */
917 public Timestamp getTimestamp(String columnLabel, Calendar calendar) throws SQLException {
918 try {
919 if (isDebugEnabled()) {
920 debugCode("getTimestamp(" + StringUtils.quoteJavaString(columnLabel) + ", calendar)");
921 }
922 Value value = get(columnLabel);
923 return DateTimeUtils.convertTimestamp(value, calendar);
924 } catch (Exception e) {
925 throw logAndConvert(e);
926 }
927 }
928
929 /**
930 * Returns the value of the specified column as a Blob.
931 *
932 * @param columnIndex (1,2,...)
933 * @return the value
934 * @throws SQLException if the column is not found or if the result set is
935 * closed
936 */
937 public Blob getBlob(int columnIndex) throws SQLException {
938 try {
939 int id = getNextId(TraceObject.BLOB);
940 debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + columnIndex + ")");
941 Value v = get(columnIndex);
942 return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
943 } catch (Exception e) {
944 throw logAndConvert(e);
945 }
946 }
947
948 /**
949 * Returns the value of the specified column as a Blob.
950 *
951 * @param columnLabel the column label
952 * @return the value
953 * @throws SQLException if the column is not found or if the result set is
954 * closed
955 */
956 public Blob getBlob(String columnLabel) throws SQLException {
957 try {
958 int id = getNextId(TraceObject.BLOB);
959 debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + quote(columnLabel) + ")");
960 Value v = get(columnLabel);
961 return v == ValueNull.INSTANCE ? null : new JdbcBlob(conn, v, id);
962 } catch (Exception e) {
963 throw logAndConvert(e);
964 }
965 }
966
967 /**
968 * Returns the value of the specified column as a byte array.
969 *
970 * @param columnIndex (1,2,...)
971 * @return the value
972 * @throws SQLException if the column is not found or if the result set is
973 * closed
974 */
975 public byte[] getBytes(int columnIndex) throws SQLException {
976 try {
977 debugCodeCall("getBytes", columnIndex);
978 return get(columnIndex).getBytes();
979 } catch (Exception e) {
980 throw logAndConvert(e);
981 }
982 }
983
984 /**
985 * Returns the value of the specified column as a byte array.
986 *
987 * @param columnLabel the column label
988 * @return the value
989 * @throws SQLException if the column is not found or if the result set is
990 * closed
991 */
992 public byte[] getBytes(String columnLabel) throws SQLException {
993 try {
994 debugCodeCall("getBytes", columnLabel);
995 return get(columnLabel).getBytes();
996 } catch (Exception e) {
997 throw logAndConvert(e);
998 }
999 }
1000
1001 /**
1002 * Returns the value of the specified column as an input stream.
1003 *
1004 * @param columnIndex (1,2,...)
1005 * @return the value
1006 * @throws SQLException if the column is not found or if the result set is
1007 * closed
1008 */
1009 public InputStream getBinaryStream(int columnIndex) throws SQLException {
1010 try {
1011 debugCodeCall("getBinaryStream", columnIndex);
1012 return get(columnIndex).getInputStream();
1013 } catch (Exception e) {
1014 throw logAndConvert(e);
1015 }
1016 }
1017
1018 /**
1019 * Returns the value of the specified column as an input stream.
1020 *
1021 * @param columnLabel the column label
1022 * @return the value
1023 * @throws SQLException if the column is not found or if the result set is
1024 * closed
1025 */
1026 public InputStream getBinaryStream(String columnLabel) throws SQLException {
1027 try {
1028 debugCodeCall("getBinaryStream", columnLabel);
1029 return get(columnLabel).getInputStream();
1030 } catch (Exception e) {
1031 throw logAndConvert(e);
1032 }
1033 }
1034
1035
1036 /**
1037 * Returns the value of the specified column as a Clob.
1038 *
1039 * @param columnIndex (1,2,...)
1040 * @return the value
1041 * @throws SQLException if the column is not found or if the result set is
1042 * closed
1043 */
1044 public Clob getClob(int columnIndex) throws SQLException {
1045 try {
1046 int id = getNextId(TraceObject.CLOB);
1047 debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + columnIndex + ")");
1048 Value v = get(columnIndex);
1049 return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
1050 } catch (Exception e) {
1051 throw logAndConvert(e);
1052 }
1053 }
1054
1055 /**
1056 * Returns the value of the specified column as a Clob.
1057 *
1058 * @param columnLabel the column label
1059 * @return the value
1060 * @throws SQLException if the column is not found or if the result set is
1061 * closed
1062 */
1063 public Clob getClob(String columnLabel) throws SQLException {
1064 try {
1065 int id = getNextId(TraceObject.CLOB);
1066 debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + quote(columnLabel) + ")");
1067 Value v = get(columnLabel);
1068 return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
1069 } catch (Exception e) {
1070 throw logAndConvert(e);
1071 }
1072 }
1073
1074 /**
1075 * Returns the value of the specified column as an Array.
1076 *
1077 * @param columnIndex (1,2,...)
1078 * @return the value
1079 * @throws SQLException if the column is not found or if the result set is
1080 * closed
1081 */
1082 public Array getArray(int columnIndex) throws SQLException {
1083 try {
1084 int id = getNextId(TraceObject.ARRAY);
1085 debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + columnIndex + ")");
1086 Value v = get(columnIndex);
1087 return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
1088 } catch (Exception e) {
1089 throw logAndConvert(e);
1090 }
1091 }
1092
1093 /**
1094 * Returns the value of the specified column as an Array.
1095 *
1096 * @param columnLabel the column label
1097 * @return the value
1098 * @throws SQLException if the column is not found or if the result set is
1099 * closed
1100 */
1101 public Array getArray(String columnLabel) throws SQLException {
1102 try {
1103 int id = getNextId(TraceObject.ARRAY);
1104 debugCodeAssign("Clob", TraceObject.ARRAY, id, "getArray(" + quote(columnLabel) + ")");
1105 Value v = get(columnLabel);
1106 return v == ValueNull.INSTANCE ? null : new JdbcArray(conn, v, id);
1107 } catch (Exception e) {
1108 throw logAndConvert(e);
1109 }
1110 }
1111
1112 /**
1113 * Returns the value of the specified column as an input stream.
1114 *
1115 * @param columnIndex (1,2,...)
1116 * @return the value
1117 * @throws SQLException if the column is not found or if the result set is
1118 * closed
1119 */
1120 public InputStream getAsciiStream(int columnIndex) throws SQLException {
1121 try {
1122 debugCodeCall("getAsciiStream", columnIndex);
1123 String s = get(columnIndex).getString();
1124 return s == null ? null : IOUtils.getInputStreamFromString(s);
1125 } catch (Exception e) {
1126 throw logAndConvert(e);
1127 }
1128 }
1129
1130 /**
1131 * Returns the value of the specified column as an input stream.
1132 *
1133 * @param columnLabel the column label
1134 * @return the value
1135 * @throws SQLException if the column is not found or if the result set is
1136 * closed
1137 */
1138 public InputStream getAsciiStream(String columnLabel) throws SQLException {
1139 try {
1140 debugCodeCall("getAsciiStream", columnLabel);
1141 String s = get(columnLabel).getString();
1142 return IOUtils.getInputStreamFromString(s);
1143 } catch (Exception e) {
1144 throw logAndConvert(e);
1145 }
1146 }
1147
1148 /**
1149 * Returns the value of the specified column as a reader.
1150 *
1151 * @param columnIndex (1,2,...)
1152 * @return the value
1153 * @throws SQLException if the column is not found or if the result set is
1154 * closed
1155 */
1156 public Reader getCharacterStream(int columnIndex) throws SQLException {
1157 try {
1158 debugCodeCall("getCharacterStream", columnIndex);
1159 return get(columnIndex).getReader();
1160 } catch (Exception e) {
1161 throw logAndConvert(e);
1162 }
1163 }
1164
1165 /**
1166 * Returns the value of the specified column as a reader.
1167 *
1168 * @param columnLabel the column label
1169 * @return the value
1170 * @throws SQLException if the column is not found or if the result set is
1171 * closed
1172 */
1173 public Reader getCharacterStream(String columnLabel) throws SQLException {
1174 try {
1175 debugCodeCall("getCharacterStream", columnLabel);
1176 return get(columnLabel).getReader();
1177 } catch (Exception e) {
1178 throw logAndConvert(e);
1179 }
1180 }
1181
1182 /**
1183 * [Not supported]
1184 */
1185 public URL getURL(int columnIndex) throws SQLException {
1186 throw unsupported("url");
1187 }
1188
1189 /**
1190 * [Not supported]
1191 */
1192 public URL getURL(String columnLabel) throws SQLException {
1193 throw unsupported("url");
1194 }
1195
1196 // =============================================================
1197
1198 /**
1199 * Updates a column in the current or insert row.
1200 *
1201 * @param columnIndex (1,2,...)
1202 * @throws SQLException if the result set is closed or not updatable
1203 */
1204 public void updateNull(int columnIndex) throws SQLException {
1205 try {
1206 debugCodeCall("updateNull", columnIndex);
1207 update(columnIndex, ValueNull.INSTANCE);
1208 } catch (Exception e) {
1209 throw logAndConvert(e);
1210 }
1211 }
1212
1213 /**
1214 * Updates a column in the current or insert row.
1215 *
1216 * @param columnLabel the column label
1217 * @throws SQLException if the result set is closed or not updatable
1218 */
1219 public void updateNull(String columnLabel) throws SQLException {
1220 try {
1221 debugCodeCall("updateNull", columnLabel);
1222 update(columnLabel, ValueNull.INSTANCE);
1223 } catch (Exception e) {
1224 throw logAndConvert(e);
1225 }
1226 }
1227
1228 /**
1229 * Updates a column in the current or insert row.
1230 *
1231 * @param columnIndex (1,2,...)
1232 * @param x the value
1233 * @throws SQLException if the result set is closed or not updatable
1234 */
1235 public void updateBoolean(int columnIndex, boolean x) throws SQLException {
1236 try {
1237 if (isDebugEnabled()) {
1238 debugCode("updateBoolean("+columnIndex+", "+x+");");
1239 }
1240 update(columnIndex, ValueBoolean.get(x));
1241 } catch (Exception e) {
1242 throw logAndConvert(e);
1243 }
1244 }
1245
1246 /**
1247 * Updates a column in the current or insert row.
1248 *
1249 * @param columnLabel the column label
1250 * @param x the value
1251 * @throws SQLException if result set is closed or not updatable
1252 */
1253 public void updateBoolean(String columnLabel, boolean x) throws SQLException {
1254 try {
1255 if (isDebugEnabled()) {
1256 debugCode("updateBoolean("+quote(columnLabel)+", "+x+");");
1257 }
1258 update(columnLabel, ValueBoolean.get(x));
1259 } catch (Exception e) {
1260 throw logAndConvert(e);
1261 }
1262 }
1263
1264 /**
1265 * Updates a column in the current or insert row.
1266 *
1267 * @param columnIndex (1,2,...)
1268 * @param x the value
1269 * @throws SQLException if the result set is closed or not updatable
1270 */
1271 public void updateByte(int columnIndex, byte x) throws SQLException {
1272 try {
1273 if (isDebugEnabled()) {
1274 debugCode("updateByte("+columnIndex+", "+x+");");
1275 }
1276 update(columnIndex, ValueByte.get(x));
1277 } catch (Exception e) {
1278 throw logAndConvert(e);
1279 }
1280 }
1281
1282 /**
1283 * Updates a column in the current or insert row.
1284 *
1285 * @param columnLabel the column label
1286 * @param x the value
1287 * @throws SQLException if the result set is closed or not updatable
1288 */
1289 public void updateByte(String columnLabel, byte x) throws SQLException {
1290 try {
1291 if (isDebugEnabled()) {
1292 debugCode("updateByte("+columnLabel+", "+x+");");
1293 }
1294 update(columnLabel, ValueByte.get(x));
1295 } catch (Exception e) {
1296 throw logAndConvert(e);
1297 }
1298 }
1299
1300 /**
1301 * Updates a column in the current or insert row.
1302 *
1303 * @param columnIndex (1,2,...)
1304 * @param x the value
1305 * @throws SQLException if the result set is closed or not updatable
1306 */
1307 public void updateBytes(int columnIndex, byte[] x) throws SQLException {
1308 try {
1309 if (isDebugEnabled()) {
1310 debugCode("updateBytes("+columnIndex+", x);");
1311 }
1312 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x));
1313 } catch (Exception e) {
1314 throw logAndConvert(e);
1315 }
1316 }
1317
1318 /**
1319 * Updates a column in the current or insert row.
1320 *
1321 * @param columnLabel the column label
1322 * @param x the value
1323 * @throws SQLException if the result set is closed or not updatable
1324 */
1325 public void updateBytes(String columnLabel, byte[] x) throws SQLException {
1326 try {
1327 if (isDebugEnabled()) {
1328 debugCode("updateBytes("+quote(columnLabel)+", x);");
1329 }
1330 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueBytes.get(x));
1331 } catch (Exception e) {
1332 throw logAndConvert(e);
1333 }
1334 }
1335
1336 /**
1337 * Updates a column in the current or insert row.
1338 *
1339 * @param columnIndex (1,2,...)
1340 * @param x the value
1341 * @throws SQLException if the result set is closed or not updatable
1342 */
1343 public void updateShort(int columnIndex, short x) throws SQLException {
1344 try {
1345 if (isDebugEnabled()) {
1346 debugCode("updateShort("+columnIndex+", (short) "+x+");");
1347 }
1348 update(columnIndex, ValueShort.get(x));
1349 } catch (Exception e) {
1350 throw logAndConvert(e);
1351 }
1352 }
1353
1354 /**
1355 * Updates a column in the current or insert row.
1356 *
1357 * @param columnLabel the column label
1358 * @param x the value
1359 * @throws SQLException if the result set is closed or not updatable
1360 */
1361 public void updateShort(String columnLabel, short x) throws SQLException {
1362 try {
1363 if (isDebugEnabled()) {
1364 debugCode("updateShort("+quote(columnLabel)+", (short) "+x+");");
1365 }
1366 update(columnLabel, ValueShort.get(x));
1367 } catch (Exception e) {
1368 throw logAndConvert(e);
1369 }
1370 }
1371
1372 /**
1373 * Updates a column in the current or insert row.
1374 *
1375 * @param columnIndex (1,2,...)
1376 * @param x the value
1377 * @throws SQLException if the result set is closed or not updatable
1378 */
1379 public void updateInt(int columnIndex, int x) throws SQLException {
1380 try {
1381 if (isDebugEnabled()) {
1382 debugCode("updateInt("+columnIndex+", "+x+");");
1383 }
1384 update(columnIndex, ValueInt.get(x));
1385 } catch (Exception e) {
1386 throw logAndConvert(e);
1387 }
1388 }
1389
1390 /**
1391 * Updates a column in the current or insert row.
1392 *
1393 * @param columnLabel the column label
1394 * @param x the value
1395 * @throws SQLException if the result set is closed or not updatable
1396 */
1397 public void updateInt(String columnLabel, int x) throws SQLException {
1398 try {
1399 if (isDebugEnabled()) {
1400 debugCode("updateInt("+quote(columnLabel)+", "+x+");");
1401 }
1402 update(columnLabel, ValueInt.get(x));
1403 } catch (Exception e) {
1404 throw logAndConvert(e);
1405 }
1406 }
1407
1408 /**
1409 * Updates a column in the current or insert row.
1410 *
1411 * @param columnIndex (1,2,...)
1412 * @param x the value
1413 * @throws SQLException if the result set is closed or not updatable
1414 */
1415 public void updateLong(int columnIndex, long x) throws SQLException {
1416 try {
1417 if (isDebugEnabled()) {
1418 debugCode("updateLong("+columnIndex+", "+x+"L);");
1419 }
1420 update(columnIndex, ValueLong.get(x));
1421 } catch (Exception e) {
1422 throw logAndConvert(e);
1423 }
1424 }
1425
1426 /**
1427 * Updates a column in the current or insert row.
1428 *
1429 * @param columnLabel the column label
1430 * @param x the value
1431 * @throws SQLException if the result set is closed or not updatable
1432 */
1433 public void updateLong(String columnLabel, long x) throws SQLException {
1434 try {
1435 if (isDebugEnabled()) {
1436 debugCode("updateLong("+quote(columnLabel)+", "+x+"L);");
1437 }
1438 update(columnLabel, ValueLong.get(x));
1439 } catch (Exception e) {
1440 throw logAndConvert(e);
1441 }
1442 }
1443
1444 /**
1445 * Updates a column in the current or insert row.
1446 *
1447 * @param columnIndex (1,2,...)
1448 * @param x the value
1449 * @throws SQLException if the result set is closed or not updatable
1450 */
1451 public void updateFloat(int columnIndex, float x) throws SQLException {
1452 try {
1453 if (isDebugEnabled()) {
1454 debugCode("updateFloat("+columnIndex+", "+x+"f);");
1455 }
1456 update(columnIndex, ValueFloat.get(x));
1457 } catch (Exception e) {
1458 throw logAndConvert(e);
1459 }
1460 }
1461
1462 /**
1463 * Updates a column in the current or insert row.
1464 *
1465 * @param columnLabel the column label
1466 * @param x the value
1467 * @throws SQLException if the result set is closed or not updatable
1468 */
1469 public void updateFloat(String columnLabel, float x) throws SQLException {
1470 try {
1471 if (isDebugEnabled()) {
1472 debugCode("updateFloat("+quote(columnLabel)+", "+x+"f);");
1473 }
1474 update(columnLabel, ValueFloat.get(x));
1475 } catch (Exception e) {
1476 throw logAndConvert(e);
1477 }
1478 }
1479
1480 /**
1481 * Updates a column in the current or insert row.
1482 *
1483 * @param columnIndex (1,2,...)
1484 * @param x the value
1485 * @throws SQLException if the result set is closed or not updatable
1486 */
1487 public void updateDouble(int columnIndex, double x) throws SQLException {
1488 try {
1489 if (isDebugEnabled()) {
1490 debugCode("updateDouble("+columnIndex+", "+x+"d);");
1491 }
1492 update(columnIndex, ValueDouble.get(x));
1493 } catch (Exception e) {
1494 throw logAndConvert(e);
1495 }
1496 }
1497
1498 /**
1499 * Updates a column in the current or insert row.
1500 *
1501 * @param columnLabel the column label
1502 * @param x the value
1503 * @throws SQLException if the result set is closed or not updatable
1504 */
1505 public void updateDouble(String columnLabel, double x) throws SQLException {
1506 try {
1507 if (isDebugEnabled()) {
1508 debugCode("updateDouble("+quote(columnLabel)+", "+x+"d);");
1509 }
1510 update(columnLabel, ValueDouble.get(x));
1511 } catch (Exception e) {
1512 throw logAndConvert(e);
1513 }
1514 }
1515
1516 /**
1517 * Updates a column in the current or insert row.
1518 *
1519 * @param columnIndex (1,2,...)
1520 * @param x the value
1521 * @throws SQLException if the result set is closed or not updatable
1522 */
1523 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
1524 try {
1525 if (isDebugEnabled()) {
1526 debugCode("updateBigDecimal("+columnIndex+", " + quoteBigDecimal(x) + ");");
1527 }
1528 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x));
1529 } catch (Exception e) {
1530 throw logAndConvert(e);
1531 }
1532 }
1533
1534 /**
1535 * Updates a column in the current or insert row.
1536 *
1537 * @param columnLabel the column label
1538 * @param x the value
1539 * @throws SQLException if the result set is closed or not updatable
1540 */
1541 public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
1542 try {
1543 if (isDebugEnabled()) {
1544 debugCode("updateBigDecimal("+quote(columnLabel)+", " + quoteBigDecimal(x) + ");");
1545 }
1546 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueDecimal.get(x));
1547 } catch (Exception e) {
1548 throw logAndConvert(e);
1549 }
1550 }
1551
1552 /**
1553 * Updates a column in the current or insert row.
1554 *
1555 * @param columnIndex (1,2,...)
1556 * @param x the value
1557 * @throws SQLException if the result set is closed or not updatable
1558 */
1559 public void updateString(int columnIndex, String x) throws SQLException {
1560 try {
1561 if (isDebugEnabled()) {
1562 debugCode("updateString("+columnIndex+", "+quote(x)+");");
1563 }
1564 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x));
1565 } catch (Exception e) {
1566 throw logAndConvert(e);
1567 }
1568 }
1569
1570 /**
1571 * Updates a column in the current or insert row.
1572 *
1573 * @param columnLabel the column label
1574 * @param x the value
1575 * @throws SQLException if the result set is closed or not updatable
1576 */
1577 public void updateString(String columnLabel, String x) throws SQLException {
1578 try {
1579 if (isDebugEnabled()) {
1580 debugCode("updateString("+quote(columnLabel)+", "+quote(x)+");");
1581 }
1582 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueString.get(x));
1583 } catch (Exception e) {
1584 throw logAndConvert(e);
1585 }
1586 }
1587
1588 /**
1589 * Updates a column in the current or insert row.
1590 *
1591 * @param columnIndex (1,2,...)
1592 * @param x the value
1593 * @throws SQLException if the result set is closed or not updatable
1594 */
1595 public void updateDate(int columnIndex, Date x) throws SQLException {
1596 try {
1597 if (isDebugEnabled()) {
1598 debugCode("updateDate("+columnIndex+", x);");
1599 }
1600 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x));
1601 } catch (Exception e) {
1602 throw logAndConvert(e);
1603 }
1604 }
1605
1606 /**
1607 * Updates a column in the current or insert row.
1608 *
1609 * @param columnLabel the column label
1610 * @param x the value
1611 * @throws SQLException if the result set is closed or not updatable
1612 */
1613 public void updateDate(String columnLabel, Date x) throws SQLException {
1614 try {
1615 if (isDebugEnabled()) {
1616 debugCode("updateDate("+quote(columnLabel)+", x);");
1617 }
1618 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueDate.get(x));
1619 } catch (Exception e) {
1620 throw logAndConvert(e);
1621 }
1622 }
1623
1624 /**
1625 * Updates a column in the current or insert row.
1626 *
1627 * @param columnIndex (1,2,...)
1628 * @param x the value
1629 * @throws SQLException if the result set is closed or not updatable
1630 */
1631 public void updateTime(int columnIndex, Time x) throws SQLException {
1632 try {
1633 if (isDebugEnabled()) {
1634 debugCode("updateTime("+columnIndex+", x);");
1635 }
1636 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x));
1637 } catch (Exception e) {
1638 throw logAndConvert(e);
1639 }
1640 }
1641
1642 /**
1643 * Updates a column in the current or insert row.
1644 *
1645 * @param columnLabel the column label
1646 * @param x the value
1647 * @throws SQLException if the result set is closed or not updatable
1648 */
1649 public void updateTime(String columnLabel, Time x) throws SQLException {
1650 try {
1651 if (isDebugEnabled()) {
1652 debugCode("updateTime("+quote(columnLabel)+", x);");
1653 }
1654 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTime.get(x));
1655 } catch (Exception e) {
1656 throw logAndConvert(e);
1657 }
1658 }
1659
1660 /**
1661 * Updates a column in the current or insert row.
1662 *
1663 * @param columnIndex (1,2,...)
1664 * @param x the value
1665 * @throws SQLException if the result set is closed or not updatable
1666 */
1667 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
1668 try {
1669 if (isDebugEnabled()) {
1670 debugCode("updateTimestamp("+columnIndex+", x);");
1671 }
1672 update(columnIndex, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x));
1673 } catch (Exception e) {
1674 throw logAndConvert(e);
1675 }
1676 }
1677
1678 /**
1679 * Updates a column in the current or insert row.
1680 *
1681 * @param columnLabel the column label
1682 * @param x the value
1683 * @throws SQLException if the result set is closed or not updatable
1684 */
1685 public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
1686 try {
1687 if (isDebugEnabled()) {
1688 debugCode("updateTimestamp("+quote(columnLabel)+", x);");
1689 }
1690 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE : ValueTimestamp.get(x));
1691 } catch (Exception e) {
1692 throw logAndConvert(e);
1693 }
1694 }
1695
1696 /**
1697 * Updates a column in the current or insert row.
1698 *
1699 * @param columnIndex (1,2,...)
1700 * @param x the value
1701 * @param length the number of characters
1702 * @throws SQLException if the result set is closed or not updatable
1703 */
1704 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
1705 updateAsciiStream(columnIndex, x, (long) length);
1706 }
1707
1708 /**
1709 * Updates a column in the current or insert row.
1710 *
1711 * @param columnIndex (1,2,...)
1712 * @param x the value
1713 * @throws SQLException if the result set is closed or not updatable
1714 */
1715 public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
1716 updateAsciiStream(columnIndex, x, -1);
1717 }
1718
1719 /**
1720 * Updates a column in the current or insert row.
1721 *
1722 * @param columnIndex (1,2,...)
1723 * @param x the value
1724 * @param length the number of characters
1725 * @throws SQLException if the result set is closed or not updatable
1726 */
1727 public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
1728 try {
1729 if (isDebugEnabled()) {
1730 debugCode("updateAsciiStream("+columnIndex+", x, "+length+"L);");
1731 }
1732 checkClosed();
1733 Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
1734 update(columnIndex, v);
1735 } catch (Exception e) {
1736 throw logAndConvert(e);
1737 }
1738 }
1739
1740 /**
1741 * Updates a column in the current or insert row.
1742 *
1743 * @param columnLabel the column label
1744 * @param x the value
1745 * @param length the number of characters
1746 * @throws SQLException if the result set is closed or not updatable
1747 */
1748 public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
1749 updateAsciiStream(columnLabel, x, (long) length);
1750 }
1751
1752 /**
1753 * Updates a column in the current or insert row.
1754 *
1755 * @param columnLabel the column label
1756 * @param x the value
1757 * @throws SQLException if the result set is closed
1758 */
1759 public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
1760 updateAsciiStream(columnLabel, x, -1);
1761 }
1762
1763 /**
1764 * Updates a column in the current or insert row.
1765 *
1766 * @param columnLabel the column label
1767 * @param x the value
1768 * @param length the number of characters
1769 * @throws SQLException if the result set is closed or not updatable
1770 */
1771 public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
1772 try {
1773 if (isDebugEnabled()) {
1774 debugCode("updateAsciiStream("+quote(columnLabel)+", x, "+length+"L);");
1775 }
1776 checkClosed();
1777 Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
1778 update(columnLabel, v);
1779 } catch (Exception e) {
1780 throw logAndConvert(e);
1781 }
1782 }
1783
1784 /**
1785 * Updates a column in the current or insert row.
1786 *
1787 * @param columnIndex (1,2,...)
1788 * @param x the value
1789 * @param length the number of characters
1790 * @throws SQLException if the result set is closed or not updatable
1791 */
1792 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
1793 updateBinaryStream(columnIndex, x, (long) length);
1794 }
1795
1796 /**
1797 * Updates a column in the current or insert row.
1798 *
1799 * @param columnIndex (1,2,...)
1800 * @param x the value
1801 * @throws SQLException if the result set is closed or not updatable
1802 */
1803 public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
1804 updateBinaryStream(columnIndex, x, -1);
1805 }
1806
1807 /**
1808 * Updates a column in the current or insert row.
1809 *
1810 * @param columnIndex (1,2,...)
1811 * @param x the value
1812 * @param length the number of characters
1813 * @throws SQLException if the result set is closed or not updatable
1814 */
1815 public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
1816 try {
1817 if (isDebugEnabled()) {
1818 debugCode("updateBinaryStream("+columnIndex+", x, "+length+"L);");
1819 }
1820 checkClosed();
1821 Value v = conn.createBlob(x, length);
1822 update(columnIndex, v);
1823 } catch (Exception e) {
1824 throw logAndConvert(e);
1825 }
1826 }
1827
1828 /**
1829 * Updates a column in the current or insert row.
1830 *
1831 * @param columnLabel the column label
1832 * @param x the value
1833 * @throws SQLException if the result set is closed or not updatable
1834 */
1835 public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
1836 updateBinaryStream(columnLabel, x, -1);
1837 }
1838
1839 /**
1840 * Updates a column in the current or insert row.
1841 *
1842 * @param columnLabel the column label
1843 * @param x the value
1844 * @param length the number of characters
1845 * @throws SQLException if the result set is closed or not updatable
1846 */
1847 public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
1848 updateBinaryStream(columnLabel, x, (long) length);
1849 }
1850
1851 /**
1852 * Updates a column in the current or insert row.
1853 *
1854 * @param columnLabel the column label
1855 * @param x the value
1856 * @param length the number of characters
1857 * @throws SQLException if the result set is closed or not updatable
1858 */
1859 public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
1860 try {
1861 if (isDebugEnabled()) {
1862 debugCode("updateBinaryStream("+quote(columnLabel)+", x, "+length+"L);");
1863 }
1864 checkClosed();
1865 Value v = conn.createBlob(x, length);
1866 update(columnLabel, v);
1867 } catch (Exception e) {
1868 throw logAndConvert(e);
1869 }
1870 }
1871
1872 /**
1873 * Updates a column in the current or insert row.
1874 *
1875 * @param columnIndex (1,2,...)
1876 * @param x the value
1877 * @param length the number of characters
1878 * @throws SQLException if the result set is closed or not updatable
1879 */
1880 public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
1881 try {
1882 if (isDebugEnabled()) {
1883 debugCode("updateCharacterStream("+columnIndex+", x, "+length+"L);");
1884 }
1885 checkClosed();
1886 Value v = conn.createClob(x, length);
1887 update(columnIndex, v);
1888 } catch (Exception e) {
1889 throw logAndConvert(e);
1890 }
1891 }
1892
1893 /**
1894 * Updates a column in the current or insert row.
1895 *
1896 * @param columnIndex (1,2,...)
1897 * @param x the value
1898 * @param length the number of characters
1899 * @throws SQLException if the result set is closed or not updatable
1900 */
1901 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
1902 updateCharacterStream(columnIndex, x, (long) length);
1903 }
1904
1905 /**
1906 * Updates a column in the current or insert row.
1907 *
1908 * @param columnIndex (1,2,...)
1909 * @param x the value
1910 * @throws SQLException if the result set is closed or not updatable
1911 */
1912 public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
1913 updateCharacterStream(columnIndex, x, -1);
1914 }
1915
1916 /**
1917 * Updates a column in the current or insert row.
1918 *
1919 * @param columnLabel the column label
1920 * @param x the value
1921 * @param length the number of characters
1922 * @throws SQLException if the result set is closed or not updatable
1923 */
1924 public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException {
1925 updateCharacterStream(columnLabel, x, (long) length);
1926 }
1927
1928 /**
1929 * Updates a column in the current or insert row.
1930 *
1931 * @param columnLabel the column label
1932 * @param x the value
1933 * @throws SQLException if the result set is closed or not updatable
1934 */
1935 public void updateCharacterStream(String columnLabel, Reader x) throws SQLException {
1936 updateCharacterStream(columnLabel, x, -1);
1937 }
1938
1939 /**
1940 * Updates a column in the current or insert row.
1941 *
1942 * @param columnLabel the column label
1943 * @param x the value
1944 * @param length the number of characters
1945 * @throws SQLException if the result set is closed or not updatable
1946 */
1947 public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
1948 try {
1949 if (isDebugEnabled()) {
1950 debugCode("updateCharacterStream("+quote(columnLabel)+", x, "+length+"L);");
1951 }
1952 checkClosed();
1953 Value v = conn.createClob(x, length);
1954 update(columnLabel, v);
1955 } catch (Exception e) {
1956 throw logAndConvert(e);
1957 }
1958 }
1959
1960 /**
1961 * Updates a column in the current or insert row.
1962 *
1963 * @param columnIndex (1,2,...)
1964 * @param x the value
1965 * @param scale is ignored
1966 * @throws SQLException if the result set is closed or not updatable
1967 */
1968 public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
1969 try {
1970 if (isDebugEnabled()) {
1971 debugCode("updateObject("+columnIndex+", x, "+scale+");");
1972 }
1973 update(columnIndex, convertToUnknownValue(x));
1974 } catch (Exception e) {
1975 throw logAndConvert(e);
1976 }
1977 }
1978
1979
1980
1981 /**
1982 * Updates a column in the current or insert row.
1983 *
1984 * @param columnLabel the column label
1985 * @param x the value
1986 * @param scale is ignored
1987 * @throws SQLException if the result set is closed or not updatable
1988 */
1989 public void updateObject(String columnLabel, Object x, int scale) throws SQLException {
1990 try {
1991 if (isDebugEnabled()) {
1992 debugCode("updateObject("+quote(columnLabel)+", x, "+scale+");");
1993 }
1994 update(columnLabel, convertToUnknownValue(x));
1995 } catch (Exception e) {
1996 throw logAndConvert(e);
1997 }
1998 }
1999
2000 /**
2001 * Updates a column in the current or insert row.
2002 *
2003 * @param columnIndex (1,2,...)
2004 * @param x the value
2005 * @throws SQLException if the result set is closed or not updatable
2006 */
2007 public void updateObject(int columnIndex, Object x) throws SQLException {
2008 try {
2009 if (isDebugEnabled()) {
2010 debugCode("updateObject("+columnIndex+", x);");
2011 }
2012 update(columnIndex, convertToUnknownValue(x));
2013 } catch (Exception e) {
2014 throw logAndConvert(e);
2015 }
2016 }
2017
2018 /**
2019 * Updates a column in the current or insert row.
2020 *
2021 * @param columnLabel the column label
2022 * @param x the value
2023 * @throws SQLException if the result set is closed or not updatable
2024 */
2025 public void updateObject(String columnLabel, Object x) throws SQLException {
2026 try {
2027 if (isDebugEnabled()) {
2028 debugCode("updateObject("+quote(columnLabel)+", x);");
2029 }
2030 update(columnLabel, convertToUnknownValue(x));
2031 } catch (Exception e) {
2032 throw logAndConvert(e);
2033 }
2034 }
2035
2036 /**
2037 * [Not supported]
2038 */
2039 public void updateRef(int columnIndex, Ref x) throws SQLException {
2040 throw unsupported("ref");
2041 }
2042
2043 /**
2044 * [Not supported]
2045 */
2046 public void updateRef(String columnLabel, Ref x) throws SQLException {
2047 throw unsupported("ref");
2048 }
2049
2050 /**
2051 * Updates a column in the current or insert row.
2052 *
2053 * @param columnIndex (1,2,...)
2054 * @param x the value
2055 * @throws SQLException if the result set is closed or not updatable
2056 */
2057 public void updateBlob(int columnIndex, InputStream x) throws SQLException {
2058 updateBlob(columnIndex, x, -1);
2059 }
2060
2061 /**
2062 * Updates a column in the current or insert row.
2063 *
2064 * @param columnIndex (1,2,...)
2065 * @param x the value
2066 * @param length the length
2067 * @throws SQLException if the result set is closed or not updatable
2068 */
2069 public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException {
2070 try {
2071 if (isDebugEnabled()) {
2072 debugCode("updateBlob("+columnIndex+", x, " + length + "L);");
2073 }
2074 checkClosed();
2075 Value v = conn.createBlob(x, length);
2076 update(columnIndex, v);
2077 } catch (Exception e) {
2078 throw logAndConvert(e);
2079 }
2080 }
2081
2082 /**
2083 * Updates a column in the current or insert row.
2084 *
2085 * @param columnIndex (1,2,...)
2086 * @param x the value
2087 * @throws SQLException if the result set is closed or not updatable
2088 */
2089 public void updateBlob(int columnIndex, Blob x) throws SQLException {
2090 try {
2091 if (isDebugEnabled()) {
2092 debugCode("updateBlob("+columnIndex+", x);");
2093 }
2094 checkClosed();
2095 Value v;
2096 if (x == null) {
2097 v = ValueNull.INSTANCE;
2098 } else {
2099 v = conn.createBlob(x.getBinaryStream(), -1);
2100 }
2101 update(columnIndex, v);
2102 } catch (Exception e) {
2103 throw logAndConvert(e);
2104 }
2105 }
2106
2107 /**
2108 * Updates a column in the current or insert row.
2109 *
2110 * @param columnLabel the column label
2111 * @param x the value
2112 * @throws SQLException if the result set is closed or not updatable
2113 */
2114 public void updateBlob(String columnLabel, Blob x) throws SQLException {
2115 try {
2116 if (isDebugEnabled()) {
2117 debugCode("updateBlob("+quote(columnLabel)+", x);");
2118 }
2119 checkClosed();
2120 Value v;
2121 if (x == null) {
2122 v = ValueNull.INSTANCE;
2123 } else {
2124 v = conn.createBlob(x.getBinaryStream(), -1);
2125 }
2126 update(columnLabel, v);
2127 } catch (Exception e) {
2128 throw logAndConvert(e);
2129 }
2130 }
2131
2132 /**
2133 * Updates a column in the current or insert row.
2134 *
2135 * @param columnLabel the column label
2136 * @param x the value
2137 * @throws SQLException if the result set is closed or not updatable
2138 */
2139 public void updateBlob(String columnLabel, InputStream x) throws SQLException {
2140 updateBlob(columnLabel, x, -1);
2141 }
2142
2143 /**
2144 * Updates a column in the current or insert row.
2145 *
2146 * @param columnLabel the column label
2147 * @param x the value
2148 * @param length the length
2149 * @throws SQLException if the result set is closed or not updatable
2150 */
2151 public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException {
2152 try {
2153 if (isDebugEnabled()) {
2154 debugCode("updateBlob("+quote(columnLabel)+", x, " + length + "L);");
2155 }
2156 checkClosed();
2157 Value v = conn.createBlob(x, -1);
2158 update(columnLabel, v);
2159 } catch (Exception e) {
2160 throw logAndConvert(e);
2161 }
2162 }
2163
2164 /**
2165 * Updates a column in the current or insert row.
2166 *
2167 * @param columnIndex (1,2,...)
2168 * @param x the value
2169 * @throws SQLException if the result set is closed or not updatable
2170 */
2171 public void updateClob(int columnIndex, Clob x) throws SQLException {
2172 try {
2173 if (isDebugEnabled()) {
2174 debugCode("updateClob("+columnIndex+", x);");
2175 }
2176 checkClosed();
2177 Value v;
2178 if (x == null) {
2179 v = ValueNull.INSTANCE;
2180 } else {
2181 v = conn.createClob(x.getCharacterStream(), -1);
2182 }
2183 update(columnIndex, v);
2184 } catch (Exception e) {
2185 throw logAndConvert(e);
2186 }
2187 }
2188
2189 /**
2190 * Updates a column in the current or insert row.
2191 *
2192 * @param columnIndex (1,2,...)
2193 * @param x the value
2194 * @throws SQLException if the result set is closed or not updatable
2195 */
2196 public void updateClob(int columnIndex, Reader x) throws SQLException {
2197 updateClob(columnIndex, x, -1);
2198 }
2199
2200 /**
2201 * Updates a column in the current or insert row.
2202 *
2203 * @param columnIndex (1,2,...)
2204 * @param x the value
2205 * @param length the length
2206 * @throws SQLException if the result set is closed or not updatable
2207 */
2208 public void updateClob(int columnIndex, Reader x, long length) throws SQLException {
2209 try {
2210 if (isDebugEnabled()) {
2211 debugCode("updateClob("+columnIndex+", x, " + length + "L);");
2212 }
2213 checkClosed();
2214 Value v = conn.createClob(x, length);
2215 update(columnIndex, v);
2216 } catch (Exception e) {
2217 throw logAndConvert(e);
2218 }
2219 }
2220
2221 /**
2222 * Updates a column in the current or insert row.
2223 *
2224 * @param columnLabel the column label
2225 * @param x the value
2226 * @throws SQLException if the result set is closed or not updatable
2227 */
2228 public void updateClob(String columnLabel, Clob x) throws SQLException {
2229 try {
2230 if (isDebugEnabled()) {
2231 debugCode("updateClob("+quote(columnLabel)+", x);");
2232 }
2233 checkClosed();
2234 Value v;
2235 if (x == null) {
2236 v = ValueNull.INSTANCE;
2237 } else {
2238 v = conn.createClob(x.getCharacterStream(), -1);
2239 }
2240 update(columnLabel, v);
2241 } catch (Exception e) {
2242 throw logAndConvert(e);
2243 }
2244 }
2245
2246 /**
2247 * Updates a column in the current or insert row.
2248 *
2249 * @param columnLabel the column label
2250 * @param x the value
2251 * @throws SQLException if the result set is closed or not updatable
2252 */
2253 public void updateClob(String columnLabel, Reader x) throws SQLException {
2254 updateClob(columnLabel, x, -1);
2255 }
2256
2257 /**
2258 * Updates a column in the current or insert row.
2259 *
2260 * @param columnLabel the column label
2261 * @param x the value
2262 * @param length the length
2263 * @throws SQLException if the result set is closed or not updatable
2264 */
2265 public void updateClob(String columnLabel, Reader x, long length) throws SQLException {
2266 try {
2267 if (isDebugEnabled()) {
2268 debugCode("updateClob("+quote(columnLabel)+", x, " + length + "L);");
2269 }
2270 checkClosed();
2271 Value v = conn.createClob(x, length);
2272 update(columnLabel, v);
2273 } catch (Exception e) {
2274 throw logAndConvert(e);
2275 }
2276 }
2277
2278 /**
2279 * [Not supported]
2280 */
2281 public void updateArray(int columnIndex, Array x) throws SQLException {
2282 throw unsupported("setArray");
2283 }
2284
2285 /**
2286 * [Not supported]
2287 */
2288 public void updateArray(String columnLabel, Array x) throws SQLException {
2289 throw unsupported("setArray");
2290 }
2291
2292 /**
2293 * [Not supported] Gets the cursor name if it was defined. This feature is
2294 * superseded by updateX methods. This method throws a SQLException because
2295 * cursor names are not supported.
2296 */
2297 public String getCursorName() throws SQLException {
2298 throw unsupported("cursorName");
2299 }
2300
2301 /**
2302 * Gets the current row number. The first row is row 1, the second 2 and so
2303 * on. This method returns 0 before the first and after the last row.
2304 *
2305 * @return the row number
2306 */
2307 public int getRow() throws SQLException {
2308 try {
2309 debugCodeCall("getRow");
2310 checkClosed();
2311 int rowId = result.getRowId();
2312 if (rowId >= result.getRowCount()) {
2313 return 0;
2314 }
2315 return rowId + 1;
2316 } catch (Exception e) {
2317 throw logAndConvert(e);
2318 }
2319 }
2320
2321 /**
2322 * Gets the result set concurrency. Result sets are only updatable if the
2323 * statement was created with updatable concurrency, and if the result set
2324 * contains all columns of the primary key or of a unique index of a table.
2325 *
2326 * @return ResultSet.CONCUR_UPDATABLE if the result set is updatable, or
2327 * ResultSet.CONCUR_READ_ONLY otherwise
2328 */
2329 public int getConcurrency() throws SQLException {
2330 try {
2331 debugCodeCall("getConcurrency");
2332 checkClosed();
2333 if (!updatable) {
2334 return ResultSet.CONCUR_READ_ONLY;
2335 }
2336 UpdatableRow row = new UpdatableRow(conn, result);
2337 return row.isUpdatable() ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY;
2338 } catch (Exception e) {
2339 throw logAndConvert(e);
2340 }
2341 }
2342
2343 /**
2344 * Gets the fetch direction.
2345 *
2346 * @return the direction: FETCH_FORWARD
2347 */
2348 public int getFetchDirection() throws SQLException {
2349 try {
2350 debugCodeCall("getFetchDirection");
2351 checkClosed();
2352 return ResultSet.FETCH_FORWARD;
2353 } catch (Exception e) {
2354 throw logAndConvert(e);
2355 }
2356 }
2357
2358 /**
2359 * Gets the number of rows suggested to read in one step.
2360 *
2361 * @return the current fetch size
2362 */
2363 public int getFetchSize() throws SQLException {
2364 try {
2365 debugCodeCall("getFetchSize");
2366 checkClosed();
2367 return result.getFetchSize();
2368 } catch (Exception e) {
2369 throw logAndConvert(e);
2370 }
2371 }
2372
2373 /**
2374 * Sets the number of rows suggested to read in one step. This value cannot
2375 * be higher than the maximum rows (setMaxRows) set by the statement or
2376 * prepared statement, otherwise an exception is throws. Setting the value
2377 * to 0 will set the default value. The default value can be changed using
2378 * the system property h2.serverResultSetFetchSize.
2379 *
2380 * @param rows the number of rows
2381 */
2382 public void setFetchSize(int rows) throws SQLException {
2383 try {
2384 debugCodeCall("setFetchSize", rows);
2385 checkClosed();
2386 if (rows < 0) {
2387 throw DbException.getInvalidValueException("rows", rows);
2388 } else if (rows > 0) {
2389 if (stat != null) {
2390 int maxRows = stat.getMaxRows();
2391 if (maxRows > 0 && rows > maxRows) {
2392 throw DbException.getInvalidValueException("rows", rows);
2393 }
2394 }
2395 } else {
2396 rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE;
2397 }
2398 result.setFetchSize(rows);
2399 } catch (Exception e) {
2400 throw logAndConvert(e);
2401 }
2402 }
2403
2404 /**
2405 * [Not supported]
2406 * Sets (changes) the fetch direction for this result set. This method
2407 * should only be called for scrollable result sets, otherwise it will throw
2408 * an exception (no matter what direction is used).
2409 *
2410 * @param direction the new fetch direction
2411 * @throws SQLException Unsupported Feature if the method is called for a
2412 * forward-only result set
2413 */
2414 public void setFetchDirection(int direction) throws SQLException {
2415 throw unsupported("setFetchDirection");
2416 }
2417
2418 /**
2419 * Get the result set type.
2420 *
2421 * @return the result set type (TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE
2422 * or TYPE_SCROLL_SENSITIVE)
2423 * @throws SQLException if the column is not found or if the result set is
2424 * closed
2425 */
2426 public int getType() throws SQLException {
2427 try {
2428 debugCodeCall("getType");
2429 checkClosed();
2430 return stat == null ? ResultSet.TYPE_FORWARD_ONLY : stat.resultSetType;
2431 } catch (Exception e) {
2432 throw logAndConvert(e);
2433 }
2434 }
2435
2436 /**
2437 * Checks if the current position is before the first row, that means next()
2438 * was not called yet, and there is at least one row.
2439 *
2440 * @return if there are results and the current position is before the first row
2441 * @throws SQLException if the result set is closed
2442 */
2443 public boolean isBeforeFirst() throws SQLException {
2444 try {
2445 debugCodeCall("isBeforeFirst");
2446 checkClosed();
2447 int row = result.getRowId();
2448 int count = result.getRowCount();
2449 return count > 0 && row < 0;
2450 } catch (Exception e) {
2451 throw logAndConvert(e);
2452 }
2453 }
2454
2455 /**
2456 * Checks if the current position is after the last row, that means next()
2457 * was called and returned false, and there was at least one row.
2458 *
2459 * @return if there are results and the current position is after the last row
2460 * @throws SQLException if the result set is closed
2461 */
2462 public boolean isAfterLast() throws SQLException {
2463 try {
2464 debugCodeCall("isAfterLast");
2465 checkClosed();
2466 int row = result.getRowId();
2467 int count = result.getRowCount();
2468 return count > 0 && row >= count;
2469 } catch (Exception e) {
2470 throw logAndConvert(e);
2471 }
2472 }
2473
2474 /**
2475 * Checks if the current position is row 1, that means next() was called
2476 * once and returned true.
2477 *
2478 * @return if the current position is the first row
2479 * @throws SQLException if the result set is closed
2480 */
2481 public boolean isFirst() throws SQLException {
2482 try {
2483 debugCodeCall("isFirst");
2484 checkClosed();
2485 int row = result.getRowId();
2486 return row == 0 && row < result.getRowCount();
2487 } catch (Exception e) {
2488 throw logAndConvert(e);
2489 }
2490 }
2491
2492 /**
2493 * Checks if the current position is the last row, that means next() was
2494 * called and did not yet returned false, but will in the next call.
2495 *
2496 * @return if the current position is the last row
2497 * @throws SQLException if the result set is closed
2498 */
2499 public boolean isLast() throws SQLException {
2500 try {
2501 debugCodeCall("isLast");
2502 checkClosed();
2503 int row = result.getRowId();
2504 return row >= 0 && row == result.getRowCount() - 1;
2505 } catch (Exception e) {
2506 throw logAndConvert(e);
2507 }
2508 }
2509
2510 /**
2511 * Moves the current position to before the first row, that means resets the
2512 * result set.
2513 *
2514 * @throws SQLException if the result set is closed
2515 */
2516 public void beforeFirst() throws SQLException {
2517 try {
2518 debugCodeCall("beforeFirst");
2519 checkClosed();
2520 if (result.getRowId() >= 0) {
2521 resetResult();
2522 }
2523 } catch (Exception e) {
2524 throw logAndConvert(e);
2525 }
2526 }
2527
2528 /**
2529 * Moves the current position to after the last row, that means after the end.
2530 *
2531 * @throws SQLException if the result set is closed
2532 */
2533 public void afterLast() throws SQLException {
2534 try {
2535 debugCodeCall("afterLast");
2536 checkClosed();
2537 while (nextRow()) {
2538 // nothing
2539 }
2540 } catch (Exception e) {
2541 throw logAndConvert(e);
2542 }
2543 }
2544
2545 /**
2546 * Moves the current position to the first row. This is the same as calling
2547 * beforeFirst() followed by next().
2548 *
2549 * @return true if there is a row available, false if not
2550 * @throws SQLException if the result set is closed
2551 */
2552 public boolean first() throws SQLException {
2553 try {
2554 debugCodeCall("first");
2555 checkClosed();
2556 if (result.getRowId() < 0) {
2557 return nextRow();
2558 }
2559 resetResult();
2560 return nextRow();
2561 } catch (Exception e) {
2562 throw logAndConvert(e);
2563 }
2564 }
2565
2566 /**
2567 * Moves the current position to the last row.
2568 *
2569 * @return true if there is a row available, false if not
2570 * @throws SQLException if the result set is closed
2571 */
2572 public boolean last() throws SQLException {
2573 try {
2574 debugCodeCall("last");
2575 checkClosed();
2576 return absolute(-1);
2577 } catch (Exception e) {
2578 throw logAndConvert(e);
2579 }
2580 }
2581
2582 /**
2583 * Moves the current position to a specific row.
2584 *
2585 * @param rowNumber the row number. 0 is not allowed, 1 means the first row,
2586 * 2 the second. -1 means the last row, -2 the row before the
2587 * last row. If the value is too large, the position is moved
2588 * after the last row, if if the value is too small it is moved
2589 * before the first row.
2590 * @return true if there is a row available, false if not
2591 * @throws SQLException if the result set is closed
2592 */
2593 public boolean absolute(int rowNumber) throws SQLException {
2594 try {
2595 debugCodeCall("absolute", rowNumber);
2596 checkClosed();
2597 if (rowNumber < 0) {
2598 rowNumber = result.getRowCount() + rowNumber + 1;
2599 } else if (rowNumber > result.getRowCount() + 1) {
2600 rowNumber = result.getRowCount() + 1;
2601 }
2602 if (rowNumber <= result.getRowId()) {
2603 resetResult();
2604 }
2605 while (result.getRowId() + 1 < rowNumber) {
2606 nextRow();
2607 }
2608 int row = result.getRowId();
2609 return row >= 0 && row < result.getRowCount();
2610 } catch (Exception e) {
2611 throw logAndConvert(e);
2612 }
2613 }
2614
2615 /**
2616 * Moves the current position to a specific row relative to the current row.
2617 *
2618 * @param rowCount 0 means don't do anything, 1 is the next row, -1 the
2619 * previous. If the value is too large, the position is moved
2620 * after the last row, if if the value is too small it is moved
2621 * before the first row.
2622 * @return true if there is a row available, false if not
2623 * @throws SQLException if the result set is closed
2624 */
2625 public boolean relative(int rowCount) throws SQLException {
2626 try {
2627 debugCodeCall("relative", rowCount);
2628 checkClosed();
2629 int row = result.getRowId() + 1 + rowCount;
2630 if (row < 0) {
2631 row = 0;
2632 } else if (row > result.getRowCount()) {
2633 row = result.getRowCount() + 1;
2634 }
2635 return absolute(row);
2636 } catch (Exception e) {
2637 throw logAndConvert(e);
2638 }
2639 }
2640
2641 /**
2642 * Moves the cursor to the last row, or row before first row if the current
2643 * position is the first row.
2644 *
2645 * @return true if there is a row available, false if not
2646 * @throws SQLException if the result set is closed
2647 */
2648 public boolean previous() throws SQLException {
2649 try {
2650 debugCodeCall("previous");
2651 checkClosed();
2652 return relative(-1);
2653 } catch (Exception e) {
2654 throw logAndConvert(e);
2655 }
2656 }
2657
2658 /**
2659 * Moves the current position to the insert row. The current row is remembered.
2660 *
2661 * @throws SQLException if the result set is closed or is not updatable
2662 */
2663 public void moveToInsertRow() throws SQLException {
2664 try {
2665 debugCodeCall("moveToInsertRow");
2666 checkUpdatable();
2667 insertRow = new Value[columnCount];
2668 } catch (Exception e) {
2669 throw logAndConvert(e);
2670 }
2671 }
2672
2673 /**
2674 * Moves the current position to the current row.
2675 *
2676 * @throws SQLException if the result set is closed or is not updatable
2677 */
2678 public void moveToCurrentRow() throws SQLException {
2679 try {
2680 debugCodeCall("moveToCurrentRow");
2681 checkUpdatable();
2682 insertRow = null;
2683 } catch (Exception e) {
2684 throw logAndConvert(e);
2685 }
2686 }
2687
2688 /**
2689 * Detects if the row was updated (by somebody else or the caller).
2690 *
2691 * @return false because this driver does not detect this
2692 */
2693 public boolean rowUpdated() throws SQLException {
2694 try {
2695 debugCodeCall("rowUpdated");
2696 return false;
2697 } catch (Exception e) {
2698 throw logAndConvert(e);
2699 }
2700 }
2701
2702 /**
2703 * Detects if the row was inserted.
2704 *
2705 * @return false because this driver does not detect this
2706 */
2707 public boolean rowInserted() throws SQLException {
2708 try {
2709 debugCodeCall("rowInserted");
2710 return false;
2711 } catch (Exception e) {
2712 throw logAndConvert(e);
2713 }
2714 }
2715
2716 /**
2717 * Detects if the row was deleted (by somebody else or the caller).
2718 *
2719 * @return false because this driver does not detect this
2720 */
2721 public boolean rowDeleted() throws SQLException {
2722 try {
2723 debugCodeCall("rowDeleted");
2724 return false;
2725 } catch (Exception e) {
2726 throw logAndConvert(e);
2727 }
2728 }
2729
2730 /**
2731 * Inserts the current row. The current position must be the insert row.
2732 *
2733 * @throws SQLException if the result set is closed or if not on the insert
2734 * row, or if the result set it not updatable
2735 */
2736 public void insertRow() throws SQLException {
2737 try {
2738 debugCodeCall("insertRow");
2739 checkUpdatable();
2740 if (insertRow == null) {
2741 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
2742 }
2743 getUpdatableRow().insertRow(insertRow);
2744 insertRow = null;
2745 } catch (Exception e) {
2746 throw logAndConvert(e);
2747 }
2748 }
2749
2750 /**
2751 * Updates the current row.
2752 *
2753 * @throws SQLException if the result set is closed, if the current row is
2754 * the insert row or if not on a valid row, or if the result set
2755 * it not updatable
2756 */
2757 public void updateRow() throws SQLException {
2758 try {
2759 debugCodeCall("updateRow");
2760 checkUpdatable();
2761 if (insertRow != null) {
2762 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
2763 }
2764 checkOnValidRow();
2765 if (updateRow != null) {
2766 UpdatableRow row = getUpdatableRow();
2767 Value[] current = new Value[columnCount];
2768 for (int i = 0; i < updateRow.length; i++) {
2769 current[i] = get(i + 1);
2770 }
2771 row.updateRow(current, updateRow);
2772 for (int i = 0; i < updateRow.length; i++) {
2773 if (updateRow[i] == null) {
2774 updateRow[i] = current[i];
2775 }
2776 }
2777 Value[] patch = row.readRow(updateRow);
2778 patchCurrentRow(patch);
2779 updateRow = null;
2780 }
2781 } catch (Exception e) {
2782 throw logAndConvert(e);
2783 }
2784 }
2785
2786 /**
2787 * Deletes the current row.
2788 *
2789 * @throws SQLException if the result set is closed, if the current row is
2790 * the insert row or if not on a valid row, or if the result set
2791 * it not updatable
2792 */
2793 public void deleteRow() throws SQLException {
2794 try {
2795 debugCodeCall("deleteRow");
2796 checkUpdatable();
2797 if (insertRow != null) {
2798 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
2799 }
2800 checkOnValidRow();
2801 getUpdatableRow().deleteRow(result.currentRow());
2802 updateRow = null;
2803 } catch (Exception e) {
2804 throw logAndConvert(e);
2805 }
2806 }
2807
2808 /**
2809 * Re-reads the current row from the database.
2810 *
2811 * @throws SQLException if the result set is closed or if the current row is
2812 * the insert row or if the row has been deleted or if not on a
2813 * valid row
2814 */
2815 public void refreshRow() throws SQLException {
2816 try {
2817 debugCodeCall("refreshRow");
2818 checkClosed();
2819 if (insertRow != null) {
2820 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
2821 }
2822 checkOnValidRow();
2823 patchCurrentRow(getUpdatableRow().readRow(result.currentRow()));
2824 updateRow = null;
2825 } catch (Exception e) {
2826 throw logAndConvert(e);
2827 }
2828 }
2829
2830 /**
2831 * Cancels updating a row.
2832 *
2833 * @throws SQLException if the result set is closed or if the current row is
2834 * the insert row
2835 */
2836 public void cancelRowUpdates() throws SQLException {
2837 try {
2838 debugCodeCall("cancelRowUpdates");
2839 checkClosed();
2840 if (insertRow != null) {
2841 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
2842 }
2843 updateRow = null;
2844 } catch (Exception e) {
2845 throw logAndConvert(e);
2846 }
2847 }
2848
2849 // =============================================================
2850
2851 private UpdatableRow getUpdatableRow() throws SQLException {
2852 UpdatableRow row = new UpdatableRow(conn, result);
2853 if (!row.isUpdatable()) {
2854 throw DbException.get(ErrorCode.RESULT_SET_NOT_UPDATABLE);
2855 }
2856 return row;
2857 }
2858
2859 private int getColumnIndex(String columnLabel) {
2860 checkClosed();
2861 if (columnLabel == null) {
2862 throw DbException.getInvalidValueException("columnLabel", null);
2863 }
2864 if (columnCount >= 3) {
2865 // use a hash table if more than 2 columns
2866 if (columnLabelMap == null) {
2867 HashMap<String, Integer> map = New.hashMap(columnCount);
2868 // column labels have higher priority
2869 for (int i = 0; i < columnCount; i++) {
2870 String c = StringUtils.toUpperEnglish(result.getAlias(i));
2871 mapColumn(map, c, i);
2872 }
2873 for (int i = 0; i < columnCount; i++) {
2874 String colName = result.getColumnName(i);
2875 if (colName != null) {
2876 colName = StringUtils.toUpperEnglish(colName);
2877 mapColumn(map, colName, i);
2878 String tabName = result.getTableName(i);
2879 if (tabName != null) {
2880 colName = StringUtils.toUpperEnglish(tabName) + "." + colName;
2881 mapColumn(map, colName, i);
2882 }
2883 }
2884 }
2885 // assign at the end so concurrent access is supported
2886 columnLabelMap = map;
2887 if (preparedStatement != null) {
2888 preparedStatement.setCachedColumnLabelMap(columnLabelMap);
2889 }
2890 }
2891 Integer index = columnLabelMap.get(StringUtils.toUpperEnglish(columnLabel));
2892 if (index == null) {
2893 throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
2894 }
2895 return index.intValue() + 1;
2896 }
2897 for (int i = 0; i < columnCount; i++) {
2898 if (columnLabel.equalsIgnoreCase(result.getAlias(i))) {
2899 return i + 1;
2900 }
2901 }
2902 int idx = columnLabel.indexOf('.');
2903 if (idx > 0) {
2904 String table = columnLabel.substring(0, idx);
2905 String col = columnLabel.substring(idx+1);
2906 for (int i = 0; i < columnCount; i++) {
2907 if (table.equalsIgnoreCase(result.getTableName(i)) && col.equalsIgnoreCase(result.getColumnName(i))) {
2908 return i + 1;
2909 }
2910 }
2911 } else {
2912 for (int i = 0; i < columnCount; i++) {
2913 if (columnLabel.equalsIgnoreCase(result.getColumnName(i))) {
2914 return i + 1;
2915 }
2916 }
2917 }
2918 throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
2919 }
2920
2921 private static void mapColumn(HashMap<String, Integer> map, String label, int index) {
2922 // put the index (usually that's the only operation)
2923 Integer old = map.put(label, index);
2924 if (old != null) {
2925 // if there was a clash (which is seldom),
2926 // put the old one back
2927 map.put(label, old);
2928 }
2929 }
2930
2931 private void checkColumnIndex(int columnIndex) {
2932 checkClosed();
2933 if (columnIndex < 1 || columnIndex > columnCount) {
2934 throw DbException.getInvalidValueException("columnIndex", columnIndex);
2935 }
2936 }
2937
2938 /**
2939 * Check if this result set is closed.
2940 *
2941 * @throws DbException if it is closed
2942 */
2943 void checkClosed() {
2944 if (result == null) {
2945 throw DbException.get(ErrorCode.OBJECT_CLOSED);
2946 }
2947 if (stat != null) {
2948 stat.checkClosed();
2949 }
2950 if (conn != null) {
2951 conn.checkClosed();
2952 }
2953 }
2954
2955 private void checkOnValidRow() {
2956 if (result.getRowId() < 0 || result.getRowId() >= result.getRowCount()) {
2957 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
2958 }
2959 }
2960
2961 private Value get(int columnIndex) {
2962 checkColumnIndex(columnIndex);
2963 checkOnValidRow();
2964 Value[] list;
2965 if (patchedRows == null) {
2966 list = result.currentRow();
2967 } else {
2968 list = patchedRows.get(result.getRowId());
2969 if (list == null) {
2970 list = result.currentRow();
2971 }
2972 }
2973 Value value = list[columnIndex - 1];
2974 wasNull = value == ValueNull.INSTANCE;
2975 return value;
2976 }
2977
2978 private Value get(String columnLabel) {
2979 int columnIndex = getColumnIndex(columnLabel);
2980 return get(columnIndex);
2981 }
2982
2983 private void update(String columnLabel, Value v) {
2984 int columnIndex = getColumnIndex(columnLabel);
2985 update(columnIndex, v);
2986 }
2987
2988 private void update(int columnIndex, Value v) {
2989 checkUpdatable();
2990 checkColumnIndex(columnIndex);
2991 if (insertRow != null) {
2992 insertRow[columnIndex - 1] = v;
2993 } else {
2994 if (updateRow == null) {
2995 updateRow = new Value[columnCount];
2996 }
2997 updateRow[columnIndex - 1] = v;
2998 }
2999 }
3000
3001 private boolean nextRow() {
3002 boolean next = result.next();
3003 if (!next && !scrollable) {
3004 result.close();
3005 }
3006 return next;
3007 }
3008
3009 private void resetResult() {
3010 if (!scrollable) {
3011 throw DbException.get(ErrorCode.RESULT_SET_NOT_SCROLLABLE);
3012 }
3013 result.reset();
3014 }
3015
3016 /**
3017 * [Not supported] Returns the value of the specified column as a row id.
3018 *
3019 * @param columnIndex (1,2,...)
3020 */
3021 //## Java 1.6 ##
3022 public RowId getRowId(int columnIndex) throws SQLException {
3023 throw unsupported("rowId");
3024 }
3025 //*/
3026
3027 /**
3028 * [Not supported] Returns the value of the specified column as a row id.
3029 *
3030 * @param columnLabel the column label
3031 */
3032 //## Java 1.6 ##
3033 public RowId getRowId(String columnLabel) throws SQLException {
3034 throw unsupported("rowId");
3035 }
3036 //*/
3037
3038 /**
3039 * [Not supported] Updates a column in the current or insert row.
3040 *
3041 * @param columnIndex (1,2,...)
3042 * @param x the value
3043 */
3044 //## Java 1.6 ##
3045 public void updateRowId(int columnIndex, RowId x) throws SQLException {
3046 throw unsupported("rowId");
3047 }
3048 //*/
3049
3050 /**
3051 * [Not supported] Updates a column in the current or insert row.
3052 *
3053 * @param columnLabel the column label
3054 * @param x the value
3055 */
3056 //## Java 1.6 ##
3057 public void updateRowId(String columnLabel, RowId x) throws SQLException {
3058 throw unsupported("rowId");
3059 }
3060 //*/
3061
3062 /**
3063 * Returns the current result set holdability.
3064 *
3065 * @return the holdability
3066 * @throws SQLException if the connection is closed
3067 */
3068 public int getHoldability() throws SQLException {
3069 try {
3070 debugCodeCall("getHoldability");
3071 checkClosed();
3072 return conn.getHoldability();
3073 } catch (Exception e) {
3074 throw logAndConvert(e);
3075 }
3076 }
3077
3078 /**
3079 * Returns whether this result set is closed.
3080 *
3081 * @return true if the result set is closed
3082 */
3083 public boolean isClosed() throws SQLException {
3084 try {
3085 debugCodeCall("isClosed");
3086 return result == null;
3087 } catch (Exception e) {
3088 throw logAndConvert(e);
3089 }
3090 }
3091
3092 /**
3093 * Updates a column in the current or insert row.
3094 *
3095 * @param columnIndex (1,2,...)
3096 * @param x the value
3097 * @throws SQLException if the result set is closed or not updatable
3098 */
3099 public void updateNString(int columnIndex, String x) throws SQLException {
3100 try {
3101 if (isDebugEnabled()) {
3102 debugCode("updateNString("+columnIndex+", "+quote(x)+");");
3103 }
3104 update(columnIndex, x == null ? (Value)
3105 ValueNull.INSTANCE : ValueString.get(x));
3106 } catch (Exception e) {
3107 throw logAndConvert(e);
3108 }
3109 }
3110
3111 /**
3112 * Updates a column in the current or insert row.
3113 *
3114 * @param columnLabel the column label
3115 * @param x the value
3116 * @throws SQLException if the result set is closed or not updatable
3117 */
3118 public void updateNString(String columnLabel, String x) throws SQLException {
3119 try {
3120 if (isDebugEnabled()) {
3121 debugCode("updateNString("+quote(columnLabel)+", "+quote(x)+");");
3122 }
3123 update(columnLabel, x == null ? (Value) ValueNull.INSTANCE :
3124 ValueString.get(x));
3125 } catch (Exception e) {
3126 throw logAndConvert(e);
3127 }
3128 }
3129
3130 /**
3131 * [Not supported]
3132 */
3133 //## Java 1.6 ##
3134 public void updateNClob(int columnIndex, NClob x) throws SQLException {
3135 throw unsupported("NClob");
3136 }
3137 //*/
3138
3139 /**
3140 * Updates a column in the current or insert row.
3141 *
3142 * @param columnIndex (1,2,...)
3143 * @param x the value
3144 * @throws SQLException if the result set is closed or not updatable
3145 */
3146 public void updateNClob(int columnIndex, Reader x) throws SQLException {
3147 updateClob(columnIndex, x, -1);
3148 }
3149
3150 /**
3151 * Updates a column in the current or insert row.
3152 *
3153 * @param columnIndex (1,2,...)
3154 * @param x the value
3155 * @param length the length
3156 * @throws SQLException if the result set is closed or not updatable
3157 */
3158 public void updateNClob(int columnIndex, Reader x, long length)
3159 throws SQLException {
3160 updateClob(columnIndex, x, length);
3161 }
3162
3163 /**
3164 * Updates a column in the current or insert row.
3165 *
3166 * @param columnLabel the column label
3167 * @param x the value
3168 * @throws SQLException if the result set is closed or not updatable
3169 */
3170 public void updateNClob(String columnLabel, Reader x) throws SQLException {
3171 updateClob(columnLabel, x, -1);
3172 }
3173
3174 /**
3175 * Updates a column in the current or insert row.
3176 *
3177 * @param columnLabel the column label
3178 * @param x the value
3179 * @param length the length
3180 * @throws SQLException if the result set is closed or not updatable
3181 */
3182 public void updateNClob(String columnLabel, Reader x, long length)
3183 throws SQLException {
3184 updateClob(columnLabel, x, length);
3185 }
3186
3187 /**
3188 * [Not supported]
3189 */
3190 //## Java 1.6 ##
3191 public void updateNClob(String columnLabel, NClob x) throws SQLException {
3192 throw unsupported("NClob");
3193 }
3194 //*/
3195
3196 /**
3197 * Returns the value of the specified column as a Clob.
3198 *
3199 * @param columnIndex (1,2,...)
3200 * @return the value
3201 * @throws SQLException if the column is not found or if the result set is closed
3202 */
3203 //## Java 1.6 ##
3204 public NClob getNClob(int columnIndex) throws SQLException {
3205 try {
3206 int id = getNextId(TraceObject.CLOB);
3207 debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnIndex + ")");
3208 Value v = get(columnIndex);
3209 return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
3210 } catch (Exception e) {
3211 throw logAndConvert(e);
3212 }
3213 }
3214 //*/
3215
3216 /**
3217 * Returns the value of the specified column as a Clob.
3218 *
3219 * @param columnLabel the column label
3220 * @return the value
3221 * @throws SQLException if the column is not found or if the result set is closed
3222 */
3223 //## Java 1.6 ##
3224 public NClob getNClob(String columnLabel) throws SQLException {
3225 try {
3226 int id = getNextId(TraceObject.CLOB);
3227 debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnLabel + ")");
3228 Value v = get(columnLabel);
3229 return v == ValueNull.INSTANCE ? null : new JdbcClob(conn, v, id);
3230 } catch (Exception e) {
3231 throw logAndConvert(e);
3232 }
3233 }
3234 //*/
3235
3236 /**
3237 * [Not supported] Returns the value of the specified column as a SQLXML object.
3238 */
3239 //## Java 1.6 ##
3240 public SQLXML getSQLXML(int columnIndex) throws SQLException {
3241 throw unsupported("SQLXML");
3242 }
3243 //*/
3244
3245 /**
3246 * [Not supported] Returns the value of the specified column as a SQLXML object.
3247 */
3248 //## Java 1.6 ##
3249 public SQLXML getSQLXML(String columnLabel) throws SQLException {
3250 throw unsupported("SQLXML");
3251 }
3252 //*/
3253
3254 /**
3255 * [Not supported] Updates a column in the current or insert row.
3256 */
3257 //## Java 1.6 ##
3258 public void updateSQLXML(int columnIndex, SQLXML xmlObject)
3259 throws SQLException {
3260 throw unsupported("SQLXML");
3261 }
3262 //*/
3263
3264 /**
3265 * [Not supported] Updates a column in the current or insert row.
3266 */
3267 //## Java 1.6 ##
3268 public void updateSQLXML(String columnLabel, SQLXML xmlObject)
3269 throws SQLException {
3270 throw unsupported("SQLXML");
3271 }
3272 //*/
3273
3274 /**
3275 * Returns the value of the specified column as a String.
3276 *
3277 * @param columnIndex (1,2,...)
3278 * @return the value
3279 * @throws SQLException if the column is not found or if the result set is
3280 * closed
3281 */
3282 public String getNString(int columnIndex) throws SQLException {
3283 try {
3284 debugCodeCall("getNString", columnIndex);
3285 return get(columnIndex).getString();
3286 } catch (Exception e) {
3287 throw logAndConvert(e);
3288 }
3289 }
3290
3291 /**
3292 * Returns the value of the specified column as a String.
3293 *
3294 * @param columnLabel the column label
3295 * @return the value
3296 * @throws SQLException if the column is not found or if the result set is
3297 * closed
3298 */
3299 public String getNString(String columnLabel) throws SQLException {
3300 try {
3301 debugCodeCall("getNString", columnLabel);
3302 return get(columnLabel).getString();
3303 } catch (Exception e) {
3304 throw logAndConvert(e);
3305 }
3306 }
3307
3308 /**
3309 * Returns the value of the specified column as a reader.
3310 *
3311 * @param columnIndex (1,2,...)
3312 * @return the value
3313 * @throws SQLException if the column is not found or if the result set is
3314 * closed
3315 */
3316 public Reader getNCharacterStream(int columnIndex) throws SQLException {
3317 try {
3318 debugCodeCall("getNCharacterStream", columnIndex);
3319 return get(columnIndex).getReader();
3320 } catch (Exception e) {
3321 throw logAndConvert(e);
3322 }
3323 }
3324
3325 /**
3326 * Returns the value of the specified column as a reader.
3327 *
3328 * @param columnLabel the column label
3329 * @return the value
3330 * @throws SQLException if the column is not found or if the result set is
3331 * closed
3332 */
3333 public Reader getNCharacterStream(String columnLabel) throws SQLException {
3334 try {
3335 debugCodeCall("getNCharacterStream", columnLabel);
3336 return get(columnLabel).getReader();
3337 } catch (Exception e) {
3338 throw logAndConvert(e);
3339 }
3340 }
3341
3342 /**
3343 * Updates a column in the current or insert row.
3344 *
3345 * @param columnIndex (1,2,...)
3346 * @param x the value
3347 * @throws SQLException if the result set is closed or not updatable
3348 */
3349 public void updateNCharacterStream(int columnIndex, Reader x)
3350 throws SQLException {
3351 updateNCharacterStream(columnIndex, x, -1);
3352 }
3353
3354 /**
3355 * Updates a column in the current or insert row.
3356 *
3357 * @param columnIndex (1,2,...)
3358 * @param x the value
3359 * @param length the number of characters
3360 * @throws SQLException if the result set is closed or not updatable
3361 */
3362 public void updateNCharacterStream(int columnIndex, Reader x, long length)
3363 throws SQLException {
3364 try {
3365 if (isDebugEnabled()) {
3366 debugCode("updateNCharacterStream("+columnIndex+", x, "+length+"L);");
3367 }
3368 checkClosed();
3369 Value v = conn.createClob(x, length);
3370 update(columnIndex, v);
3371 } catch (Exception e) {
3372 throw logAndConvert(e);
3373 }
3374 }
3375
3376 /**
3377 * Updates a column in the current or insert row.
3378 *
3379 * @param columnLabel the column label
3380 * @param x the value
3381 * @throws SQLException if the result set is closed or not updatable
3382 */
3383 public void updateNCharacterStream(String columnLabel, Reader x)
3384 throws SQLException {
3385 updateNCharacterStream(columnLabel, x, -1);
3386 }
3387
3388 /**
3389 * Updates a column in the current or insert row.
3390 *
3391 * @param columnLabel the column label
3392 * @param x the value
3393 * @param length the number of characters
3394 * @throws SQLException if the result set is closed or not updatable
3395 */
3396 public void updateNCharacterStream(String columnLabel, Reader x, long length)
3397 throws SQLException {
3398 try {
3399 if (isDebugEnabled()) {
3400 debugCode("updateNCharacterStream("+quote(columnLabel)+", x, "+length+"L);");
3401 }
3402 checkClosed();
3403 Value v = conn.createClob(x, length);
3404 update(columnLabel, v);
3405 } catch (Exception e) {
3406 throw logAndConvert(e);
3407 }
3408 }
3409
3410 /**
3411 * [Not supported] Return an object of this class if possible.
3412 */
3413 //## Java 1.6 ##
3414 public <T> T unwrap(Class<T> iface) throws SQLException {
3415 throw unsupported("unwrap");
3416 }
3417 //*/
3418
3419 /**
3420 * [Not supported] Checks if unwrap can return an object of this class.
3421 */
3422 //## Java 1.6 ##
3423 public boolean isWrapperFor(Class<?> iface) throws SQLException {
3424 throw unsupported("isWrapperFor");
3425 }
3426 //*/
3427
3428 /**
3429 * [Not supported]
3430 *
3431 * @param columnIndex the column index (1, 2, ...)
3432 * @param type the class of the returned value
3433 */
3434 /*## Java 1.7 ##
3435 public <T> T getObject(int columnIndex, Class<T> type) {
3436 return null;
3437 }
3438 //*/
3439
3440 /**
3441 * [Not supported]
3442 *
3443 * @param columnName the column name
3444 * @param type the class of the returned value
3445 */
3446 /*## Java 1.7 ##
3447 public <T> T getObject(String columnName, Class<T> type) {
3448 return null;
3449 }
3450 //*/
3451
3452 /**
3453 * INTERNAL
3454 */
3455 public String toString() {
3456 return getTraceObjectName() + ": " + result;
3457 }
3458
3459 private void patchCurrentRow(Value[] row) {
3460 boolean changed = false;
3461 Value[] current = result.currentRow();
3462 CompareMode mode = conn.getCompareMode();
3463 for (int i = 0; i < row.length; i++) {
3464 if (row[i].compareTo(current[i], mode) != 0) {
3465 changed = true;
3466 break;
3467 }
3468 }
3469 if (patchedRows == null) {
3470 patchedRows = New.hashMap();
3471 }
3472 Integer rowId = result.getRowId();
3473 if (!changed) {
3474 patchedRows.remove(rowId);
3475 } else {
3476 patchedRows.put(rowId, row);
3477 }
3478 }
3479
3480 private Value convertToUnknownValue(Object x) {
3481 checkClosed();
3482 return DataType.convertToValue(conn.getSession(), x, Value.UNKNOWN);
3483 }
3484
3485 private void checkUpdatable() {
3486 checkClosed();
3487 if (!updatable) {
3488 throw DbException.get(ErrorCode.RESULT_SET_READONLY);
3489 }
3490 }
3491
3492 }
3493