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 » SqlCtrls and IsModified()
SqlCtrls and IsModified() [message #26970] Wed, 16 June 2010 06:15 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Iīd like to use Upp::SqlCtrls to submit database table field contents for user edition and SqlUpdate the db ONLY if the user changes any of the field values.
What does method Upp::SqlCtrls::IsModified() do?
Is it to point whether a user edited any of the Ctrl contents in a SqlCtrls set?
In other words, how do I check whether a user changed the contents of any of the Ctrls of a given SqlCtrls set?
Do I have to compare one by one with their previous db values upon usersī SqlCtrls submission?

Thanks!
Re: SqlCtrls and IsModified() [message #26973 is a reply to message #26970] Wed, 16 June 2010 07:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kropniczki wrote on Wed, 16 June 2010 00:15

Iīd like to use Upp::SqlCtrls to submit database table field contents for user edition and SqlUpdate the db ONLY if the user changes any of the field values.
What does method Upp::SqlCtrls::IsModified() do?
Is it to point whether a user edited any of the Ctrl contents in a SqlCtrls set?



Yes.

Mirek
Re: SqlCtrls and IsModified() [message #26978 is a reply to message #26973] Wed, 16 June 2010 14:14 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
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!
Re: SqlCtrls and IsModified() [message #26988 is a reply to message #26978] Thu, 17 June 2010 09:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
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 Go to previous messageGo to next message
bushman is currently offline  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 Go to previous message
mirek is currently offline  mirek
Messages: 13975
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
Previous Topic: Multiple schema files?
Next Topic: MySQL bug: Missing FIELD_TYPE_TIMESTAMP
Goto Forum:
  


Current Time: Fri Apr 19 09:36:11 CEST 2024

Total time taken to generate the page: 0.02099 seconds