Thread: Strings using special characters [ ]

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    Strings using special characters [ ]

    Hello,
    I am getting an error with constructing a SQL statement in C++. I am using C++ BuilderI am wondering if the string class is doing something weird with the special characters. In particular, the SQL engine complains about the [ bracket

    String SQL = "SELECT * FROM Study ORDER BY InternalPatientID, [Study Date/Time]";

    The weird part is that this was legacy code that used to work but now does not.

    Thanks

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    C++ will not take one bit of notice as to WHAT your string contains, as long as it's printable and not a '"' - the double quotes can be inserted, and several non-printable characters as well, by escaping it with a backslash, e.g.
    Code:
    string myStr("This is a string with a quoted \"text\" and a unprintable newline \n");
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    This seems to be entirely a problem on the SQL side, if it's the SQL engine that complains.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by matsp View Post
    non-printable characters as well...
    Just wondering why we call them "non-printable"... After all the new line *does* appear in the final output, albeit not as a single char on screen...

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It has an effect, but it cannot be printed, as such?

    Strangely, though, space counts as printable, while tab does not.
    Last edited by CornedBee; 09-25-2007 at 09:24 AM.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by CornedBee View Post
    Strangely, though, space counts as printable, while tab does not.
    My point exactly.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I beleive "printable" is defined by what you could output to a lineprinter or a printing press without further processing - tab for example is "processed" by replacing it with spaces until the next tab boundary. Space is printable as such - it just doesn't show anything...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm just wondering about that syntax/naming convention - what SQL database are you using (AND is it the same database server as before?)?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Sep 2007
    Posts
    3
    I'm using Borland Database Engine with Access 2003. If I use the Query component in access alone and setup a SQL statement that exactly matches the above (minus the quotes) the query works.
    However, using C++ builder the BDE compalins about the [Study part of the string. I don't know if I would have to take into account the [ as a special character.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Well, to sum it up, from C++'s point of view, only " and \ are in any way special in string literals.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-29-2008, 03:22 AM
  2. Check strings which should only contain some characters.
    By qingxing2005 in forum C Programming
    Replies: 2
    Last Post: 06-17-2008, 09:32 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Converting C strings to list of characters
    By kazbo in forum C Programming
    Replies: 11
    Last Post: 02-14-2005, 10:17 AM
  5. Scanning characters & strings
    By rain_e in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 01:43 AM