List:MySQL++« Previous MessageNext Message »
From:Rick Gutleber Date:October 28 2008 3:03pm
Subject:Re: Insert policy design question
View as plain text  
OK.  That makes sense that you don't want to quote all the time, and I 
know that's talked about in the docs.  What I was missing was in 
manip.cpp. 

However, I wonder if there is an option to explicitly choose to write 
quoted output to a stream that isn't a Query.

I had a hard time deciding what should be done in insertfrom( ) and what 
should be done in the InsertPolicy, because the InsertPolicy needs to 
know a number of things to do its job, not the least of which is the 
current query you've built up.  The problem to me is compounded by the 
fact that if you're writing to a stream, the only way to see what you've 
written so far is to call the str( ) method which involves constructing 
a std::string and (IIUC) copying the entire contents of the string, 
which by definition is likely to be very long.  Alternately, you can 
pass the length of the VALUES element to the InsertPolicy as you add 
objects to your SQL query so it knows how long the query is, and that 
seems like a really silly thing to have to do.  So, I decided to let the 
InsertPolicy have the simple smarts to build the query itself, but that 
isn't working because I need a _special_ stream, or some way to change 
the quote option for a non-special stream in order to build properly 
quoted value lists.  Of course, another alternative is to add extra 
cases in manip.cpp for the InsertPolicy object and have it also derived 
from a stream class like Query is.

I do like the idea that the InsertPolicy actually builds the query 
string because there are other possibilities for what it could do, one 
of which as I suggested before is to deal with auto-increment IDs.  
Perhaps that isn't worth the hassle, but in order for InsertPolicy to be 
as open-ended as possible, it seemed like the way to approach it.

I apologize if this simple task is generating a ton of questions.  It's 
really the result of me trying to wrap my head around the MySQL++ way of 
doing things as well as just writing good, efficient code.

Warren Young wrote:
> Rick Gutleber wrote:
>>
>> Can you explain why this is so? 
>
> MySQL++ knows when the left hand side of operator<< is a Query, as 
> opposed to any other C++ IOstream, doing quoting and escaping only in 
> that case.  You wouldn't want this:
>
>     cout << String("foo") << endl;
>
> to produce this:
>
>     "foo"
>
> ostringstream is similarly generic.  MySQL++ doesn't know that you're 
> going to use the buffer for SQL queries, so it doesn't quote and 
> escape strings.
>
> If you're asking how MySQL++ knows, search for dynamic_cast in 
> lib/manip.cpp.  (And other places.)
>

Thread
Insert policy design questionRick Gutleber27 Oct
Re: Insert policy design questionRick Gutleber27 Oct
  • Re: Insert policy design questionDrew M.27 Oct
    • Re: Insert policy design questionWarren Young27 Oct
      • Re: Insert policy design questionRick Gutleber28 Oct
        • Re: Insert policy design questionWarren Young28 Oct
          • Re: Insert policy design questionRick Gutleber28 Oct
            • Re: Insert policy design questionWarren Young28 Oct
              • Re: Insert policy design questionRick Gutleber28 Oct
                • Re: Insert policy design questionWarren Young28 Oct
                  • Re: Insert policy design questionRick Gutleber29 Oct
                    • SVN down?Rick Gutleber6 Nov
                      • Re: SVN down?Warren Young6 Nov
                  • Query::tellp( )Rick Gutleber29 Oct
                    • Re: Query::tellp( )Warren Young29 Oct
    • Re: Insert policy design questionRick Gutleber27 Oct
      • Re: Insert policy design questionDrew M.28 Oct
        • Re: Insert policy design questionRick Gutleber28 Oct
        • Re: Insert policy design questionWarren Young28 Oct
  • Re: Insert policy design questionWarren Young28 Oct
    • Re: Insert policy design questionRick Gutleber28 Oct