primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,778 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* This crazy three line bit is required to convince Joomla! to load JDatabaseInterface which is on the same file as the
* abstract JDatabaseDriver class for reasons that beat me. It makes no sense. Furthermore, jimport on Joomla! 3.4
* doesn't seem to actually load the file, merely registering the association in the autoloader. Hence the class_exists
* in here.
*/
jimport('joomla.database.driver');
jimport('joomla.database.driver.mysqli');
class_exists('JDatabaseDriver', true);
/**
* Joomla! pass-through database driver.
*/
class F0FDatabaseDriverJoomla extends F0FDatabase implements F0FDatabaseInterface
{
/** @var F0FDatabase The real database connection object */
private $dbo;
/**
* @var string 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
* same character is used for both sides of the quoted name, else the first character will be
* used for the opening quote and the second for the closing quote.
* @since 11.1
*/
protected $nameQuote = '';
/**
* Is this driver supported
*
* @since 11.2
*/
public static function isSupported()
{
return true;
}
/**
* Database object constructor
*
* @param array $options List of options used to configure the connection
*/
public function __construct($options = array())
{
// Get best matching Akeeba Backup driver instance
$this->dbo = JFactory::getDbo();
$reflection = new ReflectionClass($this->dbo);
try
{
$refProp = $reflection->getProperty('nameQuote');
$refProp->setAccessible(true);
$this->nameQuote = $refProp->getValue($this->dbo);
}
catch (Exception $e)
{
$this->nameQuote = '`';
}
}
public function close()
{
if (method_exists($this->dbo, 'close'))
{
$this->dbo->close();
}
elseif (method_exists($this->dbo, 'disconnect'))
{
$this->dbo->disconnect();
}
}
public function disconnect()
{
$this->close();
}
public function open()
{
if (method_exists($this->dbo, 'open'))
{
$this->dbo->open();
}
elseif (method_exists($this->dbo, 'connect'))
{
$this->dbo->connect();
}
}
public function connect()
{
$this->open();
}
public function connected()
{
if (method_exists($this->dbo, 'connected'))
{
return $this->dbo->connected();
}
return true;
}
public function escape($text, $extra = false)
{
return $this->dbo->escape($text, $extra);
}
public function execute()
{
if (method_exists($this->dbo, 'execute'))
{
return $this->dbo->execute();
}
return $this->dbo->query();
}
public function getAffectedRows()
{
if (method_exists($this->dbo, 'getAffectedRows'))
{
return $this->dbo->getAffectedRows();
}
return 0;
}
public function getCollation()
{
if (method_exists($this->dbo, 'getCollation'))
{
return $this->dbo->getCollation();
}
return 'utf8_general_ci';
}
public function getConnection()
{
if (method_exists($this->dbo, 'getConnection'))
{
return $this->dbo->getConnection();
}
return null;
}
public function getCount()
{
if (method_exists($this->dbo, 'getCount'))
{
return $this->dbo->getCount();
}
return 0;
}
public function getDateFormat()
{
if (method_exists($this->dbo, 'getDateFormat'))
{
return $this->dbo->getDateFormat();
}
return 'Y-m-d H:i:s';;
}
public function getMinimum()
{
if (method_exists($this->dbo, 'getMinimum'))
{
return $this->dbo->getMinimum();
}
return '5.0.40';
}
public function getNullDate()
{
if (method_exists($this->dbo, 'getNullDate'))
{
return $this->dbo->getNullDate();
}
return '0000-00-00 00:00:00';
}
public function getNumRows($cursor = null)
{
if (method_exists($this->dbo, 'getNumRows'))
{
return $this->dbo->getNumRows($cursor);
}
return 0;
}
public function getQuery($new = false)
{
if (method_exists($this->dbo, 'getQuery'))
{
return $this->dbo->getQuery($new);
}
return null;
}
public function getTableColumns($table, $typeOnly = true)
{
if (method_exists($this->dbo, 'getTableColumns'))
{
return $this->dbo->getTableColumns($table, $typeOnly);
}
$result = $this->dbo->getTableFields(array($table), $typeOnly);
return $result[$table];
}
public function getTableKeys($tables)
{
if (method_exists($this->dbo, 'getTableKeys'))
{
return $this->dbo->getTableKeys($tables);
}
return array();
}
public function getTableList()
{
if (method_exists($this->dbo, 'getTableList'))
{
return $this->dbo->getTableList();
}
return array();
}
public function getVersion()
{
if (method_exists($this->dbo, 'getVersion'))
{
return $this->dbo->getVersion();
}
return '5.0.40';
}
public function insertid()
{
if (method_exists($this->dbo, 'insertid'))
{
return $this->dbo->insertid();
}
return null;
}
public function insertObject($table, &$object, $key = null)
{
if (method_exists($this->dbo, 'insertObject'))
{
return $this->dbo->insertObject($table, $object, $key);
}
return null;
}
public function loadAssoc()
{
if (method_exists($this->dbo, 'loadAssoc'))
{
return $this->dbo->loadAssoc();
}
return null;
}
public function loadAssocList($key = null, $column = null)
{
if (method_exists($this->dbo, 'loadAssocList'))
{
return $this->dbo->loadAssocList($key, $column);
}
return null;
}
public function loadObject($class = 'stdClass')
{
if (method_exists($this->dbo, 'loadObject'))
{
return $this->dbo->loadObject($class);
}
return null;
}
public function loadObjectList($key = '', $class = 'stdClass')
{
if (method_exists($this->dbo, 'loadObjectList'))
{
return $this->dbo->loadObjectList($key, $class);
}
return null;
}
public function loadResult()
{
if (method_exists($this->dbo, 'loadResult'))
{
return $this->dbo->loadResult();
}
return null;
}
public function loadRow()
{
if (method_exists($this->dbo, 'loadRow'))
{
return $this->dbo->loadRow();
}
return null;
}
public function loadRowList($key = null)
{
if (method_exists($this->dbo, 'loadRowList'))
{
return $this->dbo->loadRowList($key);
}
return null;
}
public function lockTable($tableName)
{
if (method_exists($this->dbo, 'lockTable'))
{
return $this->dbo->lockTable($this);
}
return $this;
}
public function quote($text, $escape = true)
{
if (method_exists($this->dbo, 'quote'))
{
return $this->dbo->quote($text, $escape);
}
return $text;
}
public function select($database)
{
if (method_exists($this->dbo, 'select'))
{
return $this->dbo->select($database);
}
return false;
}
public function setQuery($query, $offset = 0, $limit = 0)
{
if (method_exists($this->dbo, 'setQuery'))
{
return $this->dbo->setQuery($query, $offset, $limit);
}
return false;
}
public function transactionCommit($toSavepoint = false)
{
if (method_exists($this->dbo, 'transactionCommit'))
{
$this->dbo->transactionCommit($toSavepoint);
}
}
public function transactionRollback($toSavepoint = false)
{
if (method_exists($this->dbo, 'transactionRollback'))
{
$this->dbo->transactionRollback($toSavepoint);
}
}
public function transactionStart($asSavepoint = false)
{
if (method_exists($this->dbo, 'transactionStart'))
{
$this->dbo->transactionStart($asSavepoint);
}
}
public function unlockTables()
{
if (method_exists($this->dbo, 'unlockTables'))
{
return $this->dbo->unlockTables();
}
return $this;
}
public function updateObject($table, &$object, $key, $nulls = false)
{
if (method_exists($this->dbo, 'updateObject'))
{
return $this->dbo->updateObject($table, $object, $key, $nulls);
}
return false;
}
public function getLog()
{
if (method_exists($this->dbo, 'getLog'))
{
return $this->dbo->getLog();
}
return array();
}
public function dropTable($table, $ifExists = true)
{
if (method_exists($this->dbo, 'dropTable'))
{
return $this->dbo->dropTable($table, $ifExists);
}
return $this;
}
public function getTableCreate($tables)
{
if (method_exists($this->dbo, 'getTableCreate'))
{
return $this->dbo->getTableCreate($tables);
}
return array();
}
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
{
if (method_exists($this->dbo, 'renameTable'))
{
return $this->dbo->renameTable($oldTable, $newTable, $backup, $prefix);
}
return $this;
}
public function setUtf()
{
if (method_exists($this->dbo, 'setUtf'))
{
return $this->dbo->setUtf();
}
return false;
}
protected function freeResult($cursor = null)
{
return false;
}
/**
* Method to get an array of values from the <var>$offset</var> field in each row of the result set from
* the database query.
*
* @param integer $offset The row offset to use to build the result array.
*
* @return mixed The return value or null if the query failed.
*
* @since 11.1
* @throws RuntimeException
*/
public function loadColumn($offset = 0)
{
if (method_exists($this->dbo, 'loadColumn'))
{
return $this->dbo->loadColumn($offset);
}
return $this->dbo->loadResultArray($offset);
}
/**
* Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection
* risks and reserved word conflicts.
*
* @param mixed $name The identifier name to wrap in quotes, or an array of identifier names to wrap in quotes.
* Each type supports dot-notation name.
* @param mixed $as The AS query part associated to $name. It can be string or array, in latter case it has to be
* same length of $name; if is null there will not be any AS part for string or array element.
*
* @return mixed The quote wrapped name, same type of $name.
*
* @since 11.1
*/
public function quoteName($name, $as = null)
{
if (is_string($name))
{
$quotedName = $this->quoteNameStr(explode('.', $name));
$quotedAs = '';
if (!is_null($as))
{
settype($as, 'array');
$quotedAs .= ' AS ' . $this->quoteNameStr($as);
}
return $quotedName . $quotedAs;
}
else
{
$fin = array();
if (is_null($as))
{
foreach ($name as $str)
{
$fin[] = $this->quoteName($str);
}
}
elseif (is_array($name) && (count($name) == count($as)))
{
$count = count($name);
for ($i = 0; $i < $count; $i++)
{
$fin[] = $this->quoteName($name[$i], $as[$i]);
}
}
return $fin;
}
}
/**
* Quote strings coming from quoteName call.
*
* @param array $strArr Array of strings coming from quoteName dot-explosion.
*
* @return string Dot-imploded string of quoted parts.
*
* @since 11.3
*/
protected function quoteNameStr($strArr)
{
$parts = array();
$q = $this->nameQuote;
foreach ($strArr as $part)
{
if (is_null($part))
{
continue;
}
if (strlen($q) == 1)
{
$parts[] = $q . $part . $q;
}
else
{
$parts[] = $q{0} . $part . $q{1};
}
}
return implode('.', $parts);
}
/**
* Gets the error message from the database connection.
*
* @param boolean $escaped True to escape the message string for use in JavaScript.
*
* @return string The error message for the most recent query.
*
* @since 11.1
*/
public function getErrorMsg($escaped = false)
{
if (method_exists($this->dbo, 'getErrorMsg'))
{
$errorMessage = $this->dbo->getErrorMsg();
}
else
{
$errorMessage = $this->errorMsg;
}
if ($escaped)
{
return addslashes($errorMessage);
}
return $errorMessage;
}
/**
* Gets the error number from the database connection.
*
* @return integer The error number for the most recent query.
*
* @since 11.1
* @deprecated 13.3 (Platform) & 4.0 (CMS)
*/
public function getErrorNum()
{
if (method_exists($this->dbo, 'getErrorNum'))
{
$errorNum = $this->dbo->getErrorNum();
}
else
{
$errorNum = $this->getErrorNum;
}
return $errorNum;
}
/**
* Return the most recent error message for the database connector.
*
* @param boolean $showSQL True to display the SQL statement sent to the database as well as the error.
*
* @return string The error message for the most recent query.
*/
public function stderr($showSQL = false)
{
if (method_exists($this->dbo, 'stderr'))
{
return $this->dbo->stderr($showSQL);
}
return parent::stderr($showSQL);
}
/**
* Magic method to proxy all calls to the loaded database driver object
*/
public function __call($name, array $arguments)
{
if (is_null($this->dbo))
{
throw new Exception('F0F database driver is not loaded');
}
if (method_exists($this->dbo, $name) || in_array($name, array('q', 'nq', 'qn', 'query')))
{
switch ($name)
{
case 'execute':
$name = 'query';
break;
case 'q':
$name = 'quote';
break;
case 'qn':
case 'nq':
switch (count($arguments))
{
case 0 :
$result = $this->quoteName();
break;
case 1 :
$result = $this->quoteName($arguments[0]);
break;
case 2:
default:
$result = $this->quoteName($arguments[0], $arguments[1]);
break;
}
return $result;
break;
}
switch (count($arguments))
{
case 0 :
$result = $this->dbo->$name();
break;
case 1 :
$result = $this->dbo->$name($arguments[0]);
break;
case 2:
$result = $this->dbo->$name($arguments[0], $arguments[1]);
break;
case 3:
$result = $this->dbo->$name($arguments[0], $arguments[1], $arguments[2]);
break;
case 4:
$result = $this->dbo->$name($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
break;
case 5:
$result = $this->dbo->$name($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
break;
default:
// Resort to using call_user_func_array for many segments
$result = call_user_func_array(array($this->dbo, $name), $arguments);
}
if (class_exists('JDatabase') && is_object($result) && ($result instanceof JDatabase))
{
return $this;
}
return $result;
}
else
{
throw new \Exception('Method ' . $name . ' not found in F0FDatabase');
}
}
public function __get($name)
{
if (isset($this->dbo->$name) || property_exists($this->dbo, $name))
{
return $this->dbo->$name;
}
else
{
$this->dbo->$name = null;
user_error('Database driver does not support property ' . $name);
}
}
public function __set($name, $value)
{
if (isset($this->dbo->name) || property_exists($this->dbo, $name))
{
$this->dbo->$name = $value;
}
else
{
$this->dbo->$name = null;
user_error('Database driver not support property ' . $name);
}
}
}

View File

@ -0,0 +1,577 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* MySQL database driver
*
* @see http://dev.mysql.com/doc/
* @since 12.1
* @deprecated Will be removed when the minimum supported PHP version no longer includes the deprecated PHP `mysql` extension
*/
class F0FDatabaseDriverMysql extends F0FDatabaseDriverMysqli
{
/**
* The name of the database driver.
*
* @var string
* @since 12.1
*/
public $name = 'mysql';
/**
* Constructor.
*
* @param array $options Array of database options with keys: host, user, password, database, select.
*
* @since 12.1
*/
public function __construct($options)
{
// PHP's `mysql` extension is not present in PHP 7, block instantiation in this environment
if (PHP_MAJOR_VERSION >= 7)
{
throw new RuntimeException(
'This driver is unsupported in PHP 7, please use the MySQLi or PDO MySQL driver instead.'
);
}
// Get some basic values from the options.
$options['host'] = (isset($options['host'])) ? $options['host'] : 'localhost';
$options['user'] = (isset($options['user'])) ? $options['user'] : 'root';
$options['password'] = (isset($options['password'])) ? $options['password'] : '';
$options['database'] = (isset($options['database'])) ? $options['database'] : '';
$options['select'] = (isset($options['select'])) ? (bool) $options['select'] : true;
// Finalize initialisation.
parent::__construct($options);
}
/**
* Destructor.
*
* @since 12.1
*/
public function __destruct()
{
$this->disconnect();
}
/**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
*
* @since 12.1
* @throws RuntimeException
*/
public function connect()
{
if ($this->connection)
{
return;
}
// Make sure the MySQL extension for PHP is installed and enabled.
if (!self::isSupported())
{
throw new RuntimeException('Could not connect to MySQL.');
}
// Attempt to connect to the server.
if (!($this->connection = @ mysql_connect($this->options['host'], $this->options['user'], $this->options['password'], true)))
{
throw new RuntimeException('Could not connect to MySQL.');
}
// Set sql_mode to non_strict mode
mysql_query("SET @@SESSION.sql_mode = '';", $this->connection);
// If auto-select is enabled select the given database.
if ($this->options['select'] && !empty($this->options['database']))
{
$this->select($this->options['database']);
}
// Pre-populate the UTF-8 Multibyte compatibility flag based on server version
$this->utf8mb4 = $this->serverClaimsUtf8mb4Support();
// Set the character set (needed for MySQL 4.1.2+).
$this->utf = $this->setUtf();
// Turn MySQL profiling ON in debug mode:
if ($this->debug && $this->hasProfiling())
{
mysql_query("SET profiling = 1;", $this->connection);
}
}
/**
* Disconnects the database.
*
* @return void
*
* @since 12.1
*/
public function disconnect()
{
// Close the connection.
if (is_resource($this->connection))
{
foreach ($this->disconnectHandlers as $h)
{
call_user_func_array($h, array( &$this));
}
mysql_close($this->connection);
}
$this->connection = null;
}
/**
* Method to escape a string for usage in an SQL statement.
*
* @param string $text The string to be escaped.
* @param boolean $extra Optional parameter to provide extra escaping.
*
* @return string The escaped string.
*
* @since 12.1
*/
public function escape($text, $extra = false)
{
$this->connect();
$result = mysql_real_escape_string($text, $this->getConnection());
if ($extra)
{
$result = addcslashes($result, '%_');
}
return $result;
}
/**
* Test to see if the MySQL connector is available.
*
* @return boolean True on success, false otherwise.
*
* @since 12.1
*/
public static function isSupported()
{
return (function_exists('mysql_connect'));
}
/**
* Determines if the connection to the server is active.
*
* @return boolean True if connected to the database engine.
*
* @since 12.1
*/
public function connected()
{
if (is_resource($this->connection))
{
return @mysql_ping($this->connection);
}
return false;
}
/**
* Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE for the previous executed SQL statement.
*
* @return integer The number of affected rows.
*
* @since 12.1
*/
public function getAffectedRows()
{
$this->connect();
return mysql_affected_rows($this->connection);
}
/**
* Get the number of returned rows for the previous executed SQL statement.
* This command is only valid for statements like SELECT or SHOW that return an actual result set.
* To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use getAffectedRows().
*
* @param resource $cursor An optional database cursor resource to extract the row count from.
*
* @return integer The number of returned rows.
*
* @since 12.1
*/
public function getNumRows($cursor = null)
{
$this->connect();
return mysql_num_rows($cursor ? $cursor : $this->cursor);
}
/**
* Get the version of the database connector.
*
* @return string The database connector version.
*
* @since 12.1
*/
public function getVersion()
{
$this->connect();
return mysql_get_server_info($this->connection);
}
/**
* Method to get the auto-incremented value from the last INSERT statement.
*
* @return integer The value of the auto-increment field from the last inserted row.
*
* @since 12.1
*/
public function insertid()
{
$this->connect();
return mysql_insert_id($this->connection);
}
/**
* Execute the SQL statement.
*
* @return mixed A database cursor resource on success, boolean false on failure.
*
* @since 12.1
* @throws RuntimeException
*/
public function execute()
{
$this->connect();
if (!is_resource($this->connection))
{
if (class_exists('JLog'))
{
JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database');
}
throw new RuntimeException($this->errorMsg, $this->errorNum);
}
// Take a local copy so that we don't modify the original query and cause issues later
$query = $this->replacePrefix((string) $this->sql);
if (!($this->sql instanceof F0FDatabaseQuery) && ($this->limit > 0 || $this->offset > 0))
{
$query .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
}
// Increment the query counter.
$this->count++;
// Reset the error values.
$this->errorNum = 0;
$this->errorMsg = '';
// If debugging is enabled then let's log the query.
if ($this->debug)
{
// Add the query to the object queue.
$this->log[] = $query;
if (class_exists('JLog'))
{
JLog::add($query, JLog::DEBUG, 'databasequery');
}
$this->timings[] = microtime(true);
}
// Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
$this->cursor = @mysql_query($query, $this->connection);
if ($this->debug)
{
$this->timings[] = microtime(true);
if (defined('DEBUG_BACKTRACE_IGNORE_ARGS'))
{
$this->callStacks[] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
else
{
$this->callStacks[] = debug_backtrace();
}
}
// If an error occurred handle it.
if (!$this->cursor)
{
// Get the error number and message before we execute any more queries.
$this->errorNum = $this->getErrorNumber();
$this->errorMsg = $this->getErrorMessage($query);
// Check if the server was disconnected.
if (!$this->connected())
{
try
{
// Attempt to reconnect.
$this->connection = null;
$this->connect();
}
// If connect fails, ignore that exception and throw the normal exception.
catch (RuntimeException $e)
{
// Get the error number and message.
$this->errorNum = $this->getErrorNumber();
$this->errorMsg = $this->getErrorMessage($query);
// Throw the normal query exception.
if (class_exists('JLog'))
{
JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database-error');
}
throw new RuntimeException($this->errorMsg, $this->errorNum, $e);
}
// Since we were able to reconnect, run the query again.
return $this->execute();
}
// The server was not disconnected.
else
{
// Throw the normal query exception.
if (class_exists('JLog'))
{
JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), JLog::ERROR, 'database-error');
}
throw new RuntimeException($this->errorMsg, $this->errorNum);
}
}
return $this->cursor;
}
/**
* Select a database for use.
*
* @param string $database The name of the database to select for use.
*
* @return boolean True if the database was successfully selected.
*
* @since 12.1
* @throws RuntimeException
*/
public function select($database)
{
$this->connect();
if (!$database)
{
return false;
}
if (!mysql_select_db($database, $this->connection))
{
throw new RuntimeException('Could not connect to database');
}
return true;
}
/**
* Set the connection to use UTF-8 character encoding.
*
* @return boolean True on success.
*
* @since 12.1
*/
public function setUtf()
{
// If UTF is not supported return false immediately
if (!$this->utf)
{
return false;
}
// Make sure we're connected to the server
$this->connect();
// Which charset should I use, plain utf8 or multibyte utf8mb4?
$charset = $this->utf8mb4 ? 'utf8mb4' : 'utf8';
$result = @mysql_set_charset($charset, $this->connection);
/**
* If I could not set the utf8mb4 charset then the server doesn't support utf8mb4 despite claiming otherwise.
* This happens on old MySQL server versions (less than 5.5.3) using the mysqlnd PHP driver. Since mysqlnd
* masks the server version and reports only its own we can not be sure if the server actually does support
* UTF-8 Multibyte (i.e. it's MySQL 5.5.3 or later). Since the utf8mb4 charset is undefined in this case we
* catch the error and determine that utf8mb4 is not supported!
*/
if (!$result && $this->utf8mb4)
{
$this->utf8mb4 = false;
$result = @mysql_set_charset('utf8', $this->connection);
}
return $result;
}
/**
* Method to fetch a row from the result set cursor as an array.
*
* @param mixed $cursor The optional result set cursor from which to fetch the row.
*
* @return mixed Either the next row from the result set or false if there are no more rows.
*
* @since 12.1
*/
protected function fetchArray($cursor = null)
{
return mysql_fetch_row($cursor ? $cursor : $this->cursor);
}
/**
* Method to fetch a row from the result set cursor as an associative array.
*
* @param mixed $cursor The optional result set cursor from which to fetch the row.
*
* @return mixed Either the next row from the result set or false if there are no more rows.
*
* @since 12.1
*/
protected function fetchAssoc($cursor = null)
{
return mysql_fetch_assoc($cursor ? $cursor : $this->cursor);
}
/**
* Method to fetch a row from the result set cursor as an object.
*
* @param mixed $cursor The optional result set cursor from which to fetch the row.
* @param string $class The class name to use for the returned row object.
*
* @return mixed Either the next row from the result set or false if there are no more rows.
*
* @since 12.1
*/
protected function fetchObject($cursor = null, $class = 'stdClass')
{
return mysql_fetch_object($cursor ? $cursor : $this->cursor, $class);
}
/**
* Method to free up the memory used for the result set.
*
* @param mixed $cursor The optional result set cursor from which to fetch the row.
*
* @return void
*
* @since 12.1
*/
protected function freeResult($cursor = null)
{
mysql_free_result($cursor ? $cursor : $this->cursor);
}
/**
* Internal function to check if profiling is available
*
* @return boolean
*
* @since 3.1.3
*/
private function hasProfiling()
{
try
{
$res = mysql_query("SHOW VARIABLES LIKE 'have_profiling'", $this->connection);
$row = mysql_fetch_assoc($res);
return isset($row);
}
catch (Exception $e)
{
return false;
}
}
/**
* Does the database server claim to have support for UTF-8 Multibyte (utf8mb4) collation?
*
* libmysql supports utf8mb4 since 5.5.3 (same version as the MySQL server). mysqlnd supports utf8mb4 since 5.0.9.
*
* @return boolean
*
* @since CMS 3.5.0
*/
private function serverClaimsUtf8mb4Support()
{
$client_version = mysql_get_client_info();
if (strpos($client_version, 'mysqlnd') !== false)
{
$client_version = preg_replace('/^\D+([\d.]+).*/', '$1', $client_version);
return version_compare($client_version, '5.0.9', '>=');
}
else
{
return version_compare($client_version, '5.5.3', '>=');
}
}
/**
* Return the actual SQL Error number
*
* @return integer The SQL Error number
*
* @since 3.4.6
*/
protected function getErrorNumber()
{
return (int) mysql_errno($this->connection);
}
/**
* Return the actual SQL Error message
*
* @param string $query The SQL Query that fails
*
* @return string The SQL Error message
*
* @since 3.4.6
*/
protected function getErrorMessage($query)
{
$errorMessage = (string) mysql_error($this->connection);
// Replace the Databaseprefix with `#__` if we are not in Debug
if (!$this->debug)
{
$errorMessage = str_replace($this->tablePrefix, '#__', $errorMessage);
$query = str_replace($this->tablePrefix, '#__', $query);
}
return $errorMessage . ' SQL=' . $query;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,712 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* Oracle database driver
*
* @see http://php.net/pdo
* @since 12.1
*/
class F0FDatabaseDriverOracle extends F0FDatabaseDriverPdo
{
/**
* The name of the database driver.
*
* @var string
* @since 12.1
*/
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
* same character is used for both sides of the quoted name, else the first character will be
* used for the opening quote and the second for the closing quote.
*
* @var string
* @since 12.1
*/
protected $nameQuote = '"';
/**
* Returns the current dateformat
*
* @var string
* @since 12.1
*/
protected $dateformat;
/**
* Returns the current character set
*
* @var string
* @since 12.1
*/
protected $charset;
/**
* Constructor.
*
* @param array $options List of options used to configure the connection
*
* @since 12.1
*/
public function __construct($options)
{
$options['driver'] = 'oci';
$options['charset'] = (isset($options['charset'])) ? $options['charset'] : 'AL32UTF8';
$options['dateformat'] = (isset($options['dateformat'])) ? $options['dateformat'] : 'RRRR-MM-DD HH24:MI:SS';
$this->charset = $options['charset'];
$this->dateformat = $options['dateformat'];
// Finalize initialisation
parent::__construct($options);
}
/**
* Destructor.
*
* @since 12.1
*/
public function __destruct()
{
$this->freeResult();
unset($this->connection);
}
/**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
*
* @since 12.1
* @throws RuntimeException
*/
public function connect()
{
if ($this->connection)
{
return;
}
parent::connect();
if (isset($this->options['schema']))
{
$this->setQuery('ALTER SESSION SET CURRENT_SCHEMA = ' . $this->quoteName($this->options['schema']))->execute();
}
$this->setDateFormat($this->dateformat);
}
/**
* Disconnects the database.
*
* @return void
*
* @since 12.1
*/
public function disconnect()
{
// Close the connection.
$this->freeResult();
unset($this->connection);
}
/**
* Drops a table from the database.
*
* Note: The IF EXISTS flag is unused in the Oracle driver.
*
* @param string $tableName The name of the database table to drop.
* @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
*
* @return F0FDatabaseDriverOracle Returns this object to support chaining.
*
* @since 12.1
*/
public function dropTable($tableName, $ifExists = true)
{
$this->connect();
$query = $this->getQuery(true)
->setQuery('DROP TABLE :tableName');
$query->bind(':tableName', $tableName);
$this->setQuery($query);
$this->execute();
return $this;
}
/**
* Method to get the database collation in use by sampling a text field of a table in the database.
*
* @return mixed The collation in use by the database or boolean false if not supported.
*
* @since 12.1
*/
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.
*
* @return string The query to check the health of the DB.
*
* @since 12.2
*/
public function getConnectedQuery()
{
return 'SELECT 1 FROM dual';
}
/**
* Returns the current date format
* This method should be useful in the case that
* somebody actually wants to use a different
* date format and needs to check what the current
* one is to see if it needs to be changed.
*
* @return string The current date format
*
* @since 12.1
*/
public function getDateFormat()
{
return $this->dateformat;
}
/**
* Shows the table CREATE statement that creates the given tables.
*
* Note: You must have the correct privileges before this method
* will return usable results!
*
* @param mixed $tables A table name or a list of table names.
*
* @return array A list of the create SQL for the tables.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableCreate($tables)
{
$this->connect();
$result = array();
$query = $this->getQuery(true)
->select('dbms_metadata.get_ddl(:type, :tableName)')
->from('dual')
->bind(':type', 'TABLE');
// Sanitize input to an array and iterate over the list.
settype($tables, 'array');
foreach ($tables as $table)
{
$query->bind(':tableName', $table);
$this->setQuery($query);
$statement = (string) $this->loadResult();
$result[$table] = $statement;
}
return $result;
}
/**
* Retrieves field information about a given table.
*
* @param string $table The name of the database table.
* @param boolean $typeOnly True to only return field types.
*
* @return array An array of fields for the database table.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableColumns($table, $typeOnly = true)
{
$this->connect();
$columns = array();
$query = $this->getQuery(true);
$fieldCasing = $this->getOption(PDO::ATTR_CASE);
$this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
$table = strtoupper($table);
$query->select('*');
$query->from('ALL_TAB_COLUMNS');
$query->where('table_name = :tableName');
$prefixedTable = str_replace('#__', strtoupper($this->tablePrefix), $table);
$query->bind(':tableName', $prefixedTable);
$this->setQuery($query);
$fields = $this->loadObjectList();
if ($typeOnly)
{
foreach ($fields as $field)
{
$columns[$field->COLUMN_NAME] = $field->DATA_TYPE;
}
}
else
{
foreach ($fields as $field)
{
$columns[$field->COLUMN_NAME] = $field;
$columns[$field->COLUMN_NAME]->Default = null;
}
}
$this->setOption(PDO::ATTR_CASE, $fieldCasing);
return $columns;
}
/**
* Get the details list of keys for a table.
*
* @param string $table The name of the table.
*
* @return array An array of the column specification for the table.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableKeys($table)
{
$this->connect();
$query = $this->getQuery(true);
$fieldCasing = $this->getOption(PDO::ATTR_CASE);
$this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
$table = strtoupper($table);
$query->select('*')
->from('ALL_CONSTRAINTS')
->where('table_name = :tableName')
->bind(':tableName', $table);
$this->setQuery($query);
$keys = $this->loadObjectList();
$this->setOption(PDO::ATTR_CASE, $fieldCasing);
return $keys;
}
/**
* Method to get an array of all tables in the database (schema).
*
* @param string $databaseName The database (schema) name
* @param boolean $includeDatabaseName Whether to include the schema name in the results
*
* @return array An array of all the tables in the database.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableList($databaseName = null, $includeDatabaseName = false)
{
$this->connect();
$query = $this->getQuery(true);
if ($includeDatabaseName)
{
$query->select('owner, table_name');
}
else
{
$query->select('table_name');
}
$query->from('all_tables');
if ($databaseName)
{
$query->where('owner = :database')
->bind(':database', $databaseName);
}
$query->order('table_name');
$this->setQuery($query);
if ($includeDatabaseName)
{
$tables = $this->loadAssocList();
}
else
{
$tables = $this->loadColumn();
}
return $tables;
}
/**
* Get the version of the database connector.
*
* @return string The database connector version.
*
* @since 12.1
*/
public function getVersion()
{
$this->connect();
$this->setQuery("select value from nls_database_parameters where parameter = 'NLS_RDBMS_VERSION'");
return $this->loadResult();
}
/**
* Select a database for use.
*
* @param string $database The name of the database to select for use.
*
* @return boolean True if the database was successfully selected.
*
* @since 12.1
* @throws RuntimeException
*/
public function select($database)
{
$this->connect();
return true;
}
/**
* Sets the Oracle Date Format for the session
* Default date format for Oracle is = DD-MON-RR
* The default date format for this driver is:
* 'RRRR-MM-DD HH24:MI:SS' since it is the format
* that matches the MySQL one used within most Joomla
* tables.
*
* @param string $dateFormat Oracle Date Format String
*
* @return boolean
*
* @since 12.1
*/
public function setDateFormat($dateFormat = 'DD-MON-RR')
{
$this->connect();
$this->setQuery("ALTER SESSION SET NLS_DATE_FORMAT = '$dateFormat'");
if (!$this->execute())
{
return false;
}
$this->setQuery("ALTER SESSION SET NLS_TIMESTAMP_FORMAT = '$dateFormat'");
if (!$this->execute())
{
return false;
}
$this->dateformat = $dateFormat;
return true;
}
/**
* Set the connection to use UTF-8 character encoding.
*
* Returns false automatically for the Oracle driver since
* you can only set the character set when the connection
* is created.
*
* @return boolean True on success.
*
* @since 12.1
*/
public function setUtf()
{
return false;
}
/**
* Locks a table in the database.
*
* @param string $table The name of the table to unlock.
*
* @return F0FDatabaseDriverOracle Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function lockTable($table)
{
$this->setQuery('LOCK TABLE ' . $this->quoteName($table) . ' IN EXCLUSIVE MODE')->execute();
return $this;
}
/**
* Renames a table in the database.
*
* @param string $oldTable The name of the table to be renamed
* @param string $newTable The new name for the table.
* @param string $backup Not used by Oracle.
* @param string $prefix Not used by Oracle.
*
* @return F0FDatabaseDriverOracle Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
{
$this->setQuery('RENAME ' . $oldTable . ' TO ' . $newTable)->execute();
return $this;
}
/**
* Unlocks tables in the database.
*
* @return F0FDatabaseDriverOracle Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function unlockTables()
{
$this->setQuery('COMMIT')->execute();
return $this;
}
/**
* Test to see if the PDO ODBC connector is available.
*
* @return boolean True on success, false otherwise.
*
* @since 12.1
*/
public static function isSupported()
{
return class_exists('PDO') && in_array('oci', PDO::getAvailableDrivers());
}
/**
* This function replaces a string identifier <var>$prefix</var> with the string held is the
* <var>tablePrefix</var> class variable.
*
* @param string $query The SQL statement to prepare.
* @param string $prefix The common table prefix.
*
* @return string The processed SQL statement.
*
* @since 11.1
*/
public function replacePrefix($query, $prefix = '#__')
{
$startPos = 0;
$quoteChar = "'";
$literal = '';
$query = trim($query);
$n = strlen($query);
while ($startPos < $n)
{
$ip = strpos($query, $prefix, $startPos);
if ($ip === false)
{
break;
}
$j = strpos($query, "'", $startPos);
if ($j === false)
{
$j = $n;
}
$literal .= str_replace($prefix, $this->tablePrefix, substr($query, $startPos, $j - $startPos));
$startPos = $j;
$j = $startPos + 1;
if ($j >= $n)
{
break;
}
// Quote comes first, find end of quote
while (true)
{
$k = strpos($query, $quoteChar, $j);
$escaped = false;
if ($k === false)
{
break;
}
$l = $k - 1;
while ($l >= 0 && $query{$l} == '\\')
{
$l--;
$escaped = !$escaped;
}
if ($escaped)
{
$j = $k + 1;
continue;
}
break;
}
if ($k === false)
{
// Error in the query - no end quote; ignore it
break;
}
$literal .= substr($query, $startPos, $k - $startPos + 1);
$startPos = $k + 1;
}
if ($startPos < $n)
{
$literal .= substr($query, $startPos, $n - $startPos);
}
return $literal;
}
/**
* Method to commit a transaction.
*
* @param boolean $toSavepoint If true, commit to the last savepoint.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionCommit($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionCommit($toSavepoint);
}
else
{
$this->transactionDepth--;
}
}
/**
* Method to roll back a transaction.
*
* @param boolean $toSavepoint If true, rollback to the last savepoint.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionRollback($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionRollback($toSavepoint);
}
else
{
$savepoint = 'SP_' . ($this->transactionDepth - 1);
$this->setQuery('ROLLBACK TO SAVEPOINT ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth--;
}
}
}
/**
* Method to initialize a transaction.
*
* @param boolean $asSavepoint If true and a transaction is already active, a savepoint will be created.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionStart($asSavepoint = false)
{
$this->connect();
if (!$asSavepoint || !$this->transactionDepth)
{
return parent::transactionStart($asSavepoint);
}
$savepoint = 'SP_' . $this->transactionDepth;
$this->setQuery('SAVEPOINT ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth++;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,559 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* MySQL database driver supporting PDO based connections
*
* @package Joomla.Platform
* @subpackage Database
* @see http://php.net/manual/en/ref.pdo-mysql.php
* @since 3.4
*/
class F0FDatabaseDriverPdomysql extends F0FDatabaseDriverPdo
{
/**
* The name of the database driver.
*
* @var string
* @since 3.4
*/
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
* same character is used for both sides of the quoted name, else the first character will be
* used for the opening quote and the second for the closing quote.
*
* @var string
* @since 3.4
*/
protected $nameQuote = '`';
/**
* The null or zero representation of a timestamp for the database driver. This should be
* defined in child classes to hold the appropriate value for the engine.
*
* @var string
* @since 3.4
*/
protected $nullDate = '0000-00-00 00:00:00';
/**
* The minimum supported database version.
*
* @var string
* @since 3.4
*/
protected static $dbMinimum = '5.0.4';
/**
* Constructor.
*
* @param array $options Array of database options with keys: host, user, password, database, select.
*
* @since 3.4
*/
public function __construct($options)
{
/**
* Pre-populate the UTF-8 Multibyte compatibility flag. Unfortuantely PDO won't report the server version
* unless we're connected to it and we cannot connect to it unless we know if it supports utf8mb4 which requires
* us knowing the server version. Between this chicken and egg issue we _assume_ it's supported and we'll just
* catch any problems at connection time.
*/
$this->utf8mb4 = true;
// Get some basic values from the options.
$options['driver'] = 'mysql';
$options['charset'] = (isset($options['charset'])) ? $options['charset'] : 'utf8';
if ($this->utf8mb4 && ($options['charset'] == 'utf8'))
{
$options['charset'] = 'utf8mb4';
}
$this->charset = $options['charset'];
// Finalize initialisation.
parent::__construct($options);
}
/**
* Connects to the database if needed.
*
* @return void Returns void if the database connected successfully.
*
* @since 3.4
* @throws RuntimeException
*/
public function connect()
{
try
{
// Try to connect to MySQL
parent::connect();
}
catch (\RuntimeException $e)
{
// If the connection failed but not because of the wrong character set bubble up the exception
if (!$this->utf8mb4 || ($this->options['charset'] != 'utf8mb4'))
{
throw $e;
}
/**
* If the connection failed and I was trying to use the utf8mb4 charset then it is likely that the server
* doesn't support utf8mb4 despite claiming otherwise.
*
* This happens on old MySQL server versions (less than 5.5.3) using the mysqlnd PHP driver. Since mysqlnd
* masks the server version and reports only its own we can not be sure if the server actually does support
* UTF-8 Multibyte (i.e. it's MySQL 5.5.3 or later). Since the utf8mb4 charset is undefined in this case we
* catch the error and determine that utf8mb4 is not supported!
*/
$this->utf8mb4 = false;
$this->options['charset'] = 'utf8';
parent::connect();
}
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
}
/**
* Test to see if the MySQL connector is available.
*
* @return boolean True on success, false otherwise.
*
* @since 3.4
*/
public static function isSupported()
{
return class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers());
}
/**
* Drops a table from the database.
*
* @param string $tableName The name of the database table to drop.
* @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
*
* @return F0FDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function dropTable($tableName, $ifExists = true)
{
$this->connect();
$query = $this->getQuery(true);
$query->setQuery('DROP TABLE ' . ($ifExists ? 'IF EXISTS ' : '') . $this->quoteName($tableName));
$this->setQuery($query);
$this->execute();
return $this;
}
/**
* Select a database for use.
*
* @param string $database The name of the database to select for use.
*
* @return boolean True if the database was successfully selected.
*
* @since 3.4
* @throws RuntimeException
*/
public function select($database)
{
$this->connect();
$this->setQuery('USE ' . $this->quoteName($database));
$this->execute();
return $this;
}
/**
* Method to get the database collation in use by sampling a text field of a table in the database.
*
* @return mixed The collation in use by the database (string) or boolean false if not supported.
*
* @since 3.4
* @throws RuntimeException
*/
public function getCollation()
{
$this->connect();
// Attempt to get the database collation by accessing the server system variable.
$this->setQuery('SHOW VARIABLES LIKE "collation_database"');
$result = $this->loadObject();
if (property_exists($result, 'Value'))
{
return $result->Value;
}
else
{
return false;
}
}
/**
* 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.
*
* @param mixed $tables A table name or a list of table names.
*
* @return array A list of the create SQL for the tables.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableCreate($tables)
{
$this->connect();
// Initialise variables.
$result = array();
// Sanitize input to an array and iterate over the list.
settype($tables, 'array');
foreach ($tables as $table)
{
$this->setQuery('SHOW CREATE TABLE ' . $this->quoteName($table));
$row = $this->loadRow();
// Populate the result array based on the create statements.
$result[$table] = $row[1];
}
return $result;
}
/**
* Retrieves field information about a given table.
*
* @param string $table The name of the database table.
* @param boolean $typeOnly True to only return field types.
*
* @return array An array of fields for the database table.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableColumns($table, $typeOnly = true)
{
$this->connect();
$result = array();
// Set the query to get the table fields statement.
$this->setQuery('SHOW FULL COLUMNS FROM ' . $this->quoteName($table));
$fields = $this->loadObjectList();
// If we only want the type as the value add just that to the list.
if ($typeOnly)
{
foreach ($fields as $field)
{
$result[$field->Field] = preg_replace("/[(0-9)]/", '', $field->Type);
}
}
// If we want the whole field data object add that to the list.
else
{
foreach ($fields as $field)
{
$result[$field->Field] = $field;
}
}
return $result;
}
/**
* Get the details list of keys for a table.
*
* @param string $table The name of the table.
*
* @return array An array of the column specification for the table.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableKeys($table)
{
$this->connect();
// Get the details columns information.
$this->setQuery('SHOW KEYS FROM ' . $this->quoteName($table));
$keys = $this->loadObjectList();
return $keys;
}
/**
* Method to get an array of all tables in the database.
*
* @return array An array of all the tables in the database.
*
* @since 3.4
* @throws RuntimeException
*/
public function getTableList()
{
$this->connect();
// Set the query to get the tables statement.
$this->setQuery('SHOW TABLES');
$tables = $this->loadColumn();
return $tables;
}
/**
* Get the version of the database connector.
*
* @return string The database connector version.
*
* @since 3.4
*/
public function getVersion()
{
$this->connect();
return $this->getOption(PDO::ATTR_SERVER_VERSION);
}
/**
* Locks a table in the database.
*
* @param string $table The name of the table to unlock.
*
* @return F0FDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function lockTable($table)
{
$this->setQuery('LOCK TABLES ' . $this->quoteName($table) . ' WRITE')->execute();
return $this;
}
/**
* Renames a table in the database.
*
* @param string $oldTable The name of the table to be renamed
* @param string $newTable The new name for the table.
* @param string $backup Not used by MySQL.
* @param string $prefix Not used by MySQL.
*
* @return F0FDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
{
$this->setQuery('RENAME TABLE ' . $this->quoteName($oldTable) . ' TO ' . $this->quoteName($newTable));
$this->execute();
return $this;
}
/**
* Method to escape a string for usage in an SQL statement.
*
* Oracle escaping reference:
* http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_characters_when_writing_SQL_queries.3F
*
* SQLite escaping notes:
* http://www.sqlite.org/faq.html#q14
*
* Method body is as implemented by the Zend Framework
*
* Note: Using query objects with bound variables is
* preferable to the below.
*
* @param string $text The string to be escaped.
* @param boolean $extra Unused optional parameter to provide extra escaping.
*
* @return string The escaped string.
*
* @since 3.4
*/
public function escape($text, $extra = false)
{
$this->connect();
if (is_int($text) || is_float($text))
{
return $text;
}
$result = substr($this->connection->quote($text), 1, -1);
if ($extra)
{
$result = addcslashes($result, '%_');
}
return $result;
}
/**
* Unlocks tables in the database.
*
* @return F0FDatabaseDriverPdomysql Returns this object to support chaining.
*
* @since 3.4
* @throws RuntimeException
*/
public function unlockTables()
{
$this->setQuery('UNLOCK TABLES')->execute();
return $this;
}
/**
* Method to commit a transaction.
*
* @param boolean $toSavepoint If true, commit to the last savepoint.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionCommit($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionCommit($toSavepoint);
}
else
{
$this->transactionDepth--;
}
}
/**
* Method to roll back a transaction.
*
* @param boolean $toSavepoint If true, rollback to the last savepoint.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionRollback($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionRollback($toSavepoint);
}
else
{
$savepoint = 'SP_' . ($this->transactionDepth - 1);
$this->setQuery('ROLLBACK TO SAVEPOINT ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth--;
}
}
}
/**
* Method to initialize a transaction.
*
* @param boolean $asSavepoint If true and a transaction is already active, a savepoint will be created.
*
* @return void
*
* @since 3.4
* @throws RuntimeException
*/
public function transactionStart($asSavepoint = false)
{
$this->connect();
if (!$asSavepoint || !$this->transactionDepth)
{
parent::transactionStart($asSavepoint);
}
else
{
$savepoint = 'SP_' . $this->transactionDepth;
$this->setQuery('SAVEPOINT ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth++;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,30 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* SQL Server database driver
*
* @see http://msdn.microsoft.com/en-us/library/ee336279.aspx
* @since 12.1
*/
class F0FDatabaseDriverSqlazure extends F0FDatabaseDriverSqlsrv
{
/**
* The name of the database driver.
*
* @var string
* @since 12.1
*/
public $name = 'sqlazure';
}

View File

@ -0,0 +1,484 @@
<?php
/**
* @package FrameworkOnFramework
* @subpackage database
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* This file is adapted from the Joomla! Platform. It is used to iterate a database cursor returning F0FTable objects
* instead of plain stdClass objects
*/
// Protect from unauthorized access
defined('F0F_INCLUDED') or die;
/**
* SQLite database driver
*
* @see http://php.net/pdo
* @since 12.1
*/
class F0FDatabaseDriverSqlite extends F0FDatabaseDriverPdo
{
/**
* The name of the database driver.
*
* @var string
* @since 12.1
*/
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
* same character is used for both sides of the quoted name, else the first character will be
* used for the opening quote and the second for the closing quote.
*
* @var string
* @since 12.1
*/
protected $nameQuote = '`';
/**
* Destructor.
*
* @since 12.1
*/
public function __destruct()
{
$this->freeResult();
unset($this->connection);
}
/**
* Disconnects the database.
*
* @return void
*
* @since 12.1
*/
public function disconnect()
{
$this->freeResult();
unset($this->connection);
}
/**
* Drops a table from the database.
*
* @param string $tableName The name of the database table to drop.
* @param boolean $ifExists Optionally specify that the table must exist before it is dropped.
*
* @return F0FDatabaseDriverSqlite Returns this object to support chaining.
*
* @since 12.1
*/
public function dropTable($tableName, $ifExists = true)
{
$this->connect();
$query = $this->getQuery(true);
$this->setQuery('DROP TABLE ' . ($ifExists ? 'IF EXISTS ' : '') . $query->quoteName($tableName));
$this->execute();
return $this;
}
/**
* Method to escape a string for usage in an SQLite statement.
*
* Note: Using query objects with bound variables is
* preferable to the below.
*
* @param string $text The string to be escaped.
* @param boolean $extra Unused optional parameter to provide extra escaping.
*
* @return string The escaped string.
*
* @since 12.1
*/
public function escape($text, $extra = false)
{
if (is_int($text) || is_float($text))
{
return $text;
}
return SQLite3::escapeString($text);
}
/**
* Method to get the database collation in use by sampling a text field of a table in the database.
*
* @return mixed The collation in use by the database or boolean false if not supported.
*
* @since 12.1
*/
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.
*
* Note: Doesn't appear to have support in SQLite
*
* @param mixed $tables A table name or a list of table names.
*
* @return array A list of the create SQL for the tables.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableCreate($tables)
{
$this->connect();
// Sanitize input to an array and iterate over the list.
settype($tables, 'array');
return $tables;
}
/**
* Retrieves field information about a given table.
*
* @param string $table The name of the database table.
* @param boolean $typeOnly True to only return field types.
*
* @return array An array of fields for the database table.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableColumns($table, $typeOnly = true)
{
$this->connect();
$columns = array();
$query = $this->getQuery(true);
$fieldCasing = $this->getOption(PDO::ATTR_CASE);
$this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
$table = strtoupper($table);
$query->setQuery('pragma table_info(' . $table . ')');
$this->setQuery($query);
$fields = $this->loadObjectList();
if ($typeOnly)
{
foreach ($fields as $field)
{
$columns[$field->NAME] = $field->TYPE;
}
}
else
{
foreach ($fields as $field)
{
// Do some dirty translation to MySQL output.
// TODO: Come up with and implement a standard across databases.
$columns[$field->NAME] = (object) array(
'Field' => $field->NAME,
'Type' => $field->TYPE,
'Null' => ($field->NOTNULL == '1' ? 'NO' : 'YES'),
'Default' => $field->DFLT_VALUE,
'Key' => ($field->PK != '0' ? 'PRI' : '')
);
}
}
$this->setOption(PDO::ATTR_CASE, $fieldCasing);
return $columns;
}
/**
* Get the details list of keys for a table.
*
* @param string $table The name of the table.
*
* @return array An array of the column specification for the table.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableKeys($table)
{
$this->connect();
$keys = array();
$query = $this->getQuery(true);
$fieldCasing = $this->getOption(PDO::ATTR_CASE);
$this->setOption(PDO::ATTR_CASE, PDO::CASE_UPPER);
$table = strtoupper($table);
$query->setQuery('pragma table_info( ' . $table . ')');
// $query->bind(':tableName', $table);
$this->setQuery($query);
$rows = $this->loadObjectList();
foreach ($rows as $column)
{
if ($column->PK == 1)
{
$keys[$column->NAME] = $column;
}
}
$this->setOption(PDO::ATTR_CASE, $fieldCasing);
return $keys;
}
/**
* Method to get an array of all tables in the database (schema).
*
* @return array An array of all the tables in the database.
*
* @since 12.1
* @throws RuntimeException
*/
public function getTableList()
{
$this->connect();
$type = 'table';
$query = $this->getQuery(true)
->select('name')
->from('sqlite_master')
->where('type = :type')
->bind(':type', $type)
->order('name');
$this->setQuery($query);
$tables = $this->loadColumn();
return $tables;
}
/**
* Get the version of the database connector.
*
* @return string The database connector version.
*
* @since 12.1
*/
public function getVersion()
{
$this->connect();
$this->setQuery("SELECT sqlite_version()");
return $this->loadResult();
}
/**
* Select a database for use.
*
* @param string $database The name of the database to select for use.
*
* @return boolean True if the database was successfully selected.
*
* @since 12.1
* @throws RuntimeException
*/
public function select($database)
{
$this->connect();
return true;
}
/**
* Set the connection to use UTF-8 character encoding.
*
* Returns false automatically for the Oracle driver since
* you can only set the character set when the connection
* is created.
*
* @return boolean True on success.
*
* @since 12.1
*/
public function setUtf()
{
$this->connect();
return false;
}
/**
* Locks a table in the database.
*
* @param string $table The name of the table to unlock.
*
* @return F0FDatabaseDriverSqlite Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function lockTable($table)
{
return $this;
}
/**
* Renames a table in the database.
*
* @param string $oldTable The name of the table to be renamed
* @param string $newTable The new name for the table.
* @param string $backup Not used by Sqlite.
* @param string $prefix Not used by Sqlite.
*
* @return F0FDatabaseDriverSqlite Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function renameTable($oldTable, $newTable, $backup = null, $prefix = null)
{
$this->setQuery('ALTER TABLE ' . $oldTable . ' RENAME TO ' . $newTable)->execute();
return $this;
}
/**
* Unlocks tables in the database.
*
* @return F0FDatabaseDriverSqlite Returns this object to support chaining.
*
* @since 12.1
* @throws RuntimeException
*/
public function unlockTables()
{
return $this;
}
/**
* Test to see if the PDO ODBC connector is available.
*
* @return boolean True on success, false otherwise.
*
* @since 12.1
*/
public static function isSupported()
{
return class_exists('PDO') && in_array('sqlite', PDO::getAvailableDrivers());
}
/**
* Method to commit a transaction.
*
* @param boolean $toSavepoint If true, commit to the last savepoint.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionCommit($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionCommit($toSavepoint);
}
else
{
$this->transactionDepth--;
}
}
/**
* Method to roll back a transaction.
*
* @param boolean $toSavepoint If true, rollback to the last savepoint.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionRollback($toSavepoint = false)
{
$this->connect();
if (!$toSavepoint || $this->transactionDepth <= 1)
{
parent::transactionRollback($toSavepoint);
}
else
{
$savepoint = 'SP_' . ($this->transactionDepth - 1);
$this->setQuery('ROLLBACK TO ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth--;
}
}
}
/**
* Method to initialize a transaction.
*
* @param boolean $asSavepoint If true and a transaction is already active, a savepoint will be created.
*
* @return void
*
* @since 12.3
* @throws RuntimeException
*/
public function transactionStart($asSavepoint = false)
{
$this->connect();
if (!$asSavepoint || !$this->transactionDepth)
{
parent::transactionStart($asSavepoint);
}
$savepoint = 'SP_' . $this->transactionDepth;
$this->setQuery('SAVEPOINT ' . $this->quoteName($savepoint));
if ($this->execute())
{
$this->transactionDepth++;
}
}
}

File diff suppressed because it is too large Load Diff