Skip to content

Commit

Permalink
Add SQL test cases for prepended comments
Browse files Browse the repository at this point in the history
The prepended comments used in these tests are drawn from Active
Record Query Logs/Marginalia-style comments. This is also known
as sqlcommenter in other languages.
  • Loading branch information
kaylareopelle committed Jan 30, 2024
1 parent b1d5f86 commit c7e3d8b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -674,5 +674,35 @@
"cassandra",
"mssql"
]
},
{
"name": "prepended_comments_with_quotes.postgres",
"sql": "/*application:Demo,controller:posts,action:update*/ UPDATE \"posts\" SET \"updated_at\" = '2023-11-01 19:02:34.795909' WHERE \"posts\".\"id\" = 3",
"obfuscated": [
"? UPDATE \"posts\" SET \"updated_at\" = ? WHERE \"posts\".\"id\" = ?"
],
"dialects": [
"postgres"
]
},
{
"name": "prepended_comments_with_quotes.mysql",
"sql": "/*action='show',application='TrilogyTest',controller='users'*/ SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1",
"obfuscated": [
"? SELECT `users`.* FROM `users` WHERE `users`.`id` = ? LIMIT ?"
],
"dialects": [
"mysql"
]
},
{
"name": "prepended_multiline_comments_with_quotes.mysql",
"sql": "/*action='show',\napplication='TrilogyTest',controller='users'*/\nSELECT `users`.*\nFROM `users`\nWHERE `users`.`id` = 1 LIMIT 1",
"obfuscated": [
"?\nSELECT `users`.*\nFROM `users`\nWHERE `users`.`id` = ? LIMIT ?"
],
"dialects": [
"mysql"
]
}
]
3 changes: 2 additions & 1 deletion test/fixtures/cross_agent_tests/sql_parsing.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
{"input":"SELECT * /* a */ FROM alpha", "operation":"select", "table":"alpha"},
{"input":"SELECT * FROM /* a */ alpha", "operation":"select", "table":"alpha"},
{"input":"/* X */ SELECT /* Y */ foo/**/ FROM /**/alpha/**/", "operation":"select", "table":"alpha"},

{"input":"/* insert */ SELECT * FROM alpha", "operation":"select", "table":"alpha"},

{"input":"mystoredprocedure'123'", "operation":"other", "table":null},
{"input":"mystoredprocedure\t'123'", "operation":"other", "table":null},
{"input":"mystoredprocedure\r'123'", "operation":"other", "table":null},
Expand Down

0 comments on commit c7e3d8b

Please sign in to comment.