Skip to content

Commit b951516

Browse files
authored
Merge pull request #2 from mattn/master
Merge upstream
2 parents 3e97a4c + 83c59d8 commit b951516

38 files changed

+215158
-195072
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.db
22
*.exe
33
*.dll
4+
*.o

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
language: go
2+
sudo: required
3+
dist: trusty
4+
env:
5+
- GOTAGS=
6+
- GOTAGS=libsqlite3
7+
- GOTAGS=trace
8+
- GOTAGS=vtable
29
go:
10+
- 1.7
11+
- 1.8
312
- tip
413
before_install:
5-
- go get github.com/axw/gocov/gocov
614
- go get github.com/mattn/goveralls
715
- go get golang.org/x/tools/cmd/cover
816
script:
9-
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
17+
- $HOME/gopath/bin/goveralls -repotoken 3qJVUE0iQwqnCbmNcDsjYu1nh4J4KIFXx
18+
- go test -race -v . -tags "$GOTAGS"

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
go-sqlite3
22
==========
33

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

89
Description
910
-----------
@@ -16,11 +17,11 @@ Installation
1617
This package can be installed with the go get command:
1718

1819
go get github.com/mattn/go-sqlite3
19-
20+
2021
_go-sqlite3_ is *cgo* package.
2122
If you want to build your app using go-sqlite3, you need gcc.
2223
However, if you install _go-sqlite3_ with `go install github.com/mattn/go-sqlite3`, you don't need gcc to build your app anymore.
23-
24+
2425
Documentation
2526
-------------
2627

@@ -35,29 +36,50 @@ FAQ
3536

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

39+
* Want to build go-sqlite3 with libsqlite3 on OS X.
40+
41+
Install sqlite3 from homebrew: `brew install sqlite3`
42+
43+
Use `go build --tags "libsqlite3 darwin"`
44+
3845
* Want to build go-sqlite3 with icu extension.
3946

4047
Use `go build --tags "icu"`
4148

49+
Available extensions: `json1`, `fts5`, `icu`
50+
4251
* Can't build go-sqlite3 on windows 64bit.
4352

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

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

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

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

70+
* Can I use this in multiple routines concurrently?
71+
72+
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).
73+
74+
* Why is it racy if I use a `sql.Open("sqlite3", ":memory:")` database?
75+
76+
Each connection to :memory: opens a brand new in-memory sql database, so if
77+
the stdlib's sql engine happens to open another connection and you've only
78+
specified ":memory:", that connection will see a brand new database. A
79+
workaround is to use "file::memory:?mode=memory&cache=shared". Every
80+
connection to this string will point to the same in-memory database. See
81+
[#204](https://github.com/mattn/go-sqlite3/issues/204) for more info.
82+
6183
License
6284
-------
6385

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

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

70-
In this repository, those files are amalgamation code that copied from SQLite3. The license of those codes are depend on the license of SQLite3.
92+
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.
7193

7294
Author
7395
------

_example/hook/hook.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package main
22

33
import (
44
"database/sql"
5-
"github.com/mattn/go-sqlite3"
65
"log"
76
"os"
7+
8+
"github.com/mattn/go-sqlite3"
89
)
910

1011
func main() {
@@ -19,35 +20,35 @@ func main() {
1920
os.Remove("./foo.db")
2021
os.Remove("./bar.db")
2122

22-
destDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
23+
srcDb, err := sql.Open("sqlite3_with_hook_example", "./foo.db")
2324
if err != nil {
2425
log.Fatal(err)
2526
}
26-
defer destDb.Close()
27-
destDb.Ping()
27+
defer srcDb.Close()
28+
srcDb.Ping()
2829

29-
_, err = destDb.Exec("create table foo(id int, value text)")
30+
_, err = srcDb.Exec("create table foo(id int, value text)")
3031
if err != nil {
3132
log.Fatal(err)
3233
}
33-
_, err = destDb.Exec("insert into foo values(1, 'foo')")
34+
_, err = srcDb.Exec("insert into foo values(1, 'foo')")
3435
if err != nil {
3536
log.Fatal(err)
3637
}
37-
_, err = destDb.Exec("insert into foo values(2, 'bar')")
38+
_, err = srcDb.Exec("insert into foo values(2, 'bar')")
3839
if err != nil {
3940
log.Fatal(err)
4041
}
41-
_, err = destDb.Query("select * from foo")
42+
_, err = srcDb.Query("select * from foo")
4243
if err != nil {
4344
log.Fatal(err)
4445
}
45-
srcDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
46+
destDb, err := sql.Open("sqlite3_with_hook_example", "./bar.db")
4647
if err != nil {
4748
log.Fatal(err)
4849
}
49-
defer srcDb.Close()
50-
srcDb.Ping()
50+
defer destDb.Close()
51+
destDb.Ping()
5152

5253
bk, err := sqlite3conn[1].Backup("main", sqlite3conn[0], "main")
5354
if err != nil {

_example/mod_vtable/extension.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package main
33
import (
44
"database/sql"
55
"fmt"
6-
"github.com/mattn/go-sqlite3"
76
"log"
7+
8+
"github.com/mattn/go-sqlite3"
89
)
910

1011
func main() {
@@ -29,8 +30,8 @@ func main() {
2930
}
3031
defer rows.Close()
3132
for rows.Next() {
32-
var id, full_name, description, html_url string
33-
rows.Scan(&id, &full_name, &description, &html_url)
34-
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, full_name, description, html_url)
33+
var id, fullName, description, htmlURL string
34+
rows.Scan(&id, &fullName, &description, &htmlURL)
35+
fmt.Printf("%s: %s\n\t%s\n\t%s\n\n", id, fullName, description, htmlURL)
3536
}
3637
}

_example/simple/simple.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ func main() {
5252
for rows.Next() {
5353
var id int
5454
var name string
55-
rows.Scan(&id, &name)
55+
err = rows.Scan(&id, &name)
56+
if err != nil {
57+
log.Fatal(err)
58+
}
5659
fmt.Println(id, name)
5760
}
61+
err = rows.Err()
62+
if err != nil {
63+
log.Fatal(err)
64+
}
5865

5966
stmt, err = db.Prepare("select name from foo where id = ?")
6067
if err != nil {
@@ -86,7 +93,14 @@ func main() {
8693
for rows.Next() {
8794
var id int
8895
var name string
89-
rows.Scan(&id, &name)
96+
err = rows.Scan(&id, &name)
97+
if err != nil {
98+
log.Fatal(err)
99+
}
90100
fmt.Println(id, name)
91101
}
102+
err = rows.Err()
103+
if err != nil {
104+
log.Fatal(err)
105+
}
92106
}

0 commit comments

Comments
 (0)