Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unsigned integer #618

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ object CanBeParameter {
new CanBeParameter[BigInt] {
def sizeOf(param: BigInt) = 8
def typeCode(param: BigInt) = Type.LongLong
def write(writer: MysqlBufWriter, param: BigInt) = writer.writeBytes(param.toByteArray)
def write(writer: MysqlBufWriter, param: BigInt) = {
val byteArray: Array[Byte] = param.toByteArray
val lengthOfByteArray: Int = byteArray.length

if (lengthOfByteArray > 8) {
throw new Exception(s"The length of BigInt is larger than 8 bytes: $lengthOfByteArray > 8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you create a new named exception for this (can define it somehwere in the file here). I suggest something like:
class BigIntTooLongException(size: Int) extends Exception(s"BigInt is stored as an unsigned long and thus cannot be grater than 8 bytes. Size: $size"

}

for (i <- 0 until lengthOfByteArray) {
writer.writeByte(byteArray(i))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to reverse the order of the bytes we read out of byteArray: the BigInt.toByteArray method returns the bytes in big-endian order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry I should have checked that - sending the fix.

}

for (i <- lengthOfByteArray until 8) {
writer.writeByte(0x0)
}
}
}
}

Expand Down