forked from xo/usql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite3.go
56 lines (48 loc) · 1.1 KB
/
sqlite3.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package sqlite3
import (
"strconv"
"strings"
// DRIVER: sqlite3
"github.com/mattn/go-sqlite3"
"github.com/xo/xoutil"
"github.com/xo/usql/drivers"
)
func init() {
drivers.Register("sqlite3", drivers.Driver{
AMC: true,
FP: drivers.ForceQueryParameters([]string{
"loc", "auto",
}),
V: func(db drivers.DB) (string, error) {
var ver string
err := db.QueryRow(`SELECT sqlite_version()`).Scan(&ver)
if err != nil {
return "", err
}
return "SQLite3 " + ver, nil
},
E: func(err error) (string, string) {
if e, ok := err.(sqlite3.Error); ok {
return strconv.Itoa(int(e.Code)), e.Error()
}
code, msg := "", err.Error()
if e, ok := err.(sqlite3.ErrNo); ok {
code = strconv.Itoa(int(e))
}
return code, msg
},
Cb: func(tfmt string, buf []byte) string {
// attempt to convert buf if it matches a time format, and if it
// does, then return a formatted time string.
s := string(buf)
if s != "" && strings.TrimSpace(s) != "" {
t := &xoutil.SqTime{}
err := t.Scan(buf)
if err == nil {
return t.Format(tfmt)
}
}
return s
},
})
}