Escaping single quotes

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Cloud Applications
Post Reply
arkajzerek
Posts: 4
Joined: Thu 07 Jun 2012 15:48

Escaping single quotes

Post by arkajzerek » Mon 16 Jul 2012 10:20

How single quotes are escaped in case of parameters?

Trying to run simple query as follows:

select id from account where name = @name

@name is set using Parameters.AddWithValue method to "Arek's company"

Thanks.

Shalex
Site Admin
Posts: 9305
Joined: Thu 14 Aug 2008 12:44

Re: Escaping single quotes

Post by Shalex » Wed 18 Jul 2012 16:39

Here is an example of handling single quotes:

Code: Select all

        SalesforceCommand cmd = conn.CreateCommand();
        cmd.CommandText = "select * from account where type = @type";
        cmd.Parameters.AddWithValue("type", "Customers' account");
        cmd.Parameters[0].SalesforceType = SalesforceType.String;
        SalesforceDataReader reader = cmd.ExecuteReader();
        while (reader.Read()) {
            Console.WriteLine(reader["Name"]);
        }
If the SalesforceType.String type is set explicitly, dotConnect for Salesforce quotes single quote in the query which is sent to the server.

Post Reply