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++ Library : Other (not classified elsewhere) » Error in HomeBudget Example?
Error in HomeBudget Example? [message #29226] Tue, 12 October 2010 08:53 Go to next message
porto is currently offline  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 269 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 Go to previous messageGo to next message
mr_ped is currently offline  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 #29230 is a reply to message #29226] Tue, 12 October 2010 12:33 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

In latest upp I cannot reproduce this bug. Which version you have?
Re: Error in HomeBudget Example? [message #29233 is a reply to message #29230] Tue, 12 October 2010 13:16 Go to previous messageGo to next message
porto is currently offline  porto
Messages: 51
Registered: March 2007
Member
My UPP ver. is 2467 stable (Windows XP, MSC9), but this error occurs in ver. 2760 (when i use it on Ubuntu 10.10).

[Updated on: Tue, 12 October 2010 13:34]

Report message to a moderator

Re: Error in HomeBudget Example? [message #29234 is a reply to message #29226] Tue, 12 October 2010 14:03 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
I did reproduce it at 2769 SVN revision.
Re: Error in HomeBudget Example? [message #29235 is a reply to message #29234] Tue, 12 October 2010 14:53 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

[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

Re: Error in HomeBudget Example? [message #29240 is a reply to message #29235] Wed, 13 October 2010 08:37 Go to previous messageGo to next message
porto is currently offline  porto
Messages: 51
Registered: March 2007
Member
I found another bugs (maybe they came after the fix). The sequence of actions to reproduce (the screenshots is attached):
1. Switch to the "Categories" tab
2. Create any group
3. In the group create first category (e.g. "cat1")
4. Switch to the "Expenses" tab
5. Add a record with created category ("cat1") and any value (e.g. 100)
6. Switch to the "Categories" tab
7. In the created group, create second category (e.g. "cat2")
8. Switch back to the "Expenses" tab
9. Now we have the first bug! Our value in the created record is invisible (screenshot #4)
10. Then switch to the "Categories" tab and delete "cat2"
11. Switch back to the "Expenses" tab
12. Here is the second bug. Now, if you try to add a new record (or edit the created record) you will see that the deleted category still exists!

Sorry for bad English.


  • Attachment: 01.JPG
    (Size: 51.17KB, Downloaded 226 times)
  • Attachment: 02.JPG
    (Size: 50.43KB, Downloaded 220 times)
  • Attachment: 03.JPG
    (Size: 51.37KB, Downloaded 249 times)
  • Attachment: 04.JPG
    (Size: 49.13KB, Downloaded 230 times)
Re: Error in HomeBudget Example? [message #29246 is a reply to message #29240] Wed, 13 October 2010 09:17 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Both are fixed now. I'll update svn in the evening. Thank you for very good test cases!
Previous Topic: [FIXED]Case bug in X11Wnd.cpp
Next Topic: problem with fprintf
Goto Forum:
  


Current Time: Thu Mar 28 16:49:58 CET 2024

Total time taken to generate the page: 0.01356 seconds