Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ git diff
diff --git a/sqlite3.go b/sqlite3.go
index ac888fb..3ccfef8 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -94,8 +94,7 @@ type SQLiteConn struct {
}
type config struct {
- params map[string]string
- loc *time.Location
+ loc *time.Location
}
// Tx struct.
@@ -538,49 +537,31 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
return nil
}
-func parseDSN(dsn string) (cfg *config, err error) {
- cfg = new(config)
- for i := 0; i < len(dsn); i++ {
- if dsn[i] == '?' {
- if err = parseDSNParams(cfg, dsn[i+1:]); err != nil {
- return
- }
- break
- }
+func parseDSN(dsn string) (*config, error) {
+ // init
+ cfg := &config{
+ loc: time.UTC,
}
- if cfg.loc == nil {
- cfg.loc = time.UTC
+
+ // parse dsn
+ parsed, err := url.Parse(dsn)
+ if err != nil {
+ return nil, err
}
- return
-}
-func parseDSNParams(cfg *config, params string) (err error) {
- for _, v := range strings.Split(params, "&") {
- param := strings.SplitN(v, "=", 2)
- if len(param) != 2 {
- continue
- }
+ params, err := url.ParseQuery(parsed.RawQuery)
+ if err != nil {
+ return nil, err
+ }
- // cfg params
- switch value := param[1]; param[0] {
- // Time Location
- case "_loc":
- if value, err = url.QueryUnescape(value); err != nil {
- return
- }
- cfg.loc, err = time.LoadLocation(value)
- if err != nil {
- return
- }
- default:
- // lazy init
- if cfg.params == nil {
- cfg.params = make(map[string]string)
- }
- if cfg.params[param[0]], err = url.QueryUnescape(value); err != nil {
- return
- }
+ // _loc
+ if val := params.Get("_loc"); val != "" {
+ var err error
+ cfg.loc, err = time.LoadLocation(val)
+ if err != nil {
+ return nil, err
}
}
- return
+
+ return cfg, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.