add CSV module
diff --git a/sqlite3-binding.c b/sqlite3-binding.c
index 825e7d8..6ad7ac0 100644
--- a/sqlite3-binding.c
+++ b/sqlite3-binding.c
@@ -201403,6 +201403,6 @@
/************** End of fts5.c ************************************************/
#else // USE_LIBSQLITE3
- // If users really want to link against the system sqlite3 we
+// If users really want to link against the system sqlite3 we
// need to make this file a noop.
- #endif
+#endif
diff --git a/sqlite3-binding.h b/sqlite3-binding.h
index 460cf55..4fa3a10 100644
--- a/sqlite3-binding.h
+++ b/sqlite3-binding.h
@@ -1,4 +1,5 @@
#ifndef USE_LIBSQLITE3
+#define SQLITE_DISABLE_INTRINSIC 1
/*
** 2001 September 15
**
@@ -10470,6 +10471,6 @@
/******** End of fts5.h *********/
#else // USE_LIBSQLITE3
- // If users really want to link against the system sqlite3 we
+// If users really want to link against the system sqlite3 we
// need to make this file a noop.
- #endif
\ No newline at end of file
+#endif
diff --git a/sqlite3ext.h b/sqlite3ext.h
index 2eb064d..edb10dc 100644
--- a/sqlite3ext.h
+++ b/sqlite3ext.h
@@ -1,4 +1,5 @@
#ifndef USE_LIBSQLITE3
+#define SQLITE_DISABLE_INTRINSIC 1
/*
** 2006 June 7
**
@@ -560,6 +561,6 @@
#endif /* SQLITE3EXT_H */
#else // USE_LIBSQLITE3
- // If users really want to link against the system sqlite3 we
+// If users really want to link against the system sqlite3 we
// need to make this file a noop.
- #endif
\ No newline at end of file
+#endif
diff --git a/tool/upgrade.go b/tool/upgrade.go
index f93f35c..191051e 100644
--- a/tool/upgrade.go
+++ b/tool/upgrade.go
@@ -5,6 +5,7 @@
import (
"archive/zip"
"bytes"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -18,12 +19,12 @@
"github.com/PuerkitoBio/goquery"
)
-func main() {
+func downloadAmalgamationCodes() error {
site := "https://www.sqlite.org/download.html"
- fmt.Printf("scraping %v\n", site)
+ log.Printf("Scraping %v\n", site)
doc, err := goquery.NewDocument(site)
if err != nil {
- log.Fatal(err)
+ return err
}
var url string
doc.Find("a").Each(func(_ int, s *goquery.Selection) {
@@ -32,27 +33,25 @@
}
})
if url == "" {
- return
+ return errors.New("amalgamation code not found")
}
- fmt.Printf("downloading %v\n", url)
+ log.Printf("Downloading %v\n", url)
resp, err := http.Get(url)
if err != nil {
- log.Fatal(err)
+ return err
}
+ defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
- resp.Body.Close()
- log.Fatal(err)
+ return err
}
- fmt.Printf("extracting %v\n", path.Base(url))
+ log.Printf("Extracting %v\n", path.Base(url))
r, err := zip.NewReader(bytes.NewReader(b), resp.ContentLength)
if err != nil {
- resp.Body.Close()
- log.Fatal(err)
+ return err
}
- resp.Body.Close()
for _, zf := range r.File {
var f *os.File
@@ -67,33 +66,83 @@
continue
}
if err != nil {
- log.Fatal(err)
+ return err
}
zr, err := zf.Open()
if err != nil {
- log.Fatal(err)
+ return err
}
- _, err = io.WriteString(f, "#ifndef USE_LIBSQLITE3\n")
+ _, err = io.WriteString(f, "#ifndef USE_LIBSQLITE3\n#define SQLITE_DISABLE_INTRINSIC 1\n")
if err != nil {
zr.Close()
f.Close()
- log.Fatal(err)
+ return err
}
_, err = io.Copy(f, zr)
if err != nil {
zr.Close()
f.Close()
- log.Fatal(err)
+ return err
}
- _, err = io.WriteString(f, "#else // USE_LIBSQLITE3\n // If users really want to link against the system sqlite3 we\n// need to make this file a noop.\n #endif")
+ _, err = io.WriteString(f, "#else // USE_LIBSQLITE3\n// If users really want to link against the system sqlite3 we\n// need to make this file a noop.\n#endif\n")
if err != nil {
zr.Close()
f.Close()
- log.Fatal(err)
+ return err
}
zr.Close()
f.Close()
- fmt.Printf("extracted %v\n", filepath.Base(f.Name()))
+ log.Printf("Extracted %v\n", filepath.Base(f.Name()))
+ }
+ return nil
+}
+
+func downloadModuleCodes() error {
+ modules := []struct {
+ file string
+ rev string
+ }{
+ {
+ file: "csv.c",
+ rev: "531a46cbad789fca0aa9db69a0e6c8ac9e68767d",
+ },
+ }
+
+ for _, module := range modules {
+ url := fmt.Sprintf("https://www.sqlite.org/src/raw/ext/misc/%s?name=%s", module.file, module.rev)
+ log.Printf("Downloading %v\n", url)
+ resp, err := http.Get(url)
+ if err != nil {
+ return err
+ }
+ f, err := os.Create("sqlite3-" + module.file)
+ if err != nil {
+ resp.Body.Close()
+ return err
+ }
+
+ _, err = io.Copy(f, resp.Body)
+ if err != nil {
+ resp.Body.Close()
+ f.Close()
+ return err
+ }
+ resp.Body.Close()
+ f.Close()
+ log.Printf("Saved %v\n", f.Name())
+ }
+ return nil
+}
+
+func main() {
+ err := downloadAmalgamationCodes()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ err = downloadModuleCodes()
+ if err != nil {
+ log.Fatal(err)
}
}