PDF rausgenommen
This commit is contained in:
244
msd2/tracking/piwik/core/Db/Adapter/Mysqli.php
Normal file
244
msd2/tracking/piwik/core/Db/Adapter/Mysqli.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Db\Adapter;
|
||||
|
||||
use Exception;
|
||||
use Piwik\Config;
|
||||
use Piwik\Db;
|
||||
use Piwik\Db\AdapterInterface;
|
||||
use Piwik\Piwik;
|
||||
use Zend_Config;
|
||||
use Zend_Db_Adapter_Mysqli;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $config database configuration
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
// Enable LOAD DATA INFILE
|
||||
$config['driver_options'][MYSQLI_OPT_LOCAL_INFILE] = true;
|
||||
|
||||
if ($config['enable_ssl']) {
|
||||
if (!empty($config['ssl_key'])) {
|
||||
$config['driver_options']['ssl_key'] = $config['ssl_key'];
|
||||
}
|
||||
if (!empty($config['ssl_cert'])) {
|
||||
$config['driver_options']['ssl_cert'] = $config['ssl_cert'];
|
||||
}
|
||||
if (!empty($config['ssl_ca'])) {
|
||||
$config['driver_options']['ssl_ca'] = $config['ssl_ca'];
|
||||
}
|
||||
if (!empty($config['ssl_ca_path'])) {
|
||||
$config['driver_options']['ssl_ca_path'] = $config['ssl_ca_path'];
|
||||
}
|
||||
if (!empty($config['ssl_cipher'])) {
|
||||
$config['driver_options']['ssl_cipher'] = $config['ssl_cipher'];
|
||||
}
|
||||
if (!empty($config['ssl_no_verify'])) {
|
||||
$config['driver_options']['ssl_no_verify'] = $config['ssl_no_verify'];
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the configuration variables in this adapter.
|
||||
*/
|
||||
public function resetConfig()
|
||||
{
|
||||
$this->_config = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default port.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getDefaultPort()
|
||||
{
|
||||
return 3306;
|
||||
}
|
||||
|
||||
protected function _connect()
|
||||
{
|
||||
if ($this->_connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::_connect();
|
||||
|
||||
$this->_connection->query('SET sql_mode = "' . Db::SQL_MODE . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check MySQL version
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkServerVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$requiredVersion = Config::getInstance()->General['minimum_mysql_version'];
|
||||
|
||||
if (version_compare($serverVersion, $requiredVersion) === -1) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MySQL server version
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
// prioritizing SELECT @@VERSION in case the connection version string is incorrect (which can
|
||||
// occur on Azure)
|
||||
$versionInfo = $this->fetchAll('SELECT @@VERSION');
|
||||
|
||||
if (count($versionInfo)) {
|
||||
return $versionInfo[0]['@@VERSION'];
|
||||
}
|
||||
|
||||
return parent::getServerVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check client version compatibility against database server
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkClientVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$clientVersion = $this->getClientVersion();
|
||||
|
||||
// incompatible change to DECIMAL implementation in 5.0.3
|
||||
if (version_compare($serverVersion, '5.0.3') >= 0
|
||||
&& version_compare($clientVersion, '5.0.3') < 0
|
||||
) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of affected rows in last query
|
||||
*
|
||||
* @param mixed $queryResult Result from query()
|
||||
* @return int
|
||||
*/
|
||||
public function rowCount($queryResult)
|
||||
{
|
||||
return mysqli_affected_rows($this->_connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter's required extensions are enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabled()
|
||||
{
|
||||
$extensions = @get_loaded_extensions();
|
||||
return in_array('mysqli', $extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports blobs as fields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBlobDataType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports bulk loading
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBulkLoader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error number
|
||||
*
|
||||
* @param Exception $e
|
||||
* @param string $errno
|
||||
* @return bool
|
||||
*/
|
||||
public function isErrNo($e, $errno)
|
||||
{
|
||||
if (is_null($this->_connection)) {
|
||||
if (preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) {
|
||||
return $match[1] == $errno;
|
||||
}
|
||||
return mysqli_connect_errno() == $errno;
|
||||
}
|
||||
|
||||
return mysqli_errno($this->_connection) == $errno;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute unprepared SQL query and throw away the result
|
||||
*
|
||||
* Workaround some SQL statements not compatible with prepare().
|
||||
* See http://framework.zend.com/issues/browse/ZF-1398
|
||||
*
|
||||
* @param string $sqlQuery
|
||||
* @return int Number of rows affected (SELECT/INSERT/UPDATE/DELETE)
|
||||
*/
|
||||
public function exec($sqlQuery)
|
||||
{
|
||||
$rc = mysqli_query($this->_connection, $sqlQuery);
|
||||
$rowsAffected = mysqli_affected_rows($this->_connection);
|
||||
if (!is_bool($rc)) {
|
||||
mysqli_free_result($rc);
|
||||
}
|
||||
return $rowsAffected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the connection character set equal to utf8?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnectionUTF8()
|
||||
{
|
||||
$charset = mysqli_character_set_name($this->_connection);
|
||||
return $charset === 'utf8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClientVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
|
||||
$version = $this->_connection->server_version;
|
||||
$major = (int)($version / 10000);
|
||||
$minor = (int)($version % 10000 / 100);
|
||||
$revision = (int)($version % 100);
|
||||
|
||||
return $major . '.' . $minor . '.' . $revision;
|
||||
}
|
||||
}
|
266
msd2/tracking/piwik/core/Db/Adapter/Pdo/Mssql.php
Normal file
266
msd2/tracking/piwik/core/Db/Adapter/Pdo/Mssql.php
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Db\Adapter\Pdo;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Piwik\Config;
|
||||
use Piwik\Db\AdapterInterface;
|
||||
use Piwik\Piwik;
|
||||
use Zend_Db;
|
||||
use Zend_Db_Adapter_Exception;
|
||||
use Zend_Db_Adapter_Pdo_Mssql;
|
||||
use Zend_Db_Profiler;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Mssql extends Zend_Db_Adapter_Pdo_Mssql implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Returns connection handle
|
||||
*
|
||||
* @throws Zend_Db_Adapter_Exception
|
||||
* @return resource
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
// if we already have a PDO object, no need to re-connect.
|
||||
if ($this->_connection) {
|
||||
return $this->_connection;
|
||||
}
|
||||
|
||||
$this->_pdoType = "sqlsrv";
|
||||
// get the dsn first, because some adapters alter the $_pdoType
|
||||
//$dsn = $this->_dsn();
|
||||
|
||||
// check for PDO extension
|
||||
if (!extension_loaded('pdo')) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
throw new \Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
|
||||
}
|
||||
|
||||
// check the PDO driver is available
|
||||
if (!in_array($this->_pdoType, PDO::getAvailableDrivers())) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
throw new \Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
|
||||
}
|
||||
|
||||
// create PDO connection
|
||||
$q = $this->_profiler->queryStart('connect', Zend_Db_Profiler::CONNECT);
|
||||
|
||||
// add the persistence flag if we find it in our config array
|
||||
if (isset($this->_config['persistent']) && ($this->_config['persistent'] == true)) {
|
||||
$this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true;
|
||||
}
|
||||
|
||||
try {
|
||||
$serverName = $this->_config["host"];
|
||||
$database = $this->_config["dbname"];
|
||||
if (is_null($database)) {
|
||||
$database = 'master';
|
||||
}
|
||||
$uid = $this->_config['username'];
|
||||
$pwd = $this->_config['password'];
|
||||
if ($this->_config["port"] != "") {
|
||||
$serverName = $serverName . "," . $this->_config["port"];
|
||||
}
|
||||
|
||||
$this->_connection = new PDO("sqlsrv:$serverName", $uid, $pwd, array('Database' => $database));
|
||||
|
||||
if ($this->_connection === false) {
|
||||
die(self::FormatErrors(sqlsrv_errors()));
|
||||
}
|
||||
|
||||
/*
|
||||
$this->_connection = new PDO(
|
||||
$dsn,
|
||||
$this->_config['username'],
|
||||
$this->_config['password'],
|
||||
$this->_config['driver_options']
|
||||
);
|
||||
*/
|
||||
|
||||
$this->_profiler->queryEnd($q);
|
||||
|
||||
// set the PDO connection to perform case-folding on array keys, or not
|
||||
$this->_connection->setAttribute(PDO::ATTR_CASE, $this->_caseFolding);
|
||||
$this->_connection->setAttribute(PDO::SQLSRV_ENCODING_UTF8, true);
|
||||
|
||||
// always use exceptions.
|
||||
$this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
return $this->_connection;
|
||||
} catch (PDOException $e) {
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Exception
|
||||
*/
|
||||
throw new \Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the configuration variables in this adapter.
|
||||
*/
|
||||
public function resetConfig()
|
||||
{
|
||||
$this->_config = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default port.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getDefaultPort()
|
||||
{
|
||||
return 1433;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check MSSQL version
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkServerVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$requiredVersion = Config::getInstance()->General['minimum_mssql_version'];
|
||||
|
||||
if (version_compare($serverVersion, $requiredVersion) === -1) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MSSQL', $serverVersion, $requiredVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Mssql server version
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
try {
|
||||
$stmt = $this->query("SELECT CAST(SERVERPROPERTY('productversion') as VARCHAR) as productversion");
|
||||
$result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
|
||||
if (count($result)) {
|
||||
return $result[0][0];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check client version compatibility against database server
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkClientVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$clientVersion = $this->getClientVersion();
|
||||
|
||||
if (version_compare($serverVersion, '10') >= 0
|
||||
&& version_compare($clientVersion, '10') < 0
|
||||
) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MSSQL', $clientVersion, $serverVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter's required extensions are enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabled()
|
||||
{
|
||||
return extension_loaded('PDO') && extension_loaded('pdo_sqlsrv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports blobs as fields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBlobDataType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports bulk loading
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBulkLoader()
|
||||
{
|
||||
/**
|
||||
* BULK INSERT doesn't have a way to escape a terminator that appears in a value
|
||||
*
|
||||
* @link http://msdn.microsoft.com/en-us/library/ms188365.aspx
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error number
|
||||
*
|
||||
* @param Exception $e
|
||||
* @param string $errno
|
||||
* @return bool
|
||||
*/
|
||||
public function isErrNo($e, $errno)
|
||||
{
|
||||
if (preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) {
|
||||
return $match[1] == $errno;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the connection character set equal to utf8?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnectionUTF8()
|
||||
{
|
||||
//check the getconnection, it's specified on the connection string.
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve client version in PHP style
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string
|
||||
*/
|
||||
public function getClientVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
try {
|
||||
$version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION);
|
||||
$requiredVersion = Config::getInstance()->General['minimum_mssql_client_version'];
|
||||
if (version_compare($version['DriverVer'], $requiredVersion) === -1) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MSSQL', $version['DriverVer'], $requiredVersion)));
|
||||
} else {
|
||||
return $version['DriverVer'];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// In case of the driver doesn't support getting attributes
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
315
msd2/tracking/piwik/core/Db/Adapter/Pdo/Mysql.php
Normal file
315
msd2/tracking/piwik/core/Db/Adapter/Pdo/Mysql.php
Normal file
@ -0,0 +1,315 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Db\Adapter\Pdo;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Piwik\Config;
|
||||
use Piwik\Db;
|
||||
use Piwik\Db\AdapterInterface;
|
||||
use Piwik\Piwik;
|
||||
use Zend_Config;
|
||||
use Zend_Db_Adapter_Pdo_Mysql;
|
||||
use Zend_Db_Select;
|
||||
use Zend_Db_Statement_Interface;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Mysql extends Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $config database configuration
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
// Enable LOAD DATA INFILE
|
||||
if (defined('PDO::MYSQL_ATTR_LOCAL_INFILE')) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_LOCAL_INFILE] = true;
|
||||
}
|
||||
if ($config['enable_ssl']) {
|
||||
if (!empty($config['ssl_key'])) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_KEY] = $config['ssl_key'];
|
||||
}
|
||||
if (!empty($config['ssl_cert'])) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_CERT] = $config['ssl_cert'];
|
||||
}
|
||||
if (!empty($config['ssl_ca'])) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_CA] = $config['ssl_ca'];
|
||||
}
|
||||
if (!empty($config['ssl_ca_path'])) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_CAPATH] = $config['ssl_ca_path'];
|
||||
}
|
||||
if (!empty($config['ssl_cipher'])) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_CIPHER] = $config['ssl_cipher'];
|
||||
}
|
||||
if (!empty($config['ssl_no_verify'])
|
||||
&& defined('PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT')
|
||||
) {
|
||||
$config['driver_options'][PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false;
|
||||
}
|
||||
}
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns connection handle
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
if ($this->_connection) {
|
||||
return $this->_connection;
|
||||
}
|
||||
|
||||
$this->_connect();
|
||||
|
||||
/**
|
||||
* Before MySQL 5.1.17, server-side prepared statements
|
||||
* do not use the query cache.
|
||||
* @see http://dev.mysql.com/doc/refman/5.1/en/query-cache-operation.html
|
||||
*
|
||||
* MySQL also does not support preparing certain DDL and SHOW
|
||||
* statements.
|
||||
* @see http://framework.zend.com/issues/browse/ZF-1398
|
||||
*/
|
||||
$this->_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
||||
|
||||
return $this->_connection;
|
||||
}
|
||||
|
||||
protected function _connect()
|
||||
{
|
||||
if ($this->_connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
parent::_connect();
|
||||
|
||||
// MYSQL_ATTR_USE_BUFFERED_QUERY will use more memory when enabled
|
||||
// $this->_connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
|
||||
|
||||
$this->_connection->exec('SET sql_mode = "' . Db::SQL_MODE . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the configuration variables in this adapter.
|
||||
*/
|
||||
public function resetConfig()
|
||||
{
|
||||
$this->_config = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default port.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getDefaultPort()
|
||||
{
|
||||
return 3306;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check MySQL version
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkServerVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$requiredVersion = Config::getInstance()->General['minimum_mysql_version'];
|
||||
|
||||
if (version_compare($serverVersion, $requiredVersion) === -1) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('MySQL', $serverVersion, $requiredVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MySQL server version
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getServerVersion()
|
||||
{
|
||||
// prioritizing SELECT @@VERSION in case the connection version string is incorrect (which can
|
||||
// occur on Azure)
|
||||
$versionInfo = $this->fetchAll('SELECT @@VERSION');
|
||||
|
||||
if (count($versionInfo)) {
|
||||
return $versionInfo[0]['@@VERSION'];
|
||||
}
|
||||
|
||||
return parent::getServerVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check client version compatibility against database server
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkClientVersion()
|
||||
{
|
||||
$serverVersion = $this->getServerVersion();
|
||||
$clientVersion = $this->getClientVersion();
|
||||
|
||||
// incompatible change to DECIMAL implementation in 5.0.3
|
||||
if (version_compare($serverVersion, '5.0.3') >= 0
|
||||
&& version_compare($clientVersion, '5.0.3') < 0
|
||||
) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionIncompatibleClientServerVersions', array('MySQL', $clientVersion, $serverVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter's required extensions are enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabled()
|
||||
{
|
||||
return extension_loaded('PDO') && extension_loaded('pdo_mysql') && in_array('mysql', PDO::getAvailableDrivers());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports blobs as fields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBlobDataType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports bulk loading
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBulkLoader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error number
|
||||
*
|
||||
* @param Exception $e
|
||||
* @param string $errno
|
||||
* @return bool
|
||||
*/
|
||||
public function isErrNo($e, $errno)
|
||||
{
|
||||
if (preg_match('/(?:\[|\s)([0-9]{4})(?:\]|\s)/', $e->getMessage(), $match)) {
|
||||
return $match[1] == $errno;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the connection character set equal to utf8?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnectionUTF8()
|
||||
{
|
||||
$charsetInfo = $this->fetchAll('SHOW VARIABLES LIKE ?', array('character_set_connection'));
|
||||
|
||||
if (empty($charsetInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$charset = $charsetInfo[0]['Value'];
|
||||
return $charset === 'utf8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of affected rows in last query
|
||||
*
|
||||
* @param mixed $queryResult Result from query()
|
||||
* @return int
|
||||
*/
|
||||
public function rowCount($queryResult)
|
||||
{
|
||||
return $queryResult->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve client version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClientVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
try {
|
||||
$version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION);
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// In case of the driver doesn't support getting attributes
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \Zend_Db_Statement_Pdo[]
|
||||
*/
|
||||
private $cachePreparedStatement = array();
|
||||
|
||||
/**
|
||||
* Prepares and executes an SQL statement with bound data.
|
||||
* Caches prepared statements to avoid preparing the same query more than once
|
||||
*
|
||||
* @param string|Zend_Db_Select $sql The SQL statement with placeholders.
|
||||
* @param array $bind An array of data to bind to the placeholders.
|
||||
* @return Zend_Db_Statement_Interface
|
||||
*/
|
||||
public function query($sql, $bind = array())
|
||||
{
|
||||
if (!is_string($sql)) {
|
||||
return parent::query($sql, $bind);
|
||||
}
|
||||
|
||||
if (isset($this->cachePreparedStatement[$sql])) {
|
||||
if (!is_array($bind)) {
|
||||
$bind = array($bind);
|
||||
}
|
||||
|
||||
$stmt = $this->cachePreparedStatement[$sql];
|
||||
$stmt->execute($bind);
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
$stmt = parent::query($sql, $bind);
|
||||
$this->cachePreparedStatement[$sql] = $stmt;
|
||||
return $stmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override _dsn() to ensure host and port to not be passed along
|
||||
* if unix_socket is set since setting both causes unexpected behaviour
|
||||
* @see http://php.net/manual/en/ref.pdo-mysql.connection.php
|
||||
*/
|
||||
protected function _dsn()
|
||||
{
|
||||
if (!empty($this->_config['unix_socket'])) {
|
||||
unset($this->_config['host']);
|
||||
unset($this->_config['port']);
|
||||
}
|
||||
|
||||
return parent::_dsn();
|
||||
}
|
||||
}
|
183
msd2/tracking/piwik/core/Db/Adapter/Pdo/Pgsql.php
Normal file
183
msd2/tracking/piwik/core/Db/Adapter/Pdo/Pgsql.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Db\Adapter\Pdo;
|
||||
|
||||
use Exception;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Piwik\Config;
|
||||
use Piwik\Db\AdapterInterface;
|
||||
use Piwik\Piwik;
|
||||
use Zend_Db_Adapter_Pdo_Pgsql;
|
||||
|
||||
/**
|
||||
*/
|
||||
class Pgsql extends Zend_Db_Adapter_Pdo_Pgsql implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* Reset the configuration variables in this adapter.
|
||||
*/
|
||||
public function resetConfig()
|
||||
{
|
||||
$this->_config = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default port.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getDefaultPort()
|
||||
{
|
||||
return 5432;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check PostgreSQL version
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkServerVersion()
|
||||
{
|
||||
$databaseVersion = $this->getServerVersion();
|
||||
$requiredVersion = Config::getInstance()->General['minimum_pgsql_version'];
|
||||
|
||||
if (version_compare($databaseVersion, $requiredVersion) === -1) {
|
||||
throw new Exception(Piwik::translate('General_ExceptionDatabaseVersion', array('PostgreSQL', $databaseVersion, $requiredVersion)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check client version compatibility against database server
|
||||
*/
|
||||
public function checkClientVersion()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter's required extensions are enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnabled()
|
||||
{
|
||||
return extension_loaded('PDO') && extension_loaded('pdo_pgsql');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports blobs as fields
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBlobDataType()
|
||||
{
|
||||
// large objects must be loaded from a file using a non-SQL API
|
||||
// and then referenced by the object ID (oid);
|
||||
// the alternative, bytea fields, incur a space and time
|
||||
// penalty for encoding/decoding
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this adapter supports bulk loading
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasBulkLoader()
|
||||
{
|
||||
/**
|
||||
* COPY ?
|
||||
*
|
||||
* @link http://www.postgresql.org/docs/current/interactive/sql-copy.html
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test error number
|
||||
*
|
||||
* @param Exception $e
|
||||
* @param string $errno
|
||||
* @return bool
|
||||
*/
|
||||
public function isErrNo($e, $errno)
|
||||
{
|
||||
// map MySQL driver-specific error codes to PostgreSQL SQLSTATE
|
||||
$map = array(
|
||||
// MySQL: Unknown database '%s'
|
||||
// PostgreSQL: database "%s" does not exist
|
||||
'1049' => '08006',
|
||||
|
||||
// MySQL: Table '%s' already exists
|
||||
// PostgreSQL: relation "%s" already exists
|
||||
'1050' => '42P07',
|
||||
|
||||
// MySQL: Unknown column '%s' in '%s'
|
||||
// PostgreSQL: column "%s" does not exist
|
||||
'1054' => '42703',
|
||||
|
||||
// MySQL: Duplicate column name '%s'
|
||||
// PostgreSQL: column "%s" of relation "%s" already exists
|
||||
'1060' => '42701',
|
||||
|
||||
// MySQL: Duplicate key name '%s'
|
||||
// PostgreSQL: relation "%s" already exists
|
||||
'1061' => '42P07',
|
||||
|
||||
// MySQL: Duplicate entry '%s' for key '%s'
|
||||
// PostgreSQL: duplicate key violates unique constraint
|
||||
'1062' => '23505',
|
||||
|
||||
// MySQL: Can't DROP '%s'; check that column/key exists
|
||||
// PostgreSQL: index "%s" does not exist
|
||||
'1091' => '42704',
|
||||
|
||||
// MySQL: Table '%s.%s' doesn't exist
|
||||
// PostgreSQL: relation "%s" does not exist
|
||||
'1146' => '42P01',
|
||||
);
|
||||
|
||||
if (preg_match('/([0-9]{2}[0-9P][0-9]{2})/', $e->getMessage(), $match)) {
|
||||
return $match[1] == $map[$errno];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the connection character set equal to utf8?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConnectionUTF8()
|
||||
{
|
||||
$charset = $this->fetchOne('SHOW client_encoding');
|
||||
return strtolower($charset) === 'utf8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve client version in PHP style
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClientVersion()
|
||||
{
|
||||
$this->_connect();
|
||||
try {
|
||||
$version = $this->_connection->getAttribute(PDO::ATTR_CLIENT_VERSION);
|
||||
$matches = null;
|
||||
if (preg_match('/((?:[0-9]{1,2}\.){1,3}[0-9]{1,2})/', $version, $matches)) {
|
||||
return $matches[1];
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// In case of the driver doesn't support getting attributes
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user