Пример #1
0
 /**
  * Database object constructor
  *
  * @param   array  $options  List of options used to configure the connection
  */
 public function __construct($options)
 {
     $this->driverType = 'mysql';
     // Init
     $this->nameQuote = '`';
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     if (!empty($port)) {
         $host .= ':' . $port;
     }
     // finalize initialization
     parent::__construct($options);
     // Open the connection
     $this->host = $host;
     $this->user = $user;
     $this->password = $password;
     $this->_database = $database;
     $this->selectDatabase = $select;
     if (!is_resource($this->connection) || is_null($this->connection)) {
         $this->open();
     }
 }
Пример #2
0
 /**
  * Database object constructor
  *
  * @param   array $options List of options used to configure the connection
  *
  */
 public function __construct($options)
 {
     $this->driverType = 'postgresql';
     $options['host'] = isset($options['host']) ? $options['host'] : 'localhost';
     $options['user'] = isset($options['user']) ? $options['user'] : '';
     $options['password'] = isset($options['password']) ? $options['password'] : '';
     $options['database'] = isset($options['database']) ? $options['database'] : '';
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Finalize initialization
     parent::__construct($options);
     if (!is_resource($this->connection) || is_null($this->connection)) {
         $this->open();
     }
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param   array $options List of options used to configure the connection
  *
  * @since   11.1
  */
 public function __construct($options)
 {
     $this->driverType = 'mssql';
     // Get some basic values from the options.
     $host = array_key_exists('host', $options) ? $options['host'] : 'localhost';
     $port = array_key_exists('port', $options) ? $options['port'] : '';
     $user = array_key_exists('user', $options) ? $options['user'] : '';
     $password = array_key_exists('password', $options) ? $options['password'] : '';
     $database = array_key_exists('database', $options) ? $options['database'] : '';
     $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     $select = array_key_exists('select', $options) ? $options['select'] : true;
     // Build the connection configuration array.
     $this->connectionConfig = array('Database' => $database, 'uid' => $user, 'pwd' => $password, 'CharacterSet' => 'UTF-8', 'ReturnDatesAsStrings' => true);
     parent::__construct($options);
     $this->host = $host;
     $this->user = $user;
     $this->password = $password;
     $this->_database = $database;
     $this->selectDatabase = $select;
     if (!is_resource($this->connection)) {
         $this->open();
     }
 }
Пример #4
0
 /**
  * Reverse engineers the View definitions of this database
  *
  * @param   DriverBase $dbi Database connection to INFORMATION_SCHEMA
  */
 protected function reverse_engineer_views(&$dbi)
 {
     $schema_name = $this->database;
     $sql = 'SELECT * FROM [INFORMATION_SCHEMA].[VIEWS] WHERE [table_catalog] = ' . $dbi->quote($schema_name);
     $dbi->setQuery($sql);
     $all_views = $dbi->loadObjectList();
     $registry = Factory::getConfiguration();
     $root = $registry->get('volatile.database.root', '[SITEDB]');
     // If we have filters, make sure the tables pass the filtering
     $filters = Factory::getFilters();
     // First pass: populate the table_name_map
     if (!empty($all_views)) {
         foreach ($all_views as $table_object) {
             // Extract the table name
             $table_name = $table_object->TABLE_NAME;
             // Filter and convert
             if (substr($table_name, 0, 3) == '#__') {
                 $warningMessage = __CLASS__ . " :: Table {$table_name} has a prefix of #__. This would cause restoration errors; table skipped.";
                 $this->setWarning($warningMessage);
                 Factory::getLog()->log(LogLevel::WARNING, $warningMessage);
                 continue;
             }
             $table_abstract = $this->getAbstract($table_name);
             if (substr($table_abstract, 0, 4) != 'bak_') {
                 // Apply exclusion filters
                 if (!$filters->isFiltered($table_abstract, $root, 'dbobject', 'all')) {
                     Factory::getLog()->log(LogLevel::INFO, __CLASS__ . " :: Adding {$table_name} (internal name {$table_abstract})");
                     $this->table_name_map[$table_name] = $table_abstract;
                 } else {
                     Factory::getLog()->log(LogLevel::INFO, __CLASS__ . " :: Skipping {$table_name} (internal name {$table_abstract})");
                     continue;
                 }
             } else {
                 Factory::getLog()->log(LogLevel::INFO, __CLASS__ . " :: Backup view {$table_name} automatically skipped.");
                 continue;
             }
         }
     }
     // Second pass: get the create commands
     if (!empty($all_views)) {
         foreach ($all_views as $table_object) {
             // Extract the table name
             $table_name = $table_object->TABLE_NAME;
             if (!in_array($table_name, $this->table_name_map)) {
                 // Skip any views which have been filtered out
                 continue;
             }
             $table_abstract = $this->getAbstract($table_name);
             // Still here? The view is added. We now have to store its
             // create command, dependency info and so on
             $new_entry = array('type' => 'view', 'dump_records' => false);
             $dependencies = array();
             $table_sql = $table_object->VIEW_DEFINITION;
             $old_table_sql = $table_sql;
             foreach ($this->table_name_map as $ref_normal => $ref_abstract) {
                 if ($pos = strpos($table_sql, ".{$ref_normal}")) {
                     // Add a reference hit
                     $this->dependencies[$ref_normal][] = $table_name;
                     // Add the dependency to this table's metadata
                     $dependencies[] = $ref_normal;
                     // Do the replacement
                     $table_sql = str_replace(".{$ref_normal}", ".{$ref_abstract}", $table_sql);
                 }
             }
             // On DB only backup we don't want any replacing to take place, do we?
             if (!Factory::getEngineParamsProvider()->getScriptingParameter('db.abstractnames', 1)) {
                 $table_sql = $old_table_sql;
             }
             // Replace newlines with spaces
             $table_sql = str_replace("\n", " ", $table_sql) . ";\n";
             $table_sql = str_replace("\r", " ", $table_sql);
             $table_sql = str_replace("\t", " ", $table_sql);
             $new_entry['create'] = $table_sql;
             $new_entry['dependencies'] = $dependencies;
             $this->tables_data[$table_name] = $new_entry;
         }
     }
 }
Пример #5
0
 /**
  * Sets the SQL statement string for later execution.
  *
  * @param   mixed    $query          The SQL statement to set either as a JDatabaseQuery object or a string.
  * @param   integer  $offset         The affected row offset to set.
  * @param   integer  $limit          The maximum affected rows to set.
  * @param   array    $driverOptions  The optional PDO driver options
  *
  * @return  Base  This object to support method chaining.
  *
  * @since   1.0
  */
 public function setQuery($query, $offset = null, $limit = null, $driverOptions = array())
 {
     $this->open();
     $this->freeResult();
     if (is_string($query)) {
         // Allows taking advantage of bound variables in a direct query:
         $query = $this->getQuery(true)->setQuery($query);
     }
     if ($query instanceof Limitable && !is_null($offset) && !is_null($limit)) {
         $query->setLimit($limit, $offset);
     }
     $sql = $this->replacePrefix((string) $query);
     $this->prepared = $this->connection->prepare($sql, $driverOptions);
     // Store reference to the DatabaseQuery instance:
     parent::setQuery($query, $offset, $limit);
     return $this;
 }