Parsing escape characters

I have a query:
//query
String query_one = "UPDATE homepage SET section1='" + section1 + "' ";
//execute query
section1SQL.executeUpdate(query_one);
Here's the problem: if the var + section1 + contains a single quote or an apostrophe - the SQL query trips up.
Is there a function or way to parse the characters so that whatever is contained in the var can be submitted into the DB without tripping the SQL query?
Any help is appreciated.
Thanks
Mark

Hi Mark,
1.
Just take you sql and test it interactive against your database (sqlserver, oracle, db2, access, ect...)
and see how it interprete it. Then based upon that, you can write a function:
replace single ' by double ''
replace something by something
UPDATE homepage SET section1 = VALUE
where VALUE = it's my day
where VALUE = "you're right!"
where VALUE = it's correctly said "Great!"
2. In sqlserver, you need to escape single ' by double ''
--Paul.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Evaluation of escape characters

    I'm convinced there has got to be an easy way to do this, but I am too frustrated at this point to continue fighting it... I would much appreciate anyone's help.
    Let me use code to explain what I need help with.
    I have a String that contains the right hand side of a java String assignment. To simulate this:
    String rightHandSide = "\"line1\\nline2\\nline3\""so a println of rightHandSide LITERALLY displays:
    "line1\nline2\nline3"
    (notice the quotes and "escape characters" are are actually literal characters).
    I want to be able assign the evaluation/interpretation of this String to a String variable, such that:
    String escValue = workMagic(rightHandSide)is equivalent to:
    String escValue = "line1\nline2\nline3"Can anyone offer a simple solution to this problem? If the only solution involves writing my own parser, etc, I will just give up for now and work around this issue. However, it seems like there should be an easy way to do this?
    Thanks in advance for any and all help!

    Not too sure if this is what you wanted:
    workMagic.java
    ============
    public class workMagic {
       public static void main(String[] args) {
          String rightHandSide = "\"line1\\nline2\\nline3\"";
          String escValue = workMagic(rightHandSide);
          System.out.println(escValue);
       public static String workMagic(String in) {
          String out="";
          int k;
          int j=0;
          while (j<in.length()) {
             if (in.charAt(j)=='\\') {
                j++;
                if (j<in.length()) {
                   if (in.charAt(j)!='\\') out+="\\"+in.charAt(j);
                   else j--;
                } else out+='\\';
             } else if (in.charAt(j)!='\"') out+=in.charAt(j);
             j++;
          return out;
    }V.V.

  • How can I use escaped-characters in an option

    I have the following code that is used to retrieve city-names including parent-child relations from a database and place them in an array:
    <%@ page contentType="application/x-javascript" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
    <sql:setDataSource dataSource="jdbc/KADOS" var="Raak" scope="session" />
    <sql:query var="bewaringSQL" dataSource="${Raak}">
    SELECT bewaringcode, vestigingsplaats FROM BEWARING order by vestigingsplaats
    </sql:query>
    bewaringen = new Array(
    <c:forEach items="${bewaringSQL.rows}" var="plaats" varStatus="s" >
    new Array( "<c:out value="${plaats.BEWARINGCODE}" />",
    "<c:out value="${plaats.VESTIGINGSPLAATS}" />" )
    <c:if test="${not s.last}">,</c:if>
    </c:forEach>
    i=0;
    <c:forEach items="${bewaringSQL.rows}" var="plaats" varStatus="s" >
    <sql:query var="bewaringGemSQL" dataSource="${Raak}" sql="SELECT KADGEMCODE, KGMNAAM FROM KADGEMEENTE where BEWARINGCODE=? order by KGMNAAM">
    <sql:param value="${plaats.BEWARINGCODE}" />
    </sql:query>
    tmp = new Array(
    <c:forEach items="${bewaringGemSQL.rows}" var="gem" varStatus="s" >
    new Array( "<c:out value="${gem.KGMNAAM}" />",
    "<c:out value="${gem.KADGEMCODE}" />" )
    <c:if test="${not s.last}">,</c:if>
    </c:forEach>
    bewaringen[2] = tmp;
    i = i+1;
    </c:forEach>
    function bewaringenList(selectCtrl, itemArray) {
    for (i=0; i<itemArray.length; i++) {
    selectCtrl.options[i] = new Option(itemArray[i][1]);
    selectCtrl.options[i].value = itemArray[i][0];
    function setList(selectCtrl, itemArray) {
    for (i=selectCtrl.options.length; i>=0; i--) {
    selectCtrl.options[i] = null;
    for (i=0; i<itemArray.length; i++) {
    optie = filter(itemArray[i][0]);
    selectCtrl.options[i] = new Option(optie);
    selectCtrl.options[i].value = itemArray[i][1];
    function filter( invoer) {
    retour = invoer;
    retour = retour.replace("'", "\'");
    return retour;
    The function 'bewaringenList' populates a <SELECT> with parent-names and
    "setList(document.VraagForm.gemSelect, bewaringen[this.selectedIndex][2]);" populates the depending <SELECT> with child-names.
    Some names contain single quotes (like "&#039;t Zandt") and are displayd in the select-box as "&#039t Zandt".
    I expected that the quotes could be replaced by escape-characters by 'filter(invoer)' but this does not work.
    Is there a generic way to show these characters?
    Ben

    I don't understand why but this filter solved the problem:
    function filter( invoer) {
    retour = invoer;
    retour = retour.replace("&#039;", "'");
    return retour;

  • Issue with escaping characters and php

    Greetings,
    We are working on a web page using php and Oracle. We have troubles dealing with the diferent escaping characters when inserting/retrieving data (magic quotes is on but adding the backslash doesn't help :( ).
    We would like to know the correct way of dealing with those characters ( ' " / /n ...).
    Thank you in advance,
    Sincerely,
    Oriol Nonell

    Do NOT use addslashes/stripslashes to escape your queries. I use this function to do the escaping:
    function escapeSQL($string, $wildcard=false)
    $result = str_replace("'","''",$string);
    if ($wildcard == true) $result = str_replace("%","%%",$result);
    return $result;
    It basically replaces ' with ''.
    If you set $wildcard to false, then '%' is considered to be an actual '%' (for 'like' expressions). If you set it to true, a % is escaped to %% too.

  • Web Logic 10.3 upgrade causes issues with escaped characters in JSP.

    We recently upgraded our application servers from Weblogic 9.2 to Weblogic 10.3 and we are having an issue with escaped characters in a JSP code. Here is an example of what we are seeing:
    var convertedBody1 = document.getElementById('body').value.replace(/\$FIRST_NAME\$/g, firstName);
    This code works in Weblogic 9.2. In Weblogic 10.3 we have to make the following changes:
    var convertedBody1 = document.getElementById('body').value.replace(/\$FIRST_NAME\$/g, firstName);
    Thanks, Tom

    Hi:
    I have resolved the issue with the following in the jspx page.
    Put an
    <jsp:scriptlet>
    response.setContentType(“text/html; charset=UTF-8”);
    </jsp:scriptlet>
    Inside the <f:view> on the jspx file.
    Please refer the link http://www.oracle.com/global/il/support/tip/nlss11061.html for more details. It is helpful.
    Thanks & Regards
    Sridhar Doki

  • VLD-1141, Template cannot contain escape characters.

    Hi All,
    I need help about mapping deployment. I am working on a mapping. I can deploy it before to 9i target location. But after upgrading target database to 10g, I get the error VLD-1141 when I deploy it. The detail is Template cannot contain escape characters.
    And the full error message is as following:
    VLD-1141: Internal error during mapping generation.
    java.lang.IllegalArgumentException: Template cannot contain escape characters.
    at oracle.wh.util.expr.WBLiteralExpression.<init>(WBLiteralExpression.java:34)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformGenerationDelegate.addContextExpressionsForGroups(GenericTransformGenerationDelegate.java:345)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformGenerationDelegate.prepareOutputContextPlSql(GenericTransformGenerationDelegate.java:1433)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformPlSqlDelegate.prepareOutputContext(GenericTransformPlSqlDelegate.java:147)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:239)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleCursorLoopInternal(PlSqlGenerationMediator.java:3206)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleCursorLoop(PlSqlGenerationMediator.java:3190)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleRowBased(PlSqlGenerationMediator.java:3115)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assemble(PlSqlGenerationMediator.java:538)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:770)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:316)
    at oracle.wh.service.impl.mapping.generation.WBDeployableMappingGenerator.generate(WBDeployableMappingGenerator.java:99)
    at oracle.wh.service.impl.generation.common.WBGenerationService.generateCode(WBGenerationService.java:433)
    at oracle.wh.service.impl.generation.common.WBGenerationService.generateCode(WBGenerationService.java:311)
    at oracle.wh.service.impl.generation.service.WhValidationGenerationTransaction.run(WhValidationGenerationTransaction.java:241)

    There are to bugs:
    Bug 5403652 - ERROR 'TEMPLATE CANNOT CONTAIN ESCAPE CHARACTERS' WHEN VALIDATING A MAPPING
    Bug 5561224 - MIGRATION OF MAPPING REQUIRES CHANGE IN CONFIG TO ALLOW VALIDATION
    against OWB 10.2.0.1
    but these bugs are fixed from 10.2.0.2
    The bug is related to pre/post mapping operators...
    If you are on 10.2.0.3 or your mapping does not have these operators then have no clue...

  • Displaying unicode or HTML escaped characters from HTTPService in Flex components.

    Here is a solution on the Flex Cookbook I developed for
    displaying data in Flex components when the data comes back from
    HTTPService as unicode of HTML escaped data:
    Displaying
    unicode or HTML escaped characters from HTTPService in Flex
    components.

    Hi again Greg,
    I have just been adapting your idea for encountering
    occasional escaped characters within a body of "normal" text, eg
    something like
    hell&ocirc; sun&scaron;ine
    Now, the handy String.fromCharCode(charCode) call works a
    dream if instead of the above I have
    hell&#244; sun&#353;ine
    Do you know if there is an equivalent call that takes the
    named entities rather than the numeric ones? Clearly I can just do
    some text substitution to get the mapping, but this means rather
    more by-hand work than I had hoped. However, this is definitely a
    step in a useful direction for me.
    Thanks,
    Richard
    PS hoping that the web page won't simply outguess me and
    replace all the above! Basically, the first line uses named
    entities and the second the equivalent numbers...

  • Official documents on escaping characters in SQL Server query statements

    Hi,
    Are there any official documents on how to escaping special characters in SQL Server query statements? I find a lot of online resources discussing about this, but there are no definitive conclusions on:
    Which characters should be escaped? (Some only said single-quote needs to be escaped, double-quote does not need. While others said both need to be escaped)
    How to escape characters? (Some said using two single-quote to escape a single-quote. Others said using a backslash, etc.)
    So I just wonder if there is an official document from Microsoft regarding this?
    Thanks
    Alan

    Depends on where you're using them
    If its string values then single quotes(') should be escaped by putting one more single quote before it.
    If its LIKE operator you can use ESCAPE keyword or use [] to escapre special characters 
    see
    http://visakhm.blogspot.in/2013/01/wildcard-character-based-pattern-search.html
    If inside SSIS expression you can escape characters like \ " etc by adding an extra \ before the characters
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Bug in replace all. escape characters are not working.

    Hi,
    My requirement is that whenever i see ":" (Colon) in the string then i want to replace it with (\:). So i tried
    String escapedTitle = "title:the world is not enough".replace(":", "\\:")
    and to my surprise, when i printed escapedTitle i got
    title\\:the world is not enough
    instead of
    title\:the world is not enough
    (note the back slash in the string)
    I want to ask why there is a different beehavious of escape characters? I am using JDK1.6.0_06

    Sorry for the last post. Please try this:
    public class test
    public static void main(String a[])
         String escapedTitle = "title:the world is not enough".replaceAll(":+", "\\:"); //or [:]+
         String escapedTitle1 = "title:the world is not enough".replaceAll(":+", "*"); // or [:]+
         System.out.println("Another String is "+ escapedTitle);
         System.out.println("Another String is "+ escapedTitle1);
         System.out.println(System.getProperty("java.vendor"));
         System.out.println(System.getProperty("java.version"));
    output is
    Another String is title:the world is not enough
    Another String is titlethe* world is not enough
    Sun Microsystems Inc.
    1.6.0_06
    Please let me know why i am not getting : as escaped (\:) with replaceAll method.
    i want string escapedTitle as Another String is title*\:*the world is not enough

  • Validation - template cannot contain escape characters

    Hi all, im new to Warehouse builder, i find the documentation lacking, the tutorials lacking and i can't find any books on warehouse builder either. Am I stupid ? :-)
    Anyway, i've set up 3 constants (varchar2) to pass as parameter values to a function im calling and when i try to validate the mapping im getting 'Template cannot contain escape characters'.
    Then im getting validation completed successfully..however, when i try to deploy im getting this:
    VLD-1141: Internal error during mapping generation.
    java.lang.IllegalArgumentException: Template cannot contain escape characters.
    at oracle.wh.util.expr.WBLiteralExpression.<init>(WBLiteralExpression.java:34)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformGenerationDelegate.addContextExpressionsForGroups(GenericTransformGenerationDelegate.java:345)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformGenerationDelegate.prepareOutputContextPlSql(GenericTransformGenerationDelegate.java:1433)
    at oracle.wh.service.impl.mapping.component.transforms.GenericTransformPlSqlDelegate.prepareOutputContext(GenericTransformPlSqlDelegate.java:147)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:239)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleCursorLoopInternal(PlSqlGenerationMediator.java:3206)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleCursorLoop(PlSqlGenerationMediator.java:3190)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assembleRowBased(PlSqlGenerationMediator.java:3115)
    at oracle.wh.service.impl.mapping.generation.PlSqlGenerationMediator.assemble(PlSqlGenerationMediator.java:538)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:770)
    at oracle.wh.service.impl.mapping.generation.WBMappingGenerator.generate(WBMappingGenerator.java:316)
    at oracle.wh.service.impl.mapping.generation.WBDeployableMappingGenerator.generate(WBDeployableMappingGenerator.java:99)
    at oracle.wh.service.impl.generation.common.WBGenerationService.generateCode(WBGenerationService.java:433)
    at oracle.wh.service.impl.generation.common.WBGenerationService.generateCode(WBGenerationService.java:311)
    at oracle.wh.service.impl.generation.service.WhValidationGenerationTransaction.run(WhValidationGenerationTransaction.java:241)
    I have no clue whatsoever what this is about, can anyone tell ?

    hi ,
    I also got the same error when i migrated MDL from owb 9.2 version.
    I was using OWB 10.2.01, and heard that it is a bug which is fixed in owb 10.2.0.3
    So i applied the patch and this error gone.
    In case if it help u.
    rojo

  • Template cannot contain escape characters

    I created a database function which takes a varchar2 variable as input and passes back a number as output.
    I am using pre mapping process to call this function and I created a constant with the value I want to pass to this function. When I try to validate my mapping I am getting this error
    Template cannot contain escape characters.
    Why am i gettign this error any ideas as to how to fix this. I know for sure the join of the constant to the input mapping process is causing this error but my constant variable just has
    'xxxxx_xxxx' no other characters.
    Thanks

    Hi
    Are you using the 10.2.0.1 production release, I think this is bug 5403652. It should be fixed in a patch after (10.2.0.2 onwards), you could also try set based only code generation and see if this bypasses the problem (there is a comment in the bug indicating it is a row based code gen bug).
    Cheers
    David

  • Reading in/writing out escape characters from/to file

    I am trying to read in a large file which has many escape/special charaters (e.g. /, double quote (" ") etc.). I need to read them as they are and then write them out in a separate file as they were in the original file (e.g. if there was a double quote in the original file, I would have to keep the double quote in the output file)
    Now my question is: how can we tell the BufferedReader and FileWriter not to treat those characters to be escape characters?
    Thanks

    Now my question is: how can we tell the
    BufferedReader and FileWriter not to treat those
    characters to be escape characters?AFAIK, you don't need to do anything special. BR and FW already do that the right way.
    Did you try the standard approach?

  • Error in parsing special characters

    We are getting the following error when we parse a clob with special characters like \226(- special dash char), \231(the "TM"-Trademark logo), \256(the "R"-Registered logo )
    "Invalid char in text" when the parser is loaded in the db.
    But when we tried to parse this xml file as a file input (parser is now outside the db), it parses the file fine and inserts the data into the db.
    We are wondering if there is a difference in parser parsing special characters between inside and outside the db.
    We are running xml parser version 2.0.2.7 and if this is a bug and being fixed in later version, is there a workaround for this version

    Please try our latest 9.0.1 version

  • Dealing with escape characters

    I have a command that works if I represent it as "\003"+command+"\r" because my command needs to be preceded by the char 'x03' and tailed by the char 'x0d'. The literals "\003" and "\r" are being converted as I wish into their equivalent byte values.
    If I use Java string variables 'start' and 'end' to hold the values "\003" and "\r" and I issue my command as 'start+command+end', the start and end values are NOT converted into byte values. They remain represented as they are written i.e my string command is preceded by '\003' and ends with '\r'.
    How can I convert escape characters stored in string variable into their byte equivalents?
    David

    Please show us the code, because what you say isn't clear. If the Strings are written as
    String start = "\003";  // etx
    String end = "\r";   //crIt should work.
    Often this sort of thing is easier to do with character variable. eg.
    char start = 3;  // etx
    char end = 13;  // crI also wonder why you are using etx (end of text) as the start of text, the usual choice would be stx=\002. Also, none of this has anything to do with "byte" values, they are characters and take 2 bytes each. Your network code can do that conversion for you after you choose your character set. Is it UTF8, Latin-1, or some other.

  • Translate the Escape characters to sapce in mySAP ERP

    Hi all,
    I am working in mysap ERP(Unicode system). I want to TRANSLATE the Escape characters to SPACE. It is giving me a error saying that the internal table must be a character type. Please let me know how to solve this problem.
    Please find the details:
    I have 2 internal tables 1) t_file 2) t_trans.
    DATA:    BEGIN OF T_FILE OCCURS 0,
               REC(2600)  TYPE C,
             END OF T_FILE.
    DATA:    BEGIN OF T_TRANS OCCURS 0,
               X     TYPE X VALUE '00',
               C_00  TYPE C VALUE ' ',
               SOH   TYPE X VALUE '01',
               C_01  TYPE C VALUE ' ',
               STX   TYPE X VALUE '02',
               C_02  TYPE C VALUE ' ',
        end of t_trans.
    T_Trans is the conbination of character & hexa decimal.
    I am using the statement:
         TRANSLATE T_FILE USING T_TRANS.
    I am getting the error for the TRANSLATE.
    Thanks & Regards,
    Srinivas.

    Hi srinivas,
    try this one..
    DATA: BEGIN OF T_FILE OCCURS 0,
    REC(2600) TYPE C value
    END OF T_FILE.
    DATA : T_TRANS(20) VALUE '0 0 0 1 0 2 '.
    WRITE : / T_FILE.
    translate t_file using t_trans.
    WRITE : / T_FILE.
    regards
    satesh

Maybe you are looking for