sqlite3 driver for go using database/sql



GoDoc Reference GitHub Actions Financial Contributors on Open Collective codecov Go Report Card

Latest stable version is v1.14 or later not v2.

NOTE: The increase to v2 was an accident. There were no major changes or features.


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

Supported Golang version: See .github/workflows/go.yaml

This package follows the official Golang Release Policy.



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, 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.

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.

API Reference

API documentation can be found here: http://godoc.org/github.com/mattn/go-sqlite3

Examples can be found under the examples directory

Connection String

When creating a new SQLite database or connection to an existing one, with the file name additional options can be given. This is also known as a DSN string. (Data Source Name).

Options are append after the filename of the SQLite database. The database filename and options are seperated by an ? (Question Mark). Options should be URL-encoded (see url.QueryEscape).

This also applies when using an in-memory database instead of a file.

Options can be given using the following format: KEYWORD=VALUE and multiple options can be combined with the & ampersand.

This library supports dsn options of SQLite itself and provides additional options.

Boolean values can be one of:

  • 0 no false off
  • 1 yes true on
Name Key Value(s) Description
UA - Create _auth - Create User Authentication, for more information see User Authentication
UA - Username _auth_user string Username for User Authentication, for more information see User Authentication
UA - Password _auth_pass string Password for User Authentication, for more information see User Authentication
UA - Crypt _auth_crypt
  • SHA1
  • SSHA1
  • SHA256
  • SSHA256
  • SHA384
  • SSHA384
  • SHA512
  • SSHA512
Password encoder to use for User Authentication, for more information see User Authentication
UA - Salt _auth_salt string Salt to use if the configure password encoder requires a salt, for User Authentication, for more information see User Authentication
Auto Vacuum _auto_vacuum | _vacuum
  • 0 | none
  • 1 | full
  • 2 | incremental
For more information see PRAGMA auto_vacuum
Busy Timeout _busy_timeout | _timeout int Specify value for sqlite3_busy_timeout. For more information see PRAGMA busy_timeout
Case Sensitive LIKE _case_sensitive_like | _cslike boolean For more information see PRAGMA case_sensitive_like
Defer Foreign Keys _defer_foreign_keys | _defer_fk boolean For more information see PRAGMA defer_foreign_keys
Foreign Keys _foreign_keys | _fk boolean For more information see PRAGMA foreign_keys
Ignore CHECK Constraints _ignore_check_constraints boolean For more information see PRAGMA ignore_check_constraints
Immutable immutable boolean For more information see Immutable
Journal Mode _journal_mode | _journal
  • WAL
  • OFF
For more information see PRAGMA journal_mode
Locking Mode _locking_mode | _locking
For more information see PRAGMA locking_mode
Mode mode
  • ro
  • rw
  • rwc
  • memory
Access Mode of the database. For more information see SQLite Open
Mutex Locking _mutex
  • no
  • full
Specify mutex mode.
Query Only _query_only boolean For more information see PRAGMA query_only
Recursive Triggers _recursive_triggers | _rt boolean For more information see PRAGMA recursive_triggers
Secure Delete _secure_delete boolean | FAST For more information see PRAGMA secure_delete
Shared-Cache Mode cache
  • shared
  • private
Set cache mode for more information see sqlite.org
Synchronous _synchronous | _sync
  • 0 | OFF
  • 1 | NORMAL
  • 2 | FULL
  • 3 | EXTRA
For more information see PRAGMA synchronous
Time Zone Location _loc auto Specify location of time format.
Transaction Lock _txlock
  • immediate
  • deferred
  • exclusive
Specify locking behavior for transactions.
Writable Schema _writable_schema Boolean When this pragma is on, the SQLITE_MASTER tables in which database can be changed using ordinary UPDATE, INSERT, and DELETE statements. Warning: misuse of this pragma can easily result in a corrupt database file.
Cache Size _cache_size int Maximum cache size; default is 2000K (2M). See PRAGMA cache_size

DSN Examples



This package allows additional configuration of features available within SQLite3 to be enabled or disabled by golang build constraints also known as build tags.

Click here for more information about build tags / constraints.


If you wish to build this library with additional extensions / features. Use the following command.

go build --tags "<FEATURE>"

For available features see the extension list. When using multiple build tags, all the different tags should be space delimted.


go build --tags "icu json1 fts5 secure_delete"

Feature / Extension List

Extension Build Tag Description
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.

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.

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.

The SQLITE_ENABLE_STAT3 compile-time option is a no-op and is ignored if the SQLITE_ENABLE_STAT4 compile-time option is used
Allow URI Authority sqlite_allow_uri_authority URI filenames normally throws an error if the authority section is not either empty or "localhost".

