summaryrefslogtreecommitdiff
path: root/vendor/modernc.org/sqlite/sqlite.go
diff options
context:
space:
mode:
authorLibravatar kim (grufwub) <grufwub@gmail.com>2021-09-08 21:12:23 +0100
committerLibravatar kim (grufwub) <grufwub@gmail.com>2021-09-08 21:12:23 +0100
commit71a4f8667c63c2ffbe58eee7b5e963d3e09a42de (patch)
treed78cb33084b46cc0490b81a6422eee5207f608cc /vendor/modernc.org/sqlite/sqlite.go
parentrework media processing a little bit (#191) (diff)
downloadgotosocial-71a4f8667c63c2ffbe58eee7b5e963d3e09a42de.tar.xz
update sqlite library -> v1.13.0
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat (limited to 'vendor/modernc.org/sqlite/sqlite.go')
-rw-r--r--vendor/modernc.org/sqlite/sqlite.go38
1 files changed, 36 insertions, 2 deletions
diff --git a/vendor/modernc.org/sqlite/sqlite.go b/vendor/modernc.org/sqlite/sqlite.go
index 30f671478..ec3873e7c 100644
--- a/vendor/modernc.org/sqlite/sqlite.go
+++ b/vendor/modernc.org/sqlite/sqlite.go
@@ -14,6 +14,7 @@ import (
"fmt"
"io"
"math"
+ "net/url"
"reflect"
"strconv"
"strings"
@@ -727,10 +728,23 @@ type conn struct {
sync.Mutex
}
-func newConn(name string) (*conn, error) {
+func newConn(dsn string) (*conn, error) {
+ var query string
+
+ // Parse the query parameters from the dsn and them from the dsn if not prefixed by file:
+ // https://github.com/mattn/go-sqlite3/blob/3392062c729d77820afc1f5cae3427f0de39e954/sqlite3.go#L1046
+ // https://github.com/mattn/go-sqlite3/blob/3392062c729d77820afc1f5cae3427f0de39e954/sqlite3.go#L1383
+ pos := strings.IndexRune(dsn, '?')
+ if pos >= 1 {
+ query = dsn[pos+1:]
+ if !strings.HasPrefix(dsn, "file:") {
+ dsn = dsn[:pos]
+ }
+ }
+
c := &conn{tls: libc.NewTLS()}
db, err := c.openV2(
- name,
+ dsn,
sqlite3.SQLITE_OPEN_READWRITE|sqlite3.SQLITE_OPEN_CREATE|
sqlite3.SQLITE_OPEN_FULLMUTEX|
sqlite3.SQLITE_OPEN_URI,
@@ -745,9 +759,29 @@ func newConn(name string) (*conn, error) {
return nil, err
}
+ if err = applyPragmas(c, query); err != nil {
+ c.Close()
+ return nil, err
+ }
+
return c, nil
}
+func applyPragmas(c *conn, query string) error {
+ q, err := url.ParseQuery(query)
+ if err != nil {
+ return err
+ }
+ for _, v := range q["_pragma"] {
+ cmd := "pragma " + v
+ _, err := c.exec(context.Background(), cmd, nil)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
// const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
func (c *conn) columnBlob(pstmt uintptr, iCol int) (v []byte, err error) {
p := sqlite3.Xsqlite3_column_blob(c.tls, pstmt, int32(iCol))