add CSV module

This commit is contained in:
Yasuhiro Matsumoto 2017-03-20 22:14:18 +09:00
parent eac1dfa2a6
commit 564e1eeb95
4 changed files with 77 additions and 26 deletions

View File

@ -201403,6 +201403,6 @@ static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
/************** End of fts5.c ************************************************/ /************** End of fts5.c ************************************************/
#else // USE_LIBSQLITE3 #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. // need to make this file a noop.
#endif #endif

View File

@ -1,4 +1,5 @@
#ifndef USE_LIBSQLITE3 #ifndef USE_LIBSQLITE3
#define SQLITE_DISABLE_INTRINSIC 1
/* /*
** 2001 September 15 ** 2001 September 15
** **
@ -10470,6 +10471,6 @@ struct fts5_api {
/******** End of fts5.h *********/ /******** End of fts5.h *********/
#else // USE_LIBSQLITE3 #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. // need to make this file a noop.
#endif #endif

View File

@ -1,4 +1,5 @@
#ifndef USE_LIBSQLITE3 #ifndef USE_LIBSQLITE3
#define SQLITE_DISABLE_INTRINSIC 1
/* /*
** 2006 June 7 ** 2006 June 7
** **
@ -560,6 +561,6 @@ typedef int (*sqlite3_loadext_entry)(
#endif /* SQLITE3EXT_H */ #endif /* SQLITE3EXT_H */
#else // USE_LIBSQLITE3 #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. // need to make this file a noop.
#endif #endif

View File

@ -5,6 +5,7 @@ package main
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
@ -18,12 +19,12 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )
func main() { func downloadAmalgamationCodes() error {
site := "https://www.sqlite.org/download.html" site := "https://www.sqlite.org/download.html"
fmt.Printf("scraping %v\n", site) log.Printf("Scraping %v\n", site)
doc, err := goquery.NewDocument(site) doc, err := goquery.NewDocument(site)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
var url string var url string
doc.Find("a").Each(func(_ int, s *goquery.Selection) { doc.Find("a").Each(func(_ int, s *goquery.Selection) {
@ -32,27 +33,25 @@ func main() {
} }
}) })
if url == "" { 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) resp, err := http.Get(url)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body) b, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
resp.Body.Close() return err
log.Fatal(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) r, err := zip.NewReader(bytes.NewReader(b), resp.ContentLength)
if err != nil { if err != nil {
resp.Body.Close() return err
log.Fatal(err)
} }
resp.Body.Close()
for _, zf := range r.File { for _, zf := range r.File {
var f *os.File var f *os.File
@ -67,33 +66,83 @@ func main() {
continue continue
} }
if err != nil { if err != nil {
log.Fatal(err) return err
} }
zr, err := zf.Open() zr, err := zf.Open()
if err != nil { 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 { if err != nil {
zr.Close() zr.Close()
f.Close() f.Close()
log.Fatal(err) return err
} }
_, err = io.Copy(f, zr) _, err = io.Copy(f, zr)
if err != nil { if err != nil {
zr.Close() zr.Close()
f.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 { if err != nil {
zr.Close() zr.Close()
f.Close() f.Close()
log.Fatal(err) return err
} }
zr.Close() zr.Close()
f.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)
} }
} }