Hi all,
I wrote a package which wraps "
github.com/go-sql-driver/mysql" so that if the application gets disconnected from the database it will automatically reconnect and continue, without losing any commands. Unfortunately it appears to completely confuse the MySQL database.
The reconnection functionality appears to work fine, but for some reason random things happen when using this package.
One example is as follows:
// global variable
var lastinsertid *mysql.Stmt = db.MustPrepare(`SELECT LAST_INSERT_ID()`)
// later, after inserting
var id int
err = lastinsertid.QueryRow().Scan(&id)
The above never works, it does not return an error, it does not reconnect to the database, but neither does it update `id`. However, it does work if I do it the long-winded way, without the prepared statement:
// later after inserting,
var id int
li, err := db.Query(`SELECT LAST_INSERT_ID()`)
if err != nil {
panic(err)
}
if !li.Next() {
err = li.Err()
li.Close()
panic(err)
}
err = li.Scan(&id)
li.Close()
I am not using any goroutines so it doesn't make sense that `SELECT LAST_INSERT_ID()` fails when using the prepared query.
Any prepared statements from my package appear to do random things. They do not return an error but they will sometimes not update the passed pointer to the variable to to Scan, leaving it in whatever state it was before. I have not managed to work out exactly when things go wrong or why, but this package tends to entirely mess up any tables it operates on.
I can't see from the code of my package what I am doing wrong. As far as I can tell it looks good.
Thanks,
Alasdair