1 package com.quadcap.jdbc; 2 3 40 41 import java.io.Externalizable ; 42 import java.io.IOException ; 43 import java.io.ObjectInput ; 44 import java.io.ObjectOutput ; 45 import java.io.InputStream ; 46 import java.io.Reader ; 47 48 import java.util.Calendar ; 49 import java.util.Vector ; 50 51 import java.math.BigDecimal ; 52 import java.math.BigInteger ; 53 54 import java.util.Map ; 56 57 import java.sql.Array ; 58 import java.sql.Blob ; 59 import java.sql.Clob ; 60 import java.sql.Ref ; 61 63 import java.sql.Date ; 64 import java.sql.SQLException ; 65 import java.sql.SQLWarning ; 66 import java.sql.Time ; 67 import java.sql.Timestamp ; 68 import java.sql.Types ; 69 70 import com.quadcap.util.Debug; 71 72 import com.quadcap.sql.Column; 73 import com.quadcap.sql.Cursor; 74 import com.quadcap.sql.Database; 75 import com.quadcap.sql.QedResultSet; 76 import com.quadcap.sql.Row; 77 import com.quadcap.sql.SelectExpression; 78 import com.quadcap.sql.Session; 79 80 import com.quadcap.sql.types.*; 81 82 import com.quadcap.sql.file.BlockFile; 83 import com.quadcap.sql.file.Log; 84 85 import com.quadcap.io.AsciiInputStream; 86 import com.quadcap.io.AsciiReader; 87 import com.quadcap.io.InputStreamReader; 88 import com.quadcap.io.ReaderInputStream; 89 90 import com.quadcap.util.ConfigNumber; 91 import com.quadcap.util.Util; 92 93 102 public class ResultSet implements QedResultSet { 103 118 static final ConfigNumber trace = 120 ConfigNumber.find("qed.trace.ResultSet", "0"); 121 123 Statement stmt; 124 Cursor cursor; 125 Row row; 126 int rowNum = 0; 127 boolean onInsertRow = false; 128 boolean onUpdateRow = false; 129 boolean bf = false; 130 boolean rowUpdated = false; 131 boolean rowDeleted = false; 132 133 Row insertRow = null; 134 boolean wasNull = false; 135 Object lock = new Object (); 136 int rowCount = 0; 137 138 139 144 public ResultSet(Cursor cursor) { 145 this.cursor = cursor; 146 } 147 148 151 final private Session getSession() { 152 return cursor.getSession(); 153 } 154 155 158 final private BlockFile getBlockFile() { 159 return getSession().getFile(); 160 } 161 162 165 final private long getTransactionId() throws IOException , SQLException { 166 return getSession().getTransactionId(); 167 } 168 169 172 final Row getCursorRow() throws SQLException { 173 if (onInsertRow) { 174 if (insertRow == null) { 175 insertRow = new Row(cursor.getColumnCount()); 176 for (int i = 1; i <= insertRow.size(); i++) { 177 insertRow.set(i, ValueNull.valueNull); 178 } 179 } 180 return insertRow; 181 } else if (onUpdateRow) { 182 if (insertRow == null) { 183 insertRow = new Row(cursor.getColumnCount()); 184 for (int i = 1; i < insertRow.size(); i++) { 185 insertRow.set(i, row.item(i)); 186 } 187 } 188 return insertRow; 189 } else { 190 if (row == null) { 191 row = cursor.getRow(); 192 if (trace.bit(2)) { 194 Debug.println("cursor.getRow: " + row); 195 } 196 } 198 return row; 199 } 200 } 201 202 205 Value getValue(int col) throws SQLException { 206 Value v = null; 207 Row r = getCursorRow(); 208 if (r != null) { 209 v = r.item(col); 210 if (v != null) { 211 wasNull = Value.isNull(v); 212 } else { 213 throw new SQLException ("Can't return column " + col); 214 } 215 } else { 216 throw new SQLException ("ResultSet isn't positioned on a valid row"); 217 } 218 return v; 219 } 220 221 224 final Value getValue(int col, Type type) throws SQLException { 225 return type.convert(getValue(col)); 226 } 227 228 232 public Object getObject(int col, Type type) throws SQLException { 233 Value v = getValue(col, type); 234 if (trace.bit(3)) { 236 Debug.println("get(" + col + ", " + type.getTypeName() + 237 ") = " + v); 238 } 239 return v.asJavaObject(); 241 } 242 243 247 262 public boolean absolute(int x) throws SQLException { 263 checkScrollable(); 264 if (trace.bit(0)) { 266 Debug.println("ResultSet.absolute(" + x + ")"); 267 } 269 if (x == 0) { 271 throw new SQLException ("ResultSet.absolute(0), bad parameter"); 272 } 273 rowNum = x; 274 resetRow(); 275 bf = false; 276 return cursor.absolute(rowNum); 277 } 278 279 private final void resetRow() { 280 onInsertRow = false; 281 onUpdateRow = false; 282 row = null; 283 rowUpdated = false; 284 rowDeleted = false; 285 } 286 287 288 296 public void afterLast() throws SQLException { 297 checkScrollable(); 298 cursor.afterLast(); 299 resetRow(); 300 bf = false; 301 } 302 303 309 public void beforeFirst() throws SQLException { 310 checkScrollable(); 311 cursor.beforeFirst(); 312 resetRow(); 313 bf = true; 314 } 315 316 322 public void cancelRowUpdates() throws SQLException { 323 if (onInsertRow) { 324 throw new SQLException ("ResultSet.cancelRowUpdates() called " + 325 "while on insert row"); 326 } 327 resetRow(); 328 } 329 330 336 public void clearWarnings() throws SQLException { 337 } 338 339 342 public void finalize() throws Throwable { 343 try { 344 if (cursor != null) close(); 345 } catch (Throwable t) {} 346 super.finalize(); 347 } 348 349 357 public void close() throws SQLException { 358 if (cursor == null) return; 359 360 Session s = cursor.getSession(); 361 362 synchronized (lock) { 363 cursor = null; 364 if (s != null) { 365 try { 366 s.endStatement(false); 367 } catch (IOException e) { 368 throw new SQLException (e.toString()); 369 } 370 } 371 } 372 } 373 374 380 public void deleteRow() throws SQLException { 381 if (trace.bit(0)) { 383 Debug.println("ResultSet.deleteRow()"); 384 } 385 checkUpdatable(); 387 if (onInsertRow) { 388 throw new SQLException ( 389 "ResultSet.deleteRow(): Can't delete while on insert row"); 390 } 391 cursor.deleteRow(); 392 rowDeleted = true; 393 } 394 395 401 public int findColumn(String column) throws SQLException { 402 Column col = cursor.getColumn(column.toUpperCase()); 403 if (col == null) { 404 SelectExpression.showCursor(cursor, true); 406 throw new SQLException ("Bad column name: " + column, 408 "42000"); 409 } 410 int coln = col.getColumn(); 411 if (trace.bit(1)) { 413 Debug.println("ResultSet.findColumn(" + column + ") = " + coln); 414 } 415 return coln; 417 } 418 419 426 public boolean first() throws SQLException { 427 return absolute(1); 428 } 429 430 438 public InputStream getAsciiStream(int col) throws SQLException { 439 Value v = getValue(col); 440 if (Value.isNull(v)) return null; 441 return new AsciiInputStream(getCharacterStream(col)); 442 } 443 444 452 public InputStream getAsciiStream(String column) throws SQLException { 453 return getAsciiStream(findColumn(column)); 454 } 455 456 463 public BigDecimal getBigDecimal(int col) throws SQLException { 464 try { 465 ValueScaledInteger v = 466 (ValueScaledInteger)getValue(col, TypeDecimal.typeDecimal); 467 if (v != null) return v.bigDecimalValue(); 468 } catch (ClassCastException e) { 469 if (wasNull) return null; 470 } 471 throw new SQLException ("Can't return column " + col + 472 " as BigDecimal", "22003"); 473 } 474 475 478 public BigDecimal getBigDecimal(int col, int scale) throws SQLException { 479 BigDecimal big = getBigDecimal(col); 480 return big.setScale(scale); 481 } 482 483 490 public BigDecimal getBigDecimal(String column) throws SQLException { 491 return getBigDecimal(findColumn(column)); 492 } 493 494 497 public BigDecimal getBigDecimal(String column, int scale) 498 throws SQLException 499 { 500 return getBigDecimal(findColumn(column), scale); 501 } 502 503 511 public InputStream getBinaryStream(int col) throws SQLException { 512 try { 513 Value v = getValue(col); 514 if (Value.isNull(v)) return null; 515 int type = v.getType().getJDBCType(); 516 switch (type) { 517 case Types.CHAR: 518 case Types.VARCHAR: 519 return ((ValueString)v).getBinaryStream(); 520 case Types.BINARY: 521 case Types.VARBINARY: 522 return ((ValueOctets)v).getBinaryStream(); 523 case Types.BLOB: 527 return ((ValueBlob)v).getBinaryStream(); 529 case Types.CLOB: 533 return ((ValueClob)v).getBinaryStream(); 535 default: 536 throw new ValueException("Can't convert: " + type + 537 " to binary stream"); 538 } 539 } catch (ValueException e) { 540 throw new SQLException ("Can't return column " + col + 541 " as Binary Stream", "22003"); 542 } 543 } 544 545 553 public InputStream getBinaryStream(String column) throws SQLException { 554 return getBinaryStream(findColumn(column)); 555 } 556 557 564 public boolean getBoolean(int col) throws SQLException { 565 Object obj = getObject(col); 566 if (obj == null) return false; 567 if (obj instanceof Boolean ) { 568 return ((Boolean )obj).booleanValue(); 569 } 570 Number num = asNumber(obj); 571 if (num != null) { 572 return num.doubleValue() != 0; 573 } 574 return obj.toString().toLowerCase().equals("true"); 575 } 576 577 584 public boolean getBoolean(String column) throws SQLException { 585 return getBoolean(findColumn(column)); 586 } 587 588 599 final Number asNumber(Object obj) { 600 if (obj instanceof Number ) return (Number )obj; 601 if (obj instanceof String ) { 602 try { 603 return new Long (obj.toString()); 604 } catch (NumberFormatException e) { 605 } 606 } 607 if (obj instanceof byte[]) { 608 return new BigDecimal (new BigInteger ((byte[])obj)); 609 } 610 if (obj instanceof Boolean ) { 611 int val = ((Boolean )obj).booleanValue() ? 1 : 0; 612 return new Integer (val); 613 } 614 return null; 615 } 616 617 624 public byte getByte(int col) throws SQLException { 625 try { 626 ValueByte v = (ValueByte)getValue(col, TypeTinyInt.typeTinyInt); 627 if (v != null) return v.byteValue(); 628 } catch (ClassCastException e) { 629 if (wasNull) return 0; 630 } 631 throw new SQLException ("Can't return column " + col + 632 " as byte", "22003"); 633 } 634 635 642 public byte getByte(String column) throws SQLException { 643 return getByte(findColumn(column)); 644 } 645 646 653 public byte[] getBytes(int col) throws SQLException { 654 try { 655 Value v1 = getValue(col, TypeVarBinary.typeVarBinary); 656 if (wasNull) return null; 657 ValueOctets v = (ValueOctets)v1; 658 return v.getBytes(); 659 } catch (Exception e) { 660 throw new SQLException ("Can't return column " + col + 661 " as bytes", "22003"); 662 } 663 } 664 665 672 public byte[] getBytes(String column) throws SQLException { 673 return getBytes(findColumn(column)); 674 } 675 676 684 public Reader getCharacterStream(int col) throws SQLException { 685 try { 686 Value v = getValue(col); 687 if (Value.isNull(v)) return null; 688 int type = v.getType().getJDBCType(); 689 switch (type) { 690 case Types.CHAR: 691 case Types.VARCHAR: 692 return ((ValueString)v).getCharacterStream(); 693 case Types.BINARY: 694 case Types.VARBINARY: 695 return new ByteReader(((ValueOctets)v).getBinaryStream()); 696 case Types.BLOB: 697 return new ByteReader(((ValueBlob)v).getBinaryStream()); 698 case Types.CLOB: 699 return ((ValueClob)v).getCharacterStream(); 700 default: 701 throw new ValueException("Can't convert: " + type + 702 " to character stream"); 703 } 704 } catch (ValueException e) { 705 throw new SQLException ("Can't return column " + col + 706 " as character stream", "22003"); 707 } 708 709 } 710 711 719 public Reader getCharacterStream(String column) throws SQLException { 720 return getCharacterStream(findColumn(column)); 721 } 722 723 730 public String getCursorName() throws SQLException { 731 throw new SQLException ("named cursors not supported", "0A000"); 732 } 733 734 741 public Date getDate(int col) throws SQLException { 742 Date d = null; 743 Value v = getValue(col); 744 if (!Value.isNull(v)) { 745 try { 746 ValueDate vd = (ValueDate)v.convert(TypeDate.typeDate); 747 d = new Date (vd.getTime()); 748 } catch (Exception e) { 749 throw new SQLException ("Can't convert column " + col + 750 " to date", "22003"); 751 } 752 } 753 return d; 754 } 755 756 766 public Date getDate(int col, Calendar c) throws SQLException { 767 Date d = getDate(col); 768 if (d != null) { 769 long t = d.getTime(); 770 c.setTime(d); 771 t += (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)); 772 d = new Date (t); 773 } 774 return d; 775 } 776 777 784 public Date getDate(String column) throws SQLException { 785 return getDate(findColumn(column)); 786 } 787 788 798 public Date getDate(String column, Calendar c) throws SQLException { 799 return getDate(findColumn(column), c); 800 } 801 802 809 public double getDouble(int col) throws SQLException { 810 try { 811 ValueDouble v = (ValueDouble)getValue(col, TypeReal.typeDouble); 812 if (v != null) return v.doubleValue(); 813 } catch (ClassCastException e) { 814 if (wasNull) return 0; 815 } 816 throw new SQLException ("Can't return column " + col + 817 " as double", "22003"); 818 } 819 820 827 public double getDouble(String column) throws SQLException { 828 return getDouble(findColumn(column)); 829 } 830 831 838 public int getFetchSize() { 839 return 1; 840 } 841 842 849 public float getFloat(int col) throws SQLException { 850 try { 851 ValueFloat v = (ValueFloat)getValue(col, TypeReal.typeFloat); 852 if (v != null) return v.floatValue(); 853 } catch (ClassCastException e) { 854 if (wasNull) return 0; 855 } 856 throw new SQLException ("Can't return column " + col + 857 " as float", "22003"); 858 } 859 860 867 public float getFloat(String column) throws SQLException { 868 return getFloat(findColumn(column)); 869 } 870 871 878 public int getInt(int col) throws SQLException { 879 try { 880 ValueInteger v = (ValueInteger)getValue(col, TypeInt.typeInt); 881 if (v != null) return v.intValue(); 882 } catch (ClassCastException e) { 883 if (wasNull) return 0; 884 } 885 throw new SQLException ("Can't return column " + col + 886 " as int", "22003"); 887 } 888 889 896 public int getInt(String column) throws SQLException { 897 return getInt(findColumn(column)); 898 } 899 900 907 public long getLong(int col) throws SQLException { 908 try { 909 ValueLong v = (ValueLong)getValue(col, TypeBigInt.typeBigInt); 910 if (v != null) return v.longValue(); 911 } catch (ClassCastException e) { 912 if (wasNull) return 0; 913 } 914 throw new SQLException ("Can't return column " + col + 915 " as long", "22003"); 916 } 917 918 925 public long getLong(String column) throws SQLException { 926 return getLong(findColumn(column)); 927 } 928 929 938 public java.sql.ResultSetMetaData getMetaData() throws SQLException { 939 return new ResultSetMetaData(cursor); 940 } 941 942 951 public Object getObject(int col) throws SQLException { 952 try { 953 Value v = getValue(col); 954 if (trace.bit(3)) { 956 Debug.println("get(" + col + ") = " + v); 957 } 958 return v.asJavaObject(); 960 } catch (SQLException e) { 961 throw e; 962 } catch (Exception ex) { 963 Debug.print(ex); 964 throw new SQLException ("Invalid column index: " + col, "22003"); 965 } 966 } 967 968 977 public Object getObject(String column) throws SQLException { 978 return getObject(findColumn(column)); 979 } 980 981 985 public int getRow() throws SQLException { 986 if (rowNum < 0) { 987 int siz = (int)cursor.size(); 988 if (siz >= 0) { 989 rowNum = siz + 1 + rowNum; 990 } else { 991 throw new SQLException ( 992 "Sorry, but the underlying cursor (" + 993 cursor + ") doesn't supply row number information"); 994 } 995 } 996 return rowNum; 997 } 998 999 1006 public short getShort(int col) throws SQLException { 1007 try { 1008 ValueShort v = 1009 (ValueShort)getValue(col, TypeSmallInt.typeSmallInt); 1010 if (v != null) return v.shortValue(); 1011 } catch (ClassCastException e) { 1012 if (wasNull) return 0; 1013 } 1014 throw new SQLException ("Can't return column " + col + 1015 " as short", "22003"); 1016 } 1017 1018 1025 public short getShort(String column) throws SQLException { 1026 return getShort(findColumn(column)); 1027 } 1028 1029 1032 public void setStatement(java.sql.Statement stmt) { 1033 this.stmt = (Statement)stmt; 1034 this.resultSetType = this.stmt.resultSetType; 1035 this.resultSetConcurrency = this.stmt.resultSetConcurrency; 1036 } 1037 1038 1045 public java.sql.Statement getStatement() { 1046 return stmt; 1047 } 1048 1049 1056 public String getString(int col) throws SQLException { 1057 Object obj = getObject(col, TypeVarChar.typeVarChar); 1058 if (obj == null) return null; 1059 return obj.toString(); 1060 } 1061 1062 1069 public String getString(String column) throws SQLException { 1070 return getString(findColumn(column)); 1071 } 1072 1073 1080 public Time getTime(int col) throws SQLException { 1081 Time t = null; 1082 Value v = getValue(col); 1083 if (!Value.isNull(v)) { 1084 try { 1085 ValueTime vt = (ValueTime)v.convert(TypeTime.typeTime); 1086 t = new Time (vt.getTime()); 1087 } catch (Exception e) { 1088 throw new SQLException ("Can't convert column " + col + 1089 " to time", "22003"); 1090 } 1091 } 1092 return t; 1093 } 1094 1095 1105 public Time getTime(int col, Calendar c) throws SQLException { 1106 Time d = getTime(col); 1107 if (d != null) { 1108 long t = d.getTime(); 1109 c.setTime(d); 1110 t += (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)); 1111 d = new Time (t); 1112 } 1113 return d; 1114 } 1115 1116 1123 public Time getTime(String column) throws SQLException { 1124 return getTime(findColumn(column)); 1125 } 1126 1127 1137 public Time getTime(String column, Calendar c) throws SQLException { 1138 return getTime(findColumn(column)); 1139 } 1140 1141 1148 public Timestamp getTimestamp(int col) throws SQLException { 1149 Timestamp t = null; 1150 Value v = getValue(col, TypeTimestamp.typeTimestamp); 1151 if (!wasNull) { 1152 try { 1153 ValueTimestamp vt = (ValueTimestamp)v; 1154 t = new Timestamp (vt.getTime()); 1155 } catch (ClassCastException e) { 1156 throw new SQLException ("Can't convert column " + col + 1157 " to timestamp", "22003"); 1158 } 1159 } 1160 return t; 1161 } 1162 1163 1173 public Timestamp getTimestamp(int col, Calendar c) throws SQLException { 1174 Timestamp d = getTimestamp(col); 1175 if (d != null) { 1176 long t = d.getTime(); 1177 c.setTime(d); 1178 t += (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)); 1179 Timestamp r = new Timestamp (t); 1180 r.setNanos(d.getNanos()); 1181 d = r; 1182 } 1183 return d; 1184 } 1185 1186 1193 public Timestamp getTimestamp(String column) throws SQLException { 1194 return getTimestamp(findColumn(column)); 1195 } 1196 1197 1207 public Timestamp getTimestamp(String column, Calendar c) 1208 throws SQLException 1209 { 1210 return getTimestamp(findColumn(column), c); 1211 } 1212 1213 1216 public InputStream getUnicodeStream(int col) throws SQLException { 1217 return getBinaryStream(col); 1218 } 1219 1220 1223 public InputStream getUnicodeStream(String column) throws SQLException { 1224 return getBinaryStream(column); 1225 } 1226 1227 1233 public SQLWarning getWarnings() { 1234 return null; 1235 } 1236 1237 1245 public void insertRow() throws SQLException { 1246 if (trace.bit(0)) { 1248 Debug.println("ResultSet.insertRow()"); 1249 } 1250 checkUpdatable(); 1252 if (onInsertRow && insertRow != null) { 1253 cursor.insertRow(insertRow); 1254 rowUpdated = true; 1255 } else { 1256 throw new SQLException ("Can't insert -- no insert row"); 1257 } 1258 } 1259 1260 1268 public void updateRow() throws SQLException { 1269 if (trace.bit(0)) { 1271 Debug.println("ResultSet.updateRow()"); 1272 } 1273 checkUpdatable(); 1275 if (onInsertRow) { 1276 throw new SQLException ( 1277 "updateRow(): Can't update while on insert row"); 1278 } 1279 Row rowX = onUpdateRow ? insertRow : row; 1280 if (rowX != null) { 1281 cursor.getSession().clearViewCheck(); 1282 cursor.updateRow(rowX); 1283 rowUpdated = true; 1284 } 1285 } 1286 1287 1293 public boolean isAfterLast() throws SQLException { 1294 checkScrollable(); 1295 return !onInsertRow && rowNum == 0 && !bf; 1296 } 1297 1298 1304 public boolean isBeforeFirst() throws SQLException { 1305 checkScrollable(); 1306 return !onInsertRow && rowNum == 0 && bf; 1307 } 1308 1309 1315 public boolean isFirst() throws SQLException { 1316 checkScrollable(); 1317 return !onInsertRow && rowNum == 1; 1318 } 1319 1320 1326 public boolean isLast() throws SQLException { 1327 checkScrollable(); 1328 if (!onInsertRow) { 1329 if (rowNum > 0) { 1330 int siz = (int)cursor.size(); 1331 if (siz > 0) { 1332 return rowNum == siz; 1333 } 1334 } else if (rowNum < 0) { 1335 return rowNum == -1; 1336 } 1337 if (!next()) { 1338 return true; 1339 } else { 1340 previous(); 1341 } 1342 } 1343 return false; 1344 } 1345 1346 1353 public boolean last() throws SQLException { 1354 return absolute(-1); 1355 } 1356 1357 1362 public void moveToCurrentRow() { 1363 if (trace.bit(0)) { 1365 Debug.println("ResultSet.moveToCurrentRow()"); 1366 } 1367 onInsertRow = false; 1369 } 1370 1371 1374 public void moveToInsertRow() { 1375 if (trace.bit(0)) { 1377 Debug.println("ResultSet.moveToInsertRow()"); 1378 } 1379 insertRow = null; 1381 onInsertRow = true; 1382 } 1383 1384 1392 public boolean next() throws SQLException { 1393 resetRow(); 1394 boolean ret = false; 1395 if (stmt != null && stmt.maxRows > 0 && rowCount >= stmt.maxRows) { 1396 ret = false; 1397 } else if (cursor != null) { 1398 rowCount++; 1399 ret = cursor.next(); 1400 if (ret) rowNum++; 1401 } 1402 if (trace.bit(0)) { 1404 Debug.println("ResultSet.next() (cursor " + 1405 cursor.getClass().getName() + 1406 ") returns " + ret); 1407 } 1408 return ret; 1410 } 1411 1412 1420 public boolean previous() throws SQLException { 1421 resetRow(); 1422 boolean ret = false; 1423 if (stmt != null && cursor != null) { 1424 ret = cursor.prev(); 1425 if (ret) { 1426 rowNum--; 1427 rowCount--; 1428 } 1429 } 1430 if (trace.bit(0)) { 1432 Debug.println("ResultSet.next() (cursor " + 1433 cursor.getClass().getName() + 1434 ") returns " + ret); 1435 } 1436 return ret; 1438 } 1439 1440 1443 public void refreshRow() throws SQLException { 1444 this.row = null; 1445 } 1446 1447 1452 public boolean relative(int rows) throws SQLException { 1453 if (rowNum != 0) { 1454 return absolute(rowNum + rows); 1455 } else { 1456 return false; 1457 } 1458 } 1459 1460 1465 public boolean rowDeleted() { 1466 return rowDeleted; 1467 } 1468 1469 1472 public boolean rowInserted() { 1473 return rowUpdated && onInsertRow; 1474 } 1475 1476 1479 public boolean rowUpdated() throws SQLException { 1480 return rowUpdated && !onInsertRow; 1481 } 1482 1483 1486 public void setFetchDirection(int direction) throws SQLException { 1487 } 1488 1489 1494 public void setFetchSize(int size) { 1495 } 1496 1497 1509 public void updateAsciiStream(int col, InputStream is, int length) 1510 throws SQLException 1511 { 1512 updateCharacterStream(col, new AsciiReader(is), length); 1513 } 1514 1515 1527 public void updateAsciiStream(String column, InputStream is, int length) 1528 throws SQLException 1529 { 1530 updateAsciiStream(findColumn(column), is, length); 1531 } 1532 1533 1540 public void updateBigDecimal(int col, BigDecimal val) 1541 throws SQLException 1542 { 1543 checkWritable(col); 1544 getCursorRow().set(col, new ValueScaledInteger(val)); 1545 } 1546 1547 1554 public void updateBigDecimal(String column, BigDecimal val) 1555 throws SQLException 1556 { 1557 updateBigDecimal(findColumn(column), val); 1558 } 1559 1560 1570 public void updateBinaryStream(int col, InputStream is, int length) 1571 throws SQLException 1572 { 1573 checkWritable(col); 1574 try { 1575 ValueBlob val = new ValueBlob(getSession().getDatabase(), 1576 getTransactionId(), is, length); 1577 getCursorRow().set(col, val); 1578 } catch (IOException e) { 1579 Debug.print(e); 1580 throw new SQLException ("Can't update binary stream", "22000"); 1581 } 1582 1583 } 1584 1585 1595 public void updateBinaryStream(String column, InputStream is, int length) 1596 throws SQLException 1597 { 1598 updateBinaryStream(findColumn(column), is, length); 1599 } 1600 1601 1608 public void updateBoolean(int col, boolean val) throws SQLException { 1609 checkWritable(col); 1610 getCursorRow().set(col, new ValueBoolean(val)); 1611 } 1612 1613 1620 public void updateBoolean(String column, boolean val) 1621 throws SQLException 1622 { 1623 updateBoolean(findColumn(column), val); 1624 } 1625 1626 1633 public void updateByte(int col, byte val) throws SQLException { 1634 checkWritable(col); 1635 getCursorRow().set(col, new ValueShort(val)); 1636 } 1637 1638 1645 public void updateByte(String column, byte val) throws SQLException { 1646 updateByte(findColumn(column), val); 1647 } 1648 1649 1656 public void updateBytes(int col, byte[] val) throws SQLException { 1657 checkWritable(col); 1658 getCursorRow().set(col, new ValueOctets(val)); 1659 } 1660 1661 1668 public void updateBytes(String column, byte[] val) throws SQLException { 1669 updateBytes(findColumn(column), val); 1670 } 1671 1672 1682 public void updateCharacterStream(int col, Reader r, int length) 1683 throws SQLException 1684 { 1685 updateBinaryStream(col, new ReaderInputStream(r), length*2); 1686 } 1687 1688 1698 public void updateCharacterStream(String column, Reader r, int length) 1699 throws SQLException 1700 { 1701 updateCharacterStream(findColumn(column), r, length); 1702 } 1703 1704 1711 public void updateDate(int col, Date val) throws SQLException { 1712 checkWritable(col); 1713 getCursorRow().set(col, new ValueDate(val.getTime())); 1714 } 1715 1716 1723 public void updateDate(String column, Date val) throws SQLException { 1724 updateDate(findColumn(column), val); 1725 } 1726 1727 1734 public void updateDouble(int col, double val) throws SQLException { 1735 checkWritable(col); 1736 getCursorRow().set(col, new ValueDouble(val)); 1737 } 1738 1739 1746 public void updateDouble(String column, double val) throws SQLException { 1747 updateDouble(findColumn(column), val); 1748 } 1749 1750 1757 public void updateFloat(int col, float val) throws SQLException { 1758 checkWritable(col); 1759 getCursorRow().set(col, new ValueDouble(val)); 1760 } 1761 1762 1769 public void updateFloat(String column, float val) throws SQLException { 1770 updateFloat(findColumn(column), val); 1771 } 1772 1773 1780 public void updateInt(int col, int val) throws SQLException { 1781 if (trace.bit(5)) { 1783 Debug.println("updateInt(" + col + ", " + val + ")"); 1784 } 1785 checkWritable(col); 1787 Row row1 = getCursorRow(); 1788 row1.set(col, new ValueInteger(val)); 1789 } 1790 1791 1798 public void updateInt(String column, int val) throws SQLException { 1799 updateInt(findColumn(column), val); 1800 } 1801 1802 1809 public void updateLong(int col, long val) throws SQLException { 1810 checkWritable(col); 1811 getCursorRow().set(col, new ValueLong(val)); 1812 } 1813 1814 1821 public void updateLong(String column, long val) throws SQLException { 1822 updateLong(findColumn(column), val); 1823 } 1824 1825 1831 public void updateNull(int col) throws SQLException { 1832 checkWritable(col); 1833 getCursorRow().set(col, ValueNull.valueNull); 1834 } 1835 1836 1842 public void updateNull(String column) throws SQLException { 1843 updateNull(findColumn(column)); 1844 } 1845 1846 1854 public void updateObject(int col, Object val) throws SQLException { 1855 if (trace.bit(5)) { 1857 Debug.println("updateObject(" + col + ", " + val + ")"); 1858 } 1859 checkWritable(col); 1861 getCursorRow().set(col, Value.fromObject(val)); 1862 } 1863 1864 1873 public void updateObject(int col, Object val, int scale) 1874 throws SQLException 1875 { 1876 updateObject(col, val); } 1878 1879 1887 public void updateObject(String column, Object val) throws SQLException { 1888 updateObject(findColumn(column), val); 1889 1890 } 1891 1892 1901 public void updateObject(String column, Object val, int scale) 1902 throws SQLException 1903 { 1904 updateObject(findColumn(column), val, scale); 1905 } 1906 1907 1914 public void updateShort(int col, short val) throws SQLException { 1915 checkWritable(col); 1916 getCursorRow().set(col, new ValueShort(val)); 1917 } 1918 1919 1926 public void updateShort(String column, short val) throws SQLException { 1927 updateShort(findColumn(column), val); 1928 } 1929 1930 1937 public void updateString(int col, String val) throws SQLException { 1938 checkWritable(col); 1939 getCursorRow().set(col, new ValueString(val)); 1940 } 1941 1942 1949 public void updateString(String column, String val) throws SQLException { 1950 updateString(findColumn(column), val); 1951 } 1952 1953 1960 public void updateTime(int col, Time val) throws SQLException { 1961 checkWritable(col); 1962 getCursorRow().set(col, new ValueTime(val.getTime())); 1963 } 1964 1965 1972 public void updateTime(String column, Time val) throws SQLException { 1973 updateTime(findColumn(column), val); 1974 } 1975 1976 1983 public void updateTimestamp(int col, Timestamp val) throws SQLException { 1984 checkWritable(col); 1985 getCursorRow().set(col, new ValueTimestamp(val)); 1986 } 1987 1988 1995 public void updateTimestamp(String column, Timestamp val) 1996 throws SQLException 1997 { 1998 updateTimestamp(findColumn(column), val); 1999 } 2000 2001 2007 public boolean wasNull() { 2008 return wasNull; 2009 } 2010 2011 2012 int resultSetType = ResultSet.TYPE_FORWARD_ONLY; 2013 int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY; 2014 2015 2020 final void checkScrollable() throws SQLException { 2021 if (resultSetType == ResultSet.TYPE_FORWARD_ONLY) { 2022 throw new SQLException ( 2023 "checkScrollable(): type == ResultSet.TYPE_FORWARD_ONLY"); 2024 } 2025 } 2026 2027 2032 final void checkUpdatable() throws SQLException { 2033 if (resultSetConcurrency == ResultSet.CONCUR_READ_ONLY) { 2034 throw new SQLException ( 2035 "checkUpdatable(): concurrency == CONCUR_READ_ONLY"); 2036 } 2037 } 2038 2039 2042 final private void checkWritable(int col) throws SQLException { 2043 checkUpdatable(); 2044 if (!cursor.isWritable(col)) { 2045 Debug.println("cursor = " + cursor); 2047 throw new SQLException ("Not writable: " + 2049 cursor.getColumn(col).getName(), 2050 "42000"); 2051 } 2052 if (!(onInsertRow || onUpdateRow)) { 2053 onUpdateRow = true; 2054 insertRow = null; 2055 } 2056 } 2057 2058 2059 2064 public int getConcurrency() { 2065 return resultSetConcurrency; 2066 } 2067 2068 2073 public int getFetchDirection() { 2074 return FETCH_FORWARD; 2075 } 2076 2077 2083 public Array getArray(int col) throws SQLException { 2084 throw new SQLException ("not implemented", "0A000"); 2085 } 2086 2087 2092 public Array getArray(String column) throws SQLException { 2093 return getArray(findColumn(column)); 2094 } 2095 2096 2103 public Blob getBlob(int col) throws SQLException { 2104 Value v = getValue(col); 2105 if (Value.isNull(v)) return null; 2106 v = v.convert(TypeBlob.typeBlob); 2107 ValueBlob vb = (ValueBlob)v; 2108 return vb; 2109 } 2110 2111 2118 public Blob getBlob(String column) throws SQLException { 2119 return getBlob(findColumn(column)); 2120 } 2121 2122 2129 public Object getObject(int col, Map map) throws SQLException { 2130 throw new SQLException ("not implemented", "0A000"); 2131 } 2132 2133 2140 public Object getObject(String column, Map map) throws SQLException { 2141 return getObject(findColumn(column), map); 2142 } 2143 2144 2149 public Ref getRef(int col) throws SQLException { 2150 throw new SQLException ("not implemented", "0A000"); 2151 } 2152 2153 2158 public Ref getRef(String column) throws SQLException { 2159 return getRef(findColumn(column)); 2160 } 2161 2162 2167 public int getType() { 2168 return resultSetType; 2169 } 2170 2171 2178 public Clob getClob(int col) throws SQLException { 2179 Value v = getValue(col); 2180 if (Value.isNull(v)) return null; 2181 v = v.convert(TypeClob.typeClob); 2182 ValueClob vb = (ValueClob)v; 2183 return vb; 2184 } 2185 2186 2193 public Clob getClob(String column) throws SQLException { 2194 return getClob(findColumn(column)); 2195 } 2196 2197 2199 2207 2209 2215 2217 2230 public java.net.URL getURL(int columnIndex) throws SQLException { 2231 try { 2232 return new java.net.URL (getString(columnIndex)); 2233 } catch (java.net.MalformedURLException e) { 2234 throw new SQLException (e.toString()); 2235 } 2236 } 2237 2238 2251 public java.net.URL getURL(String columnName) throws SQLException { 2252 return getURL(findColumn(columnName)); 2253 } 2254 2255 2267 public void updateRef(int columnIndex, java.sql.Ref x) 2268 throws SQLException 2269 { 2270 throw new SQLException ("Not implemented"); 2271 } 2272 2273 2274 2286 public void updateRef(String columnName, java.sql.Ref x) 2287 throws SQLException 2288 { 2289 throw new SQLException ("Not implemented"); 2290 } 2291 2292 2304 public void updateBlob(int columnIndex, java.sql.Blob x) 2305 throws SQLException 2306 { 2307 throw new SQLException ("Not implemented"); 2308 } 2309 2310 2322 public void updateBlob(String columnName, java.sql.Blob x) 2323 throws SQLException 2324 { 2325 throw new SQLException ("Not implemented"); 2326 } 2327 2328 2340 public void updateClob(int columnIndex, java.sql.Clob x) 2341 throws SQLException 2342 { 2343 throw new SQLException ("Not implemented"); 2344 } 2345 2346 2358 public void updateClob(String columnName, java.sql.Clob x) 2359 throws SQLException 2360 { 2361 throw new SQLException ("Not implemented"); 2362 } 2363 2364 2376 public void updateArray(int columnIndex, java.sql.Array x) 2377 throws SQLException 2378 { 2379 throw new SQLException ("Not implemented"); 2380 } 2381 2382 2394 public void updateArray(String columnName, java.sql.Array x) 2395 throws SQLException 2396 { 2397 throw new SQLException ("Not implemented"); 2398 } 2399 } 2401 | Popular Tags |