How to put in a multi-line string without quotes on each line?

Discussion in 'C++' started by dean, Jun 3, 2006.

  1. dean

    dean Guest

    sSQL =
    " update SELECTED_NODES "
    " set LABEL_S = 'Y' "
    " where NODE_I in "
    " ( "
    " select NODE_I "
    " from "
    " ( "
    " select ONODE_I NODE_I from link "
    " union all "
    " select DNODE_I NODE_I from link "
    " ) ALL_NODES "
    " group by NODE_I "
    " having count(*) > 2 "
    " ) ";

    Is there a super-quote I can add at the start of that statement, so I
    don't need all the double quotes on each line? Something like /* and */
    but for strings and not comments.

    Thanks!

    Dean
     
    dean, Jun 3, 2006
    #1
    1. Advertising

  2. dean

    Dennis Jones Guest

    "dean" <> wrote in message
    news:...
    > sSQL =
    > " update SELECTED_NODES "
    > " set LABEL_S = 'Y' "
    > " where NODE_I in "
    > " ( "
    > " select NODE_I "
    > " from "
    > " ( "
    > " select ONODE_I NODE_I from link "
    > " union all "
    > " select DNODE_I NODE_I from link "
    > " ) ALL_NODES "
    > " group by NODE_I "
    > " having count(*) > 2 "
    > " ) ";
    >
    > Is there a super-quote I can add at the start of that statement, so I
    > don't need all the double quotes on each line? Something like /* and */
    > but for strings and not comments.


    No.

    - Dennis
     
    Dennis Jones, Jun 3, 2006
    #2
    1. Advertising

  3. dean

    Jerry Coffin Guest

    In article <1149348708.643640.258530
    @i39g2000cwa.googlegroups.com>,
    says...
    > sSQL =
    > " update SELECTED_NODES "
    > " set LABEL_S = 'Y' "
    > " where NODE_I in "
    > " ( "
    > " select NODE_I "
    > " from "
    > " ( "
    > " select ONODE_I NODE_I from link "
    > " union all "
    > " select DNODE_I NODE_I from link "
    > " ) ALL_NODES "
    > " group by NODE_I "
    > " having count(*) > 2 "
    > " ) ";
    >
    > Is there a super-quote I can add at the start of that statement, so I
    > don't need all the double quotes on each line? Something like /* and */
    > but for strings and not comments.


    I'm not sure it's any improvement in readability, but you
    can do something like this:

    sSQL = "\
    update SELECTED_NODES \
    set LABEL_S = 'Y' \
    where NODE_I in \
    ( \
    select NODE_I \
    from \
    ( \
    select ONODE_I NODE_I from link \
    union all \
    select DNODE_I NODE_I from link \
    ) all NODES \
    group by NODE_I \
    having count(*) > 2 \
    )";

    This can lead to problems though -- in particular,
    inserting white-space between the back-slash and the new-
    line can cause a bit of a problem.

    My advice would be to read the query in from an external
    file instead.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Jun 3, 2006
    #3
  4. dean wrote:
    > sSQL =
    > " update SELECTED_NODES "
    > " set LABEL_S = 'Y' "
    > " where NODE_I in "
    > " ( "
    > " select NODE_I "
    > " from "
    > " ( "
    > " select ONODE_I NODE_I from link "
    > " union all "
    > " select DNODE_I NODE_I from link "
    > " ) ALL_NODES "
    > " group by NODE_I "
    > " having count(*) > 2 "
    > " ) ";
    >
    > Is there a super-quote I can add at the start of that statement, so I
    > don't need all the double quotes on each line? Something like /* and */
    > but for strings and not comments.
    >
    > Thanks!
    >
    > Dean
    >


    This topic may be compiler dependent, I don't know...

    The best I could do without getting compile errors was:

    const char * sqla =
    "update SELECTED_NODES \
    set LABEL_S = 'Y' \
    where NODE_I in \
    ( \
    select NODE_I \
    from \
    ( \
    select ONODE_I NODE_I from link \
    union all \
    select DNODE_I NODE_I from link \
    ) ALL_NODES \
    group by NODE_I \
    having count(*) > 2 \
    )" ;

    All the above example does is eliminate the leading quote on each
    line, but you still must have the trailing backslash on every
    line but the last. Also, the final string contains ALL of the blanks
    that appear at the beginning of each line.

    I'd stay with your original approach; it's easier to read and puts
    fewer blanks in the string.

    Larry
     
    Larry I Smith, Jun 3, 2006
    #4
  5. dean

    benben Guest

    dean wrote:
    > sSQL =
    > " update SELECTED_NODES "
    > " set LABEL_S = 'Y' "
    > " where NODE_I in "
    > " ( "
    > " select NODE_I "
    > " from "
    > " ( "
    > " select ONODE_I NODE_I from link "
    > " union all "
    > " select DNODE_I NODE_I from link "
    > " ) ALL_NODES "
    > " group by NODE_I "
    > " having count(*) > 2 "
    > " ) ";
    >
    > Is there a super-quote I can add at the start of that statement, so I
    > don't need all the double quotes on each line? Something like /* and */
    > but for strings and not comments.
    >
    > Thanks!
    >
    > Dean
    >


    Put it in a file and read it at run time.

    Ben
     
    benben, Jun 4, 2006
    #5
  6. dean

    Phlip Guest

    dean wrote:

    > sSQL =
    > " update SELECTED_NODES "
    > " set LABEL_S = 'Y' "
    > " where NODE_I in "
    > " ( "
    > " select NODE_I "
    > " from "
    > " ( "
    > " select ONODE_I NODE_I from link "
    > " union all "
    > " select DNODE_I NODE_I from link "
    > " ) ALL_NODES "
    > " group by NODE_I "
    > " having count(*) > 2 "
    > " ) ";
    >
    > Is there a super-quote I can add at the start of that statement, so I
    > don't need all the double quotes on each line? Something like /* and */
    > but for strings and not comments.


    That pattern is called PerniciousIngrownSql. You are asking how to make the
    SQL easier to in-grow.

    Instead, consider writing a simple system that generates SQL with streams,
    like this:

    stringstream q;
    update(q, selectedNodesTable);
    q << "set LABEL_S = 'Y'";
    q << "where NODE_I in "
    selectNode_I(q);

    I pushed some of your strings into simple functions. As you write more SQL,
    you will re-use these simple functions. If your program grows very complex,
    that suite of simple functions will start to work as a "persistence layer".

    But if you program does not grow complex (a good thing), then they won't.
    They will just keep helping you write SQL statements that don't duplicate
    all their contents everywhere.

    --
    Phlip
    http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
     
    Phlip, Jun 4, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris White

    Quotes/Double Quotes in Image Control

    Chris White, Sep 22, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,877
    Hermit Dave
    Sep 22, 2004
  2. Chris
    Replies:
    1
    Views:
    13,693
    Oisin
    Mar 24, 2006
  3. Lawrence Tierney

    Multiline quotes - escaping quotes - et al

    Lawrence Tierney, Dec 24, 2003, in forum: Java
    Replies:
    3
    Views:
    4,518
    Andrew Thompson
    Dec 24, 2003
  4. Replies:
    5
    Views:
    399
    Hendrik van Rooyen
    Dec 22, 2007
  5. jOhn
    Replies:
    1
    Views:
    236
    Phlip
    Jan 29, 2008
Loading...

Share This Page