Completed
Push — master ( f14d46...588617 )
by Edgard
10:19
created

Command::bindValues()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.1574

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 14
cp 0.7856
rs 9.2
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 1
crap 4.1574
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace edgardmessias\db\firebird;
9
10
/**
11
 *
12
 * @author Edgard Lorraine Messias <[email protected]>
13
 * @since 2.0
14
 */
15
class Command extends \yii\db\Command
16
{
17
18
    /**
19
     * Binds a parameter to the SQL statement to be executed.
20
     * @param string|integer $name parameter identifier. For a prepared statement
21
     * using named placeholders, this will be a parameter name of
22
     * the form `:name`. For a prepared statement using question mark
23
     * placeholders, this will be the 1-indexed position of the parameter.
24
     * @param mixed $value Name of the PHP variable to bind to the SQL statement parameter
25
     * @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
26
     * @param integer $length length of the data type
27
     * @param mixed $driverOptions the driver-specific options
28
     * @return static the current command being executed
29
     * @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
30
     */
31
    public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null)
32
    {
33
        if ($dataType === null) {
34
            $dataType = $this->db->getSchema()->getPdoType($value);
35
        }
36
        if ($dataType == \PDO::PARAM_BOOL) {
37
            $dataType = \PDO::PARAM_INT;
38
        }
39
        return parent::bindParam($name, $value, $dataType, $length, $driverOptions);
40
    }
41
42
    /**
43
     * Specifies the SQL statement to be executed.
44
     * The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
45
     * @param string $sql the SQL statement to be set.
46
     * @return static this command instance
47
     */
48 134
    public function setSql($sql)
49
    {
50 134
        $matches = null;
51 134
        if (preg_match("/^\s*DROP TABLE IF EXISTS (['\"]?([^\s\;]+)['\"]?);?\s*$/i", $sql, $matches)) {
52
            if ($this->db->getSchema()->getTableSchema($matches[2]) !== null) {
53
                $sql = $this->db->getQueryBuilder()->dropTable($matches[2]);
54
            } else {
55
                $sql = 'select 1 from RDB$DATABASE;'; //Prevent Drop Table
56
            }
57
        }
58
        
59 134
        return parent::setSql($sql);
60
    }
61
62
    /**
63
     * Binds a value to a parameter.
64
     * @param string|integer $name Parameter identifier. For a prepared statement
65
     * using named placeholders, this will be a parameter name of
66
     * the form `:name`. For a prepared statement using question mark
67
     * placeholders, this will be the 1-indexed position of the parameter.
68
     * @param mixed $value The value to bind to the parameter
69
     * @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
70
     * @return static the current command being executed
71
     * @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
72
     */
73 1
    public function bindValue($name, $value, $dataType = null)
74
    {
75 1
        if ($dataType === null) {
76 1
            $dataType = $this->db->getSchema()->getPdoType($value);
77 1
        }
78 1
        if ($dataType == \PDO::PARAM_BOOL) {
79
            $dataType = \PDO::PARAM_INT;
80
        }
81
82 1
        return parent::bindValue($name, $value, $dataType);
83
    }
84
}
85