[SalesForce] how to pass picklist value in Dynamic SOQL

I am using dynamic soql where I am reading the conditions from an XML and getting those as a String
but I am not able to find it who the query will structure

String query = 'SELECT id, Name FROM CustomObject__c WHERE Status__c =: InProgress';
Database.query(query);

It throws error message as

System.QueryException: Variable does not exist: InProgress

Best Answer

use variable binding

String status = 'InProgress';
String query = 'SELECT id, Name FROM CustomObject__c WHERE Status__c = :status';
List<CustomObject__c> result = Database.query(query);

it is preferable to use variable binding than string concatenation in order to prevent SOQL Injections. Also, if it not necessary to use dynamic SOQL use static SOQL.

String status = 'InProgress';
List<CustomObject__c> result = [
    select id, Name
    from CustomObject__c
    where Status__c =:status
    ];