Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » OkCommit problem
OkCommit problem [message #5134] Wed, 06 September 2006 18:53 Go to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
The problem is this method:
bool OkCommit(SqlSession& session, const char *msg) {
	if(ErrorRollback(session, msg))
		return false;
	session.Commit();
	return true;
}


In the case of unsuccessful commit, nothing happens. This way it is very hard to detect the problem, because the next execution generates an error.

So I changed the method to this:

bool OkCommit(SqlSession& session, const char *msg) {
	if(ErrorRollback(session, msg))
		return false;
	do{
		session.Commit();
		if(!session.WasError())
		{
			session.ClearError();
			return true;
		}
	}while(IDRETRY==SqlError(t_("Unable to commit changes to database."), session, true));		
	return false;
}
Re: OkCommit problem [message #5135 is a reply to message #5134] Wed, 06 September 2006 19:51 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Seems like a good idea. However, "Retry" is a bit strange IMO - if you are not able to commit, there is something pretty wrong with your database connection...

Maybe, in that case, application abort would be in place.

Mirek
Re: OkCommit problem [message #5136 is a reply to message #5135] Wed, 06 September 2006 20:37 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
luzr wrote on Wed, 06 September 2006 19:51

Seems like a good idea. However, "Retry" is a bit strange IMO - if you are not able to commit, there is something pretty wrong with your database connection...

Maybe, in that case, application abort would be in place.

Mirek


Yes, you are right. I changed it to this:
bool OkCommit(SqlSession& session, const char *msg) {
	if(ErrorRollback(session, msg))
		return false;
	session.Commit();
	if(session.WasError())
		return false;
	session.ClearError();
	return true;
}

Application abort would be too drastic, I think, because this is one of the connections only. Programmer can use return value of OkCommit().
Re: OkCommit problem [message #5137 is a reply to message #5136] Wed, 06 September 2006 20:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, this is a bit confused... ClearError when there is no error? Should not be there warning message and then ClearError in case of failure?

As for abort/not abort, for some time I am thinking about some form of option that would abort SQL app in this and other cases, well, basically, after any unsuccesful unrecovered (by rollback) DML command. Checking for return code after each command is tedious (I usually just call OkCommit at the end of processing and rarely check the result).

Mirek
Re: OkCommit problem [message #5138 is a reply to message #5137] Wed, 06 September 2006 21:53 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
Yes maybe raising an Exception would be good here. What do you think about it?

[Updated on: Wed, 06 September 2006 21:54]

Report message to a moderator

Re: OkCommit problem [message #5171 is a reply to message #5138] Sat, 09 September 2006 12:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, for now:

bool OkCommit(SqlSession& session, const char *msg) {
	if(ErrorRollback(session, msg))
		return false;
	session.Commit();
	if(ShowError(session, msg ? msg : t_("SQL error!")))
		return false;
	return true;
}



Raising exception is a good idea. But I wish to have that configurable... (return false/raise exception/abort).

Mirek
Re: OkCommit problem [message #5255 is a reply to message #5171] Mon, 11 September 2006 16:06 Go to previous message
zsolt is currently offline  zsolt
Messages: 697
Registered: December 2005
Location: Budapest, Hungary
Contributor
Thanks, this should be good enough, I think.
Previous Topic: Can I create DBF files?
Next Topic: MySqlSession::EnumTables -> why uppercase?
Goto Forum:
  


Current Time: Sun Apr 28 21:20:57 CEST 2024

Total time taken to generate the page: 0.04244 seconds