csv
Yasuhiro Matsumoto 2016-11-06 20:43:53 +09:00
parent 15491aeb9c
commit 605d9d0851
1 changed files with 25 additions and 1 deletions

View File

@ -190,6 +190,7 @@ type SQLiteRows struct {
cols []string
decltype []string
cls bool
done chan struct{}
}
type functionInfo struct {
@ -766,7 +767,26 @@ func (s *SQLiteStmt) query(ctx context.Context, args []namedValue) (driver.Rows,
if err := s.bind(args); err != nil {
return nil, err
}
return &SQLiteRows{s, int(C.sqlite3_column_count(s.s)), nil, nil, s.cls}, nil
rows := &SQLiteRows{
s: s,
nc: int(C.sqlite3_column_count(s.s)),
cols: nil,
decltype: nil,
cls: s.cls,
done: make(chan struct{}),
}
go func() {
select {
case <-ctx.Done():
C.sqlite3_interrupt(s.c.db)
rows.Close()
case <-rows.done:
}
}()
return rows, nil
}
// LastInsertId teturn last inserted ID.
@ -813,6 +833,10 @@ func (rc *SQLiteRows) Close() error {
if rc.s.closed {
return nil
}
if rc.done != nil {
close(rc.done)
rc.done = nil
}
if rc.cls {
return rc.s.Close()
}