zio-quill icon indicating copy to clipboard operation
zio-quill copied to clipboard

Calling procedure using infix not working.

Open thunderkid opened this issue 7 years ago • 10 comments

Version: 1.2.1 Module: quill-async Database: mysql

I'm trying to call a stored procedure using infix.

    def myProcToyOdd = quote {
      (id: String) => infix"""call Try1()""".as[Query[Int]]
    }

    def procToyOdd() = run(myProcToyOdd("welsh"))

Expected behavior

Runs. (As a test if I replace the call Try1() with, eg, an UPDATE sql statement, it runs fine. And call Try1() runs fine from the sql console.)

Actual behavior

Returns the following error:

scala> 01:38:31.298 DEBUG [] [connection-handler][mysql-connection-1] - Channel became active
01:38:31.454 ERROR [] c.g.m.async.db.mysql.MySQLConnection - Received an error message -> ErrorMessage(1064,#42000,You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '()) x' at line 1)

thunderkid avatar May 24 '17 08:05 thunderkid

As said in documentation http://getquill.io/#extending-quill-infix infix is introduced to extends non-supported by quill features. To run native sql, please use execute* methods on context.

@thunderkid Feel free to reopen the issue if this is not working for you :)

mosyp avatar Jul 10 '17 19:07 mosyp

Is there any documentation on the execute* methods? I assume that to run a procedure that returns something I'd need to use executeActionReturning, but there are no docs on the meaning of the extractor or returningColumn args.

thunderkid avatar Apr 03 '18 07:04 thunderkid

@thunderkid there's not yet documentation, see https://github.com/getquill/quill/issues/1017.

mosyp avatar Apr 03 '18 08:04 mosyp

@thunderkid however it seems like calling stored procedure requires connection.prepareCall see this. Hence non of execute* methods does not provide such approach. I'd recommend to extend your jdbc context and use withConnection method to pull jdbc connection from pool and use it depending on your needs (calling prepareCall etc.)

mosyp avatar Apr 03 '18 08:04 mosyp

@mentegy Thanks. But that looks quite involved. I thought calling a stored procedure would be a fairly common use case.

thunderkid avatar Apr 03 '18 15:04 thunderkid

@thunderkid Did you have any luck calling stored procedure using Quill?

dalmat36 avatar Jan 23 '19 14:01 dalmat36

@dalmat36 No, I didn't. I actually switched back from Quill to Slick because of that. It made me rather nervous that something I'd consider pretty mainstream wasn't a standard feature in Quill. That was a while back, so perhaps things have changed by now.

thunderkid avatar Jan 23 '19 16:01 thunderkid

Reopening. We should provide an API for this, even though it doesn't seem a common use case

fwbrasil avatar Jan 23 '19 19:01 fwbrasil

Any updates on this please?

stondo avatar Sep 25 '22 12:09 stondo

In case anyone is interested I was eventually able to call a stored procedure on a MySql like database:

  override def clean(): Task[Option[Int]] = {
    val rawStoredProcedure = quote {
      sql"""select dolt_clean('--dry-run')""".pure.as[Int]
    }

    run(rawStoredProcedure).map(Option.apply)
  }

stondo avatar Oct 06 '22 10:10 stondo