Hi,
I'm letting Cake (Version 1.3.3) do some automatic imports over night
and it's doing the same thing for about half a million times.
It's working pretty well but every night I get some (about 10) really
weird SQL-errors.
I just don't understand how these even can occur.
It seems that cake is mixing up conditions from different queries
sometimes and even misspelling model-names.
This is the function that is doing the SQL-queries:
function __saveArticle($product, $hashkey, $shopId)
{
$this->VsArticle->create();
$this->VsArticle->id = false;
$this->data["VsArticle"] = $product;
$this->VsArticle->recursive = -1;
$existingArticle = $this->VsArticle->find('all', array("limit" => 1,
"fields" => array("VsArticle.id","VsArticle.toparticle"), 'conditions'
=> array(
'VsArticle.artnr' => $this->data["VsArticle"]["artnr"],
'VsArticle.vs_shop_id' => $shopId)));
if(!empty($existingArticle))
{
$this->VsArticle->id = $existingArticle[0]["VsArticle"]["id"];
$this->updateCount++;
}
else
{
$this->data["VsArticle"]["status"] = "imported";
$this->data["VsArticle"]["vs_shop_id"] = $shopId;
$this->newCount++;
}
if($existingArticle !== false)
{
if($this->VsArticle->save($this->data))
{
$lastArticleId = $this->VsArticle->id;
$this->VsArticleHasVsCategory->deleteAll("vs_article_id
=
$lastArticleId", false);
foreach($this->data["VsArticle"]["categoriesIds"] as
$categoryId)
{
$this->VsArticleHasVsCategory->create();
$this->data["VsArticleHasVsCategory"]["vs_article_id"] =
$lastArticleId;
$this->data["VsArticleHasVsCategory"]["vs_category_id"] =
$categoryId;
$this->data["VsArticleHasVsCategory"]["vs_shop_id"] = $shopId;
$this->data["VsArticleHasVsCategory"]["hash"] =
$hashkey;
$this->VsArticleHasVsCategory->save($this->data);
}
}
}
}
And here are some of the errors (with the corresponding SQL-Query):
[14-Aug-2010 01:58:35] PHP Warning: SQL Error: 1054: Unknown column
'vs_articles.id' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[14-Aug-2010 01:58:35] SQL ERROR: SELECT `VsArticle`.`id`,
`VsArticle`.`toparticle` FROM `vs_articles` AS `VsArticle` WHERE
`vs_articles`.`id` = 12040 ORDER BY `VsArticle`.`title` ASC LIMIT 1
[14-Aug-2010 04:48:20] PHP Warning: SQL Error: 1054: Unknown column
'VsArticle.artnr' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[14-Aug-2010 04:48:20] SQL ERROR: DELETE FROM `vs_articles` WHERE
`VsArticle`.`artnr` = '441124' AND `VsArticle`.`vs_shop_id` = 120
[15-Aug-2010 04:15:27] PHP Warning: SQL Error: 1054: Unknown column
'VsArticle.artnr' in 'where clause' in /var/cakephp/cake/libs/model/
datasources/dbo_source.php on line 682
[15-Aug-2010 04:15:27] SQL ERROR: DELETE `VsArticleHasVsCategory` FROM
`vs_article_has_vs_category` AS `VsArticleHasVsCategory` WHERE
`VsArticle`.`artnr` = '51715236-2-6-3-38-242' AND
`VsArticle`.`vs_shop_id` = 141
I know, it's not easy to understand, but please have a look at the
last error I posted.
As you can easily see, it's mixing up to queries:
existingArticle = $this->VsArticle->find('all', array("limit"
=> 1, "fields" => array("VsArticle.id","VsArticle.toparticle"),
'conditions' => array(
'VsArticle.artnr' => $this->data["VsArticle"]["artnr"],
'VsArticle.vs_shop_id' => $shopId)));
AND
$this->VsArticleHasVsCategory->deleteAll("vs_article_id =
$lastArticleId", false);
So somewhere in the cake-core the SQL-querybuilding get's pretty much
mixed up.
I just don't know what could trigger this and where exactly it
happens.
Not easy to debug, as this import is running for about six hours.
Does anybody have ANY idea what could cause this odd behavior?
best,
d.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" 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