如何在 ADO.NET 中使用 MySQL 用户变量
MySQL SQL 命令可以包含以@"开头的用户变量.
MySQL SQL commands can contain user variables that start with '@'.
MySQL ADO.NET 连接器还使用@"作为命令参数.
The MySQL ADO.NET connector also uses '@' for command parameters.
有没有办法转义@"字符,以便我可以在通过 ADO.NET 发送到 MySQL 的 SQL 语句中使用用户变量?
Is there a way to escape the '@' character so I can use a user-variable in an SQL statement sent to MySQL via ADO.NET?
我正在尝试做这样的事情:
I'm trying to do something like this:
UPDATE company
SET next_job_id = @jobid:=next_job_id+1
WHERE company_id = @companyid;
SELECT @jobid;
@jobid 是 MySQL 用户变量,@companyid 是参数.
Where @jobid is a MySQL user variable and @companyid is a parameter.
推荐答案
这是一个连接字符串选项 - Allow User Variables=true"
It's a connection string option - "Allow User Variables=true"
设置为 true 时,参数以'?'为前缀.
When set to true, parameters are prefixed with '?'.
更新:我已经写了更多关于这方面的文章,包括如何让它与 ADO.NET 和 Subsonic 一起工作.看这里.
Update: I've written up more on this, including how to get this to work with ADO.NET and Subsonic. See Here.
相关文章