Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JDatabaseImporterMysqli
+ Graphe d'héritage de JDatabaseImporterMysqli:
+ Graphe de collaboration de JDatabaseImporterMysqli:

Liste de tous les membres

Fonctions membres publiques

 check ()
- Fonctions membres publiques inherited from JDatabaseImporter
 __construct ()
 asXml ()
 from ($from)
 setDbo (JDatabaseDriver $db)
 withStructure ($setting=true)

Fonctions membres protégées

 getAddColumnSQL ($table, SimpleXMLElement $field)
 getAddKeySQL ($table, $keys)
 getAlterTableSQL (SimpleXMLElement $structure)
 getChangeColumnSQL ($table, SimpleXMLElement $field)
 getColumnSQL (SimpleXMLElement $field)
 getDropKeySQL ($table, $name)
 getDropPrimaryKeySQL ($table)
 getKeyLookup ($keys)
 getKeySQL ($columns)
- Fonctions membres protégées inherited from JDatabaseImporter
 getDropColumnSQL ($table, $name)
 getRealTableName ($table)
 mergeStructure ()

Additional Inherited Members

- Attributs protégés inherited from JDatabaseImporter
 $cache = array()
 $db = null
 $from = array()
 $asFormat = 'xml'
 $options = null

Description détaillée

Définition à la ligne 19 du fichier mysqli.php.


Documentation des fonctions membres

JDatabaseImporterMysqli::check ( )

Checks if all data and options are in order prior to exporting.

Renvoie:
JDatabaseImporterMysqli Method supports chaining.
Depuis:
11.1
Exceptions:
Exceptionif an error is encountered.

Réimplémentée à partir de JDatabaseImporter.

Réimplémentée dans JDatabaseImporterMysql.

Définition à la ligne 29 du fichier mysqli.php.

{
// Check if the db connector has been set.
if (!($this->db instanceof JDatabaseDriverMysqli))
{
throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE');
}
// Check if the tables have been specified.
if (empty($this->from))
{
throw new Exception('JPLATFORM_ERROR_NO_TABLES_SPECIFIED');
}
return $this;
}
JDatabaseImporterMysqli::getAddColumnSQL (   $table,
SimpleXMLElement  $field 
)
protected

Get the SQL syntax to add a column.

Paramètres:
string$tableThe table name.
SimpleXMLElement$fieldThe XML field definition.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 56 du fichier mysqli.php.

{
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' ADD COLUMN ' . $this->getColumnSQL($field);
}
JDatabaseImporterMysqli::getAddKeySQL (   $table,
  $keys 
)
protected

Get the SQL syntax to add a key.

Paramètres:
string$tableThe table name.
array$keysAn array of the fields pertaining to this key.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 71 du fichier mysqli.php.

{
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' ADD ' . $this->getKeySQL($keys);
}
JDatabaseImporterMysqli::getAlterTableSQL ( SimpleXMLElement  $structure)
protected

Get alters for table if there is a difference.

Paramètres:
SimpleXMLElement$structureThe XML structure pf the table.
Renvoie:
array
Depuis:
11.1

Définition à la ligne 85 du fichier mysqli.php.

{
$table = $this->getRealTableName($structure['name']);
$oldFields = $this->db->getTableColumns($table);
$oldKeys = $this->db->getTableKeys($table);
$alters = array();
// 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);
if ($change)
{
$alters[] = $this->getChangeColumnSQL($table, $field);
}
// Unset this field so that what we have left are fields that need to be removed.
unset($oldFields[$fName]);
}
else
{
// The field is new.
$alters[] = $this->getAddColumnSQL($table, $field);
}
}
// Any columns left are orphans
foreach ($oldFields as $name => $column)
{
// Delete the column.
$alters[] = $this->getDropColumnSQL($table, $name);
}
// Get the lookups for the old and new keys.
$oldLookup = $this->getKeyLookup($oldKeys);
$newLookup = $this->getKeyLookup($newKeys);
// 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]))
{
$same = true;
$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));
/*
Debug.
echo '<pre>';
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');
echo '</pre>';
*/
if (!$same)
{
// Break out of the loop. No need to check further.
break;
}
}
}
else
{
// Count is different, just drop and add.
$same = false;
}
if (!$same)
{
$alters[] = $this->getDropKeySQL($table, $name);
$alters[] = $this->getAddKeySQL($table, $keys);
}
// Unset this field so that what we have left are fields that need to be removed.
unset($oldLookup[$name]);
}
else
{
// This is a new key.
$alters[] = $this->getAddKeySQL($table, $keys);
}
}
// Any keys left are orphans.
foreach ($oldLookup as $name => $keys)
{
if (strtoupper($name) == 'PRIMARY')
{
$alters[] = $this->getDropPrimaryKeySQL($table);
}
else
{
$alters[] = $this->getDropKeySQL($table, $name);
}
}
return $alters;
}
JDatabaseImporterMysqli::getChangeColumnSQL (   $table,
SimpleXMLElement  $field 
)
protected

