Debian Codegraph @

src/main/org/h2/jdbc/JdbcResultSet.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.jdbc;
7
8 import java.io.InputStream;
9 import java.io.Reader;
10 import java.math.BigDecimal;
11 import java.net.URL;
12 import java.sql.Array;
13 import java.sql.Blob;
14 import java.sql.Clob;
15 import java.sql.Date;
16 import java.sql.NClob;
17 import java.sql.Ref;
18 import java.sql.ResultSet;
19 import java.sql.ResultSetMetaData;
20 import java.sql.RowId;
21 import java.sql.SQLException;
22 import java.sql.SQLType;
23 import java.sql.SQLWarning;
24 import java.sql.SQLXML;
25 import java.sql.Statement;
26 import java.sql.Time;
27 import java.sql.Timestamp;
28 import java.util.Calendar;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import org.h2.api.ErrorCode;
33 import org.h2.command.CommandInterface;
34 import org.h2.engine.Session;
35 import org.h2.engine.SysProperties;
36 import org.h2.message.DbException;
37 import org.h2.message.TraceObject;
38 import org.h2.result.ResultInterface;
39 import org.h2.result.UpdatableRow;
40 import org.h2.util.IOUtils;
41 import org.h2.util.LegacyDateTimeUtils;
42 import org.h2.util.StringUtils;
43 import org.h2.value.CompareMode;
44 import org.h2.value.DataType;
45 import org.h2.value.Value;
46 import org.h2.value.ValueBigint;
47 import org.h2.value.ValueBoolean;
48 import org.h2.value.ValueDouble;
49 import org.h2.value.ValueInteger;
50 import org.h2.value.ValueNull;
51 import org.h2.value.ValueNumeric;
52 import org.h2.value.ValueReal;
53 import org.h2.value.ValueSmallint;
54 import org.h2.value.ValueTinyint;
55 import org.h2.value.ValueToObjectConverter;
56 import org.h2.value.ValueVarbinary;
57 import org.h2.value.ValueVarchar;
58
59 /**
60 * Represents a result set.
61 * <p>
62 * Column labels are case-insensitive, quotes are not supported. The first
63 * column has the column index 1.
64 * </p>
65 * <p>
66 * Thread safety: the result set is not thread-safe and must not be used by
67 * multiple threads concurrently.
68 * </p>
69 * <p>
70 * Updatable result sets: Result sets are updatable when the result only
71 * contains columns from one table, and if it contains all columns of a unique
72 * index (primary key or other) of this table. Key columns may not contain NULL
73 * (because multiple rows with NULL could exist). In updatable result sets, own
74 * changes are visible, but not own inserts and deletes.
75 * </p>
76 */
77 public final class JdbcResultSet extends TraceObject implements ResultSet {
78
79 private final boolean scrollable;
80 private final boolean updatable;
81 private final boolean triggerUpdatable;
82 ResultInterface result;
83 private JdbcConnection conn;
84 private JdbcStatement stat;
85 private int columnCount;
86 private boolean wasNull;
87 private Value[] insertRow;
88 private Value[] updateRow;
89 private HashMap<String, Integer> columnLabelMap;
90 private HashMap<Long, Value[]> patchedRows;
91 private JdbcPreparedStatement preparedStatement;
92 private final CommandInterface command;
93
94 public JdbcResultSet(JdbcConnection conn, JdbcStatement stat, CommandInterface command, ResultInterface result,
95 int id, boolean scrollable, boolean updatable, boolean triggerUpdatable) {
96 setTrace(conn.getSession().getTrace(), TraceObject.RESULT_SET, id);
97 this.conn = conn;
98 this.stat = stat;
99 this.command = command;
100 this.result = result;
101 this.columnCount = result.getVisibleColumnCount();
102 this.scrollable = scrollable;
103 this.updatable = updatable;
104 this.triggerUpdatable = triggerUpdatable;
105 }
106
107 JdbcResultSet(JdbcConnection conn, JdbcPreparedStatement preparedStatement, CommandInterface command,
108 ResultInterface result, int id, boolean scrollable, boolean updatable,
109 HashMap<String, Integer> columnLabelMap) {
110 this(conn, preparedStatement, command, result, id, scrollable, updatable, false);
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 @Override
121 public boolean next() throws SQLException {
122 try {
123 debugCodeCall("next");
124 checkClosed();
125 return nextRow();
126 } catch (Exception e) {
127 throw logAndConvert(e);
128 }
129 }
130
131 /**
132 * Gets the meta data of this result set.
133 *
134 * @return the meta data
135 */
136 @Override
137 public ResultSetMetaData getMetaData() throws SQLException {
138 try {
139 int id = getNextId(TraceObject.RESULT_SET_META_DATA);
140 debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
141 checkClosed();
142 String catalog = conn.getCatalog();
143 return new JdbcResultSetMetaData(this, null, result, catalog, conn.getSession().getTrace(), id);
144 } catch (Exception e) {
145 throw logAndConvert(e);
146 }
147 }
148
149 /**
150 * Returns whether the last column accessed was null.
151 *
152 * @return true if the last column accessed was null
153 */
154 @Override
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 @Override
175 public int findColumn(String columnLabel) throws SQLException {
176 try {
177 debugCodeCall("findColumn", columnLabel);
178 return getColumnIndex(columnLabel);
179 } catch (Exception e) {
180 throw logAndConvert(e);
181 }
182 }
183
184 /**
185 * Closes the result set.
186 */
187 @Override
188 public void close() throws SQLException {
189 try {
190 debugCodeCall("close");
191 closeInternal(false);
192 } catch (Exception e) {
193 throw logAndConvert(e);
194 }
195 }
196
197 /**
198 * Close the result set. This method also closes the statement if required.
199 * @param fromStatement if true - close statement in the end
200 */
201 void closeInternal(boolean fromStatement) {
202 if (result != null) {
203 try {
204 if (result.isLazy()) {
205 stat.onLazyResultSetClose(command, preparedStatement == null);
206 }
207 result.close();
208 } finally {
209 JdbcStatement s = stat;
210 columnCount = 0;
211 result = null;
212 stat = null;
213 conn = null;
214 insertRow = null;
215 updateRow = null;
216 if (!fromStatement && s != null) {
217 s.closeIfCloseOnCompletion();
218 }
219 }
220 }
221 }
222
223 /**
224 * Returns the statement that created this object.
225 *
226 * @return the statement or prepared statement, or null if created by a
227 * DatabaseMetaData call.
228 */
229 @Override
230 public Statement getStatement() throws SQLException {
231 try {
232 debugCodeCall("getStatement");
233 checkClosed();
234 return stat;
235 } catch (Exception e) {
236 throw logAndConvert(e);
237 }
238 }
239
240 /**
241 * Gets the first warning reported by calls on this object.
242 *
243 * @return null
244 */
245 @Override
246 public SQLWarning getWarnings() throws SQLException {
247 try {
248 debugCodeCall("getWarnings");
249 checkClosed();
250 return null;
251 } catch (Exception e) {
252 throw logAndConvert(e);
253 }
254 }
255
256 /**
257 * Clears all warnings.
258 */
259 @Override
260 public void clearWarnings() throws SQLException {
261 try {
262 debugCodeCall("clearWarnings");
263 checkClosed();
264 } catch (Exception e) {
265 throw logAndConvert(e);
266 }
267 }
268
269 // =============================================================
270
271 /**
272 * Returns the value of the specified column as a String.
273 *
274 * @param columnIndex (1,2,...)
275 * @return the value
276 * @throws SQLException if the column is not found or if the result set is
277 * closed
278 */
279 @Override
280 public String getString(int columnIndex) throws SQLException {
281 try {
282 debugCodeCall("getString", columnIndex);
283 return get(checkColumnIndex(columnIndex)).getString();
284 } catch (Exception e) {
285 throw logAndConvert(e);
286 }
287 }
288
289 /**
290 * Returns the value of the specified column as a String.
291 *
292 * @param columnLabel the column label
293 * @return the value
294 * @throws SQLException if the column is not found or if the result set is
295 * closed
296 */
297 @Override
298 public String getString(String columnLabel) throws SQLException {
299 try {
300 debugCodeCall("getString", columnLabel);
301 return get(getColumnIndex(columnLabel)).getString();
302 } catch (Exception e) {
303 throw logAndConvert(e);
304 }
305 }
306
307 /**
308 * Returns the value of the specified column as an int.
309 *
310 * @param columnIndex (1,2,...)
311 * @return the value
312 * @throws SQLException if the column is not found or if the result set is
313 * closed
314 */
315 @Override
316 public int getInt(int columnIndex) throws SQLException {
317 try {
318 debugCodeCall("getInt", columnIndex);
319 return getIntInternal(checkColumnIndex(columnIndex));
320 } catch (Exception e) {
321 throw logAndConvert(e);
322 }
323 }
324
325 /**
326 * Returns the value of the specified column as an int.
327 *
328 * @param columnLabel the column label
329 * @return the value
330 * @throws SQLException if the column is not found or if the result set is
331 * closed
332 */
333 @Override
334 public int getInt(String columnLabel) throws SQLException {
335 try {
336 debugCodeCall("getInt", columnLabel);
337 return getIntInternal(getColumnIndex(columnLabel));
338 } catch (Exception e) {
339 throw logAndConvert(e);
340 }
341 }
342
343 private int getIntInternal(int columnIndex) {
344 Value v = getInternal(columnIndex);
345 int result;
346 if (v != ValueNull.INSTANCE) {
347 wasNull = false;
348 result = v.getInt();
349 } else {
350 wasNull = true;
351 result = 0;
352 }
353 return result;
354 }
355
356 /**
357 * Returns the value of the specified column as a BigDecimal.
358 *
359 * @param columnIndex (1,2,...)
360 * @return the value
361 * @throws SQLException if the column is not found or if the result set is
362 * closed
363 */
364 @Override
365 public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
366 try {
367 debugCodeCall("getBigDecimal", columnIndex);
368 return get(checkColumnIndex(columnIndex)).getBigDecimal();
369 } catch (Exception e) {
370 throw logAndConvert(e);
371 }
372 }
373
374 /**
375 * Returns the value of the specified column as a java.sql.Date.
376 * <p>
377 * Usage of this method is discouraged. Use
378 * {@code getObject(columnIndex, LocalDate.class)} instead.
379 * </p>
380 *
381 * @param columnIndex (1,2,...)
382 * @return the value
383 * @throws SQLException if the column is not found or if the result set is
384 * closed
385 * @see #getObject(int, Class)
386 */
387 @Override
388 public Date getDate(int columnIndex) throws SQLException {
389 try {
390 debugCodeCall("getDate", columnIndex);
391 return LegacyDateTimeUtils.toDate(conn, null, get(checkColumnIndex(columnIndex)));
392 } catch (Exception e) {
393 throw logAndConvert(e);
394 }
395 }
396
397 /**
398 * Returns the value of the specified column as a java.sql.Time.
399 * <p>
400 * Usage of this method is discouraged. Use
401 * {@code getObject(columnIndex, LocalTime.class)} instead.
402 * </p>
403 *
404 * @param columnIndex (1,2,...)
405 * @return the value
406 * @throws SQLException if the column is not found or if the result set is
407 * closed
408 * @see #getObject(int, Class)
409 */
410 @Override
411 public Time getTime(int columnIndex) throws SQLException {
412 try {
413 debugCodeCall("getTime", columnIndex);
414 return LegacyDateTimeUtils.toTime(conn, null, get(checkColumnIndex(columnIndex)));
415 } catch (Exception e) {
416 throw logAndConvert(e);
417 }
418 }
419
420 /**
421 * Returns the value of the specified column as a java.sql.Timestamp.
422 * <p>
423 * Usage of this method is discouraged. Use
424 * {@code getObject(columnIndex, LocalDateTime.class)} instead.
425 * </p>
426 *
427 * @param columnIndex (1,2,...)
428 * @return the value
429 * @throws SQLException if the column is not found or if the result set is
430 * closed
431 * @see #getObject(int, Class)
432 */
433 @Override
434 public Timestamp getTimestamp(int columnIndex) throws SQLException {
435 try {
436 debugCodeCall("getTimestamp", columnIndex);
437 return LegacyDateTimeUtils.toTimestamp(conn, null, get(checkColumnIndex(columnIndex)));
438 } catch (Exception e) {
439 throw logAndConvert(e);
440 }
441 }
442
443 /**
444 * Returns the value of the specified column as a BigDecimal.
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 @Override
452 public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
453 try {
454 debugCodeCall("getBigDecimal", columnLabel);
455 return get(getColumnIndex(columnLabel)).getBigDecimal();
456 } catch (Exception e) {
457 throw logAndConvert(e);
458 }
459 }
460
461 /**
462 * Returns the value of the specified column as a java.sql.Date.
463 * <p>
464 * Usage of this method is discouraged. Use
465 * {@code getObject(columnLabel, LocalDate.class)} instead.
466 * </p>
467 *
468 * @param columnLabel the column label
469 * @return the value
470 * @throws SQLException if the column is not found or if the result set is
471 * closed
472 * @see #getObject(String, Class)
473 */
474 @Override
475 public Date getDate(String columnLabel) throws SQLException {
476 try {
477 debugCodeCall("getDate", columnLabel);
478 return LegacyDateTimeUtils.toDate(conn, null, get(getColumnIndex(columnLabel)));
479 } catch (Exception e) {
480 throw logAndConvert(e);
481 }
482 }
483
484 /**
485 * Returns the value of the specified column as a java.sql.Time.
486 * <p>
487 * Usage of this method is discouraged. Use
488 * {@code getObject(columnLabel, LocalTime.class)} instead.
489 * </p>
490 *
491 * @param columnLabel the column label
492 * @return the value
493 * @throws SQLException if the column is not found or if the result set is
494 * closed
495 * @see #getObject(String, Class)
496 */
497 @Override
498 public Time getTime(String columnLabel) throws SQLException {
499 try {
500 debugCodeCall("getTime", columnLabel);
501 return LegacyDateTimeUtils.toTime(conn, null, get(getColumnIndex(columnLabel)));
502 } catch (Exception e) {
503 throw logAndConvert(e);
504 }
505 }
506
507 /**
508 * Returns the value of the specified column as a java.sql.Timestamp.
509 * <p>
510 * Usage of this method is discouraged. Use
511 * {@code getObject(columnLabel, LocalDateTime.class)} instead.
512 * </p>
513 *
514 * @param columnLabel the column label
515 * @return the value
516 * @throws SQLException if the column is not found or if the result set is
517 * closed
518 * @see #getObject(String, Class)
519 */
520 @Override
521 public Timestamp getTimestamp(String columnLabel) throws SQLException {
522 try {
523 debugCodeCall("getTimestamp", columnLabel);
524 return LegacyDateTimeUtils.toTimestamp(conn, null, get(getColumnIndex(columnLabel)));
525 } catch (Exception e) {
526 throw logAndConvert(e);
527 }
528 }
529
530 /**
531 * Returns a column value as a Java object. The data is
532 * de-serialized into a Java object (on the client side).
533 *
534 * @param columnIndex (1,2,...)
535 * @return the value or null
536 * @throws SQLException if the column is not found or if the result set is
537 * closed
538 */
539 @Override
540 public Object getObject(int columnIndex) throws SQLException {
541 try {
542 debugCodeCall("getObject", columnIndex);
543 return ValueToObjectConverter.valueToDefaultObject(get(checkColumnIndex(columnIndex)), conn, true);
544 } catch (Exception e) {
545 throw logAndConvert(e);
546 }
547 }
548
549 /**
550 * Returns a column value as a Java object. The data is
551 * de-serialized into a Java object (on the client side).
552 *
553 * @param columnLabel the column label
554 * @return the value or null
555 * @throws SQLException if the column is not found or if the result set is
556 * closed
557 */
558 @Override
559 public Object getObject(String columnLabel) throws SQLException {
560 try {
561 debugCodeCall("getObject", columnLabel);
562 return ValueToObjectConverter.valueToDefaultObject(get(getColumnIndex(columnLabel)), conn, true);
563 } catch (Exception e) {
564 throw logAndConvert(e);
565 }
566 }
567
568 /**
569 * Returns the value of the specified column as a boolean.
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 @Override
577 public boolean getBoolean(int columnIndex) throws SQLException {
578 try {
579 debugCodeCall("getBoolean", columnIndex);
580 return getBooleanInternal(checkColumnIndex(columnIndex));
581 } catch (Exception e) {
582 throw logAndConvert(e);
583 }
584 }
585
586 /**
587 * Returns the value of the specified column as a boolean.
588 *
589 * @param columnLabel the column label
590 * @return the value
591 * @throws SQLException if the column is not found or if the result set is
592 * closed
593 */
594 @Override
595 public boolean getBoolean(String columnLabel) throws SQLException {
596 try {
597 debugCodeCall("getBoolean", columnLabel);
598 return getBooleanInternal(getColumnIndex(columnLabel));
599 } catch (Exception e) {
600 throw logAndConvert(e);
601 }
602 }
603
604 private boolean getBooleanInternal(int columnIndex) {
605 Value v = getInternal(columnIndex);
606 boolean result;
607 if (v != ValueNull.INSTANCE) {
608 wasNull = false;
609 result = v.getBoolean();
610 } else {
611 wasNull = true;
612 result = false;
613 }
614 return result;
615 }
616
617 /**
618 * Returns the value of the specified column as a byte.
619 *
620 * @param columnIndex (1,2,...)
621 * @return the value
622 * @throws SQLException if the column is not found or if the result set is
623 * closed
624 */
625 @Override
626 public byte getByte(int columnIndex) throws SQLException {
627 try {
628 debugCodeCall("getByte", columnIndex);
629 return getByteInternal(checkColumnIndex(columnIndex));
630 } catch (Exception e) {
631 throw logAndConvert(e);
632 }
633 }
634
635 /**
636 * Returns the value of the specified column as a byte.
637 *
638 * @param columnLabel the column label
639 * @return the value
640 * @throws SQLException if the column is not found or if the result set is
641 * closed
642 */
643 @Override
644 public byte getByte(String columnLabel) throws SQLException {
645 try {
646 debugCodeCall("getByte", columnLabel);
647 return getByteInternal(getColumnIndex(columnLabel));
648 } catch (Exception e) {
649 throw logAndConvert(e);
650 }
651 }
652
653 private byte getByteInternal(int columnIndex) {
654 Value v = getInternal(columnIndex);
655 byte result;
656 if (v != ValueNull.INSTANCE) {
657 wasNull = false;
658 result = v.getByte();
659 } else {
660 wasNull = true;
661 result = 0;
662 }
663 return result;
664 }
665
666 /**
667 * Returns the value of the specified column as a short.
668 *
669 * @param columnIndex (1,2,...)
670 * @return the value
671 * @throws SQLException if the column is not found or if the result set is
672 * closed
673 */
674 @Override
675 public short getShort(int columnIndex) throws SQLException {
676 try {
677 debugCodeCall("getShort", columnIndex);
678 return getShortInternal(checkColumnIndex(columnIndex));
679 } catch (Exception e) {
680 throw logAndConvert(e);
681 }
682 }
683
684 /**
685 * Returns the value of the specified column as a short.
686 *
687 * @param columnLabel the column label
688 * @return the value
689 * @throws SQLException if the column is not found or if the result set is
690 * closed
691 */
692 @Override
693 public short getShort(String columnLabel) throws SQLException {
694 try {
695 debugCodeCall("getShort", columnLabel);
696 return getShortInternal(getColumnIndex(columnLabel));
697 } catch (Exception e) {
698 throw logAndConvert(e);
699 }
700 }
701
702 private short getShortInternal(int columnIndex) {
703 Value v = getInternal(columnIndex);
704 short result;
705 if (v != ValueNull.INSTANCE) {
706 wasNull = false;
707 result = v.getShort();
708 } else {
709 wasNull = true;
710 result = 0;
711 }
712 return result;
713 }
714
715 /**
716 * Returns the value of the specified column as a long.
717 *
718 * @param columnIndex (1,2,...)
719 * @return the value
720 * @throws SQLException if the column is not found or if the result set is
721 * closed
722 */
723 @Override
724 public long getLong(int columnIndex) throws SQLException {
725 try {
726 debugCodeCall("getLong", columnIndex);
727 return getLongInternal(checkColumnIndex(columnIndex));
728 } catch (Exception e) {
729 throw logAndConvert(e);
730 }
731 }
732
733 /**
734 * Returns the value of the specified column as a long.
735 *
736 * @param columnLabel the column label
737 * @return the value
738 * @throws SQLException if the column is not found or if the result set is
739 * closed
740 */
741 @Override
742 public long getLong(String columnLabel) throws SQLException {
743 try {
744 debugCodeCall("getLong", columnLabel);
745 return getLongInternal(getColumnIndex(columnLabel));
746 } catch (Exception e) {
747 throw logAndConvert(e);
748 }
749 }
750
751 private long getLongInternal(int columnIndex) {
752 Value v = getInternal(columnIndex);
753 long result;
754 if (v != ValueNull.INSTANCE) {
755 wasNull = false;
756 result = v.getLong();
757 } else {
758 wasNull = true;
759 result = 0L;
760 }
761 return result;
762 }
763
764 /**
765 * Returns the value of the specified column as a float.
766 *
767 * @param columnIndex (1,2,...)
768 * @return the value
769 * @throws SQLException if the column is not found or if the result set is
770 * closed
771 */
772 @Override
773 public float getFloat(int columnIndex) throws SQLException {
774 try {
775 debugCodeCall("getFloat", columnIndex);
776 return getFloatInternal(checkColumnIndex(columnIndex));
777 } catch (Exception e) {
778 throw logAndConvert(e);
779 }
780 }
781
782 /**
783 * Returns the value of the specified column as a float.
784 *
785 * @param columnLabel the column label
786 * @return the value
787 * @throws SQLException if the column is not found or if the result set is
788 * closed
789 */
790 @Override
791 public float getFloat(String columnLabel) throws SQLException {
792 try {
793 debugCodeCall("getFloat", columnLabel);
794 return getFloatInternal(getColumnIndex(columnLabel));
795 } catch (Exception e) {
796 throw logAndConvert(e);
797 }
798 }
799
800 private float getFloatInternal(int columnIndex) {
801 Value v = getInternal(columnIndex);
802 float result;
803 if (v != ValueNull.INSTANCE) {
804 wasNull = false;
805 result = v.getFloat();
806 } else {
807 wasNull = true;
808 result = 0f;
809 }
810 return result;
811 }
812
813 /**
814 * Returns the value of the specified column as a double.
815 *
816 * @param columnIndex (1,2,...)
817 * @return the value
818 * @throws SQLException if the column is not found or if the result set is
819 * closed
820 */
821 @Override
822 public double getDouble(int columnIndex) throws SQLException {
823 try {
824 debugCodeCall("getDouble", columnIndex);
825 return getDoubleInternal(checkColumnIndex(columnIndex));
826 } catch (Exception e) {
827 throw logAndConvert(e);
828 }
829 }
830
831 /**
832 * Returns the value of the specified column as a double.
833 *
834 * @param columnLabel the column label
835 * @return the value
836 * @throws SQLException if the column is not found or if the result set is
837 * closed
838 */
839 @Override
840 public double getDouble(String columnLabel) throws SQLException {
841 try {
842 debugCodeCall("getDouble", columnLabel);
843 return getDoubleInternal(getColumnIndex(columnLabel));
844 } catch (Exception e) {
845 throw logAndConvert(e);
846 }
847 }
848
849 private double getDoubleInternal(int columnIndex) {
850 Value v = getInternal(columnIndex);
851 double result;
852 if (v != ValueNull.INSTANCE) {
853 wasNull = false;
854 result = v.getDouble();
855 } else {
856 wasNull = true;
857 result = 0d;
858 }
859 return result;
860 }
861
862 /**
863 * Returns the value of the specified column as a BigDecimal.
864 *
865 * @deprecated use {@link #getBigDecimal(String)}
866 *
867 * @param columnLabel the column label
868 * @param scale the scale of the returned value
869 * @return the value
870 * @throws SQLException if the column is not found or if the result set is
871 * closed
872 */
873 @Deprecated
874 @Override
875 public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
876 try {
877 if (isDebugEnabled()) {
878 debugCode("getBigDecimal(" + quote(columnLabel) + ", " + scale + ')');
879 }
880 if (scale < 0) {
881 throw DbException.getInvalidValueException("scale", scale);
882 }
883 BigDecimal bd = get(getColumnIndex(columnLabel)).getBigDecimal();
884 return bd == null ? null : ValueNumeric.setScale(bd, scale);
885 } catch (Exception e) {
886 throw logAndConvert(e);
887 }
888 }
889
890 /**
891 * Returns the value of the specified column as a BigDecimal.
892 *
893 * @deprecated use {@link #getBigDecimal(int)}
894 *
895 * @param columnIndex (1,2,...)
896 * @param scale the scale of the returned value
897 * @return the value
898 * @throws SQLException if the column is not found or if the result set is
899 * closed
900 */
901 @Deprecated
902 @Override
903 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
904 try {
905 if (isDebugEnabled()) {
906 debugCode("getBigDecimal(" + columnIndex + ", " + scale + ')');
907 }
908 if (scale < 0) {
909 throw DbException.getInvalidValueException("scale", scale);
910 }
911 BigDecimal bd = get(checkColumnIndex(columnIndex)).getBigDecimal();
912 return bd == null ? null : ValueNumeric.setScale(bd, scale);
913 } catch (Exception e) {
914 throw logAndConvert(e);
915 }
916 }
917
918 /**
919 * [Not supported]
920 * @deprecated since JDBC 2.0, use getCharacterStream
921 */
922 @Deprecated
923 @Override
924 public InputStream getUnicodeStream(int columnIndex) throws SQLException {
925 throw unsupported("unicodeStream");
926 }
927
928 /**
929 * [Not supported]
930 * @deprecated since JDBC 2.0, use setCharacterStream
931 */
932 @Deprecated
933 @Override
934 public InputStream getUnicodeStream(String columnLabel) throws SQLException {
935 throw unsupported("unicodeStream");
936 }
937
938 /**
939 * [Not supported] Gets a column as a object using the specified type
940 * mapping.
941 */
942 @Override
943 public Object getObject(int columnIndex, Map<String, Class<?>> map)
944 throws SQLException {
945 throw unsupported("map");
946 }
947
948 /**
949 * [Not supported] Gets a column as a object using the specified type
950 * mapping.
951 */
952 @Override
953 public Object getObject(String columnLabel, Map<String, Class<?>> map)
954 throws SQLException {
955 throw unsupported("map");
956 }
957
958 /**
959 * [Not supported] Gets a column as a reference.
960 */
961 @Override
962 public Ref getRef(int columnIndex) throws SQLException {
963 throw unsupported("ref");
964 }
965
966 /**
967 * [Not supported] Gets a column as a reference.
968 */
969 @Override
970 public Ref getRef(String columnLabel) throws SQLException {
971 throw unsupported("ref");
972 }
973
974 /**
975 * Returns the value of the specified column as a java.sql.Date using a
976 * specified time zone.
977 * <p>
978 * Usage of this method is discouraged. Use
979 * {@code getObject(columnIndex, LocalDate.class)} instead.
980 * </p>
981 *
982 * @param columnIndex (1,2,...)
983 * @param calendar the calendar
984 * @return the value
985 * @throws SQLException if the column is not found or if the result set is
986 * closed
987 * @see #getObject(int, Class)
988 */
989 @Override
990 public Date getDate(int columnIndex, Calendar calendar) throws SQLException {
991 try {
992 if (isDebugEnabled()) {
993 debugCode("getDate(" + columnIndex + ", calendar)");
994 }
995 return LegacyDateTimeUtils.toDate(conn, calendar != null ? calendar.getTimeZone() : null,
996 get(checkColumnIndex(columnIndex)));
997 } catch (Exception e) {
998 throw logAndConvert(e);
999 }
1000 }
1001
1002 /**
1003 * Returns the value of the specified column as a java.sql.Date using a
1004 * specified time zone.
1005 * <p>
1006 * Usage of this method is discouraged. Use
1007 * {@code getObject(columnLabel, LocalDate.class)} instead.
1008 * </p>
1009 *
1010 * @param columnLabel the column label
1011 * @param calendar the calendar
1012 * @return the value
1013 * @throws SQLException if the column is not found or if the result set is
1014 * closed
1015 * @see #getObject(String, Class)
1016 */
1017 @Override
1018 public Date getDate(String columnLabel, Calendar calendar) throws SQLException {
1019 try {
1020 if (isDebugEnabled()) {
1021 debugCode("getDate(" + quote(columnLabel) + ", calendar)");
1022 }
1023 return LegacyDateTimeUtils.toDate(conn, calendar != null ? calendar.getTimeZone() : null,
1024 get(getColumnIndex(columnLabel)));
1025 } catch (Exception e) {
1026 throw logAndConvert(e);
1027 }
1028 }
1029
1030 /**
1031 * Returns the value of the specified column as a java.sql.Time using a
1032 * specified time zone.
1033 * <p>
1034 * Usage of this method is discouraged. Use
1035 * {@code getObject(columnIndex, LocalTime.class)} instead.
1036 * </p>
1037 *
1038 * @param columnIndex (1,2,...)
1039 * @param calendar the calendar
1040 * @return the value
1041 * @throws SQLException if the column is not found or if the result set is
1042 * closed
1043 * @see #getObject(int, Class)
1044 */
1045 @Override
1046 public Time getTime(int columnIndex, Calendar calendar) throws SQLException {
1047 try {
1048 if (isDebugEnabled()) {
1049 debugCode("getTime(" + columnIndex + ", calendar)");
1050 }
1051 return LegacyDateTimeUtils.toTime(conn, calendar != null ? calendar.getTimeZone() : null,
1052 get(checkColumnIndex(columnIndex)));
1053 } catch (Exception e) {
1054 throw logAndConvert(e);
1055 }
1056 }
1057
1058 /**
1059 * Returns the value of the specified column as a java.sql.Time using a
1060 * specified time zone.
1061 * <p>
1062 * Usage of this method is discouraged. Use
1063 * {@code getObject(columnLabel, LocalTime.class)} instead.
1064 * </p>
1065 *
1066 * @param columnLabel the column label
1067 * @param calendar the calendar
1068 * @return the value
1069 * @throws SQLException if the column is not found or if the result set is
1070 * closed
1071 * @see #getObject(String, Class)
1072 */
1073 @Override
1074 public Time getTime(String columnLabel, Calendar calendar) throws SQLException {
1075 try {
1076 if (isDebugEnabled()) {
1077 debugCode("getTime(" + quote(columnLabel) + ", calendar)");
1078 }
1079 return LegacyDateTimeUtils.toTime(conn, calendar != null ? calendar.getTimeZone() : null,
1080 get(getColumnIndex(columnLabel)));
1081 } catch (Exception e) {
1082 throw logAndConvert(e);
1083 }
1084 }
1085
1086 /**
1087 * Returns the value of the specified column as a java.sql.Timestamp using a
1088 * specified time zone.
1089 * <p>
1090 * Usage of this method is discouraged. Use
1091 * {@code getObject(columnIndex, LocalDateTime.class)} instead.
1092 * </p>
1093 *
1094 * @param columnIndex (1,2,...)
1095 * @param calendar the calendar
1096 * @return the value
1097 * @throws SQLException if the column is not found or if the result set is
1098 * closed
1099 * @see #getObject(int, Class)
1100 */
1101 @Override
1102 public Timestamp getTimestamp(int columnIndex, Calendar calendar) throws SQLException {
1103 try {
1104 if (isDebugEnabled()) {
1105 debugCode("getTimestamp(" + columnIndex + ", calendar)");
1106 }
1107 return LegacyDateTimeUtils.toTimestamp(conn, calendar != null ? calendar.getTimeZone() : null,
1108 get(checkColumnIndex(columnIndex)));
1109 } catch (Exception e) {
1110 throw logAndConvert(e);
1111 }
1112 }
1113
1114 /**
1115 * Returns the value of the specified column as a java.sql.Timestamp.
1116 * <p>
1117 * Usage of this method is discouraged. Use
1118 * {@code getObject(columnLabel, LocalDateTime.class)} instead.
1119 * </p>
1120 *
1121 * @param columnLabel the column label
1122 * @param calendar the calendar
1123 * @return the value
1124 * @throws SQLException if the column is not found or if the result set is
1125 * closed
1126 * @see #getObject(String, Class)
1127 */
1128 @Override
1129 public Timestamp getTimestamp(String columnLabel, Calendar calendar) throws SQLException {
1130 try {
1131 if (isDebugEnabled()) {
1132 debugCode("getTimestamp(" + quote(columnLabel) + ", calendar)");
1133 }
1134 return LegacyDateTimeUtils.toTimestamp(conn, calendar != null ? calendar.getTimeZone() : null,
1135 get(getColumnIndex(columnLabel)));
1136 } catch (Exception e) {
1137 throw logAndConvert(e);
1138 }
1139 }
1140
1141 /**
1142 * Returns the value of the specified column as a Blob.
1143 *
1144 * @param columnIndex (1,2,...)
1145 * @return the value
1146 * @throws SQLException if the column is not found or if the result set is
1147 * closed
1148 */
1149 @Override
1150 public Blob getBlob(int columnIndex) throws SQLException {
1151 try {
1152 int id = getNextId(TraceObject.BLOB);
1153 if (isDebugEnabled()) {
1154 debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + columnIndex + ')');
1155 }
1156 return getBlob(id, checkColumnIndex(columnIndex));
1157 } catch (Exception e) {
1158 throw logAndConvert(e);
1159 }
1160 }
1161
1162 /**
1163 * Returns the value of the specified column as a Blob.
1164 *
1165 * @param columnLabel the column label
1166 * @return the value
1167 * @throws SQLException if the column is not found or if the result set is
1168 * closed
1169 */
1170 @Override
1171 public Blob getBlob(String columnLabel) throws SQLException {
1172 try {
1173 int id = getNextId(TraceObject.BLOB);
1174 if (isDebugEnabled()) {
1175 debugCodeAssign("Blob", TraceObject.BLOB, id, "getBlob(" + quote(columnLabel) + ')');
1176 }
1177 return getBlob(id, getColumnIndex(columnLabel));
1178 } catch (Exception e) {
1179 throw logAndConvert(e);
1180 }
1181 }
1182
1183 private JdbcBlob getBlob(int id, int columnIndex) {
1184 Value v = getInternal(columnIndex);
1185 JdbcBlob result;
1186 if (v != ValueNull.INSTANCE) {
1187 wasNull = false;
1188 result = new JdbcBlob(conn, v, JdbcLob.State.WITH_VALUE, id);
1189 } else {
1190 wasNull = true;
1191 result = null;
1192 }
1193 return result;
1194 }
1195
1196 /**
1197 * Returns the value of the specified column as a byte array.
1198 *
1199 * @param columnIndex (1,2,...)
1200 * @return the value
1201 * @throws SQLException if the column is not found or if the result set is
1202 * closed
1203 */
1204 @Override
1205 public byte[] getBytes(int columnIndex) throws SQLException {
1206 try {
1207 debugCodeCall("getBytes", columnIndex);
1208 return get(checkColumnIndex(columnIndex)).getBytes();
1209 } catch (Exception e) {
1210 throw logAndConvert(e);
1211 }
1212 }
1213
1214 /**
1215 * Returns the value of the specified column as a byte array.
1216 *
1217 * @param columnLabel the column label
1218 * @return the value
1219 * @throws SQLException if the column is not found or if the result set is
1220 * closed
1221 */
1222 @Override
1223 public byte[] getBytes(String columnLabel) throws SQLException {
1224 try {
1225 debugCodeCall("getBytes", columnLabel);
1226 return get(getColumnIndex(columnLabel)).getBytes();
1227 } catch (Exception e) {
1228 throw logAndConvert(e);
1229 }
1230 }
1231
1232 /**
1233 * Returns the value of the specified column as an input stream.
1234 *
1235 * @param columnIndex (1,2,...)
1236 * @return the value
1237 * @throws SQLException if the column is not found or if the result set is
1238 * closed
1239 */
1240 @Override
1241 public InputStream getBinaryStream(int columnIndex) throws SQLException {
1242 try {
1243 debugCodeCall("getBinaryStream", columnIndex);
1244 return get(checkColumnIndex(columnIndex)).getInputStream();
1245 } catch (Exception e) {
1246 throw logAndConvert(e);
1247 }
1248 }
1249
1250 /**
1251 * Returns the value of the specified column as an input stream.
1252 *
1253 * @param columnLabel the column label
1254 * @return the value
1255 * @throws SQLException if the column is not found or if the result set is
1256 * closed
1257 */
1258 @Override
1259 public InputStream getBinaryStream(String columnLabel) throws SQLException {
1260 try {
1261 debugCodeCall("getBinaryStream", columnLabel);
1262 return get(getColumnIndex(columnLabel)).getInputStream();
1263 } catch (Exception e) {
1264 throw logAndConvert(e);
1265 }
1266 }
1267
1268
1269 /**
1270 * Returns the value of the specified column as a Clob.
1271 *
1272 * @param columnIndex (1,2,...)
1273 * @return the value
1274 * @throws SQLException if the column is not found or if the result set is
1275 * closed
1276 */
1277 @Override
1278 public Clob getClob(int columnIndex) throws SQLException {
1279 try {
1280 int id = getNextId(TraceObject.CLOB);
1281 if (isDebugEnabled()) {
1282 debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + columnIndex + ')');
1283 }
1284 return getClob(id, checkColumnIndex(columnIndex));
1285 } catch (Exception e) {
1286 throw logAndConvert(e);
1287 }
1288 }
1289
1290 /**
1291 * Returns the value of the specified column as a Clob.
1292 *
1293 * @param columnLabel the column label
1294 * @return the value
1295 * @throws SQLException if the column is not found or if the result set is
1296 * closed
1297 */
1298 @Override
1299 public Clob getClob(String columnLabel) throws SQLException {
1300 try {
1301 int id = getNextId(TraceObject.CLOB);
1302 if (isDebugEnabled()) {
1303 debugCodeAssign("Clob", TraceObject.CLOB, id, "getClob(" + quote(columnLabel) + ')');
1304 }
1305 return getClob(id, getColumnIndex(columnLabel));
1306 } catch (Exception e) {
1307 throw logAndConvert(e);
1308 }
1309 }
1310
1311 /**
1312 * Returns the value of the specified column as an Array.
1313 *
1314 * @param columnIndex (1,2,...)
1315 * @return the value
1316 * @throws SQLException if the column is not found or if the result set is
1317 * closed
1318 */
1319 @Override
1320 public Array getArray(int columnIndex) throws SQLException {
1321 try {
1322 int id = getNextId(TraceObject.ARRAY);
1323 if (isDebugEnabled()) {
1324 debugCodeAssign("Array", TraceObject.ARRAY, id, "getArray(" + columnIndex + ')');
1325 }
1326 return getArray(id, checkColumnIndex(columnIndex));
1327 } catch (Exception e) {
1328 throw logAndConvert(e);
1329 }
1330 }
1331
1332 /**
1333 * Returns the value of the specified column as an Array.
1334 *
1335 * @param columnLabel the column label
1336 * @return the value
1337 * @throws SQLException if the column is not found or if the result set is
1338 * closed
1339 */
1340 @Override
1341 public Array getArray(String columnLabel) throws SQLException {
1342 try {
1343 int id = getNextId(TraceObject.ARRAY);
1344 if (isDebugEnabled()) {
1345 debugCodeAssign("Array", TraceObject.ARRAY, id, "getArray(" + quote(columnLabel) + ')');
1346 }
1347 return getArray(id, getColumnIndex(columnLabel));
1348 } catch (Exception e) {
1349 throw logAndConvert(e);
1350 }
1351 }
1352
1353 private Array getArray(int id, int columnIndex) {
1354 Value v = getInternal(columnIndex);
1355 JdbcArray result;
1356 if (v != ValueNull.INSTANCE) {
1357 wasNull = false;
1358 result = new JdbcArray(conn, v, id);
1359 } else {
1360 wasNull = true;
1361 result = null;
1362 }
1363 return result;
1364 }
1365
1366 /**
1367 * Returns the value of the specified column as an input stream.
1368 *
1369 * @param columnIndex (1,2,...)
1370 * @return the value
1371 * @throws SQLException if the column is not found or if the result set is
1372 * closed
1373 */
1374 @Override
1375 public InputStream getAsciiStream(int columnIndex) throws SQLException {
1376 try {
1377 debugCodeCall("getAsciiStream", columnIndex);
1378 String s = get(checkColumnIndex(columnIndex)).getString();
1379 return s == null ? null : IOUtils.getInputStreamFromString(s);
1380 } catch (Exception e) {
1381 throw logAndConvert(e);
1382 }
1383 }
1384
1385 /**
1386 * Returns the value of the specified column as an input stream.
1387 *
1388 * @param columnLabel the column label
1389 * @return the value
1390 * @throws SQLException if the column is not found or if the result set is
1391 * closed
1392 */
1393 @Override
1394 public InputStream getAsciiStream(String columnLabel) throws SQLException {
1395 try {
1396 debugCodeCall("getAsciiStream", columnLabel);
1397 String s = get(getColumnIndex(columnLabel)).getString();
1398 return IOUtils.getInputStreamFromString(s);
1399 } catch (Exception e) {
1400 throw logAndConvert(e);
1401 }
1402 }
1403
1404 /**
1405 * Returns the value of the specified column as a reader.
1406 *
1407 * @param columnIndex (1,2,...)
1408 * @return the value
1409 * @throws SQLException if the column is not found or if the result set is
1410 * closed
1411 */
1412 @Override
1413 public Reader getCharacterStream(int columnIndex) throws SQLException {
1414 try {
1415 debugCodeCall("getCharacterStream", columnIndex);
1416 return get(checkColumnIndex(columnIndex)).getReader();
1417 } catch (Exception e) {
1418 throw logAndConvert(e);
1419 }
1420 }
1421
1422 /**
1423 * Returns the value of the specified column as a reader.
1424 *
1425 * @param columnLabel the column label
1426 * @return the value
1427 * @throws SQLException if the column is not found or if the result set is
1428 * closed
1429 */
1430 @Override
1431 public Reader getCharacterStream(String columnLabel) throws SQLException {
1432 try {
1433 debugCodeCall("getCharacterStream", columnLabel);
1434 return get(getColumnIndex(columnLabel)).getReader();
1435 } catch (Exception e) {
1436 throw logAndConvert(e);
1437 }
1438 }
1439
1440 /**
1441 * [Not supported]
1442 */
1443 @Override
1444 public URL getURL(int columnIndex) throws SQLException {
1445 throw unsupported("url");
1446 }
1447
1448 /**
1449 * [Not supported]
1450 */
1451 @Override
1452 public URL getURL(String columnLabel) throws SQLException {
1453 throw unsupported("url");
1454 }
1455
1456 // =============================================================
1457
1458 /**
1459 * Updates a column in the current or insert row.
1460 *
1461 * @param columnIndex (1,2,...)
1462 * @throws SQLException if the result set is closed or not updatable
1463 */
1464 @Override
1465 public void updateNull(int columnIndex) throws SQLException {
1466 try {
1467 debugCodeCall("updateNull", columnIndex);
1468 update(checkColumnIndex(columnIndex), ValueNull.INSTANCE);
1469 } catch (Exception e) {
1470 throw logAndConvert(e);
1471 }
1472 }
1473
1474 /**
1475 * Updates a column in the current or insert row.
1476 *
1477 * @param columnLabel the column label
1478 * @throws SQLException if the result set is closed or not updatable
1479 */
1480 @Override
1481 public void updateNull(String columnLabel) throws SQLException {
1482 try {
1483 debugCodeCall("updateNull", columnLabel);
1484 update(getColumnIndex(columnLabel), ValueNull.INSTANCE);
1485 } catch (Exception e) {
1486 throw logAndConvert(e);
1487 }
1488 }
1489
1490 /**
1491 * Updates a column in the current or insert row.
1492 *
1493 * @param columnIndex (1,2,...)
1494 * @param x the value
1495 * @throws SQLException if the result set is closed or not updatable
1496 */
1497 @Override
1498 public void updateBoolean(int columnIndex, boolean x) throws SQLException {
1499 try {
1500 if (isDebugEnabled()) {
1501 debugCode("updateBoolean(" + columnIndex + ", " + x + ')');
1502 }
1503 update(checkColumnIndex(columnIndex), ValueBoolean.get(x));
1504 } catch (Exception e) {
1505 throw logAndConvert(e);
1506 }
1507 }
1508
1509 /**
1510 * Updates a column in the current or insert row.
1511 *
1512 * @param columnLabel the column label
1513 * @param x the value
1514 * @throws SQLException if result set is closed or not updatable
1515 */
1516 @Override
1517 public void updateBoolean(String columnLabel, boolean x) throws SQLException {
1518 try {
1519 if (isDebugEnabled()) {
1520 debugCode("updateBoolean(" + quote(columnLabel) + ", " + x + ')');
1521 }
1522 update(getColumnIndex(columnLabel), ValueBoolean.get(x));
1523 } catch (Exception e) {
1524 throw logAndConvert(e);
1525 }
1526 }
1527
1528 /**
1529 * Updates a column in the current or insert row.
1530 *
1531 * @param columnIndex (1,2,...)
1532 * @param x the value
1533 * @throws SQLException if the result set is closed or not updatable
1534 */
1535 @Override
1536 public void updateByte(int columnIndex, byte x) throws SQLException {
1537 try {
1538 if (isDebugEnabled()) {
1539 debugCode("updateByte(" + columnIndex + ", " + x + ')');
1540 }
1541 update(checkColumnIndex(columnIndex), ValueTinyint.get(x));
1542 } catch (Exception e) {
1543 throw logAndConvert(e);
1544 }
1545 }
1546
1547 /**
1548 * Updates a column in the current or insert row.
1549 *
1550 * @param columnLabel the column label
1551 * @param x the value
1552 * @throws SQLException if the result set is closed or not updatable
1553 */
1554 @Override
1555 public void updateByte(String columnLabel, byte x) throws SQLException {
1556 try {
1557 if (isDebugEnabled()) {
1558 debugCode("updateByte(" + quote(columnLabel) + ", " + x + ')');
1559 }
1560 update(getColumnIndex(columnLabel), ValueTinyint.get(x));
1561 } catch (Exception e) {
1562 throw logAndConvert(e);
1563 }
1564 }
1565
1566 /**
1567 * Updates a column in the current or insert row.
1568 *
1569 * @param columnIndex (1,2,...)
1570 * @param x the value
1571 * @throws SQLException if the result set is closed or not updatable
1572 */
1573 @Override
1574 public void updateBytes(int columnIndex, byte[] x) throws SQLException {
1575 try {
1576 if (isDebugEnabled()) {
1577 debugCode("updateBytes(" + columnIndex + ", x)");
1578 }
1579 update(checkColumnIndex(columnIndex), x == null ? ValueNull.INSTANCE : ValueVarbinary.get(x));
1580 } catch (Exception e) {
1581 throw logAndConvert(e);
1582 }
1583 }
1584
1585 /**
1586 * Updates a column in the current or insert row.
1587 *
1588 * @param columnLabel the column label
1589 * @param x the value
1590 * @throws SQLException if the result set is closed or not updatable
1591 */
1592 @Override
1593 public void updateBytes(String columnLabel, byte[] x) throws SQLException {
1594 try {
1595 if (isDebugEnabled()) {
1596 debugCode("updateBytes(" + quote(columnLabel) + ", x)");
1597 }
1598 update(getColumnIndex(columnLabel), x == null ? ValueNull.INSTANCE : ValueVarbinary.get(x));
1599 } catch (Exception e) {
1600 throw logAndConvert(e);
1601 }
1602 }
1603
1604 /**
1605 * Updates a column in the current or insert row.
1606 *
1607 * @param columnIndex (1,2,...)
1608 * @param x the value
1609 * @throws SQLException if the result set is closed or not updatable
1610 */
1611 @Override
1612 public void updateShort(int columnIndex, short x) throws SQLException {
1613 try {
1614 if (isDebugEnabled()) {
1615 debugCode("updateShort(" + columnIndex + ", (short) " + x + ')');
1616 }
1617 update(checkColumnIndex(columnIndex), ValueSmallint.get(x));
1618 } catch (Exception e) {
1619 throw logAndConvert(e);
1620 }
1621 }
1622
1623 /**
1624 * Updates a column in the current or insert row.
1625 *
1626 * @param columnLabel the column label
1627 * @param x the value
1628 * @throws SQLException if the result set is closed or not updatable
1629 */
1630 @Override
1631 public void updateShort(String columnLabel, short x) throws SQLException {
1632 try {
1633 if (isDebugEnabled()) {
1634 debugCode("updateShort(" + quote(columnLabel) + ", (short) " + x + ')');
1635 }
1636 update(getColumnIndex(columnLabel), ValueSmallint.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 columnIndex (1,2,...)
1646 * @param x the value
1647 * @throws SQLException if the result set is closed or not updatable
1648 */
1649 @Override
1650 public void updateInt(int columnIndex, int x) throws SQLException {
1651 try {
1652 if (isDebugEnabled()) {
1653 debugCode("updateInt(" + columnIndex + ", " + x + ')');
1654 }
1655 update(checkColumnIndex(columnIndex), ValueInteger.get(x));
1656 } catch (Exception e) {
1657 throw logAndConvert(e);
1658 }
1659 }
1660
1661 /**
1662 * Updates a column in the current or insert row.
1663 *
1664 * @param columnLabel the column label
1665 * @param x the value
1666 * @throws SQLException if the result set is closed or not updatable
1667 */
1668 @Override
1669 public void updateInt(String columnLabel, int x) throws SQLException {
1670 try {
1671 if (isDebugEnabled()) {
1672 debugCode("updateInt(" + quote(columnLabel) + ", " + x + ')');
1673 }
1674 update(getColumnIndex(columnLabel), ValueInteger.get(x));
1675 } catch (Exception e) {
1676 throw logAndConvert(e);
1677 }
1678 }
1679
1680 /**
1681 * Updates a column in the current or insert row.
1682 *
1683 * @param columnIndex (1,2,...)
1684 * @param x the value
1685 * @throws SQLException if the result set is closed or not updatable
1686 */
1687 @Override
1688 public void updateLong(int columnIndex, long x) throws SQLException {
1689 try {
1690 if (isDebugEnabled()) {
1691 debugCode("updateLong(" + columnIndex + ", " + x + "L)");
1692 }
1693 update(checkColumnIndex(columnIndex), ValueBigint.get(x));
1694 } catch (Exception e) {
1695 throw logAndConvert(e);
1696 }
1697 }
1698
1699 /**
1700 * Updates a column in the current or insert row.
1701 *
1702 * @param columnLabel the column label
1703 * @param x the value
1704 * @throws SQLException if the result set is closed or not updatable
1705 */
1706 @Override
1707 public void updateLong(String columnLabel, long x) throws SQLException {
1708 try {
1709 if (isDebugEnabled()) {
1710 debugCode("updateLong(" + quote(columnLabel) + ", " + x + "L)");
1711 }
1712 update(getColumnIndex(columnLabel), ValueBigint.get(x));
1713 } catch (Exception e) {
1714 throw logAndConvert(e);
1715 }
1716 }
1717
1718 /**
1719 * Updates a column in the current or insert row.
1720 *
1721 * @param columnIndex (1,2,...)
1722 * @param x the value
1723 * @throws SQLException if the result set is closed or not updatable
1724 */
1725 @Override
1726 public void updateFloat(int columnIndex, float x) throws SQLException {
1727 try {
1728 if (isDebugEnabled()) {
1729 debugCode("updateFloat(" + columnIndex + ", " + x + "f)");
1730 }
1731 update(checkColumnIndex(columnIndex), ValueReal.get(x));
1732 } catch (Exception e) {
1733 throw logAndConvert(e);
1734 }
1735 }
1736
1737 /**
1738 * Updates a column in the current or insert row.
1739 *
1740 * @param columnLabel the column label
1741 * @param x the value
1742 * @throws SQLException if the result set is closed or not updatable
1743 */
1744 @Override
1745 public void updateFloat(String columnLabel, float x) throws SQLException {
1746 try {
1747 if (isDebugEnabled()) {
1748 debugCode("updateFloat(" + quote(columnLabel) + ", " + x + "f)");
1749 }
1750 update(getColumnIndex(columnLabel), ValueReal.get(x));
1751 } catch (Exception e) {
1752 throw logAndConvert(e);
1753 }
1754 }
1755
1756 /**
1757 * Updates a column in the current or insert row.
1758 *
1759 * @param columnIndex (1,2,...)
1760 * @param x the value
1761 * @throws SQLException if the result set is closed or not updatable
1762 */
1763 @Override
1764 public void updateDouble(int columnIndex, double x) throws SQLException {
1765 try {
1766 if (isDebugEnabled()) {
1767 debugCode("updateDouble(" + columnIndex + ", " + x + "d)");
1768 }
1769 update(checkColumnIndex(columnIndex), ValueDouble.get(x));
1770 } catch (Exception e) {
1771 throw logAndConvert(e);
1772 }
1773 }
1774
1775 /**
1776 * Updates a column in the current or insert row.
1777 *
1778 * @param columnLabel the column label
1779 * @param x the value
1780 * @throws SQLException if the result set is closed or not updatable
1781 */
1782 @Override
1783 public void updateDouble(String columnLabel, double x) throws SQLException {
1784 try {
1785 if (isDebugEnabled()) {
1786 debugCode("updateDouble(" + quote(columnLabel) + ", " + x + "d)");
1787 }
1788 update(getColumnIndex(columnLabel), ValueDouble.get(x));
1789 } catch (Exception e) {
1790 throw logAndConvert(e);
1791 }
1792 }
1793
1794 /**
1795 * Updates a column in the current or insert row.
1796 *
1797 * @param columnIndex (1,2,...)
1798 * @param x the value
1799 * @throws SQLException if the result set is closed or not updatable
1800 */
1801 @Override
1802 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
1803 try {
1804 if (isDebugEnabled()) {
1805 debugCode("updateBigDecimal(" + columnIndex + ", " + quoteBigDecimal(x) + ')');
1806 }
1807 update(checkColumnIndex(columnIndex), x == null ? ValueNull.INSTANCE : ValueNumeric.getAnyScale(x));
1808 } catch (Exception e) {
1809 throw logAndConvert(e);
1810 }
1811 }
1812
1813 /**
1814 * Updates a column in the current or insert row.
1815 *
1816 * @param columnLabel the column label
1817 * @param x the value
1818 * @throws SQLException if the result set is closed or not updatable
1819 */
1820 @Override
1821 public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
1822 try {
1823 if (isDebugEnabled()) {
1824 debugCode("updateBigDecimal(" + quote(columnLabel) + ", " + quoteBigDecimal(x) + ')');
1825 }
1826 update(getColumnIndex(columnLabel), x == null ? ValueNull.INSTANCE : ValueNumeric.getAnyScale(x));
1827 } catch (Exception e) {
1828 throw logAndConvert(e);
1829 }
1830 }
1831
1832 /**
1833 * Updates a column in the current or insert row.
1834 *
1835 * @param columnIndex (1,2,...)
1836 * @param x the value
1837 * @throws SQLException if the result set is closed or not updatable
1838 */
1839 @Override
1840 public void updateString(int columnIndex, String x) throws SQLException {
1841 try {
1842 if (isDebugEnabled()) {
1843 debugCode("updateString(" + columnIndex + ", " + quote(x) + ')');
1844 }
1845 update(checkColumnIndex(columnIndex), x == null ? ValueNull.INSTANCE : ValueVarchar.get(x, conn));
1846 } catch (Exception e) {
1847 throw logAndConvert(e);
1848 }
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 * @throws SQLException if the result set is closed or not updatable
1857 */
1858 @Override
1859 public void updateString(String columnLabel, String x) throws SQLException {
1860 try {
1861 if (isDebugEnabled()) {
1862 debugCode("updateString(" + quote(columnLabel) + ", " + quote(x) + ')');
1863 }
1864 update(getColumnIndex(columnLabel), x == null ? ValueNull.INSTANCE : ValueVarchar.get(x, conn));
1865 } catch (Exception e) {
1866 throw logAndConvert(e);
1867 }
1868 }
1869
1870 /**
1871 * Updates a column in the current or insert row.
1872 * <p>
1873 * Usage of this method is discouraged. Use
1874 * {@code updateObject(columnIndex, value)} with {@link java.time.LocalDate}
1875 * parameter instead.
1876 * </p>
1877 *
1878 * @param columnIndex (1,2,...)
1879 * @param x the value
1880 * @throws SQLException if the result set is closed or not updatable
1881 * @see #updateObject(int, Object)
1882 */
1883 @Override
1884 public void updateDate(int columnIndex, Date x) throws SQLException {
1885 try {
1886 if (isDebugEnabled()) {
1887 debugCode("updateDate(" + columnIndex + ", " + quoteDate(x) + ')');
1888 }
1889 update(checkColumnIndex(columnIndex),
1890 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromDate(conn, null, x));
1891 } catch (Exception e) {
1892 throw logAndConvert(e);
1893 }
1894 }
1895
1896 /**
1897 * Updates a column in the current or insert row.
1898 * <p>
1899 * Usage of this method is discouraged. Use
1900 * {@code updateObject(columnLabel, value)} with {@link java.time.LocalDate}
1901 * parameter instead.
1902 * </p>
1903 *
1904 * @param columnLabel the column label
1905 * @param x the value
1906 * @throws SQLException if the result set is closed or not updatable
1907 * @see #updateObject(String, Object)
1908 */
1909 @Override
1910 public void updateDate(String columnLabel, Date x) throws SQLException {
1911 try {
1912 if (isDebugEnabled()) {
1913 debugCode("updateDate(" + quote(columnLabel) + ", " + quoteDate(x) + ')');
1914 }
1915 update(getColumnIndex(columnLabel),
1916 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromDate(conn, null, x));
1917 } catch (Exception e) {
1918 throw logAndConvert(e);
1919 }
1920 }
1921
1922 /**
1923 * Updates a column in the current or insert row.
1924 * <p>
1925 * Usage of this method is discouraged. Use
1926 * {@code updateObject(columnIndex, value)} with {@link java.time.LocalTime}
1927 * parameter instead.
1928 * </p>
1929 *
1930 * @param columnIndex (1,2,...)
1931 * @param x the value
1932 * @throws SQLException if the result set is closed or not updatable
1933 * @see #updateObject(int, Object)
1934 */
1935 @Override
1936 public void updateTime(int columnIndex, Time x) throws SQLException {
1937 try {
1938 if (isDebugEnabled()) {
1939 debugCode("updateTime(" + columnIndex + ", " + quoteTime(x) + ')');
1940 }
1941 update(checkColumnIndex(columnIndex),
1942 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromTime(conn, null, x));
1943 } catch (Exception e) {
1944 throw logAndConvert(e);
1945 }
1946 }
1947
1948 /**
1949 * Updates a column in the current or insert row.
1950 * <p>
1951 * Usage of this method is discouraged. Use
1952 * {@code updateObject(columnLabel, value)} with {@link java.time.LocalTime}
1953 * parameter instead.
1954 * </p>
1955 *
1956 * @param columnLabel the column label
1957 * @param x the value
1958 * @throws SQLException if the result set is closed or not updatable
1959 * @see #updateObject(String, Object)
1960 */
1961 @Override
1962 public void updateTime(String columnLabel, Time x) throws SQLException {
1963 try {
1964 if (isDebugEnabled()) {
1965 debugCode("updateTime(" + quote(columnLabel) + ", " + quoteTime(x) + ')');
1966 }
1967 update(getColumnIndex(columnLabel),
1968 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromTime(conn, null, x));
1969 } catch (Exception e) {
1970 throw logAndConvert(e);
1971 }
1972 }
1973
1974 /**
1975 * Updates a column in the current or insert row.
1976 * <p>
1977 * Usage of this method is discouraged. Use
1978 * {@code updateObject(columnIndex, value)} with
1979 * {@link java.time.LocalDateTime} parameter instead.
1980 * </p>
1981 *
1982 * @param columnIndex (1,2,...)
1983 * @param x the value
1984 * @throws SQLException if the result set is closed or not updatable
1985 * @see #updateObject(int, Object)
1986 */
1987 @Override
1988 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
1989 try {
1990 if (isDebugEnabled()) {
1991 debugCode("updateTimestamp(" + columnIndex + ", " + quoteTimestamp(x) + ')');
1992 }
1993 update(checkColumnIndex(columnIndex),
1994 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromTimestamp(conn, null, x));
1995 } catch (Exception e) {
1996 throw logAndConvert(e);
1997 }
1998 }
1999
2000 /**
2001 * Updates a column in the current or insert row.
2002 * <p>
2003 * Usage of this method is discouraged. Use
2004 * {@code updateObject(columnLabel, value)} with
2005 * {@link java.time.LocalDateTime} parameter instead.
2006 * </p>
2007 *
2008 * @param columnLabel the column label
2009 * @param x the value
2010 * @throws SQLException if the result set is closed or not updatable
2011 * @see #updateObject(String, Object)
2012 */
2013 @Override
2014 public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
2015 try {
2016 if (isDebugEnabled()) {
2017 debugCode("updateTimestamp(" + quote(columnLabel) + ", " + quoteTimestamp(x) + ')');
2018 }
2019 update(getColumnIndex(columnLabel),
2020 x == null ? ValueNull.INSTANCE : LegacyDateTimeUtils.fromTimestamp(conn, null, x));
2021 } catch (Exception e) {
2022 throw logAndConvert(e);
2023 }
2024 }
2025
2026 /**
2027 * Updates a column in the current or insert row.
2028 *
2029 * @param columnIndex (1,2,...)
2030 * @param x the value
2031 * @param length the number of characters
2032 * @throws SQLException if the result set is closed or not updatable
2033 */
2034 @Override
2035 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
2036 try {
2037 if (isDebugEnabled()) {
2038 debugCode("updateAsciiStream(" + columnIndex + ", x, " + length + ')');
2039 }
2040 updateAscii(checkColumnIndex(columnIndex), x, length);
2041 } catch (Exception e) {
2042 throw logAndConvert(e);
2043 }
2044 }
2045
2046 /**
2047 * Updates a column in the current or insert row.
2048 *
2049 * @param columnIndex (1,2,...)
2050 * @param x the value
2051 * @throws SQLException if the result set is closed or not updatable
2052 */
2053 @Override
2054 public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException {
2055 try {
2056 if (isDebugEnabled()) {
2057 debugCode("updateAsciiStream(" + columnIndex + ", x)");
2058 }
2059 updateAscii(checkColumnIndex(columnIndex), x, -1L);
2060 } catch (Exception e) {
2061 throw logAndConvert(e);
2062 }
2063 }
2064
2065 /**
2066 * Updates a column in the current or insert row.
2067 *
2068 * @param columnIndex (1,2,...)
2069 * @param x the value
2070 * @param length the number of characters
2071 * @throws SQLException if the result set is closed or not updatable
2072 */
2073 @Override
2074 public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException {
2075 try {
2076 if (isDebugEnabled()) {
2077 debugCode("updateAsciiStream(" + columnIndex + ", x, " + length + "L)");
2078 }
2079 updateAscii(checkColumnIndex(columnIndex), x, length);
2080 } catch (Exception e) {
2081 throw logAndConvert(e);
2082 }
2083 }
2084
2085 /**
2086 * Updates a column in the current or insert row.
2087 *
2088 * @param columnLabel the column label
2089 * @param x the value
2090 * @param length the number of characters
2091 * @throws SQLException if the result set is closed or not updatable
2092 */
2093 @Override
2094 public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
2095 try {
2096 if (isDebugEnabled()) {
2097 debugCode("updateAsciiStream(" + quote(columnLabel) + ", x, " + length + ')');
2098 }
2099 updateAscii(getColumnIndex(columnLabel), x, length);
2100 } catch (Exception e) {
2101 throw logAndConvert(e);
2102 }
2103 }
2104
2105 /**
2106 * Updates a column in the current or insert row.
2107 *
2108 * @param columnLabel the column label
2109 * @param x the value
2110 * @throws SQLException if the result set is closed
2111 */
2112 @Override
2113 public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException {
2114 try {
2115 if (isDebugEnabled()) {
2116 debugCode("updateAsciiStream(" + quote(columnLabel) + ", x)");
2117 }
2118 updateAscii(getColumnIndex(columnLabel), x, -1L);
2119 } catch (Exception e) {
2120 throw logAndConvert(e);
2121 }
2122 }
2123
2124 /**
2125 * Updates a column in the current or insert row.
2126 *
2127 * @param columnLabel the column label
2128 * @param x the value
2129 * @param length the number of characters
2130 * @throws SQLException if the result set is closed or not updatable
2131 */
2132 @Override
2133 public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException {
2134 try {
2135 if (isDebugEnabled()) {
2136 debugCode("updateAsciiStream(" + quote(columnLabel) + ", x, " + length + "L)");
2137 }
2138 updateAscii(getColumnIndex(columnLabel), x, length);
2139 } catch (Exception e) {
2140 throw logAndConvert(e);
2141 }
2142 }
2143
2144 private void updateAscii(int columnIndex, InputStream x, long length) {
2145 update(columnIndex, conn.createClob(IOUtils.getAsciiReader(x), length));
2146 }
2147
2148 /**
2149 * Updates a column in the current or insert row.
2150 *
2151 * @param columnIndex (1,2,...)
2152 * @param x the value
2153 * @param length the number of characters
2154 * @throws SQLException if the result set is closed or not updatable
2155 */
2156 @Override
2157 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
2158 try {
2159 if (isDebugEnabled()) {
2160 debugCode("updateBinaryStream(" + columnIndex + ", x, " + length + ')');
2161 }
2162 updateBlobImpl(checkColumnIndex(columnIndex), x, length);
2163 } catch (Exception e) {
2164 throw logAndConvert(e);
2165 }
2166 }
2167
2168 /**
2169 * Updates a column in the current or insert row.
2170 *
2171 * @param columnIndex (1,2,...)
2172 * @param x the value
2173 * @throws SQLException if the result set is closed or not updatable
2174 */
2175 @Override
2176 public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException {
2177 try {
2178 if (isDebugEnabled()) {
2179 debugCode("updateBinaryStream(" + columnIndex + ", x)");
2180 }
2181 updateBlobImpl(checkColumnIndex(columnIndex), x, -1L);
2182 } catch (Exception e) {
2183 throw logAndConvert(e);
2184 }
2185 }
2186
2187 /**
2188 * Updates a column in the current or insert row.
2189 *
2190 * @param columnIndex (1,2,...)
2191 * @param x the value
2192 * @param length the number of characters
2193 * @throws SQLException if the result set is closed or not updatable
2194 */
2195 @Override
2196 public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException {
2197 try {
2198 if (isDebugEnabled()) {
2199 debugCode("updateBinaryStream(" + columnIndex + ", x, " + length + "L)");
2200 }
2201 updateBlobImpl(checkColumnIndex(columnIndex), x, length);
2202 } catch (Exception e) {
2203 throw logAndConvert(e);
2204 }
2205 }
2206
2207 /**
2208 * Updates a column in the current or insert row.
2209 *
2210 * @param columnLabel the column label
2211 * @param x the value
2212 * @throws SQLException if the result set is closed or not updatable
2213 */
2214 @Override
2215 public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException {
2216 try {
2217 if (isDebugEnabled()) {
2218 debugCode("updateBinaryStream(" + quote(columnLabel) + ", x)");
2219 }
2220 updateBlobImpl(getColumnIndex(columnLabel), x, -1L);
2221 } catch (Exception e) {
2222 throw logAndConvert(e);
2223 }
2224 }
2225
2226 /**
2227 * Updates a column in the current or insert row.
2228 *
2229 * @param columnLabel the column label
2230 * @param x the value
2231 * @param length the number of characters
2232 * @throws SQLException if the result set is closed or not updatable
2233 */
2234 @Override
2235 public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
2236 try {
2237 if (isDebugEnabled()) {
2238 debugCode("updateBinaryStream(" + quote(columnLabel) + ", x, " + length + ')');
2239 }
2240 updateBlobImpl(getColumnIndex(columnLabel), x, length);
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 * @param length the number of characters
2252 * @throws SQLException if the result set is closed or not updatable
2253 */
2254 @Override
2255 public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
2256 try {
2257 if (isDebugEnabled()) {
2258 debugCode("updateBinaryStream(" + quote(columnLabel) + ", x, " + length + "L)");
2259 }
2260 updateBlobImpl(getColumnIndex(columnLabel), x, length);
2261 } catch (Exception e) {
2262 throw logAndConvert(e);
2263 }
2264 }
2265
2266 /**
2267 * Updates a column in the current or insert row.
2268 *
2269 * @param columnIndex (1,2,...)
2270 * @param x the value
2271 * @param length the number of characters
2272 * @throws SQLException if the result set is closed or not updatable
2273 */
2274 @Override
2275 public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
2276 try {
2277 if (isDebugEnabled()) {
2278 debugCode("updateCharacterStream(" + columnIndex + ", x, " + length + "L)");
2279 }
2280 updateClobImpl(checkColumnIndex(columnIndex), x, length);
2281 } catch (Exception e) {
2282 throw logAndConvert(e);
2283 }
2284 }
2285
2286 /**
2287 * Updates a column in the current or insert row.
2288 *
2289 * @param columnIndex (1,2,...)
2290 * @param x the value
2291 * @param length the number of characters
2292 * @throws SQLException if the result set is closed or not updatable
2293 */
2294 @Override
2295 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
2296 try {
2297 if (isDebugEnabled()) {
2298 debugCode("updateCharacterStream(" + columnIndex + ", x, " + length + ')');
2299 }
2300 updateClobImpl(checkColumnIndex(columnIndex), x, length);
2301 } catch (Exception e) {
2302 throw logAndConvert(e);
2303 }
2304 }
2305
2306 /**
2307 * Updates a column in the current or insert row.
2308 *
2309 * @param columnIndex (1,2,...)
2310 * @param x the value
2311 * @throws SQLException if the result set is closed or not updatable
2312 */
2313 @Override
2314 public void updateCharacterStream(int columnIndex, Reader x) throws SQLException {
2315 try {
2316 if (isDebugEnabled()) {
2317 debugCode("updateCharacterStream(" + columnIndex + ", x)");
2318 }
2319 updateClobImpl(checkColumnIndex(columnIndex), x, -1L);
2320 } catch (Exception e) {
2321 throw logAndConvert(e);
2322 }
2323 }
2324
2325 /**
2326 * Updates a column in the current or insert row.
2327 *
2328 * @param columnLabel the column label
2329 * @param x the value
2330 * @param length the number of characters
2331 * @throws SQLException if the result set is closed or not updatable
2332 */
2333 @Override
2334 public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException {
2335 try {
2336 if (isDebugEnabled()) {
2337 debugCode("updateCharacterStream(" + quote(columnLabel) + ", x, " + length + ')');
2338 }
2339 updateClobImpl(getColumnIndex(columnLabel), x, length);
2340 } catch (Exception e) {
2341 throw logAndConvert(e);
2342 }
2343 }
2344
2345 /**
2346 * Updates a column in the current or insert row.
2347 *
2348 * @param columnLabel the column label
2349 * @param x the value
2350 * @throws SQLException if the result set is closed or not updatable
2351 */
2352 @Override
2353 public void updateCharacterStream(String columnLabel, Reader x) throws SQLException {
2354 try {
2355 if (isDebugEnabled()) {
2356 debugCode("updateCharacterStream(" + quote(columnLabel) + ", x)");
2357 }
2358 updateClobImpl(getColumnIndex(columnLabel), x, -1L);
2359 } catch (Exception e) {
2360 throw logAndConvert(e);
2361 }
2362 }
2363
2364 /**
2365 * Updates a column in the current or insert row.
2366 *
2367 * @param columnLabel the column label
2368 * @param x the value
2369 * @param length the number of characters
2370 * @throws SQLException if the result set is closed or not updatable
2371 */
2372 @Override
2373 public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
2374 try {
2375 if (isDebugEnabled()) {
2376 debugCode("updateCharacterStream(" + quote(columnLabel) + ", x, " + length + "L)");
2377 }
2378 updateClobImpl(getColumnIndex(columnLabel), x, length);
2379 } catch (Exception e) {
2380 throw logAndConvert(e);
2381 }
2382 }
2383
2384 /**
2385 * Updates a column in the current or insert row.
2386 *
2387 * @param columnIndex (1,2,...)
2388 * @param x the value
2389 * @param scale is ignored
2390 * @throws SQLException if the result set is closed or not updatable
2391 */
2392 @Override
2393 public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
2394 try {
2395 if (isDebugEnabled()) {
2396 debugCode("updateObject(" + columnIndex + ", x, " + scale + ')');
2397 }
2398 update(checkColumnIndex(columnIndex), convertToUnknownValue(x));
2399 } catch (Exception e) {
2400 throw logAndConvert(e);
2401 }
2402 }
2403
2404 /**
2405 * Updates a column in the current or insert row.
2406 *
2407 * @param columnLabel the column label
2408 * @param x the value
2409 * @param scale is ignored
2410 * @throws SQLException if the result set is closed or not updatable
2411 */
2412 @Override
2413 public void updateObject(String columnLabel, Object x, int scale) throws SQLException {
2414 try {
2415 if (isDebugEnabled()) {
2416 debugCode("updateObject(" + quote(columnLabel) + ", x, " + scale + ')');
2417 }
2418 update(getColumnIndex(columnLabel), convertToUnknownValue(x));
2419 } catch (Exception e) {
2420 throw logAndConvert(e);
2421 }
2422 }
2423
2424 /**
2425 * Updates a column in the current or insert row.
2426 *
2427 * @param columnIndex (1,2,...)
2428 * @param x the value
2429 * @throws SQLException if the result set is closed or not updatable
2430 */
2431 @Override
2432 public void updateObject(int columnIndex, Object x) throws SQLException {
2433 try {
2434 if (isDebugEnabled()) {
2435 debugCode("updateObject(" + columnIndex + ", x)");
2436 }
2437 update(checkColumnIndex(columnIndex), convertToUnknownValue(x));
2438 } catch (Exception e) {
2439 throw logAndConvert(e);
2440 }
2441 }
2442
2443 /**
2444 * Updates a column in the current or insert row.
2445 *
2446 * @param columnLabel the column label
2447 * @param x the value
2448 * @throws SQLException if the result set is closed or not updatable
2449 */
2450 @Override
2451 public void updateObject(String columnLabel, Object x) throws SQLException {
2452 try {
2453 if (isDebugEnabled()) {
2454 debugCode("updateObject(" + quote(columnLabel) + ", x)");
2455 }
2456 update(getColumnIndex(columnLabel), convertToUnknownValue(x));
2457 } catch (Exception e) {
2458 throw logAndConvert(e);
2459 }
2460 }
2461
2462 /**
2463 * Updates a column in the current or insert row.
2464 *
2465 * @param columnIndex (1,2,...)
2466 * @param x the value
2467 * @param targetSqlType the SQL type
2468 * @throws SQLException if the result set is closed or not updatable
2469 */
2470 @Override
2471 public void updateObject(int columnIndex, Object x, SQLType targetSqlType) throws SQLException {
2472 try {
2473 if (isDebugEnabled()) {
2474 debugCode("updateObject(" + columnIndex + ", x, " + DataType.sqlTypeToString(targetSqlType) + ')');
2475 }
2476 update(checkColumnIndex(columnIndex), convertToValue(x, targetSqlType));
2477 } catch (Exception e) {
2478 throw logAndConvert(e);
2479 }
2480 }
2481
2482 /**
2483 * Updates a column in the current or insert row.
2484 *
2485 * @param columnIndex (1,2,...)
2486 * @param x the value
2487 * @param targetSqlType the SQL type
2488 * @param scaleOrLength is ignored
2489 * @throws SQLException if the result set is closed or not updatable
2490 */
2491 @Override
2492 public void updateObject(int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength) throws SQLException {
2493 try {
2494 if (isDebugEnabled()) {
2495 debugCode("updateObject(" + columnIndex + ", x, " + DataType.sqlTypeToString(targetSqlType) + ", "
2496 + scaleOrLength + ')');
2497 }
2498 update(checkColumnIndex(columnIndex), convertToValue(x, targetSqlType));
2499 } catch (Exception e) {
2500 throw logAndConvert(e);
2501 }
2502 }
2503
2504 /**
2505 * Updates a column in the current or insert row.
2506 *
2507 * @param columnLabel the column label
2508 * @param x the value
2509 * @param targetSqlType the SQL type
2510 * @throws SQLException if the result set is closed or not updatable
2511 */
2512 @Override
2513 public void updateObject(String columnLabel, Object x, SQLType targetSqlType) throws SQLException {
2514 try {
2515 if (isDebugEnabled()) {
2516 debugCode("updateObject(" + quote(columnLabel) + ", x, " + DataType.sqlTypeToString(targetSqlType)
2517 + ')');
2518 }
2519 update(getColumnIndex(columnLabel), convertToValue(x, targetSqlType));
2520 } catch (Exception e) {
2521 throw logAndConvert(e);
2522 }
2523 }
2524
2525 /**
2526 * Updates a column in the current or insert row.
2527 *
2528 * @param columnLabel the column label
2529 * @param x the value
2530 * @param targetSqlType the SQL type
2531 * @param scaleOrLength is ignored
2532 * @throws SQLException if the result set is closed or not updatable
2533 */
2534 @Override
2535 public void updateObject(String columnLabel, Object x, SQLType targetSqlType, int scaleOrLength)
2536 throws SQLException {
2537 try {
2538 if (isDebugEnabled()) {
2539 debugCode("updateObject(" + quote(columnLabel) + ", x, " + DataType.sqlTypeToString(targetSqlType)
2540 + ", " + scaleOrLength + ')');
2541 }
2542 update(getColumnIndex(columnLabel), convertToValue(x, targetSqlType));
2543 } catch (Exception e) {
2544 throw logAndConvert(e);
2545 }
2546 }
2547
2548 /**
2549 * [Not supported]
2550 */
2551 @Override
2552 public void updateRef(int columnIndex, Ref x) throws SQLException {
2553 throw unsupported("ref");
2554 }
2555
2556 /**
2557 * [Not supported]
2558 */
2559 @Override
2560 public void updateRef(String columnLabel, Ref x) throws SQLException {
2561 throw unsupported("ref");
2562 }
2563
2564 /**
2565 * Updates a column in the current or insert row.
2566 *
2567 * @param columnIndex (1,2,...)
2568 * @param x the value
2569 * @throws SQLException if the result set is closed or not updatable
2570 */
2571 @Override
2572 public void updateBlob(int columnIndex, InputStream x) throws SQLException {
2573 try {
2574 if (isDebugEnabled()) {
2575 debugCode("updateBlob(" + columnIndex + ", (InputStream) x)");
2576 }
2577 updateBlobImpl(checkColumnIndex(columnIndex), x, -1L);
2578 } catch (Exception e) {
2579 throw logAndConvert(e);
2580 }
2581 }
2582
2583 /**
2584 * Updates a column in the current or insert row.
2585 *
2586 * @param columnIndex (1,2,...)
2587 * @param x the value
2588 * @param length the length
2589 * @throws SQLException if the result set is closed or not updatable
2590 */
2591 @Override
2592 public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException {
2593 try {
2594 if (isDebugEnabled()) {
2595 debugCode("updateBlob(" + columnIndex + ", (InputStream) x, " + length + "L)");
2596 }
2597 updateBlobImpl(checkColumnIndex(columnIndex), x, length);
2598 } catch (Exception e) {
2599 throw logAndConvert(e);
2600 }
2601 }
2602
2603 /**
2604 * Updates a column in the current or insert row.
2605 *
2606 * @param columnIndex (1,2,...)
2607 * @param x the value
2608 * @throws SQLException if the result set is closed or not updatable
2609 */
2610 @Override
2611 public void updateBlob(int columnIndex, Blob x) throws SQLException {
2612 try {
2613 if (isDebugEnabled()) {
2614 debugCode("updateBlob(" + columnIndex + ", (Blob) x)");
2615 }
2616 updateBlobImpl(checkColumnIndex(columnIndex), x, -1L);
2617 } catch (Exception e) {
2618 throw logAndConvert(e);
2619 }
2620 }
2621
2622 /**
2623 * Updates a column in the current or insert row.
2624 *
2625 * @param columnLabel the column label
2626 * @param x the value
2627 * @throws SQLException if the result set is closed or not updatable
2628 */
2629 @Override
2630 public void updateBlob(String columnLabel, Blob x) throws SQLException {
2631 try {
2632 if (isDebugEnabled()) {
2633 debugCode("updateBlob(" + quote(columnLabel) + ", (Blob) x)");
2634 }
2635 updateBlobImpl(getColumnIndex(columnLabel), x, -1L);
2636 } catch (Exception e) {
2637 throw logAndConvert(e);
2638 }
2639 }
2640
2641 private void updateBlobImpl(int columnIndex, Blob x, long length) throws SQLException {
2642 update(columnIndex, x == null ? ValueNull.INSTANCE : conn.createBlob(x.getBinaryStream(), length));
2643 }
2644
2645 /**
2646 * Updates a column in the current or insert row.
2647 *
2648 * @param columnLabel the column label
2649 * @param x the value
2650 * @throws SQLException if the result set is closed or not updatable
2651 */
2652 @Override
2653 public void updateBlob(String columnLabel, InputStream x) throws SQLException {
2654 try {
2655 if (isDebugEnabled()) {
2656 debugCode("updateBlob(" + quote(columnLabel) + ", (InputStream) x)");
2657 }
2658 updateBlobImpl(getColumnIndex(columnLabel), x, -1L);
2659 } catch (Exception e) {
2660 throw logAndConvert(e);
2661 }
2662 }
2663
2664 /**
2665 * Updates a column in the current or insert row.
2666 *
2667 * @param columnLabel the column label
2668 * @param x the value
2669 * @param length the length
2670 * @throws SQLException if the result set is closed or not updatable
2671 */
2672 @Override
2673 public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException {
2674 try {
2675 if (isDebugEnabled()) {
2676 debugCode("updateBlob(" + quote(columnLabel) + ", (InputStream) x, " + length + "L)");
2677 }
2678 updateBlobImpl(getColumnIndex(columnLabel), x, length);
2679 } catch (Exception e) {
2680 throw logAndConvert(e);
2681 }
2682 }
2683
2684 private void updateBlobImpl(int columnIndex, InputStream x, long length) {
2685 update(columnIndex, conn.createBlob(x, length));
2686 }
2687
2688 /**
2689 * Updates a column in the current or insert row.
2690 *
2691 * @param columnIndex (1,2,...)
2692 * @param x the value
2693 * @throws SQLException if the result set is closed or not updatable
2694 */
2695 @Override
2696 public void updateClob(int columnIndex, Clob x) throws SQLException {
2697 try {
2698 if (isDebugEnabled()) {
2699 debugCode("updateClob(" + columnIndex + ", (Clob) x)");
2700 }
2701 updateClobImpl(checkColumnIndex(columnIndex), x);
2702 } catch (Exception e) {
2703 throw logAndConvert(e);
2704 }
2705 }
2706
2707 /**
2708 * Updates a column in the current or insert row.
2709 *
2710 * @param columnIndex (1,2,...)
2711 * @param x the value
2712 * @throws SQLException if the result set is closed or not updatable
2713 */
2714 @Override
2715 public void updateClob(int columnIndex, Reader x) throws SQLException {
2716 try {
2717 if (isDebugEnabled()) {
2718 debugCode("updateClob(" + columnIndex + ", (Reader) x)");
2719 }
2720 updateClobImpl(checkColumnIndex(columnIndex), x, -1L);
2721 } catch (Exception e) {
2722 throw logAndConvert(e);
2723 }
2724 }
2725
2726 /**
2727 * Updates a column in the current or insert row.
2728 *
2729 * @param columnIndex (1,2,...)
2730 * @param x the value
2731 * @param length the length
2732 * @throws SQLException if the result set is closed or not updatable
2733 */
2734 @Override
2735 public void updateClob(int columnIndex, Reader x, long length) throws SQLException {
2736 try {
2737 if (isDebugEnabled()) {
2738 debugCode("updateClob(" + columnIndex + ", (Reader) x, " + length + "L)");
2739 }
2740 updateClobImpl(checkColumnIndex(columnIndex), x, length);
2741 } catch (Exception e) {
2742 throw logAndConvert(e);
2743 }
2744 }
2745
2746 /**
2747 * Updates a column in the current or insert row.
2748 *
2749 * @param columnLabel the column label
2750 * @param x the value
2751 * @throws SQLException if the result set is closed or not updatable
2752 */
2753 @Override
2754 public void updateClob(String columnLabel, Clob x) throws SQLException {
2755 try {
2756 if (isDebugEnabled()) {
2757 debugCode("updateClob(" + quote(columnLabel) + ", (Clob) x)");
2758 }
2759 updateClobImpl(getColumnIndex(columnLabel), x);
2760 } catch (Exception e) {
2761 throw logAndConvert(e);
2762 }
2763 }
2764
2765 /**
2766 * Updates a column in the current or insert row.
2767 *
2768 * @param columnLabel the column label
2769 * @param x the value
2770 * @throws SQLException if the result set is closed or not updatable
2771 */
2772 @Override
2773 public void updateClob(String columnLabel, Reader x) throws SQLException {
2774 try {
2775 if (isDebugEnabled()) {
2776 debugCode("updateClob(" + quote(columnLabel) + ", (Reader) x)");
2777 }
2778 updateClobImpl(getColumnIndex(columnLabel), x, -1L);
2779 } catch (Exception e) {
2780 throw logAndConvert(e);
2781 }
2782 }
2783
2784 /**
2785 * Updates a column in the current or insert row.
2786 *
2787 * @param columnLabel the column label
2788 * @param x the value
2789 * @param length the length
2790 * @throws SQLException if the result set is closed or not updatable
2791 */
2792 @Override
2793 public void updateClob(String columnLabel, Reader x, long length) throws SQLException {
2794 try {
2795 if (isDebugEnabled()) {
2796 debugCode("updateClob(" + quote(columnLabel) + ", (Reader) x, " + length + "L)");
2797 }
2798 updateClobImpl(getColumnIndex(columnLabel), x, length);
2799 } catch (Exception e) {
2800 throw logAndConvert(e);
2801 }
2802 }
2803
2804 /**
2805 * Updates a column in the current or insert row.
2806 *
2807 * @param columnIndex (1,2,...)
2808 * @param x the value
2809 * @throws SQLException if the result set is closed or not updatable
2810 */
2811 @Override
2812 public void updateArray(int columnIndex, Array x) throws SQLException {
2813 try {
2814 if (isDebugEnabled()) {
2815 debugCode("updateArray(" + columnIndex + ", x)");
2816 }
2817 updateArrayImpl(checkColumnIndex(columnIndex), x);
2818 } catch (Exception e) {
2819 throw logAndConvert(e);
2820 }
2821 }
2822
2823 /**
2824 * Updates a column in the current or insert row.
2825 *
2826 * @param columnLabel the column label
2827 * @param x the value
2828 * @throws SQLException if the result set is closed or not updatable
2829 */
2830 @Override
2831 public void updateArray(String columnLabel, Array x) throws SQLException {
2832 try {
2833 if (isDebugEnabled()) {
2834 debugCode("updateArray(" + quote(columnLabel) + ", x)");
2835 }
2836 updateArrayImpl(getColumnIndex(columnLabel), x);
2837 } catch (Exception e) {
2838 throw logAndConvert(e);
2839 }
2840 }
2841
2842 private void updateArrayImpl(int columnIndex, Array x) throws SQLException {
2843 update(columnIndex, x == null ? ValueNull.INSTANCE
2844 : ValueToObjectConverter.objectToValue(stat.session, x.getArray(), Value.ARRAY));
2845 }
2846
2847 /**
2848 * [Not supported] Gets the cursor name if it was defined. This feature is
2849 * superseded by updateX methods. This method throws a SQLException because
2850 * cursor names are not supported.
2851 */
2852 @Override
2853 public String getCursorName() throws SQLException {
2854 throw unsupported("cursorName");
2855 }
2856
2857 /**
2858 * Gets the current row number. The first row is row 1, the second 2 and so
2859 * on. This method returns 0 before the first and after the last row.
2860 *
2861 * @return the row number
2862 */
2863 @Override
2864 public int getRow() throws SQLException {
2865 try {
2866 debugCodeCall("getRow");
2867 checkClosed();
2868 if (result.isAfterLast()) {
2869 return 0;
2870 }
2871 long rowNumber = result.getRowId() + 1;
2872 return rowNumber <= Integer.MAX_VALUE ? (int) rowNumber : Statement.SUCCESS_NO_INFO;
2873 } catch (Exception e) {
2874 throw logAndConvert(e);
2875 }
2876 }
2877
2878 /**
2879 * Gets the result set concurrency. Result sets are only updatable if the
2880 * statement was created with updatable concurrency, and if the result set
2881 * contains all columns of the primary key or of a unique index of a table.
2882 *
2883 * @return ResultSet.CONCUR_UPDATABLE if the result set is updatable, or
2884 * ResultSet.CONCUR_READ_ONLY otherwise
2885 */
2886 @Override
2887 public int getConcurrency() throws SQLException {
2888 try {
2889 debugCodeCall("getConcurrency");
2890 checkClosed();
2891 if (!updatable) {
2892 return ResultSet.CONCUR_READ_ONLY;
2893 }
2894 UpdatableRow row = new UpdatableRow(conn, result);
2895 return row.isUpdatable() ? ResultSet.CONCUR_UPDATABLE
2896 : ResultSet.CONCUR_READ_ONLY;
2897 } catch (Exception e) {
2898 throw logAndConvert(e);
2899 }
2900 }
2901
2902 /**
2903 * Gets the fetch direction.
2904 *
2905 * @return the direction: FETCH_FORWARD
2906 */
2907 @Override
2908 public int getFetchDirection() throws SQLException {
2909 try {
2910 debugCodeCall("getFetchDirection");
2911 checkClosed();
2912 return ResultSet.FETCH_FORWARD;
2913 } catch (Exception e) {
2914 throw logAndConvert(e);
2915 }
2916 }
2917
2918 /**
2919 * Gets the number of rows suggested to read in one step.
2920 *
2921 * @return the current fetch size
2922 */
2923 @Override
2924 public int getFetchSize() throws SQLException {
2925 try {
2926 debugCodeCall("getFetchSize");
2927 checkClosed();
2928 return result.getFetchSize();
2929 } catch (Exception e) {
2930 throw logAndConvert(e);
2931 }
2932 }
2933
2934 /**
2935 * Sets the number of rows suggested to read in one step. This value cannot
2936 * be higher than the maximum rows (setMaxRows) set by the statement or
2937 * prepared statement, otherwise an exception is throws. Setting the value
2938 * to 0 will set the default value. The default value can be changed using
2939 * the system property h2.serverResultSetFetchSize.
2940 *
2941 * @param rows the number of rows
2942 */
2943 @Override
2944 public void setFetchSize(int rows) throws SQLException {
2945 try {
2946 debugCodeCall("setFetchSize", rows);
2947 checkClosed();
2948 if (rows < 0) {
2949 throw DbException.getInvalidValueException("rows", rows);
2950 } else if (rows > 0) {
2951 if (stat != null) {
2952 int maxRows = stat.getMaxRows();
2953 if (maxRows > 0 && rows > maxRows) {
2954 throw DbException.getInvalidValueException("rows", rows);
2955 }
2956 }
2957 } else {
2958 rows = SysProperties.SERVER_RESULT_SET_FETCH_SIZE;
2959 }
2960 result.setFetchSize(rows);
2961 } catch (Exception e) {
2962 throw logAndConvert(e);
2963 }
2964 }
2965
2966 /**
2967 * [Not supported]
2968 * Sets (changes) the fetch direction for this result set. This method
2969 * should only be called for scrollable result sets, otherwise it will throw
2970 * an exception (no matter what direction is used).
2971 *
2972 * @param direction the new fetch direction
2973 * @throws SQLException Unsupported Feature if the method is called for a
2974 * forward-only result set
2975 */
2976 @Override
2977 public void setFetchDirection(int direction) throws SQLException {
2978 debugCodeCall("setFetchDirection", direction);
2979 // ignore FETCH_FORWARD, that's the default value, which we do support
2980 if (direction != ResultSet.FETCH_FORWARD) {
2981 throw unsupported("setFetchDirection");
2982 }
2983 }
2984
2985 /**
2986 * Get the result set type.
2987 *
2988 * @return the result set type (TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE
2989 * or TYPE_SCROLL_SENSITIVE)
2990 * @throws SQLException if the column is not found or if the result set is
2991 * closed
2992 */
2993 @Override
2994 public int getType() throws SQLException {
2995 try {
2996 debugCodeCall("getType");
2997 checkClosed();
2998 return stat == null ? ResultSet.TYPE_FORWARD_ONLY : stat.resultSetType;
2999 } catch (Exception e) {
3000 throw logAndConvert(e);
3001 }
3002 }
3003
3004 /**
3005 * Checks if the current position is before the first row, that means next()
3006 * was not called yet, and there is at least one row.
3007 *
3008 * @return if there are results and the current position is before the first
3009 * row
3010 * @throws SQLException if the result set is closed
3011 */
3012 @Override
3013 public boolean isBeforeFirst() throws SQLException {
3014 try {
3015 debugCodeCall("isBeforeFirst");
3016 checkClosed();
3017 return result.getRowId() < 0 && result.hasNext();
3018 } catch (Exception e) {
3019 throw logAndConvert(e);
3020 }
3021 }
3022
3023 /**
3024 * Checks if the current position is after the last row, that means next()
3025 * was called and returned false, and there was at least one row.
3026 *
3027 * @return if there are results and the current position is after the last
3028 * row
3029 * @throws SQLException if the result set is closed
3030 */
3031 @Override
3032 public boolean isAfterLast() throws SQLException {
3033 try {
3034 debugCodeCall("isAfterLast");
3035 checkClosed();
3036 return result.getRowId() > 0 && result.isAfterLast();
3037 } catch (Exception e) {
3038 throw logAndConvert(e);
3039 }
3040 }
3041
3042 /**
3043 * Checks if the current position is row 1, that means next() was called
3044 * once and returned true.
3045 *
3046 * @return if the current position is the first row
3047 * @throws SQLException if the result set is closed
3048 */
3049 @Override
3050 public boolean isFirst() throws SQLException {
3051 try {
3052 debugCodeCall("isFirst");
3053 checkClosed();
3054 return result.getRowId() == 0 && !result.isAfterLast();
3055 } catch (Exception e) {
3056 throw logAndConvert(e);
3057 }
3058 }
3059
3060 /**
3061 * Checks if the current position is the last row, that means next() was
3062 * called and did not yet returned false, but will in the next call.
3063 *
3064 * @return if the current position is the last row
3065 * @throws SQLException if the result set is closed
3066 */
3067 @Override
3068 public boolean isLast() throws SQLException {
3069 try {
3070 debugCodeCall("isLast");
3071 checkClosed();
3072 long rowId = result.getRowId();
3073 return rowId >= 0 && !result.isAfterLast() && !result.hasNext();
3074 } catch (Exception e) {
3075 throw logAndConvert(e);
3076 }
3077 }
3078
3079 /**
3080 * Moves the current position to before the first row, that means resets the
3081 * result set.
3082 *
3083 * @throws SQLException if the result set is closed
3084 */
3085 @Override
3086 public void beforeFirst() throws SQLException {
3087 try {
3088 debugCodeCall("beforeFirst");
3089 checkClosed();
3090 if (result.getRowId() >= 0) {
3091 resetResult();
3092 }
3093 } catch (Exception e) {
3094 throw logAndConvert(e);
3095 }
3096 }
3097
3098 /**
3099 * Moves the current position to after the last row, that means after the
3100 * end.
3101 *
3102 * @throws SQLException if the result set is closed
3103 */
3104 @Override
3105 public void afterLast() throws SQLException {
3106 try {
3107 debugCodeCall("afterLast");
3108 checkClosed();
3109 while (nextRow()) {
3110 // nothing
3111 }
3112 } catch (Exception e) {
3113 throw logAndConvert(e);
3114 }
3115 }
3116
3117 /**
3118 * Moves the current position to the first row. This is the same as calling
3119 * beforeFirst() followed by next().
3120 *
3121 * @return true if there is a row available, false if not
3122 * @throws SQLException if the result set is closed
3123 */
3124 @Override
3125 public boolean first() throws SQLException {
3126 try {
3127 debugCodeCall("first");
3128 checkClosed();
3129 if (result.getRowId() >= 0) {
3130 resetResult();
3131 }
3132 return nextRow();
3133 } catch (Exception e) {
3134 throw logAndConvert(e);
3135 }
3136 }
3137
3138 /**
3139 * Moves the current position to the last row.
3140 *
3141 * @return true if there is a row available, false if not
3142 * @throws SQLException if the result set is closed
3143 */
3144 @Override
3145 public boolean last() throws SQLException {
3146 try {
3147 debugCodeCall("last");
3148 checkClosed();
3149 if (result.isAfterLast()) {
3150 resetResult();
3151 }
3152 while (result.hasNext()) {
3153 nextRow();
3154 }
3155 return isOnValidRow();
3156 } catch (Exception e) {
3157 throw logAndConvert(e);
3158 }
3159 }
3160
3161 /**
3162 * Moves the current position to a specific row.
3163 *
3164 * @param rowNumber the row number. 0 is not allowed, 1 means the first row,
3165 * 2 the second. -1 means the last row, -2 the row before the
3166 * last row. If the value is too large, the position is moved
3167 * after the last row, if the value is too small it is moved
3168 * before the first row.
3169 * @return true if there is a row available, false if not
3170 * @throws SQLException if the result set is closed
3171 */
3172 @Override
3173 public boolean absolute(int rowNumber) throws SQLException {
3174 try {
3175 debugCodeCall("absolute", rowNumber);
3176 checkClosed();
3177 long longRowNumber = rowNumber >= 0 ? rowNumber : result.getRowCount() + rowNumber + 1;
3178 if (--longRowNumber < result.getRowId()) {
3179 resetResult();
3180 }
3181 while (result.getRowId() < longRowNumber) {
3182 if (!nextRow()) {
3183 return false;
3184 }
3185 }
3186 return isOnValidRow();
3187 } catch (Exception e) {
3188 throw logAndConvert(e);
3189 }
3190 }
3191
3192 /**
3193 * Moves the current position to a specific row relative to the current row.
3194 *
3195 * @param rowCount 0 means don't do anything, 1 is the next row, -1 the
3196 * previous. If the value is too large, the position is moved
3197 * after the last row, if the value is too small it is moved
3198 * before the first row.
3199 * @return true if there is a row available, false if not
3200 * @throws SQLException if the result set is closed
3201 */
3202 @Override
3203 public boolean relative(int rowCount) throws SQLException {
3204 try {
3205 debugCodeCall("relative", rowCount);
3206 checkClosed();
3207 long longRowCount;
3208 if (rowCount < 0) {
3209 longRowCount = result.getRowId() + rowCount + 1;
3210 resetResult();
3211 } else {
3212 longRowCount = rowCount;
3213 }
3214 while (longRowCount-- > 0) {
3215 if (!nextRow()) {
3216 return false;
3217 }
3218 }
3219 return isOnValidRow();
3220 } catch (Exception e) {
3221 throw logAndConvert(e);
3222 }
3223 }
3224
3225 /**
3226 * Moves the cursor to the last row, or row before first row if the current
3227 * position is the first row.
3228 *
3229 * @return true if there is a row available, false if not
3230 * @throws SQLException if the result set is closed
3231 */
3232 @Override
3233 public boolean previous() throws SQLException {
3234 try {
3235 debugCodeCall("previous");
3236 checkClosed();
3237 return relative(-1);
3238 } catch (Exception e) {
3239 throw logAndConvert(e);
3240 }
3241 }
3242
3243 /**
3244 * Moves the current position to the insert row. The current row is
3245 * remembered.
3246 *
3247 * @throws SQLException if the result set is closed or is not updatable
3248 */
3249 @Override
3250 public void moveToInsertRow() throws SQLException {
3251 try {
3252 debugCodeCall("moveToInsertRow");
3253 checkUpdatable();
3254 insertRow = new Value[columnCount];
3255 } catch (Exception e) {
3256 throw logAndConvert(e);
3257 }
3258 }
3259
3260 /**
3261 * Moves the current position to the current row.
3262 *
3263 * @throws SQLException if the result set is closed or is not updatable
3264 */
3265 @Override
3266 public void moveToCurrentRow() throws SQLException {
3267 try {
3268 debugCodeCall("moveToCurrentRow");
3269 checkUpdatable();
3270 insertRow = null;
3271 } catch (Exception e) {
3272 throw logAndConvert(e);
3273 }
3274 }
3275
3276 /**
3277 * Detects if the row was updated (by somebody else or the caller).
3278 *
3279 * @return false because this driver does not detect this
3280 */
3281 @Override
3282 public boolean rowUpdated() throws SQLException {
3283 try {
3284 debugCodeCall("rowUpdated");
3285 return false;
3286 } catch (Exception e) {
3287 throw logAndConvert(e);
3288 }
3289 }
3290
3291 /**
3292 * Detects if the row was inserted.
3293 *
3294 * @return false because this driver does not detect this
3295 */
3296 @Override
3297 public boolean rowInserted() throws SQLException {
3298 try {
3299 debugCodeCall("rowInserted");
3300 return false;
3301 } catch (Exception e) {
3302 throw logAndConvert(e);
3303 }
3304 }
3305
3306 /**
3307 * Detects if the row was deleted (by somebody else or the caller).
3308 *
3309 * @return false because this driver does not detect this
3310 */
3311 @Override
3312 public boolean rowDeleted() throws SQLException {
3313 try {
3314 debugCodeCall("rowDeleted");
3315 return false;
3316 } catch (Exception e) {
3317 throw logAndConvert(e);
3318 }
3319 }
3320
3321 /**
3322 * Inserts the current row. The current position must be the insert row.
3323 *
3324 * @throws SQLException if the result set is closed or if not on the insert
3325 * row, or if the result set it not updatable
3326 */
3327 @Override
3328 public void insertRow() throws SQLException {
3329 try {
3330 debugCodeCall("insertRow");
3331 checkUpdatable();
3332 if (insertRow == null) {
3333 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
3334 }
3335 getUpdatableRow().insertRow(insertRow);
3336 insertRow = null;
3337 } catch (Exception e) {
3338 throw logAndConvert(e);
3339 }
3340 }
3341
3342 /**
3343 * Updates the current row.
3344 *
3345 * @throws SQLException if the result set is closed, if the current row is
3346 * the insert row or if not on a valid row, or if the result set
3347 * it not updatable
3348 */
3349 @Override
3350 public void updateRow() throws SQLException {
3351 try {
3352 debugCodeCall("updateRow");
3353 checkUpdatable();
3354 if (insertRow != null) {
3355 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
3356 }
3357 checkOnValidRow();
3358 if (updateRow != null) {
3359 UpdatableRow row = getUpdatableRow();
3360 Value[] current = new Value[columnCount];
3361 for (int i = 0; i < updateRow.length; i++) {
3362 current[i] = getInternal(checkColumnIndex(i + 1));
3363 }
3364 row.updateRow(current, updateRow);
3365 for (int i = 0; i < updateRow.length; i++) {
3366 if (updateRow[i] == null) {
3367 updateRow[i] = current[i];
3368 }
3369 }
3370 Value[] patch = row.readRow(updateRow);
3371 patchCurrentRow(patch);
3372 updateRow = null;
3373 }
3374 } catch (Exception e) {
3375 throw logAndConvert(e);
3376 }
3377 }
3378
3379 /**
3380 * Deletes the current row.
3381 *
3382 * @throws SQLException if the result set is closed, if the current row is
3383 * the insert row or if not on a valid row, or if the result set
3384 * it not updatable
3385 */
3386 @Override
3387 public void deleteRow() throws SQLException {
3388 try {
3389 debugCodeCall("deleteRow");
3390 checkUpdatable();
3391 if (insertRow != null) {
3392 throw DbException.get(ErrorCode.NOT_ON_UPDATABLE_ROW);
3393 }
3394 checkOnValidRow();
3395 getUpdatableRow().deleteRow(result.currentRow());
3396 updateRow = null;
3397 } catch (Exception e) {
3398 throw logAndConvert(e);
3399 }
3400 }
3401
3402 /**
3403 * Re-reads the current row from the database.
3404 *
3405 * @throws SQLException if the result set is closed or if the current row is
3406 * the insert row or if the row has been deleted or if not on a
3407 * valid row
3408 */
3409 @Override
3410 public void refreshRow() throws SQLException {
3411 try {
3412 debugCodeCall("refreshRow");
3413 checkClosed();
3414 if (insertRow != null) {
3415 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
3416 }
3417 checkOnValidRow();
3418 patchCurrentRow(getUpdatableRow().readRow(result.currentRow()));
3419 updateRow = null;
3420 } catch (Exception e) {
3421 throw logAndConvert(e);
3422 }
3423 }
3424
3425 /**
3426 * Cancels updating a row.
3427 *
3428 * @throws SQLException if the result set is closed or if the current row is
3429 * the insert row
3430 */
3431 @Override
3432 public void cancelRowUpdates() throws SQLException {
3433 try {
3434 debugCodeCall("cancelRowUpdates");
3435 checkClosed();
3436 if (insertRow != null) {
3437 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
3438 }
3439 updateRow = null;
3440 } catch (Exception e) {
3441 throw logAndConvert(e);
3442 }
3443 }
3444
3445 // =============================================================
3446
3447 private UpdatableRow getUpdatableRow() throws SQLException {
3448 UpdatableRow row = new UpdatableRow(conn, result);
3449 if (!row.isUpdatable()) {
3450 throw DbException.get(ErrorCode.RESULT_SET_NOT_UPDATABLE);
3451 }
3452 return row;
3453 }
3454
3455 private int getColumnIndex(String columnLabel) {
3456 checkClosed();
3457 if (columnLabel == null) {
3458 throw DbException.getInvalidValueException("columnLabel", null);
3459 }
3460 if (columnCount >= 3) {
3461 // use a hash table if more than 2 columns
3462 if (columnLabelMap == null) {
3463 HashMap<String, Integer> map = new HashMap<>();
3464 // column labels have higher priority
3465 for (int i = 0; i < columnCount; i++) {
3466 String c = StringUtils.toUpperEnglish(result.getAlias(i));
3467 // Don't override previous mapping
3468 map.putIfAbsent(c, i);
3469 }
3470 for (int i = 0; i < columnCount; i++) {
3471 String colName = result.getColumnName(i);
3472 if (colName != null) {
3473 colName = StringUtils.toUpperEnglish(colName);
3474 // Don't override previous mapping
3475 map.putIfAbsent(colName, i);
3476 String tabName = result.getTableName(i);
3477 if (tabName != null) {
3478 colName = StringUtils.toUpperEnglish(tabName) + '.' + colName;
3479 // Don't override previous mapping
3480 map.putIfAbsent(colName, i);
3481 }
3482 }
3483 }
3484 // assign at the end so concurrent access is supported
3485 columnLabelMap = map;
3486 if (preparedStatement != null) {
3487 preparedStatement.setCachedColumnLabelMap(columnLabelMap);
3488 }
3489 }
3490 Integer index = columnLabelMap.get(StringUtils.toUpperEnglish(columnLabel));
3491 if (index == null) {
3492 throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
3493 }
3494 return index + 1;
3495 }
3496 for (int i = 0; i < columnCount; i++) {
3497 if (columnLabel.equalsIgnoreCase(result.getAlias(i))) {
3498 return i + 1;
3499 }
3500 }
3501 int idx = columnLabel.indexOf('.');
3502 if (idx > 0) {
3503 String table = columnLabel.substring(0, idx);
3504 String col = columnLabel.substring(idx+1);
3505 for (int i = 0; i < columnCount; i++) {
3506 if (table.equalsIgnoreCase(result.getTableName(i)) &&
3507 col.equalsIgnoreCase(result.getColumnName(i))) {
3508 return i + 1;
3509 }
3510 }
3511 } else {
3512 for (int i = 0; i < columnCount; i++) {
3513 if (columnLabel.equalsIgnoreCase(result.getColumnName(i))) {
3514 return i + 1;
3515 }
3516 }
3517 }
3518 throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel);
3519 }
3520
3521 private int checkColumnIndex(int columnIndex) {
3522 checkClosed();
3523 if (columnIndex < 1 || columnIndex > columnCount) {
3524 throw DbException.getInvalidValueException("columnIndex", columnIndex);
3525 }
3526 return columnIndex;
3527 }
3528
3529 /**
3530 * Check if this result set is closed.
3531 *
3532 * @throws DbException if it is closed
3533 */
3534 void checkClosed() {
3535 if (result == null) {
3536 throw DbException.get(ErrorCode.OBJECT_CLOSED);
3537 }
3538 if (stat != null) {
3539 stat.checkClosed();
3540 }
3541 if (conn != null) {
3542 conn.checkClosed();
3543 }
3544 }
3545
3546 private boolean isOnValidRow() {
3547 return result.getRowId() >= 0 && !result.isAfterLast();
3548 }
3549
3550 private void checkOnValidRow() {
3551 if (!isOnValidRow()) {
3552 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
3553 }
3554 }
3555
3556 private Value get(int columnIndex) {
3557 Value value = getInternal(columnIndex);
3558 wasNull = value == ValueNull.INSTANCE;
3559 return value;
3560 }
3561
3562 /**
3563 * INTERNAL
3564 *
3565 * @param columnIndex
3566 * index of a column
3567 * @return internal representation of the value in the specified column
3568 */
3569 public Value getInternal(int columnIndex) {
3570 checkOnValidRow();
3571 Value[] list;
3572 if (patchedRows == null || (list = patchedRows.get(result.getRowId())) == null) {
3573 list = result.currentRow();
3574 }
3575 return list[columnIndex - 1];
3576 }
3577
3578 private void update(int columnIndex, Value v) {
3579 if (!triggerUpdatable) {
3580 checkUpdatable();
3581 }
3582 if (insertRow != null) {
3583 insertRow[columnIndex - 1] = v;
3584 } else {
3585 if (updateRow == null) {
3586 updateRow = new Value[columnCount];
3587 }
3588 updateRow[columnIndex - 1] = v;
3589 }
3590 }
3591
3592 private boolean nextRow() {
3593 boolean next = result.isLazy() ? nextLazyRow() : result.next();
3594 if (!next && !scrollable) {
3595 result.close();
3596 }
3597 return next;
3598 }
3599
3600 private boolean nextLazyRow() {
3601 Session session;
3602 if (stat.isCancelled() || conn == null || (session = conn.getSession()) == null) {
3603 throw DbException.get(ErrorCode.STATEMENT_WAS_CANCELED);
3604 }
3605 Session oldSession = session.setThreadLocalSession();
3606 boolean next;
3607 try {
3608 next = result.next();
3609 } finally {
3610 session.resetThreadLocalSession(oldSession);
3611 }
3612 return next;
3613 }
3614
3615 private void resetResult() {
3616 if (!scrollable) {
3617 throw DbException.get(ErrorCode.RESULT_SET_NOT_SCROLLABLE);
3618 }
3619 result.reset();
3620 }
3621
3622 /**
3623 * [Not supported] Returns the value of the specified column as a row id.
3624 *
3625 * @param columnIndex (1,2,...)
3626 */
3627 @Override
3628 public RowId getRowId(int columnIndex) throws SQLException {
3629 throw unsupported("rowId");
3630 }
3631
3632 /**
3633 * [Not supported] Returns the value of the specified column as a row id.
3634 *
3635 * @param columnLabel the column label
3636 */
3637 @Override
3638 public RowId getRowId(String columnLabel) throws SQLException {
3639 throw unsupported("rowId");
3640 }
3641
3642 /**
3643 * [Not supported] Updates a column in the current or insert row.
3644 *
3645 * @param columnIndex (1,2,...)
3646 * @param x the value
3647 */
3648 @Override
3649 public void updateRowId(int columnIndex, RowId x) throws SQLException {
3650 throw unsupported("rowId");
3651 }
3652
3653 /**
3654 * [Not supported] Updates a column in the current or insert row.
3655 *
3656 * @param columnLabel the column label
3657 * @param x the value
3658 */
3659 @Override
3660 public void updateRowId(String columnLabel, RowId x) throws SQLException {
3661 throw unsupported("rowId");
3662 }
3663
3664 /**
3665 * Returns the current result set holdability.
3666 *
3667 * @return the holdability
3668 * @throws SQLException if the connection is closed
3669 */
3670 @Override
3671 public int getHoldability() throws SQLException {
3672 try {
3673 debugCodeCall("getHoldability");
3674 checkClosed();
3675 return conn.getHoldability();
3676 } catch (Exception e) {
3677 throw logAndConvert(e);
3678 }
3679 }
3680
3681 /**
3682 * Returns whether this result set is closed.
3683 *
3684 * @return true if the result set is closed
3685 */
3686 @Override
3687 public boolean isClosed() throws SQLException {
3688 try {
3689 debugCodeCall("isClosed");
3690 return result == null;
3691 } catch (Exception e) {
3692 throw logAndConvert(e);
3693 }
3694 }
3695
3696 /**
3697 * Updates a column in the current or insert row.
3698 *
3699 * @param columnIndex (1,2,...)
3700 * @param x the value
3701 * @throws SQLException if the result set is closed or not updatable
3702 */
3703 @Override
3704 public void updateNString(int columnIndex, String x) throws SQLException {
3705 try {
3706 if (isDebugEnabled()) {
3707 debugCode("updateNString(" + columnIndex + ", " + quote(x) + ')');
3708 }
3709 update(checkColumnIndex(columnIndex), x == null ? ValueNull.INSTANCE : ValueVarchar.get(x, conn));
3710 } catch (Exception e) {
3711 throw logAndConvert(e);
3712 }
3713 }
3714
3715 /**
3716 * Updates a column in the current or insert row.
3717 *
3718 * @param columnLabel the column label
3719 * @param x the value
3720 * @throws SQLException if the result set is closed or not updatable
3721 */
3722 @Override
3723 public void updateNString(String columnLabel, String x) throws SQLException {
3724 try {
3725 if (isDebugEnabled()) {
3726 debugCode("updateNString(" + quote(columnLabel) + ", " + quote(x) + ')');
3727 }
3728 update(getColumnIndex(columnLabel), x == null ? ValueNull.INSTANCE : ValueVarchar.get(x, conn));
3729 } catch (Exception e) {
3730 throw logAndConvert(e);
3731 }
3732 }
3733
3734 /**
3735 * Updates a column in the current or insert row.
3736 *
3737 * @param columnIndex (1,2,...)
3738 * @param x the value
3739 * @throws SQLException if the result set is closed or not updatable
3740 */
3741 @Override
3742 public void updateNClob(int columnIndex, NClob x) throws SQLException {
3743 try {
3744 if (isDebugEnabled()) {
3745 debugCode("updateNClob(" + columnIndex + ", (NClob) x)");
3746 }
3747 updateClobImpl(checkColumnIndex(columnIndex), x);
3748 } catch (Exception e) {
3749 throw logAndConvert(e);
3750 }
3751 }
3752
3753 /**
3754 * Updates a column in the current or insert row.
3755 *
3756 * @param columnIndex (1,2,...)
3757 * @param x the value
3758 * @throws SQLException if the result set is closed or not updatable
3759 */
3760 @Override
3761 public void updateNClob(int columnIndex, Reader x) throws SQLException {
3762 try {
3763 if (isDebugEnabled()) {
3764 debugCode("updateNClob(" + columnIndex + ", (Reader) x)");
3765 }
3766 updateClobImpl(checkColumnIndex(columnIndex), x, -1L);
3767 } catch (Exception e) {
3768 throw logAndConvert(e);
3769 }
3770 }
3771
3772 /**
3773 * Updates a column in the current or insert row.
3774 *
3775 * @param columnIndex (1,2,...)
3776 * @param x the value
3777 * @param length the length
3778 * @throws SQLException if the result set is closed or not updatable
3779 */
3780 @Override
3781 public void updateNClob(int columnIndex, Reader x, long length) throws SQLException {
3782 try {
3783 if (isDebugEnabled()) {
3784 debugCode("updateNClob(" + columnIndex + ", (Reader) x, " + length + "L)");
3785 }
3786 updateClobImpl(checkColumnIndex(columnIndex), x, length);
3787 } catch (Exception e) {
3788 throw logAndConvert(e);
3789 }
3790 }
3791
3792 /**
3793 * Updates a column in the current or insert row.
3794 *
3795 * @param columnLabel the column label
3796 * @param x the value
3797 * @throws SQLException if the result set is closed or not updatable
3798 */
3799 @Override
3800 public void updateNClob(String columnLabel, Reader x) throws SQLException {
3801 try {
3802 if (isDebugEnabled()) {
3803 debugCode("updateNClob(" + quote(columnLabel) + ", (Reader) x)");
3804 }
3805 updateClobImpl(getColumnIndex(columnLabel), x, -1L);
3806 } catch (Exception e) {
3807 throw logAndConvert(e);
3808 }
3809 }
3810
3811 /**
3812 * Updates a column in the current or insert row.
3813 *
3814 * @param columnLabel the column label
3815 * @param x the value
3816 * @param length the length
3817 * @throws SQLException if the result set is closed or not updatable
3818 */
3819 @Override
3820 public void updateNClob(String columnLabel, Reader x, long length) throws SQLException {
3821 try {
3822 if (isDebugEnabled()) {
3823 debugCode("updateNClob(" + quote(columnLabel) + ", (Reader) x, " + length + "L)");
3824 }
3825 updateClobImpl(getColumnIndex(columnLabel), x, length);
3826 } catch (Exception e) {
3827 throw logAndConvert(e);
3828 }
3829 }
3830
3831 /**
3832 * Updates a column in the current or insert row.
3833 *
3834 * @param columnLabel the column label
3835 * @param x the value
3836 * @throws SQLException if the result set is closed or not updatable
3837 */
3838 @Override
3839 public void updateNClob(String columnLabel, NClob x) throws SQLException {
3840 try {
3841 if (isDebugEnabled()) {
3842 debugCode("updateNClob(" + quote(columnLabel) + ", (NClob) x)");
3843 }
3844 updateClobImpl(getColumnIndex(columnLabel), x);
3845 } catch (Exception e) {
3846 throw logAndConvert(e);
3847 }
3848 }
3849
3850 private void updateClobImpl(int columnIndex, Clob x) throws SQLException {
3851 update(columnIndex, x == null ? ValueNull.INSTANCE : conn.createClob(x.getCharacterStream(), -1));
3852 }
3853
3854 /**
3855 * Returns the value of the specified column as a Clob.
3856 *
3857 * @param columnIndex (1,2,...)
3858 * @return the value
3859 * @throws SQLException if the column is not found or if the result set is
3860 * closed
3861 */
3862 @Override
3863 public NClob getNClob(int columnIndex) throws SQLException {
3864 try {
3865 int id = getNextId(TraceObject.CLOB);
3866 if (isDebugEnabled()) {
3867 debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + columnIndex + ')');
3868 }
3869 return getClob(id, checkColumnIndex(columnIndex));
3870 } catch (Exception e) {
3871 throw logAndConvert(e);
3872 }
3873 }
3874
3875 /**
3876 * Returns the value of the specified column as a Clob.
3877 *
3878 * @param columnLabel the column label
3879 * @return the value
3880 * @throws SQLException if the column is not found or if the result set is
3881 * closed
3882 */
3883 @Override
3884 public NClob getNClob(String columnLabel) throws SQLException {
3885 try {
3886 int id = getNextId(TraceObject.CLOB);
3887 if (isDebugEnabled()) {
3888 debugCodeAssign("NClob", TraceObject.CLOB, id, "getNClob(" + quote(columnLabel) + ')');
3889 }
3890 return getClob(id, getColumnIndex(columnLabel));
3891 } catch (Exception e) {
3892 throw logAndConvert(e);
3893 }
3894 }
3895
3896 private JdbcClob getClob(int id, int columnIndex) {
3897 Value v = getInternal(columnIndex);
3898 JdbcClob result;
3899 if (v != ValueNull.INSTANCE) {
3900 wasNull = false;
3901 result = new JdbcClob(conn, v, JdbcLob.State.WITH_VALUE, id);
3902 } else {
3903 wasNull = true;
3904 result = null;
3905 }
3906 return result;
3907 }
3908
3909 /**
3910 * Returns the value of the specified column as a SQLXML.
3911 *
3912 * @param columnIndex (1,2,...)
3913 * @return the value
3914 * @throws SQLException if the column is not found or if the result set is
3915 * closed
3916 */
3917 @Override
3918 public SQLXML getSQLXML(int columnIndex) throws SQLException {
3919 try {
3920 int id = getNextId(TraceObject.SQLXML);
3921 if (isDebugEnabled()) {
3922 debugCodeAssign("SQLXML", TraceObject.SQLXML, id, "getSQLXML(" + columnIndex + ')');
3923 }
3924 Value v = get(checkColumnIndex(columnIndex));
3925 return v == ValueNull.INSTANCE ? null : new JdbcSQLXML(conn, v, JdbcLob.State.WITH_VALUE, id);
3926 } catch (Exception e) {
3927 throw logAndConvert(e);
3928 }
3929 }
3930
3931 /**
3932 * Returns the value of the specified column as a SQLXML.
3933 *
3934 * @param columnLabel the column label
3935 * @return the value
3936 * @throws SQLException if the column is not found or if the result set is
3937 * closed
3938 */
3939 @Override
3940 public SQLXML getSQLXML(String columnLabel) throws SQLException {
3941 try {
3942 int id = getNextId(TraceObject.SQLXML);
3943 if (isDebugEnabled()) {
3944 debugCodeAssign("SQLXML", TraceObject.SQLXML, id, "getSQLXML(" + quote(columnLabel) + ')');
3945 }
3946 Value v = get(getColumnIndex(columnLabel));
3947 return v == ValueNull.INSTANCE ? null : new JdbcSQLXML(conn, v, JdbcLob.State.WITH_VALUE, id);
3948 } catch (Exception e) {
3949 throw logAndConvert(e);
3950 }
3951 }
3952
3953 /**
3954 * Updates a column in the current or insert row.
3955 *
3956 * @param columnIndex (1,2,...)
3957 * @param xmlObject the value
3958 * @throws SQLException if the result set is closed or not updatable
3959 */
3960 @Override
3961 public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException {
3962 try {
3963 if (isDebugEnabled()) {
3964 debugCode("updateSQLXML(" + columnIndex + ", x)");
3965 }
3966 updateSQLXMLImpl(checkColumnIndex(columnIndex), xmlObject);
3967 } catch (Exception e) {
3968 throw logAndConvert(e);
3969 }
3970 }
3971
3972 /**
3973 * Updates a column in the current or insert row.
3974 *
3975 * @param columnLabel the column label
3976 * @param xmlObject the value
3977 * @throws SQLException if the result set is closed or not updatable
3978 */
3979 @Override
3980 public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException {
3981 try {
3982 if (isDebugEnabled()) {
3983 debugCode("updateSQLXML(" + quote(columnLabel) + ", x)");
3984 }
3985 updateSQLXMLImpl(getColumnIndex(columnLabel), xmlObject);
3986 } catch (Exception e) {
3987 throw logAndConvert(e);
3988 }
3989 }
3990
3991 private void updateSQLXMLImpl(int columnIndex, SQLXML xmlObject) throws SQLException {
3992 update(columnIndex,
3993 xmlObject == null ? ValueNull.INSTANCE : conn.createClob(xmlObject.getCharacterStream(), -1));
3994 }
3995
3996 /**
3997 * Returns the value of the specified column as a String.
3998 *
3999 * @param columnIndex (1,2,...)
4000 * @return the value
4001 * @throws SQLException if the column is not found or if the result set is
4002 * closed
4003 */
4004 @Override
4005 public String getNString(int columnIndex) throws SQLException {
4006 try {
4007 debugCodeCall("getNString", columnIndex);
4008 return get(checkColumnIndex(columnIndex)).getString();
4009 } catch (Exception e) {
4010 throw logAndConvert(e);
4011 }
4012 }
4013
4014 /**
4015 * Returns the value of the specified column as a String.
4016 *
4017 * @param columnLabel the column label
4018 * @return the value
4019 * @throws SQLException if the column is not found or if the result set is
4020 * closed
4021 */
4022 @Override
4023 public String getNString(String columnLabel) throws SQLException {
4024 try {
4025 debugCodeCall("getNString", columnLabel);
4026 return get(getColumnIndex(columnLabel)).getString();
4027 } catch (Exception e) {
4028 throw logAndConvert(e);
4029 }
4030 }
4031
4032 /**
4033 * Returns the value of the specified column as a reader.
4034 *
4035 * @param columnIndex (1,2,...)
4036 * @return the value
4037 * @throws SQLException if the column is not found or if the result set is
4038 * closed
4039 */
4040 @Override
4041 public Reader getNCharacterStream(int columnIndex) throws SQLException {
4042 try {
4043 debugCodeCall("getNCharacterStream", columnIndex);
4044 return get(checkColumnIndex(columnIndex)).getReader();
4045 } catch (Exception e) {
4046 throw logAndConvert(e);
4047 }
4048 }
4049
4050 /**
4051 * Returns the value of the specified column as a reader.
4052 *
4053 * @param columnLabel the column label
4054 * @return the value
4055 * @throws SQLException if the column is not found or if the result set is
4056 * closed
4057 */
4058 @Override
4059 public Reader getNCharacterStream(String columnLabel) throws SQLException {
4060 try {
4061 debugCodeCall("getNCharacterStream", columnLabel);
4062 return get(getColumnIndex(columnLabel)).getReader();
4063 } catch (Exception e) {
4064 throw logAndConvert(e);
4065 }
4066 }
4067
4068 /**
4069 * Updates a column in the current or insert row.
4070 *
4071 * @param columnIndex (1,2,...)
4072 * @param x the value
4073 * @throws SQLException if the result set is closed or not updatable
4074 */
4075 @Override
4076 public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException {
4077 try {
4078 if (isDebugEnabled()) {
4079 debugCode("updateNCharacterStream(" + columnIndex + ", x)");
4080 }
4081 updateClobImpl(checkColumnIndex(columnIndex), x, -1L);
4082 } catch (Exception e) {
4083 throw logAndConvert(e);
4084 }
4085 }
4086
4087 /**
4088 * Updates a column in the current or insert row.
4089 *
4090 * @param columnIndex (1,2,...)
4091 * @param x the value
4092 * @param length the number of characters
4093 * @throws SQLException if the result set is closed or not updatable
4094 */
4095 @Override
4096 public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException {
4097 try {
4098 if (isDebugEnabled()) {
4099 debugCode("updateNCharacterStream(" + columnIndex + ", x, " + length + "L)");
4100 }
4101 updateClobImpl(checkColumnIndex(columnIndex), x, length);
4102 } catch (Exception e) {
4103 throw logAndConvert(e);
4104 }
4105 }
4106
4107 /**
4108 * Updates a column in the current or insert row.
4109 *
4110 * @param columnLabel the column label
4111 * @param x the value
4112 * @throws SQLException if the result set is closed or not updatable
4113 */
4114 @Override
4115 public void updateNCharacterStream(String columnLabel, Reader x) throws SQLException {
4116 try {
4117 if (isDebugEnabled()) {
4118 debugCode("updateNCharacterStream(" + quote(columnLabel) + ", x)");
4119 }
4120 updateClobImpl(getColumnIndex(columnLabel), x, -1L);
4121 } catch (Exception e) {
4122 throw logAndConvert(e);
4123 }
4124 }
4125
4126 /**
4127 * Updates a column in the current or insert row.
4128 *
4129 * @param columnLabel the column label
4130 * @param x the value
4131 * @param length the number of characters
4132 * @throws SQLException if the result set is closed or not updatable
4133 */
4134 @Override
4135 public void updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
4136 try {
4137 if (isDebugEnabled()) {
4138 debugCode("updateNCharacterStream(" + quote(columnLabel) + ", x, " + length + "L)");
4139 }
4140 updateClobImpl(getColumnIndex(columnLabel), x, length);
4141 } catch (Exception e) {
4142 throw logAndConvert(e);
4143 }
4144 }
4145
4146 private void updateClobImpl(int columnIndex, Reader x, long length) {
4147 update(columnIndex, conn.createClob(x, length));
4148 }
4149
4150 /**
4151 * Return an object of this class if possible.
4152 *
4153 * @param iface the class
4154 * @return this
4155 */
4156 @Override
4157 @SuppressWarnings("unchecked")
4158 public <T> T unwrap(Class<T> iface) throws SQLException {
4159 try {
4160 if (isWrapperFor(iface)) {
4161 return (T) this;
4162 }
4163 throw DbException.getInvalidValueException("iface", iface);
4164 } catch (Exception e) {
4165 throw logAndConvert(e);
4166 }
4167 }
4168
4169 /**
4170 * Checks if unwrap can return an object of this class.
4171 *
4172 * @param iface the class
4173 * @return whether or not the interface is assignable from this class
4174 */
4175 @Override
4176 public boolean isWrapperFor(Class<?> iface) throws SQLException {
4177 return iface != null && iface.isAssignableFrom(getClass());
4178 }
4179
4180 /**
4181 * Returns a column value as a Java object of the specified type.
4182 *
4183 * @param columnIndex the column index (1, 2, ...)
4184 * @param type the class of the returned value
4185 * @return the value
4186 * @throws SQLException if the column is not found or if the result set is
4187 * closed
4188 */
4189 @Override
4190 public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
4191 try {
4192 if (type == null) {
4193 throw DbException.getInvalidValueException("type", type);
4194 }
4195 debugCodeCall("getObject", columnIndex);
4196 return ValueToObjectConverter.valueToObject(type, get(checkColumnIndex(columnIndex)), conn);
4197 } catch (Exception e) {
4198 throw logAndConvert(e);
4199 }
4200 }
4201
4202 /**
4203 * Returns a column value as a Java object of the specified type.
4204 *
4205 * @param columnName the column name
4206 * @param type the class of the returned value
4207 * @return the value
4208 */
4209 @Override
4210 public <T> T getObject(String columnName, Class<T> type) throws SQLException {
4211 try {
4212 if (type == null) {
4213 throw DbException.getInvalidValueException("type", type);
4214 }
4215 debugCodeCall("getObject", columnName);
4216 return ValueToObjectConverter.valueToObject(type, get(getColumnIndex(columnName)), conn);
4217 } catch (Exception e) {
4218 throw logAndConvert(e);
4219 }
4220 }
4221
4222 /**
4223 * INTERNAL
4224 */
4225 @Override
4226 public String toString() {
4227 return getTraceObjectName() + ": " + result;
4228 }
4229
4230 private void patchCurrentRow(Value[] row) {
4231 boolean changed = false;
4232 Value[] current = result.currentRow();
4233 CompareMode compareMode = conn.getCompareMode();
4234 for (int i = 0; i < row.length; i++) {
4235 if (row[i].compareTo(current[i], conn, compareMode) != 0) {
4236 changed = true;
4237 break;
4238 }
4239 }
4240 if (patchedRows == null) {
4241 patchedRows = new HashMap<>();
4242 }
4243 Long rowId = result.getRowId();
4244 if (!changed) {
4245 patchedRows.remove(rowId);
4246 } else {
4247 patchedRows.put(rowId, row);
4248 }
4249 }
4250
4251 private Value convertToValue(Object x, SQLType targetSqlType) {
4252 if (x == null) {
4253 return ValueNull.INSTANCE;
4254 } else {
4255 int type = DataType.convertSQLTypeToValueType(targetSqlType);
4256 Value v = ValueToObjectConverter.objectToValue(conn.getSession(), x, type);
4257 return v.convertTo(type, conn);
4258 }
4259 }
4260
4261 private Value convertToUnknownValue(Object x) {
4262 return ValueToObjectConverter.objectToValue(conn.getSession(), x, Value.UNKNOWN);
4263 }
4264
4265 private void checkUpdatable() {
4266 checkClosed();
4267 if (!updatable) {
4268 throw DbException.get(ErrorCode.RESULT_SET_READONLY);
4269 }
4270 }
4271
4272 /**
4273 * INTERNAL
4274 *
4275 * @return array of column values for the current row
4276 */
4277 public Value[] getUpdateRow() {
4278 return updateRow;
4279 }
4280
4281 /**
4282 * INTERNAL
4283 *
4284 * @return result
4285 */
4286 public ResultInterface getResult() {
4287 return result;
4288 }
4289
4290 }