However, if SQLite is compiled with the SQLITE_ALLOW_URI_AUTHORITY compile-time option, then the URI is converted into a Uniform Naming Convention (UNC) filename and passed down to the underlying operating system that way
App Armor sqlite_app_armor When defined, this C-preprocessor macro activates extra code that attempts to detect misuse of the SQLite API, such as passing in NULL pointers to required parameters or using objects after they have been destroyed.

App Armor is not available under Windows.
Disable Load Extensions sqlite_omit_load_extension Loading of external extensions is enabled by default.

To disable extension loading add the build tag sqlite_omit_load_extension.
Foreign Keys sqlite_foreign_keys This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections.

Each database connection can always turn enforcement of foreign key constraints on and off and run-time using the foreign_keys pragma.

Enforcement of foreign key constraints is normally off by default, but if this compile-time parameter is set to 1, enforcement of foreign key constraints will be on by default
Full Auto Vacuum sqlite_vacuum_full Set the default auto vacuum to full
Incremental Auto Vacuum sqlite_vacuum_incr Set the default auto vacuum to incremental
Full Text Search Engine sqlite_fts5 When this option is defined in the amalgamation, versions 5 of the full-text search engine (fts5) is added to the build automatically
International Components for Unicode sqlite_icu This option causes the International Components for Unicode or "ICU" extension to SQLite to be added to the build
Introspect PRAGMAS sqlite_introspect This option adds some extra PRAGMA statements.
  • PRAGMA function_list
  • PRAGMA module_list
  • PRAGMA pragma_list
JSON SQL Functions sqlite_json When this option is defined in the amalgamation, the JSON SQL functions are added to the build automatically
Pre Update Hook sqlite_preupdate_hook Registers a callback function that is invoked prior to each INSERT, UPDATE, and DELETE operation on a database table.
Secure Delete sqlite_secure_delete This compile-time option changes the default setting of the secure_delete pragma.

When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.

The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.

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
Secure Delete (FAST) sqlite_secure_delete_fast For more information see PRAGMA secure_delete
Tracing / Debug sqlite_trace Activate trace functions
User Authentication sqlite_userauth SQLite User Authentication see User Authentication for more information.


This package requires CGO_ENABLED=1 ennvironment variable if not set by default, and the presence of the gcc compiler.

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.


This package can be compiled for android. Compile with:

go build --tags "android"

For more information see #201


To compile for ARM use the following environment.

env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
    go build -v 

Additional information:

Cross Compile

This library can be cross-compiled.

In some cases you are required to the CC environment variable with the cross compiler.

Cross Compiling from MAC OSX

The simplest way to cross compile from OSX is to use xgo.


  • Install xgo (go get github.com/karalabe/xgo).
  • Ensure that your project is within your GOPATH.
  • Run xgo local/path/to/project.

Please refer to the project's README for further information.

Google Cloud Platform

Building on GCP is not possible because Google Cloud Platform does not allow gcc to be executed.

Please work only with compiled final binaries.


To compile this package on Linux you must install the development tools for your linux distribution.

To compile under linux use the build tag linux.

go build --tags "linux"

If you wish to link directly to libsqlite3 then you can use the libsqlite3 build tag.

go build --tags "libsqlite3 linux"


When building in an alpine container run the following command before building.

apk add --update gcc musl-dev


sudo yum groupinstall "Development Tools" "Development Libraries"


sudo apt-get install build-essential


OSX should have all the tools present to compile this package, if not install XCode this will add all the developers tools.

Required dependency

brew install sqlite3

For OSX there is an additional package install which is required if you wish to build the icu extension.

This additional package can be installed with homebrew.

brew upgrade icu4c

To compile for Mac OSX.

go build --tags "darwin"

If you wish to link directly to libsqlite3 then you can use the libsqlite3 build tag.

go build --tags "libsqlite3 darwin"

Additional information:


To compile this package on Windows OS you must have the gcc compiler installed.

  1. Install a Windows gcc toolchain.
  2. Add the bin folders to the Windows path if the installer did not do this by default.
  3. Open a terminal for the TDM-GCC toolchain, can be found in the Windows Start menu.
  4. Navigate to your project folder and run the go build ... command for this package.

For example the TDM-GCC Toolchain can be found here.


  • Compile error: can not be used when making a shared object; recompile with -fPIC

    When receiving a compile time error referencing recompile with -FPIC then you are probably using a hardend system.

    You can compile the library on a hardend system with the following command.

    go build -ldflags '-extldflags=-fno-PIC'

    More details see #120

  • 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: #27

  • go get github.com/mattn/go-sqlite3 throws compilation error.

    gcc throws: internal compiler error

    Remove the download repository from your disk and try re-install with:

    go install github.com/mattn/go-sqlite3

User Authentication

This package supports the SQLite User Authentication module.


To use the User authentication module the package has to be compiled with the tag sqlite_userauth. See Features.


Create protected database

To create a database protected by user authentication provide the following argument to the connection string _auth. This will enable user authentication within the database. This option however requires two additional arguments:

  • _auth_user
  • _auth_pass

