-
Notifications
You must be signed in to change notification settings - Fork 346
/
exasol.go
35 lines (32 loc) · 1022 Bytes
/
exasol.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Package exasol defines and registers usql's Exasol driver.
//
// See: https://github.com/exasol/exasol-driver-go
package exasol
import (
"context"
"regexp"
_ "github.com/exasol/exasol-driver-go" // DRIVER
"github.com/xo/usql/drivers"
)
func init() {
errCodeRE := regexp.MustCompile(`^\[([0-9]+)]\s+`)
drivers.Register("exasol", drivers.Driver{
AllowMultilineComments: true,
LowerColumnNames: true,
Copy: drivers.CopyWithInsert(func(int) string { return "?" }),
Err: func(err error) (string, string) {
code, msg := "", err.Error()
if m := errCodeRE.FindStringSubmatch(msg); m != nil {
code, msg = m[1], errCodeRE.ReplaceAllString(msg, "")
}
return code, msg
},
Version: func(ctx context.Context, db drivers.DB) (string, error) {
var ver string
if err := db.QueryRowContext(ctx, `SELECT param_value FROM exa_metadata WHERE param_name = 'databaseProductVersion'`).Scan(&ver); err != nil {
return "", err
}
return "Exasol " + ver, nil
},
})
}