handle properly 0 rows query results, fixes #28

This commit is contained in:
Jan Mercl
2020-09-21 18:36:03 +02:00
parent a6843eee0f
commit a4318db8c7
2 changed files with 39 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ var (
//lint:ignore SA1019 TODO implement QueryerContext
_ driver.Queryer = (*conn)(nil)
_ driver.Result = (*result)(nil)
_ driver.Rows = noRows{}
_ driver.Rows = (*rows)(nil)
_ driver.Stmt = (*stmt)(nil)
_ driver.Tx = (*tx)(nil)
@@ -496,6 +497,11 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
pstmt = 0
return nil
case sqlite3.SQLITE_DONE:
if r == nil {
pstmt = 0
r = noRows{}
return nil
}
// nop
default:
return s.c.errstr(int32(rc))
@@ -516,6 +522,12 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
return r, err
}
type noRows struct{}
func (noRows) Columns() []string { return nil }
func (noRows) Close() error { return nil }
func (noRows) Next([]driver.Value) error { return sql.ErrNoRows }
type tx struct {
c *conn
}