When _auth is present on the connection string user authentication will be enabled and the provided user will be created as an admin user. After initial creation, the parameter _auth has no effect anymore and can be omitted from the connection string.

Example connection string:

Create an user authentication database with user admin and password admin.


Create an user authentication database with user admin and password admin and use SHA1 for the password encoding.


Password Encoding

The passwords within the user authentication module of SQLite are encoded with the SQLite function sqlite_cryp. This function uses a ceasar-cypher which is quite insecure. This library provides several additional password encoders which can be configured through the connection string.

The password cypher can be configured with the key _auth_crypt. And if the configured password encoder also requires an salt this can be configured with _auth_salt.

Available Encoders

  • SHA1
  • SSHA1 (Salted SHA1)
  • SHA256
  • SSHA256 (salted SHA256)
  • SHA384
  • SSHA384 (salted SHA384)
  • SHA512
  • SSHA512 (salted SHA512)


Operations on the database regarding to user management can only be preformed by an administrator user.


The user authentication supports two kinds of users

  • administrators
  • regular users

User Management

User management can be done by directly using the *SQLiteConn or by SQL.


The following sql functions are available for user management.

Function Arguments Description
authenticate username string, password string Will authenticate an user, this is done by the connection; and should not be used manually.
auth_user_add username string, password string, admin int This function will add an user to the database.
if the database is not protected by user authentication it will enable it. Argument admin is an integer identifying if the added user should be an administrator. Only Administrators can add administrators.
auth_user_change username string, password string, admin int Function to modify an user. Users can change their own password, but only an administrator can change the administrator flag.
authUserDelete username string Delete an user from the database. Can only be used by an administrator. The current logged in administrator cannot be deleted. This is to make sure their is always an administrator remaining.

These functions will return an integer.

  • 0 (SQLITE_OK)
  • 23 (SQLITE_AUTH) Failed to perform due to authentication or insufficient privileges
// Autheticate user
// Create Admin User
SELECT auth_user_add('admin2', 'admin2', 1);

// Change password for user
SELECT auth_user_change('user', 'userpassword', 0);

// Delete user
SELECT user_delete('user');


The following functions are available for User authentication from the *SQLiteConn.

Function Description
Authenticate(username, password string) error Authenticate user
AuthUserAdd(username, password string, admin bool) error Add user
AuthUserChange(username, password string, admin bool) error Modify user
AuthUserDelete(username string) error Delete user

Attached database

When using attached databases. SQLite will use the authentication from the main database for the attached database(s).


If you want your own extension to be listed here or you want to add a reference to an extension; please submit an Issue for this.


Spatialite is available as an extension to SQLite, and can be used in combination with this repository. For an example see shaxbee/go-spatialite.

extension-functions.c from SQLite3 Contrib

extension-functions.c is available as an extension to SQLite, and provides the following functions:

  • Math: acos, asin, atan, atn2, atan2, acosh, asinh, atanh, difference, degrees, radians, cos, sin, tan, cot, cosh, sinh, tanh, coth, exp, log, log10, power, sign, sqrt, square, ceil, floor, pi.
  • String: replicate, charindex, leftstr, rightstr, ltrim, rtrim, trim, replace, reverse, proper, padl, padr, padc, strfilter.
  • Aggregate: stdev, variance, mode, median, lower_quartile, upper_quartile

For an example see dinedal/go-sqlite3-extension-functions.


  • Getting insert error while query is opened.

    You can pass some arguments into the connection string, for example, a URI. See: #39

  • Do you want to cross compile? mingw on Linux or Mac?

    See: #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, #51, #209, #274.

  • Why I'm getting no such table error?

    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:?cache=shared" (or "file:foobar?mode=memory&cache=shared"). Every connection to this string will point to the same in-memory database.

    Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the max idle connection limit is > 0, and the connection lifetime is infinite.

    For more information see

  • Reading from database with large amount of goroutines fails on OSX.

    OS X limits OS-wide to not have more than 1000 files open simultaneously by default.

    For more information see #289

  • Trying to execute a . (dot) command throws an error.

    Error: Error: near ".": syntax error Dot command are part of SQLite3 CLI not of this library.

    You need to implement the feature or call the sqlite3 cli.

    More information see #305

  • Error: database is locked

    When you get a database is locked. Please use the following options.

    Add to DSN: cache=shared


    db, err := sql.Open("sqlite3", "file:locked.sqlite?cache=shared")

    Second please set the database connections of the SQL package to 1.


    More information see #209


Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]



Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]


MIT: http://mattn.mit-license.org/2018

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 an amalgamation of code that was copied from SQLite3. The license of that code is the same as the license of SQLite3.


Yasuhiro Matsumoto (a.k.a mattn)

