Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to put in a multi-line string without quotes on each line?

Reply
Thread Tools

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

 
 
dean
Guest
Posts: n/a
 
      06-03-2006
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

 
Reply With Quote
 
 
 
 
Dennis Jones
Guest
Posts: n/a
 
      06-03-2006

"dean" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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


 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      06-03-2006
In article <1149348708.643640.258530
@i39g2000cwa.googlegroups.com>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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.
 
Reply With Quote
 
Larry I Smith
Guest
Posts: n/a
 
      06-03-2006
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
 
Reply With Quote
 
benben
Guest
Posts: n/a
 
      06-04-2006
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
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      06-04-2006
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!!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
PHP double quotes inside double quotes MSB Computer Support 11 10-21-2006 01:09 PM
Asp.NET Javascript string, want to pass '(single quotes' within '(single quotes) Chris ASP .Net 1 03-24-2006 09:03 PM
Quotes/Double Quotes in Image Control Chris White ASP .Net 1 09-22-2004 06:22 AM
Multiline quotes - escaping quotes - et al Lawrence Tierney Java 3 12-24-2003 05:12 PM



Advertisments