Index: library/Zend/Db/Select.php =================================================================== --- library/Zend/Db/Select.php (revision 18256) +++ library/Zend/Db/Select.php (working copy) @@ -1167,7 +1167,13 @@ $order = array(); foreach ($this->_parts[self::ORDER] as $term) { if (is_array($term)) { - $order[] = $this->_adapter->quoteIdentifier($term[0], true) . ' ' . $term[1]; + if(is_numeric($term[0]) && strval(intval($term[0])) == $term[0]) { + $order[] = (int)trim($term[0]) . ' ' . $term[1]; + } else { + $order[] = $this->_adapter->quoteIdentifier($term[0], true) . ' ' . $term[1]; + } + } else if (is_numeric($term) && strval(intval($term)) == $term) { + $order[] = (int)trim($term); } else { $order[] = $this->_adapter->quoteIdentifier($term, true); } Index: tests/Zend/Db/Select/TestCommon.php =================================================================== --- tests/Zend/Db/Select/TestCommon.php (revision 18256) +++ tests/Zend/Db/Select/TestCommon.php (working copy) @@ -1229,6 +1229,48 @@ $this->assertEquals(1, $result[0]['product_id']); } + public function testSelectOrderByPosition() + { + $select = $this->_db->select() + ->from('zfproducts') + ->order('2'); + + $stmt = $this->_db->query($select); + $result = $stmt->fetchAll(); + + $this->assertEquals(2, $result[0]['product_id']); + $this->assertEquals(3, $result[1]['product_id']); + $this->assertEquals(1, $result[2]['product_id']); + } + + public function testSelectOrderByPositionAsc() + { + $select = $this->_db->select() + ->from('zfproducts') + ->order('2 ASC'); + + $stmt = $this->_db->query($select); + $result = $stmt->fetchAll(); + + $this->assertEquals(2, $result[0]['product_id']); + $this->assertEquals(3, $result[1]['product_id']); + $this->assertEquals(1, $result[2]['product_id']); + } + + public function testSelectOrderByPositionDesc() + { + $select = $this->_db->select() + ->from('zfproducts') + ->order('2 DESC'); + + $stmt = $this->_db->query($select); + $result = $stmt->fetchAll(); + + $this->assertEquals(1, $result[0]['product_id']); + $this->assertEquals(3, $result[1]['product_id']); + $this->assertEquals(2, $result[2]['product_id']); + } + protected function _selectOrderByDesc() { $select = $this->_db->select()