G.J.R. Timmer

  • Works with 64-bit Windows (without pkg-config) but doesn't work with 32-bit Windows.

    Works with 64-bit Windows (without pkg-config) but doesn't work with 32-bit Windows.

    Hello. I've been having trouble with getting this to work on Windows using 32-bit and then found that it works on 64-bit Windows even without pkg-config (which incidentally I had got installed though I'm not sure that could help after all). Having learned more about the current head revision I understand that it works without pkg-config on Windows however I could not get it to work with 32-bit Windows and I get a stream of error messages like "__divdi3: not defined". My understanding of C and cgo is patchy and I'm not sure what this means. I couldn't see why it should be different on 32-bit Windows but perhaps some other compiler option is required.

    I resolved my problems by discarding pkg-config and the static compilation on Windows and use the DLL instead, which is what other platforms are using anyway. So instead of the #cgo pkg-config line I'm using "#cgo LDFLAGS: -lsqlite3" having the environment set up with the include files on the path for gcc (LIBRARY_PATH and C_INCLUDE_PATH). The little work with cgo that I've done so far this works best with the smallest of changes to the source-code across platforms.

    I've never used pkg-config before and while I had no trouble with it on other platforms on Windows it was a struggle getting an environment set up. Wouldn't this be better without pkg-config?

    In any case the current head revision doesn't appear to work for 32-bit Windows and the static compilation as an exception for Windows seems unnecessarily complicated. Maybe you can get it to work but I wonder if this is the wrong direction to go.

    opened by stever 85
  • Cross platform build failed

    Cross platform build failed

    When I tried to build from OS X for Linux, it says:

    $ GOOS=linux GOARCH=amd64 go install
    # github.com/mattn/go-sqlite3
    ../../../mattn/go-sqlite3/sqlite3.c:241 unknown #: if
    ../../../mattn/go-sqlite3/sqlite3.c:256 unknown #: if
    ../../../mattn/go-sqlite3/sqlite3.c:296 unknown #: if
    ../../../mattn/go-sqlite3/sqlite3.c:309 unknown #: if
    ../../../mattn/go-sqlite3/sqlite3.c:339 unknown #: if
    ../../../mattn/go-sqlite3/sqlite3.c:342 unknown #: elif
    ../../../mattn/go-sqlite3/sqlite3.c:343 macro redefined: SQLITE_INT_TO_PTR
    ../../../mattn/go-sqlite3/sqlite3.c:344 macro redefined: SQLITE_PTR_TO_INT
    ../../../mattn/go-sqlite3/sqlite3.c:345 unknown #: elif
    ../../../mattn/go-sqlite3/sqlite3.c:346 macro redefined: SQLITE_INT_TO_PTR
    ../../../mattn/go-sqlite3/sqlite3.c:347 macro redefined: SQLITE_PTR_TO_INT
    too many errors
    opened by elgs 68
  • Install without gcc (not possible)

    Install without gcc (not possible)

    Is it possible to use the library in Go without recompiling the binaries?https://github.com/lxc/lxd/issues/762#issuecomment-112463214

    I mean is it possible to compile binary pieces of SQLite needed be go-sqlite3 and ship them in separate repository, so that only Go itself can be used to assemble the final product together? Maybe Go already provides some helpers/tools to do that?

    opened by techtonik 52
  • Problem with unstable  go-sqlite3 version - 2.0.3

    Problem with unstable go-sqlite3 version - 2.0.3


    We at the platform team of razorpay internally use bulk-insert which internally uses github.com/jinzhu/gorm v1.9.12 and creates an indirect dependency on github.com/mattn/go-sqlite3 v2.0.3.

    Reference :- https://github.com/t-tiger/gorm-bulk-insert/blob/master/go.mod#L14

    Now, this setup was working fine for us till last week and suddenly we had a failure in our docker build for github actions citing github.com/mattn/[email protected]+incompatible: unknown revision v2.0.3

    We also saw one of your issues where you mentioned versions 2.0+ were unstable - issue

    Did you stop supporting 2.0.3 version suddenly in the last 7-10 days. We were wondering what caused the breakage of the build from our side. It would be helpful if you could throw some light on this issue.

    Thanks, Shriram

    opened by Shriram-RP 40
  • Cross compiling fails

    Cross compiling fails

    Very possibly a mistake on my part, if so please let me know where I went wrong. My first time with Go today!

    I have a basic Go file using this library. I am on macOS 10.12.3, Go 1.8 darwin/amd64.

    Succeeds: env GOOS=darwin go build -i app.go

    Fails: env GOOS=linux go build -i app.go

    Specifying GOARCH=amd64 makes no difference.


    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:18: undefined: SQLiteConn
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:26: undefined: SQLiteConn
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:27: undefined: namedValue
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:29: undefined: namedValue
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:35: undefined: SQLiteConn
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: undefined: namedValue
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:44: undefined: SQLiteConn
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:49: undefined: SQLiteConn
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:54: undefined: SQLiteStmt
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:63: undefined: SQLiteStmt
    ../../../go/src/github.com/mattn/go-sqlite3/sqlite3_go18.go:36: too many errors

    Said very basic Go file causing this, in-case it helps:

    package main
    import (
    	_ "github.com/mattn/go-sqlite3"
    // Bookmark represents a single row from database
    type Bookmark struct {
    	Id       int
    	Url      string
    	Metadata string
    	Tags     string
    	Desc     string
    	Flags    int
    func main() {
    	dbpath := GetDbPath()
    	db := InitDB(dbpath)
    	defer db.Close()
    	bookmarks := GetAllBookmarks(db)
    // Write errors to log & quit
    func CheckError(err error) {
    	if err != nil {
    func InitDB(filepath string) *sql.DB {
    	db, err := sql.Open("sqlite3", filepath)
    	if db == nil {
    		panic("db nil")
    	return db
    func GetAllBookmarks(db *sql.DB) []Bookmark {
    	const queryAll string = "SELECT * FROM bookmarks;"
    	rows, err := db.Query(queryAll)
    	defer rows.Close()
    	var result []Bookmark
    	for rows.Next() {
    		item := Bookmark{}
    		err2 := rows.Scan(&item.Id, &item.Url, &item.Metadata, &item.Tags, &item.Desc, &item.Flags)
    		result = append(result, item)
    	return result
    func GetDbPath() string {
    	const dbFileName string = "bookmarks.db"
    	var dir = os.Getenv("XDG_DATA_HOME")
    	if dir != "" {
    		dir += "/buku/"
    	} else {
    		dir = os.Getenv("HOME") + "/.local/share/buku/"
    	dir += dbFileName
    	return dir
    opened by samhh 40
  • Issue installing on Mac OS

    Issue installing on Mac OS

    Had some problems installing the lib on Mac, so just wanted to leave this here for future people searching for help:


    brew install pkgconfig
    brew install sqlite3

    I've tried pkg-config --cflags --libs sqlite3, but got:

    # pkg-config --cflags sqlite3
    Package sqlite3 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `sqlite3.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'sqlite3' found
    exit status 1

    What you need to do:

    sudo PKG_CONFIG_PATH=/usr/local/Cellar/sqlite/ go get github.com/mattn/go-sqlite3

    Please replace with your version.

    Thanks for the lib!

    opened by slava-vishnyakov 39
  • upstream 3.21.0 with UPDATE/DELETE LIMIT support

    upstream 3.21.0 with UPDATE/DELETE LIMIT support

    Amalgamation built with

    CFLAGS='-std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_DISABLE_INTRINSIC -Wno-deprecated-declarations' ./configure --enable-rtree --enable-fts3 --enable-fts4 --enable-json1 --enable-update-limit

    maybe defining flags before configure was too much, sorry for mess.

    Originally proposed in https://github.com/mattn/go-sqlite3/issues/213 https://github.com/mattn/go-sqlite3/pull/215

    opened by temoto 36
  • SELECT Query not working

    SELECT Query not working

    I have SQLite3 3.15.x on Windows 7 64 bit but the GCC and go (version 1.1) are 32 bit. The SELECT queries are not working for some reason. At times its leads to PANIC when the query is executed. Is there an issue with 32 bit version on Windows ? The following is the error returned with err.Error() : U??S??►??3?

    opened by raheelgup 31
  • cannot load github.com/mattn/go-sqlite3: module github.com/mattn/go-sqlite3@latest (v2.0.0+incompatible) found, but does not contain package github.com/mattn/go-sqlite3

    cannot load github.com/mattn/go-sqlite3: module github.com/mattn/go-sqlite3@latest (v2.0.0+incompatible) found, but does not contain package github.com/mattn/go-sqlite3

    This package doesn't seem to work with go modules. Here's a simple recipe in Docker, to make it easy to reproduce. Please tell me what I'm doing wrong:

    $ docker run -it --rm golang:alpine
    /go # apk add build-base
    /go # mkdir /src
    /go # cd /src
    /src # cat - > main.go
    package main
    import (
    	_ "github.com/mattn/go-sqlite3"
    func main() {
    	fmt.Println("Hello world!")
    /src # export CGO_ENABLED=1
    /src # go mod init example.com
    go: creating new go.mod: module example.com
    /src # go get github.com/mattn/go-sqlite3
    go: finding github.com/mattn/go-sqlite3 v2.0.0+incompatible
    go: downloading github.com/mattn/go-sqlite3 v2.0.0+incompatible
    go: extracting github.com/mattn/go-sqlite3 v2.0.0+incompatible
    /src # go run .
    build example.com: cannot load github.com/mattn/go-sqlite3: module github.com/mattn/go-sqlite3@latest (v2.0.0+incompatible) found, but does not contain package github.com/mattn/go-sqlite3
    opened by cjyar 29
  • database is locked

    database is locked

    We have a little app which has multiple goroutines all running queries and it often fails with "database is locked" :(

    we're running with:

    db, err := sql.Open("sqlite3", "test.db?cache=shared&mode=rwc")
    PRAGMA journal_mode = WAL;
    PRAGMA synchronous = NORMAL;

    sqlite3 -version 3.10.2 2016-01-20 15:27:19 17efb4209f97fb4971656086b138599a91a75ff9

    Is this a known issue?

    opened by stevenh 28
  • gcc issue on windows 64

    gcc issue on windows 64

    While trying to do "go install github.com/mattn/go-sqlite3" I am getting the follwoing error. In one of the issues someone mentioned that we don't need gcc if we install go-sqlite3. Any help would be greatly appreciated.


    exec: "gcc": executable file not found in %PATH%

    Thanks Arul

    opened by arulrajalivi 27
  • [REQUEST] Memory with writeback

    [REQUEST] Memory with writeback

    For performance reasons I would like to ask, if this is possible?

    Opening an existing SQLite3 file and writing it into Memory. But everytime I write or read everything, I would like it to happen in memory (so way quicker). But after it is written an async task should write it back.

    Currently I have tried it likle this:

    db, err = sql.Open("sqlite3", "file:../data/tickets.db?mode=memory&cache=shared&_journal_mode=MEMORY")

    But everytime I read/write it is way slower then other SQLite3 implementations - like in GORM, Python3 ... Here a write and read takes about 1,5ms, but for these others it actually is about 0,05ms which for me is a big difference.

    So I would like to know what I migh be doing wrong., Are any of these settings (mode=memory&cache=shared&_journal_mode=MEMORY) not beneficial for performance? Even when I have the mode=memory set, it does not seem to be actually as fast as it should be if it would have been in memory. And it does not work, when I want it to load a DB from SSD into memory. I already have a DB, and this should be copied over into memory - I dont want to have a fresh DB everytime, as this is what is happening as soon as I use mode=memory.

    Would be happy to get any feedback and I am open for an discussion.

    opened by MartinHotmann 2
  • Two process with Two sqlite db file

    Two process with Two sqlite db file

    There are two program running in one server , and program A create connection to A.db, program B create connection to B.db.

    When I use single Jmeter query A program's api and do some calculate in A.db, it can be 10 qps . (Now program B is idle) And when I use single Jmeter query B program's api and do some calculate in B.db, it can be 10 qps too. (Now program A is idle) But when I use **Two Jmeter ** query both A and B , each process only can be 5 qps.

    A and B process use different sqlite DB, I don't why is 5qps per program. Please help me, thanks a lot.

    opened by abeiabei 4
  • Add ability to open database from a

    Add ability to open database from a "virtual" file

    I would like to be able to open an sqlite database given a file descriptor ( no filenames ). The mechanism to do so is described here https://sqlite.org/forum/forumpost/d4ed1b197ec94182 but the URI parser within this library prevents this technique from working.

    The reason I want to do this is to utilize crash-safe anonymous inodes as implemented here: https://pkg.go.dev/github.com/tmthrgd/tmpfile#TempFile

    The reason I can not use the :memory: + VACUUM INTO, is because the dataset is very large (almost a TiB ) and working with it in-RAM is problematic.

    I am aware that the database will have to be opened with pragmas disabling WAL etc, as they rely on a "filename+extension" mechanism, and that's ok.

    Thank you!

    opened by ribasushi 1
  • Add support for SQLCipher

    Add support for SQLCipher

    This PR adds support for SQLCipher whilst keeping the existing embedded sqlite3 implementation. The support is enabled via the sqlcipher and libsqlcipher build tags, which respectively use the embedded SQLCipher implementation or link directly to libsqlcipher.

    An upgrade script has been added to automate the inclusion of new versions of SQLCipher.

    I believe that adding this support would benefit the Go ecosystem, as multiple unmaintained repos have flourished that are forks of this repo bolting on support for older versions of SQLCipher. Having support here would enable gorm users to benefit from the encryption feature without having to patch anything.

    opened by jgiannuzzi 4
  • ld warnings and stuck compilation

    ld warnings and stuck compilation

    go env

    GOENV="/Users/amitava.ghosh/Library/Application Support/go/env"
    CGO_CFLAGS="-g -O2"
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/h1/go-build3066795306=/tmp/go-build -gno-record-gcc-switches -fno-common"
     master± ⟩ go test github.com/go-gorm-v1/dbresolver
    # github.com/go-gorm-v1/dbresolver.test
    ld: warning: -no_pie is deprecated when targeting new OS versions
    # stuck here
    opened by amitavaghosh1 1
  • v1.14.16(Oct 26, 2022)

    What's Changed

    • Add build tag to enable OSTRACE() logging by @benbjohnson in https://github.com/mattn/go-sqlite3/pull/1067
    • TestQueryer: actually check Rows returned by @ohwgiles in https://github.com/mattn/go-sqlite3/pull/1062
    • Update README to fix reference URL by @shibukawa in https://github.com/mattn/go-sqlite3/pull/1082
    • Fix test queryer test by @joshbuddy in https://github.com/mattn/go-sqlite3/pull/1079
    • Rollback on constraint failure by @joshbuddy in https://github.com/mattn/go-sqlite3/pull/1071
    • Fix "ennviroment" by @RewardedIvan in https://github.com/mattn/go-sqlite3/pull/1077
    • こんにちわ is wrong Japanse, Correct word is こんにちは by @KiYugadgeter in https://github.com/mattn/go-sqlite3/pull/1085
    • Add test for sqlite_math_functions tag by @lggruspe in https://github.com/mattn/go-sqlite3/pull/1059
    • remove unuseful ldflags for windows platform. by @kkqy in https://github.com/mattn/go-sqlite3/pull/1084
    • Cross Compiling for Mac OS via musl-cross by @jodosha in https://github.com/mattn/go-sqlite3/pull/1090
    • Update README.md to include vtable feature by @dvas0004 in https://github.com/mattn/go-sqlite3/pull/1100
    • Updating vtable example, "BestIndex" method by @dvas0004 in https://github.com/mattn/go-sqlite3/pull/1099
    • Update amalgamation code by @mattn in https://github.com/mattn/go-sqlite3/pull/1104

    New Contributors

    • @ohwgiles made their first contribution in https://github.com/mattn/go-sqlite3/pull/1062
    • @shibukawa made their first contribution in https://github.com/mattn/go-sqlite3/pull/1082
    • @joshbuddy made their first contribution in https://github.com/mattn/go-sqlite3/pull/1079
    • @RewardedIvan made their first contribution in https://github.com/mattn/go-sqlite3/pull/1077
    • @KiYugadgeter made their first contribution in https://github.com/mattn/go-sqlite3/pull/1085
    • @lggruspe made their first contribution in https://github.com/mattn/go-sqlite3/pull/1059
    • @kkqy made their first contribution in https://github.com/mattn/go-sqlite3/pull/1084
    • @jodosha made their first contribution in https://github.com/mattn/go-sqlite3/pull/1090
    • @dvas0004 made their first contribution in https://github.com/mattn/go-sqlite3/pull/1100

    Full Changelog: https://github.com/mattn/go-sqlite3/compare/v1.14.15...v1.14.16

    Source code(tar.gz)
    Source code(zip)
  • v1.10.0(May 29, 2019)


    • SQLite 3.28.0


    • Fix type of variadic function
    • column types text, varchar, *char return as strings
    • Use SQLITE_OPEN_CREATE for sqlite3_open_v2
    • Fix data race in AutoCommit()
    Source code(tar.gz)
    Source code(zip)
  • v1.9.0(Jun 13, 2018)


    • SQLite 3.24.0


    • Add OpenBSD
    • Increase coverage
    • Added Tests for sqlite_crypt encoders

    Repository Updates

    • Shorten build time on Travis-CI
    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Jun 12, 2018)


    • SQLite: 3.24.0

    New Features

    • Implemented SQLite User Authentication Module
    • Implemented GetFilename sqlite3_db_filename
    • Implemented use of PRAGMA's from DSN
    • Implemented usleep for Windows
      • Auto Vacuum
      • Case Sensitive LIKE
      • Defer Foreign Keys
      • Ignore CHECK Constraints
      • Journal Mode
      • Query Only
      • Secure Delete
      • Synchronous
      • User Authentication
      • Writeable Schema


    • Rewrite upgrade tool to auto include UserAuth Module
    • FIX: Case-Sensitive values for PRAGMA
    • Reduced code for:
      • foreign_keys
      • recursive_triggers


    • #542
    • #568
    • ICU extension for darwin
    • Fixes WAL Mode Synchronous
    • #120
    • Compile Section Closes #175
    • Compile Section Closes #201
    • Compile Section Closes #206
    • Compile Section Closes #404
    • Compile Section Closes #217
    • Compile Section Closes #224
    • Compile Section Closes #234
    • Compile Section Closes #242
    • Feature table Closes #255
    • Description Section Closes #232
    • Golang:1.6 not supported Closes #272
    • Golang:1.5 not supported + compilation section Closes #283
    • usleep Implemented Closes #285
    • FAQ Section Closes #289
    • Compile Section closes #295
    • FAQ Section Closes #305
    • PR339 Closes #318 #321
    • Compilation Section Closes #341
    • PR407 Closes #364
    • Feature sqlite_vtable Closes #393
    • Compile Section Closes #416
    • sqlite_trace feature Closes #433
    • Compilation Section Closes #435
    • Compilation Section Closes #443
    • Golang:1.6 Not Supported Closes #445
    • Compilation Section Closes #451
    • Compilation Section Closes #467
    • Compilation Section Closes #491
    • Compilation Section Closes #495
    • Compilation Section Closes #505
    • Compilation Section Closes #557
    • Compilation Section Closes #560
    Source code(tar.gz)
    Source code(zip)
Long-time Golang user&contributor, Google Dev Expert for Go, and author of many Go tools, Vim plugin author. Windows hacker C#/Java/C/C++
Microsoft ActiveX Object DataBase driver for go that using exp/sql

go-adodb Microsoft ADODB driver conforming to the built-in database/sql interface Installation This package can be installed with the go get command:

mattn 132 Dec 30, 2022
Oracle driver for Go using database/sql

go-oci8 Description Golang Oracle database driver conforming to the Go database/sql interface Installation Install Oracle full client or Instant Clien

mattn 598 Dec 30, 2022
Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

pqssh Go driver for PostgreSQL over SSH. This driver can connect to postgres on a server via SSH using the local ssh-agent, password, or private-key.

mattn 52 Nov 6, 2022
Go Sql Server database driver.

gofreetds Go FreeTDS wrapper. Native Sql Server database driver. Features: can be used as database/sql driver handles calling stored procedures handle

minus5 108 Dec 16, 2022
Pure Go Postgres driver for database/sql

pq - A pure Go postgres driver for Go's database/sql package Install go get github.com/lib/pq Features SSL Handles bad connections for database/sql S

null 7.8k Jan 2, 2023
Attach hooks to any database/sql driver

sqlhooks Attach hooks to any database/sql driver. The purpose of sqlhooks is to provide a way to instrument your sql statements, making really easy to

Gustavo Chaín 598 Dec 14, 2022
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.

Qmgo English | 简体中文 Qmgo is a Go driver for MongoDB . It is based on MongoDB official driver, but easier to use like mgo (such as the chain call). Qmg

Qiniu Cloud 1k Dec 28, 2022
Mirror of Apache Calcite - Avatica Go SQL Driver

Apache Avatica/Phoenix SQL Driver Apache Calcite's Avatica Go is a Go database/sql driver for the Avatica server. Avatica is a sub-project of Apache C

The Apache Software Foundation 103 Nov 3, 2022
Firebird RDBMS sql driver for Go (golang)

firebirdsql (Go firebird sql driver) Firebird RDBMS http://firebirdsql.org SQL driver for Go Requirements Firebird 2.5 or higher Golang 1.13 or higher

Hajime Nakagami 186 Dec 20, 2022
Microsoft SQL server driver written in go language

A pure Go MSSQL driver for Go's database/sql package Install Requires Go 1.8 or above. Install with go get github.com/denisenkom/go-mssqldb . Connecti

null 1.7k Dec 26, 2022
GO DRiver for ORacle DB

Go DRiver for ORacle godror is a package which is a database/sql/driver.Driver for connecting to Oracle DB, using Anthony Tuininga's excellent OCI wra

null 409 Jan 5, 2023
PostgreSQL driver and toolkit for Go

pgx - PostgreSQL Driver and Toolkit pgx is a pure Go driver and toolkit for PostgreSQL. pgx aims to be low-level, fast, and performant, while also ena

Jack Christensen 6.5k Jan 4, 2023
Lightweight Golang driver for ArangoDB

Arangolite Arangolite is a lightweight ArangoDB driver for Go. It focuses on pure AQL querying. See AranGO for a more ORM-like experience. IMPORTANT:

Fabien Herfray 73 Sep 26, 2022
Go language driver for RethinkDB

RethinkDB-go - RethinkDB Driver for Go Go driver for RethinkDB Current version: v6.2.1 (RethinkDB v2.4) Please note that this version of the driver on

RethinkDB 1.6k Dec 24, 2022
goriak - Go language driver for Riak KV

goriak Current version: v3.2.1. Riak KV version: 2.0 or higher, the latest version of Riak KV is always recommended. What is goriak? goriak is a wrapp

Gustav Westling 29 Nov 22, 2022
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)

Mongo Go Models Important Note: We changed package name from github.com/Kamva/mgm/v3(uppercase Kamva) to github.com/kamva/mgm/v3(lowercase kamva) in v

kamva 607 Jan 2, 2023
The MongoDB driver for Go

The MongoDB driver for Go This fork has had a few improvements by ourselves as well as several PR's merged from the original mgo repo that are current

GlobalSign 2k Jan 8, 2023
The Go driver for MongoDB

MongoDB Go Driver The MongoDB supported driver for Go. Requirements Installation Usage Bugs / Feature Reporting Testing / Development Continuous Integ

mongodb 7.1k Dec 31, 2022
RethinkDB-go - RethinkDB Driver for Go

Go language driver for RethinkDB

RethinkDB 1.6k Dec 24, 2022