~desarrollokumbia/kumbia/ActiveRecord

« back to all changes in this revision

Viewing changes to db_pool/result_set.php

  • Committer: Deivinson Tejeda
  • Date: 2010-01-22 08:30:05 UTC
  • Revision ID: deivinsontejeda@gmail.com-20100122083005-7r7jvx8zuxki2pdk
      Añadiendo ResultSet ahora se puede probar con el Metodo sql() de ActiveRecord...
      ejemplos...
      Modelo
          public function getSql()
          {
              return $this->sql('select * from prueba where id > :id', array('id'=>2));
          }
      
      $xx = Load::model('modelo')->getSql();
      foreach ($xx as $xxx) {
          var_dump($xxx);
      }
      
      por defecto devuelve objeto, pero se puede pedir un fetchArray
      foreach ($xx->fetchArray() as $xxx) {
          var_dump($xxx);
      }

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * KumbiaPHP web & app Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://wiki.kumbiaphp.com/Licencia
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@kumbiaphp.com so we can send you a copy immediately.
 
14
 *
 
15
 * Resultado de una consulta con ActiveRecord
 
16
 * 
 
17
 * @category   Kumbia
 
18
 * @package    Db 
 
19
 * @copyright  Copyright (c) 2005-2010 KumbiaPHP Team (http://www.kumbiaphp.com)
 
20
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
 
21
 */
 
22
class ResultSet implements Iterator
 
23
{
 
24
    /**
 
25
     * Resultado de la consulta
 
26
     *
 
27
     * @var resource
 
28
     */
 
29
    protected $_result;
 
30
    /**
 
31
     * 
 
32
     */
 
33
    private $_position = 0;
 
34
    /**
 
35
     * Constructor
 
36
     *
 
37
     */
 
38
    public function __construct ($result)
 
39
    {
 
40
        $this->_result = $result;
 
41
    }
 
42
    /**
 
43
     * fetch Array
 
44
     * 
 
45
     * @return Array
 
46
     */
 
47
    public function fetchArray ()
 
48
    {
 
49
        return $this->_result->fetchAll(PDO::FETCH_ASSOC);
 
50
    }
 
51
    /**
 
52
     * Fetch Object
 
53
     * 
 
54
     * @param string Class
 
55
     * @return Array
 
56
     */
 
57
    public function fetchObject ($class = 'stdClass')
 
58
    {
 
59
        return $this->_result->fetchObject($class);
 
60
    }
 
61
    /**
 
62
     * Fetch All
 
63
     * 
 
64
     * @param int Fetch
 
65
     * @return ResultSet
 
66
     */
 
67
    public function fetchAll($fetch=PDO::FETCH_OBJ)
 
68
    {
 
69
        return $this->_result->fetchAll($fetch);
 
70
    }
 
71
    /**
 
72
     * Cantidad de filas afectadas por la sentencia
 
73
     * 
 
74
     * @return int
 
75
     */
 
76
    public function affectRows ()
 
77
    {
 
78
        return $this->_result->rowCount();
 
79
    }
 
80
    /**
 
81
     * reset result set pointer 
 
82
     * (implementation required by 'rewind()' method in Iterator interface)
 
83
     */
 
84
    public function rewind ()
 
85
    {
 
86
        $this->_pointer = 0;
 
87
    }
 
88
    /**
 
89
     * get current row set in result set 
 
90
     * (implementation required by 'current()' method in Iterator interface)
 
91
     */
 
92
    public function current ()
 
93
    {
 
94
        if (! $this->valid()) {
 
95
            throw new KumbiaException('Unable to retrieve current row.');
 
96
        }
 
97
        return $this->fetchObject();
 
98
    }
 
99
    /**
 
100
     * Obtiene la posición actual del Puntero 
 
101
     * 
 
102
     */
 
103
    public function key ()
 
104
    {
 
105
        return $this->_pointer;
 
106
    }
 
107
    /**
 
108
     * Mueve el puntero a la siguiente posición 
 
109
     * 
 
110
     */
 
111
    public function next ()
 
112
    {
 
113
        ++ $this->_pointer;
 
114
    }
 
115
    /**
 
116
     * Determina si el puntero del ResultSet es valido 
 
117
     * 
 
118
     */
 
119
    public function valid ()
 
120
    {
 
121
        return $this->_pointer < $this->_result->rowCount();
 
122
    }
 
123
}
 
 
b'\\ No newline at end of file'