Creating calculated field behaviour

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Creating calculated field behaviour

Post by jalz » Sat Oct 26, 2013 8:59 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Creating calculated field behaviour

Post by FourthWorld » Sat Oct 26, 2013 5:27 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Creating calculated field behaviour

Post by phaworth » Tue Oct 29, 2013 10:48 pm

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

Post Reply