dbTalk Databases Forums  

Multi-Insert

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Multi-Insert in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark Merendino
 
Posts: n/a

Default Multi-Insert - 04-29-2005 , 03:24 PM






------_=_NextPart_001_01C54CF9.4482A372
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I noticed someone earlier asked about a mulit-insert. I have written
one since I needed it. Seems to work well. Much faster than doing a
loop of single inserts. Maybe it could be added to the library. If
not, at least people will have an example of how to do it. Note, It
expects to recieve a vector.
=20
// insert_multi expects a vector as input

template <class T> SQLQuery& insert_multi(const T &v) {

reset();

(static_cast<std::stringstream&>(*this)) << "INSERT INTO " <<
v[0].table() << " (" << v[0].field_list()

<< ") VALUES (" << v[0].value_list() << ")";

for (unsigned int i =3D 1; i < v.size(); i++)

{

(static_cast<std::stringstream&>(*this)) << ",(" << v[i].value_list() <<
")";

}

return *this;

}=20


------_=_NextPart_001_01C54CF9.4482A372--

Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: Multi-Insert - 04-29-2005 , 09:23 PM






Mark Merendino wrote:

Quote:
I noticed someone earlier asked about a mulit-insert.
It's on the Wishlist, actually. Since it seems you're on a roll, it has
many other tasty items awaiting your perusal.

Quote:
Maybe it could be added to the library.
Certainly. I plan to rework it to take a pair of iterators like STL
algorithms do, but other than that it looks good. Thanks!

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.