The "SELECT COUNT(*)" query is used to determine whether or not the
record exists.  Based on the result of query, Cake will either perform
an INSERT or UPDATE query.  If an insert is performed, "SELECT
LAST_INSERT_ID()" query is functionally equivalent to mysql_insert_id
(though more reliable for large integers), and is used to get the ID
of the newly created record.  Neither of these queries are the result
of a bug, nor is the fact that they appear multiple times (once each
per insert).  You cannot disable them without quite a bit of trouble,
and I don't think you'd want to, as it would break Cake's normal
operation.

Rhetorical question, posed to no one in particular: why is it that
people will automatically jump to the conclusion that a particular
behavior is a bug just because it isn't consistent with how they think
it should work?  At this point, CakePHP has become a big enough
project that it has attracted a lot of help (in the form of advice,
patches, etc.) from a lot of really smart people.  We on the dev team
also do a lot of research into the techniques of other really smart
people when deciding how certain things should work (using SELECT
LAST_INSERT_ID() instead of mysql_insert_id is a perfect example).
So, for the most part, most aspects of the framework represent the
aggregation of the knowledge and wisdom of all those really smart
people, and therefore the best way to go about doing things.  That
being the case, which seems more likely: a bug in the code, or a bug
in someone's understanding of it?

In fairness, I will say that most people (lately) have been pretty
good about asking questions about things in an unassuming way before /
instead of submitting tickets, but I think it still happens the other
way around often enough for me to raise the question.  Anyone else
notice this or am I the only one?

On Apr 15, 10:13 am, "majna" <[EMAIL PROTECTED]> wrote:
> This is something new in core, i just wonder why is there.
> I think it is merged down form 1.2 in 1.1.14 release.
> Documentation do not cover things like this, so I ask here, then
> ticket...
> It is important for me to know why some feature is there, how can i
> use it.
> Why is there same query twice?
>
> @savagekabbage
> example: saving order with 5 products (including product options and
> stuff) generate 15 queries, and cake add for each insert 2x this
> above- about 20.
> And they are duplicated demnit.
> This must be a bug. How can cake save my life? :)
>
> On Apr 15, 2:26 am, "savagekabbage" <[EMAIL PROTECTED]> wrote:
>
> > Actually disregard my last message, I misread your post.  I'm not sure
> > if there's a way to avoid doing this without hacking the source
> > though.  If you're worried about one extra query per page then the
> > Cake framework probably isn't for you.
>
> > On Apr 14, 9:05 am, "majna" <[EMAIL PROTECTED]> wrote:
>
> > > There is two additional query after creating new record:SELECT
> > > LAST_INSERT_ID() AS insertID
>
> > > and two after update: COUNT(id)
>
> > > How to avoid this behavior? Why is it there?
> > > CAKE 1.1.14,


--~--~---------~--~----~------------~-------~--~----~
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