Get the syntax to alter a column.

Paramètres:
string$tableThe name of the database table to alter.
SimpleXMLElement$fieldThe XML definition for the field.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 235 du fichier mysqli.php.

{
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' CHANGE COLUMN ' . $this->db->quoteName((string) $field['Field']) . ' '
. $this->getColumnSQL($field);
}
JDatabaseImporterMysqli::getColumnSQL ( SimpleXMLElement  $field)
protected

Get the SQL syntax for a single column that would be included in a table create or alter statement.

Paramètres:
SimpleXMLElement$fieldThe XML field definition.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 250 du fichier mysqli.php.

{
// 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 ($fNull == 'NO')
{
if (in_array($fType, $blobs) || $fDefault === null)
{
$query .= ' NOT NULL';
}
else
{
// TODO Don't quote numeric values.
$query .= ' NOT NULL DEFAULT ' . $this->db->quote($fDefault);
}
}
else
{
if ($fDefault === null)
{
$query .= ' DEFAULT NULL';
}
else
{
// TODO Don't quote numeric values.
$query .= ' DEFAULT ' . $this->db->quote($fDefault);
}
}
if ($fExtra)
{
$query .= ' ' . strtoupper($fExtra);
}
return $query;
}
JDatabaseImporterMysqli::getDropKeySQL (   $table,
  $name 
)
protected

Get the SQL syntax to drop a key.

Paramètres:
string$tableThe table name.
string$nameThe name of the key to drop.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 306 du fichier mysqli.php.

{
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP KEY ' . $this->db->quoteName($name);
}
JDatabaseImporterMysqli::getDropPrimaryKeySQL (   $table)
protected

Get the SQL syntax to drop a key.

Paramètres:
string$tableThe table name.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 320 du fichier mysqli.php.

{
return 'ALTER TABLE ' . $this->db->quoteName($table) . ' DROP PRIMARY KEY';
}
JDatabaseImporterMysqli::getKeyLookup (   $keys)
protected

Get the details list of keys for a table.

Paramètres:
array$keysAn array of objects that comprise the keys for the table.
Renvoie:
array The lookup array. array({key name} => array(object, ...))
Depuis:
11.1
Exceptions:
Exception

Définition à la ligne 335 du fichier mysqli.php.

{
// First pass, create a lookup of the keys.
$lookup = array();
foreach ($keys as $key)
{
if ($key instanceof SimpleXMLElement)
{
$kName = (string) $key['Key_name'];
}
else
{
$kName = $key->Key_name;
}
if (empty($lookup[$kName]))
{
$lookup[$kName] = array();
}
$lookup[$kName][] = $key;
}
return $lookup;
}
JDatabaseImporterMysqli::getKeySQL (   $columns)
protected

Get the SQL syntax for a key.

Paramètres:
array$columnsAn array of SimpleXMLElement objects comprising the key.
Renvoie:
string
Depuis:
11.1

Définition à la ligne 371 du fichier mysqli.php.

{
// 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'];
$prefix = '';
if ($kName == 'PRIMARY')
{
$prefix = 'PRIMARY ';
}
elseif ($kNonUnique == 0)
{
$prefix = 'UNIQUE ';
}
$nColumns = count($columns);
$kColumns = array();
if ($nColumns == 1)
{
$kColumns[] = $this->db->quoteName($kColumn);
}
else
{
foreach ($columns as $column)
{
$kColumns[] = (string) $column['Column_name'];
}
}
$query = $prefix . 'KEY ' . ($kName != 'PRIMARY' ? $this->db->quoteName($kName) : '') . ' (' . implode(',', $kColumns) . ')';
return $query;
}

La documentation de cette classe a été générée à partir du fichier suivant :