dotConnect for Google BigQuery enhances SQL handling capabilities through the use of parameters in SQL queries. You can make execution of a query very flexible using several techniques. This article describes some basics you must know when working with parameters in dotConnect for Google BigQuery, as well as parameters synchronization.
In general, a parameter is a placeholder for a variable that contains a value of a certain type when a query is executed. A parameter is represented by the BigQueryParameter class. All parameters that take part in query execution constitute a collection that can be accessed through the BigQueryCommand.Parameters property.
dotConnect for Google BigQuery uses BigQuery named query parameters. Named parameters are declared in the query text using the '@' prefix followed by the name of the parameter. The name of the BigQueryParameter object in the command's collection can be specified without the prefix. Named parameters have two main advantages. First, you do not have to care about the order in which parameters are created. Second, a named parameter can appear more than once in the query text, but you have to create only one instance of it in the Parameters collection.
For example, a simple UPDATE statement with named parameters might look like the following:
To set parameters for this query, you can use the following code:
The type of a parameter value must match the type of the expression it is compared with or assigned to: BigQuery does not convert, for example, STRING parameters to INT64 implicitly. Set the DbType or BigQueryParameter.Type property, or assign a value of the corresponding .NET type.
BigQuery stored procedures are called with the CALL statement in the command text.
The CommandType.StoredProcedure command type is not supported.
The behavior described above assumes that BigQueryCommand.ParameterCheck is false (by default). If you set it to true, you enable automatic synchronization of the query text and the BigQueryCommand.Parameters collection. In this mode, all parameters are checked for validity, new ones are added if necessary, and redundant parameters are deleted. Thus, you do not have to care about the number of items in the BigQueryCommand.Parameters collection. The synchronization is performed as follows:
UPDATE dept SET loc = @loc WHERE deptno = @deptno,
use the following code to access the parameter:
The synchronization takes place when: