Skip to content

Commit 0c35ea2

Browse files
authored
Merge pull request #29 from mattn/master
Merge upstream
2 parents 3bf5982 + 3c0390b commit 0c35ea2

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

sqlite3.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,16 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []driver.Named
881881
// consume the number of arguments used in the current
882882
// statement and append all named arguments not
883883
// contained therein
884-
stmtArgs = append(stmtArgs, args[start:start+na]...)
885-
for i := range args {
886-
if (i < start || i >= na) && args[i].Name != "" {
887-
stmtArgs = append(stmtArgs, args[i])
884+
if len(args[start:start+na]) > 0 {
885+
stmtArgs = append(stmtArgs, args[start:start+na]...)
886+
for i := range args {
887+
if (i < start || i >= na) && args[i].Name != "" {
888+
stmtArgs = append(stmtArgs, args[i])
889+
}
890+
}
891+
for i := range stmtArgs {
892+
stmtArgs[i].Ordinal = i + 1
888893
}
889-
}
890-
for i := range stmtArgs {
891-
stmtArgs[i].Ordinal = i + 1
892894
}
893895
res, err = s.(*SQLiteStmt).exec(ctx, stmtArgs)
894896
if err != nil && err != driver.ErrSkip {
@@ -1683,7 +1685,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
16831685
}
16841686
}
16851687

1686-
// Forgein Keys
1688+
// Foreign Keys
16871689
if foreignKeys > -1 {
16881690
if err := exec(fmt.Sprintf("PRAGMA foreign_keys = %d;", foreignKeys)); err != nil {
16891691
C.sqlite3_close_v2(db)
@@ -1912,6 +1914,7 @@ func (s *SQLiteStmt) Close() error {
19121914
if rv != C.SQLITE_OK {
19131915
return s.c.lastError()
19141916
}
1917+
s.c = nil
19151918
runtime.SetFinalizer(s, nil)
19161919
return nil
19171920
}
@@ -2017,6 +2020,7 @@ func (s *SQLiteStmt) query(ctx context.Context, args []driver.NamedValue) (drive
20172020
closed: false,
20182021
ctx: ctx,
20192022
}
2023+
runtime.SetFinalizer(rows, (*SQLiteRows).Close)
20202024

20212025
return rows, nil
20222026
}
@@ -2062,6 +2066,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []driver.NamedValue) (driver
20622066
err error
20632067
}
20642068
resultCh := make(chan result)
2069+
defer close(resultCh)
20652070
go func() {
20662071
r, err := s.execSync(args)
20672072
resultCh <- result{r, err}
@@ -2128,6 +2133,8 @@ func (rc *SQLiteRows) Close() error {
21282133
return rc.s.c.lastError()
21292134
}
21302135
rc.s.mu.Unlock()
2136+
rc.s = nil
2137+
runtime.SetFinalizer(rc, nil)
21312138
return nil
21322139
}
21332140

@@ -2174,6 +2181,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
21742181
return rc.nextSyncLocked(dest)
21752182
}
21762183
resultCh := make(chan error)
2184+
defer close(resultCh)
21772185
go func() {
21782186
resultCh <- rc.nextSyncLocked(dest)
21792187
}()

sqlite3_libsqlite3.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ package sqlite3
1818
#cgo openbsd LDFLAGS: -lsqlite3
1919
#cgo solaris LDFLAGS: -lsqlite3
2020
#cgo windows LDFLAGS: -lsqlite3
21+
#cgo zos LDFLAGS: -lsqlite3
2122
*/
2223
import "C"

sqlite3_opt_userauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var (
8686
// combination is incorrect or unknown.
8787
//
8888
// If the SQLITE_USER table is not present in the database file, then
89-
// this interface is a harmless no-op returnning SQLITE_OK.
89+
// this interface is a harmless no-op returning SQLITE_OK.
9090
func (c *SQLiteConn) Authenticate(username, password string) error {
9191
rv := c.authenticate(username, password)
9292
switch rv {

0 commit comments

Comments
 (0)