Пример #1
0
 /**
  * @brief Free a connection when the instance count hits zero.
  *
  * @param Databasedriver $connection The connection to free
  */
 public static function freePooledConnection(DatabaseDriver $connection)
 {
     $pi = $connection->getPoolIdentity();
     self::$pool[$pi]['count']--;
     if (self::$pool[$pi]['count'] == 0) {
         unset(self::$pool[$pi]);
     }
 }
Пример #2
0
 /**
  * Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection
  * risks and reserved word conflicts.
  *
  * This method is provided for use where the query object is passed to a function for modification.
  * If you have direct access to the database object, it is recommended you use the quoteName method directly.
  *
  * Note that 'qn' is an alias for this method as it is in DatabaseDriver.
  *
  * Usage:
  * $query->quoteName('#__a');
  * $query->qn('#__a');
  *
  * @param   array|string  $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   array|string  $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  array|string  The quote wrapped name, same type of $name.
  *
  * @since   1.0
  * @throws  \RuntimeException if the internal db property is not a valid object.
  */
 public function quoteName($name, $as = null)
 {
     if (!$this->db instanceof DatabaseDriver) {
         throw new \RuntimeException('JLIB_DATABASE_ERROR_INVALID_DB_OBJECT');
     }
     return $this->db->quoteName($name, $as);
 }
Пример #3
0
 /**
  * Get the generic name of the table, converting the database prefix to the wildcard string.
  *
  * @param   string  $table  The name of the table.
  *
  * @return  string  The name of the table with the database prefix replaced with #__.
  *
  * @since   1.0
  */
 protected function getGenericTableName($table)
 {
     $prefix = $this->db->getPrefix();
     // Replace the magic prefix if found.
     $table = preg_replace("|^{$prefix}|", '#__', $table);
     return $table;
 }
 /**
  * Merges the incoming structure definition with the existing structure.
  *
  * @return  void
  *
  * @note    Currently only supports XML format.
  * @since   1.0
  * @throws  \RuntimeException on error.
  */
 protected function mergeStructure()
 {
     $prefix = $this->db->getPrefix();
     $tables = $this->db->getTableList();
     if ($this->from instanceof \SimpleXMLElement) {
         $xml = $this->from;
     } else {
         $xml = new \SimpleXMLElement($this->from);
     }
     // Get all the table definitions.
     $xmlTables = $xml->xpath('database/table_structure');
     foreach ($xmlTables as $table) {
         // Convert the magic prefix into the real table name.
         $tableName = (string) $table['name'];
         $tableName = preg_replace('|^#__|', $prefix, $tableName);
         if (in_array($tableName, $tables)) {
             // The table already exists. Now check if there is any difference.
             if ($queries = $this->getAlterTableSQL($xml->database->table_structure)) {
                 // Run the queries to upgrade the data structure.
                 foreach ($queries as $query) {
                     $this->db->setQuery((string) $query);
                     try {
                         $this->db->execute();
                     } catch (\RuntimeException $e) {
                         $this->addLog('Fail: ' . $this->db->getQuery());
                         throw $e;
                     }
                     $this->addLog('Pass: '******'Fail: ' . $this->db->getQuery());
                 throw $e;
             }
             $this->addLog('Pass: ' . $this->db->getQuery());
         }
     }
 }