List:MySQL++« Previous MessageNext Message »
From:Dan Cook (dancook) Date:July 10 2009 11:21pm
Subject:SSQLS: Iterating through field names and values...
View as plain text  
Fellow MySQL++ers, 

I am trying to put together an INSERT statement using the "ON DUPLICATE
KEY UPDATE" syntax for a generic SSQLS object.
A very simple example of the query is:
    INSERT INTO foo (id, a, b, c) VALUES (0, 2, 4, 6) ON DUPLICATE KEY
UPDATE id=VALUES(0), a=VALUES(2), b=VALUES(4), c=VALUES(6);

I want to do this for a general SSQLS object using a template:

The first part is textbook code from the docs:
   query << std::setprecision(16) <<
        "INSERT INTO " << object.table() <<
        " (" << object.field_list() << ") VALUES (" <<
object.value_list() << ")" <<
        " ON DUPLICATE KEY UPDATE ";

Building up the rest of the statement is where I get stuck.  I need to
iterate through the fields and the values to build up the construct
"field_name[x]=VALUES(field_value[x])," for the rest of the statement.

Is there a way to iterate through the list of field names and values?  
Can I do this with a custom delimiter of some kind?

Thanks, 
Dan

Thread
SSQLS: Iterating through field names and values...dancook)11 Jul
  • RE: SSQLS: Iterating through field names and values...dancook)11 Jul