mirror of https://github.com/mattn/go-sqlite3.git
close channel
This commit is contained in:
parent
4702d9b5d6
commit
6ee3e6746e
22
sqlite3.go
22
sqlite3.go
|
@ -875,14 +875,16 @@ func (c *SQLiteConn) exec(ctx context.Context, query string, args []driver.Named
|
||||||
// consume the number of arguments used in the current
|
// consume the number of arguments used in the current
|
||||||
// statement and append all named arguments not
|
// statement and append all named arguments not
|
||||||
// contained therein
|
// contained therein
|
||||||
stmtArgs = append(stmtArgs, args[start:start+na]...)
|
if len(args[start:start+na]) > 0 {
|
||||||
for i := range args {
|
stmtArgs = append(stmtArgs, args[start:start+na]...)
|
||||||
if (i < start || i >= na) && args[i].Name != "" {
|
for i := range args {
|
||||||
stmtArgs = append(stmtArgs, args[i])
|
if (i < start || i >= na) && args[i].Name != "" {
|
||||||
|
stmtArgs = append(stmtArgs, args[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range stmtArgs {
|
||||||
|
stmtArgs[i].Ordinal = i + 1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for i := range stmtArgs {
|
|
||||||
stmtArgs[i].Ordinal = i + 1
|
|
||||||
}
|
}
|
||||||
res, err = s.(*SQLiteStmt).exec(ctx, stmtArgs)
|
res, err = s.(*SQLiteStmt).exec(ctx, stmtArgs)
|
||||||
if err != nil && err != driver.ErrSkip {
|
if err != nil && err != driver.ErrSkip {
|
||||||
|
@ -1906,6 +1908,7 @@ func (s *SQLiteStmt) Close() error {
|
||||||
if rv != C.SQLITE_OK {
|
if rv != C.SQLITE_OK {
|
||||||
return s.c.lastError()
|
return s.c.lastError()
|
||||||
}
|
}
|
||||||
|
s.c = nil
|
||||||
runtime.SetFinalizer(s, nil)
|
runtime.SetFinalizer(s, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -2011,6 +2014,7 @@ func (s *SQLiteStmt) query(ctx context.Context, args []driver.NamedValue) (drive
|
||||||
closed: false,
|
closed: false,
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(rows, (*SQLiteRows).Close)
|
||||||
|
|
||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
@ -2056,6 +2060,7 @@ func (s *SQLiteStmt) exec(ctx context.Context, args []driver.NamedValue) (driver
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
resultCh := make(chan result)
|
resultCh := make(chan result)
|
||||||
|
defer close(resultCh)
|
||||||
go func() {
|
go func() {
|
||||||
r, err := s.execSync(args)
|
r, err := s.execSync(args)
|
||||||
resultCh <- result{r, err}
|
resultCh <- result{r, err}
|
||||||
|
@ -2122,6 +2127,8 @@ func (rc *SQLiteRows) Close() error {
|
||||||
return rc.s.c.lastError()
|
return rc.s.c.lastError()
|
||||||
}
|
}
|
||||||
rc.s.mu.Unlock()
|
rc.s.mu.Unlock()
|
||||||
|
rc.s = nil
|
||||||
|
runtime.SetFinalizer(rc, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2168,6 +2175,7 @@ func (rc *SQLiteRows) Next(dest []driver.Value) error {
|
||||||
return rc.nextSyncLocked(dest)
|
return rc.nextSyncLocked(dest)
|
||||||
}
|
}
|
||||||
resultCh := make(chan error)
|
resultCh := make(chan error)
|
||||||
|
defer close(resultCh)
|
||||||
go func() {
|
go func() {
|
||||||
resultCh <- rc.nextSyncLocked(dest)
|
resultCh <- rc.nextSyncLocked(dest)
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue