问题描述
我们使用一个在工作中扩展Mysqli的类,它为准备好的语句添加了另一种语法,例如:
We use a class which extends Mysqli at work, and it adds another syntax for prepared statements, something like :
<?php
$req = MySQLiWrapperClass::getInstance()->prepare('
INSERT INTO
table
SET
field = :field_value:s
')
->bindNamedValue('field_value', 'stackOverflow')
->execute();
然后,该类将在执行查询之前将:field_value:s
转换为?
.
The class will then transform :field_value:s
to ?
before executing the query.
问题是,当在PhpStorm中使用MySQL的方言时,此语法将触发错误,因为无法识别该语法.
Problem is, when using MySQL SQL dialect in PhpStorm, this syntax will trigger an error because this syntax is not recognized.
有没有一种方法可以声明一个新的SQL方言,可以在其中添加此特定语法?
Is there a way to declare a new SQL Dialect, in which I could add this specific syntax ?
推荐答案
您不能像这样添加自己的SQL方言(无法通过某些GUI配置).
You cannot add your own SQL Dialect just like that (that's not configurable via some GUI).
我的意思是:是的,可以,但是您必须将其编码为Java插件,完成所需的所有工作-它会起作用.
What I mean is: Yes, you can, but you have to code it as a plugin in Java, do the all stuff needed -- it will work.
这里遇到的问题与SQL Dialect没有关系 –您没有提供新的关键字或实际的查询语法(或类似的东西).
The issue that you are having here has nothing to do with SQL Dialect -- you are not providing new keywords or actual query syntax (or stuff like that).
代码中的问题在于参数的自定义语法(:field_value:s
与:field_value
).
The issue in your code is in custom syntax for parameters (:field_value:s
vs :field_value
).
这可以通过在Settings/Preferences | Tools | Database | User Parameters
上指定自己的语法来解决:
This can be resolved by specifying your own syntax at Settings/Preferences | Tools | Database | User Parameters
:
- 模式:
:(\w+\:[d|i|s])
- 范围:PHP& MySQL至少(根据您的代码示例)
- 位置:至少在
literals
中
- Pattern:
:(\w+\:[d|i|s])
- Scope: PHP & MySQL at very least (based on your code sample)
- Where: in
literals
at very least
重要:规则的顺序也很重要.
Important: order of the rules matters as well.
这是我的工作及其工作方式:
Here is what I did and how it works:
这篇关于PhpStorm:添加SQL方言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!