double single quote problem in cfquery

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default double single quote problem in cfquery

    Hi, i've this problem with ColdFusion MX 6.1 Updater and MX 7 If i try to
    insert a text containing a single quote (for example TEST') all works fine. But
    if try to insert a text containing 2 single quote (for example TEST'' only one
    quote was stored in the DB and the result is TEST' With 3 single quotes
    (TEST''') the result was TEST' With 4 single quotes (TEST'''') two quoes was
    stored (TEST'')
    --------------------------------------------------------------------------------
    --- Sql script for the table (SQL Server
    --------------------------------------------------------------------------------
    --- CREATE TABLE [dbo].[_TEST] ( [ID] [int] IDENTITY (1, 1) NOT NULL ,
    [TESTO] [varchar] (255) COLLATE Latin1_General_CI_AS NOT NULL ) ON [PRIMARY] GO
    ALTER TABLE [dbo].[_TEST] WITH NOCHECK ADD CONSTRAINT [PK__TEST] PRIMARY
    KEY CLUSTERED ( [ID] ) ON [PRIMARY] GO INSERT INTO _TEST
    (testo) values ('')
    --------------------------------------------------------------------------------
    ---
    --------------------------------------------------------------------------------
    --- Sample code
    --------------------------------------------------------------------------------
    --- <cfif isdefined('form.btnsubmit')> <cfquery name='write'
    datasource='dsource'> update _test set testo = '#form.altext#'
    </cfquery> </cfif> <cfquery name='read' datasource='dsource'> select top
    1 testo from _test </cfquery> <cfset thetext='SAM'''''PLE'> <cfif read.testo gt
    ''> <cfset thetext=read.testo> </cfif> <form action='test.cfm' method='post'
    name='test' id='test'> <textarea cols='80' rows='5' name='altext'
    id='altext'><cfoutput>#htmleditformat(thetext)#</cfoutput></textarea> <input
    type='submit' name='btnsubmit' id='btnsubmit' value='ok'> </form>
    --------------------------------------------------------------------------------
    ----- If you run the page and click Ok you will see the single quotas decrese
    at any click. This is different from Cold Fusion 5 or earlier behaviour!!!
    Thanks Regards

    Bigio Guest

  2. Similar Questions and Discussions

    1. MX7 Double Quote
      I just upgraded to MX7. CFQUERY using where x = "sam" used to work & now the double quotes are being treated as escape characters. I don't want...
    2. Single & Double Quote Problem in Database Insert/Update
      Hello, I have a textarea on a form where users are able to enter text wrapped in 'single' and "double" quotes. However, when I insert or update...
    3. Single Quote Problem in Excel to Export
      Hi, We have to export our data in sql server table to any excel sheet. We have a template to export, using oledb we are inserting rows to this...
    4. SQL insert/update problem if coldfusion field value has single quote
      On the coldfusion form, if the user enter the data with single quote in a field (e.g. Joe's Party), and performs SQL insert or update statements,...
    5. Single versus Double quote marks as string delimiters
      Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted...
  3. #2

    Default Re: double single quote problem in cfquery

    Hi again...
    No one can help me?
    Bigio Guest

  4. #3

    Default Re: double single quote problem in cfquery

    It's because the quotes are excaping themselves. You can write a regular expression to replace a single quote with two single quotes. Then the correct number of quotes will be stored in the DB.
    Mike Greider Guest

  5. #4

    Default Re: double single quote problem in cfquery

    Better yet, try <cfqueryparam> which replaces the string with a bind variable.

    JR
    jonwrob Guest

  6. #5

    Default Re: double single quote problem in cfquery

    Originally posted by: jonwrob
    Better yet, try <cfqueryparam> which replaces the string with a bind variable.

    JR

    Thanks.
    The problem is that we have thousands of query to "update" with cfqueryparan...
    We don't understand the reason of this changing from CF 5 to CF MX...

    Regards


    Bigio Guest

  7. #6

    Default Re: double single quote problem in cfquery

    Would this hot fix apply?

    [url]http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_19108[/url]

    If you are patched up through the latest updater than you shouldn't need to
    apply this. However, if you haven't applied any updates to a virgin
    installation, you may want to look into these. Even so, I'm still not 100% sure
    I know what the issue is. It seems like CF is behaving correctly. If you want
    to insert single quotes into the database, you have to escape them, usually by
    adding another single quote. If you want to store 3 single quotes in the
    database, than your insert must contain 6, and so on. AFAIK, most languages
    work this way - certainly PHP.


    Mike Greider Guest

  8. #7

    Default Re: double single quote problem in cfquery

    Originally posted by: Mike Greider
    Would this hot fix apply?

    [url]http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_19108[/url]

    If you are patched up through the latest updater than you shouldn't need to
    apply this. However, if you haven't applied any updates to a virgin
    installation, you may want to look into these. Even so, I'm still not 100% sure
    I know what the issue is. It seems like CF is behaving correctly. If you want
    to insert single quotes into the database, you have to escape them, usually by
    adding another single quote. If you want to store 3 single quotes in the
    database, than your insert must contain 6, and so on. AFAIK, most languages
    work this way - certainly PHP.


    Hi,
    these patch is for MX 6.1 version, but i've upgraded it to MX 6.1 upgrader.
    I've tried to install it, but it didn't solve the problem.

    Thanks again.


    Bigio Guest

  9. #8

    Default Re: double single quote problem in cfquery

    The behavior has changed in CFMX and will be documented:
    CF5 behavior - all single-quotes are escaped by changing them into two
    single-quotes. Even in a loop, this only gets done once.

    CFMX behavior - pairs of single-quotes are considered to be already escaped.
    Only un-paired single-quotes get escaped into pairs of single-quotes.

    Using cfqueryparam is probably the best way to insure that the single quotes
    get inserted into the database.

    Ted Zimmerman

    tzimmerman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139