Bug #20947 » 11813_03_without_whitespace.diff
t3lib/class.t3lib_db.php (working copy) | ||
---|---|---|
*/
|
||
function exec_INSERTquery($table,$fields_values,$no_quote_fields=FALSE) {
|
||
$res = mysql_query($this->INSERTquery($table,$fields_values,$no_quote_fields), $this->link);
|
||
if ($this->debugOutput) $this->debug('exec_INSERTquery');
|
||
if ($this->debugOutput) {
|
||
$this->debug('exec_INSERTquery');
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
*/
|
||
function exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) {
|
||
$res = mysql_query($this->UPDATEquery($table,$where,$fields_values,$no_quote_fields), $this->link);
|
||
if ($this->debugOutput) $this->debug('exec_UPDATEquery');
|
||
if ($this->debugOutput) {
|
||
$this->debug('exec_UPDATEquery');
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
*/
|
||
function exec_DELETEquery($table,$where) {
|
||
$res = mysql_query($this->DELETEquery($table,$where), $this->link);
|
||
if ($this->debugOutput) $this->debug('exec_DELETEquery');
|
||
if ($this->debugOutput) {
|
||
$this->debug('exec_DELETEquery');
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
$mmWhere = $local_table ? $local_table.'.uid='.$mm_table.'.uid_local' : '';
|
||
$mmWhere.= ($local_table AND $foreign_table) ? ' AND ' : '';
|
||
$mmWhere.= $foreign_table ? ($foreign_table_as ? $foreign_table_as : $foreign_table).'.uid='.$mm_table.'.uid_foreign' : '';
|
||
$tables = ($local_table ? $local_table . ',' : '') . $mm_table;
|
||
if ($foreign_table) {
|
||
$mmWhere .= ($foreign_table_as ? $foreign_table_as : $foreign_table) . '.uid=' . $mm_table . '.uid_foreign';
|
||
$tables .= ',' . $foreign_table . ($foreign_table_as ? ' AS ' . $foreign_table_as : '');
|
||
}
|
||
return $this->exec_SELECTquery(
|
||
$select,
|
||
($local_table ? $local_table.',' : '').$mm_table.($foreign_table ? ','. $foreign_table.($foreign_table_as ? ' AS '.$foreign_table_as : '') : ''),
|
||
$mmWhere.' '.$whereClause, // whereClauseMightContainGroupOrderBy
|
||
$tables,
|
||
// whereClauseMightContainGroupOrderBy
|
||
$mmWhere . ' ' . $whereClause,
|
||
$groupBy,
|
||
$orderBy,
|
||
$limit
|
||
... | ... | |
*/
|
||
function exec_SELECTgetRows($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='',$uidIndexField='') {
|
||
$res = $this->exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);
|
||
if ($this->debugOutput) $this->debug('exec_SELECTquery');
|
||
if ($this->debugOutput) {
|
||
$this->debug('exec_SELECTquery');
|
||
}
|
||
if (!$this->sql_error()) {
|
||
$output = array();
|
||
... | ... | |
*/
|
||
function INSERTquery($table,$fields_values,$no_quote_fields=FALSE) {
|
||
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
|
||
// 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)) {
|
||
// quote and escape values
|
||
$fields_values = $this->fullQuoteArray($fields_values,$table,$no_quote_fields);
|
||
// Build query:
|
||
$query = 'INSERT INTO '.$table.'
|
||
(
|
||
'.implode(',
|
||
',array_keys($fields_values)).'
|
||
) VALUES (
|
||
'.implode(',
|
||
',$fields_values).'
|
||
)';
|
||
$query = 'INSERT INTO ' . $table .
|
||
'(' . implode(',', array_keys($fields_values)) . ') VALUES ' .
|
||
'(' . implode(',', $fields_values) . ')';
|
||
// Return query:
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) {
|
||
$this->debug_lastBuiltQuery = $query;
|
||
}
|
||
return $query;
|
||
}
|
||
}
|
||
... | ... | |
*/
|
||
function UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) {
|
||
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).
|
||
// 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)) {
|
||
if (is_array($fields_values) && count($fields_values)) {
|
||
... | ... | |
}
|
||
// Build query:
|
||
$query = 'UPDATE '.$table.'
|
||
SET
|
||
'.implode(',
|
||
',$fields).
|
||
(strlen($where)>0 ? '
|
||
WHERE
|
||
'.$where : '');
|
||
$query = 'UPDATE ' . $table . ' SET ' . implode(',', $fields) .
|
||
(strlen($where) > 0 ? ' WHERE ' . $where : '');
|
||
// Return query:
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) {
|
||
$this->debug_lastBuiltQuery = $query;
|
||
}
|
||
return $query;
|
||
}
|
||
} else {
|
||
die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !');
|
||
die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for UPDATE ' .
|
||
'query was not a string in $this->UPDATEquery() !');
|
||
}
|
||
}
|
||
... | ... | |
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
|
||
$query = 'DELETE FROM '.$table.
|
||
(strlen($where)>0 ? '
|
||
WHERE
|
||
'.$where : '');
|
||
(strlen($where) > 0 ? ' WHERE ' . $where : '');
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
|
||
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() !');
|
||
die('<strong>TYPO3 Fatal Error:</strong> "Where" clause argument for DELETE ' .
|
||
'query was not a string in $this->DELETEquery() !');
|
||
}
|
||
}
|
||
... | ... | |
// Table and fieldnames should be "SQL-injection-safe" when supplied to this function
|
||
// Build basic query:
|
||
$query = 'SELECT '.$select_fields.'
|
||
FROM '.$from_table.
|
||
(strlen($where_clause)>0 ? '
|
||
WHERE
|
||
'.$where_clause : '');
|
||
$query = 'SELECT ' . $select_fields . ' FROM ' . $from_table .
|
||
(strlen($where_clause) > 0 ? ' WHERE ' . $where_clause : '');
|
||
// Group by:
|
||
if (strlen($groupBy)>0) {
|
||
$query.= '
|
||
GROUP BY '.$groupBy;
|
||
}
|
||
$query .= (strlen($groupBy) > 0 ? ' GROUP BY ' . $groupBy : '');
|
||
// Order by:
|
||
if (strlen($orderBy)>0) {
|
||
$query.= '
|
||
ORDER BY '.$orderBy;
|
||
}
|
||
$query .= (strlen($orderBy) > 0 ? ' ORDER BY ' . $orderBy : '');
|
||
// Group by:
|
||
if (strlen($limit)>0) {
|
||
$query.= '
|
||
LIMIT '.$limit;
|
||
}
|
||
$query .= (strlen($limit) > 0 ? ' LIMIT ' . $limit : '');
|
||
// Return query:
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query;
|
||
if ($this->debugOutput || $this->store_lastBuiltQuery) {
|
||
$this->debug_lastBuiltQuery = $query;
|
||
}
|
||
return $query;
|
||
}
|
||
/**
|
||
* Returns a WHERE clause that can find a value ($value) in a list field ($field)
|
||
* For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their positioni in the list (left, middle or right).
|
||
* For instance a record in the database might contain a list of numbers,
|
||
* "34,234,5" (with no spaces between). This query would be able to select that
|
||
* record based on the value "34", "234" or "5" regardless of their positioni in
|
||
* the list (left, middle or right).
|
||
* Is nice to look up list-relations to records or files in TYPO3 database tables.
|
||
*
|
||
* @param string Field name
|
||
... | ... | |
function listQuery($field, $value, $table) {
|
||
$pattern = $this->quoteStr($value, $table);
|
||
$patternForLike = $this->escapeStrForLike($pattern, $table);
|
||
$where = '('.$field.' LIKE \'%,'.$patternForLike.',%\' OR '.$field.' LIKE \''.$patternForLike.',%\' OR '.$field.' LIKE \'%,'.$patternForLike.'\' OR '.$field.'=\''.$pattern.'\')';
|
||
$where = '(' . $field . ' LIKE \'%,' . $patternForLike . ',%\' OR ' .
|
||
$field . ' LIKE \'' . $patternForLike . ',%\' OR ' .
|
||
$field . ' LIKE \'%,' . $patternForLike . '\' OR ' .
|
||
$field . '=\'' . $pattern . '\')';
|
||
return $where;
|
||
}
|
||
... | ... | |
function fullQuoteArray($arr, $table, $noQuote=FALSE) {
|
||
if (is_string($noQuote)) {
|
||
$noQuote = explode(',',$noQuote);
|
||
} elseif (!is_array($noQuote)) { // sanity check
|
||
// sanity check
|
||
} elseif (!is_array($noQuote)) {
|
||
$noQuote = FALSE;
|
||
}
|
||
... | ... | |
* @return array
|
||
*/
|
||
function splitGroupOrderLimit($str) {
|
||
$str = ' '.$str; // Prepending a space to make sure "[[:space:]]+" will find a space there for the first element.
|
||
// Prepending a space to make sure "[[:space:]]+" will find a space there
|
||
// for the first element.
|
||
$str = ' ' . $str;
|
||
// Init output array:
|
||
$wgolParts = array(
|
||
'WHERE' => '',
|
||
'GROUPBY' => '',
|
||
'ORDERBY' => '',
|
||
'LIMIT' => ''
|
||
'LIMIT' => '',
|
||
);
|
||
// Find LIMIT:
|
||
... | ... | |
*/
|
||
function sql($db,$query) {
|
||
$res = mysql_query($query, $this->link);
|
||
if ($this->debugOutput) $this->debug('sql',$query);
|
||
if ($this->debugOutput) {
|
||
$this->debug('sql', $query);
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
*/
|
||
function sql_query($query) {
|
||
$res = mysql_query($query, $this->link);
|
||
if ($this->debugOutput) $this->debug('sql_query',$query);
|
||
if ($this->debugOutput) {
|
||
$this->debug('sql_query', $query);
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['no_pconnect']) {
|
||
if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['dbClientCompress'] && !$isLocalhost) {
|
||
// We use PHP's default value for 4th parameter (new_link), which is false.
|
||
// See PHP sources, for example: file php-5.2.5/ext/mysql/php_mysql.c, function php_mysql_do_connect(), near line 525
|
||
// See PHP sources, for example: file php-5.2.5/ext/mysql/php_mysql.c,
|
||
// function php_mysql_do_connect(), near line 525
|
||
$this->link = @mysql_connect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password, false, MYSQL_CLIENT_COMPRESS);
|
||
} else {
|
||
$this->link = @mysql_connect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password);
|
||
... | ... | |
@ini_restore('html_errors');
|
||
if (!$this->link) {
|
||
t3lib_div::sysLog('Could not connect to MySQL server '.$TYPO3_db_host.' with user '.$TYPO3_db_username.': '.$error_msg,'Core',4);
|
||
t3lib_div::sysLog('Could not connect to MySQL server ' . $TYPO3_db_host .
|
||
' with user ' . $TYPO3_db_username . ': ' . $error_msg,
|
||
'Core',
|
||
4
|
||
);
|
||
} else {
|
||
$setDBinit = t3lib_div::trimExplode(chr(10), $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'],TRUE);
|
||
foreach ($setDBinit as $v) {
|
||
if (mysql_query($v, $this->link) === FALSE) {
|
||
t3lib_div::sysLog('Could not initialize DB connection with query "'.$v.'": '.mysql_error($this->link),'Core',3);
|
||
t3lib_div::sysLog('Could not initialize DB connection with query "' . $v .
|
||
'": ' . mysql_error($this->link),
|
||
'Core',
|
||
3
|
||
);
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
function sql_select_db($TYPO3_db) {
|
||
$ret = @mysql_select_db($TYPO3_db, $this->link);
|
||
if (!$ret) {
|
||
t3lib_div::sysLog('Could not select MySQL database '.$TYPO3_db.': '.mysql_error(),'Core',4);
|
||
t3lib_div::sysLog('Could not select MySQL database ' . $TYPO3_db . ': ' .
|
||
mysql_error(),
|
||
'Core',
|
||
4
|
||
);
|
||
}
|
||
return $ret;
|
||
}
|
||
... | ... | |
/**
|
||
* Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database.
|
||
* This is only used as a service function in the (1-2-3 process) of the Install Tool. In any case a lookup should be done in the _DEFAULT handler DBMS then.
|
||
* This is only used as a service function in the (1-2-3 process) of the Install Tool.
|
||
* In any case a lookup should be done in the _DEFAULT handler DBMS then.
|
||
* Use in Install Tool only!
|
||
* Usage count/core: 1
|
||
*
|
||
... | ... | |
/**
|
||
* Returns the list of tables from the default database, TYPO3_db (quering the DBMS)
|
||
* In a DBAL this method should 1) look up all tables from the DBMS of the _DEFAULT handler and then 2) add all tables *configured* to be managed by other handlers
|
||
* In a DBAL this method should 1) look up all tables from the DBMS of
|
||
* the _DEFAULT handler and then 2) add all tables *configured* to be managed by other handlers
|
||
* Usage count/core: 2
|
||
*
|
||
* @return array Array with tablenames as key and arrays with status information as value
|
||
... | ... | |
/**
|
||
* Returns information about each field in the $table (quering the DBMS)
|
||
* In a DBAL this should look up the right handler for the table and return compatible information
|
||
* This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery.
|
||
* This function is important not only for the Install Tool but probably for
|
||
* DBALs as well since they might need to look up table specific information
|
||
* in order to construct correct queries. In such cases this information should
|
||
* probably be cached for quick delivery.
|
||
*
|
||
* @param string Table name
|
||
* @return array Field information in an associative array with fieldname => field row
|
||
... | ... | |
/**
|
||
* Returns information about the character sets supported by the current DBM
|
||
* This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery.
|
||
* This function is important not only for the Install Tool but probably for
|
||
* DBALs as well since they might need to look up table specific information
|
||
* in order to construct correct queries. In such cases this information should
|
||
* probably be cached for quick delivery.
|
||
*
|
||
* This is used by the Install Tool to convert tables tables with non-UTF8 charsets
|
||
* Use in Install Tool only!
|
||
... | ... | |
*/
|
||
function admin_query($query) {
|
||
$res = mysql_query($query, $this->link);
|
||
if ($this->debugOutput) $this->debug('admin_query',$query);
|
||
if ($this->debugOutput) {
|
||
$this->debug('admin_query', $query);
|
||
}
|
||
return $res;
|
||
}
|
||
... | ... | |
exit;
|
||
}
|
||
} else {
|
||
die('The current username, password or host was not accepted when the connection to the database was attempted to be established!');
|
||
die('The current username, password or host was not accepted when the ' .
|
||
'connection to the database was attempted to be established!');
|
||
exit;
|
||
}
|
||
}
|
||
... | ... | |
$error = $this->sql_error();
|
||
if ($error) {
|
||
debug(array(
|
||
debug(
|
||
array(
|
||
'caller' => 't3lib_DB::'.$func,
|
||
'ERROR' => $error,
|
||
'lastBuiltQuery' => ($query ? $query : $this->debug_lastBuiltQuery),
|
||
'debug_backtrace' => t3lib_div::debug_trail()
|
||
), 'SQL debug');
|
||
'debug_backtrace' => t3lib_div::debug_trail(),
|
||
),
|
||
'SQL debug'
|
||
);
|
||
}
|
||
}
|
||
... | ... | |
$cnt = count($trace);
|
||
for ($i=0; $i<$cnt; $i++) {
|
||
// complete objects are too large for the log
|
||
if (isset($trace['object'])) unset($trace['object']);
|
||
if (isset($trace['object'])) {
|
||
unset($trace['object']);
|
||
}
|
||
}
|
||
$msg .= ': function t3lib_DB->' . $trace[0]['function'] . ' called from file ' . substr($trace[0]['file'],strlen(PATH_site)+2) . ' in line ' . $trace[0]['line'];
|
||
$msg .= ': function t3lib_DB->' . $trace[0]['function'] . ' called from file ' .
|
||
substr($trace[0]['file'], strlen(PATH_site) + 2) . ' in line ' .
|
||
$trace[0]['line'];
|
||
t3lib_div::sysLog($msg.'. Use a devLog extension to get more details.', 'Core/t3lib_db', 3);
|
||
// Send to devLog if enabled
|
||
if (TYPO3_DLOG) {
|
||
... | ... | |
*/
|
||
protected function explain($query,$from_table,$row_count) {
|
||
if ((int)$this->explainOutput==1 || ((int)$this->explainOutput==2 && t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']))) {
|
||
$explainMode = 1; // raw HTML output
|
||
if ((int)$this->explainOutput == 1 || ((int)$this->explainOutput == 2 &&
|
||
t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']))
|
||
) {
|
||
// raw HTML output
|
||
$explainMode = 1;
|
||
} elseif ((int)$this->explainOutput==3 && is_object($GLOBALS['TT'])) {
|
||
$explainMode = 2; // embed the output into the TS admin panel
|
||
// embed the output into the TS admin panel
|
||
$explainMode = 2;
|
||
} else {
|
||
return false;
|
||
}
|
||
... | ... | |
}
|
||
$indices_output = array();
|
||
if ($explain_output[0]['rows']>1 || t3lib_div::inList('ALL',$explain_output[0]['type'])) { // Notice: Rows are skipped if there is only one result, or if no conditions are set
|
||
$debug = true; // only enable output if it's really useful
|
||
// Notice: Rows are skipped if there is only one result, or if no conditions are set
|
||
if ($explain_output[0]['rows'] > 1 || t3lib_div::inList('ALL', $explain_output[0]['type'])) {
|
||
// only enable output if it's really useful
|
||
$debug = true;
|
||
foreach ($explain_tables as $table) {
|
||
$res = $this->sql_query('SHOW INDEX FROM '.$table, $this->link);
|
- « Previous
- 1
- 2
- 3
- 4
- Next »