views:

457

answers:

3

I have a textfield that contains say for example the following text:-

"A traditional English dish comprising sausages in Yorkshire pudding batter, usually served with vegetables and gravy."

This textfield is in a form that simply updates an item record using it's ID. If I edit part of the textfield and replace "and gravy." with "humous." So that the textfield now contains

"A traditional English dish comprising sausages in Yorkshire pudding batter, usually served with vegetables and humous."

I get the following exception:-

Fatal error: Uncaught exception 'Doctrine_Query_Exception' with message 'Unknown component alias humous' in C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php:780 Stack trace: C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php(767): Doctrine_Query_Abstract->getQueryComponent('humous') C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Set.php(58): Doctrine_Query_Abstract->getAliasDeclaration('humous') C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php(2092): Doctrine_Query_Set->parse('i.details = 'A ...') C:\Projects\nitrous\lightweight\system\database\Doctrine\Query.php(1058): Doctrine_Query_Abstract->_processDqlQueryPart('set', Array) C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php(971): Doctrine_Query->getSqlQuery(Array) C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php(1030): Doctrine_Query_Abstract->_execute(Array) C:\Projects\nitrous\lightweight\system\appl in C:\Projects\nitrous\lightweight\system\database\Doctrine\Query\Abstract.php on line 780

I'm using Doctrine 1.0.6 hooked into CodeIgniter 1.7.0 if anyone is interested.

My doctrine query that actually performs the update looks as follows:-

public function updateItems($id, $arrayItem) {
    $query = new Doctrine_Query();
    $query->update('Item i');

    foreach($arrayItem as $key => $value) {
        $query->set('i.'.$key, "'".$value."'");
    }

    $query->where('i.id = ?', $id);
    return $query->execute();
}

This seems bizarre because if i replace the entire string "A traditional English dish comprising sausages in Yorkshire pudding batter, usually served with vegetables and humous." with something completely different like just "test" it doesn't throw an exception and works just fine. This baffles me... is it a bug in Doctrine or have I missed something?

A: 

It is clear that Doctrine thinks

  1. you are giving it 'humous', not a long string that contains 'humous', and
  2. that 'humous' is not data but an alias.

I would doubt that you are doing to the data string what you think you are doing. Is there a setting in Doctrine to get it to dump the actual SQL it generates?

Colin Fine
Apologies, the post below is meant to be a comment to this one (i'm new forgive me!) - I think it has something to do with Doctrine thinking that in the "blah." blah is recognised as an alias.
A: 

I've just experimented a little bit and found out that the problem is because i'm adding "blah." at the end the key here is if i have just "blah" it's fine but with a "." it's not.

I know in usual sql queries a blah. syntax denotes and alias of a table. By the sounds of it this is what it means.

Any ideas why Doctrine is so confused because of the fullstop and how to get around it?

A: 

I found a solution to my own question. It appears this is a known bug in Doctrine 1.0.6. I've upgraded to Doctrine 1.1.1 and this appears to have resolved the issue.

I would recomment trying different versions of Doctrine to see if this resolves your problem as well! Thanks for answering people if you did.