Title: PRAGMA queries are not recognised · Issue #3237 · sqlc-dev/sqlc · GitHub
Open Graph Title: PRAGMA queries are not recognised · Issue #3237 · sqlc-dev/sqlc
X Title: PRAGMA queries are not recognised · Issue #3237 · sqlc-dev/sqlc
Description: Version 1.25.0 What happened? SQLite requires a PRAGMA query to enable foreign key constraints. Unfortunately, sqlc does not seem to recognise PRAGMA as a valid query, and actually collects everything until the first query it does recogn...
Open Graph Description: Version 1.25.0 What happened? SQLite requires a PRAGMA query to enable foreign key constraints. Unfortunately, sqlc does not seem to recognise PRAGMA as a valid query, and actually collects everyth...
X Description: Version 1.25.0 What happened? SQLite requires a PRAGMA query to enable foreign key constraints. Unfortunately, sqlc does not seem to recognise PRAGMA as a valid query, and actually collects everyth...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/3237
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PRAGMA queries are not recognised","articleBody":"### Version\r\n\r\n1.25.0\r\n\r\n### What happened?\r\n\r\nSQLite requires a `PRAGMA` query to enable foreign key constraints. Unfortunately, sqlc does not seem to recognise `PRAGMA` as a valid query, and actually collects everything until the first query it does recognise. Let me illustrate. In the `queries.sql` below, there are three named `PRAGMA` queries followed by an `INSERT`. Instead of generating four query functions, sqlc actually just creates one:\r\n\r\n```go\r\n\r\nconst pragmaForeignKeysEnable = `-- name: PragmaForeignKeysEnable :exec\r\n\r\nPRAGMA foreign_keys = 1;\r\n\r\nPRAGMA foreign_keys = 0;\r\n\r\nPRAGMA foreign_keys;\r\n\r\n\r\n\r\nINSERT INTO jobs (\r\n created_at,\r\n uuid,\r\n name,\r\n job_type,\r\n priority,\r\n status,\r\n activity,\r\n settings,\r\n metadata,\r\n storage_shaman_checkout_id\r\n)\r\nVALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )\r\n`\r\n\r\ntype PragmaForeignKeysEnableParams struct {\r\n\tCreatedAt time.Time\r\n\tUuid string\r\n\tName string\r\n\tJobType string\r\n\tPriority int64\r\n\tStatus string\r\n\tActivity string\r\n\tSettings json.RawMessage\r\n\tMetadata json.RawMessage\r\n\tStorageShamanCheckoutID sql.NullString\r\n}\r\n\r\n// PRAGMA queries\r\n//\r\n// Jobs / Tasks queries\r\nfunc (q *Queries) PragmaForeignKeysEnable(ctx context.Context, arg PragmaForeignKeysEnableParams) error {\r\n\t_, err := q.db.ExecContext(ctx, pragmaForeignKeysEnable,\r\n\t\targ.CreatedAt,\r\n\t\targ.Uuid,\r\n\t\targ.Name,\r\n\t\targ.JobType,\r\n\t\targ.Priority,\r\n\t\targ.Status,\r\n\t\targ.Activity,\r\n\t\targ.Settings,\r\n\t\targ.Metadata,\r\n\t\targ.StorageShamanCheckoutID,\r\n\t)\r\n\treturn err\r\n}\r\n```\r\n\r\nAs you can see, instead of using `-- name: ...` as query boundary, sqlc groups everything together until the `INSERT`.\r\n\r\n\r\n\r\n### Relevant log output\r\n\r\n_No response_\r\n\r\n### Database schema\r\n\r\n```sql\r\nCREATE TABLE jobs (\r\n id integer NOT NULL,\r\n created_at datetime NOT NULL,\r\n updated_at datetime,\r\n uuid varchar(36) UNIQUE DEFAULT '' NOT NULL,\r\n name varchar(64) DEFAULT '' NOT NULL,\r\n job_type varchar(32) DEFAULT '' NOT NULL,\r\n priority smallint DEFAULT 0 NOT NULL,\r\n status varchar(32) DEFAULT '' NOT NULL,\r\n activity varchar(255) DEFAULT '' NOT NULL,\r\n settings jsonb NOT NULL,\r\n metadata jsonb NOT NULL,\r\n delete_requested_at datetime,\r\n storage_shaman_checkout_id varchar(255) DEFAULT '',\r\n PRIMARY KEY (id),\r\n)\r\n```\r\n\r\n\r\n### SQL queries\r\n\r\n```sql\r\n-- PRAGMA queries\r\n--\r\n\r\n-- name: PragmaForeignKeysEnable :exec\r\nPRAGMA foreign_keys = 1;\r\n\r\n-- name: PragmaForeignKeysDisable :exec\r\nPRAGMA foreign_keys = 0;\r\n\r\n-- name: PragmaForeignKeysGet :one\r\nPRAGMA foreign_keys;\r\n\r\n\r\n-- Jobs / Tasks queries\r\n--\r\n\r\n-- name: CreateJob :exec\r\nINSERT INTO jobs (\r\n created_at,\r\n uuid,\r\n name,\r\n job_type,\r\n priority,\r\n status,\r\n activity,\r\n settings,\r\n metadata,\r\n storage_shaman_checkout_id\r\n)\r\nVALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );\r\n```\r\n\r\n\r\n### Configuration\r\n\r\n_No response_\r\n\r\n### Playground URL\r\n\r\nhttps://play.sqlc.dev/p/ce20411be4624a0295c2e51b8eb075a4e1069ac3d6951778cd6a54f032831a3c\r\n\r\n### What operating system are you using?\r\n\r\nWindows\r\n\r\n### What database engines are you using?\r\n\r\nSQLite\r\n\r\n### What type of code are you generating?\r\n\r\nGo","author":{"url":"https://github.com/sybrenstuvel","@type":"Person","name":"sybrenstuvel"},"datePublished":"2024-03-02T17:22:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/3237/sqlc/issues/3237"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5397e587-b5aa-45d6-64e5-9a65f0aeb13a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8942:1DCECA:41BD27:5E95D3:6A50F9B2 |
| html-safe-nonce | 3711e19b4e0754d77b5550296f29694ff05a35b5006c68d59fbd9196a8050c85 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTQyOjFEQ0VDQTo0MUJEMjc6NUU5NUQzOjZBNTBGOUIyIiwidmlzaXRvcl9pZCI6IjU3MDExMTEzNzI1NTg5NTY5NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | da8358a11bf17556c42c746f336ab8d11952ce8855790282bde5f93432f43ea2 |
| hovercard-subject-tag | issue:2164897591 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc/3237/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5494b5241039112f0da424f5d71c60753181b9bc7485ee2050ece4aaecdcd886/sqlc-dev/sqlc/issues/3237 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5494b5241039112f0da424f5d71c60753181b9bc7485ee2050ece4aaecdcd886/sqlc-dev/sqlc/issues/3237 |
| og:image:alt | Version 1.25.0 What happened? SQLite requires a PRAGMA query to enable foreign key constraints. Unfortunately, sqlc does not seem to recognise PRAGMA as a valid query, and actually collects everyth... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sybrenstuvel |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8d836581d020676cc0ef4a83cd2fe17e4af02c3d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width