TOPIC: Stored Dependencies
#900
Stored Dependencies 3 Years, 3 Months ago
It's me again. My new question is about stored dependencies. As I understand (correct me if I wrong), stored dependence is a "signal" for database engine that some field HAS dependencies. Technically it is made with creating the field which name is the same as the first field but with the "_deps" suffix. But what is more? How could database 'knows' which field or fields our field is depended on?

Taking our old 'invoice' and 'invoicelines'. I've slightly modified it and add field 'total price' (i.e. qty * price) in table structure:

Code:

create invoicelines (invoice, line_num, price, product, qty, Total_price)
    index(invoice) in invoice cascade
    key(line_num)



(field total_price is capitalized so it doesn't actually stored in table) and use a rule to calculate it:

Code:

Rule_total_price
function()
    {
    return Number(.qty) * Number(.price)
    } 



It works OK and every time I change the price or qty database engine recalcs total_price (without dependencies at all). But now I want to have a field in header table which summarize the 'total_price' on each line.

I use a query: alter invoice create (Invoice_total_price) and use a rule for it:

Code:

function()
{
return QueryTotal("invoicelines where invoice is " $ String (.invoice_main), "total_price"');
}



That works but partially. Then you browse from record to record, invoice_total_price is calculated OK, but if you are making changes (i.e. add a delete rows, change qty or price), invoice_total_price doesn't reflect it. But if you press Prev, then Next database calculates it again.

So, problem is that Invoice_total_price has no dependencies (it depends on total_price, but Suneido "doesn't know it"). But then I create the stored dependences (alter invoice create (invoice_total_price_deps)) nothing changes.

My questions are:

1) what to do with that dependensies?
2) why total_price rule works without dependensies and invoice_total_price doesn't work?
 
 
#903
Re:Stored Dependencies 3 Years, 3 Months ago
Suneido determines dependencies by tracking which other members a rule accesses (when it is triggered). It does not track dependencies on external data like queries.

Your rule should be totaling up .browse_data, not using a query. This will handle making changes. To explore this, use Inspect or put an error in the rule to get the debugger.

NOTE: This means the rule will only work in the Access since elsewhere you will not have browse_data. You can handle this be defining a rule that returns browse_data if it exists or otherwise does a query like yours.

You do not need _deps fields for rule fields (capitalized when created). Since the values are not stored, the rule will always be triggered (when referenced) and this will determine the dependencies.

It might help to review the help for Database > Rules and some of the other sections it references. (Although I am sure it does not explain everything perfectly.)

Post edited by: andrew, at: 2007/05/09 20:46
 
 
andrew