Closed nicolasrod closed 3 years ago
Strange thing, when sql.Open() called, the driver's Open() still not called. https://golang.org/pkg/database/sql/#Open
And connection error occurred at Scan() called. https://github.com/nakagami/firebirdsql/blob/master/driver_test.go#L365
For check connection you can use function Ping()
Since database/sql creates a pool, connections aren't actually opened until a operation is executed. That's why jmoiron's sqlx package calls Ping() when you call sqlx.Connect
. That's just one of the reasons I use sqlx.
If you're new to Go, it might not occur to you to check for an error after you call
conn.QueryRow("SELECT Count(*) FROM rdb$relations").Scan(&n)
but any results you get are suspect until you've checked for an error.
Here is an explanation of this problem: https://stackoverflow.com/questions/32345124/why-does-sql-open-return-nil-as-error-when-it-should-not
Maybe the example in the README can do better error handling with conn.Ping or check for an error after running the query?
Don't know if I'm doing something wrong but when I try to run this example code:
It always returns "Relations count=0" even thou the connection string is invalid (I don't have any firebird sql server running in my test VM).