Search code examples
visual-foxpro

visual foxpro escape double quote


My application creates free foxpro tables and inserts data into them. I get a Syntax Error when inserting a string that has double quotes in it. here is the string that causes the issue - "TAIL LAMPS-HEIGHT BETWEEN 15" AND 72"". I have tried escaping the double quotes with a /, single quote, a double quote, but nothing helped. Is there any other way to fix this issue? any help is much appreciated. thanks.

This is my insert statement

INSERT INTO NAMEMAIN (ACCIDENT,CHARGE,YEARSTAMP,ZIP,ZONE) VALUES ("1", "TAIL LAMPS-HEIGHT BETWEEN 15\" AND 72\"", 0, " ", "OVPK")

Solution

  • It would be better to see the insert statement you are trying to do. The insert should be from variable references rather than hard strings.

    lcSomePart = Thisform.txtboxDescription.Value
    
    insert into YourTable ( somePartField ) values ( lcSomePart )
    

    It should work no problem, but again, without your example, hard to confirm what you are running into.

    Another way is VFP allows multiple options to wrap strings if you had it hard-code referenced, such as

    lcSomePart = [TAIL LAMPS-HEIGHT BETWEEN 15" and 72"]
    lcSomePart = 'TAIL LAMPS-HEIGHT BETWEEN 15" and 72"'
    

    Both versions above work. VFP uses square brackets to identify start/end of a string (as long as they are paired). Also allows single-quotes to act as start/end of string. And if you have a string that has a single-quote within, just use either square or double-quote in the same fashion.

    Change your insert to the following, but strongly suggest variables for inserts, especially if coming from data entry fields, but notice, VFP does not do escaping characters, but I changed to just using the square brackets around the string insert..

    INSERT INTO NAMEMAIN (ACCIDENT,CHARGE,YEARSTAMP,ZIP,ZONE) VALUES ("1", [TAIL LAMPS-HEIGHT BETWEEN 15" AND 72"], 0, " ", "OVPK")