Skip to content

Commit

Permalink
UTF-8 Multibyte (utf8mb4) support
Browse files Browse the repository at this point in the history
Add JDatabaseDriver method to get the connection collation
  • Loading branch information
Nicholas K. Dionysopoulos committed Jun 13, 2015
1 parent 854d77d commit 060d2ee
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver.php
Expand Up @@ -664,6 +664,14 @@ protected function getCreateDatabaseQuery($options, $utf)
*/
abstract public function getCollation();

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
abstract public function getConnectionCollation();

/**
* Method that provides access to the underlying database connection. Useful for when you need to call a
* proprietary method such as postgresql's lo_* methods.
Expand Down
24 changes: 24 additions & 0 deletions libraries/joomla/database/driver/mysqli.php
Expand Up @@ -338,6 +338,30 @@ public function getCollation()
}
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
$this->connect();

// Attempt to get the database collation by accessing the server system variable.
$this->setQuery('SHOW VARIABLES LIKE "collation_connection"');
$result = $this->loadObject();

if (property_exists($result, 'Value'))
{
return $result->Value;
}
else
{
return false;
}
}

/**
* Get the number of returned rows for the previous executed SQL statement.
*
Expand Down
11 changes: 11 additions & 0 deletions libraries/joomla/database/driver/oracle.php
Expand Up @@ -161,6 +161,17 @@ public function getCollation()
return $this->charset;
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
return $this->charset;
}

/**
* Get a query to run and verify the database is operational.
*
Expand Down
24 changes: 24 additions & 0 deletions libraries/joomla/database/driver/pdomysql.php
Expand Up @@ -214,6 +214,30 @@ public function getCollation()
}
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
$this->connect();

// Attempt to get the database collation by accessing the server system variable.
$this->setQuery('SHOW VARIABLES LIKE "collation_connection"');
$result = $this->loadObject();

if (property_exists($result, 'Value'))
{
return $result->Value;
}
else
{
return false;
}
}

/**
* Shows the table CREATE statement that creates the given tables.
*
Expand Down
11 changes: 11 additions & 0 deletions libraries/joomla/database/driver/postgresql.php
Expand Up @@ -265,6 +265,17 @@ public function getCollation()
return $array[0]['lc_collate'];
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
return pg_client_encoding($this->connection);
}

/**
* Get the number of returned rows for the previous executed SQL statement.
*
Expand Down
11 changes: 11 additions & 0 deletions libraries/joomla/database/driver/sqlite.php
Expand Up @@ -118,6 +118,17 @@ public function getCollation()
return $this->charset;
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
return $this->charset;
}

/**
* Shows the table CREATE statement that creates the given tables.
*
Expand Down
12 changes: 12 additions & 0 deletions libraries/joomla/database/driver/sqlsrv.php
Expand Up @@ -309,6 +309,18 @@ public function getCollation()
return 'MSSQL UTF-8 (UCS2)';
}

/**
* Method to get the database connection collation, as reported by the driver. If the connector doesn't support
* reporting this value please return an empty string.
*
* @return string
*/
public function getConnectionCollation()
{
// TODO: Not fake this
return 'MSSQL UTF-8 (UCS2)';
}

/**
* Get the number of returned rows for the previous executed SQL statement.
*
Expand Down

0 comments on commit 060d2ee

Please sign in to comment.