package store import "testing" func TestSQLiteKeepsItsPlaceholders(t *testing.T) { q := "SELECT a FROM t WHERE b = ? AND c = ?" if got := SQLiteDialect.rebind(q); got != q { t.Errorf("sqlite query was rewritten: %s", got) } } func TestPostgresGetsNumberedPlaceholders(t *testing.T) { got := PostgresDialect.rebind("SELECT a FROM t WHERE b = ? AND c = ?") want := "SELECT a FROM t WHERE b = $1 AND c = $2" if got != want { t.Errorf("rebind = %q, want %q", got, want) } } func TestAQuestionMarkInsideALiteralIsLeftAlone(t *testing.T) { // No query here contains one today. This exists so that adding one is a // test failure rather than a query that silently reads the wrong argument // — or, worse, one that still parses and returns the wrong rows. got := PostgresDialect.rebind(`SELECT a FROM t WHERE name = 'why?' AND b = ?`) want := `SELECT a FROM t WHERE name = 'why?' AND b = $1` if got != want { t.Errorf("rebind = %q, want %q", got, want) } } func TestDoubleQuotedIdentifiersAreAlsoSkipped(t *testing.T) { got := PostgresDialect.rebind(`SELECT "odd?name" FROM t WHERE b = ?`) want := `SELECT "odd?name" FROM t WHERE b = $1` if got != want { t.Errorf("rebind = %q, want %q", got, want) } } func TestAQueryWithNoPlaceholdersIsUntouched(t *testing.T) { q := "DELETE FROM t" if got := PostgresDialect.rebind(q); got != q { t.Errorf("rebind = %q", got) } }