PHPStorm: How do I create an inspection to search for a specific string in SQL?

Answered

I have a series of migration files in SQL that I would like to ensure do not get a development database name.  

How can I set up an inspection for "some_database_name" in all SQL files?

I built an inspection with a Search Template, but I couldn't just put in `$_1$` alone.  I put it with a suffix of `.` and it alerts on every single `.` in my SQL.

Ideally, I'd like to be able to have it highlight/red underline the entire database name anytime it is found in an SQL file.

14 comments
Comment actions Permalink

Edit -> Find -> Search Structurally, add something like this:

Then press on Wrench icon and choose 'Save template as Inspection.

But unfortunately this does not work at the moment, we expected to fix it in v.2021.1.1

0
Comment actions Permalink

This appears to be specific to DataGrip (which is helpful for me too), but doesn't work in PHPStorm? 

At least, I get an error "The specified pattern is malformed"

Or is that what you mean by "does not work in the moment"?

0
Comment actions Permalink

This is available only in EAP v.202, for PS too.

1
Comment actions Permalink

I just installed PHPStorm 2021.1.1 and it this inspection doesn't seem to work yet. It also doesn't work in the latest released DataGrip 2021.1.  Has this fixed been pushed to a future version?

0
Comment actions Permalink

Yes, it's planned for the next version

0
Comment actions Permalink

Yuriy Vinogradov
I have PHPStorm v2021.2.2 and it does not yet have a fix for this.

Can you please advise which version I can expect to see it in?

0
Comment actions Permalink

I should not that it DOES work correctly in DataGrip whereas it did not before.

0
Comment actions Permalink

In PS 2021.3 looks good:

0
Comment actions Permalink

Yuriy Vinogradov

Still not working for me in 2021.3:

Steps to reproduce:
Edit > Find > Search Structurally
Choose File Type SQL
Enter `$db$` 
See Red Underline under $db$

Not sure what else to do.  This does work correctly in DataGrip for me.

0
Comment actions Permalink

Rex Schrader

That must be a project-specific issue. If I open the same project in PS & DB - I would get the same syntax error reported:

vs

I would suggest submitting this to our tracker at https://youtrack.jetbrains.com/newIssue to investigate in details.

0
Comment actions Permalink

Dmitry Tronin - I used to experience the issue in DataGrip, but it was indeed fixed/implemented back in DG 2021.2 (or so).  It seemed that this fix was due to be pushed out to PHPStorm, but it has not.

I created a new, blank project in PHPStorm and the issue is still present. I'll open an issue.

0
Comment actions Permalink

Interesting:
This WAS working in DataGrip, but I just opened my inspections and it is now failing in the same way:

This is DataGrip 2021.3.1

0
Comment actions Permalink

Could you please check if this is reproducible in a new project? If it is - could you please share files to reproduce this?

0
Comment actions Permalink

As I mentioned in my message, I created a new, blank project (no files at all) in PHPStorm and was able to reproduce this problem.

Steps to reproduce:

  1. Create a new, blank project (File->New Project)
  2. Edit->Find->Search Structurally
  3. Select 'SQL' File Type
  4. Enter `$db$` into the search template
  5. See the Error:
0

Please sign in to leave a comment.