Problem with parenthesis in __sql__

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

Postby Sten » Fri Jun 15, 2007 6:40 am

Hello Steve,

I am using a calculated field with 7.1.

Here is my statement
__sql__="select *, (quantite/nbre_poses)*nbre_pages as nbre_feuilles from fichestravaux"
all fields are on 1 as default and I tested to be sure the query is OK.

Although I have this error message
Cannot use a scalar value as an array in /var/www/html/dataface-0.7.1/Dataface/Table.php on line 1793
It is about the value of $data['columns']
Looking into the source I saw that there is a problme with parenthesis inside the query.

Please do you have any hunch ?

Kind regards
Jean
Sten
 
Posts: 10
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jun 15, 2007 10:53 am

Hi Jean,

Thanks for posting this.Ê The SQL parser class that I am using (based on the PEAR SQL_Parser class) doesn't handle arithmetic (e.g. (quantite/nbre_poses)*nbre_pages), unfortunately.Ê I have improved the class a great deal to make it handle most cases, but this one is remaining.

I would like to add this support but it will require a an evening of very fancy stepping to make it work.
For now, you can "cheat" by creating a dummy field, then implementing the %fieldname%__display() method to override the display value of the field.
e.g.
__sql__="select *, '' as nbre_feuilles from fichestravaux"
Then in your nbr_feuilles__display(&$record) method you would have:
(quantite/nbre_poses)*nbre_pages
function nbr_feuilles__display(&$record){
return ($record->val('quantite')/$record->val('nbre_poses'))*$record->val('nbre_pages'));
}
Hope this helps.
Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby meikel » Tue Jun 19, 2007 12:35 pm

Hi Steve,
I could only get this to work in using an existing field in the table (i.e. the ID number of every entry/row in the table) as a "dummy field". After that everything went as expected. With the "empty" query field ('' -- 2 Apostrophes) I only got an error messages in ../Dataface/Table.php on line 1789...

Kind regards
meikel



PS: Very powerful framework!!
meikel
 
Posts: 17
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Tue Jun 19, 2007 12:53 pm

Thanks for posting this Meikel.Ê Evidently there are some more things that need to be touched up in the SQL parser - but your solution looks like a good one in the mean time.

-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
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 35 guests

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