Commit d956d9c8 authored by gwenn's avatar gwenn

Misc

parent 5b36b980
...@@ -27,8 +27,8 @@ static inline void cXFinal(sqlite3_context *ctx) { ...@@ -27,8 +27,8 @@ static inline void cXFinal(sqlite3_context *ctx) {
} }
int goSqlite3CreateScalarFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) { 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); return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, cXFunc, 0, 0, goXDestroy);
} }
int goSqlite3CreateAggregateFunction(sqlite3 *db, const char *zFunctionName, int nArg, int eTextRep, void *pApp) { 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); return sqlite3_create_function_v2(db, zFunctionName, nArg, eTextRep, pApp, 0, cXStep, cXFinal, goXDestroy);
} }
...@@ -242,8 +242,10 @@ func (cc *CompletionCache) init() error { ...@@ -242,8 +242,10 @@ func (cc *CompletionCache) init() error {
{Name: ".databases", Args: ""}, {Name: ".databases", Args: ""},
{Name: ".dump", Args: "?TABLE? ..."}, {Name: ".dump", Args: "?TABLE? ..."},
{Name: ".echo", Args: "ON|OFF"}, {Name: ".echo", Args: "ON|OFF"},
{Name: ".eqp", Args: "ON|OFF"},
{Name: ".exit", Args: ""}, {Name: ".exit", Args: ""},
{Name: ".explain", Args: "?ON|OFF?"}, {Name: ".explain", Args: "?ON|OFF?"},
{Name: ".fullschema", Args: ""},
//{Name: ".header", Args: "ON|OFF"}, //{Name: ".header", Args: "ON|OFF"},
{Name: ".headers", Args: "ON|OFF"}, {Name: ".headers", Args: "ON|OFF"},
{Name: ".help", Args: ""}, {Name: ".help", Args: ""},
...@@ -262,15 +264,17 @@ func (cc *CompletionCache) init() error { ...@@ -262,15 +264,17 @@ func (cc *CompletionCache) init() error {
{Name: ".restore", Args: "?DB? FILE"}, {Name: ".restore", Args: "?DB? FILE"},
{Name: ".save", Args: "FILE"}, {Name: ".save", Args: "FILE"},
{Name: ".schema", Args: "?TABLE?"}, {Name: ".schema", Args: "?TABLE?"},
{Name: ".separator", Args: "STRING"}, {Name: ".separator", Args: "STRING ?NL?"},
{Name: ".shell", Args: "CMD ARGS..."},
{Name: ".show", Args: ""}, {Name: ".show", Args: ""},
{Name: ".stats", Args: "ON|OFF"}, {Name: ".stats", Args: "ON|OFF"},
{Name: ".system", Args: "CMD ARGS..."},
{Name: ".tables", Args: "?TABLE?"}, {Name: ".tables", Args: "?TABLE?"},
{Name: ".timeout", Args: "MS"}, {Name: ".timeout", Args: "MS"},
{Name: ".timer", Args: "ON|OFF"},
{Name: ".trace", Args: "FILE|off"}, {Name: ".trace", Args: "FILE|off"},
{Name: ".vfsname", Args: "?AUX?"}, {Name: ".vfsname", Args: "?AUX?"},
{Name: ".width", Args: "NUM1 NUM2 ..."}, {Name: ".width", Args: "NUM1 NUM2 ..."},
{Name: ".timer", Args: "ON|OFF"},
} }
for _, cmd := range cmds { for _, cmd := range cmds {
if err = s.Exec(cmd.Name, cmd.Args); err != nil { if err = s.Exec(cmd.Name, cmd.Args); err != nil {
......
...@@ -473,7 +473,8 @@ func (c *Conn) BeginTransaction(t TransactionType) error { ...@@ -473,7 +473,8 @@ func (c *Conn) BeginTransaction(t TransactionType) error {
panic(fmt.Sprintf("Unsupported transaction type: '%#v'", t)) panic(fmt.Sprintf("Unsupported transaction type: '%#v'", t))
} }
// Commit commits transaction // Commit commits transaction.
// It is strongly discouraged to defer Commit without checking the error returned.
func (c *Conn) Commit() error { func (c *Conn) Commit() error {
return c.FastExec("COMMIT") return c.FastExec("COMMIT")
} }
...@@ -563,10 +564,10 @@ func (c *Conn) exec(cmd string) error { ...@@ -563,10 +564,10 @@ func (c *Conn) exec(cmd string) error {
*/ */
// FastExec executes one or many non-parameterized statement(s) (separated by semi-colon) with no control and no stmt cache. // FastExec executes one or many non-parameterized statement(s) (separated by semi-colon) with no control and no stmt cache.
func (c *Conn) FastExec(cmd string) error { func (c *Conn) FastExec(sql string) error {
cmdstr := C.CString(cmd) sqlstr := C.CString(sql)
defer C.free(unsafe.Pointer(cmdstr)) defer C.free(unsafe.Pointer(sqlstr))
return c.error(C.sqlite3_exec(c.db, cmdstr, nil, nil, nil)) return c.error(C.sqlite3_exec(c.db, sqlstr, nil, nil, nil))
} }
// Close closes a database connection and any dangling statements. // Close closes a database connection and any dangling statements.
......
...@@ -17,11 +17,11 @@ package sqlite ...@@ -17,11 +17,11 @@ package sqlite
// #define SQLITE_STATIC ((sqlite3_destructor_type)0) // #define SQLITE_STATIC ((sqlite3_destructor_type)0)
// #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1) // #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
static inline int my_bind_text(sqlite3_stmt *stmt, int n, const char *p, int np) { static inline int my_bind_text(sqlite3_stmt *stmt, int pidx, const char *data, int data_len) {
return sqlite3_bind_text(stmt, n, p, np, SQLITE_TRANSIENT); return sqlite3_bind_text(stmt, pidx, data, data_len, SQLITE_TRANSIENT);
} }
static inline int my_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) { static inline int my_bind_blob(sqlite3_stmt *stmt, int pidx, void *data, int data_len) {
return sqlite3_bind_blob(stmt, n, p, np, SQLITE_TRANSIENT); return sqlite3_bind_blob(stmt, pidx, data, data_len, SQLITE_TRANSIENT);
} }
*/ */
import "C" import "C"
...@@ -89,18 +89,18 @@ type Stmt struct { ...@@ -89,18 +89,18 @@ type Stmt struct {
Cacheable bool Cacheable bool
} }
func (c *Conn) prepare(cmd string, args ...interface{}) (*Stmt, error) { func (c *Conn) prepare(sql string, args ...interface{}) (*Stmt, error) {
if c == nil { if c == nil {
return nil, errors.New("nil sqlite database") return nil, errors.New("nil sqlite database")
} }
cmdstr := C.CString(cmd) sqlstr := C.CString(sql)
defer C.free(unsafe.Pointer(cmdstr)) defer C.free(unsafe.Pointer(sqlstr))
var stmt *C.sqlite3_stmt var stmt *C.sqlite3_stmt
var tail *C.char var tail *C.char
// If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string. // If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string.
rv := C.sqlite3_prepare_v2(c.db, cmdstr, C.int(len(cmd)+1), &stmt, &tail) rv := C.sqlite3_prepare_v2(c.db, sqlstr, C.int(len(sql)+1), &stmt, &tail)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return nil, c.error(rv, cmd) return nil, c.error(rv, sql)
} }
var t string var t string
if tail != nil && C.strlen(tail) > 0 { if tail != nil && C.strlen(tail) > 0 {
...@@ -120,8 +120,8 @@ func (c *Conn) prepare(cmd string, args ...interface{}) (*Stmt, error) { ...@@ -120,8 +120,8 @@ func (c *Conn) prepare(cmd string, args ...interface{}) (*Stmt, error) {
// Prepare first looks in the statement cache or compiles the SQL statement. // Prepare first looks in the statement cache or compiles the SQL statement.
// And optionally bind values. // And optionally bind values.
// (See sqlite3_prepare_v2: http://sqlite.org/c3ref/prepare.html) // (See sqlite3_prepare_v2: http://sqlite.org/c3ref/prepare.html)
func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) { func (c *Conn) Prepare(sql string, args ...interface{}) (*Stmt, error) {
s := c.stmtCache.find(cmd) s := c.stmtCache.find(sql)
if s != nil { if s != nil {
if len(args) > 0 { if len(args) > 0 {
err := s.Bind(args...) err := s.Bind(args...)
...@@ -132,7 +132,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) { ...@@ -132,7 +132,7 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) {
} }
return s, nil return s, nil
} }
s, err := c.prepare(cmd, args...) s, err := c.prepare(sql, args...)
if s != nil && s.stmt != nil { if s != nil && s.stmt != nil {
s.Cacheable = true s.Cacheable = true
} }
...@@ -280,10 +280,10 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) { ...@@ -280,10 +280,10 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) {
// Returns "" if the index is out of range or if the wildcard is unnamed. // Returns "" if the index is out of range or if the wildcard is unnamed.
// The first host parameter has an index of 1, not 0. // The first host parameter has an index of 1, not 0.
// (See http://sqlite.org/c3ref/bind_parameter_name.html) // (See http://sqlite.org/c3ref/bind_parameter_name.html)
func (s *Stmt) BindParameterName(i int) (string, error) { func (s *Stmt) BindParameterName(index int) (string, error) {
name := C.sqlite3_bind_parameter_name(s.stmt, C.int(i)) name := C.sqlite3_bind_parameter_name(s.stmt, C.int(index))
if name == nil { if name == nil {
return "", s.specificError("invalid parameter index: %d", i) return "", s.specificError("invalid parameter index: %d", index)
} }
return C.GoString(name), nil return C.GoString(name), nil
} }
......
...@@ -42,6 +42,6 @@ int goSqlite3ConfigLog(void *udp) { ...@@ -42,6 +42,6 @@ int goSqlite3ConfigLog(void *udp) {
if (udp) { if (udp) {
return sqlite3_config(SQLITE_CONFIG_LOG, goXLog, udp); return sqlite3_config(SQLITE_CONFIG_LOG, goXLog, udp);
} else { } else {
return sqlite3_config(SQLITE_CONFIG_LOG, NULL, NULL); return sqlite3_config(SQLITE_CONFIG_LOG, 0, 0);
} }
} }
...@@ -27,7 +27,7 @@ static int cXInit(sqlite3 *db, void *pAux, int argc, const char *const*argv, sql ...@@ -27,7 +27,7 @@ static int cXInit(sqlite3 *db, void *pAux, int argc, const char *const*argv, sql
pvTab->vTab = vTab; pvTab->vTab = vTab;
*ppVTab = (sqlite3_vtab *)pvTab; *ppVTab = (sqlite3_vtab *)pvTab;
*pzErr = NULL; *pzErr = 0;
return SQLITE_OK; return SQLITE_OK;
} }
......
...@@ -287,7 +287,7 @@ o |- int (*xRelease)(sqlite3_vtab *pVTab, int ...@@ -287,7 +287,7 @@ o |- int (*xRelease)(sqlite3_vtab *pVTab, int
o \- int (*xRollbackTo)(sqlite3_vtab *pVTab, int) o \- int (*xRollbackTo)(sqlite3_vtab *pVTab, int)
} }
int sqlite3_declare_vtab( (Called in xCreate/xConnect) DeclareVTab int sqlite3_declare_vtab( (Called in xCreate/xConnect)
|- sqlite3 *db, |- sqlite3 *db,
\- const char *zCreateTable \- const char *zCreateTable
) )
...@@ -299,7 +299,7 @@ sqliteVTab sqlite3_vtab { (Created by xCreate/xConnect) ...@@ -299,7 +299,7 @@ sqliteVTab sqlite3_vtab { (Created by xCreate/xConnect)
\- ... \- ...
} }
? sqlite3_vtab_cursor { (Created by xOpen) sqliteVTabCursor sqlite3_vtab_cursor { (Created by xOpen)
|- sqlite3_vtab *pVtab |- sqlite3_vtab *pVtab
\- ... \- ...
} }
......
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