https://kotlinlang.org logo
#exposed
Title
# exposed
c

Chris

11/30/2023, 9:08 PM
I'd like to execute some raw sql to my db. I've been looking through the issues on the git repo, and have found some useful comments here and here. But when I try to write the sql string, the compiler complains with the message
id, name or spec expected, got blah
. I don't understand why I'm getting this error. Can anyone help?
a

Aleksei Tirman [JB]

12/04/2023, 8:43 AM
You can use the
exec
method within the transaction. Here is an example:
Copy code
transaction {
    exec("SELECT countrycodes.id FROM countrycodes") { rs ->
        while (rs.next()) {
            println(rs.getString("id"))
        }
    }
}
c

Chris

12/04/2023, 8:36 PM
That still gives me the same error. Thanks though. 👍
a

Aleksei Tirman [JB]

12/05/2023, 8:04 AM
You have to pass a block as the second argument. Does it work if you copy the entire snippet?
c

Chris

12/05/2023, 8:06 AM
I decided to revert to using jdbc, so I could make some progress. I'll bear that in mind when I try again. Thanks
c

Chantal Loncle

12/05/2023, 2:32 PM
@Chris An extra thought:
exec()
uses
@Language("sql")
on its
stmt
parameter to enable (generic sql) language injection for code assistance in the IDE. Assuming that you're using IntelliJ, if you've configured the SQL dialect to match your datasource and you're confident that the SQL statement is valid for that dialect, then the error may be related to this bug: KTIJ-24766
👀 1
c

Chris

12/05/2023, 2:39 PM
Thanks @Chantal Loncle, I'm am using Intellij. I am just getting started with connecting my database to my ktor server so am not really confident about much. I did have a search for the error message before posting here but nothing came up. Maybe this is indeed what I'm seeing, For the time being I'll stick with jdbc to get things up and running but will return to Exposed at some point and will bear this in mind also. 👍
👍 1
3 Views