Closed shaunco closed 2 months ago
I'm not sure what functionality you're unable to express. AFAIK findBindName
should be equivalent to (untested):
func myFindBindName(stmt *sqlite.Stmt, name string) (int, bool) {
for i, n := 1, stmt.BindParamCount(); i <= n; i++ {
if stmt.BindParamName(i) == name {
return i, true
}
}
return 0, false
}
FWIW, sqlitex
does roughly the same thing, so this is definitely possible without any additional API: https://github.com/zombiezen/go-sqlite/blob/e4d0fa1c279a2a6ae900c9695bb2527b3391a1b7/sqlitex/exec.go#L343-L359
Sure, I can reimplement the findBindName
code on my own, but it seemed more forward compatible to just expose the function in case you decide to optimize it to a map lookup or something else in the future.
Understood. If the implementation changes dramatically, I'll keep that in mind. For now, I'm going to close this because the public API as it exists now seems sufficient.
Stmt.ColumnIndex
is public, butStmt.findBindName
is private. When writing generic helper functions, like one that serializes a protobuf object to/from a BLOB column/field, it is nice to be able to mimic theSet/Bind
andGet/Column
pattern thatStmt
already uses, but it is currently not possible on theSet
functions without duplicating all the code in myBind
since there isn't a publicfindBindName
I can call.