Skip to content

Commit 64af600

Browse files
authored
Merge pull request #570 from GJRTimmer/update/docs
Update/docs
2 parents b8b158d + cf4b585 commit 64af600

File tree

1 file changed

+199
-11
lines changed

1 file changed

+199
-11
lines changed

README.md

Lines changed: 199 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,29 @@ go-sqlite3
1010

1111
sqlite3 driver conforming to the built-in database/sql interface
1212

13+
Supported Golang version:
14+
- 1.8.x
15+
- 1.9.x
16+
- 1.10.x
17+
1318
### Overview
1419

1520
- [Installation](#installation)
1621
- [API Reference](#api-reference)
1722
- [Features](#features)
23+
- [Compilation](#compilation)
24+
- [Android](#android)
25+
- [ARM](#arm)
26+
- [Cross Compile](#cross-compile)
27+
- [Docker](#docker)
28+
- [Alpine](#alpine)
29+
- [Google Cloud Platform](#google-cloud-platform)
30+
- [Linux](#linux)
31+
- [Fedora](#fedora)
32+
- [Ubuntu](#ubuntu)
33+
- [Mac OSX](#mac-osx)
34+
- [Windows](#windows)
35+
- [Errors](#errors)
1836
- [FAQ](#faq)
1937
- [License](#license)
2038

@@ -28,6 +46,8 @@ _go-sqlite3_ is *cgo* package.
2846
If you want to build your app using go-sqlite3, you need gcc.
2947
However, after you have built and installed _go-sqlite3_ with `go install github.com/mattn/go-sqlite3` (which requires gcc), you can build your app without relying on gcc in future.
3048

49+
***Important: because this is a `CGO` enabled package you are required to set the environment variable `CGO_ENABLED=1` and have a `gcc` compile present within your path.***
50+
3151
# API Reference
3252

3353
API documentation can be found here: http://godoc.org/github.com/mattn/go-sqlite3
@@ -40,6 +60,26 @@ This package allows additional configuration of features available within SQLite
4060

4161
[Click here for more information about build tags / constraints.](https://golang.org/pkg/go/build/#hdr-Build_Constraints)
4262

63+
### Usage
64+
65+
If you wish to build this library with additional extensions / features.
66+
Use the following command.
67+
68+
```bash
69+
go build --tags "<FEATURE>"
70+
```
71+
72+
For available features see the extension list.
73+
When using multiple build tags, all the different tags should be space delimted.
74+
75+
Example:
76+
77+
```bash
78+
go build --tags "icu json1 fts5 secure_delete"
79+
```
80+
81+
### Feature / Extension List
82+
4383
| Extension | Build Tag | Description |
4484
|-----------|-----------|-------------|
4585
| Additional Statistics | sqlite_stat4 | This option adds additional logic to the ANALYZE command and to the query planner that can help SQLite to chose a better query plan under certain situations. The ANALYZE command is enhanced to collect histogram data from all columns of every index and store that data in the sqlite_stat4 table.<br><br>The query planner will then use the histogram data to help it make better index choices. The downside of this compile-time option is that it violates the query planner stability guarantee making it more difficult to ensure consistent performance in mass-produced applications.<br><br>SQLITE_ENABLE_STAT4 is an enhancement of SQLITE_ENABLE_STAT3. STAT3 only recorded histogram data for the left-most column of each index whereas the STAT4 enhancement records histogram data from all columns of each index.<br><br>The SQLITE_ENABLE_STAT3 compile-time option is a no-op and is ignored if the SQLITE_ENABLE_STAT4 compile-time option is used |
@@ -56,33 +96,166 @@ This package allows additional configuration of features available within SQLite
5696
| Secure Delete | sqlite_secure_delete | This compile-time option changes the default setting of the secure_delete pragma.<br><br>When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.<br><br>The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.<br><br>On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information |
5797
| Tracing / Debug | sqlite_trace | Activate trace functions |
5898

59-
# FAQ
99+
# Compilation
100+
101+
This package requires `CGO_ENABLED=1` ennvironment variable if not set by default, and the presence of the `gcc` compiler.
102+
103+
If you need to add additional CFLAGS or LDFLAGS to the build command, and do not want to modify this package. Then this can be achieved by using the `CGO_CFLAGS` and `CGO_LDFLAGS` environment variables.
104+
105+
## Android
106+
107+
This package can be compiled for android.
108+
Compile with:
109+
110+
```bash
111+
go build --tags "android"
112+
```
113+
114+
For more information see [#201](https://github.com/mattn/go-sqlite3/issues/201)
115+
116+
# ARM
117+
118+
To compile for `ARM` use the following environment.
119+
120+
```bash
121+
env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
122+
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 \
123+
go build -v
124+
```
125+
126+
Additional information:
127+
- [#242](https://github.com/mattn/go-sqlite3/issues/242)
128+
- [#504](https://github.com/mattn/go-sqlite3/issues/504)
129+
130+
# Cross Compile
131+
132+
This library can be cross-compiled.
133+
134+
In some cases you are required to the `CC` environment variable with the cross compiler.
135+
136+
Additional information:
137+
- [#491](https://github.com/mattn/go-sqlite3/issues/491)
138+
- [#560](https://github.com/mattn/go-sqlite3/issues/560)
139+
140+
# Google Cloud Platform
141+
142+
Building on GCP is not possible because `Google Cloud Platform does not allow `gcc` to be executed.
143+
144+
Please work only with compiled final binaries.
145+
146+
## Linux
147+
148+
To compile this package on Linux you must install the development tools for your linux distribution.
149+
150+
To compile under linux use the build tag `linux`.
151+
152+
```bash
153+
go build --tags "linux"
154+
```
155+
156+
If you wish to link directly to libsqlite3 then you can use the `libsqlite3` build tag.
157+
158+
```
159+
go build --tags "libsqlite3 linux"
160+
```
60161

61-
- Want to build go-sqlite3 with libsqlite3 on my linux.
162+
### Alpine
62163

63-
Use `go build --tags "libsqlite3 linux"`
164+
When building in an `alpine` container run the following command before building.
64165

65-
- Want to build go-sqlite3 with libsqlite3 on OS X.
166+
```
167+
apk add --update gcc musl-dev
168+
```
66169

67-
Install sqlite3 from homebrew: `brew install sqlite3`
170+
### Fedora
68171

69-
Use `go build --tags "libsqlite3 darwin"`
172+
```bash
173+
sudo yum groupinstall "Development Tools" "Development Libraries"
174+
```
70175

71-
- Want to build go-sqlite3 with additional extensions / features.
176+
### Ubuntu
72177

73-
Use `go build --tags "<FEATURE>"`
178+
```bash
179+
sudo apt-get install build-essential
180+
```
74181

75-
When using multiple build tags, all the different tags should be space delimted.
182+
## Mac OSX
76183

77-
For available features / extensions see [Features](#features).
184+
OSX should have all the tools present to compile this package, if not install XCode this will add all the developers tools.
78185

79-
Example building multiple features: `go build --tags "icu json1 fts5 secure_delete"`
186+
Required dependency
187+
188+
```bash
189+
brew install sqlite3
190+
```
191+
192+
For OSX there is an additional package install which is required if you whish to build the `icu` extension.
193+
194+
This additional package can be installed with `homebrew`.
195+
196+
```bash
197+
brew upgrade icu4c
198+
```
199+
200+
To compile for Mac OSX.
201+
202+
```bash
203+
go build --tags "darwin"
204+
```
205+
206+
If you wish to link directly to libsqlite3 then you can use the `libsqlite3` build tag.
207+
208+
```
209+
go build --tags "libsqlite3 darwin"
210+
```
211+
212+
Additional information:
213+
- [#206](https://github.com/mattn/go-sqlite3/issues/206)
214+
- [#404](https://github.com/mattn/go-sqlite3/issues/404)
215+
216+
## Windows
217+
218+
To compile this package on Windows OS you must have the `gcc` compiler installed.
219+
220+
1) Install a Windows `gcc` toolchain.
221+
2) Add the `bin` folders to the Windows path if the installer did not do this by default.
222+
3) Open a terminal for the TDM-GCC toolchain, can be found in the Windows Start menu.
223+
4) Navigate to your project folder and run the `go build ...` command for this package.
224+
225+
For example the TDM-GCC Toolchain can be found [here](ttps://sourceforge.net/projects/tdm-gcc/).
226+
227+
## Errors
228+
229+
- Compile error: `can not be used when making a shared object; recompile with -fPIC`
230+
231+
When receiving a compile time error referencing recompile with `-FPIC` then you
232+
are probably using a hardend system.
233+
234+
You can copile the library on a hardend system with the following command.
235+
236+
```bash
237+
go build -ldflags '-extldflags=-fno-PIC'
238+
```
239+
240+
More details see [#120](https://github.com/mattn/go-sqlite3/issues/120)
80241

81242
- Can't build go-sqlite3 on windows 64bit.
82243
83244
> Probably, you are using go 1.0, go1.0 has a problem when it comes to compiling/linking on windows 64bit.
84245
> See: [#27](https://github.com/mattn/go-sqlite3/issues/27)
85246
247+
- `go get github.com/mattn/go-sqlite3` throws compilation error.
248+
249+
`gcc` throws: `internal compiler error`
250+
251+
Remove the download repository from your disk and try re-install with:
252+
253+
```bash
254+
go install github.com/mattn/go-sqlite3
255+
```
256+
257+
# FAQ
258+
86259
- Getting insert error while query is opened.
87260
88261
> You can pass some arguments into the connection string, for example, a URI.
@@ -110,6 +283,21 @@ This package allows additional configuration of features available within SQLite
110283
connection to this string will point to the same in-memory database. See
111284
[#204](https://github.com/mattn/go-sqlite3/issues/204) for more info.
112285
286+
- Reading from database with large amount of goroutines fails on OSX.
287+
288+
OS X limits OS-wide to not have more than 1000 files open simultaneously by default.
289+
290+
For more information see [#289](https://github.com/mattn/go-sqlite3/issues/289)
291+
292+
- Trying to execure a `.` (dot) command throws an error.
293+
294+
Error: `Error: near ".": syntax error`
295+
Dot command are part of SQLite3 CLI not of this library.
296+
297+
You need to implement the feature or call the sqlite3 cli.
298+
299+
More infomation see [#305](https://github.com/mattn/go-sqlite3/issues/305)
300+
113301
# License
114302
115303
MIT: http://mattn.mit-license.org/2012

0 commit comments

Comments
 (0)