|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Error in HomeBudget Example?
Error in HomeBudget Example? [message #29226] |
Tue, 12 October 2010 08:53 |
porto
Messages: 51 Registered: March 2007
|
Member |
|
|
When I try to add a new category, I get an error (screenshot is attached). That's what I found out, the error occurs somewhere in here:
void HomeBudget::UpdateCategories()
{
category.Clear(); // If I remove this line, error does not occur.
SQL & Select(ID.Of(CATEGORIES), NAME.Of(CATEGORIES), NAME.Of(GROUPS))
.From(CATEGORIES, GROUPS)
.Where(GR_ID == ID.Of(GROUPS))
.OrderBy(NAME.Of(GROUPS), NAME.Of(CATEGORIES));
while(SQL.Fetch())
category.Add(SQL[0], Format("%s - %s", SQL[2], SQL[1]));
}
Sorry for bad English.
-
Attachment: hb_error.PNG
(Size: 19.13KB, Downloaded 271 times)
[Updated on: Tue, 12 October 2010 08:58] Report message to a moderator
|
|
|
Re: Error in HomeBudget Example? [message #29228 is a reply to message #29226] |
Tue, 12 October 2010 10:14 |
mr_ped
Messages: 825 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
It's actually enough to go into Options -> Clear all data from database.
There's some callback during clear to "HomeBudget::UpdateValue()" which does try to get value from empty money grid.
But as I'm not author of any of used classes, I have no idea what went really wrong.
I did try to understand the code, but both DropGrid and GridCtrl do use "rowid = -1;" for very long time, and ignore such option in Get/Set/operator() code, so it's probably desired behavior, and it's the HomeBudget usage of DropGrid exposing this behavior.
(but I think this is not very robust design, using invalid value as "empty" and don't handle it later in Get).
Adding
void HomeBudget::UpdateValue()
{
if ( money.GetCount() <= 0 ) return; //added
try
will fix the crashes and it looks like everything else works, but I don't understand the code and I have no idea what else I may have break.
Also I noticed other HomeBudget bug:
Add the category (both the left thing and right thing, although from the UI I have no idea what is what and for what).
Now click on the left one, and choose to remove, you will get correct "You can't remove this group, it's not empty...".
But now the box on right is disabled, so you can't actually remove the content of the group. (without restarting the app)
|
|
|
|
|
|
Re: Error in HomeBudget Example? [message #29235 is a reply to message #29234] |
Tue, 12 October 2010 14:53 |
|
[quote title=mr_ped wrote on Tue, 12 October 2010 08:03]Ok I was finally able to repeat it too. Mr Ped fix is correct, however I would write it a little bit different:
void HomeBudget::UpdateValue()
{
if(money.IsEmpty())
return;
try
{
SQL & Select(DEFVALUE).From(CATEGORIES).Where(ID == money.Get(CAT_ID));
Value v = SQL.Fetch() ? SQL[0] : Value(0);
money.Set(VALUE, v);
money.Set(PM, GetCategorySign());
}
catch(SqlExc &e)
{
Exclamation("[* " + DeQtfLf(e) + "]");
}
}
The second bug fix. Replace RemoveGroup with this code:
void HomeBudget::RemoveGroup()
{
if(categories.IsEmpty())
{
SQL & Delete(GROUPS).Where(ID == groups(ID));
if(groups.GetCount() == 1)
categories.Disable();
}
else
{
PromptOK(t_("You can't remove this group. It is not empty."));
groups.CancelRemove();
}
}
I'll push changes to the main repo in the evening. Thank you both!
@Mr.Ped - Get was never supposed to be safe. IMO retrieving value from not existing row doesn't make sense and grid should crash. Returning Null (or any other value) could lead to errors that are hard to find.
[Updated on: Tue, 12 October 2010 15:08] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 24 13:25:43 CEST 2024
Total time taken to generate the page: 0.01847 seconds
|
|
|