dbTalk Databases Forums  

Transactions with MySQLPP

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


Discuss Transactions with MySQLPP in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tim Murison
 
Posts: n/a

Default Transactions with MySQLPP - 04-04-2005 , 06:22 PM






Hi all,

I was wondering if MySQLPP supports some kind of mechanism to do
transactions.
I don't need to be able to roll-back (though it could be cool), I just
want a clean way to say:

start_transaction
{ do stuff }
if failure then roll back everything
else exit_success

Cheers,

-Tim


--
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
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: Transactions with MySQLPP - 04-05-2005 , 07:15 AM






Tim Murison wrote:

Quote:
I was wondering if MySQLPP supports some kind of mechanism to do
transactions.
Not right now. Patches thoughtfully considered.

--
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
  #3  
Old   
Warren Young
 
Posts: n/a

Default Re: Transactions with MySQLPP - 04-05-2005 , 07:21 AM



Warren Young wrote:

Quote:
Tim Murison wrote:

I was wondering if MySQLPP supports some kind of mechanism to do
transactions.


Not right now. Patches thoughtfully considered.
I've thought some more about it, and this is definitely v1.8 or v2.0
material. Here's what I just added to the Wishlist:

Quote:
Transaction support. Considering block-level semantics: create a
"transaction object" on the stack, which takes a ref to the
Connection object (?) as a ctor parameter. Transaction object's ctor
calls a function on the conn telling it to tell the server to begin a
transaction set. When the transaction object is destroyed, it tells
the conn object to commit everything. Conn object in this situation
must be created in a higher scope, or on the heap.
That shouldn't be too difficult to do, nor should it be very intrusive
to the current library design. I'm thinking 1.8.

--
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
  #4  
Old   
Steve Roberts
 
Posts: n/a

Default RE: Transactions with MySQLPP - 04-05-2005 , 09:52 AM



However, the underlying SQL itself will support transactions:

query << "START TRANSACTION";
query.execute();
query.reset();
query << // your update here
query.execute();
query.reset();
query << "COMMIT"
query.execute();=20

Quote:
-----Original Message-----
From: Warren Young [mailto:mysqlpp (AT) etr-usa (DOT) com]=20
Sent: Tuesday, April 05, 2005 5:15 AM
To: MySQL++ Mailing List
Subject: Re: Transactions with MySQLPP
=20
Tim Murison wrote:
=20
I was wondering if MySQLPP supports some kind of mechanism to do=20
transactions.
=20
Not right now. Patches thoughtfully considered.
=20
--=20
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: =20
http://lists.mysql.com/plusplus?unsu...) f5 (DOT) com
=20
=20
--
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
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: Transactions with MySQLPP - 04-05-2005 , 11:03 AM



Steve Roberts wrote:

Quote:
However, the underlying SQL itself will support transactions:
Right. Automating that syntax is essentially what my proposed feature
would do.

--
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
  #6  
Old   
Tim Murison
 
Posts: n/a

Default RE: Transactions with MySQLPP - 04-11-2005 , 04:22 PM



On Tue, 2005-05-04 at 07:52 -0700, Steve Roberts wrote:
Quote:
However, the underlying SQL itself will support transactions:

query << "START TRANSACTION";
query.execute();
query.reset();
query << // your update here
query.execute();
query.reset();
query << "COMMIT"
query.execute();
Thanks... I went with this method...

At first it seemed to work but when running my program through a full
test suite, I noticed that I got failed transactions.
One in particular has me stumped, it fails on a foreign key
constraint... the perculiar thing is that if I manually enter the same
queries through the command line, it works!

The only thing I notice that your example does that I don't is
query.reset() instead of creating a new query each time... could this be
significant?

Cheers,

-Tim


--
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
  #7  
Old   
Steve Roberts
 
Posts: n/a

Default RE: Transactions with MySQLPP - 04-11-2005 , 04:29 PM



All query.reset() does is clear the underlying stringstream object. So
long as you reset after execution it "should" work, unless you're trying
to get something out of a select statement as you go.

I claim no particular expertise on mysql++, I was just trying to pass
along something I discovered in the process of developing our
application. So far we've had good luck with this method.

Quote:
-----Original Message-----
From: Tim Murison [mailto:tmurison (AT) primus (DOT) ca]=20
Sent: Monday, April 11, 2005 2:20 PM
To: Steve Roberts
Subject: RE: Transactions with MySQLPP
=20
On Tue, 2005-05-04 at 07:52 -0700, Steve Roberts wrote:
However, the underlying SQL itself will support transactions:
=20
query << "START TRANSACTION";
query.execute();
query.reset();
query << // your update here
query.execute();
query.reset();
query << "COMMIT"
query.execute();
=20
Thanks... I went with this method...
=20
At first it seemed to work but when running my program=20
through a full test suite, I noticed that I got failed transactions.
One in particular has me stumped, it fails on a foreign key=20
constraint... the perculiar thing is that if I manually enter=20
the same queries through the command line, it works!
=20
The only thing I notice that your example does that I don't is
query.reset() instead of creating a new query each time...=20
could this be significant?
=20
Cheers,
=20
-Tim
=20
=20
--
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
  #8  
Old   
Tim Murison
 
Posts: n/a

Default RE: Transactions with MySQLPP - 04-11-2005 , 04:34 PM



Quote:
All query.reset() does is clear the underlying stringstream object. So
long as you reset after execution it "should" work, unless you're trying
to get something out of a select statement as you go.

I claim no particular expertise on mysql++, I was just trying to pass
along something I discovered in the process of developing our
application. So far we've had good luck with this method.
Thx,

One final question...
I am creating one query object for each query in the transaction so:

Query q = con.query();
q << ...
Query q2 = con.query();
....

Would that make a difference? (P.S. It isn't as simple as what I wrote,
but that is basically the effect.)

Also, within a transaction I have some SELECT statements, so I use
query.store(); for those, could that make a difference?

Cheers,

-Tim

Quote:
-----Original Message-----
From: Tim Murison [mailto:tmurison (AT) primus (DOT) ca]
Sent: Monday, April 11, 2005 2:20 PM
To: Steve Roberts
Subject: RE: Transactions with MySQLPP

On Tue, 2005-05-04 at 07:52 -0700, Steve Roberts wrote:
However, the underlying SQL itself will support transactions:

query << "START TRANSACTION";
query.execute();
query.reset();
query << // your update here
query.execute();
query.reset();
query << "COMMIT"
query.execute();

Thanks... I went with this method...

At first it seemed to work but when running my program
through a full test suite, I noticed that I got failed transactions.
One in particular has me stumped, it fails on a foreign key
constraint... the perculiar thing is that if I manually enter
the same queries through the command line, it works!

The only thing I notice that your example does that I don't is
query.reset() instead of creating a new query each time...
could this be significant?

Cheers,

-Tim




--
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.