8 messages in com.mysql.lists.plusplusRe: change everything in a table
FromSent OnAttachments
Charles Ouimet24 May 2001 13:38 
Thomas Engman25 May 2001 08:14 
Charles Ouimet25 May 2001 09:22 
Denis Rampnoux26 May 2001 02:57 
TdC26 May 2001 09:05 
Charles Ouimet28 May 2001 03:58 
Benjamin Pflugmann28 May 2001 05:43 
Charles Ouimet28 May 2001 05:46 
Subject:Re: change everything in a table
From:Charles Ouimet (char@analysco.com)
Date:05/28/2001 05:46:30 AM
List:com.mysql.lists.plusplus

I apologize, I gave a bad answer...

Thanx Benjamin for the correction.

-C

At 14:44 2001-05-28 +0200, Benjamin Pflugmann wrote:

Hello.

I never used the MySQL C++ API until now, so take my comments with a grain of salt.

On Mon, May 28, 2001 at 06:58:33AM -0400, you wrote

Use "servers row = res[i];" instead of "servers row = res[0];". (You're not using the iterator at all in your loop...)

Iterators are usually used like pointers, so I assume res[i] won't probably work with MySQL++ either.

The usual usage is "row = *i".

Tip: You can directly use an "UPDATE" command instead of a select to go through every row in your table.

Ex: Query query = con.query(); query << "UPDATE SERVERS SET spliton=1"; query.eecute();

-C

At 18:06 2001-05-26 +0200, TdC wrote:

Hey, is there an easy way to change 1 field in every row of a table to the same value? i'm having some trouble doeing this :( and the example doesn't exmplain alot so i dun fully understand it right now i'm trying with Connection con(use_exceptions); con.connect(db,dbhost,dblogin,dbpass); Query query = con.query(); query << "select * from servers"; Result res = query.store(); Result::iterator i; for (i = res.begin(); i != res.end(); i++) { servers row = res[0]; servers row2 = row; row.spliton = 1; query.update(row2, row); query.execute(); }

So, this loop would look like

{ servers original = *i; i->spliton = 1; query.update(orignal, *i); query.execute(); }

Of course, solving the problem with the UPDATE above is the better method, I only corrected the loop for illustration purposes.

Bye,

Benjamin.

----------------------------------------- Charles Ouimet char@analysco.com

(514) 577-5614 http://www.analysco.com

-----------------------------------------