is there a way (other than ugly and error-prone String conversion and manipulation) to determine whether two Statments or two Expressions are "essentially the same", i.e. a method that returns true when applied to two Statements obtained from parsing the Strings
"select foo from bar"
and
"select foo from bar"
,
but returns false|/b] when applied to the Statements obtained from
"select foo from bar"
and
"select bar from foo"
**?
I would assume that the visitor pattern is not suitable for that kind of functionality, right?
So how else would you do this?
Regards,
Jens
**
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just ran an example where I parsed "select foo from bar", then did a toString() on the resulting Statement, and it normalized it to "SELECT foo FROM bar", that is one option. Then, if you wanted to collapse queries that have different literals, such as "select foo from bar where abcd = 'xyz'", you could walk the statement looking for StringValues, and replace them with question marks (JdbcParameters). If you have a lot of varying IN clauses, you can do a similar technique, and replace many ? down to 1 ?.
cheers,
brian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
is there a way (other than ugly and error-prone String conversion and manipulation) to determine whether two Statments or two Expressions are "essentially the same", i.e. a method that returns true when applied to two Statements obtained from parsing the Strings
and
,
but returns false|/b] when applied to the Statements obtained from
and
**?
I would assume that the visitor pattern is not suitable for that kind of functionality, right?
So how else would you do this?
Regards,
Jens
**
I just ran an example where I parsed "select foo from bar", then did a toString() on the resulting Statement, and it normalized it to "SELECT foo FROM bar", that is one option. Then, if you wanted to collapse queries that have different literals, such as "select foo from bar where abcd = 'xyz'", you could walk the statement looking for StringValues, and replace them with question marks (JdbcParameters). If you have a lot of varying IN clauses, you can do a similar technique, and replace many ? down to 1 ?.
cheers,
brian