mirror of https://github.com/mattn/go-sqlite3.git
add CSV module
This commit is contained in:
parent
eac1dfa2a6
commit
564e1eeb95
|
@ -201403,6 +201403,6 @@ static int sqlite3Fts5VocabInit(Fts5Global *pGlobal, sqlite3 *db){
|
|||
|
||||
/************** 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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef USE_LIBSQLITE3
|
||||
#define SQLITE_DISABLE_INTRINSIC 1
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
|
@ -10470,6 +10471,6 @@ struct fts5_api {
|
|||
|
||||
/******** 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
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifndef USE_LIBSQLITE3
|
||||
#define SQLITE_DISABLE_INTRINSIC 1
|
||||
/*
|
||||
** 2006 June 7
|
||||
**
|
||||
|
@ -560,6 +561,6 @@ typedef int (*sqlite3_loadext_entry)(
|
|||
|
||||
#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
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,7 @@ package main
|
|||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -18,12 +19,12 @@ import (
|
|||
"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 @@ func main() {
|
|||
}
|
||||
})
|
||||
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 @@ func main() {
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue