calculated fields error

A place for users and developers of the Xataface to discuss and receive support.

calculated fields error

Postby ststoddard » Fri Nov 16, 2007 12:55 pm

Hello,

I am attempting a calculated field using the __sql__ construct in the fields.ini file:

Code: Select all
__sql__ = "SELECT p.*,datediff(curdate(),birthdate) as age from Participants as p"


However, I get the following error:
Fatal error: Cannot use object of type PEAR_Error as array in /var/www/private/dataface/Dataface/Table.php on line 1789


If I just use curdate() it works, however other expressions (e.g. curdate()-birthdate) do not.

???
S. T. Stoddard
ststoddard
 
Posts: 56
Joined: Mon Nov 05, 2007 4:10 pm
Location: Davis, CA

Postby shannah » Fri Nov 16, 2007 1:47 pm

Hi Stephen,

Unfortunately dataface uses an SQL parser based on the PEAR SQL_Parser class. I have made numerous improvements to it to support most cases, however it doesn't handle arithmetic in the SQL query... it's on a todo list, but I'm not looking forward to re-opening that can of worms...

Best regards

Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby ADobkin » Mon Nov 26, 2007 2:02 pm

What is the best workaround in this situation? Should we use views instead, and let MySQL do the calculations there, or is there a better method?
ADobkin
 
Posts: 195
Joined: Mon Oct 22, 2007 7:31 pm
Location: Atlanta, GA, USA

Postby shannah » Mon Nov 26, 2007 2:08 pm

Certainly using a view is one workaround. As Stephen mentioned, using the datediff() SQL function should work. It is just the use of arithmetic operators (e.g. +, *, /, -) that the parser doesn't handle currently.

Another workaround is to just use a dummy field and then override the xxx__display() method to display the calculation that you require.

http://xataface.com/forum/viewtopic.php?t=4057#20393

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved