PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Tracker / Db / Pdo / Pgsql.php
matomo / app / core / Tracker / Db / Pdo Last commit date
Mysql.php 6 years ago Pgsql.php 6 years ago
Pgsql.php
117 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\Tracker\Db\Pdo;
11
12 use Exception;
13 use PDO;
14
15 /**
16 * PDO PostgreSQL wrapper
17 *
18 */
19 class Pgsql extends Mysql
20 {
21 /**
22 * Builds the DB object
23 *
24 * @param array $dbInfo
25 * @param string $driverName
26 */
27 public function __construct($dbInfo, $driverName = 'pgsql')
28 {
29 parent::__construct($dbInfo, $driverName);
30 }
31
32 /**
33 * Connects to the DB
34 *
35 * @throws Exception if there was an error connecting the DB
36 */
37 public function connect()
38 {
39 if (self::$profiling) {
40 $timer = $this->initProfiler();
41 }
42
43 $this->connection = new PDO($this->dsn, $this->username, $this->password, $config = array());
44 $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
45 // we may want to setAttribute(PDO::ATTR_TIMEOUT ) to a few seconds (default is 60) in case the DB is locked
46 // the matomo.php would stay waiting for the database... bad!
47 // we delete the password from this object "just in case" it could be printed
48 $this->password = '';
49
50 if (!empty($this->charset)) {
51 $sql = "SET NAMES '" . $this->charset . "'";
52 $this->connection->exec($sql);
53 }
54
55 if (self::$profiling && isset($timer)) {
56 $this->recordQueryProfile('connect', $timer);
57 }
58 }
59
60 /**
61 * Test error number
62 *
63 * @param Exception $e
64 * @param string $errno
65 * @return bool
66 */
67 public function isErrNo($e, $errno)
68 {
69 // map MySQL driver-specific error codes to PostgreSQL SQLSTATE
70 $map = array(
71 // MySQL: Unknown database '%s'
72 // PostgreSQL: database "%s" does not exist
73 '1049' => '08006',
74
75 // MySQL: Table '%s' already exists
76 // PostgreSQL: relation "%s" already exists
77 '1050' => '42P07',
78
79 // MySQL: Unknown column '%s' in '%s'
80 // PostgreSQL: column "%s" does not exist
81 '1054' => '42703',
82
83 // MySQL: Duplicate column name '%s'
84 // PostgreSQL: column "%s" of relation "%s" already exists
85 '1060' => '42701',
86
87 // MySQL: Duplicate entry '%s' for key '%s'
88 // PostgreSQL: duplicate key violates unique constraint
89 '1062' => '23505',
90
91 // MySQL: Can't DROP '%s'; check that column/key exists
92 // PostgreSQL: index "%s" does not exist
93 '1091' => '42704',
94
95 // MySQL: Table '%s.%s' doesn't exist
96 // PostgreSQL: relation "%s" does not exist
97 '1146' => '42P01',
98 );
99
100 if (preg_match('/([0-9]{2}[0-9P][0-9]{2})/', $e->getMessage(), $match)) {
101 return $match[1] == $map[$errno];
102 }
103 return false;
104 }
105
106 /**
107 * Return number of affected rows in last query
108 *
109 * @param mixed $queryResult Result from query()
110 * @return int
111 */
112 public function rowCount($queryResult)
113 {
114 return $queryResult->rowCount();
115 }
116 }
117