43d52723fde7db21b83657761cb1cf2c84ea3e22
2 /***************************************************************
5 * (c) 2011 Christian Kuhn <lolli@schwarzbu.ch>
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Verify TYPO3 DB table structure. ainly used in install tool
30 * compare wizard and extension manager.
32 * @author Christian Kuhn <lolli@schwarzbu.ch>
36 class t3lib_install_Sql
{
39 * @var string Prefix of deleted tables
41 protected $deletedPrefixKey = 'zzz_deleted_'; // Prefix used for tables/fields when deleted/renamed.
44 * @var float|int Multiplier of SQL field size (for char, varchar and text fields)
46 protected $multiplySize = 1;
49 * @var array Caching output of $GLOBALS['TYPO3_DB']->admin_get_charsets()
51 protected $character_sets = array();
54 * Constructor function
56 public function __construct() {
57 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] >= 1 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'] <= 5) {
58 $this->multiplySize
= (double) $GLOBALS['TYPO3_CONF_VARS']['SYS']['multiplyDBfieldSize'];
63 * Set prefix of deleted tables
65 * @param string $prefix Prefix string
67 public function setDeletedPrefixKey($prefix) {
68 $this->deletedPrefixKey
= $prefix;
72 * Get prefix of deleted tables
76 public function getDeletedPrefixKey() {
77 return $this->deletedPrefixKey
;
81 * Reads the field definitions for the input SQL-file string
83 * @param string $fileContent Should be a string read from an SQL-file made with 'mysqldump [database_name] -d'
84 * @return array Array with information about table.
86 public function getFieldDefinitions_fileContent($fileContent) {
87 $lines = t3lib_div
::trimExplode(LF
, $fileContent, 1);
91 foreach ($lines as $value) {
92 if (substr($value, 0, 1) == '#') {
93 continue; // Ignore comments
96 if (!strlen($table)) {
97 $parts = t3lib_div
::trimExplode(' ', $value, TRUE);
98 if (strtoupper($parts[0]) === 'CREATE' && strtoupper($parts[1]) === 'TABLE') {
99 $table = str_replace('`', '', $parts[2]);
100 if (TYPO3_OS
== 'WIN') { // tablenames are always lowercase on windows!
101 $table = strtolower($table);
105 if (substr($value, 0, 1) == ')' && substr($value, -1) == ';') {
107 if (preg_match('/(ENGINE|TYPE)[ ]*=[ ]*([a-zA-Z]*)/', $value, $ttype)) {
108 $total[$table]['extra']['ENGINE'] = $ttype[2];
109 } // Otherwise, just do nothing: If table engine is not defined, just accept the system default.
111 // Set the collation, if specified
112 if (preg_match('/(COLLATE)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcollation)) {
113 $total[$table]['extra']['COLLATE'] = $tcollation[2];
115 // Otherwise, get the CHARACTER SET and try to find the default collation for it as returned by "SHOW CHARACTER SET" query (for details, see http://dev.mysql.com/doc/refman/5.1/en/charset-table.html)
116 if (preg_match('/(CHARSET|CHARACTER SET)[ ]*=[ ]*([a-zA-z0-9_-]+)/', $value, $tcharset)) { // Note: Keywords "DEFAULT CHARSET" and "CHARSET" are the same, so "DEFAULT" can just be ignored
117 $charset = $tcharset[2];
119 $charset = $GLOBALS['TYPO3_DB']->default_charset
; // Fallback to default charset
121 $total[$table]['extra']['COLLATE'] = $this->getCollationForCharset($charset);
124 $table = ''; // Remove table marker and start looking for the next "CREATE TABLE" statement
126 $lineV = preg_replace('/,$/', '', $value); // Strip trailing commas
127 $lineV = str_replace('`', '', $lineV);
128 $lineV = str_replace(' ', ' ', $lineV); // Remove double blanks
130 $parts = explode(' ', $lineV, 2);
131 if (!preg_match('/(PRIMARY|UNIQUE|FULLTEXT|INDEX|KEY)/', $parts[0])) { // Field definition
133 // Make sure there is no default value when auto_increment is set
134 if (stristr($parts[1], 'auto_increment')) {
135 $parts[1] = preg_replace('/ default \'0\'/i', '', $parts[1]);
137 // "default" is always lower-case
138 if (stristr($parts[1], ' DEFAULT ')) {
139 $parts[1] = str_ireplace(' DEFAULT ', ' default ', $parts[1]);
142 // Change order of "default" and "NULL" statements
143 $parts[1] = preg_replace('/(.*) (default .*) (NOT NULL)/', '$1 $3 $2', $parts[1]);
144 $parts[1] = preg_replace('/(.*) (default .*) (NULL)/', '$1 $3 $2', $parts[1]);
147 $total[$table]['fields'][$key] = $parts[1];
149 } else { // Key definition
150 $search = array('/UNIQUE (INDEX|KEY)/', '/FULLTEXT (INDEX|KEY)/', '/INDEX/');
151 $replace = array('UNIQUE', 'FULLTEXT', 'KEY');
152 $lineV = preg_replace($search, $replace, $lineV);
154 if (preg_match('/PRIMARY|UNIQUE|FULLTEXT/', $parts[0])) {
155 $parts[1] = preg_replace('/^(KEY|INDEX) /', '', $parts[1]);
158 $newParts = explode(' ', $parts[1], 2);
159 $key = $parts[0] == 'PRIMARY' ?
$parts[0] : $newParts[0];
161 $total[$table]['keys'][$key] = $lineV;
163 // This is a protection against doing something stupid: Only allow clearing of cache_* and index_* tables.
164 if (preg_match('/^(cache|index)_/', $table)) {
165 // Suggest to truncate (clear) this table
166 $total[$table]['extra']['CLEAR'] = 1;
173 $this->getFieldDefinitions_sqlContent_parseTypes($total);
178 * Multiplies varchars/tinytext fields in size according to $this->multiplySize
179 * Useful if you want to use UTF-8 in the database and needs to extend the field sizes in the database so UTF-8 chars are not discarded. For most charsets available as single byte sets, multiplication with 2 should be enough. For chinese, use 3.
181 * @param array $total Total array (from getFieldDefinitions_fileContent())
184 * @see getFieldDefinitions_fileContent()
186 protected function getFieldDefinitions_sqlContent_parseTypes(&$total) {
188 $mSize = (double) $this->multiplySize
;
191 /** @var $sqlParser t3lib_sqlparser */
192 $sqlParser = t3lib_div
::makeInstance('t3lib_sqlparser');
193 foreach ($total as $table => $cfg) {
194 if (is_array($cfg['fields'])) {
195 foreach ($cfg['fields'] as $fN => $fType) {
196 $orig_fType = $fType;
197 $fInfo = $sqlParser->parseFieldDef($fType);
199 switch ($fInfo['fieldType']) {
202 $newSize = round($fInfo['value'] * $mSize);
204 if ($newSize <= 255) {
205 $fInfo['value'] = $newSize;
208 'fieldType' => 'text',
209 'featureIndex' => array(
211 'keyword' => 'NOT NULL'
215 // Change key definition if necessary (must use "prefix" on TEXT columns)
216 if (is_array($cfg['keys'])) {
217 foreach ($cfg['keys'] as $kN => $kType) {
219 preg_match('/^([^(]*)\(([^)]+)\)(.*)/', $kType, $match);
221 foreach (t3lib_div
::trimExplode(',', $match[2]) as $kfN) {
223 $kfN .= '(' . $newSize . ')';
227 $total[$table]['keys'][$kN] = $match[1] . '(' . implode(',', $keys) . ')' . $match[3];
233 $fInfo['fieldType'] = 'text';
237 $total[$table]['fields'][$fN] = $sqlParser->compileFieldCfg($fInfo);
238 if ($sqlParser->parse_error
) {
239 throw new RuntimeException(
240 'TYPO3 Fatal Error: ' . $sqlParser->parse_error
,
251 * Look up the default collation for specified character set based on "SHOW CHARACTER SET" output
253 * @param string $charset Character set
254 * @return string Corresponding default collation
256 public function getCollationForCharset($charset) {
257 // Load character sets, if not cached already
258 if (!count($this->character_sets
)) {
259 if (method_exists($GLOBALS['TYPO3_DB'], 'admin_get_charsets')) {
260 $this->character_sets
= $GLOBALS['TYPO3_DB']->admin_get_charsets();
262 $this->character_sets
[$charset] = array(); // Add empty element to avoid that the check will be repeated
267 if (isset($this->character_sets
[$charset]['Default collation'])) {
268 $collation = $this->character_sets
[$charset]['Default collation'];
275 * Reads the field definitions for the current database
277 * @return array Array with information about table.
279 public function getFieldDefinitions_database() {
282 $tempKeysPrefix = array();
284 $GLOBALS['TYPO3_DB']->sql_select_db(TYPO3_db
);
285 echo $GLOBALS['TYPO3_DB']->sql_error();
287 $tables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db
);
288 foreach ($tables as $tableName => $tableStatus) {
291 $fieldInformation = $GLOBALS['TYPO3_DB']->admin_get_fields($tableName);
292 foreach ($fieldInformation as $fN => $fieldRow) {
293 $total[$tableName]['fields'][$fN] = $this->assembleFieldDefinition($fieldRow);
297 $keyInformation = $GLOBALS['TYPO3_DB']->admin_get_keys($tableName);
299 foreach ($keyInformation as $keyRow) {
300 $keyName = $keyRow['Key_name'];
301 $colName = $keyRow['Column_name'];
302 if ($keyRow['Sub_part']) {
303 $colName .= '(' . $keyRow['Sub_part'] . ')';
305 $tempKeys[$tableName][$keyName][$keyRow['Seq_in_index']] = $colName;
306 if ($keyName == 'PRIMARY') {
307 $prefix = 'PRIMARY KEY';
309 if ($keyRow['Index_type'] == 'FULLTEXT') {
310 $prefix = 'FULLTEXT';
311 } elseif ($keyRow['Non_unique']) {
316 $prefix .= ' ' . $keyName;
318 $tempKeysPrefix[$tableName][$keyName] = $prefix;
321 // Table status (storage engine, collaction, etc.)
322 if (is_array($tableStatus)) {
323 $tableExtraFields = array(
324 'Engine' => 'ENGINE',
325 'Collation' => 'COLLATE',
328 foreach ($tableExtraFields as $mysqlKey => $internalKey) {
329 if (isset($tableStatus[$mysqlKey])) {
330 $total[$tableName]['extra'][$internalKey] = $tableStatus[$mysqlKey];
336 // Compile key information:
337 if (count($tempKeys)) {
338 foreach ($tempKeys as $table => $keyInf) {
339 foreach ($keyInf as $kName => $index) {
341 $total[$table]['keys'][$kName] = $tempKeysPrefix[$table][$kName] . ' (' . implode(',', $index) . ')';
350 * Compares two arrays with field information and returns information about fields that are MISSING and fields that have CHANGED.
351 * FDsrc and FDcomp can be switched if you want the list of stuff to remove rather than update.
353 * @param array $FDsrc Field definitions, source (from getFieldDefinitions_fileContent())
354 * @param array $FDcomp Field definitions, comparison. (from getFieldDefinitions_database())
355 * @param string $onlyTableList Table names (in list) which is the ONLY one observed.
356 * @param boolean $ignoreNotNullWhenComparing If set, this function ignores NOT NULL statements of the SQL file field definition when comparing current field definition from database with field definition from SQL file. This way, NOT NULL statements will be executed when the field is initially created, but the SQL parser will never complain about missing NOT NULL statements afterwards.
357 * @return array Returns an array with 1) all elements from $FDsrc that is not in $FDcomp (in key 'extra') and 2) all elements from $FDsrc that is different from the ones in $FDcomp
359 public function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = TRUE) {
363 if (is_array($FDsrc)) {
364 foreach ($FDsrc as $table => $info) {
365 if (!strlen($onlyTableList) || t3lib_div
::inList($onlyTableList, $table)) {
366 if (!isset($FDcomp[$table])) {
367 $extraArr[$table] = $info; // If the table was not in the FDcomp-array, the result array is loaded with that table.
368 $extraArr[$table]['whole_table'] = 1;
370 $keyTypes = explode(',', 'extra,fields,keys');
371 foreach ($keyTypes as $theKey) {
372 if (is_array($info[$theKey])) {
373 foreach ($info[$theKey] as $fieldN => $fieldC) {
374 $fieldN = str_replace('`', '', $fieldN);
375 if ($fieldN == 'COLLATE') {
376 continue; // TODO: collation support is currently disabled (needs more testing)
379 if (!isset($FDcomp[$table][$theKey][$fieldN])) {
380 $extraArr[$table][$theKey][$fieldN] = $fieldC;
382 $fieldC = trim($fieldC);
383 if ($ignoreNotNullWhenComparing) {
384 $fieldC = str_replace(' NOT NULL', '', $fieldC);
385 $FDcomp[$table][$theKey][$fieldN] = str_replace(' NOT NULL', '', $FDcomp[$table][$theKey][$fieldN]);
387 if ($fieldC !== $FDcomp[$table][$theKey][$fieldN]) {
388 $diffArr[$table][$theKey][$fieldN] = $fieldC;
389 $diffArr_cur[$table][$theKey][$fieldN] = $FDcomp[$table][$theKey][$fieldN];
401 'extra' => $extraArr,
403 'diff_currentValues' => $diffArr_cur
410 * Returns an array with SQL-statements that is needed to update according to the diff-array
412 * @param array $diffArr Array with differences of current and needed DB settings. (from getDatabaseExtra())
413 * @param string $keyList List of fields in diff array to take notice of.
414 * @return array Array of SQL statements (organized in keys depending on type)
416 public function getUpdateSuggestions($diffArr, $keyList = 'extra,diff') {
417 $statements = array();
418 $deletedPrefixKey = $this->deletedPrefixKey
;
420 if ($keyList == 'remove') {
424 $keyList = explode(',', $keyList);
425 foreach ($keyList as $theKey) {
426 if (is_array($diffArr[$theKey])) {
427 foreach ($diffArr[$theKey] as $table => $info) {
428 $whole_table = array();
429 if (is_array($info['fields'])) {
430 foreach ($info['fields'] as $fN => $fV) {
431 if ($info['whole_table']) {
432 $whole_table[] = $fN . ' ' . $fV;
434 // Special case to work around MySQL problems when adding auto_increment fields:
435 if (stristr($fV, 'auto_increment')) {
436 // The field can only be set "auto_increment" if there exists a PRIMARY key of that field already.
437 // The check does not look up which field is primary but just assumes it must be the field with the auto_increment value...
438 if (isset($diffArr['extra'][$table]['keys']['PRIMARY'])) {
439 // Remove "auto_increment" from the statement - it will be suggested in a 2nd step after the primary key was created
440 $fV = str_replace(' auto_increment', '', $fV);
442 // In the next step, attempt to clear the table once again (2 = force)
443 $info['extra']['CLEAR'] = 2;
446 if ($theKey == 'extra') {
448 if (substr($fN, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) {
449 $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $deletedPrefixKey . $fN . ' ' . $fV . ';';
450 $statements['change'][md5($statement)] = $statement;
452 $statement = 'ALTER TABLE ' . $table . ' DROP ' . $fN . ';';
453 $statements['drop'][md5($statement)] = $statement;
456 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fN . ' ' . $fV . ';';
457 $statements['add'][md5($statement)] = $statement;
459 } elseif ($theKey == 'diff') {
460 $statement = 'ALTER TABLE ' . $table . ' CHANGE ' . $fN . ' ' . $fN . ' ' . $fV . ';';
461 $statements['change'][md5($statement)] = $statement;
462 $statements['change_currentValue'][md5($statement)] = $diffArr['diff_currentValues'][$table]['fields'][$fN];
467 if (is_array($info['keys'])) {
468 foreach ($info['keys'] as $fN => $fV) {
469 if ($info['whole_table']) {
470 $whole_table[] = $fV;
472 if ($theKey == 'extra') {
474 $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ?
' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';';
475 $statements['drop'][md5($statement)] = $statement;
477 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';';
478 $statements['add'][md5($statement)] = $statement;
480 } elseif ($theKey == 'diff') {
481 $statement = 'ALTER TABLE ' . $table . ($fN == 'PRIMARY' ?
' DROP PRIMARY KEY' : ' DROP KEY ' . $fN) . ';';
482 $statements['change'][md5($statement)] = $statement;
483 $statement = 'ALTER TABLE ' . $table . ' ADD ' . $fV . ';';
484 $statements['change'][md5($statement)] = $statement;
489 if (is_array($info['extra'])) {
491 $extras_currentValue = array();
492 $clear_table = FALSE;
494 foreach ($info['extra'] as $fN => $fV) {
496 // Only consider statements which are missing in the database but don't remove existing properties
498 if (!$info['whole_table']) { // If the whole table is created at once, we take care of this later by imploding all elements of $info['extra']
499 if ($fN == 'CLEAR') {
500 // Truncate table must happen later, not now
501 // Valid values for CLEAR: 1=only clear if keys are missing, 2=clear anyway (force)
502 if (count($info['keys']) ||
$fV == 2) {
507 $extras[] = $fN . '=' . $fV;
508 $extras_currentValue[] = $fN . '=' . $diffArr['diff_currentValues'][$table]['extra'][$fN];
514 $statement = 'TRUNCATE TABLE ' . $table . ';';
515 $statements['clear_table'][md5($statement)] = $statement;
517 if (count($extras)) {
518 $statement = 'ALTER TABLE ' . $table . ' ' . implode(' ', $extras) . ';';
519 $statements['change'][md5($statement)] = $statement;
520 $statements['change_currentValue'][md5($statement)] = implode(' ', $extras_currentValue);
523 if ($info['whole_table']) {
525 if (substr($table, 0, strlen($deletedPrefixKey)) != $deletedPrefixKey) {
526 $statement = 'ALTER TABLE ' . $table . ' RENAME ' . $deletedPrefixKey . $table . ';';
527 $statements['change_table'][md5($statement)] = $statement;
529 $statement = 'DROP TABLE ' . $table . ';';
530 $statements['drop_table'][md5($statement)] = $statement;
533 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', $table);
534 $statements['tables_count'][md5($statement)] = $count ?
'Records in table: ' . $count : '';
536 $statement = 'CREATE TABLE ' . $table . " (\n" . implode(",\n", $whole_table) . "\n)";
537 if ($info['extra']) {
538 foreach ($info['extra'] as $k => $v) {
539 if ($k == 'COLLATE' ||
$k == 'CLEAR') {
540 continue; // Skip these special statements. TODO: collation support is currently disabled (needs more testing)
542 $statement .= ' ' . $k . '=' . $v; // Add extra attributes like ENGINE, CHARSET, etc.
546 $statements['create_table'][md5($statement)] = $statement;
557 * Converts a result row with field information into the SQL field definition string
559 * @param array $row MySQL result row
560 * @return string Field definition
562 public function assembleFieldDefinition($row) {
563 $field = array($row['Type']);
565 if ($row['Null'] == 'NO') {
566 $field[] = 'NOT NULL';
568 if (!strstr($row['Type'], 'blob') && !strstr($row['Type'], 'text')) {
569 // Add a default value if the field is not auto-incremented (these fields never have a default definition)
570 if (!stristr($row['Extra'], 'auto_increment')) {
571 if ($row['Default'] === NULL) {
572 $field[] = 'default NULL';
574 $field[] = 'default \'' . addslashes($row['Default']) . '\'';
579 $field[] = $row['Extra'];
582 return implode(' ', $field);
586 * Returns an array where every entry is a single SQL-statement. Input must be formatted like an ordinary MySQL-dump files.
588 * @param string $sqlcode The SQL-file content. Provided that 1) every query in the input is ended with ';' and that a line in the file contains only one query or a part of a query.
589 * @param boolean $removeNonSQL If set, non-SQL content (like comments and blank lines) is not included in the final output
590 * @param string $query_regex Regex to filter SQL lines to include
591 * @return array Array of SQL statements
593 public function getStatementArray($sqlcode, $removeNonSQL = FALSE, $query_regex = '') {
594 $sqlcodeArr = explode(LF
, $sqlcode);
596 // Based on the assumption that the sql-dump has
597 $statementArray = array();
598 $statementArrayPointer = 0;
600 foreach ($sqlcodeArr as $line => $lineContent) {
603 // auto_increment fields cannot have a default value!
604 if (stristr($lineContent, 'auto_increment')) {
605 $lineContent = preg_replace('/ default \'0\'/i', '', $lineContent);
608 if (!$removeNonSQL ||
(strcmp(trim($lineContent), '') && substr(trim($lineContent), 0, 1) != '#' && substr(trim($lineContent), 0, 2) != '--')) { // '--' is seen as mysqldump comments from server version 3.23.49
609 $statementArray[$statementArrayPointer] .= $lineContent;
612 if (substr(trim($lineContent), -1) == ';') {
613 if (isset($statementArray[$statementArrayPointer])) {
614 if (!trim($statementArray[$statementArrayPointer]) ||
($query_regex && !preg_match('/' . $query_regex . '/i', trim($statementArray[$statementArrayPointer])))) {
615 unset($statementArray[$statementArrayPointer]);
618 $statementArrayPointer++
;
621 $statementArray[$statementArrayPointer] .= LF
;
625 return $statementArray;
629 * Returns tables to create and how many records in each
631 * @param array $statements Array of SQL statements to analyse.
632 * @param boolean $insertCountFlag If set, will count number of INSERT INTO statements following that table definition
633 * @return array Array with table definitions in index 0 and count in index 1
635 public function getCreateTables($statements, $insertCountFlag = FALSE) {
637 $insertCount = array();
638 foreach ($statements as $line => $lineContent) {
640 if (preg_match('/^create[[:space:]]*table[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
641 $table = trim($reg[1]);
643 // table names are always lowercase on Windows!
644 if (TYPO3_OS
== 'WIN') {
645 $table = strtolower($table);
647 $sqlLines = explode(LF
, $lineContent);
648 foreach ($sqlLines as $k => $v) {
649 if (stristr($v, 'auto_increment')) {
650 $sqlLines[$k] = preg_replace('/ default \'0\'/i', '', $v);
653 $lineContent = implode(LF
, $sqlLines);
654 $crTables[$table] = $lineContent;
656 } elseif ($insertCountFlag && preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
657 $nTable = trim($reg[1]);
658 $insertCount[$nTable]++
;
662 return array($crTables, $insertCount);
666 * Extracts all insert statements from $statement array where content is inserted into $table
668 * @param array $statements Array of SQL statements
669 * @param string $table Table name
670 * @return array Array of INSERT INTO statements where table match $table
672 public function getTableInsertStatements($statements, $table) {
673 $outStatements = array();
674 foreach ($statements as $line => $lineContent) {
676 if (preg_match('/^insert[[:space:]]*into[[:space:]]*[`]?([[:alnum:]_]*)[`]?/i', substr($lineContent, 0, 100), $reg)) {
677 $nTable = trim($reg[1]);
678 if ($nTable && !strcmp($table, $nTable)) {
679 $outStatements[] = $lineContent;
683 return $outStatements;
687 * Performs the queries passed from the input array.
689 * @param array $arr Array of SQL queries to execute.
690 * @param array $keyArr Array with keys that must match keys in $arr. Only where a key in this array is set and TRUE will the query be executed (meant to be passed from a form checkbox)
691 * @return mixed Array with error message from database if any occured. Otherwise TRUE if everything was executed successfully.
693 public function performUpdateQueries($arr, $keyArr) {
695 if (is_array($arr)) {
696 foreach ($arr as $key => $string) {
697 if (isset($keyArr[$key]) && $keyArr[$key]) {
698 $res = $GLOBALS['TYPO3_DB']->admin_query($string);
699 if ($res === FALSE) {
700 $result[$key] = $GLOBALS['TYPO3_DB']->sql_error();
701 } elseif (is_resource($res)) {
702 $GLOBALS['TYPO3_DB']->sql_free_result($res);
707 if (count($result) > 0) {
715 * Returns list of tables in the database
717 * @return array List of tables.
718 * @see t3lib_db::admin_get_tables()
720 public function getListOfTables() {
721 $whichTables = $GLOBALS['TYPO3_DB']->admin_get_tables(TYPO3_db
);
722 foreach ($whichTables as $key => &$value) {