📄 monetresultset.java
字号:
return(ret); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a short in the Java programming language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is 0 * @throws SQLException if the ResultSet object does not contain columnName */ public short getShort(String columnName) throws SQLException { return(getShort(findColumn(columnName))); } /** * Retrieves the Statement object that produced this ResultSet object. If * the result set was generated some other way, such as by a * DatabaseMetaData method, this method returns null. * * @return the Statment object that produced this ResultSet object or null * if the result set was produced some other way */ public Statement getStatement() { return(statement); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a String in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if there is no such column */ public String getString(int columnIndex) throws SQLException { // note: all current getters use the string getter in the end // in the future this might change, and the lastColumnRead must // be updated for the wasNull command to work properly!!! try { String ret = result[columnIndex - 1]; lastColumnRead = columnIndex - 1; return(ret); } catch (IndexOutOfBoundsException e) { throw new SQLException("No such column " + columnIndex); } } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a String in the Java programming language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if the ResultSet object does not contain columnName */ public String getString(String columnName) throws SQLException { return(getString(findColumn(columnName))); } // This behaviour is according table B-6 of Sun JDBC Specification 3.0 /** * Helper method which parses the date/time value for columns of type * TIME, DATE and TIMESTAMP. For the types CHAR, VARCHAR and * LONGVARCHAR an attempt is made to parse the date according to the * given type. The given Calender object is filled with the parsed * data. Optional fractional seconds (nanos) are returned by this * method. If the underlying type of the column is none of the * mentioned six, January 1st 1970 0:00:00 GMT is returned.<br /> * The dates are parsed with the given Calendar. * * @param cal the Calendar to use/fill when parsing the date/time * @param col the column to parse * @param type the corresponding java.sql.Types type of the calling * function * @return the fractional seconds (nanos) or -1 if the value is NULL * @throws SQLException if a database error occurs */ private int getJavaDate(Calendar cal, int col, int type) throws SQLException { if (cal == null) throw new IllegalArgumentException("No Calendar object given!"); if (col <= 0) throw new IllegalArgumentException("No valid column number given!"); String monetDate; if ((monetDate = getString(col)) == null) return(-1); char[] monDate = monetDate.toCharArray(); int pos = 0; int tmp; int nanos = 0; // If we got a string type, set the datatype to the given // type so we attempt to parse it as the caller thinks it is. int dataType = MonetDriver.getJavaType(types[col - 1]); if (dataType == Types.CHAR || dataType == Types.VARCHAR || dataType == Types.LONGVARCHAR) { dataType = type; } // we want to start from scratch cal.clear(); try { switch(dataType) { default: throw new java.text.ParseException("Unsupported data type", 0); case Types.DATE: case Types.TIMESTAMP: // parse the date YYYY-MM-DD if we have enough chars if (monDate.length - pos < 10) break; // year tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 1000; tmp += getIntrinsicValue(monDate[pos], pos++) * 100; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.YEAR, tmp); if (monDate[pos++] != '-') throw new java.text.ParseException("Expected '-'", pos - 1); // month tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.MONTH, tmp - 1); if (monDate[pos++] != '-') throw new java.text.ParseException("Expected '-'", pos - 1); // day of month tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.DAY_OF_MONTH, tmp); if (dataType == Types.DATE || pos++ == monDate.length) break; case Types.TIME: // parse the time HH:mm:ss.SSSSSSSS if we have enough chars if (monDate.length - pos < 8) break; // hour of day tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.HOUR_OF_DAY, tmp); if (monDate[pos++] != ':') throw new java.text.ParseException("Expected ':'", pos - 1); // minute tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.MINUTE, tmp); if (monDate[pos++] != ':') throw new java.text.ParseException("Expected ':'", pos - 1); // second tmp = 0; tmp += getIntrinsicValue(monDate[pos], pos++) * 10; tmp += getIntrinsicValue(monDate[pos], pos++); cal.set(Calendar.SECOND, tmp); if (pos < monDate.length && monDate[pos] == '.') { int ctr; pos++; // nanos nanos = getIntrinsicValue(monDate[pos], pos++); for (ctr = 1; pos < monDate.length && monDate[pos] >= '0' && monDate[pos] <= '9'; ctr++) { if (ctr < 9) { nanos *= 10; nanos += ((int)monDate[pos] - (int)'0'); } if (ctr == 2) // we have three at this point cal.set(Calendar.MILLISECOND, nanos); pos++; } while (ctr++ < 9) nanos *= 10; } // we know whether we have a time with or without // time zone if the monet type ends with "tz" if (types[col - 1].endsWith("tz")) { int zone; // MonetDB/SQL99: Sign TwoDigitHours : Minutes tmp = pos < monDate.length ? monDate[pos++] : 0; if (tmp != '-' && tmp != '+') throw new java.text.ParseException("Expected '+' or '-'", pos - 1); // hour zone = 0; zone += getIntrinsicValue(monDate[pos], pos++) * 10; zone += getIntrinsicValue(monDate[pos], pos++); zone *= 60; // translate into minutes if (monDate[pos++] != ':') throw new java.text.ParseException("Expected ':'", pos - 1); // minute zone += getIntrinsicValue(monDate[pos], pos++) * 10; zone += getIntrinsicValue(monDate[pos], pos++); zone *= 60 * 1000; // translate into milliseconds if (tmp == '-') zone = -zone; // evaluate + or - cal.set(Calendar.ZONE_OFFSET, zone); } //break; (not needed because of the else/return) } } catch(java.text.ParseException e) { addWarning(e.getMessage() + " found: '" + monDate[e.getErrorOffset()] + "'" + " in: \"" + monetDate + "\"" + " at pos: " + e.getErrorOffset()); // default value cal.clear(); nanos = 0; } return(nanos); } /** * Small helper method that returns the intrinsic value of a char if * it represents a digit. If a non-digit character is encountered a * ParseException is thrown. * * @param c the char * @param pos the position * @return the intrinsic value of the char * @throws java.text.ParseException if c is not a digit */ final static int getIntrinsicValue(char c, int pos) throws java.text.ParseException { // note: don't use Character.isDigit() here, because // we only want ISO-LATIN-1 digits if (c >= '0' && c <= '9') { return((int)c - (int)'0'); } else { throw new java.text.ParseException("Expected a digit", pos); } } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Date object in the Java programming * language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs * @see #getDate(int col, Calendar cal) */ public java.sql.Date getDate(int columnIndex) throws SQLException { return(getDate(columnIndex, Calendar.getInstance())); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Date object in the Java programming * language. This method uses the given calendar to construct an appropriate * millisecond value for the date if the underlying database does not store * timezone information. * * @param columnIndex the first column is 1, the second is 2, ... * @param cal the java.util.Calendar object to use in constructing the date * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs */ public java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException { int ret = getJavaDate(cal, columnIndex, Types.DATE); return(ret == -1 ? null : new java.sql.Date(cal.getTime().getTime())); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Date object in the Java programming * language. * * @param columnName the SQL name of the column from which to retrieve the * value * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs */ public java.sql.Date getDate(String columnName) throws SQLException { return(getDate(columnName, Calendar.getInstance())); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Date object in the Java programming * language. This method uses the given calendar to construct an appropriate * millisecond value for the date if the underlying database does not store * timezone information. * * @param columnName the SQL name of the column from which to retrieve the * value * @param cal the java.util.Calendar object to use in constructing the date * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs */ public java.sql.Date getDate(String columnName, Calendar cal) throws SQLException { return(getDate(findColumn(columnName), cal)); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Time object in the Java programming * language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs */ public Time getTime(int columnIndex) throws SQLException { return(getTime(columnIndex, Calendar.getInstance())); } /** * Retrieves the value of the designated column in the current row of * this ResultSet object as a java.sql.Time object in the Java programming * language. This method uses the given calendar to construct an appropriate * millisecond value for the time if the underlying database does not store * timezone information. * * @param columnIndex the first column is 1, the second is 2, ... * @param cal the java.util.Calendar object to use in constructing the * timestamp * @return the column value as a java.sql.Timestamp object; if the value is * SQL NULL, the value returned is null in the Java programming * language * @throws SQLException if a database access error occurs */ public Time getTime(int columnIndex, Calendar cal) throws SQLException { int ret = getJavaDate(cal, columnIndex, Types.TIME); return(ret == -1 ? null : new Time(cal.getTime().getTime())); } /** * Retrieves the value of the designated column in the current row of this * ResultSet object as a java.sql.Time object in the Java programming * language. * * @param columnName the SQL name of the column * @return the column value; if the value is SQL NULL, the value returned * is null * @throws SQLException if a database access error occurs */ public Time getTime(String columnName) throws SQLException { return(getTime(columnName, Calendar.getInstance())); } /** * Retrieves the value of the designated column in the current row of * this ResultSet object as a java.sql.Time object in the Java programming * language. This method uses the given calendar to construct an appropriate * millisecond value for the time if the underlying database does not store * timezone information
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -