1 65 66 67 package org.hsqldb.jdbc; 68 69 import java.io.ByteArrayInputStream ; 70 import java.io.StringReader ; 71 import java.math.BigDecimal ; 72 import java.sql.Date ; 73 import java.sql.ResultSet ; 74 import java.sql.ResultSetMetaData ; 75 import java.sql.SQLException ; 76 import java.sql.SQLWarning ; 77 import java.sql.Statement ; 78 import java.sql.Time ; 79 import java.sql.Timestamp ; 80 import java.util.Calendar ; 81 82 import java.sql.Array ; 84 import java.sql.Blob ; 85 import java.sql.Clob ; 86 import java.sql.Ref ; 87 import java.util.Map ; 88 89 import org.hsqldb.Column; 91 import org.hsqldb.HsqlDateTime; 92 import org.hsqldb.HsqlException; 93 import org.hsqldb.Record; 94 import org.hsqldb.Result; 95 import org.hsqldb.ResultConstants; 96 import org.hsqldb.Trace; 97 import org.hsqldb.Types; 98 import org.hsqldb.lib.AsciiStringInputStream; 99 import org.hsqldb.lib.StringInputStream; 100 import org.hsqldb.persist.HsqlProperties; 101 import org.hsqldb.types.Binary; 102 import org.hsqldb.types.JavaObject; 103 104 119 325 public class jdbcResultSet implements ResultSet { 326 327 400 401 406 407 boolean autoClose; 408 409 410 public Result rResult; 411 412 415 private Record nCurrent; 416 417 418 private int iCurrentRow; 419 420 421 private int iUpdateCount; 422 423 424 private boolean bInit; 426 427 int iColumnCount; 428 429 430 private boolean bWasNull; 431 432 433 private ResultSetMetaData rsmd; 434 435 436 private HsqlProperties connProperties; 437 438 439 private boolean isNetConn; 440 441 445 jdbcStatement sqlStatement; 446 447 449 452 int rsType = TYPE_FORWARD_ONLY; 453 454 473 public boolean next() throws SQLException { 474 475 bWasNull = false; 476 477 if (rResult == null || rResult.isEmpty()) { 479 return false; 480 } 481 482 if (!bInit) { 483 484 nCurrent = rResult.rRoot; 487 bInit = true; 488 iCurrentRow = 1; 489 } else { 490 491 if (nCurrent == null) { 493 return false; 494 } 495 496 nCurrent = nCurrent.next; 498 499 iCurrentRow++; 500 } 501 502 if (nCurrent == null) { 504 505 iCurrentRow = rResult.getSize() + 1; 507 508 return false; 509 } else { 510 511 return true; 513 } 514 } 515 516 533 public void close() throws SQLException { 534 535 iUpdateCount = -1; 536 rResult = null; 537 538 if (autoClose) { 539 sqlStatement.close(); 540 } 541 } 542 543 557 public boolean wasNull() throws SQLException { 558 return bWasNull; 559 } 560 561 565 577 public String getString(int columnIndex) throws SQLException { 578 return (String ) getColumnInType(columnIndex, Types.CHAR); 579 } 580 581 593 public boolean getBoolean(int columnIndex) throws SQLException { 594 595 Object o = getColumnInType(columnIndex, Types.BOOLEAN); 596 597 return o == null ? false 598 : ((Boolean ) o).booleanValue(); 599 } 600 601 613 public byte getByte(int columnIndex) throws SQLException { 614 615 Object o = getColumnInType(columnIndex, Types.TINYINT); 616 617 return o == null ? 0 618 : ((Number ) o).byteValue(); 619 } 620 621 633 public short getShort(int columnIndex) throws SQLException { 634 635 Object o = getColumnInType(columnIndex, Types.SMALLINT); 636 637 return o == null ? 0 638 : ((Number ) o).shortValue(); 639 } 640 641 653 public int getInt(int columnIndex) throws SQLException { 654 655 Object o = getColumnInType(columnIndex, Types.INTEGER); 656 657 return o == null ? 0 658 : ((Number ) o).intValue(); 659 } 660 661 673 public long getLong(int columnIndex) throws SQLException { 674 675 Object o = getColumnInType(columnIndex, Types.BIGINT); 676 677 return o == null ? 0 678 : ((Number ) o).longValue(); 679 } 680 681 693 public float getFloat(int columnIndex) throws SQLException { 694 695 Object o = getColumnInType(columnIndex, Types.REAL); 696 697 return o == null ? (float) 0.0 698 : ((Number ) o).floatValue(); 699 } 700 701 713 public double getDouble(int columnIndex) throws SQLException { 714 715 Object o = getColumnInType(columnIndex, Types.DOUBLE); 716 717 return o == null ? 0.0 718 : ((Number ) o).doubleValue(); 719 } 720 721 744 745 public BigDecimal getBigDecimal(int columnIndex, 747 int scale) throws SQLException { 748 749 BigDecimal bd = (BigDecimal ) getColumnInType(columnIndex, 751 Types.DECIMAL); 752 753 if (scale < 0) { 754 throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT); 755 } 756 757 if (bd != null) { 758 bd = bd.setScale(scale, BigDecimal.ROUND_HALF_DOWN); 759 } 760 761 return bd; 762 } 763 764 766 790 public byte[] getBytes(int columnIndex) throws SQLException { 791 792 Object x = getObject(columnIndex); 793 794 if (x == null) { 795 return null; 796 } 797 798 if (x instanceof byte[]) { 799 return (byte[]) x; 800 } 801 802 if (x instanceof java.lang.String ) { 803 return ((String ) x).getBytes(); 804 } 805 806 x = getColumnInType(columnIndex, Types.BINARY); 807 808 return (byte[]) x; 809 } 810 811 823 public Date getDate(int columnIndex) throws SQLException { 824 return (Date ) getColumnInType(columnIndex, Types.DATE); 825 } 826 827 839 public Time getTime(int columnIndex) throws SQLException { 840 return (Time ) getColumnInType(columnIndex, Types.TIME); 841 } 842 843 856 public Timestamp getTimestamp(int columnIndex) throws SQLException { 857 return (Timestamp ) getColumnInType(columnIndex, Types.TIMESTAMP); 858 } 859 860 916 public java.io.InputStream getAsciiStream(int columnIndex) 917 throws SQLException { 918 919 String s = getString(columnIndex); 920 921 if (s == null) { 922 return null; 923 } 924 925 return new AsciiStringInputStream(s); 926 } 927 928 981 982 public java.io.InputStream getUnicodeStream(int columnIndex) 984 throws SQLException { 985 986 String s = getString(columnIndex); 987 988 if (s == null) { 989 return null; 990 } 991 992 return new StringInputStream(s); 993 } 994 995 997 1020 public java.io.InputStream getBinaryStream(int columnIndex) 1022 throws SQLException { 1023 1024 byte[] b = getBytes(columnIndex); 1025 1026 return wasNull() ? null 1027 : new ByteArrayInputStream (b); 1028 } 1029 1030 1034 1046 public String getString(String columnName) throws SQLException { 1047 return getString(findColumn(columnName)); 1048 } 1049 1050 1062 public boolean getBoolean(String columnName) throws SQLException { 1063 return getBoolean(findColumn(columnName)); 1064 } 1065 1066 1078 public byte getByte(String columnName) throws SQLException { 1079 return getByte(findColumn(columnName)); 1080 } 1081 1082 1094 public short getShort(String columnName) throws SQLException { 1095 return getShort(findColumn(columnName)); 1096 } 1097 1098 1110 public int getInt(String columnName) throws SQLException { 1111 return getInt(findColumn(columnName)); 1112 } 1113 1114 1126 public long getLong(String columnName) throws SQLException { 1127 return getLong(findColumn(columnName)); 1128 } 1129 1130 1142 public float getFloat(String columnName) throws SQLException { 1143 return getFloat(findColumn(columnName)); 1144 } 1145 1146 1158 public double getDouble(String columnName) throws SQLException { 1159 return getDouble(findColumn(columnName)); 1160 } 1161 1162 1185 1186 public BigDecimal getBigDecimal(String columnName, 1188 int scale) throws SQLException { 1189 return getBigDecimal(findColumn(columnName), scale); 1190 } 1191 1192 1194 1207 public byte[] getBytes(String columnName) throws SQLException { 1208 return getBytes(findColumn(columnName)); 1209 } 1210 1211 1223 public Date getDate(String columnName) throws SQLException { 1224 return getDate(findColumn(columnName)); 1225 } 1226 1227 1240 public Time getTime(String columnName) throws SQLException { 1241 return getTime(findColumn(columnName)); 1242 } 1243 1244 1256 public Timestamp getTimestamp(String columnName) throws SQLException { 1257 return getTimestamp(findColumn(columnName)); 1258 } 1259 1260 1285 public java.io.InputStream getAsciiStream(String columnName) 1286 throws SQLException { 1287 return getAsciiStream(findColumn(columnName)); 1288 } 1289 1290 1320 1321 public java.io.InputStream getUnicodeStream(String columnName) 1323 throws SQLException { 1324 return getUnicodeStream(findColumn(columnName)); 1325 } 1326 1327 1329 1352 public java.io.InputStream getBinaryStream(String columnName) 1353 throws SQLException { 1354 return getBinaryStream(findColumn(columnName)); 1355 } 1356 1357 1361 1398 public SQLWarning getWarnings() throws SQLException { 1399 return null; 1400 } 1401 1402 1422 public void clearWarnings() throws SQLException {} 1423 1424 1460 public String getCursorName() throws SQLException { 1461 throw Util.notSupported(); 1462 } 1463 1464 1524 public ResultSetMetaData getMetaData() throws SQLException { 1525 1526 if (rsmd == null) { 1527 rsmd = new jdbcResultSetMetaData(this, connProperties); 1528 } 1529 1530 return rsmd; 1531 } 1532 1533 1561 public Object getObject(int columnIndex) throws SQLException { 1562 1563 checkAvailable(); 1564 1565 Object o; 1566 int t; 1567 1568 try { 1569 o = nCurrent.data[--columnIndex]; 1570 t = rResult.metaData.colTypes[columnIndex]; 1571 } catch (ArrayIndexOutOfBoundsException e) { 1572 throw Util.sqlException(Trace.COLUMN_NOT_FOUND, 1573 String.valueOf(++columnIndex)); 1574 } 1575 1576 if (checkNull(o)) { 1578 return null; 1579 } 1580 1581 switch (t) { 1582 1583 case Types.DATE : 1584 return new Date (((Date ) o).getTime()); 1585 1586 case Types.TIME : 1587 return new Time (((Time ) o).getTime()); 1588 1589 case Types.TIMESTAMP : 1590 long m = ((Timestamp ) o).getTime(); 1591 int n = ((Timestamp ) o).getNanos(); 1592 Timestamp ts = new Timestamp (m); 1593 1594 ts.setNanos(n); 1595 1596 return ts; 1597 1598 case Types.OTHER : 1599 case Types.JAVA_OBJECT : 1600 try { 1601 return ((JavaObject) o).getObject(); 1602 } catch (HsqlException e) { 1603 throw Util.sqlException( 1604 Trace.error(Trace.SERIALIZATION_FAILURE)); 1605 } 1606 case Types.BINARY : 1607 case Types.VARBINARY : 1608 case Types.LONGVARBINARY : 1609 return ((Binary) o).getClonedBytes(); 1610 1611 default : 1612 return o; 1613 } 1614 } 1615 1616 1644 public Object getObject(String columnName) throws SQLException { 1645 return getObject(findColumn(columnName)); 1646 } 1647 1648 1650 1661 public int findColumn(String columnName) throws SQLException { 1662 1663 for (int i = 0; i < iColumnCount; i++) { 1664 String name = rResult.metaData.colLabels[i]; 1665 1666 if (columnName.equalsIgnoreCase(name)) { 1667 return i + 1; 1668 } 1669 } 1670 1671 throw Util.sqlException(Trace.COLUMN_NOT_FOUND, columnName); 1672 } 1673 1674 1679 1701 public java.io.Reader getCharacterStream(int columnIndex) 1702 throws SQLException { 1703 1704 String s = getString(columnIndex); 1705 1706 if (s == null) { 1707 return null; 1708 } 1709 1710 return new StringReader (s); 1711 } 1712 1713 1735 public java.io.Reader getCharacterStream(String columnName) 1736 throws SQLException { 1737 return getCharacterStream(findColumn(columnName)); 1738 } 1739 1740 1755 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 1756 return (BigDecimal ) getColumnInType(columnIndex, Types.DECIMAL); 1757 } 1758 1759 1774 public BigDecimal getBigDecimal(String columnName) throws SQLException { 1775 return getBigDecimal(findColumn(columnName)); 1776 } 1777 1778 1782 1795 public boolean isBeforeFirst() throws SQLException { 1796 1797 checkClosed(); 1800 1801 return rResult.rRoot != null &&!bInit; 1802 1803 } 1805 1806 1819 public boolean isAfterLast() throws SQLException { 1820 1821 checkClosed(); 1825 1826 return rResult.rRoot != null && bInit && nCurrent == null; 1827 } 1828 1829 1841 public boolean isFirst() throws SQLException { 1842 1843 checkClosed(); 1844 1845 return iCurrentRow == 1; 1846 } 1847 1848 1874 public boolean isLast() throws SQLException { 1875 1876 checkClosed(); 1877 1878 return rResult.rRoot != null && bInit && nCurrent != null 1881 && nCurrent.next == null; 1882 } 1883 1884 1897 public void beforeFirst() throws SQLException { 1898 1899 checkClosed(); 1900 1901 if (this.getType() == TYPE_FORWARD_ONLY) { 1902 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 1903 } 1904 1905 bInit = false; 1907 nCurrent = null; 1908 iCurrentRow = 0; 1909 } 1910 1911 1923 public void afterLast() throws SQLException { 1924 1925 checkClosed(); 1926 1927 if (this.getType() == TYPE_FORWARD_ONLY) { 1928 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 1929 } 1930 1931 if (rResult != null && rResult.rRoot != null) { 1932 1933 bInit = true; 1935 iCurrentRow = rResult.getSize() + 1; 1936 nCurrent = null; 1937 } 1938 } 1939 1940 1953 public boolean first() throws SQLException { 1954 1955 checkClosed(); 1956 1957 if (this.getType() == TYPE_FORWARD_ONLY) { 1958 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 1959 } 1960 1961 if (rResult == null) { 1962 return false; 1963 } 1964 1965 bInit = false; 1966 1967 if (rResult.rRoot != null) { 1968 bInit = true; 1969 nCurrent = rResult.rRoot; 1970 iCurrentRow = 1; 1971 } 1972 1973 return bInit; 1974 } 1975 1976 1989 public boolean last() throws SQLException { 1990 1991 checkClosed(); 1992 1993 if (this.getType() == TYPE_FORWARD_ONLY) { 1994 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 1995 } 1996 1997 if (rResult == null) { 1998 return false; 1999 } 2000 2001 if (rResult.rRoot == null) { 2002 return false; 2003 } 2004 2005 if (!bInit || nCurrent == null) { 2007 first(); 2008 } 2009 2010 while (nCurrent.next != null) { 2012 iCurrentRow++; 2013 2014 nCurrent = nCurrent.next; 2015 } 2016 2017 return true; 2018 } 2019 2020 2032 public int getRow() throws SQLException { 2033 2034 checkClosed(); 2035 2036 return iCurrentRow; 2037 } 2038 2039 2076 public boolean absolute(int row) throws SQLException { 2077 2078 checkClosed(); 2079 2080 if (this.getType() == TYPE_FORWARD_ONLY) { 2081 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 2082 } 2083 2084 if (rResult == null) { 2085 return false; 2086 } 2087 2088 if (rResult.rRoot == null || row == 0) { 2089 2090 return false; 2093 } 2094 2095 switch (row) { 2097 2098 case 1 : 2099 return first(); 2101 case -1 : 2102 return last(); } 2104 2105 if (row < 0) { 2108 2109 last(); 2111 2112 row = iCurrentRow + row + 1; 2114 2115 if (row <= 0) { 2117 beforeFirst(); 2118 2119 return false; 2120 } 2121 } 2122 2123 if (row < iCurrentRow || iCurrentRow == 0) { 2124 2125 beforeFirst(); 2127 } 2128 2129 while (row > iCurrentRow) { 2131 next(); 2132 2133 if (nCurrent == null) { 2134 break; 2135 } 2136 } 2137 2138 return nCurrent != null; 2139 } 2140 2141 2166 public boolean relative(int rows) throws SQLException { 2167 2168 checkClosed(); 2169 2170 if (this.getType() == TYPE_FORWARD_ONLY) { 2171 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 2172 } 2173 2174 if (rResult == null) { 2175 return false; 2176 } 2177 2178 if (rResult.rRoot == null) { 2179 return false; 2180 } 2181 2182 if (rows < 0) { 2184 rows = iCurrentRow + rows; 2185 2186 beforeFirst(); 2188 2189 if (rows <= 0) { 2191 return false; 2192 } 2193 } 2194 2195 while (rows-- > 0) { 2196 next(); 2197 2198 if (nCurrent == null) { 2199 break; 2200 } 2201 } 2202 2203 return nCurrent != null; 2205 } 2206 2207 2220 public boolean previous() throws SQLException { 2221 2222 checkClosed(); 2223 2224 if (this.getType() == TYPE_FORWARD_ONLY) { 2225 throw Util.sqlException(Trace.RESULTSET_FORWARD_ONLY); 2226 } 2227 2228 if (rResult == null || rResult.rRoot == null || iCurrentRow == 0) { 2229 2230 return false; 2232 } 2233 2234 if (bInit && nCurrent == null) { 2235 2236 return last(); 2239 } 2240 2241 int targetRow = iCurrentRow - 1; 2242 2243 if (targetRow == 0) { 2244 2245 beforeFirst(); 2249 2250 return false; 2251 } 2252 2253 first(); 2256 2257 while (targetRow != iCurrentRow) { 2258 nCurrent = nCurrent.next; 2259 2260 iCurrentRow++; 2261 } 2262 2263 return nCurrent != null; 2264 } 2265 2266 2274 2307 public void setFetchDirection(int direction) throws SQLException { 2308 2309 checkClosed(); 2310 2311 if (rsType == TYPE_FORWARD_ONLY && direction != FETCH_FORWARD) { 2312 throw Util.notSupported(); 2313 } 2314 } 2315 2316 2339 public int getFetchDirection() throws SQLException { 2340 2341 checkClosed(); 2342 2343 return FETCH_FORWARD; 2344 } 2345 2346 2377 public void setFetchSize(int rows) throws SQLException { 2378 2379 if (rows < 0) { 2380 throw Util.sqlException(Trace.INVALID_JDBC_ARGUMENT); 2381 } 2382 } 2383 2384 2407 public int getFetchSize() throws SQLException { 2408 2409 checkClosed(); 2410 2411 return 1; 2412 } 2413 2414 2437 public int getType() throws SQLException { 2438 2439 checkClosed(); 2440 2441 return rsType; 2442 } 2443 2444 2467 public int getConcurrency() throws SQLException { 2468 2469 checkClosed(); 2470 2471 return CONCUR_READ_ONLY; 2472 } 2473 2474 2478 2501 public boolean rowUpdated() throws SQLException { 2502 2503 checkClosed(); 2504 2505 return false; 2506 } 2507 2508 2532 public boolean rowInserted() throws SQLException { 2533 2534 checkClosed(); 2535 2536 return false; 2537 } 2538 2539 2563 public boolean rowDeleted() throws SQLException { 2564 2565 checkClosed(); 2566 2567 return false; 2568 } 2569 2570 2595 public void updateNull(int columnIndex) throws SQLException { 2596 throw Util.notSupported(); 2597 } 2598 2599 2624 public void updateBoolean(int columnIndex, 2625 boolean x) throws SQLException { 2626 throw Util.notSupported(); 2627 } 2628 2629 2655 public void updateByte(int columnIndex, byte x) throws SQLException { 2656 throw Util.notSupported(); 2657 } 2658 2659 2685 public void updateShort(int columnIndex, short x) throws SQLException { 2686 throw Util.notSupported(); 2687 } 2688 2689 2715 public void updateInt(int columnIndex, int x) throws SQLException { 2716 throw Util.notSupported(); 2717 } 2718 2719 2745 public void updateLong(int columnIndex, long x) throws SQLException { 2746 throw Util.notSupported(); 2747 } 2748 2749 2775 public void updateFloat(int columnIndex, float x) throws SQLException { 2776 throw Util.notSupported(); 2777 } 2778 2779 2805 public void updateDouble(int columnIndex, double x) throws SQLException { 2806 throw Util.notSupported(); 2807 } 2808 2809 2836 public void updateBigDecimal(int columnIndex, 2837 BigDecimal x) throws SQLException { 2838 throw Util.notSupported(); 2839 } 2840 2841 2867 public void updateString(int columnIndex, String x) throws SQLException { 2868 throw Util.notSupported(); 2869 } 2870 2871 2897 public void updateBytes(int columnIndex, byte[] x) throws SQLException { 2898 throw Util.notSupported(); 2899 } 2900 2901 2927 public void updateDate(int columnIndex, Date x) throws SQLException { 2928 throw Util.notSupported(); 2929 } 2930 2931 2957 public void updateTime(int columnIndex, Time x) throws SQLException { 2958 throw Util.notSupported(); 2959 } 2960 2961 2988 public void updateTimestamp(int columnIndex, 2989 Timestamp x) throws SQLException { 2990 throw Util.notSupported(); 2991 } 2992 2993 3019 public void updateAsciiStream(int columnIndex, java.io.InputStream x, 3020 int length) throws SQLException { 3021 throw Util.notSupported(); 3022 } 3023 3024 3051 public void updateBinaryStream(int columnIndex, java.io.InputStream x, 3052 int length) throws SQLException { 3053 throw Util.notSupported(); 3054 } 3055 3056 3083 public void updateCharacterStream(int columnIndex, java.io.Reader x, 3084 int length) throws SQLException { 3085 throw Util.notSupported(); 3086 } 3087 3088 3118 public void updateObject(int columnIndex, Object x, 3119 int scale) throws SQLException { 3120 throw Util.notSupported(); 3121 } 3122 3123 3149 public void updateObject(int columnIndex, Object x) throws SQLException { 3150 throw Util.notSupported(); 3151 } 3152 3153 3178 public void updateNull(String columnName) throws SQLException { 3179 updateNull(findColumn(columnName)); 3180 } 3181 3182 3208 public void updateBoolean(String columnName, 3209 boolean x) throws SQLException { 3210 updateBoolean(findColumn(columnName), x); 3211 } 3212 3213 3239 public void updateByte(String columnName, byte x) throws SQLException { 3240 updateByte(findColumn(columnName), x); 3241 } 3242 3243 3269 public void updateShort(String columnName, short x) throws SQLException { 3270 updateShort(findColumn(columnName), x); 3271 } 3272 3273 3299 public void updateInt(String columnName, int x) throws SQLException { 3300 updateInt(findColumn(columnName), x); 3301 } 3302 3303 3329 public void updateLong(String columnName, long x) throws SQLException { 3330 updateLong(findColumn(columnName), x); 3331 } 3332 3333 3359 public void updateFloat(String columnName, float x) throws SQLException { 3360 updateFloat(findColumn(columnName), x); 3361 } 3362 3363 3389 public void updateDouble(String columnName, 3390 double x) throws SQLException { 3391 updateDouble(findColumn(columnName), x); 3392 } 3393 3394 3421 public void updateBigDecimal(String columnName, 3422 BigDecimal x) throws SQLException { 3423 updateBigDecimal(findColumn(columnName), x); 3424 } 3425 3426 3452 public void updateString(String columnName, 3453 String x) throws SQLException { 3454 updateString(findColumn(columnName), x); 3455 } 3456 3457 3484 public void updateBytes(String columnName, byte[] x) throws SQLException { 3485 updateBytes(findColumn(columnName), x); 3486 } 3487 3488 3514 public void updateDate(String columnName, Date x) throws SQLException { 3515 updateDate(findColumn(columnName), x); 3516 } 3517 3518 3544 public void updateTime(String columnName, Time x) throws SQLException { 3545 updateTime(findColumn(columnName), x); 3546 } 3547 3548 3575 public void updateTimestamp(String columnName, 3576 Timestamp x) throws SQLException { 3577 updateTimestamp(findColumn(columnName), x); 3578 } 3579 3580 3607 public void updateAsciiStream(String columnName, java.io.InputStream x, 3608 int length) throws SQLException { 3609 updateAsciiStream(findColumn(columnName), x, length); 3610 } 3611 3612 3639 public void updateBinaryStream(String columnName, java.io.InputStream x, 3640 int length) throws SQLException { 3641 updateBinaryStream(findColumn(columnName), x, length); 3642 } 3643 3644 3672 public void updateCharacterStream(String columnName, 3673 java.io.Reader reader, 3674 int length) throws SQLException { 3675 updateCharacterStream(findColumn(columnName), reader, length); 3676 } 3677 3678 3708 public void updateObject(String columnName, Object x, 3709 int scale) throws SQLException { 3710 updateObject(findColumn(columnName), x, scale); 3711 } 3712 3713 3739 public void updateObject(String columnName, 3740 Object x) throws SQLException { 3741 updateObject(findColumn(columnName), x); 3742 } 3743 3744 3769 public void insertRow() throws SQLException { 3770 throw Util.notSupported(); 3771 } 3772 3773 3796 public void updateRow() throws SQLException { 3797 throw Util.notSupported(); 3798 } 3799 3800 3823 public void deleteRow() throws SQLException { 3824 throw Util.notSupported(); 3825 } 3826 3827 3866 public void refreshRow() throws SQLException { 3867 throw Util.notSupported(); 3868 } 3869 3870 3899 public void cancelRowUpdates() throws SQLException { 3900 throw Util.notSupported(); 3901 } 3902 3903 3938 public void moveToInsertRow() throws SQLException { 3939 throw Util.notSupported(); 3940 } 3941 3942 3963 public void moveToCurrentRow() throws SQLException {} 3964 3965 3981 public Statement getStatement() throws SQLException { 3982 return (Statement ) sqlStatement; 3983 } 3984 3985 4018 public Object getObject(int i, Map map) throws SQLException { 4019 throw Util.notSupported(); 4020 } 4021 4022 4047 public Ref getRef(int i) throws SQLException { 4048 throw Util.notSupported(); 4049 } 4050 4051 4072 4073 public Blob getBlob(int i) throws SQLException { 4075 4076 byte[] b = getBytes(i); 4077 4078 return b == null ? null 4079 : new jdbcBlob(b); 4080 } 4081 4082 4084 4105 public Clob getClob(int i) throws SQLException { 4107 4108 String s = getString(i); 4109 4110 return s == null ? null 4111 : new jdbcClob(s); 4112 } 4113 4114 4116 4141 public Array getArray(int i) throws SQLException { 4142 throw Util.notSupported(); 4143 } 4144 4145 4177 public Object getObject(String colName, Map map) throws SQLException { 4178 4179 return getObject(findColumn(colName), map); 4184 } 4185 4186 4210 public Ref getRef(String colName) throws SQLException { 4211 return getRef(findColumn(colName)); 4212 } 4213 4214 4235 4236 public Blob getBlob(String colName) throws SQLException { 4238 return getBlob(findColumn(colName)); 4239 } 4240 4241 4243 4264 public Clob getClob(String colName) throws SQLException { 4266 return getClob(findColumn(colName)); 4267 } 4268 4269 4271 4296 public Array getArray(String colName) throws SQLException { 4297 return getArray(findColumn(colName)); 4298 } 4299 4300 4321 public Date getDate(int columnIndex, Calendar cal) throws SQLException { 4322 4323 Date date = getDate(columnIndex); 4324 4325 if (date == null) { 4326 return null; 4327 } 4328 4329 if (cal == null) { 4330 return date; 4331 } 4332 4333 cal.setTime(date); 4334 HsqlDateTime.resetToDate(cal); 4335 4336 return new Date (cal.getTime().getTime()); 4337 } 4338 4339 4362 public Date getDate(String columnName, Calendar cal) throws SQLException { 4363 return getDate(findColumn(columnName), cal); 4364 } 4365 4366 4387 public Time getTime(int columnIndex, Calendar cal) throws SQLException { 4388 4389 Time t = getTime(columnIndex); 4390 4391 if (t == null) { 4392 return null; 4393 } 4394 4395 if (cal == null) { 4396 return t; 4397 } 4398 4399 cal.setTime(t); 4400 HsqlDateTime.resetToTime(cal); 4401 4402 return new Time (cal.getTime().getTime()); 4403 } 4404 4405 4428 public Time getTime(String columnName, Calendar cal) throws SQLException { 4429 return getTime(findColumn(columnName), cal); 4430 } 4431 4432 4454 public Timestamp getTimestamp(int columnIndex, 4455 Calendar cal) throws SQLException { 4456 4457 Timestamp ts = getTimestamp(columnIndex); 4458 4459 if (cal != null && ts != null) { 4460 ts.setTime(HsqlDateTime.getTimeInMillis(ts, null, cal)); 4461 } 4462 4463 return ts; 4464 } 4465 4466 4488 public Timestamp getTimestamp(String columnName, 4489 Calendar cal) throws SQLException { 4490 return getTimestamp(findColumn(columnName), cal); 4491 } 4492 4493 4495 4522 public java.net.URL getURL(int columnIndex) throws SQLException { 4524 throw Util.notSupported(); 4525 } 4526 4527 4529 4555 public java.net.URL getURL(String columnName) throws SQLException { 4557 throw Util.notSupported(); 4558 } 4559 4560 4562 4587 public void updateRef(int columnIndex, 4589 java.sql.Ref x) throws SQLException { 4590 throw Util.notSupported(); 4591 } 4592 4593 4595 4620 public void updateRef(String columnName, 4622 java.sql.Ref x) throws SQLException { 4623 throw Util.notSupported(); 4624 } 4625 4626 4628 4653 public void updateBlob(int columnIndex, 4655 java.sql.Blob x) throws SQLException { 4656 throw Util.notSupported(); 4657 } 4658 4659 4661 4686 public void updateBlob(String columnName, 4688 java.sql.Blob x) throws SQLException { 4689 throw Util.notSupported(); 4690 } 4691 4692 4694 4719 public void updateClob(int columnIndex, 4721 java.sql.Clob x) throws SQLException { 4722 throw Util.notSupported(); 4723 } 4724 4725 4727 4752 public void updateClob(String columnName, 4754 java.sql.Clob x) throws SQLException { 4755 throw Util.notSupported(); 4756 } 4757 4758 4760 4785 public void updateArray(int columnIndex, 4787 java.sql.Array x) throws SQLException { 4788 throw Util.notSupported(); 4789 } 4790 4791 4793 4818 public void updateArray(String columnName, 4820 java.sql.Array x) throws SQLException { 4821 throw Util.notSupported(); 4822 } 4823 4824 4828 4829 public static final int FETCH_FORWARD = 1000; 4830 4831 4832 public static final int FETCH_REVERSE = 1001; 4833 4834 4835 public static final int FETCH_UNKNOWN = 1002; 4836 4837 4838 public static final int TYPE_FORWARD_ONLY = 1003; 4839 4840 4841 public static final int TYPE_SCROLL_INSENSITIVE = 1004; 4842 4843 4844 public static final int TYPE_SCROLL_SENSITIVE = 1005; 4845 4846 4847 public static final int CONCUR_READ_ONLY = 1007; 4848 4849 4850 public static final int CONCUR_UPDATABLE = 1008; 4851 4852 4853 public static final int HOLD_CURSORS_OVER_COMMIT = 1; 4854 4855 4856 public static final int CLOSE_CURSORS_AT_COMMIT = 2; 4857 4858 4860 4865 private void checkAvailable() throws SQLException { 4866 4867 if (rResult == null ||!bInit || nCurrent == null) { 4868 throw Util.sqlException(Trace.NO_DATA_IS_AVAILABLE); 4869 } 4870 } 4871 4872 4877 private void checkClosed() throws SQLException { 4878 4879 if (rResult == null 4880 || (sqlStatement != null && sqlStatement.isClosed)) { 4881 throw Util.sqlException(Trace.JDBC_RESULTSET_IS_CLOSED); 4882 } 4883 } 4884 4885 4891 void checkColumn(int columnIndex) throws SQLException { 4892 4893 if (columnIndex < 1 || columnIndex > iColumnCount) { 4894 throw Util.sqlException(Trace.COLUMN_NOT_FOUND, 4895 String.valueOf(columnIndex)); 4896 } 4897 } 4898 4899 4904 private boolean checkNull(Object o) { 4905 4906 if (o == null) { 4907 bWasNull = true; 4908 4909 return true; 4910 } else { 4911 bWasNull = false; 4912 4913 return false; 4914 } 4915 } 4916 4917 4932 private Object getColumnInType(int columnIndex, 4933 int type) throws SQLException { 4934 4935 checkAvailable(); 4936 4937 int t; 4938 Object o; 4939 4940 try { 4941 t = rResult.metaData.colTypes[--columnIndex]; 4942 o = nCurrent.data[columnIndex]; 4943 } catch (ArrayIndexOutOfBoundsException e) { 4944 throw Util.sqlException(Trace.COLUMN_NOT_FOUND, 4945 String.valueOf(++columnIndex)); 4946 } 4947 4948 if (checkNull(o)) { 4949 return null; 4950 } 4951 4952 if (t != type) { 4953 if (o instanceof Binary && type != Types.CHAR) { 4954 throw Util.sqlException(Trace.WRONG_DATA_TYPE); 4955 } 4956 4957 try { 4959 o = Column.convertObject(o, type); 4960 } catch (Exception e) { 4961 String s = "type: " + Types.getTypeString(t) + " (" + t 4962 + ") expected: " + Types.getTypeString(type) 4963 + " value: " + o.toString(); 4964 4965 throw Util.sqlException(Trace.WRONG_DATA_TYPE, s); 4966 } 4967 } 4968 4969 switch (type) { 4971 4972 case Types.DATE : 4973 return new Date (((Date ) o).getTime()); 4974 4975 case Types.TIME : 4976 return new Time (((Time ) o).getTime()); 4977 4978 case Types.TIMESTAMP : 4979 long m = ((Timestamp ) o).getTime(); 4980 int n = ((Timestamp ) o).getNanos(); 4981 Timestamp ts = new Timestamp (m); 4982 4983 ts.setNanos(n); 4984 4985 return ts; 4986 } 4987 4988 return o; 4989 } 4990 4991 4993 5004 jdbcResultSet(jdbcStatement s, Result r, HsqlProperties props, 5005 boolean isNetConnection) throws SQLException { 5006 5007 sqlStatement = s; 5008 connProperties = props; 5009 this.isNetConn = isNetConnection; 5010 5011 if (r.mode == ResultConstants.UPDATECOUNT) { 5012 iUpdateCount = r.getUpdateCount(); 5013 } else if (r.isError()) { 5014 Util.throwError(r); 5015 } else { 5016 if (s != null) { 5017 this.rsType = s.rsType; 5018 } 5019 5020 iUpdateCount = -1; 5021 rResult = r; 5022 iColumnCount = r.getColumnCount(); 5023 } 5024 5025 bWasNull = false; 5026 } 5027 5028 5034 int getUpdateCount() { 5035 return iUpdateCount; 5036 } 5037 5038 5048 boolean isResult() { 5049 return rResult == null ? false 5050 : true; 5051 } 5052} 5053 | Popular Tags |