Skip to content

Commit 9c04406

Browse files
committed
fix(oracle): use view available for all users for driver.Version
Use v$version instead of v$instance because it is available to all users. Like v$instance, v$version is available in all non-ancient oracle versions. Testing Done: Oracle Express 21c and 11g For 11g: docker run -d -p 1521:1521 -e ORACLE_PASSWORD=foobar gvenzl/oracle-xe:11-slim ./usql oracle://sys:foobar@localhost/xe # version is shown correctly create user test identified by test; GRANT CREATE SESSION to test; \connect oracle://test:test@localhost/xe # version is still shown correctly, despite minimal privileges 21c in the issue was also tested that way.
1 parent ce82ecc commit 9c04406

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/oracle/orshared/orshared.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ func Register(name string, err func(error) (string, string), isPasswordErr func(
3737
},
3838
Version: func(ctx context.Context, db drivers.DB) (string, error) {
3939
var ver string
40-
if err := db.QueryRowContext(ctx, `SELECT version FROM v$instance`).Scan(&ver); err != nil {
40+
// this query must work for the "public" role - the minimum privileges for a user
41+
// v$version view is available at least since Oracle 10g (2003)
42+
if err := db.QueryRowContext(ctx, `SELECT banner FROM v$version`).Scan(&ver); err != nil {
4143
return "", err
4244
}
43-
return "Oracle Database " + ver, nil
45+
return ver, nil // typical output: Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production
4446
},
4547
User: func(ctx context.Context, db drivers.DB) (string, error) {
4648
var user string

0 commit comments

Comments
 (0)