Tests can now use config files (#36)
This commit is contained in:
116
vendor/github.com/mattn/go-sqlite3/sqlite3.go
generated
vendored
116
vendor/github.com/mattn/go-sqlite3/sqlite3.go
generated
vendored
@ -78,8 +78,38 @@ _sqlite3_exec(sqlite3* db, const char* pcmd, long long* rowid, long long* change
|
||||
return rv;
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
extern int _sqlite3_step_blocking(sqlite3_stmt *stmt);
|
||||
extern int _sqlite3_step_row_blocking(sqlite3_stmt* stmt, long long* rowid, long long* changes);
|
||||
extern int _sqlite3_prepare_v2_blocking(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail);
|
||||
|
||||
static int
|
||||
_sqlite3_step(sqlite3_stmt* stmt, long long* rowid, long long* changes)
|
||||
_sqlite3_step_internal(sqlite3_stmt *stmt)
|
||||
{
|
||||
return _sqlite3_step_blocking(stmt);
|
||||
}
|
||||
|
||||
static int
|
||||
_sqlite3_step_row_internal(sqlite3_stmt* stmt, long long* rowid, long long* changes)
|
||||
{
|
||||
return _sqlite3_step_row_blocking(stmt, rowid, changes);
|
||||
}
|
||||
|
||||
static int
|
||||
_sqlite3_prepare_v2_internal(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail)
|
||||
{
|
||||
return _sqlite3_prepare_v2_blocking(db, zSql, nBytes, ppStmt, pzTail);
|
||||
}
|
||||
|
||||
#else
|
||||
static int
|
||||
_sqlite3_step_internal(sqlite3_stmt *stmt)
|
||||
{
|
||||
return sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
static int
|
||||
_sqlite3_step_row_internal(sqlite3_stmt* stmt, long long* rowid, long long* changes)
|
||||
{
|
||||
int rv = sqlite3_step(stmt);
|
||||
sqlite3* db = sqlite3_db_handle(stmt);
|
||||
@ -88,6 +118,13 @@ _sqlite3_step(sqlite3_stmt* stmt, long long* rowid, long long* changes)
|
||||
return rv;
|
||||
}
|
||||
|
||||
static int
|
||||
_sqlite3_prepare_v2_internal(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail)
|
||||
{
|
||||
return sqlite3_prepare_v2(db, zSql, nBytes, ppStmt, pzTail);
|
||||
}
|
||||
#endif
|
||||
|
||||
void _sqlite3_result_text(sqlite3_context* ctx, const char* s) {
|
||||
sqlite3_result_text(ctx, s, -1, &free);
|
||||
}
|
||||
@ -119,6 +156,8 @@ int commitHookTrampoline(void*);
|
||||
void rollbackHookTrampoline(void*);
|
||||
void updateHookTrampoline(void*, int, char*, char*, sqlite3_int64);
|
||||
|
||||
int authorizerTrampoline(void*, int, char*, char*, char*, char*);
|
||||
|
||||
#ifdef SQLITE_LIMIT_WORKER_THREADS
|
||||
# define _SQLITE_HAS_LIMIT
|
||||
# define SQLITE_LIMIT_LENGTH 0
|
||||
@ -200,18 +239,57 @@ func Version() (libVersion string, libVersionNumber int, sourceID string) {
|
||||
}
|
||||
|
||||
const (
|
||||
// used by authorizer and pre_update_hook
|
||||
SQLITE_DELETE = C.SQLITE_DELETE
|
||||
SQLITE_INSERT = C.SQLITE_INSERT
|
||||
SQLITE_UPDATE = C.SQLITE_UPDATE
|
||||
|
||||
// used by authorzier - as return value
|
||||
SQLITE_OK = C.SQLITE_OK
|
||||
SQLITE_IGNORE = C.SQLITE_IGNORE
|
||||
SQLITE_DENY = C.SQLITE_DENY
|
||||
|
||||
// different actions query tries to do - passed as argument to authorizer
|
||||
SQLITE_CREATE_INDEX = C.SQLITE_CREATE_INDEX
|
||||
SQLITE_CREATE_TABLE = C.SQLITE_CREATE_TABLE
|
||||
SQLITE_CREATE_TEMP_INDEX = C.SQLITE_CREATE_TEMP_INDEX
|
||||
SQLITE_CREATE_TEMP_TABLE = C.SQLITE_CREATE_TEMP_TABLE
|
||||
SQLITE_CREATE_TEMP_TRIGGER = C.SQLITE_CREATE_TEMP_TRIGGER
|
||||
SQLITE_CREATE_TEMP_VIEW = C.SQLITE_CREATE_TEMP_VIEW
|
||||
SQLITE_CREATE_TRIGGER = C.SQLITE_CREATE_TRIGGER
|
||||
SQLITE_CREATE_VIEW = C.SQLITE_CREATE_VIEW
|
||||
SQLITE_CREATE_VTABLE = C.SQLITE_CREATE_VTABLE
|
||||
SQLITE_DROP_INDEX = C.SQLITE_DROP_INDEX
|
||||
SQLITE_DROP_TABLE = C.SQLITE_DROP_TABLE
|
||||
SQLITE_DROP_TEMP_INDEX = C.SQLITE_DROP_TEMP_INDEX
|
||||
SQLITE_DROP_TEMP_TABLE = C.SQLITE_DROP_TEMP_TABLE
|
||||
SQLITE_DROP_TEMP_TRIGGER = C.SQLITE_DROP_TEMP_TRIGGER
|
||||
SQLITE_DROP_TEMP_VIEW = C.SQLITE_DROP_TEMP_VIEW
|
||||
SQLITE_DROP_TRIGGER = C.SQLITE_DROP_TRIGGER
|
||||
SQLITE_DROP_VIEW = C.SQLITE_DROP_VIEW
|
||||
SQLITE_DROP_VTABLE = C.SQLITE_DROP_VTABLE
|
||||
SQLITE_PRAGMA = C.SQLITE_PRAGMA
|
||||
SQLITE_READ = C.SQLITE_READ
|
||||
SQLITE_SELECT = C.SQLITE_SELECT
|
||||
SQLITE_TRANSACTION = C.SQLITE_TRANSACTION
|
||||
SQLITE_ATTACH = C.SQLITE_ATTACH
|
||||
SQLITE_DETACH = C.SQLITE_DETACH
|
||||
SQLITE_ALTER_TABLE = C.SQLITE_ALTER_TABLE
|
||||
SQLITE_REINDEX = C.SQLITE_REINDEX
|
||||
SQLITE_ANALYZE = C.SQLITE_ANALYZE
|
||||
SQLITE_FUNCTION = C.SQLITE_FUNCTION
|
||||
SQLITE_SAVEPOINT = C.SQLITE_SAVEPOINT
|
||||
SQLITE_COPY = C.SQLITE_COPY
|
||||
/*SQLITE_RECURSIVE = C.SQLITE_RECURSIVE*/
|
||||
)
|
||||
|
||||
// SQLiteDriver implement sql.Driver.
|
||||
// SQLiteDriver implements driver.Driver.
|
||||
type SQLiteDriver struct {
|
||||
Extensions []string
|
||||
ConnectHook func(*SQLiteConn) error
|
||||
}
|
||||
|
||||
// SQLiteConn implement sql.Conn.
|
||||
// SQLiteConn implements driver.Conn.
|
||||
type SQLiteConn struct {
|
||||
mu sync.Mutex
|
||||
db *C.sqlite3
|
||||
@ -221,12 +299,12 @@ type SQLiteConn struct {
|
||||
aggregators []*aggInfo
|
||||
}
|
||||
|
||||
// SQLiteTx implemen sql.Tx.
|
||||
// SQLiteTx implements driver.Tx.
|
||||
type SQLiteTx struct {
|
||||
c *SQLiteConn
|
||||
}
|
||||
|
||||
// SQLiteStmt implement sql.Stmt.
|
||||
// SQLiteStmt implements driver.Stmt.
|
||||
type SQLiteStmt struct {
|
||||
mu sync.Mutex
|
||||
c *SQLiteConn
|
||||
@ -236,13 +314,13 @@ type SQLiteStmt struct {
|
||||
cls bool
|
||||
}
|
||||
|
||||
// SQLiteResult implement sql.Result.
|
||||
// SQLiteResult implements sql.Result.
|
||||
type SQLiteResult struct {
|
||||
id int64
|
||||
changes int64
|
||||
}
|
||||
|
||||
// SQLiteRows implement sql.Rows.
|
||||
// SQLiteRows implements driver.Rows.
|
||||
type SQLiteRows struct {
|
||||
s *SQLiteStmt
|
||||
nc int
|
||||
@ -440,6 +518,20 @@ func (c *SQLiteConn) RegisterUpdateHook(callback func(int, string, string, int64
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterAuthorizer sets the authorizer for connection.
|
||||
//
|
||||
// The parameters to the callback are the operation (one of the constants
|
||||
// SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE), and 1 to 3 arguments,
|
||||
// depending on operation. More details see:
|
||||
// https://www.sqlite.org/c3ref/c_alter_table.html
|
||||
func (c *SQLiteConn) RegisterAuthorizer(callback func(int, string, string, string) int) {
|
||||
if callback == nil {
|
||||
C.sqlite3_set_authorizer(c.db, nil, nil)
|
||||
} else {
|
||||
C.sqlite3_set_authorizer(c.db, (*[0]byte)(C.authorizerTrampoline), unsafe.Pointer(newHandle(c, callback)))
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterFunc makes a Go function available as a SQLite function.
|
||||
//
|
||||
// The Go function can have arguments of the following types: any
|
||||
@ -1582,7 +1674,7 @@ func (c *SQLiteConn) prepare(ctx context.Context, query string) (driver.Stmt, er
|
||||
defer C.free(unsafe.Pointer(pquery))
|
||||
var s *C.sqlite3_stmt
|
||||
var tail *C.char
|
||||
rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail)
|
||||
rv := C._sqlite3_prepare_v2_internal(c.db, pquery, -1, &s, &tail)
|
||||
if rv != C.SQLITE_OK {
|
||||
return nil, c.lastError()
|
||||
}
|
||||
@ -1816,7 +1908,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []namedValue) (driver.Result
|
||||
}
|
||||
|
||||
var rowid, changes C.longlong
|
||||
rv := C._sqlite3_step(s.s, &rowid, &changes)
|
||||
rv := C._sqlite3_step_row_internal(s.s, &rowid, &changes)
|
||||
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
|
||||
err := s.c.lastError()
|
||||
C.sqlite3_reset(s.s)
|
||||
@ -1883,12 +1975,12 @@ func (rc *SQLiteRows) DeclTypes() []string {
|
||||
|
||||
// Next move cursor to next.
|
||||
func (rc *SQLiteRows) Next(dest []driver.Value) error {
|
||||
rc.s.mu.Lock()
|
||||
defer rc.s.mu.Unlock()
|
||||
if rc.s.closed {
|
||||
return io.EOF
|
||||
}
|
||||
rc.s.mu.Lock()
|
||||
defer rc.s.mu.Unlock()
|
||||
rv := C.sqlite3_step(rc.s.s)
|
||||
rv := C._sqlite3_step_internal(rc.s.s)
|
||||
if rv == C.SQLITE_DONE {
|
||||
return io.EOF
|
||||
}
|
||||
|
Reference in New Issue
Block a user