The semantics of sql.Tx.Commit impose that the transaction is
finished and cleaned up by the time the driver's Commit function
returns. However sqlite3 leaves the transaction open if COMMIT
fails due to an SQLITE_BUSY error, so *we* must clean it up.
Closes#184.
The cgo pointer passing rules forbid passing a Go pointer to C if that
pointer points to memory containing other Go pointers. This is true
even if the Go pointer is converted to uintptr.
This change fixes the code to use a handle instead, and to look up the
handle in the callback function.
In Go 1.6, the cgo checking rules are more precise when they see an
address operation as an argument to the C function. When you pass &v[0]
to a C function, the cgo check just verifies that v itself does not
contain any pointers. When you write `p := &v[0]` and then pass p to
the C function, the cgo check is conservative: it verifies that the
entire memory block to which p points does not contain any pointers.
When the bind function is called by code that passes a slice that is
part of a larger struct, this means that the cgo check will look at the
entire larger struct, not just the slice. This can cause a surprising
run time failure.
Avoid this problem by rewriting the code slightly to pass &v[0] in the
call to the C function itself.
In particular this fixes the tests of github.com/jmoiron/sqlx when using
Go 1.6.
Previously, the timezone information for a provided value was discarded
and the value always stored as in UTC. However, sqlite allows specifying
the timezone offsets and handles those values appropriately. This change
stores the timezone information and parses it out if present, otherwise
it defaults to UTC as before.
One additional bugfix: Previously, a unix timestamp in seconds was
parsed in the local timezone (rather than UTC), in contrast to a unix
timestamp in milliseconds that was parsed in UTC.
While fixing that extra bug, I cleaned up the parsing code -- no need to
convert to a string and then parse it back again and risk a parse error,
just to check the number of digits.
The tests were extended to cover non-UTC timezones storage & retrieval,
meaningful unix timestamps, and correct handling of a trailing Z.
sqlite_omit_load_extension is a go build tag which behaves much like its
C counterpart SQLITE_OMIT_LOAD_EXTENSION
Signed-off-by: Jessica Frazelle <acidburn@docker.com>
A call now doesn't have to do any reflection, it just blindly invokes
a bunch of argument and return value handlers to execute the translation,
and the safety of the translation is determined at registration time.
When specified, changes the default locking at a tx.Begin.
Changelog (v2):
Add a testcase to ensure _txlock is properly handled.
Closes#189
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
This fixes the problem where when building with gccgo, sqlite3.c is
overwritten, leading to a build failure.
An alternative would have been to move sqlite3*.{c,h} to a subdirectory,
but that seems to confuse the linker a fair bit and would just swap one
implementation-dependent issue for another.
Closes#20
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Fixes the following error message on SmartOS:
$ go get github.com/mattn/go-sqlite3
In file included from /usr/include/stdio.h:37:0,
from go/src/github.com/mattn/go-sqlite3/sqlite3.c:8422:
/opt/local/gcc47/lib/gcc/i386-sun-solaris2.11/4.7.3/include-fixed/sys/feature_tests.h:366:2: error: #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications require the use of c99"
Use the sqlite3_errmsg() API to retrieve more specific error
messages.
eg. Attempting to exec 'CREATE TABLE ExistingTableName (...)'
will now report 'table already exists: ExistingTableName' rather
than 'SQL logic error or missing database'
This commit introduces a new type 'ErrNo', implementing the error
interface. Constants for all sqlite3 error codes are provided
in the new source file "error.go".
By loading extensions this way, it's not possible to later load
extensions using db.Exec, which improves security, and makes it much
easier to load extensions correctly. The zero value for the slice
(the empty slice) loads no extensions by default.
The extension example has been updated to use this much simpler system.
The ConnectHook field is still in SQLiteDriver in case it's needed for
other driver-wide initialization.
Updates #71 of mattn/go-sqlite3.
The ConnectHook field of an SQLiteDriver should return an error in
case something bad happened during the hook.
The extension example needs to load the extension in a ConnectHook,
otherwise the extension is only loaded in a single connection in the pool.
By putting the extension loading in the ConnectHook, its called for every
connection that is opened by the sql.DB.