wxDbTable - Inner Join Topic is solved

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Post Reply
Thanksalot
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Feb 06, 2012 1:28 pm

wxDbTable - Inner Join

Post by Thanksalot »

Hello.
I'm here with a problem again, I just not get resolved. Unfortunately I am under extreme time pressure. So I would be incredibly grateful for a quick help :( Sorry and thanks you.

Table definition:

Code: Select all

	// Patch
	memset (&loc_Patch, 0, sizeof(loc_Patch));
	loc_Patch_table = new wxDbTable (db, _("Patch"), 7, _(""), _(""), wxDB_DEFAULT_CURSOR, _(""));
	col = 0;
	loc_Patch_table -> SetColDefs (col++, _("patchID"), DB_DATA_TYPE_INTEGER, &(loc_Patch.patchID), SQL_C_SLONG, sizeof(&(loc_Patch.patchID)), true, false, false);
	loc_Patch_table -> SetColDefs (col++, _("socketID"), DB_DATA_TYPE_INTEGER, &(loc_Patch.socketID), SQL_C_SLONG, sizeof(loc_Patch.socketID), false, true);
	loc_Patch_table -> SetColDefs (col++, _("switchID"), DB_DATA_TYPE_INTEGER, &(loc_Patch.switchID), SQL_C_SLONG, sizeof(loc_Patch.switchID), false, true);
	loc_Patch_table -> SetColDefs (col++, _("patchWire"), DB_DATA_TYPE_VARCHAR, &(loc_Patch.patchWire), SQL_C_WXCHAR, sizeof(loc_Patch.patchWire), false, true);
	loc_Patch_table -> SetColDefs (col++, _("patchPort"), DB_DATA_TYPE_VARCHAR, &(loc_Patch.patchPort), SQL_C_WXCHAR, sizeof(loc_Patch.patchPort), false, true);
	loc_Patch_table -> SetColDefs (col++, _("patchNetwork"), DB_DATA_TYPE_VARCHAR, &(loc_Patch.patchNetwork), SQL_C_WXCHAR, sizeof(loc_Patch.patchNetwork), false, true);
	loc_Patch_table -> SetColDefs (col++, _("patchUplink"), DB_DATA_TYPE_INTEGER, &(loc_Patch.patchUplink), SQL_C_SLONG, sizeof(loc_Patch.patchUplink), false, true);

	if (!loc_Patch_table->Open ())
	{
		wxLogError (_("Table Patch open fail"));
		return false;
	}
Query Building:

Code: Select all

wxString where, orderby, from;
where = _("Patch.socketID = Socket.socketID");
from = _("Socket");
orderby = _("");
patch = con->GetSDA_Patch(where, orderby, from);


tab_Patch *DBConnection::GetSDA_Patch (wxString where, wxString orderBy, wxString from) 
{ 
	tab_Patch *tmp = new tab_Patch; 
	memset(tmp, 0, sizeof (tab_Patch)); 
	loc_Patch_table -> SetWhereClause(where); 
	loc_Patch_table -> SetOrderByClause(orderBy); 
	loc_Patch_table -> SetFromClause(from); 
	if (!loc_Patch_table ->Query(false, true)) 
	{ 
               // HERE I GET IN, everytime
		wxMessageBox(_("error"));
	} 
	if (!loc_Patch_table ->GetNext()) 
	{ 
		delete tmp; 
		return 0; 
	} 
	memcpy(tmp, &loc_Patch  , sizeof (tab_Patch)); 
	memset(&loc_Patch, 0, sizeof (tab_Patch)); 
	return tmp; 
}
Table:

Code: Select all

Socket:
socketID
socketName

Patch:
patchID
socketID
...
Any idea or solution?

Thank you!
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDbTable - Inner Join

Post by doublemax »

I don't know this library and the syntax it uses. So just a wild guess:

Try this:

Code: Select all

from = _("Socket, Patch");
There should be a way to get the last SQL error message.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxDbTable - Inner Join

Post by PB »

I second doublemax. To get the error message produced by the SQL engine is the necessary first step. I don't know the library either, but there should be a way to peek at the final query string you built with those Set* calls and check if it is correct. I also find rather odd that you wrap database name and column names in _() calls, but I guess that's probably by design (or you don't load any localized message catalogues) so it's probably not a problem.
Thanksalot
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Feb 06, 2012 1:28 pm

Re: wxDbTable - Inner Join

Post by Thanksalot »

Thank you! It was just a query failure.. how depressing :? Thank you anyway... u helped me a lot!
Post Reply