Plain SQL GetResult is restricted to 22 columns

570 views
Skip to first unread message

Michael Slinn

unread,
Jan 4, 2013, 8:47:05 PM1/4/13
to scala...@googlegroups.com
There is no winning with this.

Dickon Field

unread,
Jan 5, 2013, 4:13:51 PM1/5/13
to scala...@googlegroups.com
Does this constraint apply to any row or is this only if you parse the row to a flat tuple? So, if you parse the row to a tuple of tuples, or tuple of case classes, does this not overcome the constraint?


On Sat, Jan 5, 2013 at 1:47 AM, Michael Slinn <msl...@gmail.com> wrote:
There is no winning with this.

--
 
 
 

Ryan Bair

unread,
Jan 5, 2013, 4:29:30 PM1/5/13
to scala...@googlegroups.com
Tuples and case classes are limited to 22 fields in Scala. So either way you're going to hit it.

I agree that this is a real pain. I have a few views that are much wider than 22 columns which I ended up falling back on JDBC for.


--
 
 
 

Dickon Field

unread,
Jan 5, 2013, 6:12:01 PM1/5/13
to scala...@googlegroups.com
I guess my point is this is only a constraint if you want to parse a row to a single, flat tuple of more than 22 fields. If you define a parser to create a nested tuple of tuples then this will work for rows of more than 22 fields. Do I have that right?


--
 
 
 

Michael Slinn

unread,
Jan 6, 2013, 1:55:32 AM1/6/13
to scala...@googlegroups.com
I believe you are correct, but I have yet to see a working example.

Here is Play Anorm code that DOES insert >22 columns into a database, using Play 2.1 and Scala 2.10-RC5. I built Play 2.1 against Scala 2.10-RC5 using my fork of the project, but this code should work fine for Scala 2.9.x also, especially since Anorm is now a small independent Scala module. Now I can move forward with other things.

Stefan Zeiger

unread,
Jan 8, 2013, 12:49:56 PM1/8/13
to scala...@googlegroups.com
On 2013-01-05 2:47, Michael Slinn wrote:
There is no winning with this.

No, it's not.

Here's some win:

    val q = sql"select 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23"
    val r1 = q.as[((Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int), (Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int))].first
    println(r1)

And here, too:

    class Foo(v1: Int, v2: Int, v3: Int, v4: Int, v5: Int, v6: Int, v7: Int, v8: Int, v9: Int, v10: Int, v11: Int, v12: Int, v13: Int, v14: Int, v15: Int, v16: Int, v17: Int, v18: Int, v19: Int, v20: Int, v21: Int, v22: Int, v23: Int) {
      override def toString = s"Foo($v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v11, $v12, $v13, $v14, $v15, $v16, $v17, $v18, $v19, $v20, $v21, $v22, $v23)"
    }
    implicit val getFooResult = GetResult(r => new Foo(r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<, r.<<))
    val r2 = q.as[Foo].first
    println(r2)

--
Stefan Zeiger
Typesafe - The software stack for applications that scale
Twitter: @StefanZeiger

Michael Slinn

unread,
Jan 24, 2013, 1:27:24 PM1/24/13
to scala...@googlegroups.com
Here is a controller from a Play 2.1 sample project that shows how to use nested mappings to overcome Play's 18 field limit. This repository contains the sample applications for the book Play for Scala. This example could form the basis for a combined Slick/Play working example of how to handle more than 22 fields. Perhaps this might be enough for the Slick team to integrate the two products?

I have a comprehensive Play 2.1-RC2 app in advanced development and would be happy to contribute to the sample project.

Mike
Reply all
Reply to author
Forward
0 new messages