예제 #1
0
파일: Model.php 프로젝트: nanjingboy/clown
 public static function find($options = array())
 {
     if (!array_key_exists('order', $options) && static::$primaryKey !== null) {
         $options['order'] = static::$primaryKey . ' asc';
     }
     $params = SqlBuilder::parseQuerySql(static::table(), $options);
     return new ModelIterator(Connection::instance()->fetch($params['sql'], $params['values']), get_called_class());
 }
예제 #2
0
 public function testParseQuerySql()
 {
     $this->assertEquals(array('sql' => 'SELECT * FROM `user`', 'values' => array()), SqlBuilder::parseQuerySql('user'));
     $this->assertEquals(array('sql' => 'SELECT id,concat(first_name, family_name) as fullname FROM `user` WHERE `id` in (?) GROUP BY sex HAVING sex = ? ORDER BY id DESC LIMIT 0,10', 'values' => array(array(1, 2), 'male')), SqlBuilder::parseQuerySql('user', array('select' => array('id', 'concat(first_name, family_name) as fullname'), 'conditions' => array('id' => array(1, 2)), 'group' => 'sex', 'having' => array('sex = ?', 'male'), 'order' => 'id DESC', 'limit' => 10)));
 }