Commit e7464b51 authored by gwenn's avatar gwenn

Fix for last weekly.

parent a007c4ab
# Copyright 2010 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
include $(GOROOT)/src/Make.inc
TARG=github.com/gwenn/gosqlite
CGOFILES=\
sqlite.go\
backup.go\
meta.go\
trace.go\
blob.go\
hook.go\
function.go
GOFILES=\
date.go\
driver.go
include $(GOROOT)/src/Make.pkg
......@@ -11,7 +11,6 @@ package sqlite
import "C"
import (
"os"
"time"
"unsafe"
)
......@@ -92,10 +91,10 @@ func (b *Backup) Run(npage int, sleepNs time.Duration, c chan<- BackupStatus) er
// Finish/stop the backup
// (See http://sqlite.org/c3ref/backup_finish.html#sqlite3backupfinish)
func (b *Backup) Close() error {
if b.sb == nil {
return os.EINVAL
rv := C.sqlite3_backup_finish(b.sb)
if rv != C.SQLITE_OK {
return Errno(rv)
}
C.sqlite3_backup_finish(b.sb)
b.sb = nil
return nil
}
......@@ -33,8 +33,12 @@ func (d *Driver) Open(name string) (driver.Conn, error) {
// PRAGMA schema_version may be used to detect when the database schema is altered
func (c *connImpl) Exec(query string, args []interface{}) (driver.Result, error) {
if err := c.c.Exec(query, args...); err != nil {
func (c *connImpl) Exec(query string, args []driver.Value) (driver.Result, error) {
tmp := make([]interface{}, len(args))
for i, arg := range args {
tmp[i] = arg
}
if err := c.c.Exec(query, tmp...); err != nil {
return nil, err
}
return c, nil // FIXME RowAffected/ddlSuccess
......@@ -84,9 +88,11 @@ func (s *stmtImpl) NumInput() int {
return s.s.BindParameterCount()
}
func (s *stmtImpl) Exec(args []interface{}) (driver.Result, error) {
err := s.s.Exec(args...)
if err != nil {
func (s *stmtImpl) Exec(args []driver.Value) (driver.Result, error) {
if err := s.bind(args); err != nil {
return nil, err
}
if err := s.s.exec(); err != nil {
return nil, err
}
return s, nil // FIXME RowAffected/ddlSuccess
......@@ -102,19 +108,28 @@ func (s *stmtImpl) RowsAffected() (int64, error) {
return int64(s.s.c.Changes()), nil
}
func (s *stmtImpl) Query(args []interface{}) (driver.Rows, error) {
if err := s.s.Bind(args...); err != nil {
func (s *stmtImpl) Query(args []driver.Value) (driver.Rows, error) {
if err := s.bind(args); err != nil {
return nil, err
}
return s, nil
}
func (s *stmtImpl) bind(args []driver.Value) error {
for i, v := range args {
if err := s.s.BindByIndex(i+1, v); err != nil {
return err
}
}
return nil
}
// TODO Cache result?
func (s *stmtImpl) Columns() []string {
return s.s.ColumnNames()
}
func (s *stmtImpl) Next(dest []interface{}) error {
func (s *stmtImpl) Next(dest []driver.Value) error {
ok, err := s.s.Next()
if err != nil {
return err
......@@ -122,6 +137,8 @@ func (s *stmtImpl) Next(dest []interface{}) error {
if !ok {
return io.EOF
}
s.s.ScanValues(dest)
for i := range dest {
dest[i] = s.s.ScanValue(i)
}
return nil
}
......@@ -106,7 +106,6 @@ func TestSqlQuery(t *testing.T) {
err = rows.Scan(&id, &name)
checkNoError(t, err, "Error while scanning: %s")
}
// FIXME Dangling statement
}
func TestSqlTx(t *testing.T) {
......
#include <sqlite3.h>
#include <stdlib.h>
extern void goXAuxDataDestroy(void *ad);
void goSqlite3SetAuxdata(sqlite3_context *ctx, int N, void *ad) {
sqlite3_set_auxdata(ctx, N, ad, goXAuxDataDestroy);
}
extern void goXFunc(sqlite3_context *ctx, void *udf, void *goctx, int argc, sqlite3_value **argv);
extern void goXStep(sqlite3_context *ctx, void *udf, int argc, sqlite3_value **argv);
extern void goXFinal(sqlite3_context *ctx, void *udf);
extern void goXDestroy(void *pApp);
static void cXFunc(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
void *goctx = sqlite3_get_auxdata(ctx, 0);
goXFunc(ctx, udf, goctx, argc, argv);
}
static void cXStep(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
goXStep(ctx, udf, argc, argv);
}
static void cXFinal(sqlite3_context *ctx) {
void *udf = sqlite3_user_data(ctx);
goXFinal(ctx, udf);
}
int goSqlite3CreateScalarFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, cXFunc, NULL, NULL, goXDestroy);
}
int goSqlite3CreateAggregateFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, NULL, cXStep, cXFinal, goXDestroy);
}
......@@ -46,39 +46,9 @@ static int my_value_numeric_type(sqlite3_value **argv, int i) {
return sqlite3_value_numeric_type(argv[i]);
}
extern void goXAuxDataDestroy(void *ad);
static void goSqlite3SetAuxdata(sqlite3_context *ctx, int N, void *ad) {
sqlite3_set_auxdata(ctx, N, ad, goXAuxDataDestroy);
}
extern void goXFunc(sqlite3_context *ctx, void *udf, void *goctx, int argc, sqlite3_value **argv);
extern void goXStep(sqlite3_context *ctx, void *udf, int argc, sqlite3_value **argv);
extern void goXFinal(sqlite3_context *ctx, void *udf);
extern void goXDestroy(void *pApp);
static void cXFunc(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
void *goctx = sqlite3_get_auxdata(ctx, 0);
goXFunc(ctx, udf, goctx, argc, argv);
}
static void cXStep(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
goXStep(ctx, udf, argc, argv);
}
static void cXFinal(sqlite3_context *ctx) {
void *udf = sqlite3_user_data(ctx);
goXFinal(ctx, udf);
}
static int goSqlite3CreateScalarFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, cXFunc, NULL, NULL, goXDestroy);
}
static int goSqlite3CreateAggregateFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) {
return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, NULL, cXStep, cXFinal, goXDestroy);
}
void goSqlite3SetAuxdata(sqlite3_context *ctx, int N, void *ad);
int goSqlite3CreateScalarFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp);
int goSqlite3CreateAggregateFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp);
*/
import "C"
......
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <sqlite3.h>
extern int goXCommitHook(void *udp);
void* goSqlite3CommitHook(sqlite3 *db, void *udp) {
return sqlite3_commit_hook(db, goXCommitHook, udp);
}
extern void goXRollbackHook(void *udp);
void* goSqlite3RollbackHook(sqlite3 *db, void *udp) {
return sqlite3_rollback_hook(db, goXRollbackHook, udp);
}
extern void goXUpdateHook(void *udp, int action, char const *dbName, char const *tableName, sqlite3_int64 rowId);
void* goSqlite3UpdateHook(sqlite3 *db, void *udp) {
return sqlite3_update_hook(db, goXUpdateHook, udp);
}
......@@ -6,25 +6,10 @@ package sqlite
/*
#include <sqlite3.h>
#include <stdlib.h>
extern int goXCommitHook(void *udp);
static void* goSqlite3CommitHook(sqlite3 *db, void *udp) {
return sqlite3_commit_hook(db, goXCommitHook, udp);
}
extern void goXRollbackHook(void *udp);
static void* goSqlite3RollbackHook(sqlite3 *db, void *udp) {
return sqlite3_rollback_hook(db, goXRollbackHook, udp);
}
extern void goXUpdateHook(void *udp, int action, char const *dbName, char const *tableName, sqlite3_int64 rowId);
static void* goSqlite3UpdateHook(sqlite3 *db, void *udp) {
return sqlite3_update_hook(db, goXUpdateHook, udp);
}
void* goSqlite3CommitHook(sqlite3 *db, void *udp);
void* goSqlite3RollbackHook(sqlite3 *db, void *udp);
void* goSqlite3UpdateHook(sqlite3 *db, void *udp);
*/
import "C"
......
......@@ -523,6 +523,9 @@ func (s *Stmt) Exec(args ...interface{}) error {
if err != nil {
return err
}
return s.exec()
}
func (s *Stmt) exec() error {
rv := C.sqlite3_step(s.stmt)
C.sqlite3_reset(s.stmt)
if Errno(rv) != Done {
......
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include <sqlite3.h>
#include <stdlib.h>
extern void goXTrace(void *udp, const char *sql);
void goSqlite3Trace(sqlite3 *db, void *udp) {
sqlite3_trace(db, goXTrace, udp);
}
extern void goXProfile(void *udp, const char *sql, sqlite3_uint64 nanoseconds);
void goSqlite3Profile(sqlite3 *db, void *udp) {
sqlite3_profile(db, goXProfile, udp);
}
extern int goXAuth(void *udp, int action, const char *arg1, const char *arg2, const char *dbName, const char *triggerName);
int goSqlite3SetAuthorizer(sqlite3 *db, void *udp) {
return sqlite3_set_authorizer(db, goXAuth, udp);
}
extern int goXBusy(void *udp, int count);
int goSqlite3BusyHandler(sqlite3 *db, void *udp) {
return sqlite3_busy_handler(db, goXBusy, udp);
}
extern int goXProgress(void *udp);
void goSqlite3ProgressHandler(sqlite3 *db, int numOps, void *udp) {
sqlite3_progress_handler(db, numOps, goXProgress, udp);
}
extern void goXLog(void *udp, int err, const char *msg);
int goSqlite3ConfigLog(void *udp) {
if (udp) {
return sqlite3_config(SQLITE_CONFIG_LOG, goXLog, udp);
} else {
return sqlite3_config(SQLITE_CONFIG_LOG, NULL, NULL);
}
}
\ No newline at end of file
......@@ -8,49 +8,18 @@ package sqlite
#include <sqlite3.h>
#include <stdlib.h>
extern void goXTrace(void *udp, const char *sql);
static void goSqlite3Trace(sqlite3 *db, void *udp) {
sqlite3_trace(db, goXTrace, udp);
}
extern void goXProfile(void *udp, const char *sql, sqlite3_uint64 nanoseconds);
static void goSqlite3Profile(sqlite3 *db, void *udp) {
sqlite3_profile(db, goXProfile, udp);
}
extern int goXAuth(void *udp, int action, const char *arg1, const char *arg2, const char *dbName, const char *triggerName);
static int goSqlite3SetAuthorizer(sqlite3 *db, void *udp) {
return sqlite3_set_authorizer(db, goXAuth, udp);
}
extern int goXBusy(void *udp, int count);
static int goSqlite3BusyHandler(sqlite3 *db, void *udp) {
return sqlite3_busy_handler(db, goXBusy, udp);
}
extern int goXProgress(void *udp);
static void goSqlite3ProgressHandler(sqlite3 *db, int numOps, void *udp) {
sqlite3_progress_handler(db, numOps, goXProgress, udp);
}
void goSqlite3Trace(sqlite3 *db, void *udp);
void goSqlite3Profile(sqlite3 *db, void *udp);
int goSqlite3SetAuthorizer(sqlite3 *db, void *udp);
int goSqlite3BusyHandler(sqlite3 *db, void *udp);
void goSqlite3ProgressHandler(sqlite3 *db, int numOps, void *udp);
// cgo doesn't support varargs
static void my_log(int iErrCode, char *msg) {
sqlite3_log(iErrCode, msg);
}
extern void goXLog(void *udp, int err, const char *msg);
static int goSqlite3ConfigLog(void *udp) {
if (udp) {
return sqlite3_config(SQLITE_CONFIG_LOG, goXLog, udp);
} else {
return sqlite3_config(SQLITE_CONFIG_LOG, NULL, NULL);
}
}
int goSqlite3ConfigLog(void *udp);
*/
import "C"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment