Home » U++ Library support » U++ SQL » SqlCtrls and IsModified()
|
|
|
Re: SqlCtrls and IsModified() [message #26988 is a reply to message #26978] |
Thu, 17 June 2010 09:38 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
kropniczki wrote on Wed, 16 June 2010 08:14 | Ok. It didnīt work for me in the beggining, but now I see why:
after some more code diving Iīve seen you gotta call SqlCtrls::ClearModify() right after you SqlCtrls::Load(...) your Ctrl set, or it ainīt gonna work. I must have somewhat assumed that fresh SqlCtrls::Load calls would somehow automatically reset some modification flag internally to the SqlCtrls object. But then again I see this SqlCtrls::ClearModify() method and got a wakeup call, which makes me feellike 'why-havenīt-you-seen-it-before?'.
Anyway, this might come up as somebody else's doubt too, so I thought I should post it.
Sorry for taking up your time...
Many thanks!
|
Actually, it somewhat comes to my surprise you bother to test it at all.
Usually, I am using SqlCtrls for dialog that edits some database row. Then it is simply, if user presses OK I do update...
BTW, my usual set of methods looks something like this:
PriceEntryDlg::PriceEntryDlg()
{
CtrlLayoutOKCancel(*this, "Entry");
ctrls
(IMPRESSIONS, impressions)
(REGION, region)
(DURATION, duration)
(PRICE, price)
;
}
void ProductSchemaDlg::NewPe()
{
if(!product.IsCursor())
return;
PriceEntryDlg dlg;
if(dlg.Execute() == IDOK) {
SQL * dlg.ctrls.Insert(PRICE)(PRODUCT_ID, product.GetKey());
int id = SQL.GetInsertedId();
price.ReQuery();
price.FindSetCursor(id);
}
}
void ProductSchemaDlg::EditPe()
{
int id = price.GetKey();
if(IsNull(id))
return;
PriceEntryDlg dlg;
dlg.ctrls.Load(PRICE, ID == id);
if(dlg.Execute() == IDOK) {
SQL * dlg.ctrls.Update(PRICE).Where(ID == id);
price.ReQuery();
}
}
where product is master SqlArray and price is the SqlArray of those edited rows.
Mirek
|
|
|
Re: SqlCtrls and IsModified() [message #26997 is a reply to message #26988] |
Sat, 19 June 2010 20:01 |
|
bushman
Messages: 134 Registered: February 2009
|
Experienced Member |
|
|
I guess I see what you mean.
In my app context, however, Iīm using push buttons on the main window to load table rows to a SqlCtrls set, so that users can navigate back and forth along the db table lines and alter them if desired. Thatīs why I must check whether changes occurred when moving from one row to the next and update them if thatīs been the case.
In my app thereīs no master SqlArr for users to pick a line from, for then editting the selected row in a SqlCtrls set in a pop-up dlg. Instead, it goes like,
SqlCtrls ctrls;
Value currendId; // -> pointer to table row key id
...
ctrls
(ID, idedit)
(FIELD1, field1edit)
...
(FIELDN, fieldnedit)
;
...
forwardbutton <<= THISBACK(MoveForward);
...
void MoveForward()
{
if(ctrls.IsModified())
SQL * ctrls.Update(TABLE).Where(ID == currentId);
SQL * Select(SqlMin(ID)).From(TABLE).Where(ID > currentId));
if(SQL.Fetch())
currentId = SQL[0];
ctrls.Load(SQL, TABLE, ID == currentId);
ctrls.ClearModify(); // <-- reset modify flag
}
Thanks!
[Updated on: Sat, 19 June 2010 20:57] Report message to a moderator
|
|
|
Re: SqlCtrls and IsModified() [message #27002 is a reply to message #26997] |
Sun, 20 June 2010 17:53 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
kropniczki wrote on Sat, 19 June 2010 14:01 | I guess I see what you mean.
In my app context, however, Iīm using push buttons on the main window to load table rows to a SqlCtrls set, so that users can navigate back and forth along the db table lines and alter them if desired. Thatīs why I must check whether changes occurred when moving from one row to the next and update them if thatīs been the case.
In my app thereīs no master SqlArr for users to pick a line from, for then editting the selected row in a SqlCtrls set in a pop-up dlg. Instead, it goes like,
SqlCtrls ctrls;
Value currendId; // -> pointer to table row key id
...
ctrls
(ID, idedit)
(FIELD1, field1edit)
...
(FIELDN, fieldnedit)
;
...
forwardbutton <<= THISBACK(MoveForward);
...
void MoveForward()
{
if(ctrls.IsModified())
SQL * ctrls.Update(TABLE).Where(ID == currentId);
SQL * Select(SqlMin(ID)).From(TABLE).Where(ID > currentId));
if(SQL.Fetch())
currentId = SQL[0];
ctrls.Load(SQL, TABLE, ID == currentId);
ctrls.ClearModify(); // <-- reset modify flag
}
Thanks!
|
Something similar SqlArray can do for automagically. Just use AddCtrl method (of ArrayCtrl).
In fact, SqlCtrls were sort of derived from this arrangement to have something similar in dialogs.
Mirek
|
|
|
Goto Forum:
Current Time: Fri Sep 20 04:58:57 CEST 2024
Total time taken to generate the page: 0.03630 seconds
|