This commit is contained in:
mattn 2011-11-11 21:38:53 +09:00
parent 79234d62ef
commit 0b35f58e9d
1 changed files with 20 additions and 19 deletions

View File

@ -31,6 +31,7 @@ func init() {
} }
type SQLiteDriver struct { type SQLiteDriver struct {
} }
type SQLiteConn struct { type SQLiteConn struct {
@ -131,7 +132,7 @@ func (c *SQLiteConn) Prepare(query string) (driver.Stmt, error) {
} }
func (s *SQLiteStmt) Close() error { func (s *SQLiteStmt) Close() error {
rv := C.sqlite3_finalize(s.s); rv := C.sqlite3_finalize(s.s)
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return errors.New(C.GoString(C.sqlite3_errmsg(s.c.db))) return errors.New(C.GoString(C.sqlite3_errmsg(s.c.db)))
} }
@ -144,12 +145,12 @@ func (s *SQLiteStmt) NumInput() int {
func (s *SQLiteStmt) bind(args []interface{}) error { func (s *SQLiteStmt) bind(args []interface{}) error {
rv := C.sqlite3_reset(s.s) rv := C.sqlite3_reset(s.s)
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv!= C.SQLITE_DONE { if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
return errors.New(C.GoString(C.sqlite3_errmsg(s.c.db))) return errors.New(C.GoString(C.sqlite3_errmsg(s.c.db)))
} }
for i, v := range args { for i, v := range args {
n := C.int(i+1) n := C.int(i + 1)
switch v := v.(type) { switch v := v.(type) {
case nil: case nil:
rv = C.sqlite3_bind_null(s.s, n) rv = C.sqlite3_bind_null(s.s, n)
@ -198,7 +199,7 @@ func (s *SQLiteStmt) Exec(args []interface{}) (driver.Result, error) {
return nil, err return nil, err
} }
rv := C.sqlite3_step(s.s) rv := C.sqlite3_step(s.s)
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv!= C.SQLITE_DONE { if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
return nil, errors.New(C.GoString(C.sqlite3_errmsg(s.c.db))) return nil, errors.New(C.GoString(C.sqlite3_errmsg(s.c.db)))
} }
return driver.DDLSuccess, nil return driver.DDLSuccess, nil
@ -234,7 +235,7 @@ func (rc *SQLiteRows) Next(dest []interface{}) error {
return errors.New(C.GoString(C.sqlite3_errmsg(rc.s.c.db))) return errors.New(C.GoString(C.sqlite3_errmsg(rc.s.c.db)))
} }
for i := range dest { for i := range dest {
switch (C.sqlite3_column_type(rc.s.s, C.int(i))) { switch C.sqlite3_column_type(rc.s.s, C.int(i)) {
case C.SQLITE_INTEGER: case C.SQLITE_INTEGER:
dest[i] = int64(C.sqlite3_column_int64(rc.s.s, C.int(i))) dest[i] = int64(C.sqlite3_column_int64(rc.s.s, C.int(i)))
case C.SQLITE_FLOAT: case C.SQLITE_FLOAT: