Part of the EllisLab Network
   
 
Active Record class update() return ?
Posted: 06 January 2008 11:53 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  515
Joined  08-26-2006

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.

Profile
 
 
Posted: 06 January 2008 12:19 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

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.

Profile
 
 
Posted: 06 January 2008 12:28 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  515
Joined  08-26-2006

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.

Profile
 
 
Posted: 06 January 2008 03:51 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  737
Joined  10-18-2006

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

 Signature 

Once in a while I remember I use Twitter

Profile
 
 
Posted: 06 January 2008 03:57 PM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  157
Joined  04-17-2006

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.

Profile
 
 
Posted: 06 January 2008 04:08 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  515
Joined  08-26-2006

Thanks a lot guys. I have it now fixed for me and it should be solid.

Profile
 
 
Posted: 07 January 2008 07:36 AM   [ Ignore ]   [ # 6 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2517
Joined  06-11-2007

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

 Signature 

Blog | Twitter | GitHub
————————-
CodeIgniter 2: Everything you need to know
————————
PyroCMS - open source modular CMS built with CodeIgniter
CleverAndy - get money for un-used concept designs
————————
Libraries: Asset, Dwoo, Cache, cURL, CLI, REST, Template

Profile
 
 
Posted: 07 January 2008 09:18 AM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  515
Joined  08-26-2006

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)

<?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.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120347 Total Logged-in Users: 49
Total Topics: 126474 Total Anonymous Users: 3
Total Replies: 665071 Total Guests: 426
Total Posts: 791545    
Members ( View Memberlist )
Newest Members:  ThatchVagariPatient ShareNixnizviVadotlogikCariNetX-C0d3C01010011may32753