Skip to content

MySql support

Simon Boddy edited this page Oct 25, 2020 · 2 revisions

To use QueryFirst with a MySql Database, you need to set the provider in your qfconfig.json, and pay attention to put Allow User Variables = true in the connection string. Here is a working qfconfig.json for a MySql DB...

{
  "defaultConnection": "Database=mydb; Data Source=mydb.mysql.database.azure.com; User Id=myUserId; Password=myPassword; Allow User Variables=True",
  "provider": "MySql.Data.MySqlClient"
}

MySql support has some limitations: we can't detect parameters in queries, so you need to manually declare them in the design time section of the query. QueryFirst will parse declarations of the form SET @SearchCriteria = 'Smith'; (This creates a user variable for the design time execution, then generates code for a real parameter at run time.) Also, we have no way of detecting or declaring the types of parameters, so they will show up in method signatures as object.

Here is a working sql statement with a parameter for MySql...

/* .sql query managed by QueryFirst add-in */
-- designTime - put parameter declarations and design time initialization here
SET @SearchCriteria = 'Smith';
-- endDesignTime

SELECT
	c.FirstName,
	c.LastName
FROM
	qf.Contacts c
WHERE
	c.LastName = @SearchCriteria;
Clone this wiki locally