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
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/mysql_optimizer_hints/mysql/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- name: InlineHint :one
SELECT /*+ MAX_EXECUTION_TIME(1000) */ bar FROM foo LIMIT 1;

-- name: MultilineHint :one
SELECT
/*+ MAX_EXECUTION_TIME(1000) */
bar
FROM foo
LIMIT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE foo (bar text);
12 changes: 12 additions & 0 deletions internal/endtoend/testdata/mysql_optimizer_hints/mysql/sqlc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "schema.sql",
"queries": "query.sql"
}
]
}
6 changes: 6 additions & 0 deletions internal/source/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func StripComments(sql string) (string, []string, error) {
continue
}
if strings.HasPrefix(t, "/*") && strings.HasSuffix(t, "*/") {
// Preserve MySQL optimizer hints, which share block-comment
// syntax but are semantically part of the query.
if strings.HasPrefix(t, "/*+") {
lines = append(lines, t)
continue
}
t = strings.TrimPrefix(t, "/*")
t = strings.TrimSuffix(t, "*/")
comments = append(comments, t)
Expand Down
Loading