Open jilen opened 8 years ago
Yeah, I started work for this at https://github.com/mauricio/postgresql-async/tree/closing-prepared-statements but the MySQL piece is giving me trouble, any help is appreciated.
@mauricio I am trying to close it like this. But actually with no confidence whether it is correctly
@mauricio I've looked into the code a bit, what do you think about a different API for releasing prepared statements?
If I understand the code in Connection
correctly you want to do this:
val sql = "SELECT something FROM t WHERE id=?"
for {
res <- connection.sendPreparedStatement(sql, List(1))
x <- doSomething(res)
_ <- connection.releasePreparedStatement(sql)
} yield x
I'd propose to let Connection.sendPreparedStatement
return a Future[PreparedStatementQueryResult]
, where PreparedStatementQueryResult
is something like this:
class PreparedStatementQueryResult(val rowsAffected: Long, val statusMessage: String, val rows: Option[ResultSet] = None)
extends QueryResult(rowsAffected, statusMessage, rows) {
def release(): Future[Boolean] = ???
}
What do you think about that?
User code might look like this:
for {
res <- connection.sendPreparedStatement("SELECT something FROM t WHERE id=?", List(1))
x <- doSomething(res)
_ <- res.release()
} yield x
I just saw that this issue is more or less a duplicate of #111 @mauricio :)
Yup, MySQL is still a pain in this :(
I merged the fix in jasync fork: https://github.com/jasync-sql/jasync-sql/issues/82
Which will leads to #194 . As a normal jdbc driver, we must call
statment.close
after using an prepared statement