Hello everyone !

My intentions:
- to get a (kind of) sequence nr for naming an object
- (maybe) save someone a headache

My (first) approach was to use the function "query()" in  the Model
like so:

*snip*
function getNextSeqNr()
{
        $seqnr = $this->query("SELECT (MAX(Item.id)+1) AS seqnr FROM items AS
Item");

        if(empty($seqnr[0][0]['seqnr']))
                $seqnr[0][0]['seqnr'] = 1;

        return $seqnr[0][0]['seqnr'];
}
*snip*

This method was sufficient for a while, it worked, BUT...
...only if it was called once per controller-action.
If I tried to do this in a loop, the query was only executed once...
(although i turned everything off, that had remotely to do with
caching)
I finally got around to another, a little bit more
"unfancy"/"oldskool" method to get what i wanted.

*snip*
function getNextSeqNr()
{
        $db =& ConnectionManager::getDataSource($this->useDbConfig);
        $result = $db->rawQuery("SELECT (MAX(Item.id)+1) AS seqnr FROM items
AS Item");

        $seqnr = 1;

        if($result === false)
        {
                $this->log("bleep, error blah.");
                $seqnr = false;
        }
        else
        {
                if($result->num_rows == 1)
                {
                        $row    = $result->fetch_assoc();
                        $seqnr  = $row['seqnr'];
                }
        }

        return $seqnr;
}
*snip*

Now the query is not unduly cached anymore.

Or maybe there is another explanation ? - Would love to hear it.

Cheers,
        Ray


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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