?? resultsetrow.java
字號:
+ Messages.getString("ResultSet.___in_column__268")
+ (columnIndex + 1),
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
hr = StringUtils.getInt(timeAsBytes, offset + 0, offset + 2);
min = StringUtils.getInt(timeAsBytes, offset + 3, offset + 5);
sec = (length == 5) ? 0 : StringUtils.getInt(timeAsBytes,
offset + 6, offset + 8);
}
Calendar sessionCalendar = rs.getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
return TimeUtil.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimeCreate(sessionCalendar, hr,
min, sec), conn.getServerTimezoneTZ(), tz,
rollForward);
}
} catch (Exception ex) {
throw SQLError.createSQLException(ex.toString(),
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
public abstract Time getTimeFast(int columnIndex, Calendar targetCalendar,
TimeZone tz, boolean rollForward, ConnectionImpl conn,
ResultSetImpl rs) throws SQLException;
protected Timestamp getTimestampFast(int columnIndex,
byte[] timestampAsBytes, int offset, int length,
Calendar targetCalendar, TimeZone tz, boolean rollForward,
ConnectionImpl conn, ResultSetImpl rs) throws SQLException {
try {
Calendar sessionCalendar = conn.getUseJDBCCompliantTimezoneShift() ? conn
.getUtcCalendar()
: rs.getCalendarInstanceForSessionOrNew();
synchronized (sessionCalendar) {
boolean allZeroTimestamp = true;
boolean onlyTimePresent = false;
for (int i = 0; i < length; i++) {
if (timestampAsBytes[offset + i] == ':') {
onlyTimePresent = true;
break;
}
}
for (int i = 0; i < length; i++) {
byte b = timestampAsBytes[offset + i];
if (b == ' ' || b == '-' || b == '/') {
onlyTimePresent = false;
}
if (b != '0' && b != ' ' && b != ':' && b != '-'
&& b != '/' && b != '.') {
allZeroTimestamp = false;
break;
}
}
if (!onlyTimePresent && allZeroTimestamp) {
if (ConnectionPropertiesImpl.ZERO_DATETIME_BEHAVIOR_CONVERT_TO_NULL
.equals(conn.getZeroDateTimeBehavior())) {
return null;
} else if (ConnectionPropertiesImpl.ZERO_DATETIME_BEHAVIOR_EXCEPTION
.equals(conn.getZeroDateTimeBehavior())) {
throw SQLError
.createSQLException(
"Value '"
+ timestampAsBytes
+ "' can not be represented as java.sql.Timestamp",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
// We're left with the case of 'round' to a date Java _can_
// represent, which is '0001-01-01'.
return rs.fastTimestampCreate(null, 1, 1, 1, 0, 0, 0, 0);
} else if (this.metadata[columnIndex].getMysqlType() == MysqlDefs.FIELD_TYPE_YEAR) {
return TimeUtil.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, StringUtils.getInt(
timestampAsBytes, offset, 4), 1, 1,
0, 0, 0, 0), conn.getServerTimezoneTZ(),
tz, rollForward);
} else {
if (timestampAsBytes[offset + length - 1] == '.') {
length--;
}
// Convert from TIMESTAMP or DATE
switch (length) {
case 26:
case 25:
case 24:
case 23:
case 22:
case 21:
case 20:
case 19: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 4);
int month = StringUtils.getInt(timestampAsBytes,
offset + 5, offset + 7);
int day = StringUtils.getInt(timestampAsBytes,
offset + 8, offset + 10);
int hour = StringUtils.getInt(timestampAsBytes,
offset + 11, offset + 13);
int minutes = StringUtils.getInt(timestampAsBytes,
offset + 14, offset + 16);
int seconds = StringUtils.getInt(timestampAsBytes,
offset + 17, offset + 19);
int nanos = 0;
if (length > 19) {
int decimalIndex = -1;
for (int i = 0; i < length; i++) {
if (timestampAsBytes[offset + i] == '.') {
decimalIndex = i;
}
}
if (decimalIndex != -1) {
if ((decimalIndex + 2) <= length) {
nanos = StringUtils.getInt(
timestampAsBytes, decimalIndex + 1,
offset + length);
} else {
throw new IllegalArgumentException(); // re-thrown
// further
// down
// with
// a
// much better error message
}
}
}
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year, month,
day, hour, minutes, seconds,
nanos), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
case 14: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 4);
int month = StringUtils.getInt(timestampAsBytes,
offset + 4, offset + 6);
int day = StringUtils.getInt(timestampAsBytes,
offset + 6, offset + 8);
int hour = StringUtils.getInt(timestampAsBytes,
offset + 8, offset + 10);
int minutes = StringUtils.getInt(timestampAsBytes,
offset + 10, offset + 12);
int seconds = StringUtils.getInt(timestampAsBytes,
offset + 12, offset + 14);
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar,
rs.fastTimestampCreate(sessionCalendar,
year, month, day, hour,
minutes, seconds, 0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
case 12: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
if (year <= 69) {
year = (year + 100);
}
int month = StringUtils.getInt(timestampAsBytes,
offset + 2, offset + 4);
int day = StringUtils.getInt(timestampAsBytes,
offset + 4, offset + 6);
int hour = StringUtils.getInt(timestampAsBytes,
offset + 6, offset + 8);
int minutes = StringUtils.getInt(timestampAsBytes,
offset + 8, offset + 10);
int seconds = StringUtils.getInt(timestampAsBytes,
offset + 10, offset + 12);
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year + 1900,
month, day, hour, minutes,
seconds, 0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
case 10: {
int year;
int month;
int day;
int hour;
int minutes;
boolean hasDash = false;
for (int i = 0; i < length; i++) {
if (timestampAsBytes[offset + i] == '-') {
hasDash = true;
break;
}
}
if ((this.metadata[columnIndex].getMysqlType() == MysqlDefs.FIELD_TYPE_DATE)
|| hasDash) {
year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 4);
month = StringUtils.getInt(timestampAsBytes,
offset + 5, offset + 7);
day = StringUtils.getInt(timestampAsBytes,
offset + 8, offset + 10);
hour = 0;
minutes = 0;
} else {
year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
if (year <= 69) {
year = (year + 100);
}
month = StringUtils.getInt(timestampAsBytes,
offset + 2, offset + 4);
day = StringUtils.getInt(timestampAsBytes,
offset + 4, offset + 6);
hour = StringUtils.getInt(timestampAsBytes,
offset + 6, offset + 8);
minutes = StringUtils.getInt(timestampAsBytes,
offset + 8, offset + 10);
year += 1900; // two-digit year
}
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year, month,
day, hour, minutes, 0, 0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
case 8: {
boolean hasColon = false;
for (int i = 0; i < length; i++) {
if (timestampAsBytes[offset + i] == ':') {
hasColon = true;
break;
}
}
if (hasColon) {
int hour = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
int minutes = StringUtils.getInt(timestampAsBytes,
offset + 3, offset + 5);
int seconds = StringUtils.getInt(timestampAsBytes,
offset + 6, offset + 8);
return TimeUtil.changeTimezone(conn,
sessionCalendar, targetCalendar, rs
.fastTimestampCreate(
sessionCalendar, 1970, 1,
1, hour, minutes, seconds,
0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 4);
int month = StringUtils.getInt(timestampAsBytes,
offset + 4, offset + 6);
int day = StringUtils.getInt(timestampAsBytes,
offset + 6, offset + 8);
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year - 1900,
month - 1, day, 0, 0, 0, 0),
conn.getServerTimezoneTZ(), tz,
rollForward);
}
case 6: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
if (year <= 69) {
year = (year + 100);
}
int month = StringUtils.getInt(timestampAsBytes,
offset + 2, offset + 4);
int day = StringUtils.getInt(timestampAsBytes,
offset + 4, offset + 6);
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year + 1900,
month, day, 0, 0, 0, 0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
case 4: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
if (year <= 69) {
year = (year + 100);
}
int month = StringUtils.getInt(timestampAsBytes,
offset + 2, offset + 4);
return TimeUtil.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
sessionCalendar, year + 1900, month, 1,
0, 0, 0, 0),
conn.getServerTimezoneTZ(), tz, rollForward);
}
case 2: {
int year = StringUtils.getInt(timestampAsBytes,
offset + 0, offset + 2);
if (year <= 69) {
year = (year + 100);
}
return TimeUtil
.changeTimezone(conn, sessionCalendar,
targetCalendar, rs.fastTimestampCreate(
null, year + 1900, 1, 1, 0, 0,
0, 0), conn
.getServerTimezoneTZ(), tz,
rollForward);
}
default:
throw new java.sql.SQLException(
"Bad format for Timestamp '"
+ new String(timestampAsBytes)
+ "' in column " + (columnIndex + 1)
+ ".",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
}
} catch (Exception e) {
throw new java.sql.SQLException("Cannot convert value '"
+ getString(columnIndex, "ISO8859_1", conn)
+ "' from column " + (columnIndex + 1) + " to TIMESTAMP.",
SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
public abstract Timestamp getTimestampFast(int columnIndex,
Calendar targetCalendar, TimeZone tz, boolean rollForward,
ConnectionImpl conn, ResultSetImpl rs) throws SQLException;
/**
* Could the column value at the given index (which starts at 0) be
* interpreted as a floating-point number (has +/-/E/e in it)?
*
* @param index
* of the column value (starting at 0) to check.
*
* @return true if the column value at the given index looks like it might
* be a floating-point number, false if not.
*
* @throws SQLException
* if an error occurs
*/
public abstract boolean isFloatingPointNumber(int index)
throws SQLException;
/**
* Is the column value at the given index (which starts at 0) NULL?
*
* @param index
* of the column value (starting at 0) to check.
*
* @return true if the column value is NULL, false if not.
*
* @throws SQLException
* if an error occurs
*/
public abstract boolean isNull(int index) throws SQLException;
/**
* Returns the length of the column at the given index (which starts at 0).
*
* @param index
* of the column value (starting at 0) for which to return the
* length.
* @return the length of the requested column, 0 if null (clients of this
* interface should use isNull() beforehand to determine status of
* NULL values in the column).
*
* @throws SQLException
*/
public abstract long length(int index) throws SQLException;
/**
* Sets the given column value (only works currently with
* ByteArrayRowHolder).
*
* @param index
* index of the column value (starting at 0) to set.
* @param value
* the (raw) value to set
*
* @throws SQLException
* if an error occurs, or the concrete RowHolder doesn't support
* this operation.
*/
public abstract void setColumnValue(int index, byte[] value)
throws SQLException;
public void setMetadata(Field[] f) throws SQLException {
this.metadata = f;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -