Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Do not directly query the INFORMATION_SCHEMA database (see #7302)
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Sep 18, 2014
1 parent fa53e9d commit b20d455
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
3 changes: 3 additions & 0 deletions system/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Contao Open Source CMS changelog
Version 3.4.0-beta1 (2014-10-XX)
--------------------------------

### Improved
Do not directly query the `INFORMATION_SCHEMA` database (see #7302).

### New
Added the "doNoTrim" flag to the `Widget` class (see #4287).

Expand Down
34 changes: 19 additions & 15 deletions system/modules/core/controllers/BackendInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,29 +531,33 @@ protected function storeCollation()
}
catch (\Exception $e) {}

$objField = $this->Database->prepare("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME LIKE 'tl_%' AND !ISNULL(COLLATION_NAME)")
->execute(\Config::get('dbDatabase'));
$objTable = $this->Database->query("SHOW TABLE STATUS WHERE Name LIKE 'tl_%' AND !ISNULL(Collation)");

while ($objField->next())
while ($objTable->next())
{
if (!in_array($objField->TABLE_NAME, $arrTables))
if (!in_array($objTable->Name, $arrTables))
{
$this->Database->query("ALTER TABLE {$objField->TABLE_NAME} DEFAULT CHARACTER SET $strCharset COLLATE $strCollation");
$arrTables[] = $objField->TABLE_NAME;
$this->Database->query("ALTER TABLE {$objTable->Name} DEFAULT CHARACTER SET $strCharset COLLATE $strCollation");
$arrTables[] = $objTable->Name;
}

$strQuery = "ALTER TABLE {$objField->TABLE_NAME} CHANGE {$objField->COLUMN_NAME} {$objField->COLUMN_NAME} {$objField->COLUMN_TYPE} CHARACTER SET $strCharset COLLATE $strCollation";
$objField = $this->Database->query("SHOW FULL COLUMNS FROM {$objTable->Name} WHERE !ISNULL(Collation)");

if ($objField->IS_NULLABLE == 'YES')
while ($objField->next())
{
$strQuery .= " NULL";
}
else
{
$strQuery .= " NOT NULL DEFAULT '{$objField->COLUMN_DEFAULT}'";
}
$strQuery = "ALTER TABLE {$objTable->Name} CHANGE {$objField->Field} {$objField->Field} {$objField->Type} CHARACTER SET $strCharset COLLATE $strCollation";

$this->Database->query($strQuery);
if ($objField->Null == 'YES')
{
$strQuery .= " NULL";
}
else
{
$strQuery .= " NOT NULL DEFAULT '{$objField->Default}'";
}

$this->Database->query($strQuery);
}
}

\Config::persist('dbCollation', $strCollation);
Expand Down
19 changes: 9 additions & 10 deletions system/modules/core/library/Contao/Database/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ protected function find_in_set($strKey, $varSet, $blnIsField=false)
protected function list_fields($strTable)
{
$arrReturn = array();
$objFields = $this->query("SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` LIKE '{$this->arrConfig['dbDatabase']}' AND `TABLE_NAME` LIKE '$strTable'");
$objFields = $this->query("SHOW FULL COLUMNS FROM $strTable");

while ($objFields->next())
{
$arrTmp = array();
$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->COLUMN_TYPE, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->Type, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

$arrTmp['name'] = $objFields->COLUMN_NAME;
$arrTmp['name'] = $objFields->Field;
$arrTmp['type'] = $arrChunks[0];

if (!empty($arrChunks[1]))
Expand All @@ -161,7 +161,6 @@ protected function list_fields($strTable)
else
{
$arrSubChunks = explode(',', $arrChunks[1]);

$arrTmp['length'] = trim($arrSubChunks[0]);

if (!empty($arrSubChunks[1]))
Expand All @@ -176,9 +175,9 @@ protected function list_fields($strTable)
$arrTmp['attributes'] = trim($arrChunks[2]);
}

if ($objFields->COLUMN_KEY != '')
if ($objFields->Key != '')
{
switch ($objFields->COLUMN_KEY)
switch ($objFields->Key)
{
case 'PRI':
$arrTmp['index'] = 'PRIMARY';
Expand All @@ -199,10 +198,10 @@ protected function list_fields($strTable)
}

// Do not modify the order!
$arrTmp['collation'] = $objFields->COLLATION_NAME;
$arrTmp['null'] = ($objFields->IS_NULLABLE == 'YES') ? 'NULL' : 'NOT NULL';
$arrTmp['default'] = $objFields->COLUMN_DEFAULT;
$arrTmp['extra'] = $objFields->EXTRA;
$arrTmp['collation'] = $objFields->Collation;
$arrTmp['null'] = ($objFields->Null == 'YES') ? 'NULL' : 'NOT NULL';
$arrTmp['default'] = $objFields->Default;
$arrTmp['extra'] = $objFields->Extra;

$arrReturn[] = $arrTmp;
}
Expand Down
18 changes: 9 additions & 9 deletions system/modules/core/library/Contao/Database/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ protected function find_in_set($strKey, $varSet, $blnIsField=false)
protected function list_fields($strTable)
{
$arrReturn = array();
$objFields = $this->query("SELECT * FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` LIKE '{$this->arrConfig['dbDatabase']}' AND `TABLE_NAME` LIKE '$strTable'");
$objFields = $this->query("SHOW FULL COLUMNS FROM $strTable");

while ($objFields->next())
{
$arrTmp = array();
$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->COLUMN_TYPE, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->Type, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

$arrTmp['name'] = $objFields->COLUMN_NAME;
$arrTmp['name'] = $objFields->Field;
$arrTmp['type'] = $arrChunks[0];

if (!empty($arrChunks[1]))
Expand Down Expand Up @@ -158,9 +158,9 @@ protected function list_fields($strTable)
$arrTmp['attributes'] = trim($arrChunks[2]);
}

if ($objFields->COLUMN_KEY != '')
if ($objFields->Key != '')
{
switch ($objFields->COLUMN_KEY)
switch ($objFields->Key)
{
case 'PRI':
$arrTmp['index'] = 'PRIMARY';
Expand All @@ -181,10 +181,10 @@ protected function list_fields($strTable)
}

// Do not modify the order!
$arrTmp['collation'] = $objFields->COLLATION_NAME;
$arrTmp['null'] = ($objFields->IS_NULLABLE == 'YES') ? 'NULL' : 'NOT NULL';
$arrTmp['default'] = $objFields->COLUMN_DEFAULT;
$arrTmp['extra'] = $objFields->EXTRA;
$arrTmp['collation'] = $objFields->Collation;
$arrTmp['null'] = ($objFields->Null == 'YES') ? 'NULL' : 'NOT NULL';
$arrTmp['default'] = $objFields->Default;
$arrTmp['extra'] = $objFields->Extra;

$arrReturn[] = $arrTmp;
}
Expand Down

0 comments on commit b20d455

Please sign in to comment.