aboutsummaryrefslogtreecommitdiff
path: root/sqlite3.go
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2013-09-09 10:44:44 +0900
committermattn <mattn.jp@gmail.com>2013-09-09 10:44:44 +0900
commitd4673cd31cac7742ce1735defa74d63090ac3401 (patch)
tree3da80a8ee6040c2ca063888718662834ad33e1fe /sqlite3.go
parentRemove old information (diff)
downloadgolite-d4673cd31cac7742ce1735defa74d63090ac3401.tar.gz
golite-d4673cd31cac7742ce1735defa74d63090ac3401.tar.xz
Implements Execer
Diffstat (limited to 'sqlite3.go')
-rw-r--r--sqlite3.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 4ac45e1..3d77f06 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -129,10 +129,36 @@ func (tx *SQLiteTx) Rollback() error {
return nil
}
+// AutoCommit return which currently auto commit or not.
func (c *SQLiteConn) AutoCommit() bool {
return int(C.sqlite3_get_autocommit(c.db)) != 0
}
+// Implements Execer
+func (c *SQLiteConn) Exec(query string, args []driver.Value) (driver.Result, error) {
+ for {
+ println(query)
+ ds, err := c.Prepare(query)
+ if err != nil {
+ println("FOO1")
+ return nil, err
+ }
+ s := ds.(*SQLiteStmt)
+ na := s.NumInput()
+ res, err := s.Exec(args[:na])
+ args = args[na:]
+ s.Close()
+ if err != nil {
+ return nil, err
+ }
+ if s.t == "" {
+ return res, nil
+ }
+ s.Close()
+ query = s.t
+ }
+}
+
func (c *SQLiteConn) exec(cmd string) error {
pcmd := C.CString(cmd)
defer C.free(unsafe.Pointer(pcmd))
@@ -244,14 +270,14 @@ func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
pquery := C.CString(query)
defer C.free(unsafe.Pointer(pquery))
var s *C.sqlite3_stmt
- var perror *C.char
- rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &perror)
+ var tail *C.char
+ rv := C.sqlite3_prepare_v2(c.db, pquery, -1, &s, &tail)
if rv != C.SQLITE_OK {
return nil, ErrNo(rv)
}
var t string
- if perror != nil && C.strlen(perror) > 0 {
- t = C.GoString(perror)
+ if tail != nil && C.strlen(tail) > 0 {
+ t = strings.TrimSpace(C.GoString(tail))
}
return &SQLiteStmt{c: c, s: s, t: t}, nil
}