Welcome Guest, Not a member yet? Register   Sign In
Active Record class update() return ?
#1

[eluser]tomcode[/eluser]
Hi,

Knows anybody the exact return values and types of the Active record class method update() ?

The User Guide does not mention anything.

The Docblock in the code pretends object.

My tests give me boolean TRUE, whether or not an update has been done (sort of strange, no ?).

Can there be other return values /types ?

I can of course get the affected rows, but still, this puzzles me.


Thanks.
#2

[eluser]axle_foley00[/eluser]
As far as I'm aware when you do an update all you would need to know is if it returns TRUE (a successful update), FALSE (one that is not successful) and get the number of affected rows. I don't think it returns anything else or any other type.
#3

[eluser]tomcode[/eluser]
I've been looking into the code, update returns FALSE when one of its params is invalid, but besides that, it'll return the result of the method query(), which is a pretty monster to read. It just puzzles me that it'll return TRUE if no row has been updated.
#4

[eluser]Seppo[/eluser]
I donĀ“t think is wrong returning TRUE if no row was updated... the query has been successfully executed, if you want to check the affected rows, affected_rows method will do the trick
#5

[eluser]axle_foley00[/eluser]
tomcode:

Seppo would be correct. I just checked and as long as the query successfully gets executed (even if it doesn't update anything), it will return TRUE.
#6

[eluser]tomcode[/eluser]
Thanks a lot guys. I have it now fixed for me and it should be solid.
#7

[eluser]Phil Sturgeon[/eluser]
Never has for me, if nothing is updated it doesnt return TRUE. Or it least thats how its always happened for me. Its hard to work out whats going on in that DB driver library with a headache :p
#8

[eluser]tomcode[/eluser]
Quote:Never has for me, if nothing is updated it doesnt return TRUE

@thepyromaniac: This is very strange. Can You give Your environnement ?
I'm working on WinXP under
Apache/2.2.3 (Win32) PHP/5.2.0 MySQL/5.0.22
Apache/1.3.33 (Win32) PHP/4.3.10 MySQL/3.23.49

I've checked again the code:

the update() method:
returns FALSE or exists (with $this->db_debug enabled) if one of its params aint valid.

else it 'just' returns the central query() method:

returns FALSE or exists (with $this->db_debug enabled) if one of its params aint valid.
returns $this->CACHE->read($sql) if cache is on
returns FALSE if $this->simple_query($sql) returns false
returns TRUE for write_type queries
returns TRUE if param $return_object (the third one) is other than TRUE
returns the created result object new 'CI_DB_'.$this->dbdriver.'_result'

That's it.

The comment: (which omits to mention the third param)

Code:
<?php
    /**
     * Execute the query
     *
     * Accepts an SQL string as input and returns a result object upon
     * successful execution of a "read" type query.  Returns boolean TRUE
     * upon successful execution of a "write" type query. Returns boolean
     * FALSE upon failure, and if the $db_debug variable is set to TRUE
     * will raise an error.
     *
     * @access    public
     * @param    string    An SQL query string
     * @param    array    An array of binding data
     * @return    mixed        
     */    
    function query($sql, $binds = FALSE, $return_object = TRUE)
    {

I get the behaviour as decribed in the comment above.




Theme © iAndrew 2016 - Forum software by © MyBB