[BUGFIX] Fix override handling for element specific field values
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / PdoHelper.php
1 <?php
2 namespace TYPO3\CMS\Core\Database;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A helper class for handling PDO databases
19 */
20 class PdoHelper
21 {
22 /**
23 * Pumps the SQL into the database. Use for DDL only.
24 *
25 * Important: key definitions with length specifiers (needed for MySQL) must
26 * be given as "field"(xyz) - no space between double quote and parenthesis -
27 * so they can be removed automatically.
28 *
29 * @param \PDO $databaseHandle
30 * @param string $pdoDriver
31 * @param string $pathAndFilename
32 */
33 public static function importSql(\PDO $databaseHandle, $pdoDriver, $pathAndFilename)
34 {
35 $sql = file($pathAndFilename, FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES);
36 // Remove MySQL style key length delimiters (yuck!) if we are not setting up a MySQL db
37 if (substr($pdoDriver, 0, 5) !== 'mysql') {
38 $sql = preg_replace('/"\\([0-9]+\\)/', '"', $sql);
39 }
40 $statement = '';
41 foreach ($sql as $line) {
42 $statement .= ' ' . trim($line);
43 if (substr($statement, -1) === ';') {
44 $databaseHandle->exec($statement);
45 $statement = '';
46 }
47 }
48 }
49 }