1 | <?php |
---|
2 | /* |
---|
3 | * $Id: DebugPDOStatement.php 989 2008-03-11 14:29:30Z heltem $ |
---|
4 | * |
---|
5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
16 | * |
---|
17 | * This software consists of voluntary contributions made by many individuals |
---|
18 | * and is licensed under the LGPL. For more information please see |
---|
19 | * <http://propel.phpdb.org>. |
---|
20 | */ |
---|
21 | |
---|
22 | /** |
---|
23 | * PDOStatement that provides some enhanced functionality needed by Propel. |
---|
24 | * |
---|
25 | * Simply adds the ability to count the number of queries executed and log the queries. |
---|
26 | * |
---|
27 | * @author Oliver Schonrock <oliver@realtsp.com> |
---|
28 | * @since 2007-07-12 |
---|
29 | * @package propel.util |
---|
30 | */ |
---|
31 | class DebugPDOStatement extends PDOStatement { |
---|
32 | |
---|
33 | /** |
---|
34 | * the pdo connection from which we were created |
---|
35 | * @var DebugPDO |
---|
36 | */ |
---|
37 | protected $pdo; |
---|
38 | |
---|
39 | protected $typeMap = array( PDO::PARAM_BOOL => "PDO::PARAM_BOOL", |
---|
40 | PDO::PARAM_INT => "PDO::PARAM_INT", |
---|
41 | PDO::PARAM_STR => "PDO::PARAM_STR", |
---|
42 | PDO::PARAM_LOB => "PDO::PARAM_LOB", |
---|
43 | PDO::PARAM_NULL => "PDO::PARAM_NULL", |
---|
44 | ); |
---|
45 | |
---|
46 | /** |
---|
47 | * Construct a new statement class with reference to main DebugPDO object. |
---|
48 | */ |
---|
49 | protected function __construct(DebugPDO $pdo) |
---|
50 | { |
---|
51 | $this->pdo = $pdo; |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Overridden for query counting. |
---|
56 | * @return int |
---|
57 | */ |
---|
58 | public function execute($input_parameters = null) |
---|
59 | { |
---|
60 | $this->pdo->incrementQueryCount(); |
---|
61 | return parent::execute($input_parameters); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * Binds value to PDOStatement. |
---|
66 | * |
---|
67 | * @param int $pos |
---|
68 | * @param mixed $value |
---|
69 | * @param int $type |
---|
70 | * @return boolean |
---|
71 | */ |
---|
72 | public function bindValue($pos, $value, $type = null) |
---|
73 | { |
---|
74 | $typestr = isset($this->typeMap[$type]) ? $this->typeMap[$type] : '(default)'; |
---|
75 | if ($type == PDO::PARAM_LOB) { |
---|
76 | $this->pdo->log("Binding [LOB value] at position ".$pos." w/ PDO type " . $typestr); |
---|
77 | } else { |
---|
78 | $this->pdo->log("Binding " . var_export($value, true) . " at position $pos w/ PDO type " . $typestr); |
---|
79 | } |
---|
80 | return parent::bindValue($pos, $value, $type); |
---|
81 | } |
---|
82 | } |
---|