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 » Application crashes when connected to MySQL, what am I doing wrong?
Application crashes when connected to MySQL, what am I doing wrong? [message #45113] Thu, 03 September 2015 17:07 Go to next message
Giorgio is currently offline  Giorgio
Messages: 184
Registered: August 2015
Experienced Member
Hi there,
I have been learning ultimatepp for a couple of weeks now, so I am kinda of a noob. My application communicates with a MySQL server. Usually I create a connection to the server each time I need data. I put each query in a separate method. The code goes like this:

void MyApplication::MyQuery1()
{
	MySqlSession session;
	if(session.Connect("Userfoobar", "secret", "mydb","192.168.1.1",3306))
	{
		SQL = session;		
		SqlSchema sch(MY_SQL);
		All_Tables(sch);
		SQL.ClearError();
		try {
			//Here's my query
                        int ritorno = Select(SqlSum(N_BOB))
			.From(PEZZATURE)
			.Where( COMM == ~dlgSceltaPezzature.strLav3A );

		} catch(SqlExc &err) {
			Cerr() << "ERROR: " << err << "\n";
			ErrorOK("Problem retrieving data: " + session.GetLastError());
			SetExitCode(1);
		}
	}
	else {
		ErrorOK("Connection to the db failed: " + session.GetLastError());
		SetExitCode(1);
	}
}


Note that the connection is not closed, but this has been worked well for me.

Today I experienced some unexpected crashes of my application. After some investigation, I noticed that the problem happens when pressing a specific button. This button executes some instructions including two different calls to two procedures similar to the one above, let's call them Myquey1 and Myquery2. If I comment out one of the two procedures, the application does not crash. Is not important which one I comment out, the important is that only one of the procedures is called, if I call both the application crashes. So, to me, the problem is not the procedure itself.

I thought that the problem was the fact that I do not close the connection, so I added the following line in each procedure:

if(session.IsOpen()) { session.Close(); }


but the problem is still there.

Could someone help me on this?
Regards,
Giorgio
Re: Application crashes when connected to MySQL, what am I doing wrong? [message #45129 is a reply to message #45113] Thu, 10 September 2015 08:24 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 184
Registered: August 2015
Experienced Member
I managed to fix that. The problem was that I opened a new connection on each procedure. I just moved the code for opening the connection on the GUI_APP_MAIN and scraped from the procedure and the problem was solved. Not sure why this made the application crash, though.
Re: Application crashes when connected to MySQL, what am I doing wrong? [message #45137 is a reply to message #45113] Mon, 14 September 2015 08:33 Go to previous message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
void MyApplication::MyQuery1()
			//Here's my query
                        int ritorno = Select(SqlSum(N_BOB))
			.From(PEZZATURE)
			.Where( COMM == ~dlgSceltaPezzature.strLav3A );


Not that this is not correct. This is not executing query, just creates Select structure and converts it to bool (->true -> 1).

You should use something like

void MyApplication::MyQuery1()
			//Here's my query
                        int ritorno = my_sql_session % Select(SqlSum(N_BOB))
			.From(PEZZATURE)
			.Where( COMM == ~dlgSceltaPezzature.strLav3A );


Anyway, as for your original problem, hard to say what was causing the issue. Technically, creating session for each query should work. However, it is not a good idea at all, usually creating (and destroying) session takes certain amount of time, so it is ineffective.

As 90% of applications work with just single SQL backend, we have that global SQL session support....

Mirek
Previous Topic: Accessing Database from multiple files
Next Topic: PATCH/BUGFIX Oracle global temporary table
Goto Forum:
  


Current Time: Wed Nov 20 13:46:47 CET 2019

Total time taken to generate the page: 0.02776 seconds