'-!' is a flag to cake to not interpret the conditions, just put them
as they are. If's useful for handling database functions, expressions
and whatnot, so I thought it would be appropriate. Although it doesn't
seem to be, I think it only works on a right-hand assignment (like
'field' => '-!expression').

Still, it seems to be far easier than that. Using this query:

    $data = $this->Person->find('all', array('conditions' => array(
      'SUBSTRING(Person.name, 1, 1)=\'J\''
    )));

I get this SQL:

SELECT `Person`.`id`, `Person`.`name`, **snip** FROM `people` AS
`Person` WHERE SUBSTRING(`Person`.`name`, 1, 1)='J'

Which is perfect.

I also think that the following query would be optimized better (but
have the same result);

    $data = $this->Person->find('all', array('conditions' => array(
      'Person.name' => 'LIKE J%'
    )));

SQL : SELECT `Person`.`id`, `Person`.`name`, **snip** FROM `people` AS
`Person` WHERE `Person`.`name` LIKE 'J%'

Hope this helps

On Feb 4, 2:06 pm, roliver <[EMAIL PROTECTED]> wrote:
> Thanks for everyone's help, but I'm still having issues with the
> substring
>
> I have debugging turned on and it does not like the parentheses '()'
> Below is the actual mysql error:
>
> SQL Error: 1064: You have an error in your SQL syntax; check the
> manual that corresponds to your MySQL server version for the right
> syntax to use near ')  =  '2008-02-04'' at line 1 [CORE/cake/libs/
> model/datasources/dbo_source.php, line 440]
>
> grigri: what does the '-!' do in your example below?
>
> Thanks
>
> On Feb 1, 4:25 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > Try this:
>
> > $data = $this->find(array('campaign_id as id'=>
> > $id,'-!substring(upload_date,1, 10) = \'2008-01-31\''),
> > array('imp','clicks','ctr','cpc','cost','pos','conv','conv_rate','cost_per_conv'))
>
> > On Feb 1, 3:56 am, "Wayne Fay" <[EMAIL PROTECTED]> wrote:
>
> > > You should turn on debugging to see the actual SQL that is being
> > > executed, and then try running it in Mysql.
>
> > > Wayne
>
> > > On 1/31/08, roliver <[EMAIL PROTECTED]> wrote:
>
> > > > Can anyone tell me if it is possible to use the 'substring' keyword in
> > > > Model->findAll()   I'm trying to do this but I keep getting the mysql
> > > > error "you have an error in yoru sql near...blah..blah) The query I'm
> > > > using is below.
>
> > > > $data = $this->find(array('campaign_id as id'=>
> > > > $id,'substring(upload_date,1, 10)'=>'2008-01-31'),
> > > > array('imp','clicks','ctr','cpc','cost','pos','conv','conv_rate','cost_per_conv'))
>
> > > > If can't then what should I use Model->query() ?
>
> > > > thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to