/** * Execute the SQL statement. * * @param boolean $replacePrefixQuotes Replace the prefixes inside the quotes too * * @return mixed A database cursor resource on success, boolean false on failure. * * @since 12.1 * @throws RuntimeException */ public function execute($replacePrefixQuotes = false) { if ($replacePrefixQuotes) { $this->sql = $this->replacePrefix((string) $this->sql, '#__', $replacePrefixQuotes); } return parent::execute(); }
/** * 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 11.1 */ protected function getGenericTableName($table) { // TODO Incorporate into parent class and use $this. $prefix = $this->db->getPrefix(); // Replace the magic prefix if found. $table = preg_replace("|^{$prefix}|", '#__', $table); return $table; }
/** * This function replaces a string identifier <var>$prefix</var> with the * string held is the <var>_table_prefix</var> class variable. * * @param string $sql The SQL query * @param string $prefx The common table prefix */ public function replacePrefix($sql, $prefix = '#__') { $app = JFactory::getApplication(); $package = $app->getUserStateFromRequest('com_fabrik.package', 'package', 'fabrik'); if ($package == '') { $package = 'fabrik'; } $sql = str_replace('{package}', $package, $sql); return parent::replacePrefix($sql, $prefix); }
/** * Constructor. * * @param array $options List of options used to configure the connection * * @since 12.1 */ public function __construct($options) { // Get some basic values from the options. $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'] : ''; $options['select'] = isset($options['select']) ? (bool) $options['select'] : true; $options['port'] = null; $options['socket'] = null; // Finalize initialisation. parent::__construct($options); }
/** * Merges the incoming structure definition with the existing structure. * * @return void * * @note Currently only supports XML format. * @since 11.1 * @throws Exception on error. * @todo If it's not XML convert to XML first. */ protected function mergeStructure() { // Initialise variables. $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()); } } }
/** * Test isSupported method. * * @return void * * @since 11.4 */ public function testIsSupported() { $this->assertThat(JDatabaseDriverMysql::isSupported(), $this->isTrue(), __LINE__); }
/** * Test isSupported method. * * @return void * * @since 11.4 */ public function testIsSupported() { $this->assertTrue(JDatabaseDriverMysql::isSupported()); }