Skip to content

Commit

Permalink
UTF-8 Multibyte (utf8mb4) support
Browse files Browse the repository at this point in the history
Added getName and getServerType methods to JDatabaseDriver to let the CMS (and its extensions) figure out the type of the database driver in use.
  • Loading branch information
Nicholas K. Dionysopoulos committed Jun 13, 2015
1 parent e2621e3 commit 4727bca
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 0 deletions.
75 changes: 75 additions & 0 deletions libraries/joomla/database/driver.php
Expand Up @@ -52,6 +52,15 @@ abstract class JDatabaseDriver extends JDatabase implements JDatabaseInterface
*/
public $name;

/**
* The type of the database server family supported by this driver. Examples: mysql, oracle, postgresql, mssql,
* sqlite.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType;

/**
* @var resource The database connection resource.
* @since 11.1
Expand Down Expand Up @@ -1035,6 +1044,72 @@ public function getImporter()
return $o;
}

/**
* Get the name of the database driver. If $this->name is not set it will try guessing the driver name from the
* class name.
*
* @return string
* @since CMS 3.5.0
*/
public function getName()
{
if (empty($this->name))
{
$className = get_class($this);
$className = str_replace('JDatabaseDriver', '', $className);
$this->name = strtolower($className);
}

return $this->name;
}

/**
* Get the server family type, e.g. mysql, postgresql, oracle, sqlite, mssql. If $this->serverType is not set it
* will attempt guessing the server family type from the driver name. If this is not possible the driver name will
* be returned instead.
*
* @return string
* @since CMS 3.5.0
*/
public function getServerType()
{
if (empty($this->serverType))
{
$name = $this->getName();

if (stristr($name, 'mysql') !== false)
{
$this->serverType = 'mysql';
}
elseif (stristr($name, 'postgre') !== false)
{
$this->serverType = 'postgresql';
}
elseif (stristr($name, 'oracle') !== false)
{
$this->serverType = 'oracle';
}
elseif (stristr($name, 'sqlite') !== false)
{
$this->serverType = 'sqlite';
}
elseif (stristr($name, 'sqlsrv') !== false)
{
$this->serverType = 'mssql';
}
elseif (stristr($name, 'mssql') !== false)
{
$this->serverType = 'mssql';
}
else
{
$this->serverType = $name;
}
}

return $this->serverType;
}

/**
* Get the current query object or a new JDatabaseQuery object.
*
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/mysqli.php
Expand Up @@ -25,6 +25,14 @@ class JDatabaseDriverMysqli extends JDatabaseDriver
*/
public $name = 'mysqli';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'mysql';

/**
* @var mysqli The database connection resource.
* @since 11.1
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/oracle.php
Expand Up @@ -25,6 +25,14 @@ class JDatabaseDriverOracle extends JDatabaseDriverPdo
*/
public $name = 'oracle';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'oracle';

/**
* The character(s) used to quote SQL statement names such as table names or field names,
* etc. The child classes should define this as necessary. If a single character string the
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/pdomysql.php
Expand Up @@ -27,6 +27,14 @@ class JDatabaseDriverPdomysql extends JDatabaseDriverPdo
*/
public $name = 'pdomysql';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'mysql';

/**
* The character(s) used to quote SQL statement names such as table names or field names,
* etc. The child classes should define this as necessary. If a single character string the
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/postgresql.php
Expand Up @@ -24,6 +24,14 @@ class JDatabaseDriverPostgresql extends JDatabaseDriver
*/
public $name = 'postgresql';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'postgresql';

/**
* Quote for named objects
*
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/sqlite.php
Expand Up @@ -25,6 +25,14 @@ class JDatabaseDriverSqlite extends JDatabaseDriverPdo
*/
public $name = 'sqlite';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'sqlite';

/**
* The character(s) used to quote SQL statement names such as table names or field names,
* etc. The child classes should define this as necessary. If a single character string the
Expand Down
8 changes: 8 additions & 0 deletions libraries/joomla/database/driver/sqlsrv.php
Expand Up @@ -25,6 +25,14 @@ class JDatabaseDriverSqlsrv extends JDatabaseDriver
*/
public $name = 'sqlsrv';

/**
* The type of the database server family supported by this driver.
*
* @var string
* @since CMS 3.5.0
*/
public $serverType = 'mssql';

/**
* The character(s) used to quote SQL statement names such as table names or field names,
* etc. The child classes should define this as necessary. If a single character string the
Expand Down

0 comments on commit 4727bca

Please sign in to comment.