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

Execute stored procedures with resultSet, MS SQL #1249

Closed
TemichCh opened this issue May 26, 2021 · 3 comments
Closed

Execute stored procedures with resultSet, MS SQL #1249

TemichCh opened this issue May 26, 2021 · 3 comments

Comments

@TemichCh
Copy link

I have SQL stored procedure that returns a resultset.
Trying to execute it with exec() statement, but dont have any results

transaction(getSQLCon(159)) {
exec(
            """
                    declare @face_id int, @data smalldatetime,@sklad_id int
                    set @data=getdate()
                    exec p_sklad_show_siz_by_face @face_id,@data,@sklad_id
    """.trimIndent()
        )
{
            println(it.fetchSize)
            while (it.next()) {
                result.add(
                    Ppe(
                        it.getString("mat_nam"),
                        it.getString("edizm_abr"),
                        it.getInt("matnorm_kol"),
                        it.getInt("matvid_kol"),
                        it.getDate("docum_dat")?.toLocalDate().toString(),
                        it.getDate("vozvrat_dat")?.toLocalDate().toString(),
                        it.getInt("snkd_n")
                    )
                )
            }
            //   return@exec result//.toTypedArray()
        }
}

If i add selec 1 as mat_nam in the first row in exec() statement, i go to the { while (it.next()) ....} block.

In Transaction.kt on the row № 93 there is code

        val result = when (type) {
                    StatementType.SELECT -> executeQuery()
                    else -> {
                        executeUpdate()
                        resultSet
                    }
                }

My query goes to else.
So to resolve it, i save procedure results to #table, and use second exec() where do select from that #table.

Maybe there is another way? thanks

@TemichCh
Copy link
Author

found this, it works. Thanks to vasily-kirichenko

#390

Tapac added a commit that referenced this issue Jun 4, 2021
How to call a MSSQL stored procedure and iterate over returned result set? #390
Execute stored procedures with resultSet, MS SQL #1249
Tapac added a commit that referenced this issue Jun 4, 2021
@Tapac
Copy link
Contributor

Tapac commented Jun 4, 2021

Duplicate of #390

@Tapac Tapac marked this as a duplicate of #390 Jun 4, 2021
@Tapac
Copy link
Contributor

Tapac commented Jun 4, 2021

@TemichCh , please check #390 (comment)

@Tapac Tapac closed this as completed Jun 4, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
How to call a MSSQL stored procedure and iterate over returned result set? JetBrains#390
Execute stored procedures with resultSet, MS SQL JetBrains#1249
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants