Skip to content

Commit ffaa9c9

Browse files
committed
Remove useless nVars and nCols checks.
1 parent b5283e5 commit ffaa9c9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

go1/sqlite3/sqlite3.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int bind_blob(sqlite3_stmt *s, int i, const void *p, int n, int copy) {
5656
}
5757
5858
// Faster retrieval of column data types (1 cgo call instead of n).
59-
static void column_types(sqlite3_stmt *s, unsigned char *p, int n) {
59+
static void column_types(sqlite3_stmt *s, unsigned char p[], int n) {
6060
int i = 0;
6161
for (; i < n; ++i, ++p) {
6262
*p = sqlite3_column_type(s, i);
@@ -541,7 +541,9 @@ func newStmt(c *Conn, sql string) (*Stmt, error) {
541541
// be useful to the caller, so s is still returned without an error.
542542
s := &Stmt{conn: c, stmt: stmt}
543543
if stmt != nil {
544-
s.nVars = int(C.sqlite3_bind_parameter_count(stmt))
544+
if s.nVars = int(C.sqlite3_bind_parameter_count(stmt)); s.nVars == 0 {
545+
s.varNames = unnamedVars
546+
}
545547
s.nCols = int(C.sqlite3_column_count(stmt))
546548
runtime.SetFinalizer(s, (*Stmt).Close)
547549
}
@@ -622,7 +624,7 @@ var unnamedVars = make([]string, 0, 1)
622624
// is returned if the statement does not use named parameters.
623625
// [http://www.sqlite.org/c3ref/bind_parameter_name.html]
624626
func (s *Stmt) Params() []string {
625-
if s.varNames == nil && s.nVars > 0 {
627+
if s.varNames == nil {
626628
var names []string
627629
for i := 0; i < s.nVars; i++ {
628630
name := C.sqlite3_bind_parameter_name(s.stmt, C.int(i+1))
@@ -638,7 +640,7 @@ func (s *Stmt) Params() []string {
638640
s.varNames = names
639641
}
640642
if len(s.varNames) == 0 {
641-
return nil
643+
return nil // unnamedVars -> nil
642644
}
643645
return s.varNames
644646
}
@@ -687,7 +689,7 @@ func (s *Stmt) DeclTypes() []string {
687689
// [http://www.sqlite.org/c3ref/column_blob.html]
688690
func (s *Stmt) DataTypes() []uint8 {
689691
if len(s.colTypes) == 0 {
690-
if !s.haveRow || s.nCols == 0 {
692+
if !s.haveRow {
691693
return nil
692694
}
693695
s.colType(0)

0 commit comments

Comments
 (0)