SugarQuery with a Where clause field LIKE '%58%'

I have a field in my DB, it is type INT.   Lets call it test_int so

<?php

$query = new SugarQuery();
$query->from(BeanFactory::getBean('Accounts'));
$query->select(array('id', 'name', 'test_int'));
$query->where()->contains('test_int', '58');
$returnArray = $query->execute();

the SQL I get is

SELECT  accounts.id id, accounts.name name, accounts.test_int test_int FROM accounts 
LEFT JOIN accounts_cstm ON accounts_cstm.id_c = accounts.id 
WHERE accounts.deleted = 0 AND accounts.test_int LIKE 58

Which pulls up no records, what am I doing wrong?  I want '%58%' for the where clause.

  • Hi Kenneth Brill 

    Once this field is type INT so why don't you call $query->where()->equals() ?

    As far I understand "contains" is a string specific condition.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • That makes sense, I'll have to go back and figure out exactly why I needed to do that.  Seems to me that should generate an error and not incorrect SQL though...

  • The like operator is only allowed an strings and performs a pattern search within these strings. So you would find 58, 158, 5845 or others if the datatype would be any string type like char, varchar or text.

    On int fields you can execute equal or range operators only (=, <, >).

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH