📄 bufferrow.java
字号:
+ Messages.getString("MysqlIO.98")
+ (index + 1)
+ Messages.getString("MysqlIO.99") //$NON-NLS-1$ //$NON-NLS-2$
+ this.metadata.length + Messages.getString("MysqlIO.100"), //$NON-NLS-1$
SQLError.SQL_STATE_GENERAL_ERROR);
}
}
public int getInt(int columnIndex) throws SQLException {
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
if (length == Buffer.NULL_LENGTH) {
return 0;
}
return StringUtils.getInt(this.rowFromServer.getByteBuffer(), offset,
offset + (int) length);
}
public long getLong(int columnIndex) throws SQLException {
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
if (length == Buffer.NULL_LENGTH) {
return 0;
}
return StringUtils.getLong(this.rowFromServer.getByteBuffer(), offset,
offset + (int) length);
}
public double getNativeDouble(int columnIndex) throws SQLException {
if (isNull(columnIndex)) {
return 0;
}
findAndSeekToOffset(columnIndex);
int offset = this.rowFromServer.getPosition();
return getNativeDouble(this.rowFromServer.getByteBuffer(), offset);
}
public float getNativeFloat(int columnIndex) throws SQLException {
if (isNull(columnIndex)) {
return 0;
}
findAndSeekToOffset(columnIndex);
int offset = this.rowFromServer.getPosition();
return getNativeFloat(this.rowFromServer.getByteBuffer(), offset);
}
public int getNativeInt(int columnIndex) throws SQLException {
if (isNull(columnIndex)) {
return 0;
}
findAndSeekToOffset(columnIndex);
int offset = this.rowFromServer.getPosition();
return getNativeInt(this.rowFromServer.getByteBuffer(), offset);
}
public long getNativeLong(int columnIndex) throws SQLException {
if (isNull(columnIndex)) {
return 0;
}
findAndSeekToOffset(columnIndex);
int offset = this.rowFromServer.getPosition();
return getNativeLong(this.rowFromServer.getByteBuffer(), offset);
}
public short getNativeShort(int columnIndex) throws SQLException {
if (isNull(columnIndex)) {
return 0;
}
findAndSeekToOffset(columnIndex);
int offset = this.rowFromServer.getPosition();
return getNativeShort(this.rowFromServer.getByteBuffer(), offset);
}
public Timestamp getNativeTimestamp(int columnIndex,
Calendar targetCalendar, TimeZone tz, boolean rollForward,
ConnectionImpl conn, ResultSetImpl rs) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getNativeTimestamp(this.rowFromServer.getByteBuffer(), offset,
(int) length, targetCalendar, tz, rollForward, conn, rs);
}
public Reader getReader(int columnIndex) throws SQLException {
InputStream stream = getBinaryInputStream(columnIndex);
if (stream == null) {
return null;
}
try {
return new InputStreamReader(stream, this.metadata[columnIndex]
.getCharacterSet());
} catch (UnsupportedEncodingException e) {
SQLException sqlEx = SQLError.createSQLException("");
sqlEx.initCause(e);
throw sqlEx;
}
}
public String getString(int columnIndex, String encoding, ConnectionImpl conn)
throws SQLException {
if (this.isBinaryEncoded) {
if (isNull(columnIndex)) {
return null;
}
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
if (length == Buffer.NULL_LENGTH) {
return null;
}
if (length == 0) {
return "";
}
// TODO: I don't like this, would like to push functionality back
// to the buffer class somehow
int offset = this.rowFromServer.getPosition();
return getString(encoding, conn, this.rowFromServer.getByteBuffer(),
offset, (int) length);
}
public Time getTimeFast(int columnIndex, Calendar targetCalendar,
TimeZone tz, boolean rollForward, ConnectionImpl conn,
ResultSetImpl rs) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getTimeFast(columnIndex, this.rowFromServer.getByteBuffer(),
offset, (int)length, targetCalendar, tz, rollForward, conn, rs);
}
public Timestamp getTimestampFast(int columnIndex, Calendar targetCalendar,
TimeZone tz, boolean rollForward, ConnectionImpl conn,
ResultSetImpl rs) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getTimestampFast(columnIndex,
this.rowFromServer.getByteBuffer(), offset, (int)length, targetCalendar, tz,
rollForward, conn, rs);
}
public boolean isFloatingPointNumber(int index) throws SQLException {
if (this.isBinaryEncoded) {
switch (this.metadata[index].getSQLType()) {
case Types.FLOAT:
case Types.DOUBLE:
case Types.DECIMAL:
case Types.NUMERIC:
return true;
default:
return false;
}
}
findAndSeekToOffset(index);
long length = this.rowFromServer.readFieldLength();
if (length == Buffer.NULL_LENGTH) {
return false;
}
if (length == 0) {
return false;
}
for (int i = 0; i < (int) length; i++) {
char c = (char) this.rowFromServer.readByte();
if ((c == 'e') || (c == 'E')) {
return true;
}
}
return false;
}
public boolean isNull(int index) throws SQLException {
if (!this.isBinaryEncoded) {
findAndSeekToOffset(index);
return this.rowFromServer.readFieldLength() == Buffer.NULL_LENGTH;
}
return this.isNull[index];
}
public long length(int index) throws SQLException {
findAndSeekToOffset(index);
long length = this.rowFromServer.readFieldLength();
if (length == Buffer.NULL_LENGTH) {
return 0;
}
return length;
}
public void setColumnValue(int index, byte[] value) throws SQLException {
throw new OperationNotSupportedException();
}
public ResultSetRow setMetadata(Field[] f) throws SQLException {
super.setMetadata(f);
if (this.isBinaryEncoded) {
setupIsNullBitmask();
}
return this;
}
/**
* Unpacks the bitmask at the head of the row packet that tells us what
* columns hold null values, and sets the "home" position directly after the
* bitmask.
*/
private void setupIsNullBitmask() throws SQLException {
if (this.isNull != null) {
return; // we've already done this
}
this.rowFromServer.setPosition(this.preNullBitmaskHomePosition);
int nullCount = (this.metadata.length + 9) / 8;
byte[] nullBitMask = new byte[nullCount];
for (int i = 0; i < nullCount; i++) {
nullBitMask[i] = this.rowFromServer.readByte();
}
this.homePosition = this.rowFromServer.getPosition();
this.isNull = new boolean[this.metadata.length];
int nullMaskPos = 0;
int bit = 4; // first two bits are reserved for future use
for (int i = 0; i < this.metadata.length; i++) {
this.isNull[i] = ((nullBitMask[nullMaskPos] & bit) != 0);
if (((bit <<= 1) & 255) == 0) {
bit = 1; /* To next byte */
nullMaskPos++;
}
}
}
public Date getDateFast(int columnIndex, ConnectionImpl conn,
ResultSetImpl rs, Calendar targetCalendar) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getDateFast(columnIndex, this.rowFromServer.getByteBuffer(),
offset, (int)length, conn, rs, targetCalendar);
}
public java.sql.Date getNativeDate(int columnIndex, ConnectionImpl conn,
ResultSetImpl rs) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getNativeDate(columnIndex, this.rowFromServer.getByteBuffer(),
offset, (int) length, conn, rs);
}
public Object getNativeDateTimeValue(int columnIndex, Calendar targetCalendar,
int jdbcType, int mysqlType, TimeZone tz,
boolean rollForward, ConnectionImpl conn, ResultSetImpl rs)
throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getNativeDateTimeValue(columnIndex, this.rowFromServer
.getByteBuffer(), offset, (int) length, targetCalendar, jdbcType,
mysqlType, tz, rollForward, conn, rs);
}
public Time getNativeTime(int columnIndex, Calendar targetCalendar,
TimeZone tz, boolean rollForward, ConnectionImpl conn,
ResultSetImpl rs) throws SQLException {
if (isNull(columnIndex)) {
return null;
}
findAndSeekToOffset(columnIndex);
long length = this.rowFromServer.readFieldLength();
int offset = this.rowFromServer.getPosition();
return getNativeTime(columnIndex, this.rowFromServer.getByteBuffer(),
offset, (int) length, targetCalendar, tz, rollForward, conn, rs);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -