Skip to content

Commit

Permalink
Merge pull request #399 from nr-swilloughby/dbnameparse
Browse files Browse the repository at this point in the history
(fix issue #397) incorrect table name reported
  • Loading branch information
nr-swilloughby committed Oct 20, 2021
2 parents 06dc024 + 19ab2b4 commit 1483137
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions v3/newrelic/sqlparse/sqlparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var (
extractTableRegex = regexp.MustCompile(`[\s` + "`" + `"'\(\)\{\}\[\]]*`)
updateRegex = regexp.MustCompile(`(?is)^update(?:\s+(?:low_priority|ignore|or|rollback|abort|replace|fail|only))*` + tablePattern)
sqlOperations = map[string]*regexp.Regexp{
"select": regexp.MustCompile(`(?is)^.*?\sfrom` + tablePattern),
"delete": regexp.MustCompile(`(?is)^.*?\sfrom` + tablePattern),
"insert": regexp.MustCompile(`(?is)^.*?\sinto?` + tablePattern),
"select": regexp.MustCompile(`(?is)^.*\sfrom` + tablePattern),
"delete": regexp.MustCompile(`(?is)^.*\sfrom` + tablePattern),
"insert": regexp.MustCompile(`(?is)^.*\sinto?` + tablePattern),
"update": updateRegex,
"call": nil,
"create": nil,
Expand Down
4 changes: 4 additions & 0 deletions v3/newrelic/sqlparse/sqlparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestParseSQLSubQuery(t *testing.T) {
{Input: "SELECT * FROM (SELECT * FROM foobar)", Operation: "select", Table: "foobar"},
{Input: "SELECT * FROM (SELECT * FROM foobar) WHERE x > y", Operation: "select", Table: "foobar"},
{Input: "SELECT * FROM(SELECT * FROM foobar) WHERE x > y", Operation: "select", Table: "foobar"},
{Input: "SELECT substring('spam' FROM 2 FOR 3) AS x FROM FROMAGE) FROM fromagier", Operation: "select", Table: "fromagier"},
} {
tc.test(t)
}
Expand All @@ -71,6 +72,9 @@ func TestParseSQLOther(t *testing.T) {
{Input: "SELECT * FROM[ `something`.'foo' ]", Operation: "select", Table: "foo"},
// Test that we handle the cheese.
{Input: "SELECT fromage FROM fromagier", Operation: "select", Table: "fromagier"},
{Input: "SELECT (x from fromage) FROM fromagier", Operation: "select", Table: "fromagier"},
{Input: "SELECT (x FROM FROMAGE) FROM fromagier", Operation: "select", Table: "fromagier"},
{Input: "SELECT substring('spam' FROM 2 FOR 3) AS x FROM FROMAGE) FROM fromagier", Operation: "select", Table: "fromagier"},
} {
tc.test(t)
}
Expand Down

0 comments on commit 1483137

Please sign in to comment.