Skip to content

Commit fd264d0

Browse files
committed
do not panic in init()
Instead return initDriver error from (Driver).Open.
1 parent cf37ce2 commit fd264d0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

conn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ type Conn struct {
2222
var accessDriverSubstr = strings.ToUpper(strings.Replace("DRIVER={Microsoft Access Driver", " ", "", -1))
2323

2424
func (d *Driver) Open(dsn string) (driver.Conn, error) {
25+
if d.initErr != nil {
26+
return nil, d.initErr
27+
}
28+
2529
var out api.SQLHANDLE
2630
ret := api.SQLAllocHandle(api.SQL_HANDLE_DBC, api.SQLHANDLE(d.h), &out)
2731
if IsError(ret) {

driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ var drv Driver
1616

1717
type Driver struct {
1818
Stats
19-
h api.SQLHENV // environment handle
19+
h api.SQLHENV // environment handle
20+
initErr error
2021
}
2122

2223
func initDriver() error {
@@ -72,7 +73,7 @@ func (d *Driver) Close() error {
7273
func init() {
7374
err := initDriver()
7475
if err != nil {
75-
panic(err)
76+
drv.initErr = err
7677
}
7778
sql.Register("odbc", &drv)
7879
}

0 commit comments

Comments
 (0)