From eb86f084da9fbd726693c5c3de1adf2aaabe5f82 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Sat, 26 Jul 2025 22:53:22 +0900 Subject: [PATCH] check authEnabled --- error_test.go | 5 ++++- sqlite3.go | 8 +++++--- sqlite3_opt_userauth.go | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/error_test.go b/error_test.go index 0ff14c1..fc6353d 100644 --- a/error_test.go +++ b/error_test.go @@ -43,7 +43,10 @@ func TestCorruptDbErrors(t *testing.T) { _, err = db.Exec("drop table foo") } - sqliteErr := err.(Error) + sqliteErr, ok := err.(Error) + if !ok { + t.Fatal(err) + } if sqliteErr.Code != ErrNotADB { t.Error("wrong error code for corrupted DB") } diff --git a/sqlite3.go b/sqlite3.go index a967cab..c0e4f5c 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1568,9 +1568,11 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) { } } - // Preform Authentication - if err := conn.Authenticate(authUser, authPass); err != nil { - return nil, err + if conn.AuthEnabled() { + // Preform Authentication + if err := conn.Authenticate(authUser, authPass); err != nil { + return nil, err + } } // Register: authenticate diff --git a/sqlite3_opt_userauth.go b/sqlite3_opt_userauth.go index a565c46..30c0965 100644 --- a/sqlite3_opt_userauth.go +++ b/sqlite3_opt_userauth.go @@ -161,7 +161,7 @@ func (c *SQLiteConn) AuthEnabled() (exists bool) { // 0 - Disabled // 1 - Enabled func (c *SQLiteConn) authEnabled() int { - return 1 + return 0 } // EOF