Welcome Guest, Not a member yet? Register   Sign In
RapidDataMapper, a new Object-Relational-Mapper
#38

[eluser]Jelmer[/eluser]
Maybe again something I should have read in the manual, but I couldn't find out how to get a MAX(`column`)/MIN(`column`) done so I added 2 carbon-copies of the count() method in the DB_Query_Select class:
Code:
public function min($column)
{
    if($this->escape)
    {
        // escape the string
        $column = $this->_instance->protectIdentifiers($column);
    }
    
    // save it, so we still can use this query object here
    $tmp = $this->columns;
    
    // construct the MIN
    $this->columns = array('MIN(' . $column . ')');
    
    // call
    $ret = $this->_instance->query($this->__toString());
    
    // reset the columns
    $this->columns = $tmp;
    
    // return unless error
    if($ret === false)
    {
        return false;
    }
    else
    {
        return ($r = $ret->val()) !== false ? $r : false;
    }
}

public function max($column)
{
    if($this->escape)
    {
        // escape the string
        $column = $this->_instance->protectIdentifiers($column);
    }
    
    // save it, so we still can use this query object here
    $tmp = $this->columns;
    
    // construct the MAX
    $this->columns = array('MAX(' . $column . ')');
    
    // call
    $ret = $this->_instance->query($this->__toString());
    
    // reset the columns
    $this->columns = $tmp;
    
    // return unless error
    if($ret === false)
    {
        return false;
    }
    else
    {
        return ($r = $ret->val()) !== false ? $r : false;
    }
}
Good or bad solution?

(EDIT after suggestion of sophistry)


Messages In This Thread
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-13-2009, 07:24 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-14-2009, 03:12 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-14-2009, 07:42 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-14-2009, 10:40 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-14-2009, 10:49 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-14-2009, 11:34 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-15-2009, 03:38 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-15-2009, 11:42 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 01:07 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 01:22 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 01:47 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 01:59 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 02:02 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 02:54 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 02:57 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 03:19 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 03:38 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 03:57 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 04:54 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 04:58 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 05:07 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-17-2009, 08:54 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-18-2009, 05:44 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-18-2009, 08:11 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-20-2009, 10:18 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-20-2009, 06:15 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-21-2009, 07:45 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-21-2009, 09:15 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-21-2009, 09:17 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-21-2009, 09:43 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-21-2009, 10:16 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-22-2009, 04:03 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-23-2009, 08:25 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-24-2009, 08:26 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-24-2009, 08:35 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-29-2009, 11:51 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-29-2009, 01:37 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-30-2009, 08:15 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-30-2009, 10:16 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 12-31-2009, 05:16 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-04-2010, 03:24 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-04-2010, 04:13 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-04-2010, 04:22 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-04-2010, 05:01 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-08-2010, 03:09 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-16-2010, 07:25 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 01-16-2010, 07:35 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 02-05-2010, 01:33 PM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 02-20-2010, 07:18 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 02-20-2010, 07:28 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 03-03-2010, 03:46 AM
RapidDataMapper, a new Object-Relational-Mapper - by El Forum - 03-04-2010, 09:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB