Question

I noticed that an expression like this one:

DB.withConnection { implicit conn =>
  SQL("Select id, description FROM my_table WHERE id = {id}").on("id" -> 4)()
    .map {
      // TODO: Notice Integer.MAXVALUE = 2,147,483,647
      // How can I handle a value retrieved from a int(11) column ?
      case Row(id:Integer, Some(description:String) ) => 
            new UserInquiry(id.toLong, description)
    }

converts the value retrieved from the 'id' column in a java.lang.Integer. That's fine unless I define the size of my column over 9 digits in length. That would allow my table column to store values larger than java.lang.Integer class can hold.

How can we get over this limitation? The solution would be make Anorm converting to a BigInt or Long, but how?

Was it helpful?

Solution

The 11 in int(11) just presentation/formatting, so int will be 4 bytes and have the same min and max as the java Integer. If the column was BigInt you would have to map it to Long since it can be larger than the values an Integer can represent.

What is the size of column of int(11) in mysql in bytes?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top