DatabaseLayer commands out of sync

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
Gera555
Knows some wx things
Knows some wx things
Posts: 42
Joined: Mon Aug 02, 2010 11:49 am
Location: Ukraine, Odessa

DatabaseLayer commands out of sync

Post by Gera555 »

I use MySQL + DatabaseLayer. I've created Stored Procedure to calculate maximum used index(table name as parameter):

Code: Select all

CREATE DEFINER = 'usaw'@'%'
PROCEDURE rf_activity_map.procedure1(IN table_name VARCHAR(255))
BEGIN
  SET @dyn_sql=CONCAT('SELECT id FROM ',table_name,' WHERE id =(SELECT MAX( id ) FROM ',table_name,' )'); 
  PREPARE s1 from @dyn_sql;
  EXECUTE s1;
  DEALLOCATE PREPARE s1;
END
It works when I call it first time. But second time I receive error message: "commands out of sync you can't run this command now". Though I use CloseResultSet( result ).

Code: Select all

             std::wstringstream select_query;
             select_query <<_("CALL procedure1( '")<<table_name<< _("' );");
             DatabaseResultSet *result = 0;
	try
	{
		result = db->ExecuteQuery( select_query.str() );
	}
	catch(DatabaseLayerException & e)
	{
		wxUnusedVar( e );
		wxFAIL_MSG( e.GetErrorMessage() );
		return false;
	}

	bool res = true;
	if( result && result->Next() )
	{
		//some code
	}

	
	db->CloseResultSet( result );
I've tried to execute other queries. This lead to same error message. Though I can execute store procedure directly from MySQL.
Please advise how to handle this.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DatabaseLayer commands out of sync

Post by doublemax »

I don't really know a solution, but i can tell that i started a new project based on DatabaseLayer a few weeks ago and already regret it. It's pretty buggy and incomplete.

And it's not official part of wxWidgets. So you probably have to fix this problem yourself or try to find a way around it. Did you try the same without using stored procedures?
Use the source, Luke!
Gera555
Knows some wx things
Knows some wx things
Posts: 42
Joined: Mon Aug 02, 2010 11:49 am
Location: Ukraine, Odessa

Re: DatabaseLayer commands out of sync

Post by Gera555 »

Yes. And its works well. But customer demands Stored Procedures for performance.
Gera555
Knows some wx things
Knows some wx things
Posts: 42
Joined: Mon Aug 02, 2010 11:49 am
Location: Ukraine, Odessa

Re: DatabaseLayer commands out of sync

Post by Gera555 »

doublemax wrote:I don't really know a solution, but i can tell that i started a new project based on DatabaseLayer a few weeks ago and already regret it. It's pretty buggy and incomplete.

And it's not official part of wxWidgets. So you probably have to fix this problem yourself or try to find a way around it. Did you try the same without using stored procedures?
If not the secret. What did you use instead of DatabaseLayer?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: DatabaseLayer commands out of sync

Post by doublemax »

Code: Select all

If not the secret. What did you use instead of DatabaseLayer?
I'm still using it. The project is on a tight schedule and i can't switch at this point in time.

But i'll take a closer look at SOCI next time:
http://soci.sourceforge.net/
Use the source, Luke!
Post Reply