Source for file mysqli.php
Documentation is available at mysqli.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* @package Joomla.Platform
* Checks if all data and options are in order prior to exporting.
* @return JDatabaseImporterMysqli Method supports chaining.
* @throws Exception if an error is encountered.
// Check if the db connector has been set.
throw
new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
// Check if the tables have been specified.
throw
new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
* Get the SQL syntax to add a column.
* @param string $table The table name.
* @param SimpleXMLElement $field The XML field definition.
return 'ALTER TABLE ' .
$this->db->quoteName($table) .
' ADD COLUMN ' .
$this->getColumnSQL($field);
* Get the SQL syntax to add a key.
* @param string $table The table name.
* @param array $keys An array of the fields pertaining to this key.
return 'ALTER TABLE ' .
$this->db->quoteName($table) .
' ADD ' .
$this->getKeySQL($keys);
* Get alters for table if there is a difference.
* @param SimpleXMLElement $structure The XML structure pf the table.
$oldFields =
$this->db->getTableColumns($table);
$oldKeys =
$this->db->getTableKeys($table);
// Get the fields and keys from the XML that we are aiming for.
$newFields =
$structure->xpath('field');
$newKeys =
$structure->xpath('key');
// Loop through each field in the new structure.
foreach ($newFields as $field)
$fName = (string)
$field['Field'];
if (isset
($oldFields[$fName]))
// The field exists, check it's the same.
$column =
$oldFields[$fName];
// Test whether there is a change.
$change =
((string)
$field['Type'] !=
$column->Type) ||
((string)
$field['Null'] !=
$column->Null)
||
((string)
$field['Default'] !=
$column->Default) ||
((string)
$field['Extra'] !=
$column->Extra);
// Unset this field so that what we have left are fields that need to be removed.
unset
($oldFields[$fName]);
// Any columns left are orphans
foreach ($oldFields as $name =>
$column)
// Get the lookups for the old and new keys.
// Loop through each key in the new structure.
foreach ($newLookup as $name =>
$keys)
// Check if there are keys on this field in the existing table.
if (isset
($oldLookup[$name]))
$newCount =
count($newLookup[$name]);
$oldCount =
count($oldLookup[$name]);
// There is a key on this field in the old and new tables. Are they the same?
if ($newCount ==
$oldCount)
// Need to loop through each key and do a fine grained check.
for ($i =
0; $i <
$newCount; $i++
)
$same =
(((string)
$newLookup[$name][$i]['Non_unique'] ==
$oldLookup[$name][$i]->Non_unique)
&&
((string)
$newLookup[$name][$i]['Column_name'] ==
$oldLookup[$name][$i]->Column_name)
&&
((string)
$newLookup[$name][$i]['Seq_in_index'] ==
$oldLookup[$name][$i]->Seq_in_index)
&&
((string)
$newLookup[$name][$i]['Collation'] ==
$oldLookup[$name][$i]->Collation)
&&
((string)
$newLookup[$name][$i]['Index_type'] ==
$oldLookup[$name][$i]->Index_type));
echo '<br />Non_unique: '.
((string) $newLookup[$name][$i]['Non_unique'] == $oldLookup[$name][$i]->Non_unique ? 'Pass' : 'Fail').' '.
(string) $newLookup[$name][$i]['Non_unique'].' vs '.$oldLookup[$name][$i]->Non_unique;
echo '<br />Column_name: '.
((string) $newLookup[$name][$i]['Column_name'] == $oldLookup[$name][$i]->Column_name ? 'Pass' : 'Fail').' '.
(string) $newLookup[$name][$i]['Column_name'].' vs '.$oldLookup[$name][$i]->Column_name;
echo '<br />Seq_in_index: '.
((string) $newLookup[$name][$i]['Seq_in_index'] == $oldLookup[$name][$i]->Seq_in_index ? 'Pass' : 'Fail').' '.
(string) $newLookup[$name][$i]['Seq_in_index'].' vs '.$oldLookup[$name][$i]->Seq_in_index;
echo '<br />Collation: '.
((string) $newLookup[$name][$i]['Collation'] == $oldLookup[$name][$i]->Collation ? 'Pass' : 'Fail').' '.
(string) $newLookup[$name][$i]['Collation'].' vs '.$oldLookup[$name][$i]->Collation;
echo '<br />Index_type: '.
((string) $newLookup[$name][$i]['Index_type'] == $oldLookup[$name][$i]->Index_type ? 'Pass' : 'Fail').' '.
(string) $newLookup[$name][$i]['Index_type'].' vs '.$oldLookup[$name][$i]->Index_type;
echo '<br />Same = '.($same ? 'true' : 'false');
// Break out of the loop. No need to check further.
// Count is different, just drop and add.
// Unset this field so that what we have left are fields that need to be removed.
unset
($oldLookup[$name]);
// Any keys left are orphans.
foreach ($oldLookup as $name =>
$keys)
* Get the syntax to alter a column.
* @param string $table The name of the database table to alter.
* @param SimpleXMLElement $field The XML definition for the field.
return 'ALTER TABLE ' .
$this->db->quoteName($table) .
' CHANGE COLUMN ' .
$this->db->quoteName((string)
$field['Field']) .
' '
* Get the SQL syntax for a single column that would be included in a table create or alter statement.
* @param SimpleXMLElement $field The XML field definition.
// TODO Incorporate into parent class and use $this.
$blobs =
array('text', 'smalltext', 'mediumtext', 'largetext');
$fName = (string)
$field['Field'];
$fType = (string)
$field['Type'];
$fNull = (string)
$field['Null'];
$fDefault = isset
($field['Default']) ? (string)
$field['Default'] :
null;
$fExtra = (string)
$field['Extra'];
$query =
$this->db->quoteName($fName) .
' ' .
$fType;
if (in_array($fType, $blobs) ||
$fDefault ===
null)
// TODO Don't quote numeric values.
$query .=
' NOT NULL DEFAULT ' .
$this->db->quote($fDefault);
$query .=
' DEFAULT NULL';
// TODO Don't quote numeric values.
$query .=
' DEFAULT ' .
$this->db->quote($fDefault);
* Get the SQL syntax to drop a key.
* @param string $table The table name.
* @param string $name The name of the key to drop.
return 'ALTER TABLE ' .
$this->db->quoteName($table) .
' DROP KEY ' .
$this->db->quoteName($name);
* Get the SQL syntax to drop a key.
* @param string $table The table name.
return 'ALTER TABLE ' .
$this->db->quoteName($table) .
' DROP PRIMARY KEY';
* Get the details list of keys for a table.
* @param array $keys An array of objects that comprise the keys for the table.
* @return array The lookup array. array({key name} => array(object, ...))
// First pass, create a lookup of the keys.
if ($key instanceof
SimpleXMLElement)
$kName = (string)
$key['Key_name'];
if (empty($lookup[$kName]))
$lookup[$kName] =
array();
$lookup[$kName][] =
$key;
* Get the SQL syntax for a key.
* @param array $columns An array of SimpleXMLElement objects comprising the key.
// TODO Error checking on array and element types.
$kNonUnique = (string)
$columns[0]['Non_unique'];
$kName = (string)
$columns[0]['Key_name'];
$kColumn = (string)
$columns[0]['Column_name'];
elseif ($kNonUnique ==
0)
$nColumns =
count($columns);
$kColumns[] =
$this->db->quoteName($kColumn);
foreach ($columns as $column)
$kColumns[] = (string)
$column['Column_name'];
$query =
$prefix .
'KEY ' .
($kName !=
'PRIMARY' ?
$this->db->quoteName($kName) :
'') .
' (' .
implode(',', $kColumns) .
')';
Documentation generated on Tue, 19 Nov 2013 15:09:12 +0100 by phpDocumentor 1.4.3