Changeset 1612

Show
Ignore:
Timestamp:
05/30/08 14:00:10 (3 months ago)
Author:
mikey
Message:

added extreme simple order by support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilder.php

    r1311 r1612  
    8484        } 
    8585         
     86        if ($select->isOrdered() === true) { 
     87            $selectQuery .= ' ORDER BY ' . $select->getOrderedBy(); 
     88        } 
     89         
    8690        return $selectQuery; 
    8791    } 
  • trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelect.php

    r1305 r1612  
    3838     */ 
    3939    protected $criterion; 
     40    /** 
     41     * order by clause 
     42     * 
     43     * @var  string 
     44     */ 
     45    protected $orderBy; 
    4046 
    4147    /** 
     
    119125        return $this->criterion; 
    120126    } 
     127 
     128    /** 
     129     * sets the order by clause 
     130     * 
     131     * @param   string              $orderBy 
     132     * @return  stubDatabaseSelect 
     133     */ 
     134    public function orderBy($orderBy) 
     135    { 
     136        $this->orderBy = $orderBy; 
     137        return $this; 
     138    } 
     139 
     140    /** 
     141     * checks whether an order by clause is set 
     142     * 
     143     * @return  bool 
     144     */ 
     145    public function isOrdered() 
     146    { 
     147        return (null !== $this->orderBy); 
     148    } 
     149 
     150    /** 
     151     * returns the order by clause 
     152     * 
     153     * @return  string 
     154     */ 
     155    public function getOrderedBy() 
     156    { 
     157        return  $this->orderBy; 
     158    } 
    121159} 
    122160?> 
  • trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseMySQLQueryBuilderTestCase.php

    r1303 r1612  
    6363        $select->addCriterion($mockCriterion2); 
    6464        $this->assertEquals("SELECT * FROM `foo` INNER JOIN `bar` USING (`id`) LEFT JOIN `baz` ON `bar`.`id` = `baz`.`other_id` WHERE (`foo`.`id` = 'mock' AND `baz`.`other_id` IS NOT NULL)", $this->mySqlQueryBuilder->createSelect($select)); 
     65        $select->orderBy('foo ASC'); 
     66        $this->assertEquals("SELECT * FROM `foo` INNER JOIN `bar` USING (`id`) LEFT JOIN `baz` ON `bar`.`id` = `baz`.`other_id` WHERE (`foo`.`id` = 'mock' AND `baz`.`other_id` IS NOT NULL) ORDER BY foo ASC", $this->mySqlQueryBuilder->createSelect($select)); 
    6567    } 
    6668 
  • trunk/src/test/php/net/stubbles/rdbms/querybuilder/stubDatabaseSelectTestCase.php

    r1303 r1612  
    7171        $this->assertTrue($this->select->hasCriterion()); 
    7272    } 
     73 
     74    /** 
     75     * orderedBy property 
     76     * 
     77     * @test 
     78     */ 
     79    public function orderedBy() 
     80    { 
     81        $this->assertFalse($this->select->isOrdered()); 
     82        $this->assertNull($this->select->getOrderedBy()); 
     83        $this->assertSame($this->select, $this->select->orderBy('foo ASC')); 
     84        $this->assertTrue($this->select->isOrdered()); 
     85        $this->assertEquals('foo ASC', $this->select->getOrderedBy()); 
     86    } 
    7387} 
    7488?>