Skip to content

Commit

Permalink
Merge pull request #2 from mattn/master
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
otoolep authored Jun 17, 2017
2 parents 3e97a4c + 83c59d8 commit b951516
Show file tree
Hide file tree
Showing 38 changed files with 215,158 additions and 195,072 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.db
*.exe
*.dll
*.o
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
language: go
sudo: required
dist: trusty
env:
- GOTAGS=
- GOTAGS=libsqlite3
- GOTAGS=trace
- GOTAGS=vtable
go:
- 1.7
- 1.8
- tip
before_install:
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover
script:
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
- go test -race -v . -tags "$GOTAGS"
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
go-sqlite3
==========

[![GoDoc Reference](https://godoc.org/github.com/mattn/go-sqlite3?status.svg)](http://godoc.org/github.com/mattn/go-sqlite3)
[![Build Status](https://travis-ci.org/mattn/go-sqlite3.svg?branch=master)](https://travis-ci.org/mattn/go-sqlite3)
[![Coverage Status](https://coveralls.io/repos/mattn/go-sqlite3/badge.svg?branch=master)](https://coveralls.io/r/mattn/go-sqlite3?branch=master)
[![GoDoc](https://godoc.org/github.com/mattn/go-sqlite3?status.svg)](http://godoc.org/github.com/mattn/go-sqlite3)
[![Go Report Card](https://goreportcard.com/badge/github.com/mattn/go-sqlite3)](https://goreportcard.com/report/github.com/mattn/go-sqlite3)

Description
-----------
Expand All @@ -16,11 +17,11 @@ Installation
This package can be installed with the go get command:

go get github.com/mattn/go-sqlite3

_go-sqlite3_ is *cgo* package.
If you want to build your app using go-sqlite3, you need gcc.
However, if you install _go-sqlite3_ with `go install github.com/mattn/go-sqlite3`, you don't need gcc to build your app anymore.

Documentation
-------------

Expand All @@ -35,29 +36,50 @@ FAQ

Use `go build --tags "libsqlite3 linux"`

* Want to build go-sqlite3 with libsqlite3 on OS X.

Install sqlite3 from homebrew: `brew install sqlite3`

Use `go build --tags "libsqlite3 darwin"`

* Want to build go-sqlite3 with icu extension.

Use `go build --tags "icu"`

Available extensions: `json1`, `fts5`, `icu`

* Can't build go-sqlite3 on windows 64bit.

> Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit.
> See: https://github.com/mattn/go-sqlite3/issues/27
> Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit.
> See: [#27](https://github.com/mattn/go-sqlite3/issues/27)
* Getting insert error while query is opened.

> You can pass some arguments into the connection string, for example, a URI.
> See: https://github.com/mattn/go-sqlite3/issues/39
> See: [#39](https://github.com/mattn/go-sqlite3/issues/39)
* Do you want cross compiling? mingw on Linux or Mac?
* Do you want to cross compile? mingw on Linux or Mac?

> See: https://github.com/mattn/go-sqlite3/issues/106
> See: [#106](https://github.com/mattn/go-sqlite3/issues/106)
> See also: http://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html
* Want to get time.Time with current locale

Use `loc=auto` in SQLite3 filename schema like `file:foo.db?loc=auto`.

* Can I use this in multiple routines concurrently?

Yes for readonly. But, No for writable. See [#50](https://github.com/mattn/go-sqlite3/issues/50), [#51](https://github.com/mattn/go-sqlite3/issues/51), [#209](https://github.com/mattn/go-sqlite3/issues/209).

* Why is it racy if I use a `sql.Open("sqlite3", ":memory:")` database?

Each connection to :memory: opens a brand new in-memory sql database, so if
the stdlib's sql engine happens to open another connection and you've only
specified ":memory:", that connection will see a brand new database. A
workaround is to use "file::memory:?mode=memory&cache=shared". Every
connection to this string will point to the same in-memory database. See
[#204](https://github.com/mattn/go-sqlite3/issues/204) for more info.

License
-------

Expand All @@ -67,7 +89,7 @@ sqlite3-binding.c, sqlite3-binding.h, sqlite3ext.h

The -binding suffix was added to avoid build failures under gccgo.

In this repository, those files are amalgamation code that copied from SQLite3. The license of those codes are depend on the license of SQLite3.
In this repository, those files are an amalgamation of code that was copied from SQLite3. The license of that code is the same as the license of SQLite3.

Author
------
Expand Down
23 changes: 12 additions & 11 deletions _example/hook/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"database/sql"
"github.com/mattn/go-sqlite3"
"log"
"os"

"github.com/mattn/go-sqlite3"
)

func main() {
Expand All @@ -19,35 +20,35 @@ func main() {
os.Remove("./foo.db")
os.Remove("./bar.db")

destDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
srcDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
if err != nil {
log.Fatal(err)
}
defer destDb.Close()
destDb.Ping()
defer srcDb.Close()
srcDb.Ping()

_, err = destDb.Exec("create table foo(id int, value text)")
_, err = srcDb.Exec("create table foo(id int, value text)")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Exec("insert into foo values(1, 'foo')")
_, err = srcDb.Exec("insert into foo values(1, 'foo')")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Exec("insert into foo values(2, 'bar')")
_, err = srcDb.Exec("insert into foo values(2, 'bar')")
if err != nil {
log.Fatal(err)
}
_, err = destDb.Query("select * from foo")
_, err = srcDb.Query("select * from foo")
if err != nil {
log.Fatal(err)
}
srcDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
destDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
if err != nil {
log.Fatal(err)
}
defer srcDb.Close()
srcDb.Ping()
defer destDb.Close()
destDb.Ping()

bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main")
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions _example/mod_vtable/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package main
import (
"database/sql"
"fmt"
"github.com/mattn/go-sqlite3"
"log"

"github.com/mattn/go-sqlite3"
)

func main() {
Expand All @@ -29,8 +30,8 @@ func main() {
}
defer rows.Close()
for rows.Next() {
var id, full_name, description, html_url string
rows.Scan(&id, &full_name, &description, &html_url)
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, full_name, description, html_url)
var id, fullName, description, htmlURL string
rows.Scan(&id, &fullName, &description, &htmlURL)
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
}
}
18 changes: 16 additions & 2 deletions _example/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@ func main() {
for rows.Next() {
var id int
var name string
rows.Scan(&id, &name)
err = rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
fmt.Println(id, name)
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}

stmt, err = db.Prepare("select name from foo where id = ?")
if err != nil {
Expand Down Expand Up @@ -86,7 +93,14 @@ func main() {
for rows.Next() {
var id int
var name string
rows.Scan(&id, &name)
err = rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
fmt.Println(id, name)
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}
}
Loading

0 comments on commit b951516

Please sign in to comment.