The cluster page's usage table showed session:usr-... and proj-... ids; it now shows the person's email, whether it came through a key or the chat page, and the project's path or "personal". Times read "3 hours ago" rather than "3h7m25s ago", everywhere. The usage page's legend gave each line's latest slice, which was 0 beside a table of hundreds; it gives the window's total, and the table's numbers are right-aligned like everywhere else. The PostgreSQL placeholder rewriting skips line comments. An apostrophe in one opened a string that swallowed every placeholder after it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
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)
|
|
}
|
|
}
|
|
|
|
func TestACommentDoesNotOpenAString(t *testing.T) {
|
|
// An apostrophe in a comment is not a quote. Read as one, it swallowed
|
|
// every placeholder after it.
|
|
got := PostgresDialect.rebind("SELECT a -- the key's owner\nFROM t WHERE x = ? AND y = ?")
|
|
want := "SELECT a -- the key's owner\nFROM t WHERE x = $1 AND y = $2"
|
|
if got != want {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
// A comment's own question mark is not a placeholder either.
|
|
if got := PostgresDialect.rebind("SELECT 1 -- why?\nWHERE x = ?"); got != "SELECT 1 -- why?\nWHERE x = $1" {
|
|
t.Errorf("got %q", got)
|
|
}
|
|
}
|