3

MySQL SQL commands can contain user variables that start with '@'.

The MySQL ADO.NET connector also uses '@' for command parameters.

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;

Where @jobid is a MySQL user variable and @companyid is a parameter.

Brad Robinson
  • 44,114
  • 19
  • 59
  • 88

1 Answers1

7

It's a connection string option - "Allow User Variables=true"

When set to true, parameters are prefixed with '?'.

Update: I've written up more on this, including how to get this to work with ADO.NET and Subsonic. See Here.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Brad Robinson
  • 44,114
  • 19
  • 59
  • 88