use of org.hsqldb_voltpatches.types.BinaryData in project voltdb by VoltDB.
the class Scanner method convertToBit.
public synchronized BinaryData convertToBit(String s) {
BitMap map = new BitMap(32);
int bitIndex = map.size();
reset(s);
resetState();
byteOutputStream.reset(byteBuffer);
for (; currentPosition < limit; currentPosition++) {
int c = sqlString.charAt(currentPosition);
if (c == '0') {
bitIndex++;
} else if (c == '1') {
map.set(bitIndex);
bitIndex++;
} else {
token.tokenType = Tokens.X_MALFORMED_BIT_STRING;
token.isMalformed = true;
throw Error.error(ErrorCode.X_22018);
}
}
map.setSize(bitIndex);
return new BinaryData(map.getBytes(), map.size());
}
use of org.hsqldb_voltpatches.types.BinaryData in project voltdb by VoltDB.
the class Scanner method convertToBinary.
public synchronized BinaryData convertToBinary(String s) {
boolean hi = true;
byte b = 0;
reset(s);
resetState();
byteOutputStream.reset(byteBuffer);
for (; currentPosition < limit; currentPosition++, hi = !hi) {
int c = sqlString.charAt(currentPosition);
c = getHexValue(c);
if (c == -1) {
// bad character
token.tokenType = Tokens.X_MALFORMED_BINARY_STRING;
token.isMalformed = true;
break;
}
if (hi) {
b = (byte) (c << 4);
} else {
b += (byte) c;
byteOutputStream.writeByte(b);
}
}
if (!hi) {
// odd nibbles
token.tokenType = Tokens.X_MALFORMED_BINARY_STRING;
token.isMalformed = true;
}
if (token.isMalformed) {
throw Error.error(ErrorCode.X_22018);
}
BinaryData data = new BinaryData(byteOutputStream.toByteArray(), false);
byteOutputStream.reset(byteBuffer);
return data;
}
use of org.hsqldb_voltpatches.types.BinaryData in project voltdb by VoltDB.
the class Scanner method scanBitString.
void scanBitString() {
BitMap map = new BitMap(32);
while (true) {
scanBitStringPart(map);
if (token.isMalformed) {
return;
}
if (scanSeparator() && charAt(currentPosition) == '\'') {
continue;
}
break;
}
token.tokenValue = new BinaryData(map.getBytes(), map.size());
}
use of org.hsqldb_voltpatches.types.BinaryData in project voltdb by VoltDB.
the class Scanner method scanBinaryString.
void scanBinaryString() {
byteOutputStream.reset(byteBuffer);
while (true) {
scanBinaryStringPart();
if (token.isMalformed) {
return;
}
if (scanSeparator() && charAt(currentPosition) == '\'') {
continue;
}
break;
}
token.tokenValue = new BinaryData(byteOutputStream.toByteArray(), false);
byteOutputStream.reset(byteBuffer);
}
use of org.hsqldb_voltpatches.types.BinaryData in project voltdb by VoltDB.
the class JDBCPreparedStatement method setParameter.
/**
* The internal parameter value setter always converts the parameter to
* the Java type required for data transmission.
*
* @param i parameter index
* @param o object
* @throws SQLException if either argument is not acceptable.
*/
void setParameter(int i, Object o) throws SQLException {
checkSetParameterIndex(i, false);
i--;
if (o == null) {
parameterValues[i] = null;
return;
}
Type outType = parameterTypes[i];
switch(outType.typeCode) {
case Types.OTHER:
try {
if (o instanceof Serializable) {
o = new JavaObjectData((Serializable) o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
break;
case Types.SQL_BIT:
case Types.SQL_BIT_VARYING:
if (o instanceof Boolean) {
if (outType.precision == 1) {
byte[] bytes = ((Boolean) o).booleanValue() ? new byte[] { -0x80 } : new byte[] { 0 };
o = new BinaryData(bytes, 1);
break;
}
Util.throwError(Error.error(ErrorCode.X_42565));
}
try {
if (o instanceof byte[]) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
if (o instanceof String) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
// $FALL-THROUGH$
case Types.SQL_BINARY:
case Types.SQL_VARBINARY:
if (o instanceof byte[]) {
o = new BinaryData((byte[]) o, !connection.isNetConn);
break;
}
try {
if (o instanceof String) {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
}
} catch (HsqlException e) {
Util.throwError(e);
}
Util.throwError(Error.error(ErrorCode.X_42565));
break;
case Types.SQL_BLOB:
setBlobParameter(i + 1, o);
return;
case Types.SQL_CLOB:
setClobParameter(i + 1, o);
return;
case Types.SQL_DATE:
case Types.SQL_TIME_WITH_TIME_ZONE:
case Types.SQL_TIMESTAMP_WITH_TIME_ZONE:
case Types.SQL_TIME:
case Types.SQL_TIMESTAMP:
{
try {
if (o instanceof String) {
o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
break;
}
o = outType.convertJavaToSQL(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
}
// $FALL-THROUGH$
case Types.TINYINT:
case Types.SQL_SMALLINT:
case Types.SQL_INTEGER:
case Types.SQL_BIGINT:
case Types.SQL_REAL:
case Types.SQL_FLOAT:
case Types.SQL_DOUBLE:
case Types.SQL_NUMERIC:
case Types.SQL_DECIMAL:
try {
if (o instanceof String) {
o = outType.convertToType(connection.sessionProxy, o, Type.SQL_VARCHAR);
break;
}
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
// $FALL-THROUGH$
default:
try {
o = outType.convertToDefaultType(connection.sessionProxy, o);
break;
} catch (HsqlException e) {
Util.throwError(e);
}
}
parameterValues[i] = o;
}
Aggregations