/typo3/sysext/dbal/class.ux_t3lib_db.php
PHP | 3891 lines | 2448 code | 380 blank | 1063 comment | 527 complexity | 76ddac9259d9bc49e86e428aa782a7c5 MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /***************************************************************
- * Copyright notice
- *
- * (c) 2004-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
- * (c) 2004-2009 Karsten Dambekalns <karsten@typo3.org>
- * (c) 2009-2010 Xavier Perseguers <typo3@perseguers.ch>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- * A copy is found in the textfile GPL.txt and important notices to the license
- * from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
- /**
- * Contains a database abstraction layer class for TYPO3
- *
- * $Id: class.ux_t3lib_db.php 42596 2011-01-25 20:02:07Z xperseguers $
- *
- * @author Kasper Skårhøj <kasper@typo3.com>
- * @author Karsten Dambekalns <k.dambekalns@fishfarm.de>
- * @author Xavier Perseguers <typo3@perseguers.ch>
- */
- /**
- * [CLASS/FUNCTION INDEX of SCRIPT]
- *
- *
- *
- * 161: class ux_t3lib_DB extends t3lib_DB
- * 229: public function __construct()
- * 260: protected function initInternalVariables()
- * 283: public function clearCachedFieldInfo()
- * 294: public function cacheFieldInfo()
- * 342: protected function analyzeFields($parsedExtSQL)
- * 375: protected function mapCachedFieldInfo($fieldInfo)
- *
- * SECTION: Query Building (Overriding parent methods)
- * 438: public function exec_INSERTquery($table, $fields_values, $no_quote_fields = '')
- * 575: public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE)
- * 600: public function exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields = '')
- * 692: public function exec_DELETEquery($table, $where)
- * 759: public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '')
- * 856: public function exec_TRUNCATEquery($table)
- * 914: protected function exec_query(array $queryParts)
- *
- * SECTION: Query building
- * 978: public function INSERTquery($table, $fields_values, $no_quote_fields = '')
- * 1052: public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE)
- * 1085: public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = '')
- * 1170: public function DELETEquery($table, $where)
- * 1196: public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '')
- * 1229: protected function SELECTqueryFromArray(array $params)
- * 1267: protected function compileSelectParameters(array $params)
- * 1283: public function TRUNCATEquery($table)
- *
- * SECTION: Prepared Query Support
- * 1314: public function prepare_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '', array $input_parameters = array())
- * 1416: protected function getQueryComponents($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit)
- * 1465: protected function precompileSELECTquery(array $components)
- * 1523: public function exec_PREPAREDquery($query, array $precompiledParts)
- *
- * SECTION: Functions for quoting table/field names
- * 1619: protected function quoteSELECTsubquery(array $components)
- * 1634: public function quoteSelectFields($select_fields)
- * 1644: public function quoteFieldNames($select_fields)
- * 1664: protected function _quoteFieldNames(array $select_fields)
- * 1701: public function quoteFromTables($from_table)
- * 1717: protected function _quoteFromTables(array $from_table)
- * 1746: public function quoteWhereClause($where_clause)
- * 1767: protected function _quoteWhereClause(array $where_clause)
- * 1843: protected function quoteGroupBy($groupBy)
- * 1860: protected function _quoteGroupBy(array $groupBy)
- * 1877: protected function quoteOrderBy($orderBy)
- * 1894: protected function _quoteOrderBy(array $orderBy)
- *
- * SECTION: Various helper functions
- * 1919: public function fullQuoteStr($str, $table)
- * 1932: public function quoteStr($str, $table)
- * 1965: public function quoteName($name, $handlerKey = NULL, $useBackticks = FALSE)
- * 1984: public function MetaType($type, $table, $max_length = -1)
- * 2015: public function MySQLMetaType($t)
- * 2062: public function MySQLActualType($meta)
- *
- * SECTION: SQL wrapper functions (Overriding parent methods)
- * 2105: public function sql_error()
- * 2125: public function sql_errno()
- * 2146: public function sql_num_rows(&$res)
- * 2170: public function sql_fetch_assoc(&$res)
- * 2233: public function sql_fetch_row(&$res)
- * 2279: public function sql_free_result(&$res)
- * 2308: public function sql_insert_id()
- * 2328: public function sql_affected_rows()
- * 2350: public function sql_data_seek(&$res, $seek)
- * 2375: public function sql_field_metatype($table, $field)
- * 2405: public function sql_field_type(&$res,$pointer)
- *
- * SECTION: Legacy functions, bound to _DEFAULT handler. (Overriding parent methods)
- * 2459: public function sql($db,$query)
- * 2477: public function sql_query($query)
- * 2516: public function sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password)
- * 2534: public function sql_select_db($TYPO3_db)
- *
- * SECTION: SQL admin functions
- * 2566: public function admin_get_dbs()
- * 2607: public function admin_get_tables()
- * 2673: public function admin_get_fields($tableName)
- * 2742: public function admin_get_keys($tableName)
- * 2847: public function admin_get_charsets()
- * 2857: public function admin_query($query)
- *
- * SECTION: Handler management
- * 2941: public function handler_getFromTableList($tableList)
- * 2989: public function handler_init($handlerKey)
- * 3107: public function isConnected()
- * 3127: public function runningNative()
- * 3138: public function runningADOdbDriver($driver)
- *
- * SECTION: Table/Field mapping
- * 3165: protected function map_needMapping($tableList, $fieldMappingOnly = FALSE, array &$parsedTableList = array())
- * 3215: protected function map_assocArray($input, $tables, $rev = FALSE)
- * 3263: protected function map_remapSELECTQueryParts($select_fields, $from_table, $where_clause, $groupBy, $orderBy)
- * 3357: protected function getMappingKey($tableName)
- * 3371: protected function getFreeMappingKey($tableName)
- * 3387: protected function map_sqlParts(&$sqlPartArray, $defaultTable)
- * 3549: protected function map_subquery(&$parsedQuery)
- * 3589: protected function map_genericQueryParsed(&$parsedQuery)
- * 3654: protected function map_fieldNamesInArray($table,&$fieldArray)
- *
- * SECTION: Debugging
- * 3695: public function debugHandler($function,$execTime,$inData)
- * 3790: public function debug_WHERE($table, $where, $script = '')
- * 3813: public function debug_log($query,$ms,$data,$join,$errorFlag, $script='')
- * 3846: public function debug_explain($query)
- *
- * TOTAL FUNCTIONS: 82
- * (This index is automatically created/updated by the extension "extdeveval")
- *
- */
- /**
- * TYPO3 database abstraction layer
- *
- * @author Kasper Skårhøj <kasper@typo3.com>
- * @author Karsten Dambekalns <k.dambekalns@fishfarm.de>
- * @package TYPO3
- * @subpackage tx_dbal
- */
- class ux_t3lib_DB extends t3lib_DB {
- // Internal, static:
- var $printErrors = FALSE; // Enable output of SQL errors after query executions. Set through TYPO3_CONF_VARS, see init()
- var $debug = FALSE; // Enable debug mode. Set through TYPO3_CONF_VARS, see init()
- var $conf = array(); // Configuration array, copied from TYPO3_CONF_VARS in constructor.
- var $mapping = array(); // See manual.
- var $table2handlerKeys = array(); // See manual.
- var $handlerCfg = array( // See manual.
- '_DEFAULT' => array(
- 'type' => 'native',
- 'config' => array(
- 'username' => '', // Set by default (overridden)
- 'password' => '', // Set by default (overridden)
- 'host' => '', // Set by default (overridden)
- 'database' => '', // Set by default (overridden)
- 'driver' => '', // ONLY "adodb" type; eg. "mysql"
- 'sequenceStart' => 1, // ONLY "adodb", first number in sequences/serials/...
- 'useNameQuote' => 0 // ONLY "adodb", whether to use NameQuote() method from ADOdb to quote names
- )
- ),
- );
- // Internal, dynamic:
- var $handlerInstance = array(); // Contains instance of the handler objects as they are created. Exception is the native mySQL calls which are registered as an array with keys "handlerType" = "native" and "link" pointing to the link resource for the connection.
- var $lastHandlerKey = ''; // Storage of the handler key of last ( SELECT) query - used for subsequent fetch-row calls etc.
- var $lastQuery = ''; // Storage of last SELECT query
- var $lastParsedAndMappedQueryArray = array(); // Query array, the last one parsed
- var $resourceIdToTableNameMap = array(); // Mapping of resource ids to table names.
- // Internal, caching:
- var $cache_handlerKeyFromTableList = array(); // Caching handlerKeys for table lists
- var $cache_mappingFromTableList = array(); // Caching mapping information for table lists
- var $cache_autoIncFields = array(); // parsed SQL from standard DB dump file
- var $cache_fieldType = array(); // field types for tables/fields
- var $cache_primaryKeys = array(); // primary keys
- /**
- * SQL parser
- *
- * @var tx_dbal_sqlengine
- */
- var $SQLparser;
- /**
- * Installer
- *
- * @var t3lib_install
- */
- var $Installer;
- /**
- * Cache for queries
- *
- * @var t3lib_cache_frontend_VariableFrontend
- */
- protected $queryCache;
- /**
- * Constructor.
- * Creates SQL parser object and imports configuration from $TYPO3_CONF_VARS['EXTCONF']['dbal']
- */
- public function __construct() {
- // Set SQL parser object for internal use:
- $this->SQLparser = t3lib_div::makeInstance('tx_dbal_sqlengine');
- $this->Installer = t3lib_div::makeInstance('t3lib_install');
- if (TYPO3_UseCachingFramework) {
- tx_dbal_querycache::initializeCachingFramework();
- try {
- $this->queryCache = $GLOBALS['typo3CacheManager']->getCache(
- 'dbal'
- );
- } catch (t3lib_cache_exception_NoSuchCache $e) {
- tx_dbal_querycache::initDbalCache();
- $this->queryCache = $GLOBALS['typo3CacheManager']->getCache(
- 'dbal'
- );
- }
- }
- // Set internal variables with configuration:
- $this->conf = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal'];
- $this->initInternalVariables();
- }
- /**
- * Setting internal variables from $this->conf.
- *
- * @return void
- */
- protected function initInternalVariables() {
- // Set outside configuration:
- if (isset($this->conf['mapping'])) {
- $this->mapping = $this->conf['mapping'];
- }
- if (isset($this->conf['table2handlerKeys'])) {
- $this->table2handlerKeys = $this->conf['table2handlerKeys'];
- }
- if (isset($this->conf['handlerCfg'])) {
- $this->handlerCfg = $this->conf['handlerCfg'];
- }
- $this->cacheFieldInfo();
- // Debugging settings:
- $this->printErrors = $this->conf['debugOptions']['printErrors'] ? TRUE : FALSE;
- $this->debug = $this->conf['debugOptions']['enabled'] ? TRUE : FALSE;
- }
- /**
- * Clears the cached field information file.
- *
- * @return void
- */
- public function clearCachedFieldInfo() {
- if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
- unlink(PATH_typo3conf . 'temp_fieldInfo.php');
- }
- }
- /**
- * Caches the field information.
- *
- * @return void
- */
- public function cacheFieldInfo() {
- $extSQL = '';
- $parsedExtSQL = array();
- // try to fetch cached file first
- // file is removed when admin_query() is called
- if (file_exists(PATH_typo3conf . 'temp_fieldInfo.php')) {
- $fdata = unserialize(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'));
- $this->cache_autoIncFields = $fdata['incFields'];
- $this->cache_fieldType = $fdata['fieldTypes'];
- $this->cache_primaryKeys = $fdata['primaryKeys'];
- } else {
- // handle stddb.sql, parse and analyze
- $extSQL = t3lib_div::getUrl(PATH_site . 't3lib/stddb/tables.sql');
- $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
- $this->analyzeFields($parsedExtSQL);
- // loop over all installed extensions
- foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $ext => $v) {
- if (!is_array($v) || !isset($v['ext_tables.sql'])) {
- continue;
- }
- // fetch db dump (if any) and parse it, then analyze
- $extSQL = t3lib_div::getUrl($v['ext_tables.sql']);
- $parsedExtSQL = $this->Installer->getFieldDefinitions_fileContent($extSQL);
- $this->analyzeFields($parsedExtSQL);
- }
- $cachedFieldInfo = array('incFields' => $this->cache_autoIncFields, 'fieldTypes' => $this->cache_fieldType, 'primaryKeys' => $this->cache_primaryKeys);
- $cachedFieldInfo = serialize($this->mapCachedFieldInfo($cachedFieldInfo));
- // write serialized content to file
- t3lib_div::writeFile(PATH_typo3conf . 'temp_fieldInfo.php', $cachedFieldInfo);
- if (strcmp(t3lib_div::getUrl(PATH_typo3conf . 'temp_fieldInfo.php'), $cachedFieldInfo)) {
- die('typo3conf/temp_fieldInfo.php was NOT updated properly (written content didn\'t match file content) - maybe write access problem?');
- }
- }
- }
- /**
- * Analyzes fields and adds the extracted information to the field type, auto increment and primary key info caches.
- *
- * @param array $parsedExtSQL The output produced by t3lib_install::getFieldDefinitions_fileContent()
- * @return void
- * @see t3lib_install::getFieldDefinitions_fileContent()
- */
- protected function analyzeFields($parsedExtSQL) {
- foreach ($parsedExtSQL as $table => $tdef) {
- if (is_array($tdef['fields'])) {
- foreach ($tdef['fields'] as $field => $fdef) {
- $fdef = $this->SQLparser->parseFieldDef($fdef);
- $this->cache_fieldType[$table][$field]['type'] = $fdef['fieldType'];
- $this->cache_fieldType[$table][$field]['metaType'] = $this->MySQLMetaType($fdef['fieldType']);
- $this->cache_fieldType[$table][$field]['notnull'] = (isset($fdef['featureIndex']['NOTNULL']) && !$this->SQLparser->checkEmptyDefaultValue($fdef['featureIndex'])) ? 1 : 0;
- if (isset($fdef['featureIndex']['DEFAULT'])) {
- $default = $fdef['featureIndex']['DEFAULT']['value'][0];
- if (isset($fdef['featureIndex']['DEFAULT']['value'][1])) {
- $default = $fdef['featureIndex']['DEFAULT']['value'][1] . $default . $fdef['featureIndex']['DEFAULT']['value'][1];
- }
- $this->cache_fieldType[$table][$field]['default'] = $default;
- }
- if (isset($fdef['featureIndex']['AUTO_INCREMENT'])) {
- $this->cache_autoIncFields[$table] = $field;
- }
- if (isset($tdef['keys']['PRIMARY'])) {
- $this->cache_primaryKeys[$table] = substr($tdef['keys']['PRIMARY'], 13, -1);
- }
- }
- }
- }
- }
- /**
- * This function builds all definitions for mapped tables and fields
- * @see cacheFieldInfo()
- */
- protected function mapCachedFieldInfo($fieldInfo) {
- if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'])) {
- foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['mapping'] as $mappedTable => $mappedConf) {
- if (array_key_exists($mappedTable, $fieldInfo['incFields'])) {
- $mappedTableAlias = $mappedConf['mapTableName'];
- if (isset($mappedConf['mapFieldNames'][$fieldInfo['incFields'][$mappedTable]])) {
- $fieldInfo['incFields'][$mappedTableAlias] = $mappedConf['mapFieldNames'][$fieldInfo['incFields'][$mappedTable]];
- } else {
- $fieldInfo['incFields'][$mappedTableAlias] = $fieldInfo['incFields'][$mappedTable];
- }
- }
- if (array_key_exists($mappedTable, $fieldInfo['fieldTypes'])) {
- foreach ($fieldInfo['fieldTypes'][$mappedTable] as $field => $fieldConf) {
- $tempMappedFieldConf[$mappedConf['mapFieldNames'][$field]] = $fieldConf;
- }
- $fieldInfo['fieldTypes'][$mappedConf['mapTableName']] = $tempMappedFieldConf;
- }
- if (array_key_exists($mappedTable, $fieldInfo['primaryKeys'])) {
- $mappedTableAlias = $mappedConf['mapTableName'];
- if (isset($mappedConf['mapFieldNames'][$fieldInfo['primaryKeys'][$mappedTable]])) {
- $fieldInfo['primaryKeys'][$mappedTableAlias] = $mappedConf['mapFieldNames'][$fieldInfo['primaryKeys'][$mappedTable]];
- } else {
- $fieldInfo['primaryKeys'][$mappedTableAlias] = $fieldInfo['primaryKeys'][$mappedTable];
- }
- }
- }
- }
- return $fieldInfo;
- }
- /************************************
- *
- * Query Building (Overriding parent methods)
- * These functions are extending counterparts in the parent class.
- *
- **************************************/
- /* From the ADOdb documentation, this is what we do (_Execute for SELECT, _query for the other actions)
- Execute() is the default way to run queries. You can use the low-level functions _Execute() and _query() to reduce query overhead.
- Both these functions share the same parameters as Execute().
- If you do not have any bind parameters or your database supports binding (without emulation), then you can call _Execute() directly.
- Calling this function bypasses bind emulation. Debugging is still supported in _Execute().
- If you do not require debugging facilities nor emulated binding, and do not require a recordset to be returned, then you can call _query.
- This is great for inserts, updates and deletes. Calling this function bypasses emulated binding, debugging, and recordset handling. Either
- the resultid, TRUE or FALSE are returned by _query().
- */
- /**
- * Inserts a record for $table from the array with field/value pairs $fields_values.
- *
- * @param string Table name
- * @param array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$insertFields" with 'fieldname'=>'value' and pass it to this function as argument.
- * @param mixed List/array of keys NOT to quote (eg. SQL functions)
- * @return mixed Result from handler, usually TRUE when success and FALSE on failure
- */
- public function exec_INSERTquery($table, $fields_values, $no_quote_fields = '') {
- if ($this->debug) {
- $pt = t3lib_div::milliseconds();
- }
- // Do field mapping if needed:
- $ORIG_tableName = $table;
- if ($tableArray = $this->map_needMapping($table)) {
- // Field mapping of array:
- $fields_values = $this->map_assocArray($fields_values, $tableArray);
- // Table name:
- if ($this->mapping[$table]['mapTableName']) {
- $table = $this->mapping[$table]['mapTableName'];
- }
- }
- // Select API:
- $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- switch ($hType) {
- case 'native':
- $this->lastQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields);
- if (is_string($this->lastQuery)) {
- $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
- } else {
- $sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']);
- $new_id = $this->sql_insert_id();
- $where = $this->cache_autoIncFields[$table] . '=' . $new_id;
- foreach ($this->lastQuery[1] as $field => $content) {
- mysql_query('UPDATE ' . $this->quoteFromTables($table) . ' SET ' . $this->quoteFromTables($field) . '=' . $this->fullQuoteStr($content, $table) . ' WHERE ' . $this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']);
- }
- }
- break;
- case 'adodb':
- // auto generate ID for auto_increment fields if not present (static import needs this!)
- // should we check the table name here (static_*)?
- if (isset($this->cache_autoIncFields[$table])) {
- if (isset($fields_values[$this->cache_autoIncFields[$table]])) {
- $new_id = $fields_values[$this->cache_autoIncFields[$table]];
- if ($table != 'tx_dbal_debuglog') {
- $this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id;
- }
- } else {
- $new_id = $this->handlerInstance[$this->lastHandlerKey]->GenID($table . '_' . $this->cache_autoIncFields[$table], $this->handlerInstance[$this->lastHandlerKey]->sequenceStart);
- $fields_values[$this->cache_autoIncFields[$table]] = $new_id;
- if ($table != 'tx_dbal_debuglog') {
- $this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id;
- }
- }
- }
- $this->lastQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields);
- if (is_string($this->lastQuery)) {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE);
- } else {
- $this->handlerInstance[$this->lastHandlerKey]->StartTrans();
- if (strlen($this->lastQuery[0])) {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0], FALSE);
- }
- if (is_array($this->lastQuery[1])) {
- foreach ($this->lastQuery[1] as $field => $content) {
- if (empty($content)) continue;
- if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) {
- $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($this->cache_autoIncFields[$table] . '=' . $new_id));
- } elseif (isset($this->cache_primaryKeys[$table])) {
- $where = '';
- $pks = explode(',', $this->cache_primaryKeys[$table]);
- foreach ($pks as $pk) {
- if (isset($fields_values[$pk]))
- $where .= $pk . '=' . $this->fullQuoteStr($fields_values[$pk], $table) . ' AND ';
- }
- $where = $this->quoteWhereClause($where . '1=1');
- $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $where);
- } else {
- $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(FALSE);
- die('Could not update BLOB >>>> no WHERE clause found!'); // should never ever happen
- }
- }
- }
- if (is_array($this->lastQuery[2])) {
- foreach ($this->lastQuery[2] as $field => $content) {
- if (empty($content)) continue;
- if (isset($this->cache_autoIncFields[$table]) && isset($new_id)) {
- $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($this->cache_autoIncFields[$table] . '=' . $new_id));
- } elseif (isset($this->cache_primaryKeys[$table])) {
- $where = '';
- $pks = explode(',', $this->cache_primaryKeys[$table]);
- foreach ($pks as $pk) {
- if (isset($fields_values[$pk]))
- $where .= $pk . '=' . $this->fullQuoteStr($fields_values[$pk], $table) . ' AND ';
- }
- $where = $this->quoteWhereClause($where . '1=1');
- $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $where);
- } else {
- $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(FALSE);
- die('Could not update CLOB >>>> no WHERE clause found!'); // should never ever happen
- }
- }
- }
- $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans();
- }
- break;
- case 'userdefined':
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_INSERTquery($table, $fields_values, $no_quote_fields);
- break;
- }
- if ($this->printErrors && $this->sql_error()) {
- debug(array($this->lastQuery, $this->sql_error()));
- }
- if ($this->debug) {
- $this->debugHandler(
- 'exec_INSERTquery',
- t3lib_div::milliseconds() - $pt,
- array(
- 'handlerType' => $hType,
- 'args' => array($table, $fields_values),
- 'ORIG_tablename' => $ORIG_tableName
- )
- );
- }
- // Return output:
- return $sqlResult;
- }
- /**
- * Creates and executes an INSERT SQL-statement for $table with multiple rows.
- * This method uses exec_INSERTquery() and is just a syntax wrapper to it.
- *
- * @param string Table name
- * @param array Field names
- * @param array Table rows. Each row should be an array with field values mapping to $fields
- * @param string/array See fullQuoteArray()
- * @return mixed Result from last handler, usually TRUE when success and FALSE on failure
- */
- public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) {
- if ((string) $this->handlerCfg[$this->lastHandlerKey]['type'] === 'native') {
- return parent::exec_INSERTmultipleRows($table, $fields, $rows, $no_quote_fields);
- }
- foreach ($rows as $row) {
- $fields_values = array();
- foreach ($fields as $key => $value) {
- $fields_values[$value] = $row[$key];
- }
- $res = $this->exec_INSERTquery($table, $fields_values, $no_quote_fields);
- }
- return $res;
- }
- /**
- * Updates a record from $table
- *
- * @param string Database tablename
- * @param string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
- * @param array Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$updateFields" with 'fieldname'=>'value' and pass it to this function as argument.
- * @param mixed List/array of keys NOT to quote (eg. SQL functions)
- * @return mixed Result from handler, usually TRUE when success and FALSE on failure
- */
- public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = '') {
- if ($this->debug) {
- $pt = t3lib_div::milliseconds();
- }
- // Do table/field mapping:
- $ORIG_tableName = $table;
- if ($tableArray = $this->map_needMapping($table)) {
- // Field mapping of array:
- $fields_values = $this->map_assocArray($fields_values, $tableArray);
- // Where clause table and field mapping:
- $whereParts = $this->SQLparser->parseWhereClause($where);
- $this->map_sqlParts($whereParts, $tableArray[0]['table']);
- $where = $this->SQLparser->compileWhereClause($whereParts, FALSE);
- // Table name:
- if ($this->mapping[$table]['mapTableName']) {
- $table = $this->mapping[$table]['mapTableName'];
- }
- }
- // Select API
- $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- switch ($hType) {
- case 'native':
- $this->lastQuery = $this->UPDATEquery($table, $where, $fields_values, $no_quote_fields);
- if (is_string($this->lastQuery)) {
- $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
- }
- else {
- $sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']);
- foreach ($this->lastQuery[1] as $field => $content) {
- mysql_query('UPDATE ' . $this->quoteFromTables($table) . ' SET ' . $this->quoteFromTables($field) . '=' . $this->fullQuoteStr($content, $table) . ' WHERE ' . $this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']);
- }
- }
- break;
- case 'adodb':
- $this->lastQuery = $this->UPDATEquery($table, $where, $fields_values, $no_quote_fields);
- if (is_string($this->lastQuery)) {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE);
- } else {
- $this->handlerInstance[$this->lastHandlerKey]->StartTrans();
- if (strlen($this->lastQuery[0])) {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0], FALSE);
- }
- if (is_array($this->lastQuery[1])) {
- foreach ($this->lastQuery[1] as $field => $content) {
- $this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($where));
- }
- }
- if (is_array($this->lastQuery[2])) {
- foreach ($this->lastQuery[2] as $field => $content) {
- $this->handlerInstance[$this->lastHandlerKey]->UpdateClob($this->quoteFromTables($table), $field, $content, $this->quoteWhereClause($where));
- }
- }
- $this->handlerInstance[$this->lastHandlerKey]->CompleteTrans();
- }
- break;
- case 'userdefined':
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields);
- break;
- }
- if ($this->printErrors && $this->sql_error()) {
- debug(array($this->lastQuery, $this->sql_error()));
- }
- if ($this->debug) {
- $this->debugHandler(
- 'exec_UPDATEquery',
- t3lib_div::milliseconds() - $pt,
- array(
- 'handlerType' => $hType,
- 'args' => array($table, $where, $fields_values),
- 'ORIG_from_table' => $ORIG_tableName
- )
- );
- }
- // Return result:
- return $sqlResult;
- }
- /**
- * Deletes records from table
- *
- * @param string Database tablename
- * @param string WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
- * @return mixed Result from handler
- */
- public function exec_DELETEquery($table, $where) {
- if ($this->debug) {
- $pt = t3lib_div::milliseconds();
- }
- // Do table/field mapping:
- $ORIG_tableName = $table;
- if ($tableArray = $this->map_needMapping($table)) {
- // Where clause:
- $whereParts = $this->SQLparser->parseWhereClause($where);
- $this->map_sqlParts($whereParts, $tableArray[0]['table']);
- $where = $this->SQLparser->compileWhereClause($whereParts, FALSE);
- // Table name:
- if ($this->mapping[$table]['mapTableName']) {
- $table = $this->mapping[$table]['mapTableName'];
- }
- }
- // Select API
- $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- switch ($hType) {
- case 'native':
- $this->lastQuery = $this->DELETEquery($table, $where);
- $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
- break;
- case 'adodb':
- $this->lastQuery = $this->DELETEquery($table, $where);
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE);
- break;
- case 'userdefined':
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_DELETEquery($table, $where);
- break;
- }
- if ($this->printErrors && $this->sql_error()) {
- debug(array($this->lastQuery, $this->sql_error()));
- }
- if ($this->debug) {
- $this->debugHandler(
- 'exec_DELETEquery',
- t3lib_div::milliseconds() - $pt,
- array(
- 'handlerType' => $hType,
- 'args' => array($table, $where),
- 'ORIG_from_table' => $ORIG_tableName
- )
- );
- }
- // Return result:
- return $sqlResult;
- }
- /**
- * Selects records from Data Source
- *
- * @param string $select_fields List of fields to select from the table. This is what comes right after "SELECT ...". Required value.
- * @param string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value.
- * @param string $where_clause Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQquoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
- * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string.
- * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string.
- * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
- * @return mixed Result from handler. Typically object from DBAL layers.
- */
- public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') {
- if ($this->debug) {
- $pt = t3lib_div::milliseconds();
- }
- // Map table / field names if needed:
- $ORIG_tableName = $from_table; // Saving table names in $ORIG_from_table since $from_table is transformed beneath:
- $parsedFromTable = array();
- $remappedParameters = array();
- if ($tableArray = $this->map_needMapping($ORIG_tableName, FALSE, $parsedFromTable)) {
- $from = $parsedFromTable ? $parsedFromTable : $from_table;
- $remappedParameters = $this->map_remapSELECTQueryParts($select_fields, $from, $where_clause, $groupBy, $orderBy);
- }
- // Get handler key and select API:
- $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- switch ($hType) {
- case 'native':
- if (count($remappedParameters) > 0) {
- list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters);
- }
- $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
- $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
- $this->resourceIdToTableNameMap[(string) $sqlResult] = $ORIG_tableName;
- break;
- case 'adodb':
- if ($limit != '') {
- $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values:
- if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise:
- $numrows = $splitLimit[1];
- $offset = $splitLimit[0];
- } else {
- $numrows = $splitLimit[0];
- $offset = 0;
- }
- if (count($remappedParameters) > 0) {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTqueryFromArray($remappedParameters), $numrows, $offset);
- } else {
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy), $numrows, $offset);
- }
- $this->lastQuery = $sqlResult->sql;
- } else {
- if (count($remappedParameters) > 0) {
- $this->lastQuery = $this->SELECTqueryFromArray($remappedParameters);
- } else {
- $this->lastQuery = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy);
- }
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_Execute($this->lastQuery);
- }
- $sqlResult->TYPO3_DBAL_handlerType = 'adodb'; // Setting handler type in result object (for later recognition!)
- $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
- break;
- case 'userdefined':
- if (count($remappedParameters) > 0) {
- list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSelectParameters($remappedParameters);
- }
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
- if (is_object($sqlResult)) {
- $sqlResult->TYPO3_DBAL_handlerType = 'userdefined'; // Setting handler type in result object (for later recognition!)
- $sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;
- }
- break;
- }
- if ($this->printErrors && $this->sql_error()) {
- debug(array($this->lastQuery, $this->sql_error()));
- }
- if ($this->debug) {
- $data = array(
- 'handlerType' => $hType,
- 'args' => array($from_table, $select_fields, $where_clause, $groupBy, $orderBy, $limit),
- 'ORIG_from_table' => $ORIG_tableName,
- );
- if ($this->conf['debugOptions']['numberRows']) {
- $data['numberRows'] = $this->sql_num_rows($sqlResult);
- }
- $this->debugHandler(
- 'exec_SELECTquery',
- t3lib_div::milliseconds() - $pt,
- $data
- );
- }
- // Return result handler.
- return $sqlResult;
- }
- /**
- * Truncates a table.
- *
- * @param string Database tablename
- * @return mixed Result from handler
- */
- public function exec_TRUNCATEquery($table) {
- if ($this->debug) {
- $pt = t3lib_div::milliseconds();
- }
- // Do table/field mapping:
- $ORIG_tableName = $table;
- if ($tableArray = $this->map_needMapping($table)) {
- // Table name:
- if ($this->mapping[$table]['mapTableName']) {
- $table = $this->mapping[$table]['mapTableName'];
- }
- }
- // Select API
- $this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- switch ($hType) {
- case 'native':
- $this->lastQuery = $this->TRUNCATEquery($table);
- $sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);
- break;
- case 'adodb':
- $this->lastQuery = $this->TRUNCATEquery($table);
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery, FALSE);
- break;
- case 'userdefined':
- $sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_TRUNCATEquery($table);
- break;
- }
- if ($this->printErrors && $this->sql_error()) {
- debug(array($this->lastQuery, $this->sql_error()));
- }
- if ($this->debug) {
- $this->debugHandler(
- 'exec_TRUNCATEquery',
- t3lib_div::milliseconds() - $pt,
- array(
- 'handlerType' => $hType,
- 'args' => array($table),
- 'ORIG_from_table' => $ORIG_tableName
- )
- );
- }
- // Return result:
- return $sqlResult;
- }
- /**
- * Executes a query.
- * EXPERIMENTAL since TYPO3 4.4.
- *
- * @param array $queryParts SQL parsed by method parseSQL() of t3lib_sqlparser
- * @return pointer Result pointer / DBAL object
- * @see ux_t3lib_db::sql_query()
- */
- protected function exec_query(array $queryParts) {
- switch ($queryParts['type']) {
- case 'SELECT':
- $selectFields = $this->SQLparser->compileFieldList($queryParts['SELECT']);
- $fromTables = $this->SQLparser->compileFromTables($queryParts['FROM']);
- $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1';
- $groupBy = isset($queryParts['GROUPBY']) ? $this->SQLparser->compileFieldList($queryParts['GROUPBY']) : '';
- $orderBy = isset($queryParts['ORDERBY']) ? $this->SQLparser->compileFieldList($queryParts['ORDERBY']) : '';
- $limit = isset($queryParts['LIMIT']) ? $this->SQLparser->compileWhereClause($queryParts['LIMIT']) : '';
- return $this->exec_SELECTquery($selectFields, $fromTables, $whereClause, $groupBy, $orderBy, $limit);
- case 'UPDATE':
- $table = $queryParts['TABLE'];
- $fields = array();
- foreach ($queryParts['FIELDS'] as $fN => $fV) {
- $fields[$fN] = $fV[0];
- }
- $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1';
- return $this->exec_UPDATEquery($table, $whereClause, $fields);
- case 'INSERT':
- $table = $queryParts['TABLE'];
- $values = array();
- if (isset($queryParts['VALUES_ONLY']) && is_array($queryParts['VALUES_ONLY'])) {
- $fields = $GLOBALS['TYPO3_DB']->cache_fieldType[$table];
- $fc = 0;
- foreach ($fields as $fn => $fd) {
- $values[$fn] = $queryParts['VALUES_ONLY'][$fc++][0];
- }
- } else {
- foreach ($queryParts['FIELDS'] as $fN => $fV) {
- $values[$fN] = $fV[0];
- }
- }
- return $this->exec_INSERTquery($table, $values);
- case 'DELETE':
- $table = $queryParts['TABLE'];
- $whereClause = isset($queryParts['WHERE']) ? $this->SQLparser->compileWhereClause($queryParts['WHERE']) : '1=1';
- return $this->exec_DELETEquery($table, $whereClause);
- case 'TRUNCATETABLE':
- $table = $queryParts['TABLE'];
- return $this->exec_TRUNCATEquery($table);
- }
- }
- /**************************************
- *
- * Query building
- *
- **************************************/
- /**
- * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.
- * Usage count/core: 4
- *
- * @param string See exec_INSERTquery()
- * @param array See exec_INSERTquery()
- * @param mixed See exec_INSERTquery()
- * @return mixed Full SQL query for INSERT as string or array (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields
- */
- public function INSERTquery($table, $fields_values, $no_quote_fields = '') {
- // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
- if (is_array($fields_values) && count($fields_values)) {
- if (is_string($no_quote_fields)) {
- $no_quote_fields = explode(',', $no_quote_fields);
- } elseif (!is_array($no_quote_fields)) {
- $no_quote_fields = array();
- }
- $blobfields = array();
- $nArr = array();
- foreach ($fields_values as $k => $v) {
- if (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'B') {
- // we skip the field in the regular INSERT statement, it is only in blobfields
- $blobfields[$this->quoteFieldNames($k)] = $v;
- } elseif (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'XL') {
- // we skip the field in the regular INSERT statement, it is only in clobfields
- $clobfields[$this->quoteFieldNames($k)] = $v;
- } else {
- // Add slashes old-school:
- // cast numerical values
- $mt = $this->sql_field_metatype($table, $k);
- if ($mt{0} == 'I') {
- $v = (int) $v;
- } else if ($mt{0} == 'F') {
- $v = (double) $v;
- }
- $nArr[$this->quoteFieldNames($k)] = (!in_array($k, $no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v;
- }
- }
- if (count($blobfields) || count($clobfields)) {
- if (count($nArr)) {
- $query[0] = 'INSERT INTO ' . $this->quoteFromTables($table) . '
- (
- ' . implode(',
- ', array_keys($nArr)) . '
- ) VALUES (
- ' . implode(',
- ', $nArr) . '
- )';
- }
- if (count($blobfields)) $query[1] = $blobfields;
- if (count($clobfields)) $query[2] = $clobfields;
- if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query[0];
- } else {
- $query = 'INSERT INTO ' . $this->quoteFromTables($table) . '
- (
- ' . implode(',
- ', array_keys($nArr)) . '
- ) VALUES (
- ' . implode(',
- ', $nArr) . '
- )';
- if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
- }
- return $query;
- }
- }
- /**
- * Creates an INSERT SQL-statement for $table with multiple rows.
- * This method will create multiple INSERT queries concatenated with ';'
- *
- * @param string Table name
- * @param array Field names
- * @param array Table rows. Each row should be an array with field values mapping to $fields
- * @param string/array See fullQuoteArray()
- * @return array Full SQL query for INSERT as array of strings (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned for each row, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields.
- */
- public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) {
- if ((string) $this->handlerCfg[$this->lastHandlerKey]['type'] === 'native') {
- return parent::INSERTmultipleRows($table, $fields, $rows, $no_quote_fields);
- }
- $result = array();
- foreach ($rows as $row) {
- $fields_values = array();
- foreach ($fields as $key => $value) {
- $fields_values[$value] = $row[$key];
- }
- $rowQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields);
- if (is_array($rowQuery)) {
- $result[] = $rowQuery;
- } else {
- $result[][0] = $rowQuery;
- }
- }
- return $result;
- }
- /**
- * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values.
- * Usage count/core: 6
- *
- * @param string See exec_UPDATEquery()
- * @param string See exec_UPDATEquery()
- * @param array See exec_UPDATEquery()
- * @param mixed See exec_UPDATEquery()
- * @return mixed Full SQL query for UPDATE as string or array (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields
- */
- public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = '') {
- // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
- if (is_string($where)) {
- $fields = array();
- $blobfields = array();
- $clobfields = array();
- if (is_array($fields_values) && count($fields_values)) {
- if (is_string($no_quote_fields)) {
- $no_quote_fields = explode(',', $no_quote_fields);
- } elseif (!is_array($no_quote_fields)) {
- $no_quote_fields = array();
- }
- $nArr = array();
- foreach ($fields_values as $k => $v) {
- if (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'B') {
- // we skip the field in the regular UPDATE statement, it is only in blobfields
- $blobfields[$this->quoteFieldNames($k)] = $v;
- } elseif (!$this->runningNative() && $this->sql_field_metatype($table, $k) == 'XL') {
- // we skip the field in the regular UPDATE statement, it is only in clobfields
- $clobfields[$this->quoteFieldNames($k)] = $v;
- } else {
- // Add slashes old-school:
- // cast numeric values
- $mt = $this->sql_field_metatype($table, $k);
- if ($mt{0} == 'I') {
- $v = (int) $v;
- } else if ($mt{0} == 'F') {
- $v = (double) $v;
- }
- $nArr[] = $this->quoteFieldNames($k) . '=' . ((!in_array($k, $no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v);
- }
- }
- }
- if (count($blobfields) || count($clobfields)) {
- if (count($nArr)) {
- $query[0] = 'UPDATE ' . $this->quoteFromTables($table) . '
- SET
- ' . implode(',
- ', $nArr) .
- (strlen($where) > 0 ? '
- WHERE
- ' . $this->quoteWhereClause($where) : '');
- }
- if (count($blobfields)) {
- $query[1] = $blobfields;
- }
- if (count($clobfields)) {
- $query[2] = $clobfields;
- }
- if ($this->debugOutput || $this->store_lastBuiltQuery) {
- $this->debug_lastBuiltQuery = $query[0];
- }
- } else {
- $query = 'UPDATE ' . $this->quoteFromTables($table) . '
- SET
- ' . implode(',
- ', $nArr) .
- (strlen($where) > 0 ? '
- WHERE
- ' . $this->quoteWhereClause($where) : '');
- if ($this->debugOutput || $this->store_lastBuiltQuery) {
- $this->debug_lastBuiltQuery = $query;
- }
- }
- return $query;
- } else {
- throw new InvalidArgumentException(
- 'TYPO3 Fatal Error: "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !',
- 1270853880
- );
- }
- }
- /**
- * Creates a DELETE SQL-statement for $table where $where-clause
- * Usage count/core: 3
- *
- * @param string See exec_DELETEquery()
- * @param string See exec_DELETEquery()
- * @return string Full SQL query for DELETE
- */
- public function DELETEquery($table, $where) {
- if (is_string($where)) {
- $table = $this->quoteFromTables($table);
- $where = $this->quoteWhereClause($where);
- $query = parent::DELETEquery($table, $where);
- if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
- return $query;
- } else {
- die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for DELETE query was not a string in $this->DELETEquery() !');
- }
- }
- /**
- * Creates a SELECT SQL-statement
- * Usage count/core: 11
- *
- * @param string See exec_SELECTquery()
- * @param string See exec_SELECTquery()
- * @param string See exec_SELECTquery()
- * @param string See exec_SELECTquery()
- * @param string See exec_SELECTquery()
- * @param string See exec_SELECTquery()
- * @return string Full SQL query for SELECT
- */
- public function SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') {
- $this->lastHandlerKey = $this->handler_getFromTableList($from_table);
- $hType = (string) $this->handlerCfg[$this->lastHandlerKey]['type'];
- if ($hType === 'adodb' && $this->runningADOdbDriver('postgres')) {
- // Possibly rewrite the LIMIT to be PostgreSQL-compatible
- $splitLimit = t3lib_div::intExplode(',', $limit); // Splitting the limit values:
- if ($splitLimit[1]) { // If there are two parameters, do mapping differently than otherwise:
- $numrows = $splitLimit[1];
- $offset = $splitLimit[0];
- $limit = $numrows . ' OFFSET ' . $offset;
- }
- }
- $select_fields = $this->quoteFieldNames($select_fields);
- $from_table = $this->quoteFromTables($from_table);
- $where_clause = $this->quoteWhereClause($where_clause);
- $groupBy = $this->quoteGroupBy($groupBy);
- $orderBy = $this->quoteOrderBy($orderBy);
- // Call parent method to build actual query
- $query = parent::SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
- if ($this->debugOutput || $this->store_lastBuiltQuery) {
- $this->debug_lastBuiltQuery = $query;
- }
- return $query;
- }
- /**
- * Creates a SELECT SQL-statement to be used with an ADOdb backend.
- *
- * @param array parsed parameters: array($select_fields, $from_table, $where_clause, $groupBy, $orderBy)
- * @return string Full SQL query for SELECT
- */
- protected function SELECTqueryFromArray(array $params) {
- // $select_fields
- $params[0] = $this->_quoteFieldNames($params[0]);
- // $from_table
- $params[1] = $this->_quoteFromTables($params[1]);
- // $where_clause
- if (count($params[2]) > 0) {
- $params[2] = $this->_quoteWhereClause($params[2]);
- }
- // $group_by
- if (count($params[3]) > 0) {
- $params[3] = $this->_quoteGroupBy($params[3]);
- }
- // $order_by
- if (count($params[4]) > 0) {
- $params[4] = $this->_quoteOrderBy($params[4]);
- }
- // Compile the SELECT parameters
- list($select_fields, $from_table, $where_clause, $groupBy, $orderBy) = $this->compileSe…
Large files files are truncated, but you can click here to view the full file