Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Tip of the Day --- Views (Part Four)
Message
From
28/09/1999 00:06:25
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Tip of the Day --- Views (Part Four)
Miscellaneous
Thread ID:
00269789
Message ID:
00269789
Views:
41
"I tell ya, Slim ... t'aint normal for dat to happen"

Never underestimate the power of a denormalized view. What is that you ask? Consider the following three tables (partial structures; don't email me about missing fields):

SalesHeader (headerPK C(10))
SalesDetail (headerfk C(10), lineno N(3,0), widgetfk C(10))
Widgets (widgetPK C(10), widgetdesc C(40), widgetcost N(7,2))

If you want to display a sales order with widget detail in, let's say, a grid, you're gonna want a view that looks like:

CREATE SQL VIEW lvSDetail AS ;
SELECT salesdetail.*,widgets.widgetdesc,widgets.widgetcost FROM salesdetail, widgets WHERE salesdetail.headerfk = ?salesheader.headerpk AND salesdetail.widgetfk = widgets.widgetpk

So, all is well and good and you put the view into the DE of a form and show it in a Grid. You get especially slick and use a Combobox to allow the user to change which widget it is for a given line.

What happens on the change? Nada to widgetdesc and widgetcost. These values are populated when the view is opened or refreshed. Changing the widget doesn't automatically update those values.

What to do? Well, for one, these values are for display purposes only. So, you only need them to be right until you issue a TABLEUPDATE, at which time the view resets and all is well.

So...in the InterActive change of the combobox, REPLACE widgetdesc and widgetcost with the equivalent values in widgets and refresh the Grid. The record pointer of widgets will be pointing at the right record so the replace will work fine. No mess, no fuss.

Just make sure you don't make these two fields updateable through the field Updateable property. Oy veh, what a mess if you do :-)
------------------------------------------------
John Koziol, ex-MVP, ex-MS, ex-FoxTeam. Just call me "X"
"When the going gets weird, the weird turn pro" - Hunter Thompson (Gonzo) RIP 2/19/05
Reply
Map
View

Click here to load this message in the networking platform