Constrain and Double Quote

In VDF 16.1 and prior, if you have ever tried to constrain a database field to a string which contains the double quote character, you will find that VDF doesn't really like it. Let's see it in action. Open up Order Entry Example, Order.vw, add the following code to your OrderHea_DD.

    Object OrderHea_DD is a OrderHea_DataDictionary
        Set DDO_Server to Customer_DD
        Set DDO_Server to SalesP_DD
        Procedure OnConstrain  // ========= Add this procedure =========
        	String sOrderBy
        	Move 'Hello"World' to sOrderBy
            Constrain OrderHea.Ordered_By eq sOrderBy
        End_Procedure
    End_Object    // OrderHea_DD

Run the example, you are going to get the error Bad format of expression (operator). WORLD But, why? I am guessing (I don't work for DAW, I don't have access to the VDF source code, and I certainly don't claim to have any inside knowledge of VDF) that VDF puts double quotes around the data you supply, then it would wrap around it with double quotes, then it would evaluate (eval) it at runtime. How did I come up with that guess? Just look at the error message. VDF doesn't know what to do with the word "WORLD", which is after the double quote. And also, double quote is usually used to denote something is a string (of course you can use single quote as well, but single quote is not giving us any problem). So, knowing that the constrain you provide will be wrapped around in double quotes, and it will be passed into Eval, there is a sneaky workaround you can do.

    Object OrderHea_DD is a OrderHea_DataDictionary
        Set DDO_Server to Customer_DD
        Set DDO_Server to SalesP_DD
        Procedure OnConstrain  // ========= Add this procedure =========
        	String sOrderBy
        	Move 'Hello"World' to sOrderBy
        	Move (Replaces('"',sOrderBy,'"+Character(34)+"')) to sOrderBy // <== Add this
            Constrain OrderHea.Ordered_By eq sOrderBy
        End_Procedure
    End_Object    // OrderHea_DD

You might wonder why I don't do "Constrain As" as a workaround like in this knowledge-base article. Well, the reason is speed. VDF 17.1 and above fixed the issue. However if you are stuck using older version of VDF, then the code above might help you out.