/** * Builds the XML structure to export. * * @return array An array of XML lines (strings). * * @since 12.1 * @throws Exception if an error occurs. */ protected function buildXmlStructure() { $buffer = array(); foreach ($this->from as $table) { // Replace the magic prefix if found. $table = $this->getGenericTableName($table); // Get the details columns information. $fields = $this->db->getTableColumns($table, false); $keys = $this->db->getTableKeys($table); $sequences = $this->db->getTableSequences($table); $buffer[] = ' <table_structure name="' . $table . '">'; foreach ($sequences as $sequence) { if (version_compare($this->db->getVersion(), '9.1.0') < 0) { $sequence->start_value = null; } $buffer[] = ' <sequence Name="' . $sequence->sequence . '"' . ' Schema="' . $sequence->schema . '"' . ' Table="' . $sequence->table . '"' . ' Column="' . $sequence->column . '"' . ' Type="' . $sequence->data_type . '"' . ' Start_Value="' . $sequence->start_value . '"' . ' Min_Value="' . $sequence->minimum_value . '"' . ' Max_Value="' . $sequence->maximum_value . '"' . ' Increment="' . $sequence->increment . '"' . ' Cycle_option="' . $sequence->cycle_option . '"' . ' />'; } foreach ($fields as $field) { $buffer[] = ' <field Field="' . $field->column_name . '"' . ' Type="' . $field->type . '"' . ' Null="' . $field->null . '"' . (isset($field->default) ? ' Default="' . $field->default . '"' : '') . ' Comments="' . $field->comments . '"' . ' />'; } foreach ($keys as $key) { $buffer[] = ' <key Index="' . $key->idxName . '"' . ' is_primary="' . $key->isPrimary . '"' . ' is_unique="' . $key->isUnique . '"' . ' Query="' . $key->Query . '" />'; } $buffer[] = ' </table_structure>'; } return $buffer; }
/** * Get the syntax to alter a sequence. * * @param SimpleXMLElement $field The XML definition for the sequence. * * @return string * * @since 12.1 */ protected function getChangeSequenceSQL($field) { /* For older database version that doesn't support these fields use default values */ if (version_compare($this->db->getVersion(), '9.1.0') < 0) { $field['Min_Value'] = '1'; $field['Max_Value'] = '9223372036854775807'; $field['Increment'] = '1'; $field['Cycle_option'] = 'NO'; $field['Start_Value'] = '1'; } $sql = 'ALTER SEQUENCE ' . (string) $field['Name'] . ' INCREMENT BY ' . (string) $field['Increment'] . ' MINVALUE ' . (string) $field['Min_Value'] . ' MAXVALUE ' . (string) $field['Max_Value'] . ' START ' . (string) $field['Start_Value'] . ' OWNED BY ' . $this->db->quoteName((string) $field['Schema'] . '.' . (string) $field['Table'] . '.' . (string) $field['Column']); return $sql; }