Skip to content

Commit

Permalink
Capture table names in double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Oct 14, 2024
1 parent e73b23a commit 46616da
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Patches
# Module to prepend to Mysql2::Client for instrumentation
module Client
# Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["']?([\w.]+)["']?/i
TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["]?([\w.]+)["]?/i

def query(sql, options = {})
tracer.in_span(
Expand Down
4 changes: 4 additions & 0 deletions instrumentation/mysql2/test/fixtures/sql_table_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@
{
"name": "from_with_join",
"sql": "SELECT columns FROM test_table JOIN table2 ON test_table.column = table2.column"
},
{
"name": "table_name_with_double_quotes",
"sql": "SELECT columns FROM \"test_table\""
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Patches
# Module to prepend to Trilogy for instrumentation
module Client
# Capture the first word (including letters, digits, underscores, & '.', ) that follows common table commands
TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["']?([\w.]+)["']?/i
TABLE_NAME = /\b(?:(?:FROM|INTO|UPDATE)|(?:(?:CREATE|DROP|ALTER)\s+TABLE(?:\s+IF\s+(?:NOT\s+)?EXISTS)?))\s+["]?([\w.]+)["]?/i

def initialize(options = {})
@connection_options = options # This is normally done by Trilogy#initialize
Expand Down
4 changes: 4 additions & 0 deletions instrumentation/trilogy/test/fixtures/sql_table_name.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@
{
"name": "from_with_join",
"sql": "SELECT columns FROM test_table JOIN table2 ON test_table.column = table2.column"
},
{
"name": "table_name_with_double_quotes",
"sql": "SELECT columns FROM \"test_table\""
}
]

0 comments on commit 46616da

Please sign in to comment.