/** * Test loadRowList method * * @return void * * @since 11.1 */ public function testLoadRowList() { $query = $this->object->getQuery(true); $query->select('*'); $query->from('jos_dbtest'); $query->where('description=' . $this->object->quote('one')); $this->object->setQuery($query); $result = $this->object->loadRowList(); $expected = array(array(1, 'Testing', '1980-04-18 00:00:00', 'one'), array(2, 'Testing2', '1980-04-18 00:00:00', 'one')); $this->assertThat($result, $this->equalTo($expected), __LINE__); }
/** * Merges the incoming structure definition with the existing structure. * * @return void * * @since 11.1 * * @throws Exception on error. * @note Currently only supports XML format. * @todo If it's not XML convert to XML first. */ protected function mergeStructure() { // Initialise variables. $prefix = $this->db->getPrefix(); $tables = $this->db->getTableList(); $result = true; 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); if (!$this->db->query()) { $this->addLog('Fail: ' . $this->db->getQuery()); throw new Exception($this->db->getErrorMsg()); } else { $this->addLog('Pass: '******'Fail: ' . $this->db->getQuery()); throw new Exception($this->db->getErrorMsg()); } else { $this->addLog('Pass: ' . $this->db->getQuery()); } } } }
/** * Builds the XML structure to export. * * @return array An array of XML lines (strings). * * @since 11.1 * @throws Exception if an error occurs. */ protected function buildXmlStructure() { $buffer = array(); $query = $this->db->getQuery(true); foreach ($this->from as $table) { // Replace the magic prefix if found. $table = $this->getGenericTableName($table); /* * Table structure */ // Get the details columns information. $fields = $this->db->getTableColumns($table, false); $keys = $this->db->getTableKeys($table); $buffer[] = ' <table_structure name="' . $table . '">'; foreach ($fields as $field) { $buffer[] = ' <field' . ' Field="' . $field->Field . '"' . ' Type="' . $field->Type . '"' . ' Null="' . $field->Null . '"' . ' Key="' . $field->Key . '"' . (isset($field->Default) ? ' Default="' . $field->Default . '"' : '') . ' Extra="' . $field->Extra . '"' . ' Comment="' . htmlspecialchars($field->Comment) . '"' . ' />'; } foreach ($keys as $key) { $buffer[] = ' <key' . ' Table="' . $table . '"' . ' Non_unique="' . $key->Non_unique . '"' . ' Key_name="' . $key->Key_name . '"' . ' Seq_in_index="' . $key->Seq_in_index . '"' . ' Column_name="' . $key->Column_name . '"' . ' Collation="' . $key->Collation . '"' . ' Null="' . $key->Null . '"' . ' Index_type="' . $key->Index_type . '"' . ' Comment="' . htmlspecialchars($key->Comment) . '"' . ' />'; } $buffer[] = ' </table_structure>'; /* * Table data */ if (!$this->options->get('with-data')) { continue; } $query->clear()->from($this->db->quoteName($table))->select('*'); $rows = $this->db->setQuery($query)->loadObjectList(); $buffer[] = ' <table_data name="' . $table . '">'; foreach ($rows as $row) { $buffer[] = ' <row>'; foreach ($row as $fieldName => $fieldValue) { $buffer[] = ' <field' . ' name="' . $fieldName . '">' . htmlspecialchars($fieldValue) . '</field>'; } $buffer[] = ' </row>'; } $buffer[] = ' </table_data>'; } return $buffer; }