コード例 #1
0
ファイル: SqlSelectTest.php プロジェクト: studio-v/nano
 public function testLimit()
 {
     self::assertEquals('select * from t limit 1', sql::select(sql::ALL)->from('t')->limit(1)->toString(Nano::db()));
     self::assertEquals('select * from t limit 20, 10', sql::select(sql::ALL)->from('t')->limit(10, 20)->toString(Nano::db()));
     self::assertEquals('select * from t limit 0, 5', sql::select(sql::ALL)->from('t')->limitPage(1, 5)->toString(Nano::db()));
     self::assertEquals('select * from t limit 5, 5', sql::select(sql::ALL)->from('t')->limitPage(2, 5)->toString(Nano::db()));
     self::assertEquals('select * from t limit 10, 5', sql::select(sql::ALL)->from('t')->limitPage(3, 5)->toString(Nano::db()));
 }
コード例 #2
0
ファイル: Category.php プロジェクト: studio-v/nano
 protected static function loadCache()
 {
     $result = array();
     $rows = self::fetchThis(sql::select('*')->from(self::NAME)->order(Nano::db()->quoteName('order')));
     foreach ($rows as $row) {
         $result[$row->name] = $row;
     }
     return $result;
 }
コード例 #3
0
ファイル: DbObject.php プロジェクト: studio-v/nano
 /**
  * @return sql_query
  * @param string $class
  * @param string $alias
  */
 protected static function createQuery($class, $alias = null)
 {
     $name = constant($class . '::NAME');
     $prefix = ($alias ? $alias : $name) . '.';
     return sql::select($prefix . '*')->from($alias ? array($alias => $name) : $name);
 }
コード例 #4
0
ファイル: dao.class.php プロジェクト: jsyinwenjun/zentao
 /**
  * Use it to do some convenient queries.
  * 
  * @param  string $funcName  the function name to be called
  * @param  array  $funcArgs  the params
  * @access public
  * @return object the dao object self.
  */
 public function __call($funcName, $funcArgs)
 {
     $funcName = strtolower($funcName);
     /* findByxxx, xxx as will be in the where. */
     if (strpos($funcName, 'findby') !== false) {
         $this->setMode('magic');
         $field = str_replace('findby', '', $funcName);
         if (count($funcArgs) == 1) {
             $operator = '=';
             $value = $funcArgs[0];
         } else {
             $operator = $funcArgs[0];
             $value = $funcArgs[1];
         }
         $this->sqlobj = sql::select('%s')->from('%s')->where($field, $operator, $value);
         return $this;
     } elseif (strpos($funcName, 'fetch') !== false) {
         $max = str_replace('fetch', '', $funcName);
         $stmt = $this->query();
         $rows = array();
         $key = isset($funcArgs[0]) ? $funcArgs[0] : '';
         $i = 0;
         while ($row = $stmt->fetch()) {
             $key ? $rows[$row->{$key}] = $row : ($rows[] = $row);
             $i++;
             if ($i == $max) {
                 break;
             }
         }
         return $rows;
     } else {
         /* Create the max counts of sql class methods, and then create $arg0, $arg1... */
         for ($i = 0; $i < SQL::MAX_ARGS; $i++) {
             ${"arg{$i}"} = isset($funcArgs[$i]) ? $funcArgs[$i] : null;
         }
         $this->sqlobj->{$funcName}($arg0, $arg1, $arg2);
         return $this;
     }
 }
コード例 #5
0
ファイル: Db.php プロジェクト: studio-v/nano
 /**
  * @return sql_select
  */
 public function select()
 {
     return sql::select();
 }
コード例 #6
0
ファイル: Setting.php プロジェクト: studio-v/nano
 protected static function loadCache()
 {
     $result = array();
     $query = sql::select('s.*')->from(array('s' => self::NAME))->innerJoin(array('c' => Setting_Category::NAME), 's.setting_category_id = c.setting_category_id')->order('c.' . self::db()->quoteName('order'))->order('s.' . self::db()->quoteName('order'));
     $rows = self::fetchThis($query);
     foreach ($rows as $row) {
         $category = Setting_Category::getById($row->setting_category_id)->name;
         if (isset($result[$category])) {
             $result[$category][$row->name] = $row;
         } else {
             $result[$category] = array($row->name => $row);
         }
     }
     return $result;
 }
コード例 #7
0
 public function listar2()
 {
     //con tablegetway y zend.db.sql
     /*$lista = $this->tableGateway->select(function (Select $select) {
       $select->where->like('nombre', 'kev%');
       });*/
     $adapter = $this->tableGateway->getAdapter();
     $sql = new sql($adapter);
     $select = $sql->select()->from('ta_usuario')->where(array('va_nombre' => 'kevin'));
     //where('nombre=kevin');//
     //$select->from('usuario');
     //$select->where(array('nombre' => 'kevin'));
     $selectString = $sql->getSqlStringForSqlObject($select);
     $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
     //$sql = new Sql($this->tableGateway->getAdapter());
     /*  $spec = function (Where $where) {
               $where->like('nombre','kev%');
         };*/
     // $lista = $sql->select()->from('usuario');//->where->like('nombre', 'kev%');
     $returnArray = array();
     foreach ($results as $result) {
         $returnArray[] = $result;
     }
     var_dump($returnArray);
     exit;
 }