Completed
Push — master ( 07fa0a...a5b00e )
by Edgard
10:14
created

PdoAdapter::rollBack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * @link http://www.yiiframework.com/
5
 * @copyright Copyright (c) 2008 Yii Software LLC
6
 * @license http://www.yiiframework.com/license/
7
 */
8
9
namespace edgardmessias\db\firebird;
10
11
use PDO;
12
13
/**
14
 * Description of PdoAdapter
15
 *
16
 * @author Edgard Lorraine Messias <[email protected]>
17
 */
18
class PdoAdapter extends PDO
19
{
20
21
    private $_inTransaction = false;
22
23
    /**
24
     * Do some basic setup for Firebird.
25
     * o Force use of exceptions on error.
26
     * o Force all metadata to lower case.
27
     *   Yii will behave in unpredicatable ways if
28
     *   metadata is not lowercase.
29
     * o Ensure that table names are not prefixed to
30
     *    fieldnames when returning metadata.
31
     * Finally call parent constructor.
32
     *
33
     */
34 150
    public function __construct($dsn, $username, $password, $driver_options = [])
35
    {
36
        // Windows OS paths with backslashes should be changed
37 150
        $dsn = str_replace("\\", "/", $dsn);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \\ does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal / does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
38
        // apply error mode
39 150
        $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
40
        // lower case column names in results are necessary for Yii ActiveRecord proper functioning
41 150
        $driver_options[PDO::ATTR_CASE] = PDO::CASE_LOWER;
42
        // ensure we only receive fieldname not tablename.fieldname.
43 150
        $driver_options[PDO::ATTR_FETCH_TABLE_NAMES] = false;
44 150
        parent::__construct($dsn, $username, $password, $driver_options);
45 150
    }
46
47
    /**
48
     * Initiates a transaction
49
     * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
50
     */
51 6
    public function beginTransaction($isolationLevel = null)
52
    {
53 6
        $this->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
54
55 6
        if ($isolationLevel === false) {
56 2
            $this->_inTransaction = true;
57 2
            return true;
58
        }
59
60 4
        if ($isolationLevel === null) {
61 4
            $r = $this->exec("SET TRANSACTION");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SET TRANSACTION does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
62 4
            $success = ($r !== false);
63 4
            if ($success) {
64 4
                $this->_inTransaction = true;
65 4
            }
66 4
            return ($success);
67
        }
68
69
        $r = $this->exec("SET TRANSACTION ISOLATION LEVEL $isolationLevel");
70
        $success = ($r !== false);
71
        if ($success) {
72
            $this->_inTransaction = true;
73
        }
74
        return ($success);
75
    }
76
77
    /**
78
     * Commits a transaction
79
     * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
80
     */
81 5
    public function commit()
82
    {
83 5
        $r = $this->exec("COMMIT");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal COMMIT does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
84 5
        $this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
85 5
        $success = ($r !== false);
86 5
        if ($success) {
87 5
            $this->_inTransaction = false;
88 5
        }
89 5
        return ($success);
90
    }
91
92
    /**
93
     * Rolls back a transaction
94
     * @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
95
     */
96 2
    public function rollBack()
97
    {
98 2
        $r = $this->exec("ROLLBACK");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ROLLBACK does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
99 2
        $this->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
100 2
        $success = ($r !== false);
101 2
        if ($success) {
102 2
            $this->_inTransaction = false;
103 2
        }
104 2
        return ($success);
105
    }
106
107
    /**
108
     * Checks if inside a transaction
109
     * @return bool <b>TRUE</b> if a transaction is currently active, and <b>FALSE</b> if not.
110
     */
111
    public function inTransaction()
112
    {
113
        return $this->_inTransaction;
114
    }
115
}
116