Commit 56d2664a authored by Dries's avatar Dries

- Patch #245115 by kkaefer, John Morahan, JohnAlbin et al: after a long...

- Patch #245115 by kkaefer, John Morahan, JohnAlbin et al: after a long discussion we've decided to make the concatenation operator consistent with the other operators.
parent 46cda4c6
......@@ -65,8 +65,8 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
if ($where) {
$where_clause = implode(' ', $where);
// Strip off leading 'OR '.
$where_clause = '('. strstr($where_clause, " ") .')';
$result_db = db_query('SELECT * FROM {actions} WHERE '. $where_clause, $where_values);
$where_clause = '(' . strstr($where_clause, " ") . ')';
$result_db = db_query('SELECT * FROM {actions} WHERE ' . $where_clause, $where_values);
while ($action = db_fetch_object($result_db)) {
$actions[$action->aid] = $action->parameters ? unserialize($action->parameters) : array();
$actions[$action->aid]['callback'] = $action->callback;
......
......@@ -78,7 +78,7 @@ function _batch_progress_page_js() {
$url = url($batch['url'], array('query' => array('id' => $batch['id'])));
$js_setting = array(
'batch' => array(
'errorMessage' => $current_set['error_message'] .'<br/>'. $batch['error_message'],
'errorMessage' => $current_set['error_message'] . '<br/>' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => $url,
),
......@@ -132,7 +132,7 @@ function _batch_progress_page_nojs() {
// function), it will output whatever is in the output buffer,
// followed by the error message.
ob_start();
$fallback = $current_set['error_message'] .'<br/>'. $batch['error_message'];
$fallback = $current_set['error_message'] . '<br/>' . $batch['error_message'];
$fallback = theme('maintenance_page', $fallback, FALSE, FALSE);
// We strip the end of the page using a marker in the template, so any
......@@ -153,7 +153,7 @@ function _batch_progress_page_nojs() {
}
$url = url($batch['url'], array('query' => array('id' => $batch['id'], 'op' => $new_op)));
drupal_set_html_head('<meta http-equiv="Refresh" content="0; URL='. $url .'">');
drupal_set_html_head('<meta http-equiv="Refresh" content="0; URL=' . $url . '">');
$output = theme('progress_bar', $percentage, $message);
return $output;
}
......@@ -243,7 +243,7 @@ function _batch_process() {
'@current' => floor($current),
'@percentage' => $percentage,
);
$message = strtr($progress_message, $values) .'<br/>';
$message = strtr($progress_message, $values) . '<br/>';
$message .= $task_message ? $task_message : '&nbsp';
return array($percentage, $message);
......
......@@ -277,8 +277,8 @@ function conf_init() {
global $db_url, $db_prefix, $cookie_domain, $conf, $installed_profile, $update_free_access;
$conf = array();
if (file_exists('./'. conf_path() .'/settings.php')) {
include_once './'. conf_path() .'/settings.php';
if (file_exists('./' . conf_path() . '/settings.php')) {
include_once './' . conf_path() . '/settings.php';
}
if (isset($base_url)) {
......@@ -287,7 +287,7 @@ function conf_init() {
if (!isset($parts['path'])) {
$parts['path'] = '';
}
$base_path = $parts['path'] .'/';
$base_path = $parts['path'] . '/';
// Build $base_root (everything until first slash after "scheme://").
$base_root = substr($base_url, 0, strlen($base_url) - strlen($parts['path']));
}
......@@ -297,7 +297,7 @@ function conf_init() {
// As $_SERVER['HTTP_HOST'] is user input, ensure it only contains
// characters allowed in hostnames.
$base_url = $base_root .= '://'. preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
$base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
// $_SERVER['SCRIPT_NAME'] can, in contrast to $_SERVER['PHP_SELF'], not
// be modified by a visitor.
......@@ -330,13 +330,13 @@ function conf_init() {
$cookie_domain = substr($cookie_domain, 4);
}
$cookie_domain = explode(':', $cookie_domain);
$cookie_domain = '.'. $cookie_domain[0];
$cookie_domain = '.' . $cookie_domain[0];
// Per RFC 2109, cookie domains must contain at least one dot other than the
// first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.
if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
ini_set('session.cookie_domain', $cookie_domain);
}
session_name('SESS'. md5($session_name));
session_name('SESS' . md5($session_name));
}
/**
......@@ -566,7 +566,7 @@ function drupal_load($type, $name) {
*/
function drupal_page_header() {
header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
}
......@@ -582,8 +582,8 @@ function drupal_page_header() {
*/
function drupal_page_cache_header($cache) {
// Set default values:
$last_modified = gmdate('D, d M Y H:i:s', $cache->created) .' GMT';
$etag = '"'. md5($last_modified) .'"';
$last_modified = gmdate('D, d M Y H:i:s', $cache->created) . ' GMT';
$etag = '"' . md5($last_modified) . '"';
// See if the client has provided the required HTTP headers:
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
......@@ -720,10 +720,10 @@ function request_uri() {
}
else {
if (isset($_SERVER['argv'])) {
$uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['argv'][0];
$uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['argv'][0];
}
elseif (isset($_SERVER['QUERY_STRING'])) {
$uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
$uri = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
}
else {
$uri = $_SERVER['SCRIPT_NAME'];
......@@ -955,7 +955,7 @@ function _drupal_bootstrap($phase) {
// Deny access to blocked IP addresses - t() is not yet available.
if (drupal_is_denied(ip_address())) {
header('HTTP/1.1 403 Forbidden');
print 'Sorry, '. check_plain(ip_address()) .' has been banned.';
print 'Sorry, ' . check_plain(ip_address()) . ' has been banned.';
exit();
}
break;
......
......@@ -20,10 +20,10 @@ function cache_get($cid, $table = 'cache') {
// Reset the variable immediately to prevent a meltdown in heavy load situations.
variable_set('cache_flush', 0);
// Time to flush old cache data
db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
}
$cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $cid));
$cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = '%s'", $cid));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
......@@ -106,9 +106,9 @@ function cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $he
$serialized = 1;
}
$created = time();
db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid);
db_query("UPDATE {" . $table . "} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
@db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized);
@db_query("INSERT INTO {" . $table . "} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized);
}
}
......@@ -157,26 +157,26 @@ function cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE) {
else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) {
// Clear the cache for everyone, cache_flush_delay seconds have
// passed since the first request to clear the cache.
db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
variable_set('cache_flush', 0);
}
}
else {
// No minimum cache lifetime, flush all temporary cache entries now.
db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
}
}
else {
if ($wildcard) {
if ($cid == '*') {
db_query("DELETE FROM {". $table ."}");
db_query("DELETE FROM {" . $table . "}");
}
else {
db_query("DELETE FROM {". $table ."} WHERE cid LIKE '%s%%'", $cid);
db_query("DELETE FROM {" . $table . "} WHERE cid LIKE '%s%%'", $cid);
}
}
else {
db_query("DELETE FROM {". $table ."} WHERE cid = '%s'", $cid);
db_query("DELETE FROM {" . $table . "} WHERE cid = '%s'", $cid);
}
}
}
......
This diff is collapsed.
......@@ -87,13 +87,13 @@ function db_prefix_tables($sql) {
$tmp = $db_prefix;
unset($tmp['default']);
foreach ($tmp as $key => $val) {
$sql = strtr($sql, array('{'. $key .'}' => $val . $key));
$sql = strtr($sql, array('{' . $key . '}' => $val . $key));
}
return strtr($sql, array('{' => $db_prefix['default'], '}' => ''));
}
else {
foreach ($db_prefix as $key => $val) {
$sql = strtr($sql, array('{'. $key .'}' => $val . $key));
$sql = strtr($sql, array('{' . $key . '}' => $val . $key));
}
return strtr($sql, array('{' => '', '}' => ''));
}
......@@ -146,7 +146,7 @@ function db_set_active($name = 'default') {
include_once $handler;
}
else {
_db_error_page("The database type '". $db_type ."' is unsupported. Please use either 'mysql' or 'mysqli' for MySQL, or 'pgsql' for PostgreSQL databases.");
_db_error_page("The database type '" . $db_type . "' is unsupported. Please use either 'mysql' or 'mysqli' for MySQL, or 'pgsql' for PostgreSQL databases.");
}
$db_conns[$name] = db_connect($connect_url);
......@@ -180,7 +180,7 @@ function _db_error_page($error = '') {
$message .= '<hr /><p><small>If you are the maintainer of this site, please check your database settings in the <code>settings.php</code> file and ensure that your hosting provider\'s database server is running. For more help, see the <a href="http://drupal.org/node/258">handbook</a>, or contact your hosting provider.</small></p>';
if ($error && ini_get('display_errors')) {
$message .= '<p><small>The '. theme('placeholder', $db_type) .' error was: '. theme('placeholder', $error) .'.</small></p>';
$message .= '<p><small>The ' . theme('placeholder', $db_type) . ' error was: ' . theme('placeholder', $error) . '.</small></p>';
}
print theme('maintenance_page', $message);
......@@ -282,7 +282,7 @@ function _db_rewrite_sql($query = '', $primary_table = 'n', $primary_field = 'ni
}
}
$where = empty($where) ? '' : '('. implode(') AND (', $where) .')';
$where = empty($where) ? '' : '(' . implode(') AND (', $where) . ')';
$join = empty($join) ? '' : implode(' ', $join);
return array($join, $where, $distinct);
......@@ -331,7 +331,7 @@ function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $
if ($where) {
$n = strlen($matches[1]);
$second_part = substr($query, $n);
$first_part = substr($matches[1], 0, $n - 5) ." $join WHERE $where AND ( ";
$first_part = substr($matches[1], 0, $n - 5) . " $join WHERE $where AND ( ";
// PHP 4 does not support strrpos for strings. We emulate it.
$haystack_reverse = strrev($second_part);
// No need to use strrev on the needle, we supply GROUP, ORDER, LIMIT
......@@ -345,14 +345,14 @@ function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $
}
}
if ($pos === FALSE) {
$query = $first_part . $second_part .')';
$query = $first_part . $second_part . ')';
}
else {
$query = $first_part . substr($second_part, 0, -$pos) .')'. substr($second_part, -$pos);
$query = $first_part . substr($second_part, 0, -$pos) . ')' . substr($second_part, -$pos);
}
}
else {
$query = $matches[1] ." $join ". substr($query, strlen($matches[1]));
$query = $matches[1] . " $join " . substr($query, strlen($matches[1]));
}
}
......@@ -564,7 +564,7 @@ function db_type_placeholder($type) {
// There is no safe value to return here, so return something that
// will cause the query to fail.
return 'unsupported type '. $type .'for db_type_placeholder';
return 'unsupported type ' . $type . 'for db_type_placeholder';
}
/**
......
......@@ -63,21 +63,21 @@ function db_create_table_sql($name, $table) {
$table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */";
}
$sql = "CREATE TABLE {". $name ."} (\n";
$sql = "CREATE TABLE {" . $name . "} (\n";
// Add the SQL statement for each field.
foreach ($table['fields'] as $field_name => $field) {
$sql .= _db_create_field_sql($field_name, _db_process_field($field)) .", \n";
$sql .= _db_create_field_sql($field_name, _db_process_field($field)) . ", \n";
}
// Process keys & indexes.
$keys = _db_create_keys_sql($table);
if (count($keys)) {
$sql .= implode(", \n", $keys) .", \n";
$sql .= implode(", \n", $keys) . ", \n";
}
// Remove the last comma and space.
$sql = substr($sql, 0, -3) ."\n) ";
$sql = substr($sql, 0, -3) . "\n) ";
$sql .= $table['mysql_suffix'];
......@@ -88,16 +88,16 @@ function _db_create_keys_sql($spec) {
$keys = array();
if (!empty($spec['primary key'])) {
$keys[] = 'PRIMARY KEY ('. _db_create_key_sql($spec['primary key']) .')';
$keys[] = 'PRIMARY KEY (' . _db_create_key_sql($spec['primary key']) . ')';
}
if (!empty($spec['unique keys'])) {
foreach ($spec['unique keys'] as $key => $fields) {
$keys[] = 'UNIQUE KEY '. $key .' ('. _db_create_key_sql($fields) .')';
$keys[] = 'UNIQUE KEY ' . $key . ' (' . _db_create_key_sql($fields) . ')';
}
}
if (!empty($spec['indexes'])) {
foreach ($spec['indexes'] as $index => $fields) {
$keys[] = 'INDEX '. $index .' ('. _db_create_key_sql($fields) .')';
$keys[] = 'INDEX ' . $index . ' (' . _db_create_key_sql($fields) . ')';
}
}
......@@ -108,7 +108,7 @@ function _db_create_key_sql($fields) {
$ret = array();
foreach ($fields as $field) {
if (is_array($field)) {
$ret[] = $field[0] .'('. $field[1] .')';
$ret[] = $field[0] . '(' . $field[1] . ')';
}
else {
$ret[] = $field;
......@@ -132,7 +132,7 @@ function _db_process_field($field) {
// Set the correct database-engine specific datatype.
if (!isset($field['mysql_type'])) {
$map = db_type_map();
$field['mysql_type'] = $map[$field['type'] .':'. $field['size']];
$field['mysql_type'] = $map[$field['type'] . ':' . $field['size']];
}
if ($field['type'] == 'serial') {
......@@ -154,13 +154,13 @@ function _db_process_field($field) {
* The field specification, as per the schema data structure format.
*/
function _db_create_field_sql($name, $spec) {
$sql = "`". $name ."` ". $spec['mysql_type'];
$sql = "`" . $name . "` " . $spec['mysql_type'];
if (isset($spec['length'])) {
$sql .= '('. $spec['length'] .')';
$sql .= '(' . $spec['length'] . ')';
}
elseif (isset($spec['precision']) && isset($spec['scale'])) {
$sql .= '('. $spec['precision'] .', '. $spec['scale'] .')';
$sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
}
if (!empty($spec['unsigned'])) {
......@@ -177,9 +177,9 @@ function _db_create_field_sql($name, $spec) {
if (isset($spec['default'])) {
if (is_string($spec['default'])) {
$spec['default'] = "'". $spec['default'] ."'";
$spec['default'] = "'" . $spec['default'] . "'";
}
$sql .= ' DEFAULT '. $spec['default'];
$sql .= ' DEFAULT ' . $spec['default'];
}
if (empty($spec['not null']) && !isset($spec['default'])) {
......@@ -246,7 +246,7 @@ function db_type_map() {
* The new name for the table.
*/
function db_rename_table(&$ret, $table, $new_name) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} RENAME TO {'. $new_name .'}');
$ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
}
/**
......@@ -258,7 +258,7 @@ function db_rename_table(&$ret, $table, $new_name) {
* The table to be dropped.
*/
function db_drop_table(&$ret, $table) {
$ret[] = update_sql('DROP TABLE {'. $table .'}');
$ret[] = update_sql('DROP TABLE {' . $table . '}');
}
/**
......@@ -290,17 +290,17 @@ function db_add_field(&$ret, $table, $field, $spec, $keys_new = array()) {
$fixnull = TRUE;
$spec['not null'] = FALSE;
}
$query = 'ALTER TABLE {'. $table .'} ADD ';
$query = 'ALTER TABLE {' . $table . '} ADD ';
$query .= _db_create_field_sql($field, _db_process_field($spec));
if (count($keys_new)) {
$query .= ', ADD '. implode(', ADD ', _db_create_keys_sql($keys_new));
$query .= ', ADD ' . implode(', ADD ', _db_create_keys_sql($keys_new));
}
$ret[] = update_sql($query);
if (isset($spec['initial'])) {
// All this because update_sql does not support %-placeholders.
$sql = 'UPDATE {'. $table .'} SET '. $field .' = '. db_type_placeholder($spec['type']);
$sql = 'UPDATE {' . $table . '} SET ' . $field . ' = ' . db_type_placeholder($spec['type']);
$result = db_query($sql, $spec['initial']);
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql .' ('. $spec['initial'] .')'));
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql . ' (' . $spec['initial'] . ')'));
}
if ($fixnull) {
$spec['not null'] = TRUE;
......@@ -319,7 +319,7 @@ function db_add_field(&$ret, $table, $field, $spec, $keys_new = array()) {
* The field to be dropped.
*/
function db_drop_field(&$ret, $table, $field) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} DROP '. $field);
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP ' . $field);
}
/**
......@@ -342,7 +342,7 @@ function db_field_set_default(&$ret, $table, $field, $default) {
$default = is_string($default) ? "'$default'" : $default;
}
$ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' SET DEFAULT '. $default);
$ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN ' . $field . ' SET DEFAULT ' . $default);
}
/**
......@@ -356,7 +356,7 @@ function db_field_set_default(&$ret, $table, $field, $default) {
* The field to be altered.
*/
function db_field_set_no_default(&$ret, $table, $field) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' DROP DEFAULT');
$ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN ' . $field . ' DROP DEFAULT');
}
/**
......@@ -370,8 +370,8 @@ function db_field_set_no_default(&$ret, $table, $field) {
* Fields for the primary key.
*/
function db_add_primary_key(&$ret, $table, $fields) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} ADD PRIMARY KEY ('.
_db_create_key_sql($fields) .')');
$ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' .
_db_create_key_sql($fields) . ')');
}
/**
......@@ -383,7 +383,7 @@ function db_add_primary_key(&$ret, $table, $fields) {
* The table to be altered.
*/
function db_drop_primary_key(&$ret, $table) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} DROP PRIMARY KEY');
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
}
/**
......@@ -399,8 +399,8 @@ function db_drop_primary_key(&$ret, $table) {
* An array of field names.
*/
function db_add_unique_key(&$ret, $table, $name, $fields) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} ADD UNIQUE KEY '.
$name .' ('. _db_create_key_sql($fields) .')');
$ret[] = update_sql('ALTER TABLE {' . $table . '} ADD UNIQUE KEY ' .
$name . ' (' . _db_create_key_sql($fields) . ')');
}
/**
......@@ -414,7 +414,7 @@ function db_add_unique_key(&$ret, $table, $name, $fields) {
* The name of the key.
*/
function db_drop_unique_key(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} DROP KEY '. $name);
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP KEY ' . $name);
}
/**
......@@ -430,7 +430,7 @@ function db_drop_unique_key(&$ret, $table, $name) {
* An array of field names.
*/
function db_add_index(&$ret, $table, $name, $fields) {
$query = 'ALTER TABLE {'. $table .'} ADD INDEX '. $name .' ('. _db_create_key_sql($fields) .')';
$query = 'ALTER TABLE {' . $table . '} ADD INDEX ' . $name . ' (' . _db_create_key_sql($fields) . ')';
$ret[] = update_sql($query);
}
......@@ -445,7 +445,7 @@ function db_add_index(&$ret, $table, $name, $fields) {
* The name of the index.
*/
function db_drop_index(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {'. $table .'} DROP INDEX '. $name);
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP INDEX ' . $name);
}
/**
......@@ -512,10 +512,10 @@ function db_drop_index(&$ret, $table, $name) {
*/
function db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
$sql = 'ALTER TABLE {'. $table .'} CHANGE '. $field .' '.
$sql = 'ALTER TABLE {' . $table . '} CHANGE ' . $field . ' ' .
_db_create_field_sql($field_new, _db_process_field($spec));
if (count($keys_new)) {
$sql .= ', ADD '. implode(', ADD ', _db_create_keys_sql($keys_new));
$sql .= ', ADD ' . implode(', ADD ', _db_create_keys_sql($keys_new));
}
$ret[] = update_sql($sql);
}
......
......@@ -65,7 +65,7 @@ function db_connect($url) {
// Allow for non-standard MySQL port.
if (isset($url['port'])) {
$url['host'] = $url['host'] .':'. $url['port'];
$url['host'] = $url['host'] . ':' . $url['port'];
}
// - TRUE makes mysql_connect() always open a new link, even if
......@@ -103,13 +103,13 @@ function _db_query($query, $debug = 0) {
$name = $user->uid ? $user->name : variable_get('anonymous', 'Anonymous');
// str_replace() to prevent SQL injection via username or anonymous name.
$name = str_replace(array('*', '/'), '', $name);
$query = '/* '. $name .' : '. $bt[2]['function'] .' */ '. $query;
$query = '/* ' . $name . ' : ' . $bt[2]['function'] . ' */ ' . $query;
}
$result = mysql_query($query, $active_db);
if (variable_get('dev_query', 0)) {
$query = $bt[2]['function'] ."\n". $query;
$query = $bt[2]['function'] . "\n" . $query;
list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
......@@ -117,7 +117,7 @@ function _db_query($query, $debug = 0) {
}
if ($debug) {
print '<p>query: '. $query .'<br />error:'. mysql_error($active_db) .'</p>';
print '<p>query: ' . $query . '<br />error:' . mysql_error($active_db) . '</p>';
}
if (!mysql_errno($active_db)) {
......@@ -126,7 +126,7 @@ function _db_query($query, $debug = 0) {
else {
// Indicate to drupal_error_handler that this is a database error.
${DB_ERROR} = TRUE;
trigger_error(check_plain(mysql_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
trigger_error(check_plain(mysql_error($active_db) . "\nquery: " . $query), E_USER_WARNING);
return FALSE;
}
}
......@@ -239,7 +239,7 @@ function db_query_range($query) {
}
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
$query .= ' LIMIT '. (int)$from .', '. (int)$count;
$query .= ' LIMIT ' . (int)$from . ', ' . (int)$count;
return _db_query($query);
}
......@@ -280,7 +280,7 @@ function db_query_temporary($query) {
$tablename = array_pop($args);
array_shift($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' Engine=HEAP SELECT', db_prefix_tables($query));
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=HEAP SELECT', db_prefix_tables($query));
if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
$args = $args[0];
}
......@@ -299,7 +299,7 @@ function db_query_temporary($query) {
*/
function db_encode_blob($data) {
global $active_db;
return "'". mysql_real_escape_string($data, $active_db) ."'";
return "'" . mysql_real_escape_string($data, $active_db) . "'";
}
/**
......@@ -326,7 +326,7 @@ function db_escape_string($text) {
* Lock a table.
*/
function db_lock_table($table) {
db_query('LOCK TABLES {'. db_escape_table($table) .'} WRITE');
db_query('LOCK TABLES {' . db_escape_table($table) . '} WRITE');
}
/**
......@@ -340,14 +340,14 @@ function db_unlock_tables() {
* Check if a table exists.
*/
function db_table_exists($table) {
return (bool) db_fetch_object(db_query("SHOW TABLES LIKE '{". db_escape_table($table) ."}'"));
return (bool) db_fetch_object(db_query("SHOW TABLES LIKE '{" . db_escape_table($table) . "}'"));
}
/**
* Check if a column exists in the given table.
*/
function db_column_exists($table, $column) {
return (bool) db_fetch_object(db_query("SHOW COLUMNS FROM {". db_escape_table($table) ."} LIKE '". db_escape_table($column) ."'"));
return (bool) db_fetch_object(db_query("SHOW COLUMNS FROM {" . db_escape_table($table) . "} LIKE '" . db_escape_table($column) . "'"));
}
/**
......@@ -362,9 +362,9 @@ function db_column_exists($table, $column) {
* @return SQL query with the DISTINCT wrapper surrounding the given table.field.
*/
function db_distinct_field($table, $field, $query) {
$field_to_select = 'DISTINCT('. $table .'.'. $field .')';
$field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
// (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
return preg_replace('/(SELECT.*)(?:'. $table .'\.|\s)(?<!DISTINCT\()(?<!DISTINCT\('. $table .'\.)'. $field .'(.*FROM )/AUsi', '\1 '. $field_to_select .'\2', $query);
return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
}
/**
......
......@@ -104,13 +104,13 @@ function _db_query($query, $debug = 0) {
$name = $user->uid ? $user->name : variable_get('anonymous', 'Anonymous');
// str_replace() to prevent SQL injection via username or anonymous name.
$name = str_replace(array('*', '/'), '', $name);
$query = '/* '. $name .' : '. $bt[2]['function'] .' */ '. $query;
$query = '/* ' . $name . ' : ' . $bt[2]['function'] . ' */ ' . $query;
}
$result = mysqli_query($active_db, $query);
if (variable_get('dev_query', 0)) {
$query = $bt[2]['function'] ."\n". $query;
$query = $bt[2]['function'] . "\n" . $query;
list($usec, $sec) = explode(' ', microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
......@@ -118,7 +118,7 @@ function _db_query($query, $debug = 0) {
}
if ($debug) {
print '<p>query: '. $query .'<br />error:'. mysqli_error($active_db) .'</p>';
print '<p>query: ' . $query . '<br />error:' . mysqli_error($active_db) . '</p>';
}
if (!mysqli_errno($active_db)) {
......@@ -127,7 +127,7 @@ function _db_query($query, $debug = 0) {
else {
// Indicate to drupal_error_handler that this is a database error.
${DB_ERROR} = TRUE;
trigger_error(check_plain(mysqli_error($active_db) ."\nquery: ". $query), E_USER_WARNING);
trigger_error(check_plain(mysqli_error($active_db) . "\nquery: " . $query), E_USER_WARNING);
return FALSE;
}
}
......@@ -242,7 +242,7 @@ function db_query_range($query) {
}
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
$query .= ' LIMIT '. (int)$from .', '. (int)$count;
$query .= ' LIMIT ' . (int)$from . ', ' . (int)$count;
return _db_query($query);
}
......@@ -283,7 +283,7 @@ function db_query_temporary($query) {
$tablename = array_pop($args);
array_shift($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' Engine=HEAP SELECT', db_prefix_tables($query));
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE ' . $tablename . ' Engine=HEAP SELECT', db_prefix_tables($query));
if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax