Hi Guys,
Im a FileMaker developer, converting one of my database apps into LiveCode and SQLite. One of the things we have in FileMaker are calculated fields, so if I had a field called price and a field called qty, I can create a calculated field called total_price and put the formula price*qty. Sql doesnt have this feature probably for performance, but whats the best way to replicate this kind of behaviour in LiveCode?
Do I create a standard integer field in my SQLite database and run an update query every time the user focus's out of the price or qty field? Just wondering regarding the integrity of the data, if one update for whatever reason dodnt get published the data will be out of sync.
Another thing I have noticed in my SQL UI (Im using Navicat essentials) is something called Triggers and Queries. I'm wondering whether I should be using these trigger updates, but then these update/trigger when I write to the where as I want the total price displayed when the user is keying in price and qty details.
Whats the best way to approach this, many thanks as always
Jalz
Creating calculated field behaviour
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 10053
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Creating calculated field behaviour
In LiveCode, actions are triggered by messages. In the Dictionary you can use the filters on the left side, selecting "Message" to get a list of all messages LiveCode sends to its objects.
If you want to trigger an action when the contents of a field is changed, you may want to use a textChanged handler in that field.
If you want to trigger an action when the contents of a field is changed, you may want to use a textChanged handler in that field.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Creating calculated field behaviour
Hi Jalz,
SQL does have the ability to do that:
SELECT (price * qty) as total_price FROM myTable
I'd recommend doing that rather than using triggers to calculate total_price.
That works when you're retrieving the data for display but you still have to do the calculation yourself with Livecode when they change either qty or price or add a new row to the table, assuming you want them to see the result before the database is updated, and Richard's reply points you in the right direction for that.
Pete
SQL does have the ability to do that:
SELECT (price * qty) as total_price FROM myTable
I'd recommend doing that rather than using triggers to calculate total_price.
That works when you're retrieving the data for display but you still have to do the calculation yourself with Livecode when they change either qty or price or add a new row to the table, assuming you want them to see the result before the database is updated, and Richard's reply points you in the right direction for that.
Pete