Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cgosqlite/cgosqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ func (stmt *Stmt) BindParameterIndexSearch(name string) int {
if i := stmt.BindParameterIndex("@" + name); i > 0 {
return i
}
if i := stmt.BindParameterIndex("$" + name); i > 0 {
return i
}
return stmt.BindParameterIndex("?" + name)
}

Expand Down
39 changes: 39 additions & 0 deletions cgosqlite/cgosqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ import (
"github.com/tailscale/sqlite/sqliteh"
)

func TestBindParameterIndexSearch(t *testing.T) {
db, err := Open(filepath.Join(t.TempDir(), "test.db"), sqliteh.OpenFlagsDefault, "")
if err != nil {
t.Fatal(err)
}
defer db.Close()

tests := []struct {
name string
query string
param string
wantOK bool
}{
{"colon", "SELECT :foo", "foo", true},
{"at_sybol", "SELECT @foo", "foo", true},
{"dollar", "SELECT $foo", "foo", true},
{"question", "SELECT ?123", "123", true},
{"not_found", "SELECT :bar", "foo", false},
{"dollar_multiple_params", "SELECT $a, $b, $c", "b", true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stmt, _, err := db.Prepare(tt.query, 0)
if err != nil {
t.Fatalf("Prepare %q: %v", tt.query, err)
}
defer stmt.Finalize()

idx := stmt.BindParameterIndexSearch(tt.param)
gotOK := idx > 0
if gotOK != tt.wantOK {
t.Errorf("BindParameterIndexSearch(%q) = %d, wantOK=%v gotOK=%v",
tt.param, idx, tt.wantOK, gotOK)
}
})
}
}

func TestColumnBlob(t *testing.T) {
// Run the test with and without the SetAlwaysCopyBlob flag enabled.
cases := []struct {
Expand Down
Loading