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 » SqlArray Join
Re: SqlArray Join [message #4112 is a reply to message #4108] Fri, 21 July 2006 14:33 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
OK, I hope I have found it.

The trouble is that bug exposes only in the start (you double-click on first record). I have tested after clicking to another row - there it was OK.

Anyway, the bug is caused by wrong placement of

	list.CListView.Query();


You are performing the query _before_ you join with detail. Query sets the cursor to the first row, means detail will not get loaded for this row....

Putting it at the end of constructor fixed the problem.

I have taken the oportunity a tried to improve the code a bit:

#include <CtrlLib/CtrlLib.h>
#include <SqlCtrl/SqlCtrl.h>
#include <plugin/Sqlite3/Sqlite3.h>

#define LAYOUTFILE <EzellApp4/EzellApp4.lay>
#include <CtrlCore/lay.h>

class EzellApp4 : public WithEzellApp4Layout<TopWindow> {
	WithListLayout<ParentCtrl> list;
	WithDetailLayout<ParentCtrl> detail;
	// The SQLite session

	// For editing
	EditDate editDate;
	EditString editDesc;
	EditString editCost;
	
public:
	typedef EzellApp4 CLASSNAME;
	void SwitchView();
	void CrossUpdate(int);
	EzellApp4();
};

void EzellApp4::CrossUpdate(int i)
{
	// In progress
	PromptOK("Yea, OK");
	list.CListView.Refresh();
}

EzellApp4::EzellApp4()
{
	// Setup the layouts
	CtrlLayout(*this, "Bean Heat and Air- Customer Files");
	CtrlLayout(list);
	CtrlLayout(detail);
	
	Sizeable();
	Zoomable();
	
	// Tell tab control what slave ctrls to use
	tab.Add(list, "Customers");
	tab.Add(detail, "Details");
	
	// Kinda dumb that we have to do this
	// isn't there a better way?
	SqlId JOBID("JOBID");
	SqlId NAME("NAME");
	SqlId CUSTOMER_ID("CUSTOMER_ID");
	
	// Setup primary customer list
	list.CListView.SetTable("CUSTOMERS");
	list.CListView.AddColumn("ID", "Id");
	list.CListView.HeaderObject().HideTab(0);
	list.CListView.AddColumn("NAME","Name");
	list.CListView.AddColumn("ADDRESS","Address");
	list.CListView.AddColumn("CSZ","City, State Zip");
	list.CListView.AddColumn("PHONE1","Phone 1");

	list.CListView.AddCtrl("NAME",list.strName1);
	list.CListView.AddCtrl("NAME", detail.strName);
	list.CListView.AddCtrl("ADDRESS", detail.strAddress);
	list.CListView.AddCtrl("CSZ", detail.strCSZ);

	list.CListView.SetOrderBy(NAME);
	list.CListView.WhenLeftDouble = THISBACK(SwitchView);
	
	detail.detailList.SetTable("JOBS");
	detail.detailList.AddColumn("JOBID","Id");
	detail.detailList.HeaderObject().HideTab(0);
	detail.detailList.AddColumn("DONEDATE","Date").Edit(editDate);
	detail.detailList.AddColumn("DESCRIPTION","Description").Edit(editDesc);
	detail.detailList.AddColumn("COST","Cost").Edit(editCost);
	detail.detailList.SetOrderBy(JOBID);
	detail.detailList.Join(CUSTOMER_ID, list.CListView);
	detail.detailList.Removing().Appending();

	list.CListView.Query();
}

void EzellApp4::SwitchView()
{
	tab.Set(1);
}

GUI_APP_MAIN
{
	Sqlite3Session session;

	if(!session.Open(ConfigFile("simple2.db"))) {
		Exclamation("Error opening the database file");
		return;
	}

#ifdef _DEBUG
	session.SetTrace();
	session.LogErrors(true);
#endif

	SQL = session;

	EzellApp4().Run();
}


Changes:

SqlDetails are really not necessary.

Most application do not use more than single DB engine, therefore it is a good ideal to define default session - you do not have to se it everywhere ("SQL=session").

Opening session in constructor is really bad thing Smile

BTW, is your database schema fixed in existing .db file, or is it a part of application you are developing? U++ has nice support for schemas... I would be happy to help you with that...

...because, in fact, it would not be a bad idea to finally add some nice SQL example to U++ Smile

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ODBC ?
Next Topic: MS SQL Server connection possible?
Goto Forum:
  


Current Time: Sat Jun 15 22:40:25 CEST 2024

Total time taken to generate the page: 0.02682 seconds