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 |
|
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
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
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++
Mirek
|
|
|
|
|
SqlArray Join
By: rbmatt on Wed, 19 July 2006 02:47
|
|
|
Re: SqlArray Join
By: rbmatt on Wed, 19 July 2006 07:27
|
|
|
Re: SqlArray Join
By: mirek on Wed, 19 July 2006 11:11
|
|
|
Re: SqlArray Join
By: rbmatt on Wed, 19 July 2006 17:07
|
|
|
Re: SqlArray Join
By: mirek on Wed, 19 July 2006 17:13
|
|
|
Re: SqlArray Join
By: rbmatt on Wed, 19 July 2006 18:36
|
|
|
Re: SqlArray Join
By: mirek on Wed, 19 July 2006 21:17
|
|
|
Re: SqlArray Join
By: rbmatt on Wed, 19 July 2006 22:53
|
|
|
Re: SqlArray Join
By: mirek on Wed, 19 July 2006 23:48
|
|
|
Re: SqlArray Join
By: rbmatt on Thu, 20 July 2006 00:09
|
|
|
Re: SqlArray Join
By: rbmatt on Fri, 21 July 2006 06:35
|
|
|
Re: SqlArray Join
By: mirek on Fri, 21 July 2006 14:33
|
|
|
Re: SqlArray Join
By: rbmatt on Fri, 21 July 2006 17:16
|
|
|
Re: SqlArray Join
By: rbmatt on Sat, 22 July 2006 07:42
|
|
|
Re: SqlArray Join
By: forlano on Sat, 10 March 2007 18:44
|
|
|
Re: SqlArray Join
By: mirek on Sun, 23 July 2006 19:15
|
|
|
Re: SqlArray Join
By: rbmatt on Sun, 23 July 2006 19:49
|
Goto Forum:
Current Time: Sat Jun 15 22:40:25 CEST 2024
Total time taken to generate the page: 0.02682 seconds
|