Using advance database completion on tables with a prefix possible?

Hi Guys,

First of all well done on the excellent work that has been the result PHPStorm 6, it is truly truly an amazing release. I wanted to know if the following is possible, say I have the following table:

    protected $sql = "
          SELECT
               user_id, user_display_name, user_name, user_email, user_role, date_registered,
               user_role_name
             FROM
               _db_core_users t1
          LEFT JOIN
                  _db_core_user_roles t2
          ON
               t1.user_role = t2.user_role_id
    ";


It is all well and good, the problem is even though PHPStorms connects fine with the database, it cant find it with error "unable to resolve table", the reason this happens is because _db_ is a general prefix to the tables and the code actually converts _db_ to a stored prefix value, in this case the real table is for instance "pds_core_users" and  "_db_core_user_roles".

Is there a way to tell PHPStorm that _db_ is a prefix to pds_ ?

Thanks in advance for any reply.

7 comments
Comment actions Permalink

Hi Jason,

Is there a way to tell PHPStorm that _db_ is a prefix to pds_ ?

AFAIK  -- No.

You may want to use "Keywords only" SQL Dialect (instead of specific one -- "Settings | SQL Dialects").. or disable such additional inspection (which verified against actual DB -- Settings | Inspections | SQL). It may also be possible to suppress this inspection not globally, but for that line only (have not tried this myself recently) -- try Alt+Enter on error and proceed from there.

0
Comment actions Permalink

Thanks a mil, I thought so. I have just corrected the prefix to use the default installed db prefix on the development side which is actually the correct way to do this. So it works perfectly this way thanks.

0
Comment actions Permalink

I've found a solution which involves using a modified ddl dump of your db. Here's a link to a StackOverflow answer I wrote about this subject: https://stackoverflow.com/a/51730952/314056

0
Comment actions Permalink

@Uuf6429

Well, https://youtrack.jetbrains.com/issue/WI-26986 is now fixed (2018.2) so some prefixing should work. Maybe your case uses different pattern?

0
Comment actions Permalink

Hi! I have just looked at that ticket (and the linked tickets), but I couldn't find how they work.

How would PhpStorm know how to handle prefixing?

0
Comment actions Permalink

Not super sure (not using this myself).

But if thinking about it... if constant is used then IDE may just insert its' value in that place. Otherwise I think it would be just warning suppression (e.g. if you have a table named "wp_users" in your DB and you use "SELECT * FROM {$prefix}users" query IDE may see that you have a table that matches "SOMETHINGusers" and will not show any warnings).

0
Comment actions Permalink

Did a quick test, it seems that this works only for constants. Of course, my ugly-ish solution above also has the disadvantage of requiring the use of the same variable name. But at least we're not bound to a constant.

0

Please sign in to leave a comment.