[Solar-talk] bounding zero
Rodrigo Moraes
rodrigo.moraes at gmail.com
Mon Mar 12 10:08:38 PDT 2007
On 3/12/07, Rodrigo Moraes wrote:
> Hi.
> I'm in doubt about the cleanest way to bound a variable that can be 0
> (integer zero). For example:
>
> $select = Solar::factory('Solar_Sql_Select');
> $res = $select->from('my_table', 'my_column')
> ->where('my_column = ?', $x)
> ->fetch('value');
>
> If $x = 0, a exception is thrown, but if $x = '0' it is not. Is it
> really necessary to quote the zero or cast it to a string? I thought
> this could be a bug in Solar_Sql_Select::where(), on these lines:
Addind more info. The exception is:
Uncaught exception 'Solar_Sql_Adapter_Exception_QueryFailed'
class::code 'Tipos_Sql_Adapter_Mysql::ERR_QUERY_FAILED' with message
'ERR_QUERY_FAILED' information array ( 'pdo_code' => 'HY093',
'pdo_text' => 'SQLSTATE[HY093]: Invalid parameter number: no
parameters were bound', [...]
in Solar_Sql_Select::where():
1. when the bound parameter is integer 0:
var_dump($val != SOLAR_IGNORE_PARAM);
result: false
1. when the bound parameter is string 0:
var_dump($val != SOLAR_IGNORE_PARAM);
result: true
So int(0) is not allowed to be bound. :-|
rodrigo
More information about the solar-talk
mailing list