177 MYSQLI_TYPE_TINY =>
'tinyint',
178 MYSQLI_TYPE_CHAR =>
'tinyint',
179 MYSQLI_TYPE_SHORT =>
'smallint',
180 MYSQLI_TYPE_LONG =>
'int',
181 MYSQLI_TYPE_FLOAT =>
'float',
182 MYSQLI_TYPE_DOUBLE =>
'double',
183 MYSQLI_TYPE_TIMESTAMP =>
'timestamp',
184 MYSQLI_TYPE_LONGLONG =>
'bigint',
185 MYSQLI_TYPE_INT24 =>
'mediumint',
186 MYSQLI_TYPE_DATE =>
'date',
187 MYSQLI_TYPE_NEWDATE =>
'date',
188 MYSQLI_TYPE_TIME =>
'time',
189 MYSQLI_TYPE_DATETIME =>
'datetime',
190 MYSQLI_TYPE_YEAR =>
'year',
191 MYSQLI_TYPE_BIT =>
'bit',
192 MYSQLI_TYPE_INTERVAL =>
'interval',
193 MYSQLI_TYPE_ENUM =>
'enum',
194 MYSQLI_TYPE_SET =>
'set',
195 MYSQLI_TYPE_TINY_BLOB =>
'blob',
196 MYSQLI_TYPE_MEDIUM_BLOB =>
'blob',
197 MYSQLI_TYPE_LONG_BLOB =>
'blob',
198 MYSQLI_TYPE_BLOB =>
'blob',
199 MYSQLI_TYPE_VAR_STRING =>
'varchar',
200 MYSQLI_TYPE_STRING =>
'char',
201 MYSQLI_TYPE_DECIMAL =>
'decimal',
202 MYSQLI_TYPE_NEWDECIMAL =>
'decimal',
203 MYSQLI_TYPE_GEOMETRY =>
'geometry' 221 $this->conf =
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'];
231 if (isset($this->conf[
'mapping'])) {
232 $this->mapping = $this->conf[
'mapping'];
234 if (isset($this->conf[
'table2handlerKeys'])) {
235 $this->table2handlerKeys = $this->conf[
'table2handlerKeys'];
237 if (isset($this->conf[
'handlerCfg'])) {
238 $this->handlerCfg = $this->conf[
'handlerCfg'];
240 if (isset($this->handlerCfg[
'_DEFAULT'][
'config'][
'driver'])) {
242 $driver = $this->handlerCfg[
'_DEFAULT'][
'config'][
'driver'];
243 $className =
'TYPO3\\CMS\\Dbal\\Database\\Specifics\\' . ucfirst(strtolower(
$driver));
244 if (class_exists($className)) {
245 if (!is_subclass_of($className,
'TYPO3\\CMS\\Dbal\\Database\\Specifics\\AbstractSpecifics')) {
246 throw new \InvalidArgumentException($className .
' must inherit from \\TYPO3\\CMS\\Dbal\\Database\\Specifics\\AbstractSpecifics', 1416919866);
254 $this->printErrors = !empty($this->conf[
'debugOptions'][
'printErrors']);
255 $this->
debug = !empty($this->conf[
'debugOptions'][
'enabled']);
292 if ($phpCodeCache->has($this->cacheIdentifier)) {
293 $fieldInformation = $phpCodeCache->requireOnce($this->cacheIdentifier);
294 $this->cache_autoIncFields = $fieldInformation[
'incFields'];
295 $this->cache_fieldType = $fieldInformation[
'fieldTypes'];
296 $this->cache_primaryKeys = $fieldInformation[
'primaryKeys'];
301 $phpCodeCache->set($this->cacheIdentifier, $this->
getCacheableString($completeFieldInformation), array(
't3lib_db'));
323 if (isset(
$GLOBALS[
'TYPO3_LOADED_EXT']) && (is_array(
$GLOBALS[
'TYPO3_LOADED_EXT']) ||
$GLOBALS[
'TYPO3_LOADED_EXT'] instanceof \ArrayAccess)) {
324 foreach (
$GLOBALS[
'TYPO3_LOADED_EXT'] as $extensionConfiguration) {
325 $isArray = (is_array($extensionConfiguration) || $extensionConfiguration instanceof \ArrayAccess);
326 if (!$isArray || ($isArray && !isset($extensionConfiguration[
'ext_tables.sql']))) {
329 $extensionsSql = file_get_contents($extensionConfiguration[
'ext_tables.sql']);
342 $parsedSql = $this->installerSql->getFieldDefinitions_fileContent(
$sql);
353 return array(
'incFields' => $this->cache_autoIncFields,
'fieldTypes' => $this->cache_fieldType,
'primaryKeys' => $this->cache_primaryKeys);
364 $cacheString =
'return ';
365 $cacheString .= var_export($fieldInformation, TRUE);
377 foreach ($parsedExtSQL as $table => $tdef) {
379 if (isset($this->mapping[$table])) {
380 $table = $this->mapping[$table][
'mapTableName'];
382 if (is_array($tdef[
'fields'])) {
383 foreach ($tdef[
'fields'] as $field => $fdefString) {
384 $fdef = $this->SQLparser->parseFieldDef($fdefString);
385 $fieldType = isset($fdef[
'fieldType']) ? $fdef[
'fieldType'] :
'';
386 $this->cache_fieldType[$table][$field][
'type'] = $fieldType;
387 $this->cache_fieldType[$table][$field][
'metaType'] = $this->
MySQLMetaType($fieldType);
388 $this->cache_fieldType[$table][$field][
'notnull'] = isset($fdef[
'featureIndex'][
'NOTNULL']) && !$this->SQLparser->checkEmptyDefaultValue($fdef[
'featureIndex']) ? 1 : 0;
389 if (isset($fdef[
'featureIndex'][
'DEFAULT'])) {
390 $default = $fdef[
'featureIndex'][
'DEFAULT'][
'value'][0];
391 if (isset($fdef[
'featureIndex'][
'DEFAULT'][
'value'][1])) {
392 $default = $fdef[
'featureIndex'][
'DEFAULT'][
'value'][1] . $default . $fdef[
'featureIndex'][
'DEFAULT'][
'value'][1];
394 $this->cache_fieldType[$table][$field][
'default'] = $default;
396 if (isset($fdef[
'featureIndex'][
'AUTO_INCREMENT'])) {
397 $this->cache_autoIncFields[$table] = $field;
399 if (isset($tdef[
'keys'][
'PRIMARY'])) {
400 $this->cache_primaryKeys[$table] = substr($tdef[
'keys'][
'PRIMARY'], 13, -1);
416 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'mapping'])) {
417 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'dbal'][
'mapping'] as $mappedTable => $mappedConf) {
418 if (array_key_exists($mappedTable, $fieldInfo[
'incFields'])) {
419 $mappedTableAlias = $mappedConf[
'mapTableName'];
420 if (isset($mappedConf[
'mapFieldNames'][$fieldInfo[
'incFields'][$mappedTable]])) {
421 $fieldInfo[
'incFields'][$mappedTableAlias] = $mappedConf[
'mapFieldNames'][$fieldInfo[
'incFields'][$mappedTable]];
423 $fieldInfo[
'incFields'][$mappedTableAlias] = $fieldInfo[
'incFields'][$mappedTable];
426 if (array_key_exists($mappedTable, $fieldInfo[
'fieldTypes'])) {
427 $tempMappedFieldConf = array();
428 foreach ($fieldInfo[
'fieldTypes'][$mappedTable] as $field => $fieldConf) {
429 $tempMappedFieldConf[$mappedConf[
'mapFieldNames'][$field]] = $fieldConf;
431 $fieldInfo[
'fieldTypes'][$mappedConf[
'mapTableName']] = $tempMappedFieldConf;
433 if (array_key_exists($mappedTable, $fieldInfo[
'primaryKeys'])) {
434 $mappedTableAlias = $mappedConf[
'mapTableName'];
435 if (isset($mappedConf[
'mapFieldNames'][$fieldInfo[
'primaryKeys'][$mappedTable]])) {
436 $fieldInfo[
'primaryKeys'][$mappedTableAlias] = $mappedConf[
'mapFieldNames'][$fieldInfo[
'primaryKeys'][$mappedTable]];
438 $fieldInfo[
'primaryKeys'][$mappedTableAlias] = $fieldInfo[
'primaryKeys'][$mappedTable];
476 $ORIG_tableName = $table;
479 $fields_values = $this->
map_assocArray($fields_values, $tableArray);
481 if ($this->mapping[$table][
'mapTableName']) {
482 $table = $this->mapping[$table][
'mapTableName'];
487 $hType = (string)$this->handlerCfg[$this->lastHandlerKey][
'type'];
491 $this->lastQuery = $this->
INSERTquery($table, $fields_values, $no_quote_fields);
492 if (is_string($this->lastQuery)) {
493 $sqlResult = $this->
query($this->lastQuery);
495 $sqlResult = $this->
query($this->lastQuery[0]);
497 $where = $this->cache_autoIncFields[$table] .
'=' . $new_id;
498 foreach ($this->lastQuery[1] as $field => $content) {
507 if (isset($this->cache_autoIncFields[$table])) {
508 if (isset($fields_values[$this->cache_autoIncFields[$table]])) {
509 $new_id = $fields_values[$this->cache_autoIncFields[$table]];
510 if ($table !=
'tx_dbal_debuglog') {
513 } elseif (!$this->handlerInstance[$this->lastHandlerKey]->hasInsertID) {
516 $new_id = $this->handlerInstance[
$this->lastHandlerKey]->GenID($table .
'_' . $this->cache_autoIncFields[$table], $this->handlerInstance[$this->lastHandlerKey]->sequenceStart);
517 $fields_values[$this->cache_autoIncFields[$table]] = $new_id;
518 if ($table !=
'tx_dbal_debuglog') {
523 $this->lastQuery = $this->
INSERTquery($table, $fields_values, $no_quote_fields);
524 if (is_string($this->lastQuery)) {
528 if (strlen($this->lastQuery[0])) {
530 if ($this->handlerInstance[$this->lastHandlerKey]->hasInsertID) {
532 $new_id = $this->handlerInstance[
$this->lastHandlerKey]->Insert_ID($table, $this->cache_autoIncFields[$table]);
533 if ($table !==
'tx_dbal_debuglog') {
538 if (is_array($this->lastQuery[1])) {
539 foreach ($this->lastQuery[1] as $field => $content) {
540 if (empty($content)) {
543 if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) {
545 } elseif (isset($this->cache_primaryKeys[$table])) {
547 $pks = explode(
',', $this->cache_primaryKeys[$table]);
548 foreach ($pks as $pk) {
549 if (isset($fields_values[$pk])) {
550 $where .= $pk .
'=' . $this->
fullQuoteStr($fields_values[$pk], $table) .
' AND ';
558 throw new \RuntimeException(
'Could not update BLOB >>>> no WHERE clause found!', 1321860519);
562 if (is_array($this->lastQuery[2])) {
563 foreach ($this->lastQuery[2] as $field => $content) {
564 if (empty($content)) {
567 if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) {
569 } elseif (isset($this->cache_primaryKeys[$table])) {
571 $pks = explode(
',', $this->cache_primaryKeys[$table]);
572 foreach ($pks as $pk) {
573 if (isset($fields_values[$pk])) {
574 $where .= $pk .
'=' . $this->
fullQuoteStr($fields_values[$pk], $table) .
' AND ';
582 throw new \RuntimeException(
'Could not update CLOB >>>> no WHERE clause found!', 1310027337);
590 $sqlResult = $this->handlerInstance[
$this->lastHandlerKey]->exec_INSERTquery($table, $fields_values, $no_quote_fields);
593 if ($this->printErrors && $this->
sql_error()) {
597 $this->
debugHandler(
'exec_INSERTquery', GeneralUtility::milliseconds() - $pt, array(
598 'handlerType' => $hType,
599 'args' => array($table, $fields_values),
600 'ORIG_tablename' => $ORIG_tableName
603 foreach ($this->postProcessHookObjects as $hookObject) {
604 $hookObject->exec_INSERTquery_postProcessAction($table, $fields_values, $no_quote_fields, $this);
621 if ((
string)$this->handlerCfg[$this->lastHandlerKey][
'type'] ===
'native') {
623 $res = $this->
query(parent::INSERTmultipleRows($table, $fields, $rows, $no_quote_fields));
625 foreach ($rows as $row) {
626 $fields_values = array();
627 foreach ($fields as $key => $value) {
628 $fields_values[$value] = $row[$key];
633 foreach ($this->postProcessHookObjects as $hookObject) {
634 $hookObject->exec_INSERTmultipleRows_postProcessAction($table, $fields, $rows, $no_quote_fields, $this);
649 public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = FALSE) {
652 $ORIG_tableName = $table;
655 $fields_values = $this->
map_assocArray($fields_values, $tableArray);
657 $whereParts = $this->SQLparser->parseWhereClause($where);
658 $this->
map_sqlParts($whereParts, $tableArray[0][
'table']);
659 $where = $this->SQLparser->compileWhereClause($whereParts, FALSE);
661 if ($this->mapping[$table][
'mapTableName']) {
662 $table = $this->mapping[$table][
'mapTableName'];
667 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
671 $this->lastQuery = $this->
UPDATEquery($table, $where, $fields_values, $no_quote_fields);
672 if (is_string($this->lastQuery)) {
673 $sqlResult = $this->
query($this->lastQuery);
675 $sqlResult = $this->
query($this->lastQuery[0]);
676 foreach ($this->lastQuery[1] as $field => $content) {
683 $this->lastQuery = $this->
UPDATEquery($table, $where, $fields_values, $no_quote_fields);
684 if (is_string($this->lastQuery)) {
688 if (strlen($this->lastQuery[0])) {
691 if (is_array($this->lastQuery[1])) {
692 foreach ($this->lastQuery[1] as $field => $content) {
696 if (is_array($this->lastQuery[2])) {
697 foreach ($this->lastQuery[2] as $field => $content) {
705 $sqlResult = $this->handlerInstance[
$this->lastHandlerKey]->exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields);
708 if ($this->printErrors && $this->
sql_error()) {
712 $this->
debugHandler(
'exec_UPDATEquery', GeneralUtility::milliseconds() - $pt, array(
713 'handlerType' => $hType,
714 'args' => array($table, $where, $fields_values),
715 'ORIG_from_table' => $ORIG_tableName
718 foreach ($this->postProcessHookObjects as $hookObject) {
719 $hookObject->exec_UPDATEquery_postProcessAction($table, $where, $fields_values, $no_quote_fields, $this);
735 $ORIG_tableName = $table;
738 $whereParts = $this->SQLparser->parseWhereClause($where);
739 $this->
map_sqlParts($whereParts, $tableArray[0][
'table']);
740 $where = $this->SQLparser->compileWhereClause($whereParts, FALSE);
742 if ($this->mapping[$table][
'mapTableName']) {
743 $table = $this->mapping[$table][
'mapTableName'];
748 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
752 $this->lastQuery = $this->
DELETEquery($table, $where);
753 $sqlResult = $this->
query($this->lastQuery);
756 $this->lastQuery = $this->
DELETEquery($table, $where);
763 if ($this->printErrors && $this->
sql_error()) {
767 $this->
debugHandler(
'exec_DELETEquery', GeneralUtility::milliseconds() - $pt, array(
768 'handlerType' => $hType,
769 'args' => array($table, $where),
770 'ORIG_from_table' => $ORIG_tableName
773 foreach ($this->postProcessHookObjects as $hookObject) {
774 $hookObject->exec_DELETEquery_postProcessAction($table, $where, $this);
792 public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy =
'', $orderBy =
'', $limit =
'') {
795 $ORIG_tableName = $from_table;
797 $parsedFromTable = array();
798 $remappedParameters = array();
799 if ($tableArray = $this->
map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) {
800 $from = $parsedFromTable ? $parsedFromTable : $from_table;
804 if (count($remappedParameters) > 0) {
806 $fromTable = $mappedQueryParts[1];
808 $fromTable = $from_table;
811 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
815 if (count($remappedParameters) > 0) {
816 list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->
compileSelectParameters($remappedParameters);
818 $this->lastQuery = $this->
SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
819 $sqlResult = $this->
query($this->lastQuery);
820 $this->resourceIdToTableNameMap[serialize($sqlResult)] = $ORIG_tableName;
826 if ($splitLimit[1]) {
828 $numrows = $splitLimit[1];
829 $offset = $splitLimit[0];
831 $numrows = $splitLimit[0];
834 if (count($remappedParameters) > 0) {
837 $sqlResult = $this->handlerInstance[
$this->lastHandlerKey]->SelectLimit($this->
SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy), $numrows, $offset);
839 $this->lastQuery = $sqlResult->sql;
841 if (count($remappedParameters) > 0) {
844 $this->lastQuery = $this->
SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
848 if (!is_object($sqlResult)) {
851 $sqlResult->TYPO3_DBAL_handlerType =
'adodb';
853 $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
856 if (count($remappedParameters) > 0) {
857 list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->
compileSelectParameters($remappedParameters);
859 $sqlResult = $this->handlerInstance[
$this->lastHandlerKey]->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
860 if (is_object($sqlResult)) {
861 $sqlResult->TYPO3_DBAL_handlerType =
'userdefined';
863 $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
867 if ($this->printErrors && $this->
sql_error()) {
872 'handlerType' => $hType,
873 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit),
874 'ORIG_from_table' => $ORIG_tableName
876 if ($this->conf[
'debugOptions'][
'numberRows']) {
879 $this->
debugHandler(
'exec_SELECTquery', GeneralUtility::milliseconds() - $pt, $data);
894 $ORIG_tableName = $table;
897 if ($this->mapping[$table][
'mapTableName']) {
898 $table = $this->mapping[$table][
'mapTableName'];
903 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
908 $sqlResult = $this->
query($this->lastQuery);
918 if ($this->printErrors && $this->
sql_error()) {
922 $this->
debugHandler(
'exec_TRUNCATEquery', GeneralUtility::milliseconds() - $pt, array(
923 'handlerType' => $hType,
924 'args' => array($table),
925 'ORIG_from_table' => $ORIG_tableName
928 foreach ($this->postProcessHookObjects as $hookObject) {
929 $hookObject->exec_TRUNCATEquery_postProcessAction($table, $this);
944 switch ($queryParts[
'type']) {
946 $selectFields = $this->SQLparser->compileFieldList($queryParts[
'SELECT']);
947 $fromTables = $this->SQLparser->compileFromTables($queryParts[
'FROM']);
948 $whereClause = isset($queryParts[
'WHERE']) ? $this->SQLparser->compileWhereClause($queryParts[
'WHERE']) :
'1=1';
949 $groupBy = isset($queryParts[
'GROUPBY']) ? $this->SQLparser->compileFieldList($queryParts[
'GROUPBY']) :
'';
950 $orderBy = isset($queryParts[
'ORDERBY']) ? $this->SQLparser->compileFieldList($queryParts[
'ORDERBY']) :
'';
951 $limit = isset($queryParts[
'LIMIT']) ? $queryParts[
'LIMIT'] :
'';
952 return $this->
exec_SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy, $limit);
954 $table = $queryParts[
'TABLE'];
956 foreach ($queryParts[
'FIELDS'] as $fN => $fV) {
957 $fields[$fN] = $fV[0];
959 $whereClause = isset($queryParts[
'WHERE']) ? $this->SQLparser->compileWhereClause($queryParts[
'WHERE']) :
'1=1';
962 $table = $queryParts[
'TABLE'];
964 if (isset($queryParts[
'VALUES_ONLY']) && is_array($queryParts[
'VALUES_ONLY'])) {
965 $fields =
$GLOBALS[
'TYPO3_DB']->cache_fieldType[$table];
967 foreach ($fields as $fn => $fd) {
968 $values[$fn] = $queryParts[
'VALUES_ONLY'][$fc++][0];
971 foreach ($queryParts[
'FIELDS'] as $fN => $fV) {
972 $values[$fN] = $fV[0];
977 $table = $queryParts[
'TABLE'];
978 $whereClause = isset($queryParts[
'WHERE']) ? $this->SQLparser->compileWhereClause($queryParts[
'WHERE']) :
'1=1';
980 case 'TRUNCATETABLE':
981 $table = $queryParts[
'TABLE'];
1015 public function INSERTquery($table, $fields_values, $no_quote_fields = FALSE) {
1017 if (!is_array($fields_values) || count($fields_values) === 0) {
1020 foreach ($this->preProcessHookObjects as $hookObject) {
1021 $hookObject->INSERTquery_preProcessAction($table, $fields_values, $no_quote_fields, $this);
1023 if (is_string($no_quote_fields)) {
1024 $no_quote_fields = explode(
',', $no_quote_fields);
1025 } elseif (!is_array($no_quote_fields)) {
1026 $no_quote_fields = array();
1028 $blobFields = $clobFields = array();
1031 $quoteClob = isset($this->handlerCfg[$handlerKey][
'config'][
'quoteClob']) ? $this->handlerCfg[$handlerKey][
'config'][
'quoteClob'] : FALSE;
1032 foreach ($fields_values as $k => $v) {
1043 if ($mt[0] ==
'I') {
1045 } elseif ($mt[0] ==
'F') {
1051 if (count($blobFields) || count($clobFields)) {
1057 ', array_keys($nArr)) .
' 1063 if (count($blobFields)) {
1064 $query[1] = $blobFields;
1066 if (count($clobFields)) {
1067 $query[2] = $clobFields;
1069 if (isset($query[0]) && ($this->debugOutput || $this->store_lastBuiltQuery)) {
1070 $this->debug_lastBuiltQuery = $query[0];
1076 ', array_keys($nArr)) .
' 1081 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1082 $this->debug_lastBuiltQuery = $query;
1098 if ((
string) $this->handlerCfg[$this->lastHandlerKey][
'type'] ===
'native') {
1099 return parent::INSERTmultipleRows($table, $fields, $rows, $no_quote_fields);
1102 foreach ($rows as $row) {
1103 $fields_values = array();
1104 foreach ($fields as $key => $value) {
1105 $fields_values[$value] = $row[$key];
1107 $rowQuery = $this->
INSERTquery($table, $fields_values, $no_quote_fields);
1108 if (is_array($rowQuery)) {
1128 public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = FALSE) {
1130 if (is_string($where)) {
1131 foreach ($this->preProcessHookObjects as $hookObject) {
1132 $hookObject->UPDATEquery_preProcessAction($table, $where, $fields_values, $no_quote_fields, $this);
1134 $blobFields = $clobFields = array();
1136 if (is_array($fields_values) && count($fields_values)) {
1137 if (is_string($no_quote_fields)) {
1138 $no_quote_fields = explode(
',', $no_quote_fields);
1139 } elseif (!is_array($no_quote_fields)) {
1140 $no_quote_fields = array();
1143 $quoteClob = isset($this->handlerCfg[$handlerKey][
'config'][
'quoteClob']) ? $this->handlerCfg[$handlerKey][
'config'][
'quoteClob'] : FALSE;
1144 foreach ($fields_values as $k => $v) {
1155 if ($mt[0] ==
'I') {
1157 } elseif ($mt[0] ==
'F') {
1164 if (count($blobFields) || count($clobFields)) {
1170 ', $nArr) . (strlen($where) > 0 ?
' 1174 if (count($blobFields)) {
1175 $query[1] = $blobFields;
1177 if (count($clobFields)) {
1178 $query[2] = $clobFields;
1181 $this->debug_lastBuiltQuery = $query[0];
1187 ', $nArr) . (strlen($where) > 0 ?
' 1190 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1191 $this->debug_lastBuiltQuery = $query;
1196 throw new \InvalidArgumentException(
'TYPO3 Fatal Error: "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !', 1270853887);
1209 if (is_string($where)) {
1210 foreach ($this->preProcessHookObjects as $hookObject) {
1211 $hookObject->DELETEquery_preProcessAction($table, $where, $this);
1215 $query =
'DELETE FROM ' . $table . (strlen($where) > 0 ?
' WHERE ' . $where :
'');
1216 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1217 $this->debug_lastBuiltQuery = $query;
1221 throw new \InvalidArgumentException(
'TYPO3 Fatal Error: "Where" clause argument for DELETE query was not a string in $this->DELETEquery() !', 1310027383);
1236 public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy =
'', $orderBy =
'', $limit =
'') {
1238 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
1243 if ($splitLimit[1]) {
1245 $numrows = $splitLimit[1];
1246 $offset = $splitLimit[0];
1247 $limit = $numrows .
' OFFSET ' . $offset;
1256 $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
1257 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1258 $this->debug_lastBuiltQuery = $query;
1275 if (count($params[2]) > 0) {
1279 if (count($params[3]) > 0) {
1283 if (count($params[4]) > 0) {
1287 list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->
compileSelectParameters($params);
1289 $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
1290 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1291 $this->debug_lastBuiltQuery = $query;
1304 $select_fields = $this->SQLparser->compileFieldList($params[0]);
1305 $from_table = $this->SQLparser->compileFromTables($params[1]);
1306 $where_clause = count($params[2]) > 0 ? $this->SQLparser->compileWhereClause($params[2]) :
'';
1307 $groupBy = count($params[3]) > 0 ? $this->SQLparser->compileFieldList($params[3]) :
'';
1308 $orderBy = count($params[4]) > 0 ? $this->SQLparser->compileFieldList($params[4]) :
'';
1309 return array($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
1319 foreach ($this->preProcessHookObjects as $hookObject) {
1320 $hookObject->TRUNCATEquery_preProcessAction($table, $this);
1324 $query =
'TRUNCATE TABLE ' . $table;
1325 if ($this->debugOutput || $this->store_lastBuiltQuery) {
1326 $this->debug_lastBuiltQuery = $query;
1348 public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy =
'', $orderBy =
'', $limit =
'', array $input_parameters = array()) {
1350 $precompiledParts = array();
1351 if ($this->queryCache) {
1353 'selectFields' => $select_fields,
1354 'fromTable' => $from_table,
1355 'whereClause' => $where_clause,
1356 'groupBy' => $groupBy,
1357 'orderBy' => $orderBy,
1360 if ($this->queryCache->has($cacheKey)) {
1361 $precompiledParts = $this->queryCache->get($cacheKey);
1364 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters),
1365 'precompiledParts' => $precompiledParts
1367 $this->
debugHandler(
'prepare_SELECTquery (cache hit)', GeneralUtility::milliseconds() - $pt, $data);
1371 $ORIG_tableName =
'';
1372 if (count($precompiledParts) == 0) {
1374 $ORIG_tableName = $from_table;
1376 $parsedFromTable = array();
1377 $queryComponents = array();
1378 if ($tableArray = $this->
map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) {
1379 $from = $parsedFromTable ? $parsedFromTable : $from_table;
1381 $queryComponents[
'SELECT'] = $components[0];
1382 $queryComponents[
'FROM'] = $components[1];
1383 $queryComponents[
'WHERE'] = $components[2];
1384 $queryComponents[
'GROUPBY'] = $components[3];
1385 $queryComponents[
'ORDERBY'] = $components[4];
1386 $queryComponents[
'parameters'] = $components[5];
1388 $queryComponents = $this->
getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
1390 $queryComponents[
'ORIG_tableName'] = $ORIG_tableName;
1393 $queryComponents[
'SELECT'] = $this->
_quoteFieldNames($queryComponents[
'SELECT']);
1394 $queryComponents[
'FROM'] = $this->
_quoteFromTables($queryComponents[
'FROM']);
1395 $queryComponents[
'WHERE'] = $this->
_quoteWhereClause($queryComponents[
'WHERE']);
1396 $queryComponents[
'GROUPBY'] = $this->
_quoteGroupBy($queryComponents[
'GROUPBY']);
1397 $queryComponents[
'ORDERBY'] = $this->
_quoteOrderBy($queryComponents[
'ORDERBY']);
1400 if ($this->queryCache) {
1402 $this->queryCache->set($cacheKey, $precompiledParts);
1403 }
catch (\
TYPO3\CMS\Core\Cache\Exception $e) {
1410 $preparedStatement =
GeneralUtility::makeInstance(
'TYPO3\\CMS\\Core\\Database\\PreparedStatement',
'', $from_table, $precompiledParts);
1413 foreach ($input_parameters as $key => $value) {
1414 $preparedStatement->bindValue($key, $value, \
TYPO3\CMS\Core\Database\PreparedStatement::PARAM_AUTOTYPE);
1418 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit, $input_parameters),
1419 'ORIG_from_table' => $ORIG_tableName
1421 $this->
debugHandler(
'prepare_SELECTquery', GeneralUtility::milliseconds() - $pt, $data);
1424 return $preparedStatement;
1439 protected function getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit) {
1440 $queryComponents = array(
1447 'parameters' => array()
1450 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
1455 if ($splitLimit[1]) {
1457 $numrows = $splitLimit[1];
1458 $offset = $splitLimit[0];
1459 $limit = $numrows .
' OFFSET ' . $offset;
1462 $queryComponents[
'LIMIT'] = $limit;
1463 $queryComponents[
'SELECT'] = $this->SQLparser->parseFieldList($select_fields);
1464 if ($this->SQLparser->parse_error) {
1465 throw new \InvalidArgumentException($this->SQLparser->parse_error, 1310027408);
1467 $queryComponents[
'FROM'] = $this->SQLparser->parseFromTables($from_table);
1468 $queryComponents[
'WHERE'] = $this->SQLparser->parseWhereClause($where_clause,
'', $queryComponents[
'parameters']);
1469 if (!is_array($queryComponents[
'WHERE'])) {
1470 throw new \InvalidArgumentException(
'Could not parse where clause', 1310027427);
1472 $queryComponents[
'GROUPBY'] = $this->SQLparser->parseFieldList($groupBy);
1473 $queryComponents[
'ORDERBY'] = $this->SQLparser->parseFieldList($orderBy);
1475 return $queryComponents;
1485 $parameterWrap =
'__' . dechex(time()) .
'__';
1486 foreach ($components[
'parameters'] as $key => $params) {
1488 foreach ($params as $index => $param) {
1489 $components[
'parameters'][$key][$index][0] = $parameterWrap . $param[0] . $parameterWrap;
1492 $components[
'parameters'][$key][0] = $parameterWrap . $params[0] . $parameterWrap;
1495 $select_fields = $this->SQLparser->compileFieldList($components[
'SELECT']);
1496 $from_table = $this->SQLparser->compileFromTables($components[
'FROM']);
1497 $where_clause = $this->SQLparser->compileWhereClause($components[
'WHERE']);
1498 $groupBy = $this->SQLparser->compileFieldList($components[
'GROUPBY']);
1499 $orderBy = $this->SQLparser->compileFieldList($components[
'ORDERBY']);
1500 $limit = $components[
'LIMIT'];
1501 $precompiledParts = array();
1503 $hType = (string) $this->handlerCfg[$this->lastHandlerKey][
'type'];
1504 $precompiledParts[
'handler'] = $hType;
1505 $precompiledParts[
'ORIG_tableName'] = $components[
'ORIG_tableName'];
1508 $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
1509 $precompiledParts[
'queryParts'] = explode($parameterWrap, $query);
1512 $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
1513 $precompiledParts[
'queryParts'] = explode($parameterWrap, $query);
1514 $precompiledParts[
'LIMIT'] = $limit;
1517 $precompiledParts[
'queryParts'] = array(
1518 'SELECT' => $select_fields,
1519 'FROM' => $from_table,
1520 'WHERE' => $where_clause,
1521 'GROUPBY' => $groupBy,
1522 'ORDERBY' => $orderBy,
1527 return $precompiledParts;
1542 $preparedStatement = NULL;
1543 switch ($queryComponents[
'handler']) {
1545 $this->lastQuery = $query;
1546 $preparedStatement = parent::prepare_PREPAREDquery($this->lastQuery, $queryComponents);
1547 $this->resourceIdToTableNameMap[serialize($preparedStatement)] = $queryComponents[
'ORIG_tableName'];
1551 $preparedStatement =
GeneralUtility::makeInstance(
'TYPO3\\CMS\\Dbal\\Database\\AdodbPreparedStatement', $query, $queryComponents, $this);
1552 if (!$preparedStatement->prepare()) {
1553 $preparedStatement = FALSE;
1557 throw new \RuntimeException(
'prepare_PREPAREDquery is not implemented for userdefined handlers', 1394620167);
1569 if ($this->printErrors && $this->
sql_error()) {
1574 'handlerType' => $queryComponents[
'handler'],
1575 'args' => $queryComponents,
1576 'ORIG_from_table' => $queryComponents[
'ORIG_tableName']
1578 $this->
debugHandler(
'prepare_PREPAREDquery', GeneralUtility::milliseconds() - $pt, $data);
1581 return $preparedStatement;
1610 if ($select_fields ==
'') {
1614 return $select_fields;
1616 $select_fields = $this->SQLparser->parseFieldList($select_fields);
1617 if ($this->SQLparser->parse_error) {
1618 throw new \InvalidArgumentException($this->SQLparser->parse_error, 1310027490);
1621 return $this->SQLparser->compileFieldList($select_fields);
1632 foreach ($select_fields as $k => $v) {
1633 if ($select_fields[$k][
'field'] !=
'' && $select_fields[$k][
'field'] !=
'*' && !is_numeric($select_fields[$k][
'field'])) {
1634 $select_fields[$k][
'field'] = $this->
quoteName($select_fields[$k][
'field']);
1636 if ($select_fields[$k][
'table'] !=
'' && !is_numeric($select_fields[$k][
'table'])) {
1637 $select_fields[$k][
'table'] = $this->
quoteName($select_fields[$k][
'table']);
1639 if ($select_fields[$k][
'as'] !=
'') {
1640 $select_fields[$k][
'as'] = $this->
quoteName($select_fields[$k][
'as']);
1642 if (isset($select_fields[$k][
'func_content.']) && $select_fields[$k][
'func_content.'][0][
'func_content'] !=
'*') {
1643 $select_fields[$k][
'func_content.'][0][
'func_content'] = $this->
quoteFieldNames($select_fields[$k][
'func_content.'][0][
'func_content']);
1644 $select_fields[$k][
'func_content'] = $this->
quoteFieldNames($select_fields[$k][
'func_content']);
1646 if (isset($select_fields[$k][
'flow-control'])) {
1648 if ($select_fields[$k][
'flow-control'][
'type'] ===
'CASE') {
1649 if (isset($select_fields[$k][
'flow-control'][
'case_field'])) {
1650 $select_fields[$k][
'flow-control'][
'case_field'] = $this->
quoteFieldNames($select_fields[$k][
'flow-control'][
'case_field']);
1652 foreach ($select_fields[$k][
'flow-control'][
'when'] as $key => $when) {
1653 $select_fields[$k][
'flow-control'][
'when'][$key][
'when_value'] = $this->
_quoteWhereClause($when[
'when_value']);
1658 return $select_fields;
1668 if ($from_table ===
'') {
1674 $from_table = $this->SQLparser->parseFromTables($from_table);
1676 return $this->SQLparser->compileFromTables($from_table);
1687 foreach ($from_table as $k => $v) {
1688 $from_table[$k][
'table'] = $this->
quoteName($from_table[$k][
'table']);
1689 if ($from_table[$k][
'as'] !=
'') {
1690 $from_table[$k][
'as'] = $this->
quoteName($from_table[$k][
'as']);
1692 if (is_array($v[
'JOIN'])) {
1693 foreach ($v[
'JOIN'] as $joinCnt => $join) {
1694 $from_table[$k][
'JOIN'][$joinCnt][
'withTable'] = $this->
quoteName($join[
'withTable']);
1695 $from_table[$k][
'JOIN'][$joinCnt][
'as'] = $join[
'as'] ? $this->
quoteName($join[
'as']) :
'';
1696 foreach ($from_table[$k][
'JOIN'][$joinCnt][
'ON'] as &$condition) {
1697 $condition[
'left'][
'table'] = $condition[
'left'][
'table'] ? $this->
quoteName($condition[
'left'][
'table']) :
'';
1698 $condition[
'left'][
'field'] = $this->
quoteName($condition[
'left'][
'field']);
1699 $condition[
'right'][
'table'] = $condition[
'right'][
'table'] ? $this->
quoteName($condition[
'right'][
'table']) :
'';
1700 $condition[
'right'][
'field'] = $this->
quoteName($condition[
'right'][
'field']);
1717 return $where_clause;
1719 $where_clause = $this->SQLparser->parseWhereClause($where_clause);
1720 if (is_array($where_clause)) {
1722 $where_clause = $this->SQLparser->compileWhereClause($where_clause);
1724 throw new \InvalidArgumentException(
'Could not parse where clause', 1310027511);
1726 return $where_clause;
1737 foreach ($where_clause as $k => $v) {
1739 if (is_array($where_clause[$k][
'sub'])) {
1741 } elseif (isset($v[
'func'])) {
1742 switch ($where_clause[$k][
'func'][
'type']) {
1744 $where_clause[$k][
'func'][
'subquery'] = $this->
quoteSELECTsubquery($v[
'func'][
'subquery']);
1748 $pattern = str_replace($where_clause[$k][
'func'][
'str'][1],
'\\' . $where_clause[$k][
'func'][
'str'][1], $where_clause[$k][
'func'][
'str'][0]);
1751 $patternForLike = $this->
escapeStrForLike($pattern, $where_clause[$k][
'func'][
'table']);
1752 $where_clause[$k][
'func'][
'str_like'] = $patternForLike;
1753 if ($where_clause[$k][
'func'][
'table'] !==
'') {
1754 $where_clause[$k][
'func'][
'table'] = $this->
quoteName($v[
'func'][
'table']);
1756 if ($where_clause[$k][
'func'][
'field'] !==
'') {
1757 if (!empty($this->dbmsSpecifics) && $this->dbmsSpecifics->getSpecific(Specifics\AbstractSpecifics::CAST_FIND_IN_SET)) {
1758 $where_clause[$k][
'func'][
'field'] =
'CAST(' . $this->
quoteName($v[
'func'][
'field']) .
' AS CHAR)';
1760 $where_clause[$k][
'func'][
'field'] = $this->
quoteName($v[
'func'][
'field']);
1767 if ($where_clause[$k][
'func'][
'table'] !=
'') {
1768 $where_clause[$k][
'func'][
'table'] = $this->
quoteName($v[
'func'][
'table']);
1770 if ($where_clause[$k][
'func'][
'field'] !=
'') {
1771 $where_clause[$k][
'func'][
'field'] = $this->
quoteName($v[
'func'][
'field']);
1776 if ($where_clause[$k][
'table'] !=
'') {
1777 $where_clause[$k][
'table'] = $this->
quoteName($where_clause[$k][
'table']);
1779 if (!is_numeric($where_clause[$k][
'field'])) {
1780 $where_clause[$k][
'field'] = $this->
quoteName($where_clause[$k][
'field']);
1782 if (isset($where_clause[$k][
'calc_table'])) {
1783 if ($where_clause[$k][
'calc_table'] !=
'') {
1784 $where_clause[$k][
'calc_table'] = $this->
quoteName($where_clause[$k][
'calc_table']);
1786 if ($where_clause[$k][
'calc_field'] !=
'') {
1787 $where_clause[$k][
'calc_field'] = $this->
quoteName($where_clause[$k][
'calc_field']);
1791 if ($where_clause[$k][
'comparator']) {
1792 if (isset($v[
'value'][
'operator'])) {
1793 foreach ($where_clause[$k][
'value'][
'args'] as $argK => $fieldDef) {
1794 $where_clause[$k][
'value'][
'args'][$argK][
'table'] = $this->
quoteName($fieldDef[
'table']);
1795 $where_clause[$k][
'value'][
'args'][$argK][
'field'] = $this->
quoteName($fieldDef[
'field']);
1799 if (
GeneralUtility::inList(
'NOTIN,IN', strtoupper(str_replace(array(
' ', LF, CR, TAB),
'', $where_clause[$k][
'comparator'])))) {
1800 if (isset($v[
'subquery'])) {
1805 (!isset($where_clause[$k][
'value'][1]) || $where_clause[$k][
'value'][1] ==
'')
1806 && is_string($where_clause[$k][
'value'][0]) && strstr($where_clause[$k][
'value'][0],
'.')
1808 $where_clause[$k][
'value'][0] = $this->
quoteFieldNames($where_clause[$k][
'value'][0]);
1810 $where_clause[$k][
'value'][0] = substr($this->handlerInstance[$this->lastHandlerKey]->qstr($where_clause[$k][
'value'][0]), 1, -1);
1816 return $where_clause;
1827 if ($groupBy ===
'') {
1833 $groupBy = $this->SQLparser->parseFieldList($groupBy);
1835 return $this->SQLparser->compileFieldList($groupBy);
1846 foreach ($groupBy as $k => $v) {
1847 $groupBy[$k][
'field'] = $this->
quoteName($groupBy[$k][
'field']);
1848 if ($groupBy[$k][
'table'] !=
'') {
1849 $groupBy[$k][
'table'] = $this->
quoteName($groupBy[$k][
'table']);
1863 if ($orderBy ===
'') {
1869 $orderBy = $this->SQLparser->parseFieldList($orderBy);
1871 return $this->SQLparser->compileFieldList($orderBy);
1882 foreach ($orderBy as $k => $v) {
1883 if ($orderBy[$k][
'table'] ===
'' && $v[
'field'] !==
'' && ctype_digit($v[
'field'])) {
1886 $orderBy[$k][
'field'] = $this->
quoteName($orderBy[$k][
'field']);
1887 if ($orderBy[$k][
'table'] !==
'') {
1888 $orderBy[$k][
'table'] = $this->
quoteName($orderBy[$k][
'table']);
1909 if ($allowNull && $str === NULL) {
1912 return '\'' . $this->
quoteStr($str, $table) .
'\'';
1928 switch ((
string)$this->handlerCfg[$this->lastHandlerKey][
'type']) {
1930 if ($this->handlerInstance[$this->lastHandlerKey][
'link']) {
1937 $str = str_replace(
'\'',
'\\\'', $str);
1944 $str = substr($this->handlerInstance[$this->lastHandlerKey]->qstr($str), 1, -1);
1950 throw new \RuntimeException(
'No handler found!!!', 1310027655);
1963 public function quoteName($name, $handlerKey = NULL, $useBackticks = FALSE) {
1965 $useNameQuote = isset($this->handlerCfg[$handlerKey][
'config'][
'useNameQuote']) ? $this->handlerCfg[$handlerKey][
'config'][
'useNameQuote'] : FALSE;
1966 if ($useNameQuote) {
1968 if (!is_object($this->handlerInstance[$handlerKey]->DataDictionary)) {
1969 $this->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($this->handlerInstance[$handlerKey]);
1971 return $this->handlerInstance[$handlerKey]->DataDictionary->NameQuote($name);
1973 $quote = $useBackticks ?
'`' : $this->handlerInstance[$handlerKey]->nameQuote;
1974 return $quote . $name . $quote;
1987 public function MetaType($type, $table, $maxLength = -1) {
1990 switch ((
string) $this->handlerCfg[$this->lastHandlerKey][
'type']) {
1995 if (in_array($table, $this->cache_fieldType)) {
1997 $str =
$rs->MetaType($type, $maxLength);
2004 throw new \RuntimeException(
'No handler found!!!', 1310027685);
2016 switch (strtoupper($t)) {
2083 switch (strtoupper($meta)) {
2134 switch ($this->handlerCfg[$this->lastHandlerKey][
'type']) {
2155 switch ($this->handlerCfg[$this->lastHandlerKey][
'type']) {
2176 if ($res === FALSE) {
2181 switch ($handlerType) {
2183 $output = $res->num_rows;
2186 $output = method_exists($res,
'RecordCount') ? $res->RecordCount() : 0;
2189 $output = $res->sql_num_rows();
2207 $output = $res->fetch_assoc();
2208 $key = serialize($res);
2209 $tableList = $this->resourceIdToTableNameMap[$key];
2210 unset($this->resourceIdToTableNameMap[$key]);
2217 if (method_exists($res,
'FetchRow')) {
2218 $output = $res->FetchRow();
2219 $tableList = $res->TYPO3_DBAL_tableList;
2225 if (is_array($output)) {
2228 foreach ($output as $key => $value) {
2229 if ($value ===
' ') {
2234 foreach ($output as $key => $value) {
2235 if (is_integer($key)) {
2236 unset($output[$key]);
2244 $output = $res->sql_fetch_assoc();
2245 $tableList = $res->TYPO3_DBAL_tableList;
2250 if (is_array($output)) {
2255 if ($output === NULL) {
2275 $output = $res->fetch_row();
2276 if ($output === NULL) {
2285 if (method_exists($res,
'FetchRow')) {
2286 $output = $res->FetchRow();
2291 if (is_array($output)) {
2293 foreach ($output as $key => $value) {
2294 unset($output[$key]);
2296 $output[$keyIndex] = $value;
2297 if ($value ===
' ') {
2299 $output[$keyIndex] =
'';
2308 $output = $res->sql_fetch_row();
2311 if ($output === NULL) {
2326 if ($res === FALSE) {
2335 if (method_exists($res,
'Close')) {
2357 if (is_object($res) && !$res instanceof \mysqli_result) {
2358 $handlerType = $res->TYPO3_DBAL_handlerType;
2359 } elseif ($res instanceof \mysqli_result) {
2360 $handlerType =
'native';
2362 $handlerType = FALSE;
2364 return $handlerType;
2374 switch ($this->handlerCfg[$this->lastHandlerKey][
'type']) {
2395 switch ($this->handlerCfg[$this->lastHandlerKey][
'type']) {
2420 $output = $res->data_seek($seek);
2423 $output = $res->Move($seek);
2426 $output = $res->sql_data_seek($seek);
2443 foreach ($this->mapping as $tableName => $tableMapInfo) {
2444 if (isset($tableMapInfo[
'mapFieldNames'])) {
2445 foreach ($tableMapInfo[
'mapFieldNames'] as $fieldName => $fieldMapInfo) {
2446 if ($fieldMapInfo === $field) {
2448 $field = $fieldName;
2453 return $this->cache_fieldType[$table][$field][
'metaType'];
2465 if ($res === NULL) {
2466 debug(array(
'no res in sql_field_type!'));
2468 } elseif (is_string($res)) {
2469 if ($res ===
'tx_dbal_debuglog') {
2472 $handlerType =
'adodb';
2477 switch ($handlerType) {
2479 $metaInfo = $res->fetch_field_direct($pointer);
2481 $output = $this->mysqlDataTypeMapping[$metaInfo->type];
2487 if (is_string($pointer)) {
2488 $output = $this->cache_fieldType[$res][$pointer][
'type'];
2492 $output = $res->sql_field_type($pointer);
2521 $globalConfig = unserialize(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXT'][
'extConf'][
'dbal']);
2522 if ($globalConfig[
'sql_query.'][
'passthrough']) {
2523 return parent::sql_query($query);
2526 $queryParts = $this->SQLparser->parseSQL($query);
2527 if (is_array($queryParts) &&
GeneralUtility::inList(
'SELECT,UPDATE,INSERT,DELETE', $queryParts[
'type'])) {
2531 switch ($this->handlerCfg[
'_DEFAULT'][
'type']) {
2536 $sqlResult = $this->handlerInstance[
'_DEFAULT'][
'link']->query($query);
2539 $sqlResult = $this->handlerInstance[
'_DEFAULT']->Execute($query);
2540 $sqlResult->TYPO3_DBAL_handlerType =
'adodb';
2543 $sqlResult = $this->handlerInstance[
'_DEFAULT']->sql_query($query);
2544 $sqlResult->TYPO3_DBAL_handlerType =
'userdefined';
2547 $this->lastHandlerKey =
'_DEFAULT';
2548 if ($this->printErrors && $this->
sql_error()) {
2564 if (
$host || $username || $password) {
2584 if ((
string)$this->handlerCfg[$this->lastHandlerKey][
'type'] ===
'native') {
2588 GeneralUtility::sysLog(
2589 'Could not select MySQL database ' . $TYPO3_db .
': ' . $this->
sql_error(),
2614 $this->lastHandlerKey =
'_DEFAULT';
2615 switch ($this->handlerCfg[
'_DEFAULT'][
'type']) {
2618 $db_list = $this->
query(
"SELECT SCHEMA_NAME FROM information_schema.SCHEMATA");
2619 while ($row = $db_list->fetch_object()) {
2621 $dbArr[] = $row->SCHEMA_NAME;
2629 if (method_exists($this->handlerInstance[
'_DEFAULT'],
'MetaDatabases')) {
2630 $sqlDBs = $this->handlerInstance[
'_DEFAULT']->MetaDatabases();
2631 if (is_array($sqlDBs)) {
2632 foreach ($sqlDBs as $k => $theDB) {
2639 $dbArr = $this->handlerInstance[
'_DEFAULT']->admin_get_tables();
2653 $whichTables = array();
2655 switch ($this->handlerCfg[
'_DEFAULT'][
'type']) {
2657 $tables_result = $this->
query(
'SHOW TABLE STATUS FROM `' . TYPO3_db .
'`');
2660 $whichTables[$theTable[
'Name']] = $theTable;
2663 $tables_result->free();
2668 if (method_exists($this->handlerInstance[
'_DEFAULT'],
'MetaTables')) {
2669 $sqlTables = $this->handlerInstance[
'_DEFAULT']->MetaTables(
'TABLES');
2670 foreach ($sqlTables as $k => $theTable) {
2671 if (preg_match(
'/BIN\\$/', $theTable)) {
2675 $whichTables[$theTable] = array(
'Name' => $theTable);
2680 $whichTables = $this->handlerInstance[
'_DEFAULT']->admin_get_tables();
2684 if (is_array($this->mapping) && count($this->mapping)) {
2687 foreach ($this->mapping as $tN => $tMapInfo) {
2688 if (isset($tMapInfo[
'mapTableName'])) {
2689 $tMap[$tMapInfo[
'mapTableName']] = $tN;
2694 foreach ($whichTables as $tN => $tDefinition) {
2695 if (isset($tMap[$tN])) {
2697 $tDefinition = array(
'Name' => $tN);
2699 $newList[$tN] = $tDefinition;
2701 $whichTables = $newList;
2704 if (is_array($this->table2handlerKeys)) {
2705 foreach ($this->table2handlerKeys as $key => $handlerKey) {
2706 $whichTables[$key] = array(
'Name' => $key);
2709 return $whichTables;
2726 $ORIG_tableName = $tableName;
2729 if ($this->mapping[$tableName][
'mapTableName']) {
2730 $tableName = $this->mapping[$tableName][
'mapTableName'];
2735 switch ((
string) $this->handlerCfg[$this->lastHandlerKey][
'type']) {
2738 $columns_res = $this->
query(
'SHOW columns FROM ' . $tableName);
2739 while ($fieldRow = $columns_res->fetch_assoc()) {
2740 $output[$fieldRow[
'Field']] = $fieldRow;
2742 $columns_res->free();
2746 if (is_array($fieldRows)) {
2747 foreach ($fieldRows as $k => $fieldRow) {
2748 settype($fieldRow,
'array');
2749 $fieldRow[
'Field'] = $fieldRow[
'name'];
2751 $ntype .= $fieldRow[
'max_length'] != -1 ? ($ntype ==
'INT' ?
'(11)' :
'(' . $fieldRow[
'max_length'] .
')') :
'';
2752 $fieldRow[
'Type'] = strtolower($ntype);
2753 $fieldRow[
'Null'] =
'';
2754 $fieldRow[
'Key'] =
'';
2755 $fieldRow[
'Default'] = $fieldRow[
'default_value'];
2756 $fieldRow[
'Extra'] =
'';
2757 $output[$fieldRow[
'name']] = $fieldRow;
2766 if (is_array($tableArray) && is_array($this->mapping[$ORIG_tableName][
'mapFieldNames'])) {
2767 $revFields = array_flip($this->mapping[$ORIG_tableName][
'mapFieldNames']);
2768 $newOutput = array();
2769 foreach ($output as $fN => $fInfo) {
2770 if (isset($revFields[$fN])) {
2771 $fN = $revFields[$fN];
2772 $fInfo[
'Field'] = $fN;
2774 $newOutput[$fN] = $fInfo;
2776 $output = $newOutput;
2791 $ORIG_tableName = $tableName;
2794 if ($this->mapping[$tableName][
'mapTableName']) {
2795 $tableName = $this->mapping[$tableName][
'mapTableName'];
2800 switch ((
string) $this->handlerCfg[$this->lastHandlerKey][
'type']) {
2803 $keyRes = $this->
query(
'SHOW keys FROM ' . $tableName);
2804 while ($keyRow = $keyRes->fetch_assoc()) {
2805 $output[] = $keyRow;
2811 if ($keyRows !== FALSE) {
2812 foreach ($keyRows as $k => $theKey) {
2813 $theKey[
'Table'] = $tableName;
2814 $theKey[
'Non_unique'] = (int)(!$theKey[
'unique']);
2815 $theKey[
'Key_name'] = str_replace($tableName .
'_',
'', $k);
2817 $theKey[
'Collation'] =
'';
2818 $theKey[
'Cardinality'] =
'';
2819 $theKey[
'Sub_part'] =
'';
2820 $theKey[
'Packed'] =
'';
2821 $theKey[
'Null'] =
'';
2822 $theKey[
'Index_type'] =
'';
2823 $theKey[
'Comment'] =
'';
2825 $keycols = $theKey[
'columns'];
2826 foreach ($keycols as $c => $theCol) {
2827 $theKey[
'Seq_in_index'] = $c + 1;
2828 $theKey[
'Column_name'] = $theCol;
2829 $output[] = $theKey;
2835 $theKey[
'Table'] = $tableName;
2836 $theKey[
'Non_unique'] = 0;
2837 $theKey[
'Key_name'] =
'PRIMARY';
2839 $theKey[
'Collation'] =
'';
2840 $theKey[
'Cardinality'] =
'';
2841 $theKey[
'Sub_part'] =
'';
2842 $theKey[
'Packed'] =
'';
2843 $theKey[
'Null'] =
'';
2844 $theKey[
'Index_type'] =
'';
2845 $theKey[
'Comment'] =
'';
2847 if ($priKeyRow !== FALSE) {
2848 foreach ($priKeyRow as $c => $theCol) {
2849 $theKey[
'Seq_in_index'] = $c + 1;
2850 $theKey[
'Column_name'] = $theCol;
2851 $output[] = $theKey;
2860 if (is_array($tableArray) && is_array($this->mapping[$ORIG_tableName][
'mapFieldNames'])) {
2861 $revFields = array_flip($this->mapping[$ORIG_tableName][
'mapFieldNames']);
2862 $newOutput = array();
2863 foreach ($output as $kN => $kInfo) {
2865 $kInfo[
'Table'] = $ORIG_tableName;
2867 if (isset($revFields[$kInfo[
'Column_name']])) {
2868 $kInfo[
'Column_name'] = $revFields[$kInfo[
'Column_name']];
2871 $newOutput[$kN] = $kInfo;
2873 $output = $newOutput;
2892 if ((
string)$this->handlerCfg[$this->lastHandlerKey][
'type'] ===
'native') {
2894 $columns_res = $this->
query(
'SHOW CHARACTER SET');
2895 if ($columns_res !== FALSE) {
2896 while ($row = $columns_res->fetch_assoc()) {
2897 $output[$row[
'Charset']] = $row;
2899 $columns_res->free();
2913 $parsedQuery = $this->SQLparser->parseSQL($query);
2914 if (!is_array($parsedQuery)) {
2915 throw new \InvalidArgumentException(
'ERROR: Query could not be parsed: "' . htmlspecialchars($parsedQuery) .
'". Query: "' . htmlspecialchars($query) .
'"', 1310027793);
2917 $ORIG_table = $parsedQuery[
'TABLE'];
2919 switch ($parsedQuery[
'type']) {
2930 case 'TRUNCATETABLE':
2933 case 'CREATEDATABASE':
2934 throw new \InvalidArgumentException(
'Creating a database with DBAL is not supported. Did you really read the manual?', 1310027716);
2937 throw new \InvalidArgumentException(
'ERROR: Invalid Query type (' . $parsedQuery[
'type'] .
') for ->admin_query() function!: "' . htmlspecialchars($query) .
'"', 1310027740);
2940 $this->lastParsedAndMappedQueryArray = $parsedQuery;
2944 switch ((
string)$this->handlerCfg[$this->lastHandlerKey][
'type']) {
2947 $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
2948 if (in_array($this->lastParsedAndMappedQueryArray[
'type'], array(
'INSERT',
'DROPTABLE',
'ALTERTABLE'))) {
2956 $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
2957 switch ($this->lastParsedAndMappedQueryArray[
'type']) {
2961 case 'TRUNCATETABLE':
2970 $compiledQuery = $this->SQLparser->compileSQL($this->lastParsedAndMappedQueryArray);
2993 if (!isset($this->cache_handlerKeyFromTableList[$key])) {
2995 $_tableList = $tableList;
2996 $tableArray = $this->SQLparser->parseFromTables($_tableList);
2998 if (is_array($tableArray) && count($tableArray)) {
2999 $outputHandlerKey =
'';
3000 foreach ($tableArray as $vArray) {
3002 $handlerKey = $this->table2handlerKeys[$vArray[
'table']] ? $this->table2handlerKeys[$vArray[
'table']] :
'_DEFAULT';
3004 if ($outputHandlerKey && $handlerKey != $outputHandlerKey) {
3005 throw new \RuntimeException(
'DBAL fatal error: Tables in this list "' . $tableList .
'" didn\'t use the same DB handler!', 1310027833);
3007 $outputHandlerKey = $handlerKey;
3010 if (!isset($this->handlerInstance[$outputHandlerKey])) {
3014 $this->cache_handlerKeyFromTableList[$key] = $outputHandlerKey;
3016 throw new \RuntimeException(
'DBAL fatal error: No handler found in handler_getFromTableList() for: "' . $tableList .
'" (' . $tableArray .
')', 1310027933);
3019 return $this->cache_handlerKeyFromTableList[$key];
3031 if (!isset($this->handlerCfg[$handlerKey]) || !is_array($this->handlerCfg[$handlerKey])) {
3032 throw new \RuntimeException(
'ERROR: No handler for key "' . $handlerKey .
'"', 1310028018);
3034 if ($handlerKey ===
'_DEFAULT') {
3039 $this->handlerCfg[$handlerKey][
'config'][
'port'] = (int)$this->databasePort;
3042 $cfgArray = $this->handlerCfg[$handlerKey];
3043 if (!$cfgArray[
'config'][
'database']) {
3049 switch ((
string)$cfgArray[
'type']) {
3051 $host = $cfgArray[
'config'][
'host'];
3052 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'no_pconnect']) {
3055 $link = mysqli_init();
3056 $connected =
$link->real_connect(
3058 $cfgArray[
'config'][
'username'],
3059 $cfgArray[
'config'][
'password'],
3060 $cfgArray[
'config'][
'database'],
3061 isset($cfgArray[
'config'][
'port']) ? $cfgArray[
'config'][
'port'] : null
3065 $this->handlerInstance[$handlerKey] = array(
'handlerType' =>
'native',
'link' =>
$link);
3067 if (
$link->set_charset($this->connectionCharset) === FALSE) {
3068 GeneralUtility::sysLog(
3069 'Error setting connection charset to "' . $this->connectionCharset .
'"',
3076 if ($handlerKey ===
'_DEFAULT') {
3077 $this->link =
$link;
3079 $this->lastHandlerKey = $handlerKey;
3080 foreach ($this->initializeCommandsAfterConnect as $command) {
3081 if ($this->
query($command) === FALSE) {
3082 GeneralUtility::sysLog(
3083 'Could not initialize DB connection with query "' . $command .
'": ' . $this->
sql_error(),
3097 GeneralUtility::sysLog(
'Could not connect to MySQL server ' . $cfgArray[
'config'][
'host'] .
' with user ' . $cfgArray[
'config'][
'username'] .
'.',
'Core', 4);
3102 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
'adodb') .
'adodb/adodb.inc.php';
3103 if (!defined(
'ADODB_FORCE_NULLS')) {
3104 define(
'ADODB_FORCE_NULLS', 1);
3106 $GLOBALS[
'ADODB_FORCE_TYPE'] = ADODB_FORCE_VALUE;
3107 $GLOBALS[
'ADODB_FETCH_MODE'] = ADODB_FETCH_BOTH;
3108 $this->handlerInstance[$handlerKey] = ADONewConnection($cfgArray[
'config'][
'driver']);
3110 if (isset($cfgArray[
'config'][
'driverOptions'])) {
3111 foreach ($cfgArray[
'config'][
'driverOptions'] as $optionName => $optionValue) {
3112 $optionSetterName =
'set' . ucfirst($optionName);
3113 if (method_exists($this->handlerInstance[$handlerKey], $optionSetterName)) {
3114 $this->handlerInstance[$handlerKey]->{$optionSetterName}($optionValue);
3116 $this->handlerInstance[$handlerKey]->{$optionName} = $optionValue;
3120 if (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'no_pconnect']) {
3121 $this->handlerInstance[$handlerKey]->Connect($cfgArray[
'config'][
'host'] . (isset($cfgArray[
'config'][
'port']) ?
':' . $cfgArray[
'config'][
'port'] :
''), $cfgArray[
'config'][
'username'], $cfgArray[
'config'][
'password'], $cfgArray[
'config'][
'database']);
3123 $this->handlerInstance[$handlerKey]->PConnect($cfgArray[
'config'][
'host'] . (isset($cfgArray[
'config'][
'port']) ?
':' . $cfgArray[
'config'][
'port'] :
''), $cfgArray[
'config'][
'username'], $cfgArray[
'config'][
'password'], $cfgArray[
'config'][
'database']);
3125 if (!$this->handlerInstance[$handlerKey]->
isConnected()) {
3126 $dsn = $cfgArray[
'config'][
'driver'] .
'://' . $cfgArray[
'config'][
'username'] . (strlen($cfgArray[
'config'][
'password']) ?
':XXXX@' :
'') . $cfgArray[
'config'][
'host'] . (isset($cfgArray[
'config'][
'port']) ?
':' . $cfgArray[
'config'][
'port'] :
'') .
'/' . $cfgArray[
'config'][
'database'] . (
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'no_pconnect'] ?
'' :
'?persistent=1');
3127 GeneralUtility::sysLog(
'Could not connect to DB server using ADOdb on ' . $cfgArray[
'config'][
'host'] .
' with user ' . $cfgArray[
'config'][
'username'] .
'.',
'Core', 4);
3128 error_log(
'DBAL error: Connection to ' . $dsn .
' failed. Maybe PHP doesn\'t support the database?');
3131 $this->handlerInstance[$handlerKey]->DataDictionary = NewDataDictionary($this->handlerInstance[$handlerKey]);
3132 $this->handlerInstance[$handlerKey]->last_insert_id = 0;
3133 if (isset($cfgArray[
'config'][
'sequenceStart'])) {
3134 $this->handlerInstance[$handlerKey]->sequenceStart = $cfgArray[
'config'][
'sequenceStart'];
3136 $this->handlerInstance[$handlerKey]->sequenceStart = 1;
3143 if (@is_file($fileName)) {
3144 require_once $fileName;
3146 throw new \RuntimeException(
'DBAL error: "' . $fileName .
'" was not a file to include.', 1310027975);
3150 $this->handlerInstance[$handlerKey]->init($cfgArray, $this);
3151 if (is_object($this->handlerInstance[$handlerKey])) {
3156 throw new \RuntimeException(
'ERROR: Invalid handler type: "' . $cfgArray[
'type'] .
'"', 1310027995);
3168 switch ((
string) $this->handlerCfg[$this->lastHandlerKey][
'type']) {
3170 $result = isset($this->handlerCfg[$this->lastHandlerKey][
'link']);
3197 return strpos($this->handlerCfg[$this->lastHandlerKey][
'config'][
'driver'],
$driver) !== FALSE;
3213 protected function map_needMapping($tableList, $fieldMappingOnly = FALSE, array &$parsedTableList = array()) {
3214 $key = $tableList .
'|' . $fieldMappingOnly;
3215 if (!isset($this->cache_mappingFromTableList[$key])) {
3216 $this->cache_mappingFromTableList[$key] = FALSE;
3218 $tables = $this->SQLparser->parseFromTables($tableList);
3219 if (is_array($tables)) {
3220 $parsedTableList = $tables;
3221 foreach ($tables as $tableCfg) {
3222 if ($fieldMappingOnly) {
3223 if (is_array($this->mapping[$tableCfg[
'table']][
'mapFieldNames'])) {
3224 $this->cache_mappingFromTableList[$key] = $tables;
3225 } elseif (is_array($tableCfg[
'JOIN'])) {
3226 foreach ($tableCfg[
'JOIN'] as $join) {
3227 if (is_array($this->mapping[$join[
'withTable']][
'mapFieldNames'])) {
3228 $this->cache_mappingFromTableList[$key] = $tables;
3234 if (is_array($this->mapping[$tableCfg[
'table']])) {
3235 $this->cache_mappingFromTableList[$key] = $tables;
3236 } elseif (is_array($tableCfg[
'JOIN'])) {
3237 foreach ($tableCfg[
'JOIN'] as $join) {
3238 if (is_array($this->mapping[$join[
'withTable']])) {
3239 $this->cache_mappingFromTableList[$key] = $tables;
3248 return $this->cache_mappingFromTableList[$key];
3264 foreach ($tables as $tableCfg) {
3266 if (is_array($this->mapping[$tableKey][
'mapFieldNames'])) {
3269 $theMap = array_flip($this->mapping[$tableKey][
'mapFieldNames']);
3271 $theMap = $this->mapping[$tableKey][
'mapFieldNames'];
3275 foreach ($input as $fN => $value) {
3278 $newKey = $theMap[$fN];
3283 $output[$newKey] = $value;
3308 $tables = is_array($from_table) ? $from_table : $this->SQLparser->parseFromTables($from_table);
3309 $defaultTable = $tables[0][
'table'];
3313 foreach ($tables as $k => $v) {
3314 if ($v[
'as'] && is_array($this->mapping[$v[
'table']][
'mapFieldNames'])) {
3316 $this->mapping[$mappingKey][
'mapFieldNames'] =& $this->mapping[$v[
'table']][
'mapFieldNames'];
3318 if (is_array($v[
'JOIN'])) {
3319 foreach ($v[
'JOIN'] as $joinCnt => $join) {
3320 if ($join[
'as'] && is_array($this->mapping[$join[
'withTable']][
'mapFieldNames'])) {
3322 $this->mapping[$mappingKey][
'mapFieldNames'] =& $this->mapping[$join[
'withTable']][
'mapFieldNames'];
3327 foreach ($tables as $k => $v) {
3329 if ($this->mapping[$tableKey][
'mapTableName']) {
3330 $tables[$k][
'table'] = $this->mapping[$tableKey][
'mapTableName'];
3333 if (is_array($v[
'JOIN'])) {
3334 foreach ($v[
'JOIN'] as $joinCnt => $join) {
3337 if ($this->mapping[$withTableKey][
'mapTableName']) {
3338 $tables[$k][
'JOIN'][$joinCnt][
'withTable'] = $this->mapping[$withTableKey][
'mapTableName'];
3340 $onPartsArray = array();
3342 if (is_array($tables[$k][
'JOIN'][$joinCnt][
'ON'])) {
3343 foreach ($tables[$k][
'JOIN'][$joinCnt][
'ON'] as &$condition) {
3345 $leftTableKey = $this->
getMappingKey($condition[
'left'][
'table']);
3346 if (isset($this->mapping[$leftTableKey][
'mapFieldNames'][$condition[
'left'][
'field']])) {
3347 $condition[
'left'][
'field'] = $this->mapping[$leftTableKey][
'mapFieldNames'][$condition[
'left'][
'field']];
3349 if (isset($this->mapping[$leftTableKey][
'mapTableName'])) {
3350 $condition[
'left'][
'table'] = $this->mapping[$leftTableKey][
'mapTableName'];
3353 $rightTableKey = $this->
getMappingKey($condition[
'right'][
'table']);
3354 if (isset($this->mapping[$rightTableKey][
'mapFieldNames'][$condition[
'right'][
'field']])) {
3355 $condition[
'right'][
'field'] = $this->mapping[$rightTableKey][
'mapFieldNames'][$condition[
'right'][
'field']];
3357 if (isset($this->mapping[$rightTableKey][
'mapTableName'])) {
3358 $condition[
'right'][
'table'] = $this->mapping[$rightTableKey][
'mapTableName'];
3365 $fromParts = $tables;
3367 $parameterReferences = array();
3368 $whereParts = $this->SQLparser->parseWhereClause($where_clause,
'', $parameterReferences);
3371 $selectParts = $this->SQLparser->parseFieldList($select_fields);
3374 $groupByParts = $this->SQLparser->parseFieldList($groupBy);
3377 $orderByParts = $this->SQLparser->parseFieldList($orderBy);
3380 $this->mapping = $backupMapping;
3381 return array($selectParts, $fromParts, $whereParts, $groupByParts, $orderByParts, $parameterReferences);
3393 while (isset($this->mapping[
'*' . $tableName])) {
3394 $tableName =
'*' . $tableName;
3406 while (isset($this->mapping[$tableName])) {
3407 $tableName =
'*' . $tableName;
3423 if (is_array($sqlPartArray)) {
3424 foreach ($sqlPartArray as $k => $v) {
3425 if (isset($sqlPartArray[$k][
'type'])) {
3426 switch ($sqlPartArray[$k][
'type']) {
3427 case 'flow-control':
3428 $temp = array($sqlPartArray[$k][
'flow-control']);
3431 $sqlPartArray[$k][
'flow-control'] = $temp[0];
3434 if (isset($sqlPartArray[$k][
'case_field'])) {
3435 $fieldArray = explode(
'.', $sqlPartArray[$k][
'case_field']);
3436 if (count($fieldArray) == 1 && is_array($this->mapping[$defaultTableKey][
'mapFieldNames']) && isset($this->mapping[$defaultTableKey][
'mapFieldNames'][$fieldArray[0]])) {
3437 $sqlPartArray[$k][
'case_field'] = $this->mapping[$defaultTableKey][
'mapFieldNames'][$fieldArray[0]];
3438 } elseif (count($fieldArray) == 2) {
3440 $table = $fieldArray[0];
3442 if (isset($this->mapping[$tableKey][
'mapTableName'])) {
3443 $table = $this->mapping[$tableKey][
'mapTableName'];
3446 $field = $fieldArray[1];
3447 if (is_array($this->mapping[$tableKey][
'mapFieldNames']) && isset($this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]])) {
3448 $field = $this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]];
3450 $sqlPartArray[$k][
'case_field'] = $table .
'.' . $field;
3453 foreach ($sqlPartArray[$k][
'when'] as $key => $when) {
3454 $this->
map_sqlParts($sqlPartArray[$k][
'when'][$key][
'when_value'], $defaultTable);
3460 if (is_array($sqlPartArray[$k][
'sub'])) {
3461 $this->
map_sqlParts($sqlPartArray[$k][
'sub'], $defaultTable);
3462 } elseif (isset($sqlPartArray[$k][
'func'])) {
3463 switch ($sqlPartArray[$k][
'func'][
'type']) {
3465 $this->
map_subquery($sqlPartArray[$k][
'func'][
'subquery']);
3473 $t = $sqlPartArray[$k][
'func'][
'table'] ? $sqlPartArray[$k][
'func'][
'table'] : $defaultTable;
3475 if (is_array($this->mapping[$t][
'mapFieldNames']) && $this->mapping[$t][
'mapFieldNames'][$sqlPartArray[$k][
'func'][
'field']]) {
3476 $sqlPartArray[$k][
'func'][
'field'] = $this->mapping[$t][
'mapFieldNames'][$sqlPartArray[$k][
'func'][
'field']];
3478 if ($this->mapping[$t][
'mapTableName']) {
3479 $sqlPartArray[$k][
'func'][
'table'] = $this->mapping[$t][
'mapTableName'];
3485 $t = $sqlPartArray[$k][
'table'] ? $sqlPartArray[$k][
'table'] : $defaultTable;
3488 if (is_array($this->mapping[$t][
'mapFieldNames']) && isset($this->mapping[$t][
'mapFieldNames'][$sqlPartArray[$k][
'field']])) {
3489 $sqlPartArray[$k][
'field'] = $this->mapping[$t][
'mapFieldNames'][$sqlPartArray[$k][
'field']];
3492 if ($this->mapping[$t][
'mapFieldNames']) {
3493 $fieldArray = explode(
'.', $sqlPartArray[$k][
'func_content']);
3494 if (count($fieldArray) == 1 && is_array($this->mapping[$t][
'mapFieldNames']) && isset($this->mapping[$t][
'mapFieldNames'][$fieldArray[0]])) {
3495 $sqlPartArray[$k][
'func_content.'][0][
'func_content'] = $this->mapping[$t][
'mapFieldNames'][$fieldArray[0]];
3496 $sqlPartArray[$k][
'func_content'] = $this->mapping[$t][
'mapFieldNames'][$fieldArray[0]];
3497 } elseif (count($fieldArray) == 2) {
3499 $table = $fieldArray[0];
3501 if (isset($this->mapping[$tableKey][
'mapTableName'])) {
3502 $table = $this->mapping[$tableKey][
'mapTableName'];
3505 $field = $fieldArray[1];
3506 if (is_array($this->mapping[$tableKey][
'mapFieldNames']) && isset($this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]])) {
3507 $field = $this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]];
3509 $sqlPartArray[$k][
'func_content.'][0][
'func_content'] = $table .
'.' . $field;
3510 $sqlPartArray[$k][
'func_content'] = $table .
'.' . $field;
3513 if (isset($sqlPartArray[$k][
'flow-control'])) {
3514 if (isset($sqlPartArray[$k][
'flow-control'][
'type'])) {
3515 $temp = array($sqlPartArray[$k][
'flow-control']);
3518 $sqlPartArray[$k][
'flow-control'] = $temp[0];
3523 if (isset($v[
'value'][
'operator'])) {
3524 foreach ($sqlPartArray[$k][
'value'][
'args'] as $argK => $fieldDef) {
3526 if (isset($this->mapping[$tableKey][
'mapTableName'])) {
3527 $sqlPartArray[$k][
'value'][
'args'][$argK][
'table'] = $this->mapping[$tableKey][
'mapTableName'];
3529 if (is_array($this->mapping[$tableKey][
'mapFieldNames']) && isset($this->mapping[$tableKey][
'mapFieldNames'][$fieldDef[
'field']])) {
3530 $sqlPartArray[$k][
'value'][
'args'][$argK][
'field'] = $this->mapping[$tableKey][
'mapFieldNames'][$fieldDef[
'field']];
3535 if (isset($sqlPartArray[$k][
'subquery'])) {
3540 if (!is_numeric($sqlPartArray[$k][
'value'][0]) && !isset($sqlPartArray[$k][
'value'][1])) {
3541 $fieldArray = explode(
'.', $sqlPartArray[$k][
'value'][0]);
3542 if (count($fieldArray) == 1 && is_array($this->mapping[$t][
'mapFieldNames']) && isset($this->mapping[$t][
'mapFieldNames'][$fieldArray[0]])) {
3543 $sqlPartArray[$k][
'value'][0] = $this->mapping[$t][
'mapFieldNames'][$fieldArray[0]];
3544 } elseif (count($fieldArray) == 2) {
3546 $table = $fieldArray[0];
3548 if (isset($this->mapping[$tableKey][
'mapTableName'])) {
3549 $table = $this->mapping[$tableKey][
'mapTableName'];
3552 $field = $fieldArray[1];
3553 if (is_array($this->mapping[$tableKey][
'mapFieldNames']) && isset($this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]])) {
3554 $field = $this->mapping[$tableKey][
'mapFieldNames'][$fieldArray[1]];
3556 $sqlPartArray[$k][
'value'][0] = $table .
'.' . $field;
3560 $tableKey = $this->
getMappingKey($sqlPartArray[$k][
'table']);
3561 if ($sqlPartArray[$k][
'table'] && $this->mapping[$tableKey][
'mapTableName']) {
3562 $sqlPartArray[$k][
'table'] = $this->mapping[$tableKey][
'mapTableName'];
3578 foreach ($parsedQuery[
'FROM'] as $k => $v) {
3579 $mappingKey = $v[
'table'];
3580 if ($v[
'as'] && is_array($this->mapping[$v[
'table']][
'mapFieldNames'])) {
3588 $this->mapping[$mappingKey][
'mapTableName'] =& $this->mapping[$v[
'table']][
'mapTableName'];
3591 if ($mappingKey !== $v[
'table']) {
3592 $this->mapping[$mappingKey][
'mapFieldNames'] =& $this->mapping[$v[
'table']][
'mapFieldNames'];
3596 $defaultTable = $parsedQuery[
'FROM'][0][
'table'];
3597 $this->
map_sqlParts($parsedQuery[
'SELECT'], $defaultTable);
3598 $this->
map_sqlParts($parsedQuery[
'FROM'], $defaultTable);
3599 $this->
map_sqlParts($parsedQuery[
'WHERE'], $defaultTable);
3601 $this->mapping = $backupMapping;
3615 $table = $parsedQuery[
'TABLE'];
3617 throw new \InvalidArgumentException(
'ERROR, mapping: No table found in parsed Query array...', 1310028048);
3622 if ($this->mapping[$table][
'mapTableName']) {
3623 $parsedQuery[
'TABLE'] = $this->mapping[$table][
'mapTableName'];
3626 switch ($parsedQuery[
'type']) {
3629 $newFieldName = $this->mapping[$table][
'mapFieldNames'][$parsedQuery[
'FIELD']];
3630 if ($newFieldName) {
3631 if ($parsedQuery[
'FIELD'] == $parsedQuery[
'newField']) {
3632 $parsedQuery[
'FIELD'] = ($parsedQuery[
'newField'] = $newFieldName);
3634 $parsedQuery[
'FIELD'] = $newFieldName;
3638 if (is_array($parsedQuery[
'fields'])) {
3644 if (is_array($parsedQuery[
'FIELDS'])) {
3645 $newFieldsArray = array();
3646 foreach ($parsedQuery[
'FIELDS'] as $fN => $fInfo) {
3647 if ($this->mapping[$table][
'mapFieldNames'][$fN]) {
3648 $fN = $this->mapping[$table][
'mapFieldNames'][$fN];
3650 $newFieldsArray[$fN] = $fInfo;
3652 $parsedQuery[
'FIELDS'] = $newFieldsArray;
3655 if (is_array($parsedQuery[
'KEYS'])) {
3656 foreach ($parsedQuery[
'KEYS'] as $kN => $kInfo) {
3673 if (is_array($this->mapping[$table][
'mapFieldNames'])) {
3674 foreach ($fieldArray as $k => $v) {
3675 if ($this->mapping[$table][
'mapFieldNames'][$v]) {
3676 $fieldArray[$k] = $this->mapping[$table][
'mapFieldNames'][$v];
3699 if (substr($script, -strlen(
'dbal/mod1/index.php')) !=
'dbal/mod1/index.php' && !strstr($inData[
'args'][0],
'tx_dbal_debuglog')) {
3708 if (empty($this->lastQuery)) {
3709 $query = implode(
' ', $inData[
'args']);
3713 if ($this->conf[
'debugOptions'][
'numberRows']) {
3714 switch ($function) {
3715 case 'exec_INSERTquery':
3717 case 'exec_UPDATEquery':
3719 case 'exec_DELETEquery':
3722 case 'exec_SELECTquery':
3723 $data[
'numberRows'] = $inData[
'numberRows'];
3727 if ($this->conf[
'debugOptions'][
'backtrace']) {
3728 $backtrace = debug_backtrace();
3729 unset($backtrace[0]);
3731 $data[
'backtrace'] = array_slice($backtrace, 0, $this->conf[
'debugOptions'][
'backtrace']);
3733 switch ($function) {
3734 case 'exec_INSERTquery':
3736 case 'exec_UPDATEquery':
3738 case 'exec_DELETEquery':
3739 $this->
debug_log($query, $execTime, $data, $joinTable, $errorFlag, $script);
3741 case 'exec_SELECTquery':
3743 if ($this->conf[
'debugOptions'][
'EXPLAIN'] &&
GeneralUtility::inList(
'adodb,native', $inData[
'handlerType'])) {
3747 if ($this->conf[
'debugOptions'][
'parseQuery']) {
3748 $parseResults = array();
3749 $parseResults[
'SELECT'] = $this->SQLparser->debug_parseSQLpart(
'SELECT', $inData[
'args'][1]);
3750 $parseResults[
'FROM'] = $this->SQLparser->debug_parseSQLpart(
'FROM', $inData[
'args'][0]);
3751 $parseResults[
'WHERE'] = $this->SQLparser->debug_parseSQLpart(
'WHERE', $inData[
'args'][2]);
3752 $parseResults[
'GROUPBY'] = $this->SQLparser->debug_parseSQLpart(
'SELECT', $inData[
'args'][3]);
3754 $parseResults[
'ORDERBY'] = $this->SQLparser->debug_parseSQLpart(
'SELECT', $inData[
'args'][4]);
3756 foreach ($parseResults as $k => $v) {
3757 if (!strlen($parseResults[$k])) {
3758 unset($parseResults[$k]);
3761 if (count($parseResults)) {
3762 $data[
'parseError'] = $parseResults;
3767 if ($this->conf[
'debugOptions'][
'joinTables']) {
3768 if (count(explode(
',', $inData[
'ORIG_from_table'])) > 1) {
3769 $joinTable = $inData[
'args'][0];
3773 $this->
debug_log($query, $execTime, $data, $joinTable, $errorFlag, $script);
3774 if (!empty($inData[
'args'][2])) {
3775 $this->
debug_WHERE($inData[
'args'][0], $inData[
'args'][2], $script);
3791 $insertArray = array(
3793 'beuser_id' => (
int)
$GLOBALS[
'BE_USER']->user[
'uid'],
3794 'script' => $script,
3795 'tablename' => $table,
3796 'whereclause' => $where
3812 public function debug_log($query, $ms, $data, $join, $errorFlag, $script =
'') {
3813 if (is_array($query)) {
3814 $queryToLog = $query[0] .
' -- ';
3815 if (count($query[1])) {
3816 $queryToLog .= count($query[1]) .
' BLOB FIELDS: ' . implode(
', ', array_keys($query[1]));
3818 if (count($query[2])) {
3819 $queryToLog .= count($query[2]) .
' CLOB FIELDS: ' . implode(
', ', array_keys($query[2]));
3822 $queryToLog = $query;
3824 $insertArray = array(
3826 'beuser_id' => (
int)
$GLOBALS[
'BE_USER']->user[
'uid'],
3827 'script' => $script,
3829 'table_join' => $join,
3830 'serdata' => serialize($data),
3831 'query' => $queryToLog,
3832 'errorFlag' => $errorFlag
3845 $hType = (string)$this->handlerCfg[$this->lastHandlerKey][
'type'];
3848 $res = $this->
sql_query(
'EXPLAIN ' . $query);
3854 switch ($this->handlerCfg[
'_DEFAULT'][
'config'][
'driver']) {
3856 $this->
sql_query(
'EXPLAIN PLAN ' . $query);
3857 $output[] =
'EXPLAIN PLAN data logged to default PLAN_TABLE';
3860 $res = $this->
sql_query(
'EXPLAIN ' . $query);
sql_field_metatype($table, $field)
map_fieldNamesInArray($table, &$fieldArray)
map_subquery(&$parsedQuery)
$resourceIdToTableNameMap
_quoteGroupBy(array $groupBy)
debug_WHERE($table, $where, $script='')
quoteFieldNames($select_fields)
quoteName($name, $handlerKey=NULL, $useBackticks=FALSE)
handler_getFromTableList($tableList)
static getCacheKey($config)
prepare_PREPAREDquery($query, array $queryComponents)
MetaType($type, $table, $maxLength=-1)
map_assocArray($input, $tables, $rev=FALSE)
debugHandler($function, $execTime, $inData)
sql_select_db($TYPO3_db=NULL)
exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields=FALSE)
handler_init($handlerKey)
const SYSLOG_SEVERITY_FATAL
static devLog($msg, $extKey, $severity=0, $dataVar=FALSE)
if(isset($_REQUEST['nrows'])) else $rs
map_needMapping($tableList, $fieldMappingOnly=FALSE, array &$parsedTableList=array())
fullQuoteStr($str, $table, $allowNull=FALSE)
_quoteFieldNames(array $select_fields)
getMappingKey($tableName)
exec_query(array $queryParts)
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
sql_pconnect($host=NULL, $username=NULL, $password=NULL)
precompileSELECTquery(array $components)
getCompleteFieldInformation()
INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields=FALSE)
getCacheableString(array $fieldInformation)
static makeInstance($className)
quoteFromTables($from_table)
admin_get_keys($tableName)
const SYSLOG_SEVERITY_ERROR
quoteWhereClause($where_clause)
runningADOdbDriver($driver)
debug_log($query, $ms, $data, $join, $errorFlag, $script='')
$cache_mappingFromTableList
_quoteWhereClause(array $where_clause)
getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit)
INSERTquery($table, $fields_values, $no_quote_fields=FALSE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren't numeric.
exec_INSERTquery($table, $fields_values, $no_quote_fields=FALSE)
exec_TRUNCATEquery($table)
exec_DELETEquery($table, $where)
handleDeprecatedConnectArguments($host=NULL, $username=NULL, $password=NULL, $db=NULL)
admin_get_fields($tableName)
getFreeMappingKey($tableName)
map_genericQueryParsed(&$parsedQuery)
map_remapSELECTQueryParts($select_fields, $from_table, $where_clause, $groupBy, $orderBy)
UPDATEquery($table, $where, $fields_values, $no_quote_fields=FALSE)
analyzeFields($parsedExtSQL)
sql_field_type($res, $pointer)
prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy='', $orderBy='', $limit='', array $input_parameters=array())
exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy='', $orderBy='', $limit='')
quoteSELECTsubquery(array $components)
connectDB($host=NULL, $username=NULL, $password=NULL, $db=NULL)
_quoteOrderBy(array $orderBy)
DELETEquery($table, $where)
SELECTquery($select_fields, $from_table, $where_clause, $groupBy='', $orderBy='', $limit='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields=FALSE)
determineHandlerType($res)
static inList($list, $item)
_quoteFromTables(array $from_table)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
escapeStrForLike($str, $table)
compileSelectParameters(array $params)
static stripPathSitePrefix($path)
sql_data_seek($res, $seek)
mapCachedFieldInfo(array $fieldInfo)
map_sqlParts(&$sqlPartArray, $defaultTable)
$lastParsedAndMappedQueryArray
SELECTqueryFromArray(array $params)
$cache_handlerKeyFromTableList