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

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.tools;
8
9 import java.io.InputStream;
10 import java.io.Reader;
11 import java.math.BigDecimal;
12 import java.net.URL;
13 import java.sql.Array;
14 import java.sql.Blob;
15 import java.sql.Clob;
16 import java.sql.Date;
17 import java.sql.Ref;
18 import java.sql.ResultSet;
19 import java.sql.ResultSetMetaData;
20 import java.sql.SQLException;
21 import java.sql.SQLWarning;
22 import java.sql.Statement;
23 import java.sql.Time;
24 import java.sql.Timestamp;
25 import java.sql.Types;
26 import java.util.ArrayList;
27 import java.util.Calendar;
28 import java.util.Map;
29 import org.h2.constant.ErrorCode;
30 import org.h2.message.DbException;
31 import org.h2.util.MathUtils;
32 import org.h2.util.New;
33 import org.h2.value.DataType;
34
35 //## Java 1.6 ##
36 import java.sql.NClob;
37 import java.sql.RowId;
38 import java.sql.SQLXML;
39 //*/
40
41 /**
42 * This class is a simple result set and meta data implementation.
43 * It can be used in Java functions that return a result set.
44 * Only the most basic methods are implemented, the others throw an exception.
45 * This implementation is standalone, and only relies on standard classes.
46 * It can be extended easily if required.
47 *
48 * An application can create a result set using the following code:
49 *
50 * <pre>
51 * SimpleResultSet rs = new SimpleResultSet();
52 * rs.addColumn(&quot;ID&quot;, Types.INTEGER, 10, 0);
53 * rs.addColumn(&quot;NAME&quot;, Types.VARCHAR, 255, 0);
54 * rs.addRow(0, &quot;Hello&quot; });
55 * rs.addRow(1, &quot;World&quot; });
56 * </pre>
57 *
58 */
59 public class SimpleResultSet implements ResultSet, ResultSetMetaData {
60
61 private ArrayList<Object[]> rows;
62 private Object[] currentRow;
63 private int rowId = -1;
64 private boolean wasNull;
65 private SimpleRowSource source;
66 private ArrayList<Column> columns = New.arrayList();
67 private boolean autoClose = true;
68
69 /**
70 * This class holds the data of a result column.
71 */
72 static class Column {
73
74 /**
75 * The column label.
76 */
77 String name;
78
79 /**
80 * The SQL type.
81 */
82 int sqlType;
83
84 /**
85 * The precision.
86 */
87 int precision;
88
89 /**
90 * The scale.
91 */
92 int scale;
93 }
94
95 /**
96 * A simple array implementation,
97 * backed by an object array
98 */
99 public static class SimpleArray implements Array {
100
101 private final Object[] value;
102
103 SimpleArray(Object[] value) {
104 this.value = value;
105 }
106
107 /**
108 * Get the object array.
109 *
110 * @return the object array
111 */
112 public Object getArray() {
113 return value;
114 }
115
116 /**
117 * INTERNAL
118 */
119 public Object getArray(Map<String, Class<?>> map) throws SQLException {
120 throw getUnsupportedException();
121 }
122
123 /**
124 * INTERNAL
125 */
126 public Object getArray(long index, int count) throws SQLException {
127 throw getUnsupportedException();
128 }
129
130 /**
131 * INTERNAL
132 */
133 public Object getArray(long index, int count, Map<String, Class<?>> map) throws SQLException {
134 throw getUnsupportedException();
135 }
136
137 /**
138 * Get the base type of this array.
139 *
140 * @return Types.NULL
141 */
142 public int getBaseType() {
143 return Types.NULL;
144 }
145
146 /**
147 * Get the base type name of this array.
148 *
149 * @return "NULL"
150 */
151 public String getBaseTypeName() {
152 return "NULL";
153 }
154
155 /**
156 * INTERNAL
157 */
158 public ResultSet getResultSet() throws SQLException {
159 throw getUnsupportedException();
160 }
161
162 /**
163 * INTERNAL
164 */
165 public ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
166 throw getUnsupportedException();
167 }
168
169 /**
170 * INTERNAL
171 */
172 public ResultSet getResultSet(long index, int count) throws SQLException {
173 throw getUnsupportedException();
174 }
175
176 /**
177 * INTERNAL
178 */
179 public ResultSet getResultSet(long index, int count, Map<String, Class<?>> map) throws SQLException {
180 throw getUnsupportedException();
181 }
182
183 /**
184 * INTERNAL
185 */
186 public void free() {
187 // nothing to do
188 }
189
190 }
191
192 /**
193 * This constructor is used if the result set is later populated with addRow.
194 */
195 public SimpleResultSet() {
196 rows = New.arrayList();
197 }
198
199 /**
200 * This constructor is used if the result set should retrieve the rows using
201 * the specified row source object.
202 *
203 * @param source the row source
204 */
205 public SimpleResultSet(SimpleRowSource source) {
206 this.source = source;
207 }
208
209 /**
210 * Adds a column to the result set.
211 * All columns must be added before adding rows.
212 *
213 * @param name null is replaced with C1, C2,...
214 * @param sqlType the value returned in getColumnType(..) (ignored internally)
215 * @param precision the precision
216 * @param scale the scale
217 */
218 public void addColumn(String name, int sqlType, int precision, int scale) {
219 if (rows != null && rows.size() > 0) {
220 throw new IllegalStateException("Cannot add a column after adding rows");
221 }
222 if (name == null) {
223 name = "C" + (columns.size() + 1);
224 }
225 Column column = new Column();
226 column.name = name;
227 column.sqlType = sqlType;
228 column.precision = precision;
229 column.scale = scale;
230 columns.add(column);
231 }
232
233 /**
234 * Add a new row to the result set.
235 * Do not use this method when using a RowSource.
236 *
237 * @param row the row as an array of objects
238 */
239 public void addRow(Object... row) {
240 if (rows == null) {
241 throw new IllegalStateException("Cannot add a row when using RowSource");
242 }
243 rows.add(row);
244 }
245
246 /**
247 * Returns ResultSet.CONCUR_READ_ONLY.
248 *
249 * @return CONCUR_READ_ONLY
250 */
251 public int getConcurrency() {
252 return ResultSet.CONCUR_READ_ONLY;
253 }
254
255 /**
256 * Returns ResultSet.FETCH_FORWARD.
257 *
258 * @return FETCH_FORWARD
259 */
260 public int getFetchDirection() {
261 return ResultSet.FETCH_FORWARD;
262 }
263
264 /**
265 * Returns 0.
266 *
267 * @return 0
268 */
269 public int getFetchSize() {
270 return 0;
271 }
272
273 /**
274 * Returns the row number (1, 2,...) or 0 for no row.
275 *
276 * @return 0
277 */
278 public int getRow() {
279 return rowId + 1;
280 }
281
282 /**
283 * Returns ResultSet.TYPE_FORWARD_ONLY.
284 *
285 * @return TYPE_FORWARD_ONLY
286 */
287 public int getType() {
288 return ResultSet.TYPE_FORWARD_ONLY;
289 }
290
291 /**
292 * Closes the result set and releases the resources.
293 */
294 public void close() {
295 currentRow = null;
296 rows = null;
297 columns = null;
298 rowId = -1;
299 if (source != null) {
300 source.close();
301 source = null;
302 }
303 }
304
305 /**
306 * Moves the cursor to the next row of the result set.
307 *
308 * @return true if successful, false if there are no more rows
309 */
310 public boolean next() throws SQLException {
311 if (source != null) {
312 rowId++;
313 currentRow = source.readRow();
314 if (currentRow != null) {
315 return true;
316 }
317 } else if (rows != null && rowId < rows.size()) {
318 rowId++;
319 if (rowId < rows.size()) {
320 currentRow = rows.get(rowId);
321 return true;
322 }
323 }
324 if (autoClose) {
325 close();
326 }
327 return false;
328 }
329
330 /**
331 * Moves the current position to before the first row, that means resets the
332 * result set.
333 */
334 public void beforeFirst() throws SQLException {
335 rowId = -1;
336 if (source != null) {
337 source.reset();
338 }
339 }
340
341 /**
342 * Returns whether the last column accessed was null.
343 *
344 * @return true if the last column accessed was null
345 */
346 public boolean wasNull() {
347 return wasNull;
348 }
349
350 /**
351 * Searches for a specific column in the result set. A case-insensitive
352 * search is made.
353 *
354 * @param columnLabel the column label
355 * @return the column index (1,2,...)
356 * @throws SQLException if the column is not found or if the result set is
357 * closed
358 */
359 public int findColumn(String columnLabel) throws SQLException {
360 if (columnLabel != null && columns != null) {
361 for (int i = 0, size = columns.size(); i < size; i++) {
362 if (columnLabel.equalsIgnoreCase(getColumn(i).name)) {
363 return i + 1;
364 }
365 }
366 }
367 throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, columnLabel).getSQLException();
368 }
369
370 /**
371 * Returns a reference to itself.
372 *
373 * @return this
374 */
375 public ResultSetMetaData getMetaData() {
376 return this;
377 }
378
379 /**
380 * Returns null.
381 *
382 * @return null
383 */
384 public SQLWarning getWarnings() {
385 return null;
386 }
387
388 /**
389 * Returns null.
390 *
391 * @return null
392 */
393 public Statement getStatement() {
394 return null;
395 }
396
397 /**
398 * INTERNAL
399 */
400 public void clearWarnings() {
401 // nothing to do
402 }
403
404 // ---- get ---------------------------------------------
405
406 /**
407 * Returns the value as a java.sql.Array.
408 *
409 * @param columnIndex (1,2,...)
410 * @return the value
411 */
412 public Array getArray(int columnIndex) throws SQLException {
413 Object[] o = (Object[]) get(columnIndex);
414 return o == null ? null : new SimpleArray(o);
415 }
416
417 /**
418 * Returns the value as a java.sql.Array.
419 *
420 * @param columnLabel the column label
421 * @return the value
422 */
423 public Array getArray(String columnLabel) throws SQLException {
424 return getArray(findColumn(columnLabel));
425 }
426
427 /**
428 * INTERNAL
429 */
430 public InputStream getAsciiStream(int columnIndex) throws SQLException {
431 throw getUnsupportedException();
432 }
433
434 /**
435 * INTERNAL
436 */
437 public InputStream getAsciiStream(String columnLabel) throws SQLException {
438 throw getUnsupportedException();
439 }
440
441 /**
442 * Returns the value as a java.math.BigDecimal.
443 *
444 * @param columnIndex (1,2,...)
445 * @return the value
446 */
447 public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
448 Object o = get(columnIndex);
449 if (o != null && !(o instanceof BigDecimal)) {
450 o = new BigDecimal(o.toString());
451 }
452 return (BigDecimal) o;
453 }
454
455 /**
456 * Returns the value as a java.math.BigDecimal.
457 *
458 * @param columnLabel the column label
459 * @return the value
460 */
461 public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
462 return getBigDecimal(findColumn(columnLabel));
463 }
464
465 /**
466 * @deprecated INTERNAL
467 */
468 public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
469 throw getUnsupportedException();
470 }
471
472 /**
473 * @deprecated INTERNAL
474 */
475 public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
476 throw getUnsupportedException();
477 }
478
479 /**
480 * Returns the value as a java.io.InputStream.
481 *
482 * @param columnIndex (1,2,...)
483 * @return the value
484 */
485 public InputStream getBinaryStream(int columnIndex) throws SQLException {
486 return asInputStream(get(columnIndex));
487 }
488
489 private static InputStream asInputStream(Object o) throws SQLException {
490 if (o == null) {
491 return null;
492 } else if (o instanceof Blob) {
493 return ((Blob) o).getBinaryStream();
494 }
495 return (InputStream) o;
496 }
497
498 /**
499 * Returns the value as a java.io.InputStream.
500 *
501 * @param columnLabel the column label
502 * @return the value
503 */
504 public InputStream getBinaryStream(String columnLabel) throws SQLException {
505 return getBinaryStream(findColumn(columnLabel));
506 }
507
508 /**
509 * Returns the value as a java.sql.Blob.
510 * This is only supported if the
511 * result set was created using a Blob object.
512 *
513 * @param columnIndex (1,2,...)
514 * @return the value
515 */
516 public Blob getBlob(int columnIndex) throws SQLException {
517 return (Blob) get(columnIndex);
518 }
519
520 /**
521 * Returns the value as a java.sql.Blob.
522 * This is only supported if the
523 * result set was created using a Blob object.
524 *
525 * @param columnLabel the column label
526 * @return the value
527 */
528 public Blob getBlob(String columnLabel) throws SQLException {
529 return getBlob(findColumn(columnLabel));
530 }
531
532 /**
533 * Returns the value as a boolean.
534 *
535 * @param columnIndex (1,2,...)
536 * @return the value
537 */
538 public boolean getBoolean(int columnIndex) throws SQLException {
539 Object o = get(columnIndex);
540 if (o != null && !(o instanceof Boolean)) {
541 o = Boolean.valueOf(o.toString());
542 }
543 return o == null ? false : ((Boolean) o).booleanValue();
544 }
545
546 /**
547 * Returns the value as a boolean.
548 *
549 * @param columnLabel the column label
550 * @return the value
551 */
552 public boolean getBoolean(String columnLabel) throws SQLException {
553 return getBoolean(findColumn(columnLabel));
554 }
555
556 /**
557 * Returns the value as a byte.
558 *
559 * @param columnIndex (1,2,...)
560 * @return the value
561 */
562 public byte getByte(int columnIndex) throws SQLException {
563 Object o = get(columnIndex);
564 if (o != null && !(o instanceof Number)) {
565 o = Byte.decode(o.toString());
566 }
567 return o == null ? 0 : ((Number) o).byteValue();
568 }
569
570 /**
571 * Returns the value as a byte.
572 *
573 * @param columnLabel the column label
574 * @return the value
575 */
576 public byte getByte(String columnLabel) throws SQLException {
577 return getByte(findColumn(columnLabel));
578 }
579
580 /**
581 * Returns the value as a byte array.
582 *
583 * @param columnIndex (1,2,...)
584 * @return the value
585 */
586 public byte[] getBytes(int columnIndex) throws SQLException {
587 return (byte[]) get(columnIndex);
588 }
589
590 /**
591 * Returns the value as a byte array.
592 *
593 * @param columnLabel the column label
594 * @return the value
595 */
596 public byte[] getBytes(String columnLabel) throws SQLException {
597 return getBytes(findColumn(columnLabel));
598 }
599
600 /**
601 * Returns the value as a java.io.Reader.
602 * This is only supported if the
603 * result set was created using a Clob or Reader object.
604 *
605 * @param columnIndex (1,2,...)
606 * @return the value
607 */
608 public Reader getCharacterStream(int columnIndex) throws SQLException {
609 return asReader(get(columnIndex));
610 }
611
612 private static Reader asReader(Object o) throws SQLException {
613 if (o == null) {
614 return null;
615 } else if (o instanceof Clob) {
616 return ((Clob) o).getCharacterStream();
617 }
618 return (Reader) o;
619 }
620
621 /**
622 * Returns the value as a java.io.Reader.
623 * This is only supported if the
624 * result set was created using a Clob or Reader object.
625 *
626 * @param columnLabel the column label
627 * @return the value
628 */
629 public Reader getCharacterStream(String columnLabel) throws SQLException {
630 return getCharacterStream(findColumn(columnLabel));
631 }
632
633 /**
634 * Returns the value as a java.sql.Clob.
635 * This is only supported if the
636 * result set was created using a Clob object.
637 *
638 * @param columnIndex (1,2,...)
639 * @return the value
640 */
641 public Clob getClob(int columnIndex) throws SQLException {
642 Clob c = (Clob) get(columnIndex);
643 return c == null ? null : c;
644 }
645
646 /**
647 * Returns the value as a java.sql.Clob.
648 * This is only supported if the
649 * result set was created using a Clob object.
650 *
651 * @param columnLabel the column label
652 * @return the value
653 */
654 public Clob getClob(String columnLabel) throws SQLException {
655 return getClob(findColumn(columnLabel));
656 }
657
658 /**
659 * Returns the value as an java.sql.Date.
660 *
661 * @param columnIndex (1,2,...)
662 * @return the value
663 */
664 public Date getDate(int columnIndex) throws SQLException {
665 return (Date) get(columnIndex);
666 }
667
668 /**
669 * Returns the value as a java.sql.Date.
670 *
671 * @param columnLabel the column label
672 * @return the value
673 */
674 public Date getDate(String columnLabel) throws SQLException {
675 return getDate(findColumn(columnLabel));
676 }
677
678 /**
679 * INTERNAL
680 */
681 public Date getDate(int columnIndex, Calendar cal) throws SQLException {
682 throw getUnsupportedException();
683 }
684
685 /**
686 * INTERNAL
687 */
688 public Date getDate(String columnLabel, Calendar cal) throws SQLException {
689 throw getUnsupportedException();
690 }
691
692 /**
693 * Returns the value as an double.
694 *
695 * @param columnIndex (1,2,...)
696 * @return the value
697 */
698 public double getDouble(int columnIndex) throws SQLException {
699 Object o = get(columnIndex);
700 if (o != null && !(o instanceof Number)) {
701 return Double.parseDouble(o.toString());
702 }
703 return o == null ? 0 : ((Number) o).doubleValue();
704 }
705
706 /**
707 * Returns the value as a double.
708 *
709 * @param columnLabel the column label
710 * @return the value
711 */
712 public double getDouble(String columnLabel) throws SQLException {
713 return getDouble(findColumn(columnLabel));
714 }
715
716 /**
717 * Returns the value as a float.
718 *
719 * @param columnIndex (1,2,...)
720 * @return the value
721 */
722 public float getFloat(int columnIndex) throws SQLException {
723 Object o = get(columnIndex);
724 if (o != null && !(o instanceof Number)) {
725 return Float.parseFloat(o.toString());
726 }
727 return o == null ? 0 : ((Number) o).floatValue();
728 }
729
730 /**
731 * Returns the value as a float.
732 *
733 * @param columnLabel the column label
734 * @return the value
735 */
736 public float getFloat(String columnLabel) throws SQLException {
737 return getFloat(findColumn(columnLabel));
738 }
739
740 /**
741 * Returns the value as an int.
742 *
743 * @param columnIndex (1,2,...)
744 * @return the value
745 */
746 public int getInt(int columnIndex) throws SQLException {
747 Object o = get(columnIndex);
748 if (o != null && !(o instanceof Number)) {
749 o = Integer.decode(o.toString());
750 }
751 return o == null ? 0 : ((Number) o).intValue();
752 }
753
754 /**
755 * Returns the value as an int.
756 *
757 * @param columnLabel the column label
758 * @return the value
759 */
760 public int getInt(String columnLabel) throws SQLException {
761 return getInt(findColumn(columnLabel));
762 }
763
764 /**
765 * Returns the value as a long.
766 *
767 * @param columnIndex (1,2,...)
768 * @return the value
769 */
770 public long getLong(int columnIndex) throws SQLException {
771 Object o = get(columnIndex);
772 if (o != null && !(o instanceof Number)) {
773 o = Long.decode(o.toString());
774 }
775 return o == null ? 0 : ((Number) o).longValue();
776 }
777
778 /**
779 * Returns the value as a long.
780 *
781 * @param columnLabel the column label
782 * @return the value
783 */
784 public long getLong(String columnLabel) throws SQLException {
785 return getLong(findColumn(columnLabel));
786 }
787
788 /**
789 * INTERNAL
790 */
791 //## Java 1.6 ##
792 public Reader getNCharacterStream(int columnIndex) throws SQLException {
793 throw getUnsupportedException();
794 }
795 //*/
796
797 /**
798 * INTERNAL
799 */
800 //## Java 1.6 ##
801 public Reader getNCharacterStream(String columnLabel) throws SQLException {
802 throw getUnsupportedException();
803 }
804 //*/
805
806 /**
807 * INTERNAL
808 */
809 //## Java 1.6 ##
810 public NClob getNClob(int columnIndex) throws SQLException {
811 throw getUnsupportedException();
812 }
813 //*/
814
815 /**
816 * INTERNAL
817 */
818 //## Java 1.6 ##
819 public NClob getNClob(String columnLabel) throws SQLException {
820 throw getUnsupportedException();
821 }
822 //*/
823
824 /**
825 * INTERNAL
826 */
827 //## Java 1.6 ##
828 public String getNString(int columnIndex) throws SQLException {
829 return getString(columnIndex);
830 }
831 //*/
832
833 /**
834 * INTERNAL
835 */
836 //## Java 1.6 ##
837 public String getNString(String columnLabel) throws SQLException {
838 return getString(columnLabel);
839 }
840 //*/
841
842 /**
843 * Returns the value as an Object.
844 *
845 * @param columnIndex (1,2,...)
846 * @return the value
847 */
848 public Object getObject(int columnIndex) throws SQLException {
849 return get(columnIndex);
850 }
851
852 /**
853 * Returns the value as an Object.
854 *
855 * @param columnLabel the column label
856 * @return the value
857 */
858 public Object getObject(String columnLabel) throws SQLException {
859 return getObject(findColumn(columnLabel));
860 }
861
862 /**
863 * INTERNAL
864 *
865 * @param columnIndex the column index (1, 2, ...)
866 * @param type the class of the returned value
867 */
868 /*## Java 1.7 ##
869 public <T> T getObject(int columnIndex, Class<T> type) {
870 return null;
871 }
872 //*/
873
874 /**
875 * INTERNAL
876 *
877 * @param columnName the column name
878 * @param type the class of the returned value
879 */
880 /*## Java 1.7 ##
881 public <T> T getObject(String columnName, Class<T> type) {
882 return null;
883 }
884 //*/
885
886 /**
887 * INTERNAL
888 */
889 public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLException {
890 throw getUnsupportedException();
891 }
892
893 /**
894 * INTERNAL
895 */
896 public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
897 throw getUnsupportedException();
898 }
899
900 /**
901 * INTERNAL
902 */
903 public Ref getRef(int columnIndex) throws SQLException {
904 throw getUnsupportedException();
905 }
906
907 /**
908 * INTERNAL
909 */
910 public Ref getRef(String columnLabel) throws SQLException {
911 throw getUnsupportedException();
912 }
913
914 /**
915 * INTERNAL
916 */
917 //## Java 1.6 ##
918 public RowId getRowId(int columnIndex) throws SQLException {
919 throw getUnsupportedException();
920 }
921 //*/
922
923 /**
924 * INTERNAL
925 */
926 //## Java 1.6 ##
927 public RowId getRowId(String columnLabel) throws SQLException {
928 throw getUnsupportedException();
929 }
930 //*/
931
932 /**
933 * Returns the value as a short.
934 *
935 * @param columnIndex (1,2,...)
936 * @return the value
937 */
938 public short getShort(int columnIndex) throws SQLException {
939 Object o = get(columnIndex);
940 if (o != null && !(o instanceof Number)) {
941 o = Short.decode(o.toString());
942 }
943 return o == null ? 0 : ((Number) o).shortValue();
944 }
945
946 /**
947 * Returns the value as a short.
948 *
949 * @param columnLabel the column label
950 * @return the value
951 */
952 public short getShort(String columnLabel) throws SQLException {
953 return getShort(findColumn(columnLabel));
954 }
955
956 /**
957 * INTERNAL
958 */
959 //## Java 1.6 ##
960 public SQLXML getSQLXML(int columnIndex) throws SQLException {
961 throw getUnsupportedException();
962 }
963 //*/
964
965 /**
966 * INTERNAL
967 */
968 //## Java 1.6 ##
969 public SQLXML getSQLXML(String columnLabel) throws SQLException {
970 throw getUnsupportedException();
971 }
972 //*/
973
974 /**
975 * Returns the value as a String.
976 *
977 * @param columnIndex (1,2,...)
978 * @return the value
979 */
980 public String getString(int columnIndex) throws SQLException {
981 Object o = get(columnIndex);
982 if (o == null) {
983 return null;
984 }
985 switch (columns.get(columnIndex - 1).sqlType) {
986 case Types.CLOB:
987 Clob c = (Clob) o;
988 return c.getSubString(1, MathUtils.convertLongToInt(c.length()));
989 }
990 return o.toString();
991 }
992
993 /**
994 * Returns the value as a String.
995 *
996 * @param columnLabel the column label
997 * @return the value
998 */
999 public String getString(String columnLabel) throws SQLException {
1000 return getString(findColumn(columnLabel));
1001 }
1002
1003 /**
1004 * Returns the value as an java.sql.Time.
1005 *
1006 * @param columnIndex (1,2,...)
1007 * @return the value
1008 */
1009 public Time getTime(int columnIndex) throws SQLException {
1010 return (Time) get(columnIndex);
1011 }
1012
1013 /**
1014 * Returns the value as a java.sql.Time.
1015 *
1016 * @param columnLabel the column label
1017 * @return the value
1018 */
1019 public Time getTime(String columnLabel) throws SQLException {
1020 return getTime(findColumn(columnLabel));
1021 }
1022
1023 /**
1024 * INTERNAL
1025 */
1026 public Time getTime(int columnIndex, Calendar cal) throws SQLException {
1027 throw getUnsupportedException();
1028 }
1029
1030 /**
1031 * INTERNAL
1032 */
1033 public Time getTime(String columnLabel, Calendar cal) throws SQLException {
1034 throw getUnsupportedException();
1035 }
1036
1037 /**
1038 * Returns the value as an java.sql.Timestamp.
1039 *
1040 * @param columnIndex (1,2,...)
1041 * @return the value
1042 */
1043 public Timestamp getTimestamp(int columnIndex) throws SQLException {
1044 return (Timestamp) get(columnIndex);
1045 }
1046
1047 /**
1048 * Returns the value as a java.sql.Timestamp.
1049 *
1050 * @param columnLabel the column label
1051 * @return the value
1052 */
1053 public Timestamp getTimestamp(String columnLabel) throws SQLException {
1054 return getTimestamp(findColumn(columnLabel));
1055 }
1056
1057 /**
1058 * INTERNAL
1059 */
1060 public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
1061 throw getUnsupportedException();
1062 }
1063
1064 /**
1065 * INTERNAL
1066 */
1067 public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException {
1068 throw getUnsupportedException();
1069 }
1070
1071 /**
1072 * @deprecated INTERNAL
1073 */
1074 public InputStream getUnicodeStream(int columnIndex) throws SQLException {
1075 throw getUnsupportedException();
1076 }
1077
1078 /**
1079 * @deprecated INTERNAL
1080 */
1081 public InputStream getUnicodeStream(String columnLabel) throws SQLException {
1082 throw getUnsupportedException();
1083 }
1084
1085 /**
1086 * INTERNAL
1087 */
1088 public URL getURL(int columnIndex) throws SQLException {
1089 throw getUnsupportedException();
1090 }
1091
1092 /**
1093 * INTERNAL
1094 */
1095 public URL getURL(String columnLabel) throws SQLException {
1096 throw getUnsupportedException();
1097 }
1098
1099 // ---- update ---------------------------------------------
1100
1101 /**
1102 * INTERNAL
1103 */
1104 public void updateArray(int columnIndex, Array x) throws SQLException {
1105 update(columnIndex, x);
1106 }
1107
1108 /**
1109 * INTERNAL
1110 */
1111 public void updateArray(String columnLabel, Array x) throws SQLException {
1112 update(columnLabel, x);
1113 }
1114
1115 /**
1116 * INTERNAL
1117 */
1118 //## Java 1.6 ##
1119 public void updateAsciiStream(int columnIndex, InputStream x)
1120 throws SQLException {
1121 update(columnIndex, x);
1122 }
1123 //*/
1124
1125 /**
1126 * INTERNAL
1127 */
1128 //## Java 1.6 ##
1129 public void updateAsciiStream(String columnLabel, InputStream x)
1130 throws SQLException {
1131 update(columnLabel, x);
1132 }
1133 //*/
1134
1135 /**
1136 * INTERNAL
1137 */
1138 public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
1139 update(columnIndex, x);
1140 }
1141
1142 /**
1143 * INTERNAL
1144 */
1145 public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
1146 update(columnLabel, x);
1147 }
1148
1149 /**
1150 * INTERNAL
1151 */
1152 //## Java 1.6 ##
1153 public void updateAsciiStream(int columnIndex, InputStream x, long length)
1154 throws SQLException {
1155 update(columnIndex, x);
1156 }
1157 //*/
1158
1159 /**
1160 * INTERNAL
1161 */
1162 //## Java 1.6 ##
1163 public void updateAsciiStream(String columnLabel, InputStream x, long length)
1164 throws SQLException {
1165 update(columnLabel, x);
1166 }
1167 //*/
1168
1169 /**
1170 * INTERNAL
1171 */
1172 public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
1173 update(columnIndex, x);
1174 }
1175
1176 /**
1177 * INTERNAL
1178 */
1179 public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
1180 update(columnLabel, x);
1181 }
1182
1183 /**
1184 * INTERNAL
1185 */
1186 //## Java 1.6 ##
1187 public void updateBinaryStream(int columnIndex, InputStream x)
1188 throws SQLException {
1189 update(columnIndex, x);
1190 }
1191 //*/
1192
1193 /**
1194 * INTERNAL
1195 */
1196 //## Java 1.6 ##
1197 public void updateBinaryStream(String columnLabel, InputStream x)
1198 throws SQLException {
1199 update(columnLabel, x);
1200 }
1201 //*/
1202
1203 /**
1204 * INTERNAL
1205 */
1206 public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
1207 update(columnIndex, x);
1208 }
1209
1210 /**
1211 * INTERNAL
1212 */
1213 public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
1214 update(columnLabel, x);
1215 }
1216
1217 /**
1218 * INTERNAL
1219 */
1220 //## Java 1.6 ##
1221 public void updateBinaryStream(int columnIndex, InputStream x, long length)
1222 throws SQLException {
1223 update(columnIndex, x);
1224 }
1225 //*/
1226
1227 /**
1228 * INTERNAL
1229 */
1230 //## Java 1.6 ##
1231 public void updateBinaryStream(String columnLabel, InputStream x, long length)
1232 throws SQLException {
1233 update(columnLabel, x);
1234 }
1235 //*/
1236
1237 /**
1238 * INTERNAL
1239 */
1240 public void updateBlob(int columnIndex, Blob x) throws SQLException {
1241 update(columnIndex, x);
1242 }
1243
1244 /**
1245 * INTERNAL
1246 */
1247 public void updateBlob(String columnLabel, Blob x) throws SQLException {
1248 update(columnLabel, x);
1249 }
1250
1251 /**
1252 * INTERNAL
1253 */
1254 //## Java 1.6 ##
1255 public void updateBlob(int columnIndex, InputStream x) throws SQLException {
1256 update(columnIndex, x);
1257 }
1258 //*/
1259
1260 /**
1261 * INTERNAL
1262 */
1263 //## Java 1.6 ##
1264 public void updateBlob(String columnLabel, InputStream x) throws SQLException {
1265 update(columnLabel, x);
1266 }
1267 //*/
1268
1269 /**
1270 * INTERNAL
1271 */
1272 //## Java 1.6 ##
1273 public void updateBlob(int columnIndex, InputStream x, long length)
1274 throws SQLException {
1275 update(columnIndex, x);
1276 }
1277 //*/
1278
1279 /**
1280 * INTERNAL
1281 */
1282 //## Java 1.6 ##
1283 public void updateBlob(String columnLabel, InputStream x, long length)
1284 throws SQLException {
1285 update(columnLabel, x);
1286 }
1287 //*/
1288
1289 /**
1290 * INTERNAL
1291 */
1292 public void updateBoolean(int columnIndex, boolean x) throws SQLException {
1293 update(columnIndex, x);
1294 }
1295
1296 /**
1297 * INTERNAL
1298 */
1299 public void updateBoolean(String columnLabel, boolean x) throws SQLException {
1300 update(columnLabel, x);
1301 }
1302
1303 /**
1304 * INTERNAL
1305 */
1306 public void updateByte(int columnIndex, byte x) throws SQLException {
1307 update(columnIndex, x);
1308 }
1309
1310 /**
1311 * INTERNAL
1312 */
1313 public void updateByte(String columnLabel, byte x) throws SQLException {
1314 update(columnLabel, x);
1315 }
1316
1317 /**
1318 * INTERNAL
1319 */
1320 public void updateBytes(int columnIndex, byte[] x) throws SQLException {
1321 update(columnIndex, x);
1322 }
1323
1324 /**
1325 * INTERNAL
1326 */
1327 public void updateBytes(String columnLabel, byte[] x) throws SQLException {
1328 update(columnLabel, x);
1329 }
1330
1331 /**
1332 * INTERNAL
1333 */
1334 //## Java 1.6 ##
1335 public void updateCharacterStream(int columnIndex, Reader x)
1336 throws SQLException {
1337 update(columnIndex, x);
1338 }
1339 //*/
1340
1341 /**
1342 * INTERNAL
1343 */
1344 //## Java 1.6 ##
1345 public void updateCharacterStream(String columnLabel, Reader x)
1346 throws SQLException {
1347 update(columnLabel, x);
1348 }
1349 //*/
1350
1351 /**
1352 * INTERNAL
1353 */
1354 public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
1355 update(columnIndex, x);
1356 }
1357
1358 /**
1359 * INTERNAL
1360 */
1361 public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException {
1362 update(columnLabel, x);
1363 }
1364
1365 /**
1366 * INTERNAL
1367 */
1368 //## Java 1.6 ##
1369 public void updateCharacterStream(int columnIndex, Reader x, long length)
1370 throws SQLException {
1371 update(columnIndex, x);
1372 }
1373 //*/
1374
1375 /**
1376 * INTERNAL
1377 */
1378 //## Java 1.6 ##
1379 public void updateCharacterStream(String columnLabel, Reader x, long length)
1380 throws SQLException {
1381 update(columnLabel, x);
1382 }
1383 //*/
1384
1385 /**
1386 * INTERNAL
1387 */
1388 public void updateClob(int columnIndex, Clob x) throws SQLException {
1389 update(columnIndex, x);
1390 }
1391
1392 /**
1393 * INTERNAL
1394 */
1395 public void updateClob(String columnLabel, Clob x) throws SQLException {
1396 update(columnLabel, x);
1397 }
1398
1399 /**
1400 * INTERNAL
1401 */
1402 //## Java 1.6 ##
1403 public void updateClob(int columnIndex, Reader x) throws SQLException {
1404 update(columnIndex, x);
1405 }
1406 //*/
1407
1408 /**
1409 * INTERNAL
1410 */
1411 //## Java 1.6 ##
1412 public void updateClob(String columnLabel, Reader x) throws SQLException {
1413 update(columnLabel, x);
1414 }
1415 //*/
1416
1417 /**
1418 * INTERNAL
1419 */
1420 //## Java 1.6 ##
1421 public void updateClob(int columnIndex, Reader x, long length)
1422 throws SQLException {
1423 update(columnIndex, x);
1424 }
1425 //*/
1426
1427 /**
1428 * INTERNAL
1429 */
1430 //## Java 1.6 ##
1431 public void updateClob(String columnLabel, Reader x, long length)
1432 throws SQLException {
1433 update(columnLabel, x);
1434 }
1435 //*/
1436
1437 /**
1438 * INTERNAL
1439 */
1440 public void updateDate(int columnIndex, Date x) throws SQLException {
1441 update(columnIndex, x);
1442 }
1443
1444 /**
1445 * INTERNAL
1446 */
1447 public void updateDate(String columnLabel, Date x) throws SQLException {
1448 update(columnLabel, x);
1449 }
1450
1451 /**
1452 * INTERNAL
1453 */
1454 public void updateDouble(int columnIndex, double x) throws SQLException {
1455 update(columnIndex, x);
1456 }
1457
1458 /**
1459 * INTERNAL
1460 */
1461 public void updateDouble(String columnLabel, double x) throws SQLException {
1462 update(columnLabel, x);
1463 }
1464
1465 /**
1466 * INTERNAL
1467 */
1468 public void updateFloat(int columnIndex, float x) throws SQLException {
1469 update(columnIndex, x);
1470 }
1471
1472 /**
1473 * INTERNAL
1474 */
1475 public void updateFloat(String columnLabel, float x) throws SQLException {
1476 update(columnLabel, x);
1477 }
1478
1479 /**
1480 * INTERNAL
1481 */
1482 public void updateInt(int columnIndex, int x) throws SQLException {
1483 update(columnIndex, x);
1484 }
1485
1486 /**
1487 * INTERNAL
1488 */
1489 public void updateInt(String columnLabel, int x) throws SQLException {
1490 update(columnLabel, x);
1491 }
1492
1493 /**
1494 * INTERNAL
1495 */
1496 public void updateLong(int columnIndex, long x) throws SQLException {
1497 update(columnIndex, x);
1498 }
1499
1500 /**
1501 * INTERNAL
1502 */
1503 public void updateLong(String columnLabel, long x) throws SQLException {
1504 update(columnLabel, x);
1505 }
1506
1507 /**
1508 * INTERNAL
1509 */
1510 //## Java 1.6 ##
1511 public void updateNCharacterStream(int columnIndex, Reader x)
1512 throws SQLException {
1513 update(columnIndex, x);
1514 }
1515 //*/
1516
1517 /**
1518 * INTERNAL
1519 */
1520 //## Java 1.6 ##
1521 public void updateNCharacterStream(String columnLabel, Reader x)
1522 throws SQLException {
1523 update(columnLabel, x);
1524 }
1525 //*/
1526
1527 /**
1528 * INTERNAL
1529 */
1530 //## Java 1.6 ##
1531 public void updateNCharacterStream(int columnIndex, Reader x, long length)
1532 throws SQLException {
1533 update(columnIndex, x);
1534 }
1535 //*/
1536
1537 /**
1538 * INTERNAL
1539 */
1540 //## Java 1.6 ##
1541 public void updateNCharacterStream(String columnLabel, Reader x, long length)
1542 throws SQLException {
1543 update(columnLabel, x);
1544 }
1545 //*/
1546
1547 /**
1548 * INTERNAL
1549 */
1550 //## Java 1.6 ##
1551 public void updateNClob(int columnIndex, NClob x) throws SQLException {
1552 update(columnIndex, x);
1553 }
1554 //*/
1555
1556 /**
1557 * INTERNAL
1558 */
1559 //## Java 1.6 ##
1560 public void updateNClob(String columnLabel, NClob x) throws SQLException {
1561 update(columnLabel, x);
1562 }
1563 //*/
1564
1565 /**
1566 * INTERNAL
1567 */
1568 //## Java 1.6 ##
1569 public void updateNClob(int columnIndex, Reader x) throws SQLException {
1570 update(columnIndex, x);
1571 }
1572 //*/
1573
1574 /**
1575 * INTERNAL
1576 */
1577 //## Java 1.6 ##
1578 public void updateNClob(String columnLabel, Reader x) throws SQLException {
1579 update(columnLabel, x);
1580 }
1581 //*/
1582
1583 /**
1584 * INTERNAL
1585 */
1586 //## Java 1.6 ##
1587 public void updateNClob(int columnIndex, Reader x, long length)
1588 throws SQLException {
1589 update(columnIndex, x);
1590 }
1591 //*/
1592
1593 /**
1594 * INTERNAL
1595 */
1596 //## Java 1.6 ##
1597 public void updateNClob(String columnLabel, Reader x, long length)
1598 throws SQLException {
1599 update(columnLabel, x);
1600 }
1601 //*/
1602
1603 /**
1604 * INTERNAL
1605 */
1606 //## Java 1.6 ##
1607 public void updateNString(int columnIndex, String x) throws SQLException {
1608 update(columnIndex, x);
1609 }
1610 //*/
1611
1612 /**
1613 * INTERNAL
1614 */
1615 //## Java 1.6 ##
1616 public void updateNString(String columnLabel, String x) throws SQLException {
1617 update(columnLabel, x);
1618 }
1619 //*/
1620
1621 /**
1622 * INTERNAL
1623 */
1624 public void updateNull(int columnIndex) throws SQLException {
1625 update(columnIndex, null);
1626 }
1627
1628 /**
1629 * INTERNAL
1630 */
1631 public void updateNull(String columnLabel) throws SQLException {
1632 update(columnLabel, null);
1633 }
1634
1635 /**
1636 * INTERNAL
1637 */
1638 public void updateObject(int columnIndex, Object x) throws SQLException {
1639 update(columnIndex, x);
1640 }
1641
1642 /**
1643 * INTERNAL
1644 */
1645 public void updateObject(String columnLabel, Object x) throws SQLException {
1646 update(columnLabel, x);
1647 }
1648
1649 /**
1650 * INTERNAL
1651 */
1652 public void updateObject(int columnIndex, Object x, int scale) throws SQLException {
1653 update(columnIndex, x);
1654 }
1655
1656 /**
1657 * INTERNAL
1658 */
1659 public void updateObject(String columnLabel, Object x, int scale) throws SQLException {
1660 update(columnLabel, x);
1661 }
1662
1663 /**
1664 * INTERNAL
1665 */
1666 public void updateRef(int columnIndex, Ref x) throws SQLException {
1667 update(columnIndex, x);
1668 }
1669
1670 /**
1671 * INTERNAL
1672 */
1673 public void updateRef(String columnLabel, Ref x) throws SQLException {
1674 update(columnLabel, x);
1675 }
1676
1677 /**
1678 * INTERNAL
1679 */
1680 //## Java 1.6 ##
1681 public void updateRowId(int columnIndex, RowId x) throws SQLException {
1682 update(columnIndex, x);
1683 }
1684 //*/
1685
1686 /**
1687 * INTERNAL
1688 */
1689 //## Java 1.6 ##
1690 public void updateRowId(String columnLabel, RowId x) throws SQLException {
1691 update(columnLabel, x);
1692 }
1693 //*/
1694
1695 /**
1696 * INTERNAL
1697 */
1698 public void updateShort(int columnIndex, short x) throws SQLException {
1699 update(columnIndex, x);
1700 }
1701
1702 /**
1703 * INTERNAL
1704 */
1705 public void updateShort(String columnLabel, short x) throws SQLException {
1706 update(columnLabel, x);
1707 }
1708
1709 /**
1710 * INTERNAL
1711 */
1712 //## Java 1.6 ##
1713 public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException {
1714 update(columnIndex, x);
1715 }
1716 //*/
1717
1718 /**
1719 * INTERNAL
1720 */
1721 //## Java 1.6 ##
1722 public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException {
1723 update(columnLabel, x);
1724 }
1725 //*/
1726
1727 /**
1728 * INTERNAL
1729 */
1730 public void updateString(int columnIndex, String x) throws SQLException {
1731 update(columnIndex, x);
1732 }
1733
1734 /**
1735 * INTERNAL
1736 */
1737 public void updateString(String columnLabel, String x) throws SQLException {
1738 update(columnLabel, x);
1739 }
1740
1741 /**
1742 * INTERNAL
1743 */
1744 public void updateTime(int columnIndex, Time x) throws SQLException {
1745 update(columnIndex, x);
1746 }
1747
1748 /**
1749 * INTERNAL
1750 */
1751 public void updateTime(String columnLabel, Time x) throws SQLException {
1752 update(columnLabel, x);
1753 }
1754
1755 /**
1756 * INTERNAL
1757 */
1758 public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
1759 update(columnIndex, x);
1760 }
1761
1762 /**
1763 * INTERNAL
1764 */
1765 public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
1766 update(columnLabel, x);
1767 }
1768
1769 // ---- result set meta data ---------------------------------------------
1770
1771 /**
1772 * Returns the column count.
1773 *
1774 * @return the column count
1775 */
1776 public int getColumnCount() {
1777 return columns.size();
1778 }
1779
1780 /**
1781 * Returns 15.
1782 *
1783 * @param columnIndex (1,2,...)
1784 * @return 15
1785 */
1786 public int getColumnDisplaySize(int columnIndex) {
1787 return 15;
1788 }
1789
1790 /**
1791 * Returns the SQL type.
1792 *
1793 * @param columnIndex (1,2,...)
1794 * @return the SQL type
1795 */
1796 public int getColumnType(int columnIndex) throws SQLException {
1797 return getColumn(columnIndex - 1).sqlType;
1798 }
1799
1800 /**
1801 * Returns the precision.
1802 *
1803 * @param columnIndex (1,2,...)
1804 * @return the precision
1805 */
1806 public int getPrecision(int columnIndex) throws SQLException {
1807 return getColumn(columnIndex - 1).precision;
1808 }
1809
1810 /**
1811 * Returns the scale.
1812 *
1813 * @param columnIndex (1,2,...)
1814 * @return the scale
1815 */
1816 public int getScale(int columnIndex) throws SQLException {
1817 return getColumn(columnIndex - 1).scale;
1818 }
1819
1820 /**
1821 * Returns ResultSetMetaData.columnNullableUnknown.
1822 *
1823 * @param columnIndex (1,2,...)
1824 * @return columnNullableUnknown
1825 */
1826 public int isNullable(int columnIndex) {
1827 return ResultSetMetaData.columnNullableUnknown;
1828 }
1829
1830 /**
1831 * Returns false.
1832 *
1833 * @param columnIndex (1,2,...)
1834 * @return false
1835 */
1836 public boolean isAutoIncrement(int columnIndex) {
1837 return false;
1838 }
1839
1840 /**
1841 * Returns true.
1842 *
1843 * @param columnIndex (1,2,...)
1844 * @return true
1845 */
1846 public boolean isCaseSensitive(int columnIndex) {
1847 return true;
1848 }
1849
1850 /**
1851 * Returns false.
1852 *
1853 * @param columnIndex (1,2,...)
1854 * @return false
1855 */
1856 public boolean isCurrency(int columnIndex) {
1857 return false;
1858 }
1859
1860 /**
1861 * Returns false.
1862 *
1863 * @param columnIndex (1,2,...)
1864 * @return false
1865 */
1866 public boolean isDefinitelyWritable(int columnIndex) {
1867 return false;
1868 }
1869
1870 /**
1871 * Returns true.
1872 *
1873 * @param columnIndex (1,2,...)
1874 * @return true
1875 */
1876 public boolean isReadOnly(int columnIndex) {
1877 return true;
1878 }
1879
1880 /**
1881 * Returns true.
1882 *
1883 * @param columnIndex (1,2,...)
1884 * @return true
1885 */
1886 public boolean isSearchable(int columnIndex) {
1887 return true;
1888 }
1889
1890 /**
1891 * Returns true.
1892 *
1893 * @param columnIndex (1,2,...)
1894 * @return true
1895 */
1896 public boolean isSigned(int columnIndex) {
1897 return true;
1898 }
1899
1900 /**
1901 * Returns false.
1902 *
1903 * @param columnIndex (1,2,...)
1904 * @return false
1905 */
1906 public boolean isWritable(int columnIndex) {
1907 return false;
1908 }
1909
1910 /**
1911 * Returns null.
1912 *
1913 * @param columnIndex (1,2,...)
1914 * @return null
1915 */
1916 public String getCatalogName(int columnIndex) {
1917 return null;
1918 }
1919
1920 /**
1921 * Returns the Java class name if this column.
1922 *
1923 * @param columnIndex (1,2,...)
1924 * @return the class name
1925 */
1926 public String getColumnClassName(int columnIndex) throws SQLException {
1927 int sqlType = getColumn(columnIndex - 1).sqlType;
1928 int type = DataType.convertSQLTypeToValueType(sqlType);
1929 return DataType.getTypeClassName(type);
1930 }
1931
1932 /**
1933 * Returns the column label.
1934 *
1935 * @param columnIndex (1,2,...)
1936 * @return the column label
1937 */
1938 public String getColumnLabel(int columnIndex) throws SQLException {
1939 return getColumn(columnIndex - 1).name;
1940 }
1941
1942 /**
1943 * Returns the column name.
1944 *
1945 * @param columnIndex (1,2,...)
1946 * @return the column name
1947 */
1948 public String getColumnName(int columnIndex) throws SQLException {
1949 return getColumnLabel(columnIndex);
1950 }
1951
1952 /**
1953 * Returns the data type name of a column.
1954 *
1955 * @param columnIndex (1,2,...)
1956 * @return the type name
1957 */
1958 public String getColumnTypeName(int columnIndex) throws SQLException {
1959 int sqlType = getColumn(columnIndex - 1).sqlType;
1960 int type = DataType.convertSQLTypeToValueType(sqlType);
1961 return DataType.getDataType(type).name;
1962 }
1963
1964 /**
1965 * Returns null.
1966 *
1967 * @param columnIndex (1,2,...)
1968 * @return null
1969 */
1970 public String getSchemaName(int columnIndex) {
1971 return null;
1972 }
1973
1974 /**
1975 * Returns null.
1976 *
1977 * @param columnIndex (1,2,...)
1978 * @return null
1979 */
1980 public String getTableName(int columnIndex) {
1981 return null;
1982 }
1983
1984 // ---- unsupported / result set ---------------------------------------------
1985
1986 /**
1987 * INTERNAL
1988 */
1989 public void afterLast() throws SQLException {
1990 throw getUnsupportedException();
1991 }
1992
1993 /**
1994 * INTERNAL
1995 */
1996 public void cancelRowUpdates() throws SQLException {
1997 throw getUnsupportedException();
1998 }
1999
2000 /**
2001 * INTERNAL
2002 */
2003 public void deleteRow() throws SQLException {
2004 throw getUnsupportedException();
2005 }
2006
2007 /**
2008 * INTERNAL
2009 */
2010 public void insertRow() throws SQLException {
2011 throw getUnsupportedException();
2012 }
2013
2014 /**
2015 * INTERNAL
2016 */
2017 public void moveToCurrentRow() throws SQLException {
2018 throw getUnsupportedException();
2019 }
2020
2021 /**
2022 * INTERNAL
2023 */
2024 public void moveToInsertRow() throws SQLException {
2025 throw getUnsupportedException();
2026 }
2027
2028 /**
2029 * INTERNAL
2030 */
2031 public void refreshRow() throws SQLException {
2032 throw getUnsupportedException();
2033 }
2034
2035 /**
2036 * INTERNAL
2037 */
2038 public void updateRow() throws SQLException {
2039 throw getUnsupportedException();
2040 }
2041
2042 /**
2043 * INTERNAL
2044 */
2045 public boolean first() throws SQLException {
2046 throw getUnsupportedException();
2047 }
2048
2049 /**
2050 * INTERNAL
2051 */
2052 public boolean isAfterLast() throws SQLException {
2053 throw getUnsupportedException();
2054 }
2055
2056 /**
2057 * INTERNAL
2058 */
2059 public boolean isBeforeFirst() throws SQLException {
2060 throw getUnsupportedException();
2061 }
2062
2063 /**
2064 * INTERNAL
2065 */
2066 public boolean isFirst() throws SQLException {
2067 throw getUnsupportedException();
2068 }
2069
2070 /**
2071 * INTERNAL
2072 */
2073 public boolean isLast() throws SQLException {
2074 throw getUnsupportedException();
2075 }
2076
2077 /**
2078 * INTERNAL
2079 */
2080 public boolean last() throws SQLException {
2081 throw getUnsupportedException();
2082 }
2083
2084 /**
2085 * INTERNAL
2086 */
2087 public boolean previous() throws SQLException {
2088 throw getUnsupportedException();
2089 }
2090
2091 /**
2092 * INTERNAL
2093 */
2094 public boolean rowDeleted() throws SQLException {
2095 throw getUnsupportedException();
2096 }
2097
2098 /**
2099 * INTERNAL
2100 */
2101 public boolean rowInserted() throws SQLException {
2102 throw getUnsupportedException();
2103 }
2104
2105 /**
2106 * INTERNAL
2107 */
2108 public boolean rowUpdated() throws SQLException {
2109 throw getUnsupportedException();
2110 }
2111
2112 /**
2113 * INTERNAL
2114 */
2115 public void setFetchDirection(int direction) throws SQLException {
2116 throw getUnsupportedException();
2117 }
2118
2119 /**
2120 * INTERNAL
2121 */
2122 public void setFetchSize(int rows) throws SQLException {
2123 throw getUnsupportedException();
2124 }
2125
2126 /**
2127 * INTERNAL
2128 */
2129 public boolean absolute(int row) throws SQLException {
2130 throw getUnsupportedException();
2131 }
2132
2133 /**
2134 * INTERNAL
2135 */
2136 public boolean relative(int offset) throws SQLException {
2137 throw getUnsupportedException();
2138 }
2139
2140 /**
2141 * INTERNAL
2142 */
2143 public String getCursorName() throws SQLException {
2144 throw getUnsupportedException();
2145 }
2146
2147 // --- private -----------------------------
2148
2149 private void update(int columnIndex, Object obj) throws SQLException {
2150 checkColumnIndex(columnIndex);
2151 this.currentRow[columnIndex - 1] = obj;
2152 }
2153
2154 private void update(String columnLabel, Object obj) throws SQLException {
2155 this.currentRow[findColumn(columnLabel) - 1] = obj;
2156 }
2157
2158 /**
2159 * INTERNAL
2160 */
2161 static SQLException getUnsupportedException() {
2162 return DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1).getSQLException();
2163 }
2164
2165 private void checkColumnIndex(int columnIndex) throws SQLException {
2166 if (columnIndex < 1 || columnIndex > columns.size()) {
2167 throw DbException.getInvalidValueException("columnIndex", columnIndex).getSQLException();
2168 }
2169 }
2170
2171 private Object get(int columnIndex) throws SQLException {
2172 if (currentRow == null) {
2173 throw DbException.get(ErrorCode.NO_DATA_AVAILABLE).getSQLException();
2174 }
2175 checkColumnIndex(columnIndex);
2176 columnIndex--;
2177 Object o = columnIndex < currentRow.length ? currentRow[columnIndex] : null;
2178 wasNull = o == null;
2179 return o;
2180 }
2181
2182 private Column getColumn(int i) throws SQLException {
2183 checkColumnIndex(i + 1);
2184 return columns.get(i);
2185 }
2186
2187 /**
2188 * Returns the current result set holdability.
2189 *
2190 * @return the holdability
2191 */
2192 public int getHoldability() {
2193 return ResultSet.HOLD_CURSORS_OVER_COMMIT;
2194 }
2195
2196 /**
2197 * Returns whether this result set has been closed.
2198 *
2199 * @return true if the result set was closed
2200 */
2201 public boolean isClosed() {
2202 return rows == null;
2203 }
2204
2205 /**
2206 * INTERNAL
2207 */
2208 //## Java 1.6 ##
2209 public <T> T unwrap(Class<T> iface) throws SQLException {
2210 throw getUnsupportedException();
2211 }
2212 //*/
2213
2214 /**
2215 * INTERNAL
2216 */
2217 //## Java 1.6 ##
2218 public boolean isWrapperFor(Class<?> iface) throws SQLException {
2219 throw getUnsupportedException();
2220 }
2221 //*/
2222
2223 /**
2224 * Set the auto-close behavior. If enabled (the default), the result set is
2225 * closed after reading the last row.
2226 *
2227 * @param autoClose the new value
2228 */
2229 public void setAutoClose(boolean autoClose) {
2230 this.autoClose = autoClose;
2231 }
2232
2233 /**
2234 * Get the current auto-close behavior.
2235 *
2236 * @return the auto-close value
2237 */
2238 public boolean getAutoClose() {
2239 return autoClose;
2240 }
2241
2242 }
2243