1 19 package com.mysql.jdbc; 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.ObjectInputStream ; 25 import java.io.StringReader ; 26 27 import java.math.BigDecimal ; 28 29 import java.net.MalformedURLException ; 30 import java.net.URL ; 31 32 import java.sql.Array ; 33 import java.sql.Date ; 34 import java.sql.Ref ; 35 import java.sql.SQLException ; 36 import java.sql.SQLWarning ; 37 import java.sql.Time ; 38 import java.sql.Timestamp ; 39 import java.sql.Types ; 40 41 import java.util.Calendar ; 42 import java.util.GregorianCalendar ; 43 import java.util.HashMap ; 44 import java.util.Map ; 45 import java.util.TimeZone ; 46 47 48 106 public class ResultSet implements java.sql.ResultSet { 107 111 private TimeZone defaultTimeZone; 112 113 114 protected com.mysql.jdbc.Connection connection; 116 117 protected Map columnNameToIndex = null; 118 119 120 protected Map fullColumnNameToIndex = null; 121 122 123 protected RowData rowData; 125 126 protected java.sql.SQLWarning warningChain = null; 127 128 129 protected com.mysql.jdbc.Statement owningStatement; 130 131 132 protected String catalog = null; 133 134 138 protected String serverInfo = null; 139 140 141 protected Field[] fields; 143 144 protected byte[][] thisRow; 146 147 protected boolean doingUpdates = false; 148 149 150 protected boolean isClosed = false; 151 152 153 protected boolean onInsertRow = false; 154 155 159 protected boolean reallyResult = false; 160 161 162 protected boolean wasNullFlag = false; 163 164 169 protected char firstCharOfQuery; 170 171 172 protected int currentRow = -1; 174 175 protected int fetchDirection = FETCH_FORWARD; 176 177 178 protected int fetchSize = 0; 179 180 181 protected int resultSetConcurrency = 0; 182 183 184 protected int resultSetType = 0; 185 186 187 protected long updateCount; 188 189 197 198 protected long updateId = -1; 199 private Calendar fastDateCal = null; 200 private boolean hasBuiltIndexMapping = false; 201 private boolean useStrictFloatingPoint = false; 202 203 209 public ResultSet(long updateCount, long updateID) { 210 this.updateCount = updateCount; 211 this.updateId = updateID; 212 reallyResult = false; 213 fields = new Field[0]; 214 } 215 216 227 public ResultSet(String catalog, Field[] fields, RowData tuples, 228 com.mysql.jdbc.Connection conn) throws SQLException { 229 this(fields, tuples); 230 setConnection(conn); 231 this.catalog = catalog; 232 233 } 234 235 243 public ResultSet(Field[] fields, RowData tuples) throws SQLException { 244 this.fields = fields; 246 this.rowData = tuples; 247 this.updateCount = (long) rowData.size(); 248 249 if (Driver.DEBUG) { 250 System.out.println("Retrieved " + updateCount + " rows"); 251 } 252 253 this.reallyResult = true; 254 255 if (this.rowData.size() > 0) { 257 if (this.updateCount == 1) { 259 if (this.thisRow == null) { 260 this.rowData.close(); this.updateCount = -1; 263 } 264 } 265 } else { 266 this.thisRow = null; 267 } 268 269 this.rowData.setOwner(this); 270 } 271 272 284 public boolean isAfterLast() throws SQLException { 285 if (Driver.TRACE) { 286 Object [] args = { }; 287 Debug.methodCall(this, "isAfterLast", args); 288 } 289 290 boolean b = rowData.isAfterLast(); 291 292 if (Driver.TRACE) { 293 Debug.returnValue(this, "isAfterLast", new Boolean (b)); 294 } 295 296 return b; 297 } 298 299 309 public java.sql.Array getArray(int i) throws SQLException { 310 throw new NotImplemented(); 311 } 312 313 323 public java.sql.Array getArray(String colName) throws SQLException { 324 throw new NotImplemented(); 325 } 326 327 350 public InputStream getAsciiStream(int columnIndex) 351 throws java.sql.SQLException { 352 checkRowPos(); 353 354 return getBinaryStream(columnIndex); 355 } 356 357 366 public InputStream getAsciiStream(String columnName) 367 throws java.sql.SQLException { 368 return getAsciiStream(findColumn(columnName)); 369 } 370 371 375 387 public boolean isBeforeFirst() throws SQLException { 388 if (Driver.TRACE) { 389 Object [] args = { }; 390 Debug.methodCall(this, "isBeforeFirst", args); 391 } 392 393 boolean b = rowData.isBeforeFirst(); 394 395 if (Driver.TRACE) { 396 Debug.returnValue(this, "isBeforeFirst", new Boolean (b)); 397 } 398 399 return b; 400 } 401 402 413 public BigDecimal getBigDecimal(int columnIndex, int scale) 414 throws java.sql.SQLException { 415 String stringVal = getString(columnIndex); 416 BigDecimal val; 417 418 if (stringVal != null) { 419 if (stringVal.length() == 0) { 420 val = new BigDecimal (0); 421 422 return val.setScale(scale); 423 } 424 425 try { 426 val = new BigDecimal (stringVal); 427 } catch (NumberFormatException ex) { 428 throw new java.sql.SQLException ("Bad format for BigDecimal '" 429 + stringVal + "' in column " + columnIndex + "(" 430 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 431 } 432 433 try { 434 return val.setScale(scale); 435 } catch (ArithmeticException ex) { 436 throw new java.sql.SQLException ("Bad format for BigDecimal '" 437 + stringVal + "' in column " + columnIndex + "(" 438 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 439 } 440 } 441 442 return null; 443 } 444 445 455 public BigDecimal getBigDecimal(String columnName, int scale) 456 throws java.sql.SQLException { 457 return getBigDecimal(findColumn(columnName), scale); 458 } 459 460 472 public BigDecimal getBigDecimal(int columnIndex) throws SQLException { 473 String stringVal = getString(columnIndex); 474 BigDecimal val; 475 476 if (stringVal != null) { 477 if (stringVal.length() == 0) { 478 val = new BigDecimal (0); 479 480 return val; 481 } 482 483 try { 484 val = new BigDecimal (stringVal); 485 486 return val; 487 } catch (NumberFormatException ex) { 488 throw new java.sql.SQLException ("Bad format for BigDecimal '" 489 + stringVal + "' in column " + columnIndex + "(" 490 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 491 } 492 } 493 494 return null; 495 } 496 497 507 public BigDecimal getBigDecimal(String columnName) 508 throws SQLException { 509 return getBigDecimal(findColumn(columnName)); 510 } 511 512 527 public InputStream getBinaryStream(int columnIndex) 528 throws java.sql.SQLException { 529 checkRowPos(); 530 531 byte[] b = getBytes(columnIndex); 532 533 if (b != null) { 534 return new ByteArrayInputStream (b); 535 } 536 537 return null; 538 } 539 540 549 public InputStream getBinaryStream(String columnName) 550 throws java.sql.SQLException { 551 return getBinaryStream(findColumn(columnName)); 552 } 553 554 564 public java.sql.Blob getBlob(int columnIndex) throws SQLException { 565 checkRowPos(); 566 567 if ((columnIndex < 1) || (columnIndex > fields.length)) { 568 throw new java.sql.SQLException ("Column Index out of range ( " 569 + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); 570 } 571 572 try { 573 if (thisRow[columnIndex - 1] == null) { 574 wasNullFlag = true; 575 } else { 576 wasNullFlag = false; 577 } 578 } catch (NullPointerException ex) { 579 wasNullFlag = true; 580 } 581 582 if (wasNullFlag) { 583 return null; 584 } 585 586 return new Blob(thisRow[columnIndex - 1]); 587 } 588 589 598 public java.sql.Blob getBlob(String colName) throws SQLException { 599 return getBlob(findColumn(colName)); 600 } 601 602 611 public boolean getBoolean(int columnIndex) throws java.sql.SQLException { 612 String stringVal = getString(columnIndex); 613 614 if ((stringVal != null) && (stringVal.length() > 0)) { 615 int c = Character.toLowerCase(stringVal.charAt(0)); 616 617 return ((c == 't') || (c == 'y') || (c == '1') 618 || stringVal.equals("-1")); 619 } 620 621 return false; 622 } 623 624 633 public boolean getBoolean(String columnName) throws java.sql.SQLException { 634 return getBoolean(findColumn(columnName)); 635 } 636 637 647 public byte getByte(int columnIndex) throws java.sql.SQLException { 648 checkRowPos(); 649 650 try { 651 if (thisRow[columnIndex - 1] == null) { 652 wasNullFlag = true; 653 } else { 654 wasNullFlag = false; 655 } 656 } catch (NullPointerException E) { 657 wasNullFlag = true; 658 } 659 660 if (wasNullFlag) { 661 return 0; 662 } 663 664 Field field = fields[columnIndex - 1]; 665 666 switch (field.getMysqlType()) { 667 case MysqlDefs.FIELD_TYPE_DECIMAL: 668 case MysqlDefs.FIELD_TYPE_TINY: 669 case MysqlDefs.FIELD_TYPE_SHORT: 670 case MysqlDefs.FIELD_TYPE_LONG: 671 case MysqlDefs.FIELD_TYPE_FLOAT: 672 case MysqlDefs.FIELD_TYPE_DOUBLE: 673 case MysqlDefs.FIELD_TYPE_LONGLONG: 674 case MysqlDefs.FIELD_TYPE_INT24: 675 676 try { 677 String stringVal = getString(columnIndex); 678 int decimalIndex = stringVal.indexOf("."); 679 680 if (decimalIndex != -1) { 682 stringVal = stringVal.substring(0, decimalIndex); 683 } 684 685 return Byte.parseByte(stringVal); 686 } catch (NumberFormatException NFE) { 687 throw new SQLException ("Value '" + getString(columnIndex) 688 + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 689 } 690 691 default: 692 693 try { 694 String stringVal = getString(columnIndex); 695 696 int decimalIndex = stringVal.indexOf("."); 697 698 if (decimalIndex != -1) { 700 stringVal = stringVal.substring(0, decimalIndex); 701 } 702 703 return Byte.parseByte(stringVal); 704 } catch (NumberFormatException NFE) { 705 throw new SQLException ("Value '" + getString(columnIndex) 706 + "' is out of range [-127,127]", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 707 } 708 709 } 712 } 713 714 723 public byte getByte(String columnName) throws java.sql.SQLException { 724 return getByte(findColumn(columnName)); 725 } 726 727 740 public byte[] getBytes(int columnIndex) throws java.sql.SQLException { 741 checkRowPos(); 742 743 try { 744 if (thisRow[columnIndex - 1] == null) { 745 wasNullFlag = true; 746 } else { 747 wasNullFlag = false; 748 } 749 } catch (NullPointerException E) { 750 wasNullFlag = true; 751 } catch (ArrayIndexOutOfBoundsException aioobEx) { 752 throw new java.sql.SQLException ("Column Index out of range ( " 753 + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); 754 } 755 756 if (wasNullFlag) { 757 return null; 758 } else { 759 return thisRow[columnIndex - 1]; 760 } 761 } 762 763 772 public byte[] getBytes(String columnName) throws java.sql.SQLException { 773 return getBytes(findColumn(columnName)); 774 } 775 776 781 794 public java.io.Reader getCharacterStream(int columnIndex) 795 throws SQLException { 796 String stringVal = getString(columnIndex); 797 798 if (stringVal != null) { 799 return new StringReader (stringVal); 800 } else { 801 return null; 802 } 803 } 804 805 818 public java.io.Reader getCharacterStream(String columnName) 819 throws SQLException { 820 return getCharacterStream(findColumn(columnName)); 821 } 822 823 832 public java.sql.Clob getClob(int i) throws SQLException { 833 return new com.mysql.jdbc.Clob(getString(i)); 834 } 835 836 845 public java.sql.Clob getClob(String colName) throws SQLException { 846 return getClob(findColumn(colName)); 847 } 848 849 857 public int getConcurrency() throws SQLException { 858 return (CONCUR_READ_ONLY); 859 } 860 861 866 public void setConnection(com.mysql.jdbc.Connection conn) { 867 this.connection = conn; 868 869 if (this.connection != null) { 870 this.useStrictFloatingPoint = this.connection.useStrictFloatingPoint(); 871 this.defaultTimeZone = this.connection.getDefaultTimeZone(); 872 } else { 873 this.defaultTimeZone = TimeZone.getDefault(); 874 } 875 } 876 877 901 public String getCursorName() throws java.sql.SQLException { 902 throw new java.sql.SQLException ("Positioned Update not supported.", 903 "S1C00"); 904 } 905 906 915 public java.sql.Date getDate(int columnIndex) throws java.sql.SQLException { 916 return getDate(columnIndex, null); 917 } 918 919 928 public java.sql.Date getDate(String columnName) 929 throws java.sql.SQLException { 930 return getDate(findColumn(columnName)); 931 } 932 933 947 public java.sql.Date getDate(int columnIndex, Calendar cal) 948 throws SQLException { 949 Integer year = null; 950 Integer month = null; 951 Integer day = null; 952 String stringVal = ""; 953 954 try { 955 stringVal = getString(columnIndex); 956 957 if (stringVal == null) { 958 return null; 959 } else { 960 int length = stringVal.length(); 961 962 if ((length > 0) && (stringVal.charAt(0) == '0') 963 && (stringVal.equals("0000-00-00") 964 || stringVal.equals("0000-00-00 00:00:00") 965 || stringVal.equals("00000000000000") 966 || stringVal.equals("0"))) { 967 wasNullFlag = true; 968 969 return null; 970 } else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP) { 971 switch (length) { 973 case 14: 974 case 8: { 975 year = new Integer (stringVal.substring(0, 4)); 976 month = new Integer (stringVal.substring(4, 6)); 977 day = new Integer (stringVal.substring(6, 8)); 978 979 return fastDateCreate(cal, year.intValue() - 1900, 980 month.intValue() - 1, day.intValue()); 981 } 982 983 case 12: 984 case 10: 985 case 6: { 986 year = new Integer (stringVal.substring(0, 2)); 987 988 if (year.intValue() <= 69) { 989 year = new Integer (year.intValue() + 100); 990 } 991 992 month = new Integer (stringVal.substring(2, 4)); 993 day = new Integer (stringVal.substring(4, 6)); 994 995 return fastDateCreate(cal, year.intValue(), 996 month.intValue() - 1, day.intValue()); 997 } 998 999 case 4: { 1000 year = new Integer (stringVal.substring(0, 4)); 1001 1002 if (year.intValue() <= 69) { 1003 year = new Integer (year.intValue() + 100); 1004 } 1005 1006 month = new Integer (stringVal.substring(2, 4)); 1007 1008 return fastDateCreate(cal, year.intValue(), 1009 month.intValue() - 1, 1); 1010 } 1011 1012 case 2: { 1013 year = new Integer (stringVal.substring(0, 2)); 1014 1015 if (year.intValue() <= 69) { 1016 year = new Integer (year.intValue() + 100); 1017 } 1018 1019 return fastDateCreate(cal, year.intValue(), 0, 1); 1020 } 1021 1022 default: 1023 throw new SQLException ("Bad format for Date '" 1024 + stringVal + "' in column " + columnIndex + "(" 1025 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1026 } 1027 } else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) { 1028 year = new Integer (stringVal.substring(0, 4)); 1029 1030 return fastDateCreate(cal, year.intValue() - 1900, 0, 1); 1031 } else { 1032 if (length < 10) { 1033 throw new SQLException ("Bad format for Date '" 1034 + stringVal + "' in column " + columnIndex + "(" 1035 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1036 } 1037 1038 year = new Integer (stringVal.substring(0, 4)); 1039 month = new Integer (stringVal.substring(5, 7)); 1040 day = new Integer (stringVal.substring(8, 10)); 1041 } 1042 1043 return fastDateCreate(cal, year.intValue() - 1900, 1044 month.intValue() - 1, day.intValue()); 1045 } 1046 } catch (Exception e) { 1047 throw new java.sql.SQLException ("Cannot convert value '" 1048 + stringVal + "' from column " + columnIndex + "(" + stringVal 1049 + " ) to DATE.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1050 } 1051 } 1052 1053 1065 public java.sql.Date getDate(String columnName, Calendar cal) 1066 throws SQLException { 1067 return getDate(columnName); 1068 } 1069 1070 1079 public double getDouble(int columnIndex) throws java.sql.SQLException { 1080 try { 1081 return getDoubleInternal(columnIndex); 1082 } catch (NumberFormatException E) { 1083 throw new java.sql.SQLException ("Bad format for number '" 1084 + new String (thisRow[columnIndex - 1]) + "' in column " 1085 + columnIndex + "(" + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1086 } 1087 } 1088 1089 1098 public double getDouble(String columnName) throws java.sql.SQLException { 1099 return getDouble(findColumn(columnName)); 1100 } 1101 1102 1116 public void setFetchDirection(int direction) throws SQLException { 1117 if ((direction != FETCH_FORWARD) && (direction != FETCH_REVERSE) 1118 && (direction != FETCH_UNKNOWN)) { 1119 throw new SQLException ("Illegal value for fetch direction", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1120 } else { 1121 fetchDirection = direction; 1122 } 1123 } 1124 1125 1132 public int getFetchDirection() throws SQLException { 1133 return fetchDirection; 1134 } 1135 1136 1151 public void setFetchSize(int rows) throws SQLException { 1152 if (rows < 0) { 1153 throw new SQLException ("Value must be between 0 and getMaxRows()", 1154 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1155 } 1156 1157 fetchSize = rows; 1158 } 1159 1160 1167 public int getFetchSize() throws SQLException { 1168 return fetchSize; 1169 } 1170 1171 1182 public boolean isFirst() throws SQLException { 1183 if (Driver.TRACE) { 1184 Object [] args = { }; 1185 Debug.methodCall(this, "isFirst", args); 1186 } 1187 1188 boolean b = rowData.isFirst(); 1189 1190 if (Driver.TRACE) { 1191 Debug.returnValue(this, "isFirst", new Boolean (b)); 1192 } 1193 1194 return b; 1195 } 1196 1197 1207 public float getFloat(int columnIndex) throws java.sql.SQLException { 1208 checkRowPos(); 1209 1210 String val = null; 1211 1212 try { 1213 val = getString(columnIndex); 1214 1215 if ((val != null) && (val.length() != 0)) { 1216 float f = Float.parseFloat(val); 1217 1218 return f; 1219 } else { 1220 return 0; 1221 } 1222 } catch (NumberFormatException nfe) { 1223 try { 1224 return (float) Double.parseDouble(val); 1226 } catch (NumberFormatException newNfe) { 1227 ; } 1229 1230 throw new SQLException ("Invalid value for getFloat() - '" + val 1231 + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1232 } 1233 } 1234 1235 1244 public float getFloat(String columnName) throws java.sql.SQLException { 1245 return getFloat(findColumn(columnName)); 1246 } 1247 1248 1258 public int getInt(int columnIndex) throws java.sql.SQLException { 1259 String val = null; 1260 1261 try { 1262 val = getString(columnIndex); 1263 1264 if ((val != null) && (val.length() != 0)) { 1265 if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) 1266 && (val.indexOf(".") == -1)) { 1267 return Integer.parseInt(val); 1268 } else { 1269 return (int) (Double.parseDouble(val)); 1271 } 1272 } else { 1273 return 0; 1274 } 1275 } catch (NumberFormatException nfe) { 1276 try { 1277 return (int) Double.parseDouble(val); 1279 } catch (NumberFormatException newNfe) { 1280 ; } 1282 1283 throw new SQLException ("Invalid value for getInt() - '" + val + "'", 1284 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1285 } 1286 } 1287 1288 1297 public int getInt(String columnName) throws java.sql.SQLException { 1298 return getInt(findColumn(columnName)); 1299 } 1300 1301 1315 public boolean isLast() throws SQLException { 1316 if (Driver.TRACE) { 1317 Object [] args = { }; 1318 Debug.methodCall(this, "isLast", args); 1319 } 1320 1321 boolean b = rowData.isLast(); 1322 1323 if (Driver.TRACE) { 1324 Debug.returnValue(this, "relative", new Boolean (b)); 1325 } 1326 1327 return b; 1328 } 1329 1330 1340 public long getLong(int columnIndex) throws java.sql.SQLException { 1341 checkRowPos(); 1342 1343 String val = null; 1344 1345 try { 1346 val = getString(columnIndex); 1347 1348 if ((val != null) && (val.length() != 0)) { 1349 if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1)) { 1350 return Long.parseLong(val); 1351 } else { 1352 return Double.doubleToLongBits(Double.parseDouble(val)); 1354 } 1355 } else { 1356 return 0; 1357 } 1358 } catch (NumberFormatException nfe) { 1359 try { 1360 return (long) Double.parseDouble(val); 1362 } catch (NumberFormatException newNfe) { 1363 ; } 1365 1366 throw new SQLException ("Invalid value for getLong() - '" + val 1367 + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1368 } 1369 } 1370 1371 1380 public long getLong(String columnName) throws java.sql.SQLException { 1381 return getLong(findColumn(columnName)); 1382 } 1383 1384 1392 public java.sql.ResultSetMetaData getMetaData() 1393 throws java.sql.SQLException { 1394 return new com.mysql.jdbc.ResultSetMetaData(fields); 1395 } 1396 1397 1419 public Object getObject(int columnIndex) throws java.sql.SQLException { 1420 checkRowPos(); 1421 1422 if (Driver.TRACE) { 1423 Object [] args = { new Integer (columnIndex) }; 1424 Debug.methodCall(this, "getObject", args); 1425 } 1426 1427 try { 1428 if (thisRow[columnIndex - 1] == null) { 1429 wasNullFlag = true; 1430 1431 return null; 1432 } 1433 } catch (ArrayIndexOutOfBoundsException aioobEx) { 1434 throw new java.sql.SQLException ("Column Index out of range ( " 1435 + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); 1436 } 1437 1438 wasNullFlag = false; 1439 1440 Field field; 1441 field = fields[columnIndex - 1]; 1442 1443 switch (field.getSQLType()) { 1444 case Types.BIT: 1445 return new Boolean (getBoolean(columnIndex)); 1446 1447 case Types.TINYINT: 1448 1449 return new Integer (getInt(columnIndex)); 1450 1451 case Types.SMALLINT: 1452 1453 return new Integer (getInt(columnIndex)); 1454 1455 case Types.INTEGER: 1456 1457 if (field.isUnsigned()) { 1458 return new Long (getLong(columnIndex)); 1459 } else { 1460 return new Integer (getInt(columnIndex)); 1461 } 1462 1463 case Types.BIGINT: 1464 1465 if (field.isUnsigned()) { 1466 return getBigDecimal(columnIndex); 1467 } else { 1468 return new Long (getLong(columnIndex)); 1469 } 1470 1471 case Types.DECIMAL: 1472 case Types.NUMERIC: 1473 1474 String stringVal = getString(columnIndex); 1475 BigDecimal val; 1476 1477 if (stringVal != null) { 1478 if (stringVal.length() == 0) { 1479 val = new BigDecimal (0); 1480 1481 return val; 1482 } 1483 1484 try { 1485 val = new BigDecimal (stringVal); 1486 } catch (NumberFormatException ex) { 1487 throw new java.sql.SQLException ( 1488 "Bad format for BigDecimal '" + stringVal 1489 + "' in column " + columnIndex + "(" 1490 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1491 } 1492 1493 return val; 1494 } else { 1495 return null; 1496 } 1497 1498 case Types.REAL: 1499 return new Float (getFloat(columnIndex)); 1500 1501 case Types.FLOAT: 1502 case Types.DOUBLE: 1503 return new Double (getDouble(columnIndex)); 1504 1505 case Types.CHAR: 1506 case Types.VARCHAR: 1507 case Types.LONGVARCHAR: 1508 return getString(columnIndex); 1509 1510 case Types.BINARY: 1511 case Types.VARBINARY: 1512 case Types.LONGVARBINARY: 1513 1514 if (!field.isBlob()) { 1515 return getString(columnIndex); 1516 } else if (!field.isBinary()) { 1517 return getString(columnIndex); 1518 } else { 1519 byte[] data = getBytes(columnIndex); 1520 Object obj = data; 1521 1522 if ((data != null) && (data.length >= 2)) { 1523 if ((data[0] == -84) && (data[1] == -19)) { 1524 try { 1526 ByteArrayInputStream bytesIn = new ByteArrayInputStream (data); 1527 ObjectInputStream objIn = new ObjectInputStream (bytesIn); 1528 obj = objIn.readObject(); 1529 objIn.close(); 1530 bytesIn.close(); 1531 } catch (ClassNotFoundException cnfe) { 1532 throw new SQLException ("Class not found: " 1533 + cnfe.toString() 1534 + " while reading serialized object"); 1535 } catch (IOException ex) { 1536 obj = data; } 1538 } 1539 } 1540 1541 return obj; 1542 } 1543 1544 case Types.DATE: 1545 return getDate(columnIndex); 1546 1547 case Types.TIME: 1548 return getTime(columnIndex); 1549 1550 case Types.TIMESTAMP: 1551 return getTimestamp(columnIndex); 1552 1553 default: 1554 return getString(columnIndex); 1555 } 1556 } 1557 1558 1579 public Object getObject(String columnName) throws java.sql.SQLException { 1580 return getObject(findColumn(columnName)); 1581 } 1582 1583 1595 public Object getObject(int i, java.util.Map map) throws SQLException { 1596 return getObject(i); 1597 } 1598 1599 1611 public Object getObject(String colName, java.util.Map map) 1612 throws SQLException { 1613 return getObject(findColumn(colName), map); 1614 } 1615 1616 1626 public java.sql.Ref getRef(int i) throws SQLException { 1627 throw new NotImplemented(); 1628 } 1629 1630 1640 public java.sql.Ref getRef(String colName) throws SQLException { 1641 throw new NotImplemented(); 1642 } 1643 1644 1656 public int getRow() throws SQLException { 1657 if (Driver.TRACE) { 1658 Object [] args = { }; 1659 Debug.methodCall(this, "getRow", args); 1660 } 1661 1662 int currentRow = rowData.getCurrentRowNumber(); 1663 int row = 0; 1664 1665 if (!rowData.isDynamic()) { 1668 if ((currentRow < 0) || rowData.isAfterLast() || rowData.isEmpty()) { 1669 row = 0; 1670 } else { 1671 row = currentRow + 1; 1672 } 1673 } else { 1674 row = currentRow + 1; 1676 } 1677 1678 if (Driver.TRACE) { 1679 Debug.returnValue(this, "getRow", new Integer (row)); 1680 } 1681 1682 if (Driver.TRACE) { 1683 Debug.returnValue(this, "getRow", new Integer (row)); 1684 } 1685 1686 return row; 1687 } 1688 1689 1699 public short getShort(int columnIndex) throws java.sql.SQLException { 1700 checkRowPos(); 1701 1702 String val = null; 1703 1704 try { 1705 val = getString(columnIndex); 1706 1707 if ((val != null) && (val.length() != 0)) { 1708 if ((val.indexOf("e") == -1) && (val.indexOf("E") == -1) 1709 && (val.indexOf(".") == -1)) { 1710 return Short.parseShort(val); 1711 } else { 1712 return (short) (Double.parseDouble(val)); 1714 } 1715 } else { 1716 return 0; 1717 } 1718 } catch (NumberFormatException nfe) { 1719 try { 1720 return (short) Double.parseDouble(val); 1722 } catch (NumberFormatException newNfe) { 1723 ; } 1725 1726 throw new SQLException ("Invalid value for getShort() - '" + val 1727 + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1728 } 1729 } 1730 1731 1740 public short getShort(String columnName) throws java.sql.SQLException { 1741 return getShort(findColumn(columnName)); 1742 } 1743 1744 1752 public java.sql.Statement getStatement() throws SQLException { 1753 return (java.sql.Statement ) owningStatement; 1754 } 1755 1756 1766 public String getString(int columnIndex) throws java.sql.SQLException { 1767 checkRowPos(); 1768 1769 if (fields == null) { 1770 throw new java.sql.SQLException ("Query generated no fields for ResultSet", 1771 SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); 1772 } 1773 1774 try { 1775 if (thisRow[columnIndex - 1] == null) { 1776 wasNullFlag = true; 1777 1778 return null; 1779 } else { 1780 wasNullFlag = false; 1781 } 1782 } catch (NullPointerException E) { 1783 wasNullFlag = true; 1784 1785 return null; 1786 } catch (ArrayIndexOutOfBoundsException aioobEx) { 1787 throw new java.sql.SQLException ("Column Index out of range ( " 1788 + columnIndex + " > " + fields.length + ").", SQLError.SQL_STATE_INVALID_COLUMN_NUMBER); 1789 } 1790 1791 String stringVal = null; 1792 columnIndex--; 1794 if ((connection != null) && connection.useUnicode()) { 1795 try { 1796 String encoding = this.fields[columnIndex].getCharacterSet(); 1797 1798 if (encoding == null) { 1799 stringVal = new String (thisRow[columnIndex]); 1800 } else { 1801 SingleByteCharsetConverter converter = this.connection.getCharsetConverter(encoding); 1802 1803 if (converter != null) { 1804 stringVal = converter.toString(thisRow[columnIndex]); 1805 } else { 1806 stringVal = new String (thisRow[columnIndex], encoding); 1807 } 1808 } 1809 } catch (java.io.UnsupportedEncodingException E) { 1810 throw new SQLException ("Unsupported character encoding '" 1811 + connection.getEncoding() + "'.", SQLError.SQL_STATE_GENERAL_ERROR); 1812 } 1813 } else { 1814 stringVal = StringUtils.toAsciiString(thisRow[columnIndex]); 1815 } 1816 1817 return stringVal; 1818 } 1819 1820 1830 public String getString(String columnName) throws java.sql.SQLException { 1831 return getString(findColumn(columnName)); 1832 } 1833 1834 1843 public synchronized Time getTime(int columnIndex) throws java.sql.SQLException { 1844 return getTimeInternal(columnIndex, this.defaultTimeZone); 1845 } 1846 1847 1856 public Time getTime(String columnName) throws java.sql.SQLException { 1857 return getTime(findColumn(columnName)); 1858 } 1859 1860 1872 public java.sql.Time getTime(int columnIndex, Calendar cal) 1873 throws SQLException { 1874 return getTimeInternal(columnIndex, cal.getTimeZone()); 1875 } 1876 1877 1889 public java.sql.Time getTime(String columnName, Calendar cal) 1890 throws SQLException { 1891 return getTime(findColumn(columnName), cal); 1892 } 1893 1894 1904 public synchronized Timestamp getTimestamp(int columnIndex) throws java.sql.SQLException { 1905 return getTimestampInternal(columnIndex, this.defaultTimeZone); 1906 } 1907 1908 1917 public Timestamp getTimestamp(String columnName) 1918 throws java.sql.SQLException { 1919 return getTimestamp(findColumn(columnName)); 1920 } 1921 1922 1935 public java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal) 1936 throws SQLException { 1937 return getTimestampInternal(columnIndex, cal.getTimeZone()); 1938 } 1939 1940 1953 public java.sql.Timestamp getTimestamp(String columnName, Calendar cal) 1954 throws SQLException { 1955 return getTimestamp(findColumn(columnName), cal); 1956 } 1957 1958 1967 public int getType() throws SQLException { 1968 return resultSetType; 1969 } 1970 1971 1974 public URL getURL(int colIndex) throws SQLException { 1975 String val = getString(colIndex); 1976 1977 if (val == null) { 1978 return null; 1979 } else { 1980 try { 1981 return new URL (val); 1982 } catch (MalformedURLException mfe) { 1983 throw new SQLException ("Malformed URL '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 1984 } 1985 } 1986 } 1987 1988 1991 public URL getURL(String colName) throws SQLException { 1992 String val = getString(colName); 1993 1994 if (val == null) { 1995 return null; 1996 } else { 1997 try { 1998 return new URL (val); 1999 } catch (MalformedURLException mfe) { 2000 throw new SQLException ("Malformed URL '" + val + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 2001 } 2002 } 2003 } 2004 2005 2020 public InputStream getUnicodeStream(int columnIndex) 2021 throws java.sql.SQLException { 2022 checkRowPos(); 2023 2024 return getBinaryStream(columnIndex); 2025 } 2026 2027 2036 public InputStream getUnicodeStream(String columnName) 2037 throws java.sql.SQLException { 2038 return getUnicodeStream(findColumn(columnName)); 2039 } 2040 2041 2060 public java.sql.SQLWarning getWarnings() throws java.sql.SQLException { 2061 return warningChain; 2062 } 2063 2064 2102 public boolean absolute(int row) throws SQLException { 2103 if (Driver.TRACE) { 2104 Object [] args = { new Integer (row) }; 2105 Debug.methodCall(this, "absolute", args); 2106 } 2107 2108 checkClosed(); 2109 2110 boolean b; 2111 2112 if (rowData.size() == 0) { 2113 b = false; 2114 } else { 2115 if (row == 0) { 2116 throw new SQLException ("Cannot absolute position to row 0", 2117 SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 2118 } 2119 2120 if (onInsertRow) { 2121 onInsertRow = false; 2122 } 2123 2124 if (doingUpdates) { 2125 doingUpdates = false; 2126 } 2127 2128 if (row == 1) { 2129 b = first(); 2130 } else if (row == -1) { 2131 b = last(); 2132 } else if (row > rowData.size()) { 2133 afterLast(); 2134 b = false; 2135 } else { 2136 if (row < 0) { 2137 int newRowPosition = rowData.size() + row + 1; 2139 2140 if (newRowPosition <= 0) { 2141 beforeFirst(); 2142 b = false; 2143 } else { 2144 b = absolute(newRowPosition); 2145 } 2146 } else { 2147 row--; rowData.setCurrentRow(row); 2149 thisRow = (byte[][]) rowData.getAt(row); 2150 b = true; 2151 } 2152 } 2153 } 2154 2155 if (Driver.TRACE) { 2156 Debug.returnValue(this, "absolute", new Boolean (b)); 2157 } 2158 2159 return b; 2160 } 2161 2162 2173 public void afterLast() throws SQLException { 2174 if (Driver.TRACE) { 2175 Object [] args = { }; 2176 Debug.methodCall(this, "afterLast", args); 2177 } 2178 2179 checkClosed(); 2180 2181 if (onInsertRow) { 2182 onInsertRow = false; 2183 } 2184 2185 if (doingUpdates) { 2186 doingUpdates = false; 2187 } 2188 2189 if (rowData.size() != 0) { 2190 rowData.afterLast(); 2191 thisRow = null; 2192 } 2193 } 2194 2195 2206 public void beforeFirst() throws SQLException { 2207 if (Driver.TRACE) { 2208 Object [] args = { }; 2209 Debug.methodCall(this, "beforeFirst", args); 2210 } 2211 2212 checkClosed(); 2213 2214 if (onInsertRow) { 2215 onInsertRow = false; 2216 } 2217 2218 if (doingUpdates) { 2219 doingUpdates = false; 2220 } 2221 2222 if (rowData.size() == 0) { 2223 return; 2224 } else { 2225 rowData.beforeFirst(); 2226 thisRow = null; 2227 } 2228 } 2229 2230 2240 public void cancelRowUpdates() throws SQLException { 2241 throw new NotUpdatable(); 2242 } 2243 2244 2250 public void clearWarnings() throws java.sql.SQLException { 2251 warningChain = null; 2252 } 2253 2254 2270 public void close() throws java.sql.SQLException { 2271 realClose(true); 2272 } 2273 2274 2282 public void deleteRow() throws SQLException { 2283 throw new NotUpdatable(); 2284 } 2285 2286 2295 public int findColumn(String columnName) throws java.sql.SQLException { 2296 Integer index; 2297 2298 synchronized (this) { 2299 if (!hasBuiltIndexMapping) { 2300 buildIndexMapping(); 2301 } 2302 } 2303 2304 index = (Integer ) columnNameToIndex.get(columnName); 2305 2306 if (index == null) { 2307 index = (Integer ) fullColumnNameToIndex.get(columnName); 2308 } 2309 2310 if (index != null) { 2311 return index.intValue() + 1; 2312 } else { 2313 String columnNameUC = columnName.toUpperCase(); 2315 2316 for (int i = 0; i < fields.length; i++) { 2317 if (fields[i].getName().toUpperCase().equals(columnNameUC)) { 2318 return i + 1; 2319 } else if (fields[i].getFullName().toUpperCase().equals(columnNameUC)) { 2320 return i + 1; 2321 } 2322 } 2323 2324 throw new java.sql.SQLException ("Column '" + columnName 2325 + "' not found.", SQLError.SQL_STATE_COLUMN_NOT_FOUND); 2326 } 2327 } 2328 2329 2341 public boolean first() throws SQLException { 2342 if (Driver.TRACE) { 2343 Object [] args = { }; 2344 Debug.methodCall(this, "first", args); 2345 } 2346 2347 checkClosed(); 2348 2349 if (onInsertRow) { 2350 onInsertRow = false; 2351 } 2352 2353 if (rowData.isEmpty()) { 2354 return false; 2355 } else { 2356 if (doingUpdates) { 2357 doingUpdates = false; 2358 } 2359 2360 rowData.beforeFirst(); 2361 thisRow = rowData.next(); 2362 2363 return true; 2364 } 2365 } 2366 2367 2376 public void insertRow() throws SQLException { 2377 throw new NotUpdatable(); 2378 } 2379 2380 2392 public boolean last() throws SQLException { 2393 if (Driver.TRACE) { 2394 Object [] args = { }; 2395 Debug.methodCall(this, "last", args); 2396 } 2397 2398 checkClosed(); 2399 2400 if (rowData.size() == 0) { 2401 return false; 2402 } else { 2403 if (onInsertRow) { 2404 onInsertRow = false; 2405 } 2406 2407 if (doingUpdates) { 2408 doingUpdates = false; 2409 } 2410 2411 rowData.beforeLast(); 2412 thisRow = rowData.next(); 2413 2414 return true; 2415 } 2416 } 2417 2418 2426 public void moveToCurrentRow() throws SQLException { 2427 throw new NotUpdatable(); 2428 } 2429 2430 2446 public void moveToInsertRow() throws SQLException { 2447 throw new NotUpdatable(); 2448 } 2449 2450 2466 public boolean next() throws java.sql.SQLException { 2467 if (Driver.TRACE) { 2468 Object [] args = { }; 2469 Debug.methodCall(this, "next", args); 2470 } 2471 2472 checkClosed(); 2473 2474 if (onInsertRow) { 2475 onInsertRow = false; 2476 } 2477 2478 if (doingUpdates) { 2479 doingUpdates = false; 2480 } 2481 2482 boolean b; 2483 2484 if (!reallyResult()) { 2485 throw new java.sql.SQLException ("ResultSet is from UPDATE. No Data", 2486 SQLError.SQL_STATE_GENERAL_ERROR); 2487 } 2488 2489 if (rowData.size() == 0) { 2490 b = false; 2491 } else { 2492 if (!rowData.hasNext()) { 2493 rowData.next(); 2495 b = false; 2496 } else { 2497 clearWarnings(); 2498 thisRow = rowData.next(); 2499 b = true; 2500 } 2501 } 2502 2503 if (Driver.TRACE) { 2504 Debug.returnValue(this, "next", new Boolean (b)); 2505 } 2506 2507 return b; 2508 } 2509 2510 2526 public boolean prev() throws java.sql.SQLException { 2527 checkClosed(); 2528 2529 int rowIndex = rowData.getCurrentRowNumber(); 2530 2531 if ((rowIndex - 1) >= 0) { 2532 rowIndex--; 2533 rowData.setCurrentRow(rowIndex); 2534 thisRow = (byte[][]) rowData.getAt(rowIndex); 2535 2536 return true; 2537 } else if ((rowIndex - 1) == -1) { 2538 rowIndex--; 2539 rowData.setCurrentRow(rowIndex); 2540 thisRow = null; 2541 2542 return false; 2543 } else { 2544 return false; 2545 } 2546 } 2547 2548 2565 public boolean previous() throws SQLException { 2566 if (Driver.TRACE) { 2567 Object [] args = { }; 2568 Debug.methodCall(this, "previous", args); 2569 } 2570 2571 if (onInsertRow) { 2572 onInsertRow = false; 2573 } 2574 2575 if (doingUpdates) { 2576 doingUpdates = false; 2577 } 2578 2579 return prev(); 2580 } 2581 2582 2600 public void refreshRow() throws SQLException { 2601 throw new NotUpdatable(); 2602 } 2603 2604 2628 public boolean relative(int rows) throws SQLException { 2629 if (Driver.TRACE) { 2630 Object [] args = { new Integer (rows) }; 2631 Debug.methodCall(this, "relative", args); 2632 } 2633 2634 checkClosed(); 2635 2636 if (rowData.size() == 0) { 2637 return false; 2638 } 2639 2640 rowData.moveRowRelative(rows); 2641 thisRow = rowData.getAt(rowData.getCurrentRowNumber()); 2642 2643 boolean b = (!rowData.isAfterLast() && !rowData.isBeforeFirst()); 2644 2645 if (Driver.TRACE) { 2646 Debug.returnValue(this, "relative", new Boolean (b)); 2647 } 2648 2649 return b; 2650 } 2651 2652 2665 public boolean rowDeleted() throws SQLException { 2666 throw new NotImplemented(); 2667 } 2668 2669 2681 public boolean rowInserted() throws SQLException { 2682 throw new NotImplemented(); 2683 } 2684 2685 2689 2701 public boolean rowUpdated() throws SQLException { 2702 throw new NotImplemented(); 2703 } 2704 2705 2708 public void updateArray(int arg0, Array arg1) throws SQLException { 2709 throw new NotImplemented(); 2710 } 2711 2712 2715 public void updateArray(String arg0, Array arg1) throws SQLException { 2716 throw new NotImplemented(); 2717 } 2718 2719 2733 public void updateAsciiStream(int columnIndex, java.io.InputStream x, 2734 int length) throws SQLException { 2735 throw new NotUpdatable(); 2736 } 2737 2738 2751 public void updateAsciiStream(String columnName, java.io.InputStream x, 2752 int length) throws SQLException { 2753 updateAsciiStream(findColumn(columnName), x, length); 2754 } 2755 2756 2769 public void updateBigDecimal(int columnIndex, BigDecimal x) 2770 throws SQLException { 2771 throw new NotUpdatable(); 2772 } 2773 2774 2786 public void updateBigDecimal(String columnName, BigDecimal x) 2787 throws SQLException { 2788 updateBigDecimal(findColumn(columnName), x); 2789 } 2790 2791 2805 public void updateBinaryStream(int columnIndex, java.io.InputStream x, 2806 int length) throws SQLException { 2807 throw new NotUpdatable(); 2808 } 2809 2810 2823 public void updateBinaryStream(String columnName, java.io.InputStream x, 2824 int length) throws SQLException { 2825 updateBinaryStream(findColumn(columnName), x, length); 2826 } 2827 2828 2831 public void updateBlob(int arg0, java.sql.Blob arg1) 2832 throws SQLException { 2833 throw new NotUpdatable(); 2834 } 2835 2836 2839 public void updateBlob(String arg0, java.sql.Blob arg1) 2840 throws SQLException { 2841 throw new NotUpdatable(); 2842 } 2843 2844 2857 public void updateBoolean(int columnIndex, boolean x) 2858 throws SQLException { 2859 throw new NotUpdatable(); 2860 } 2861 2862 2874 public void updateBoolean(String columnName, boolean x) 2875 throws SQLException { 2876 updateBoolean(findColumn(columnName), x); 2877 } 2878 2879 2891 public void updateByte(int columnIndex, byte x) throws SQLException { 2892 throw new NotUpdatable(); 2893 } 2894 2895 2906 public void updateByte(String columnName, byte x) throws SQLException { 2907 updateByte(findColumn(columnName), x); 2908 } 2909 2910 2923 public void updateBytes(int columnIndex, byte[] x) 2924 throws SQLException { 2925 throw new NotUpdatable(); 2926 } 2927 2928 2940 public void updateBytes(String columnName, byte[] x) 2941 throws SQLException { 2942 updateBytes(findColumn(columnName), x); 2943 } 2944 2945 2959 public void updateCharacterStream(int columnIndex, java.io.Reader x, 2960 int length) throws SQLException { 2961 throw new NotUpdatable(); 2962 } 2963 2964 2977 public void updateCharacterStream(String columnName, java.io.Reader reader, 2978 int length) throws SQLException { 2979 updateCharacterStream(findColumn(columnName), reader, length); 2980 } 2981 2982 2985 public void updateClob(int arg0, java.sql.Clob arg1) throws SQLException { 2986 throw new NotUpdatable(); 2987 } 2988 2989 2992 public void updateClob(String columnName, java.sql.Clob clob) throws SQLException { 2993 updateClob(findColumn(columnName), clob); 2994 } 2995 2996 3008 public void updateDate(int columnIndex, java.sql.Date x) 3009 throws SQLException { 3010 throw new NotUpdatable(); 3011 } 3012 3013 3024 public void updateDate(String columnName, java.sql.Date x) 3025 throws SQLException { 3026 updateDate(findColumn(columnName), x); 3027 } 3028 3029 3042 public void updateDouble(int columnIndex, double x) 3043 throws SQLException { 3044 throw new NotUpdatable(); 3045 } 3046 3047 3059 public void updateDouble(String columnName, double x) 3060 throws SQLException { 3061 updateDouble(findColumn(columnName), x); 3062 } 3063 3064 3076 public void updateFloat(int columnIndex, float x) throws SQLException { 3077 throw new NotUpdatable(); 3078 } 3079 3080 3091 public void updateFloat(String columnName, float x) 3092 throws SQLException { 3093 updateFloat(findColumn(columnName), x); 3094 } 3095 3096 3109 public void updateInt(int columnIndex, int x) throws SQLException { 3110 throw new NotUpdatable(); 3111 } 3112 3113 3125 public void updateInt(String columnName, int x) throws SQLException { 3126 updateInt(findColumn(columnName), x); 3127 } 3128 3129 3141 public void updateLong(int columnIndex, long x) throws SQLException { 3142 throw new NotUpdatable(); 3143 } 3144 3145 3156 public void updateLong(String columnName, long x) throws SQLException { 3157 updateLong(findColumn(columnName), x); 3158 } 3159 3160 3172 public void updateNull(int columnIndex) throws SQLException { 3173 throw new NotUpdatable(); 3174 } 3175 3176 3186 public void updateNull(String columnName) throws SQLException { 3187 updateNull(findColumn(columnName)); 3188 } 3189 3190 3206 public void updateObject(int columnIndex, Object x, int scale) 3207 throws SQLException { 3208 throw new NotUpdatable(); 3209 } 3210 3211 3224 public void updateObject(int columnIndex, Object x) 3225 throws SQLException { 3226 throw new NotUpdatable(); 3227 } 3228 3229 3244 public void updateObject(String columnName, Object x, int scale) 3245 throws SQLException { 3246 updateObject(findColumn(columnName), x); 3247 } 3248 3249 3261 public void updateObject(String columnName, Object x) 3262 throws SQLException { 3263 updateObject(findColumn(columnName), x); 3264 } 3265 3266 3269 public void updateRef(int arg0, Ref arg1) throws SQLException { 3270 throw new NotImplemented(); 3271 } 3272 3273 3276 public void updateRef(String arg0, Ref arg1) throws SQLException { 3277 throw new NotImplemented(); 3278 } 3279 3280 3288 public void updateRow() throws SQLException { 3289 throw new NotUpdatable(); 3290 } 3291 3292 3304 public void updateShort(int columnIndex, short x) throws SQLException { 3305 throw new NotUpdatable(); 3306 } 3307 3308 3319 public void updateShort(String columnName, short x) 3320 throws SQLException { 3321 updateShort(findColumn(columnName), x); 3322 } 3323 3324 3337 public void updateString(int columnIndex, String x) 3338 throws SQLException { 3339 throw new NotUpdatable(); 3340 } 3341 3342 3354 public void updateString(String columnName, String x) 3355 throws SQLException { 3356 updateString(findColumn(columnName), x); 3357 } 3358 3359 3371 public void updateTime(int columnIndex, java.sql.Time x) 3372 throws SQLException { 3373 throw new NotUpdatable(); 3374 } 3375 3376 3387 public void updateTime(String columnName, java.sql.Time x) 3388 throws SQLException { 3389 updateTime(findColumn(columnName), x); 3390 } 3391 3392 3405 public void updateTimestamp(int columnIndex, java.sql.Timestamp x) 3406 throws SQLException { 3407 throw new NotUpdatable(); 3408 } 3409 3410 3422 public void updateTimestamp(String columnName, java.sql.Timestamp x) 3423 throws SQLException { 3424 updateTimestamp(findColumn(columnName), x); 3425 } 3426 3427 3437 public boolean wasNull() throws java.sql.SQLException { 3438 return wasNullFlag; 3439 } 3440 3441 3449 3460 protected double getDoubleInternal(int colIndex) throws SQLException { 3461 String s = ""; 3462 3463 try { 3464 s = getString(colIndex); 3465 3466 if ((s == null) || (s.length() == 0)) { 3467 return 0; 3468 } 3469 3470 double d = Double.parseDouble(s); 3471 3472 if (this.useStrictFloatingPoint) { 3473 if (d == 2.147483648E9) { 3475 d = 2.147483647E9; 3477 } else if (d == 1.0000000036275E-15) { 3478 d = 1.0E-15; 3480 } else if (d == 9.999999869911E14) { 3481 d = 9.99999999999999E14; 3482 } else if (d == 1.4012984643248E-45) { 3483 d = 1.4E-45; 3484 } else if (d == 1.4013E-45) { 3485 d = 1.4E-45; 3486 } else if (d == 3.4028234663853E37) { 3487 d = 3.4028235E37; 3488 } else if (d == -2.14748E9) { 3489 d = -2.147483648E9; 3490 } else if (d == 3.40282E37) { 3491 d = 3.4028235E37; 3492 } 3493 } 3494 3495 return d; 3496 } catch (NumberFormatException e) { 3497 throw new SQLException ("Bad format for number '" + s + "'"); 3498 } 3499 } 3500 3501 3507 protected void setFirstCharOfQuery(char c) { 3508 this.firstCharOfQuery = c; 3509 } 3510 3511 3517 protected char getFirstCharOfQuery() { 3518 return this.firstCharOfQuery; 3519 } 3520 3521 3526 protected void setResultSetConcurrency(int concurrencyFlag) { 3527 resultSetConcurrency = concurrencyFlag; 3528 } 3529 3530 3536 protected void setResultSetType(int typeFlag) { 3537 resultSetType = typeFlag; 3538 } 3539 3540 3545 protected void setServerInfo(String info) { 3546 this.serverInfo = info; 3547 } 3548 3549 3554 protected String getServerInfo() { 3555 return this.serverInfo; 3556 } 3557 3558 3561 protected void buildIndexMapping() { 3562 int numFields = fields.length; 3563 columnNameToIndex = new HashMap (); 3564 fullColumnNameToIndex = new HashMap (); 3565 3566 3578 for (int i = numFields-1; i>= 0 ; i--) { 3579 Integer index = new Integer (i); 3580 String columnName = fields[i].getName(); 3581 String fullColumnName = fields[i].getFullName(); 3582 3583 if (columnName != null) { 3584 columnNameToIndex.put(columnName, index); 3585 columnNameToIndex.put(columnName.toUpperCase(), index); 3586 columnNameToIndex.put(columnName.toLowerCase(), index); 3587 } 3588 3589 if (fullColumnName != null) { 3590 fullColumnNameToIndex.put(fullColumnName, index); 3591 fullColumnNameToIndex.put(fullColumnName.toUpperCase(), index); 3592 fullColumnNameToIndex.put(fullColumnName.toLowerCase(), index); 3593 } 3594 } 3595 3596 hasBuiltIndexMapping = true; 3598 } 3599 3600 3605 protected void checkClosed() throws SQLException { 3606 if (isClosed) { 3607 throw new SQLException ("Operation not allowed after ResultSet closed", 3608 SQLError.SQL_STATE_GENERAL_ERROR); 3609 } 3610 } 3611 3612 3619 protected void checkRowPos() throws SQLException { 3620 checkClosed(); 3621 3622 if (!rowData.isDynamic() && (rowData.size() == 0)) { 3623 throw new SQLException ("Illegal operation on empty result set", 3624 SQLError.SQL_STATE_GENERAL_ERROR); 3625 } 3626 3627 if (rowData.isBeforeFirst()) { 3628 throw new SQLException ("Before start of result set", SQLError.SQL_STATE_GENERAL_ERROR); 3629 } 3630 3631 if (rowData.isAfterLast()) { 3632 throw new SQLException ("After end of result set", SQLError.SQL_STATE_GENERAL_ERROR); 3633 } 3634 } 3635 3636 protected void realClose(boolean closeRowData) throws SQLException { 3637 try { 3638 if (closeRowData && (this.rowData != null)) { 3639 rowData.close(); 3640 } 3641 } finally { 3642 this.defaultTimeZone = null; 3643 this.rowData = null; 3644 this.isClosed = true; 3645 } 3646 } 3647 3648 void setStatement(com.mysql.jdbc.Statement stmt) { 3649 owningStatement = stmt; 3650 } 3651 3652 long getUpdateCount() { 3653 return updateCount; 3654 } 3655 3656 long getUpdateID() { 3657 return updateId; 3658 } 3659 3660 boolean reallyResult() { 3661 return reallyResult; 3662 } 3663 3664 3675 private Time getTimeInternal(int columnIndex, TimeZone tz) 3676 throws java.sql.SQLException { 3677 int hr = 0; 3678 int min = 0; 3679 int sec = 0; 3680 3681 try { 3682 String timeAsString = getString(columnIndex); 3683 3684 if (timeAsString == null) { 3685 return null; 3686 } else { 3687 int length = timeAsString.length(); 3688 3689 if ((length > 0) && (timeAsString.charAt(0) == '0') 3690 && (timeAsString.equals("0000-00-00") 3691 || timeAsString.equals("0000-00-00 00:00:00") 3692 || timeAsString.equals("00000000000000"))) { 3693 wasNullFlag = true; 3694 3695 return null; 3696 } 3697 3698 Field timeColField = fields[columnIndex - 1]; 3699 3700 if (timeColField.getMysqlType() == MysqlDefs.FIELD_TYPE_TIMESTAMP) { 3701 switch (length) { 3703 case 14: 3704 case 12: { 3705 hr = Integer.parseInt(timeAsString.substring(length - 6, 3706 length - 4)); 3707 min = Integer.parseInt(timeAsString.substring(length 3708 - 4, length - 2)); 3709 sec = Integer.parseInt(timeAsString.substring(length 3710 - 2, length)); 3711 } 3712 3713 break; 3714 3715 case 10: { 3716 hr = Integer.parseInt(timeAsString.substring(6, 8)); 3717 min = Integer.parseInt(timeAsString.substring(8, 10)); 3718 sec = 0; 3719 } 3720 3721 break; 3722 3723 default: 3724 throw new SQLException ( 3725 "Timestamp too small to convert to Time value in column " 3726 + columnIndex + "(" + fields[columnIndex - 1] 3727 + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 3728 } 3729 3730 SQLWarning precisionLost = new SQLWarning ( 3731 "Precision lost converting TIMESTAMP to Time with getTime() on column " 3732 + columnIndex + "(" + fields[columnIndex - 1] 3733 + ")."); 3734 3735 if (warningChain == null) { 3736 warningChain = precisionLost; 3737 } else { 3738 warningChain.setNextWarning(precisionLost); 3739 } 3740 } else if (timeColField.getMysqlType() == MysqlDefs.FIELD_TYPE_DATETIME) { 3741 hr = Integer.parseInt(timeAsString.substring(11, 13)); 3742 min = Integer.parseInt(timeAsString.substring(14, 16)); 3743 sec = Integer.parseInt(timeAsString.substring(17, 19)); 3744 3745 SQLWarning precisionLost = new SQLWarning ( 3746 "Precision lost converting DATETIME to Time with getTime() on column " 3747 + columnIndex + "(" + fields[columnIndex - 1] 3748 + ")."); 3749 3750 if (warningChain == null) { 3751 warningChain = precisionLost; 3752 } else { 3753 warningChain.setNextWarning(precisionLost); 3754 } 3755 } else { 3756 if ((length != 5) && (length != 8)) { 3758 throw new SQLException ("Bad format for Time '" 3759 + timeAsString + "' in column " + columnIndex + "(" 3760 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 3761 } 3762 3763 hr = Integer.parseInt(timeAsString.substring(0, 2)); 3764 min = Integer.parseInt(timeAsString.substring(3, 5)); 3765 sec = (length == 5) ? 0 3766 : Integer.parseInt(timeAsString 3767 .substring(6)); 3768 } 3769 3770 return TimeUtil.changeTimezone(this.connection, 3771 fastTimeCreate(null, hr, min, sec), 3772 connection.getServerTimezone(), tz); 3773 } 3774 } catch (Exception ex) { 3775 throw new java.sql.SQLException (ex.getClass().getName(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 3776 } 3777 } 3778 3779 3790 private Timestamp getTimestampInternal(int columnIndex, TimeZone tz) 3791 throws java.sql.SQLException { 3792 String timestampValue = getString(columnIndex); 3793 3794 try { 3795 if (timestampValue == null) { 3796 return null; 3797 } else { 3798 int length = timestampValue.length(); 3799 3800 if ((length > 0) && (timestampValue.charAt(0) == '0') 3801 && (timestampValue.equals("0000-00-00") 3802 || timestampValue.equals("0000-00-00 00:00:00") 3803 || timestampValue.equals("00000000000000") 3804 || timestampValue.equals("0"))) { 3805 wasNullFlag = true; 3806 3807 return null; 3808 } else if (fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) { 3809 return TimeUtil.changeTimezone(this.connection, 3810 fastTimestampCreate(null, 3811 Integer.parseInt(timestampValue.substring(0, 4)) 3812 - 1900, 0, 1, 0, 0, 0, 0), 3813 connection.getServerTimezone(), tz); 3814 } else { 3815 switch (length) { 3817 case 19: { 3818 int year = Integer.parseInt(timestampValue.substring( 3819 0, 4)); 3820 int month = Integer.parseInt(timestampValue.substring( 3821 5, 7)); 3822 int day = Integer.parseInt(timestampValue.substring(8, 3823 10)); 3824 int hour = Integer.parseInt(timestampValue.substring( 3825 11, 13)); 3826 int minutes = Integer.parseInt(timestampValue.substring( 3827 14, 16)); 3828 int seconds = Integer.parseInt(timestampValue.substring( 3829 17, 19)); 3830 3831 return TimeUtil.changeTimezone(this.connection, 3832 fastTimestampCreate(null, year - 1900, month - 1, 3833 day, hour, minutes, seconds, 0), 3834 connection.getServerTimezone(), tz); 3835 } 3836 3837 case 14: { 3838 int year = Integer.parseInt(timestampValue.substring( 3839 0, 4)); 3840 int month = Integer.parseInt(timestampValue.substring( 3841 4, 6)); 3842 int day = Integer.parseInt(timestampValue.substring(6, 8)); 3843 int hour = Integer.parseInt(timestampValue.substring( 3844 8, 10)); 3845 int minutes = Integer.parseInt(timestampValue.substring( 3846 10, 12)); 3847 int seconds = Integer.parseInt(timestampValue.substring( 3848 12, 14)); 3849 3850 return TimeUtil.changeTimezone(this.connection, 3851 fastTimestampCreate(null, year - 1900, month - 1, 3852 day, hour, minutes, seconds, 0), 3853 connection.getServerTimezone(), tz); 3854 } 3855 3856 case 12: { 3857 int year = Integer.parseInt(timestampValue.substring( 3858 0, 2)); 3859 3860 if (year <= 69) { 3861 year = (year + 100); 3862 } 3863 3864 int month = Integer.parseInt(timestampValue.substring( 3865 2, 4)); 3866 int day = Integer.parseInt(timestampValue.substring(4, 6)); 3867 int hour = Integer.parseInt(timestampValue.substring( 3868 6, 8)); 3869 int minutes = Integer.parseInt(timestampValue.substring( 3870 8, 10)); 3871 int seconds = Integer.parseInt(timestampValue.substring( 3872 10, 12)); 3873 3874 return TimeUtil.changeTimezone(this.connection, 3875 fastTimestampCreate(null, year, month - 1, day, 3876 hour, minutes, seconds, 0), 3877 connection.getServerTimezone(), tz); 3878 } 3879 3880 case 10: { 3881 int year; 3882 int month; 3883 int day; 3884 int hour; 3885 int minutes; 3886 3887 if ((this.fields[columnIndex - 1].getMysqlType() == MysqlDefs.FIELD_TYPE_DATE) 3888 || (timestampValue.indexOf("-") != -1)) { 3889 year = Integer.parseInt(timestampValue.substring( 3890 0, 4)) - 1900; 3891 month = Integer.parseInt(timestampValue.substring( 3892 5, 7)); 3893 day = Integer.parseInt(timestampValue.substring(8, 3894 10)); 3895 hour = 0; 3896 minutes = 0; 3897 } else { 3898 year = Integer.parseInt(timestampValue.substring( 3899 0, 2)); 3900 3901 if (year <= 69) { 3902 year = (year + 100); 3903 } 3904 3905 month = Integer.parseInt(timestampValue.substring( 3906 2, 4)); 3907 day = Integer.parseInt(timestampValue.substring(4, 6)); 3908 hour = Integer.parseInt(timestampValue.substring( 3909 6, 8)); 3910 minutes = Integer.parseInt(timestampValue.substring( 3911 8, 10)); 3912 } 3913 3914 return TimeUtil.changeTimezone(this.connection, 3915 fastTimestampCreate(null, year, month - 1, day, 3916 hour, minutes, 0, 0), 3917 connection.getServerTimezone(), tz); 3918 } 3919 3920 case 8: { 3921 int year = Integer.parseInt(timestampValue.substring( 3922 0, 4)); 3923 int month = Integer.parseInt(timestampValue.substring( 3924 4, 6)); 3925 int day = Integer.parseInt(timestampValue.substring(6, 8)); 3926 3927 return TimeUtil.changeTimezone(this.connection, 3928 fastTimestampCreate(null, year - 1900, month - 1, 3929 day, 0, 0, 0, 0), 3930 connection.getServerTimezone(), tz); 3931 } 3932 3933 case 6: { 3934 int year = Integer.parseInt(timestampValue.substring( 3935 0, 2)); 3936 3937 if (year <= 69) { 3938 year = (year + 100); 3939 } 3940 3941 int month = Integer.parseInt(timestampValue.substring( 3942 2, 4)); 3943 int day = Integer.parseInt(timestampValue.substring(4, 6)); 3944 3945 return TimeUtil.changeTimezone(this.connection, 3946 fastTimestampCreate(null, year, month - 1, day, 0, 3947 0, 0, 0), connection.getServerTimezone(), tz); 3948 } 3949 3950 case 4: { 3951 int year = Integer.parseInt(timestampValue.substring( 3952 0, 2)); 3953 3954 if (year <= 69) { 3955 year = (year + 100); 3956 } 3957 3958 int month = Integer.parseInt(timestampValue.substring( 3959 2, 4)); 3960 3961 return TimeUtil.changeTimezone(this.connection, 3962 fastTimestampCreate(null, year, month - 1, 1, 0, 0, 3963 0, 0), connection.getServerTimezone(), tz); 3964 } 3965 3966 case 2: { 3967 int year = Integer.parseInt(timestampValue.substring( 3968 0, 2)); 3969 3970 if (year <= 69) { 3971 year = (year + 100); 3972 } 3973 3974 return TimeUtil.changeTimezone(this.connection, 3975 fastTimestampCreate(null, year, 0, 1, 0, 0, 0, 0), 3976 connection.getServerTimezone(), tz); 3977 } 3978 3979 default: 3980 throw new java.sql.SQLException ( 3981 "Bad format for Timestamp '" + timestampValue 3982 + "' in column " + columnIndex + "(" 3983 + fields[columnIndex - 1] + ").", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 3984 } 3985 } 3986 } 3987 } catch (Exception e) { 3988 throw new java.sql.SQLException ("Cannot convert value '" 3989 + timestampValue + "' from column " + columnIndex + "(" 3990 + timestampValue + " ) to TIMESTAMP.", SQLError.SQL_STATE_ILLEGAL_ARGUMENT); 3991 } 3992 } 3993 3994 private synchronized Date fastDateCreate(Calendar cal, int year, int month, 3995 int day) { 3996 if (cal == null) { 3997 if (this.fastDateCal == null) { 3998 this.fastDateCal = new GregorianCalendar (); 3999 4000 this.fastDateCal.setTimeZone(this.defaultTimeZone); 4001 } 4002 4003 cal = this.fastDateCal; 4004 } 4005 4006 cal.clear(); 4007 cal.set(year + 1900, month, day, 0, 0, 0); 4008 4009 long dateAsMillis = 0; 4010 4011 try { 4012 dateAsMillis = cal.getTimeInMillis(); 4013 } catch (IllegalAccessError iae) { 4014 dateAsMillis = cal.getTime().getTime(); 4016 } 4017 4018 return new Date (dateAsMillis); 4019 } 4020 4021 private synchronized Time fastTimeCreate(Calendar cal, int hour, 4022 int minute, int second) { 4023 if (cal == null) { 4024 if (this.fastDateCal == null) { 4025 this.fastDateCal = new GregorianCalendar (); 4026 4027 this.fastDateCal.setTimeZone(this.defaultTimeZone); 4028 } 4029 4030 cal = this.fastDateCal; 4031 } 4032 4033 cal.clear(); 4034 4035 cal.set(1970, 0, 1, hour, minute, second); 4037 4038 long timeAsMillis = 0; 4039 4040 try { 4041 timeAsMillis = cal.getTimeInMillis(); 4042 } catch (IllegalAccessError iae) { 4043 timeAsMillis = cal.getTime().getTime(); 4045 } 4046 4047 return new Time (timeAsMillis); 4048 } 4049 4050 private synchronized Timestamp fastTimestampCreate(Calendar cal, int year, 4051 int month, int day, int hour, int minute, int seconds, int secondsPart) { 4052 if (cal == null) { 4053 if (this.fastDateCal == null) { 4054 this.fastDateCal = new GregorianCalendar (); 4055 4056 this.fastDateCal.setTimeZone(this.defaultTimeZone); 4057 } 4058 4059 cal = this.fastDateCal; 4060 } 4061 4062 cal.clear(); 4063 cal.set(year + 1900, month, day, hour, minute, seconds); 4064 4065 long tsAsMillis = 0; 4066 4067 try { 4068 tsAsMillis = cal.getTimeInMillis(); 4069 } catch (IllegalAccessError iae) { 4070 tsAsMillis = cal.getTime().getTime(); 4072 } 4073 4074 Timestamp ts = new Timestamp (tsAsMillis); 4075 ts.setNanos(secondsPart); 4076 4077 return ts; 4078 } 4079} 4080 | Popular Tags |