GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — SQLite: parameter in LIKE ... ESCAPE ? is dropped from generated code · Issue #4668 · sqlc-dev/sqlc Open Labels bugSomething isn't workingSomething isn't working DescriptionVersion1.31.1 What happened?When the ESCAPE clause of a LIKE expression is a parameter, sqlc leaves that parameter out of the generated Go method. The SQL constant still includes all placeholders, but the method passes one fewer argument, so the query either fails at runtime or quietly returns incorrect results. For example: -- name: SearchName :many generates: func (q *Queries) SearchName(ctx context.Context, name string) ([]int64, error) { This happens with every parameter style:
A literal escape (ESCAPE '') works correctly. I ran the generated code against github.com/ncruces/go-sqlite3 v0.35.6. The table held the rows '100%' and '100 apples', and each call searched for the prefix 100% using ! as the escape character: SearchName: ids=[] err=sql: expected 2 arguments, got 1 Expected: each method takes and passes the escape character as a string parameter. For example, SearchName(ctx, arg SearchNameParams) should pass both the pattern and the escape value. Relevant log outputsql: expected 2 arguments, got 1 Database schemaCREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT NOT NULL, score INTEGER NOT NULL, created TEXT); SQL queries-- name: SearchName :many SELECT id FROM t WHERE name LIKE ? ESCAPE ?; -- name: SearchNameNamed :many SELECT id FROM t WHERE name LIKE sqlc.arg(pattern) ESCAPE sqlc.arg(esc); -- name: SearchNameAt :many SELECT id FROM t WHERE name LIKE @pattern ESCAPE @esc; -- name: SearchEscapeOnly :many SELECT id FROM t WHERE name LIKE 'a%' ESCAPE ?; -- name: SearchLiteralEscape :many SELECT id FROM t WHERE name LIKE ? ESCAPE '\'; -- name: SearchThenWhere :many SELECT id FROM t WHERE name LIKE ? ESCAPE ? AND score > ?; Configurationversion: "2" sql: - engine: "sqlite" schema: "schema.sql" queries: "query.sql" gen: go: package: "db" out: "db" Playground URLNo response What operating system are you using?Linux What database engines are you using?SQLite What type of code are you generating?Go Activity
MetadataMetadataAssigneesLabelsbugSomething isn't workingSomething isn't working TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |