go-sqlmock icon indicating copy to clipboard operation
go-sqlmock copied to clipboard

Invalid regex not reported as so

Open nazneen84 opened this issue 6 years ago • 2 comments
trafficstars

I tried a nested query. Instead of letting me know the regex is not valid or pointing out differences in the string literal versus the regex pattern, it said query not expected and unable to match actual versus expected query respectively.

Please clarify the regex was invalid in the panic message or a compile time warning please.

Stack overflow question here: https://stackoverflow.com/questions/58142191/call-to-query-with-args-was-not-expected-in-go-sqlmock-for-compound-sql-quer/58160875#58160875.

Example of working query:

sqlMock.ExpectQuery("SELECT EXISTS \\( SELECT 1 FROM information_schema\\.tables WHERE table_schema = 'public' AND table_name = 'myTable3' \\);").
        WillReturnRows(existsRows)

Example of Invalid query unable to match:

sqlMock.ExpectQuery("SELECT EXISTS ( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'myTable3' );").
        WillReturnRows(existsRows)

Example of invalid regex query skipped in evaulation:

sqlMock.ExpectQuery("SELECT EXISTS \\( SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'myTable3' \\);").
        WillReturnRows(existsRows)

nazneen84 avatar Sep 30 '19 22:09 nazneen84

Hi, probably should follow as an improvement to #158 in order to tell whether sql was not matched

l3pp4rd avatar Oct 01 '19 06:10 l3pp4rd