BeginTx reuses the same driver.Conn?

37 views
Skip to first unread message

Tamás Gulácsi

unread,
Aug 31, 2017, 2:40:25 AM8/31/17
to golang-sql

Hi,

I'm implementing database/sql/driver for Oracle with ODPI-C.
My first attemt for BeginTx was to create a new connection and return that - as Oracle manages transactions at the connection level, this seemed the only option.

Now I see that the database/sql.DB.BeginTx returns an sql.Tx with the same db object that it got, and my printfs says that everything executed on this Tx object uses the original (not-in-a-transaction) driver.Conn!

My temporary workaround is to just mark the connection as "in-transaction" in BeginTx, and this works, but means I "switch" the connection's mode,
thus a BeginTx cannot follow a BeginTx before Rollback/Commit - no nested transactions.

Which way is closer to what I shall implement in database/sql/driver? Which was intended?
I acknowledge that probably I was wrong, and the second approach is the better, but I don't know for sure.

Thanks,
Tamás Gulácsi

Daniel Theophanes

unread,
Aug 31, 2017, 1:15:10 PM8/31/17
to Tamás Gulácsi, golang-sql
Yes, use the second method; database/sql doesn't support nested transaction at this time regardless, so just "mode switch" an existing connection.

Let me know if I misunderstood something.

On Wed, Aug 30, 2017 at 11:40 PM Tamás Gulácsi <tgula...@gmail.com> wrote:

Tamás Gulácsi

unread,
Aug 31, 2017, 2:05:21 PM8/31/17
to golang-sql, tgula...@gmail.com
Ok, thanks!
Works, thus far.
Reply all
Reply to author
Forward
0 new messages