Where is where [message #2229] |
Sat, 18 July 2009 04:22 |
edortizq
Messages: 82 Registered: August 2008 Location: Ecuador
|
Member |
|
|
I've created a new class (with no phisycal file on db), this class have a select from 4 tables (files .class and .dict attached); when I instance the class the fields in where clause requires must be qualificated, if not, it gives an error on the SQL sentence execution; when the fields are qualificated the where clause of the query dissapears.
That's the query
$object =& singleton::getInstance('evento_informe_resumen_q1');
$_idevento = $fieldarray['idevento'];
$object->sql_orderby = 'descripcionlocalidad';
$object->sql_where .= 'ti.idevento= '.$_idevento.' and tm.idtipomovimiento = 1';
$outarray = $object->getData();
And the sql log records this:
SELECT SQL_CALC_FOUND_ROWS lo.idlocalidad, lo.descripcionlocalidad, ti.idevento, lt.idtipomovimiento, tm.descripciontipomovimiento, count(*) as ingresos FROM localidad lo left join tarifa ta on lo.idlocalidad = ta.idlocalidad left join ticket ti on ta.idtarifa = ti.idtarifa left join logticket lt on ti.idticket = lt.idticket right join tipomovimiento tm on lt.idtipomovimiento = tm.idtipomovimiento GROUP BY lo.idlocalidad, lt.idtipomovimiento ORDER BY descripcionlocalidad
As you see there in no where clause. Please you help
|
|
|
Re: Where is where [message #2230 is a reply to message #2229] |
Sat, 18 July 2009 04:55 |
AJM
Messages: 2373 Registered: April 2006 Location: Surrey, UK
|
Senior Member |
|
|
You say that you have created a new class with no physical file on the database, so how come you are trying to generate an sql SELECT statement within this class?
If the WHERE string is empty it means that whatever was in it has been filtered out because the field name(s) cannot be found on any table in the FROM clause. I notice that you are using alias names for your table names, but you are not using the 'AS' word in front of the alias name. You should write them as 'tablename AS alias' and not the shortened 'tablename alias'. The framework specifically looks for ' AS ' (case insensitive) in order to identify alias names.
This is documented in Using Parent Relations to construct sql JOINs .
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
|
|
|
|