SQL - Syntax Error in valid sql, but only in CF?

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

  1. #1

    Default SQL - Syntax Error in valid sql, but only in CF?

    Hi CF-people

    As a php coder, I'm having quite a hard time getting used to cf :)

    I've coded a component which generates a SQL-Insert Statement and (tries to)
    execute it. When I cfout and copy/paste it to the (ms-sql) query analyzer it
    works but if I want CF to do it, it throws a Syntax Error? Does anybody of you
    know where my problem is?

    I'd appreciate any kind of hint!
    Markus

    PS: Thats the Statement:

    INSERT INTO Person (id,Name,Vorname,Eintrittsdatum,Email) VALUES (235,
    'TestName', 'TestFirstname', '12.07.05', 'test@email.com')

    And the Error Statement (unfortunatelly in german)

    [Macromedia][SQLServer JDBC Driver][SQLServer]Zeile 1: Falsche Syntax in der
    N?he von 'TestName'.

    marksta80 Guest

  2. Similar Questions and Discussions

    1. your role no longer valid error message and cannot edit page
      Unfortunately I don't have access to the file, am asking on behalf of a friend who is skittish about his skills navigating a forum. His question...
    2. error : syntax error at or near $1 for over select rows
      This is the error i am getting when calling select * from cas_reset_qi_changedate('CAS','2003-02-03' ERROR: syntax error at or near "$1" at...
    3. System.InvalidCastException: Specified cast is not valid. error when updating datagrid
      Hello, I am trying to update a record using a data grid. I Have a footer column in my data grid that allows users to add a new record. However, I...
    4. Help error message - not a valid Freehand File
      WIN NT FH10 When I try to open some back up files I am recently getting an error message that reads "Could not convert the document because it is...
    5. #25818 [Com]: Valid select using OCI8 causes integer overflow error in Oracle
      ID: 25818 Comment by: cjbj at hotmail dot com Reported By: iolaire dot mckinnon at vcint dot com Status: Open...
  3. #2

    Default Re: SQL - Syntax Error in valid sql, but only in CF?

    On 2005-07-17 10:39:39 -0500, "marksta80" <webforumsuser@macromedia.com> said:
    > Hi CF-people
    >
    > As a php coder, I'm having quite a hard time getting used to cf :)
    >
    > I've coded a component which generates a SQL-Insert Statement and
    > (tries to) execute it. When I cfout and copy/paste it to the (ms-sql)
    > query analyzer it works but if I want CF to do it, it throws a Syntax
    > Error? Does anybody of you know where my problem is?
    >
    > I'd appreciate any kind of hint!
    > Markus
    >
    > PS: Thats the Statement:
    >
    > INSERT INTO Person (id,Name,Vorname,Eintrittsdatum,Email) VALUES (235,
    > 'TestName', 'TestFirstname', '12.07.05', 'test@email.com')
    >
    > And the Error Statement (unfortunatelly in german)
    >
    > [Macromedia][SQLServer JDBC Driver][SQLServer]Zeile 1: Falsche Syntax
    > in der N?he von 'TestName'.
    My first guess would be that the date format is throwing it. Try
    building your statement up one piece at a time to see where it breaks.
    For example, can you just insert the ID? Just ID and first name? etc.
    (Your ability to do this might be affected by how you have your
    nullable fields set in your database.)

    Matt
    --
    Matt Woodward
    [email]mpwoodward@gmail.com[/email]
    Team Macromedia - ColdFusion

    mpwoodward *TMM* Guest

  4. #3

    Default re: Using DISTINCT wirh ORDER BY

    Use the PreserveSingleQuotes() function in your cfquery...

    <CFQUERY ...>
    #PreserveSingleQuotes (GeneratedSQL_Text)#
    </CFQUERY>
    MikerRoo Guest

  5. #4

    Default RE: SQL - Syntax Error in valid sql, but only in CF?

    Wrap your query string in PreserveSingleQuotes().
    MikerRoo Guest

  6. #5

    Default Re: SQL - Syntax Error in valid sql, but only in CF?

    Thank you for your help. I've set up all fields as text fields, so I don't need
    to worry (yet) about the data-format.

    But I keep getting these syntax errors... but copy&past to query analyzer does
    still work.

    I'd be really happy if may have another tip.
    Thanks
    Markus

    Here's my code, did I make an mistake?

    <cfset insVals= ArrayToList(#values#,", ")>
    <cfset insVals= #PreserveSingleQuotes(insVals)#>
    <cfset insStr = #insStr# & " (" & ArrayToList(#columns#,",") & ") VALUES (" &
    #insVals# & ")">

    marksta80 Guest

  7. #6

    Default Re: SQL - Syntax Error in valid sql, but only in CF?

    That's not quite right.

    Use PreserveSingleQuotes() like this:

    <CFSET sSQL_Str = "INSERT INTO SomeTable VALUES ('Some text', 25)">
    <CFQUERY ... ...>
    #PreserveSingleQuotes (sSQL_Str)#
    </CFQUERY>

    If that's not enough, Post your entire CFQuery code.

    Regards,
    -- MikeR

    MikerRoo Guest

  8. #7

    Default Re: Re: SQL - Syntax Error in valid sql, but only inCF?

    That's how it's done! Thank you very much!
    marksta80 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