Commit a98905f5 authored by Dries's avatar Dries

- Patch #471800 by stella: more code style fixes.

parent 76957a25
......@@ -372,9 +372,11 @@ public function getComment($table, $column = NULL) {
if (isset($column)) {
$condition->condition('column_name', $column);
$condition->compile($this->connection);
// Don't use {} around information_schema table.
return db_query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField();
}
$condition->compile($this->connection);
// Don't use {} around information_schema table.
$comment = db_query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
// Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379
return preg_replace('/; InnoDB free:.*$/', '', $comment);
......
......@@ -51,6 +51,7 @@ public function queryTableInformation($table) {
'blob_fields' => array(),
'sequences' => array(),
);
// Don't use {} around information_schema table.
$result = db_query("SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default LIKE :default))", array(':schema' => $schema, ':table' => $table_name, ':default' => '%nextval%'));
foreach ($result as $column) {
if ($column->data_type == 'bytea') {
......@@ -603,6 +604,7 @@ protected function _createKeys(&$ret, $table, $new_keys) {
*/
public function getComment($table, $column = NULL) {
$table = $this->connection->prefixTables('{' . $table . '}');
// Don't use {} around pg_class, pg_attribute tables.
if (isset($column)) {
return db_query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($table, $column))->fetchField();
}
......
......@@ -187,6 +187,7 @@ public function tableExists($table) {
// concatination for conditionals like this however, we
// couldn't use db_select() here because it would prefix
// information_schema.tables and the query would fail.
// Don't use {} around information_schema table.
return db_query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
}
......@@ -206,6 +207,7 @@ public function findTables($table_expression) {
// concatination for conditionals like this however, we
// couldn't use db_select() here because it would prefix
// information_schema.tables and the query would fail.
// Don't use {} around information_schema table.
return db_query("SELECT table_name FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchAllKeyed(0, 0);
}
......@@ -220,6 +222,7 @@ public function columnExists($table, $column) {
// concatination for conditionals like this however, we
// couldn't use db_select() here because it would prefix
// information_schema.tables and the query would fail.
// Don't use {} around information_schema table.
return db_query("SELECT column_name FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchAllKeyed(0, 0);
}
......
......@@ -15,6 +15,7 @@
class DatabaseSchema_sqlite extends DatabaseSchema {
public function tableExists($table) {
// Don't use {} around sqlite_master table.
return (bool) $this->connection->query("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE '{" . $table . "}'", array(), array())->fetchField();
}
......@@ -564,6 +565,7 @@ public function fieldSetNoDefault(&$ret, $table, $field) {
* Array, both the keys and the values are the matching tables.
*/
public function findTables($table_expression) {
// Don't use {} around sqlite_master table.
$result = db_query("SELECT name FROM sqlite_master WHERE name LIKE :table_name", array(
':table_name' => $table_expression,
));
......
......@@ -457,7 +457,7 @@ function node_admin_content($form_state) {
function node_admin_nodes() {
// Enable language column if translation module is enabled
// or if we have any node with language.
$multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language != ''")->fetchField());
$multilanguage = (module_exists('translation') || db_query("SELECT COUNT(*) FROM {node} WHERE language <> ''")->fetchField());
// Build the sortable table header.
$header = array();
......
......@@ -341,10 +341,10 @@ function profile_view_profile(&$user) {
// Show private fields to administrators and people viewing their own account.
if (user_access('administer users') || $GLOBALS['user']->uid == $user->uid) {
$result = db_query('SELECT * FROM {profile_field} WHERE visibility != %d ORDER BY category, weight', PROFILE_HIDDEN);
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> %d ORDER BY category, weight', PROFILE_HIDDEN);
}
else {
$result = db_query('SELECT * FROM {profile_field} WHERE visibility != %d AND visibility != %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN);
$result = db_query('SELECT * FROM {profile_field} WHERE visibility <> %d AND visibility <> %d ORDER BY category, weight', PROFILE_PRIVATE, PROFILE_HIDDEN);
}
$fields = array();
......
......@@ -29,7 +29,7 @@ function profile_browse() {
// Compile a list of fields to show.
$fields = array();
$result = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid != %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
$result = db_query('SELECT name, title, type, weight, page FROM {profile_field} WHERE fid <> %d AND visibility = %d ORDER BY weight', $field->fid, PROFILE_PUBLIC_LISTINGS);
while ($record = db_fetch_object($result)) {
$fields[] = $record;
}
......@@ -55,7 +55,7 @@ function profile_browse() {
}
// Extract the affected users:
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_value} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access != 0 AND u.status != 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments)->fetchAllAssoc('uid');
$result = pager_query("SELECT u.uid, u.access FROM {users} u INNER JOIN {profile_value} v ON u.uid = v.uid WHERE v.fid = %d AND $query AND u.access <> 0 AND u.status <> 0 ORDER BY u.access DESC", 20, 0, NULL, $arguments)->fetchAllAssoc('uid');
// Load the users.
$users = user_load_multiple(array_keys($result));
......@@ -90,7 +90,7 @@ function profile_browse() {
}
// Extract the affected users:
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status != 0 AND access != 0 ORDER BY access DESC', 20, 0, NULL)->fetchAllAssoc('uid');
$result = pager_query('SELECT uid, access FROM {users} WHERE uid > 0 AND status <> 0 AND access <> 0 ORDER BY access DESC', 20, 0, NULL)->fetchAllAssoc('uid');
$users = user_load_multiple(array_keys($result));
$content = '';
foreach ($users as $account) {
......
......@@ -316,6 +316,7 @@ function system_install() {
\'SELECT greatest($1, greatest($2, $3));\'
LANGUAGE \'sql\''
);
// Don't use {} around pg_proc table.
if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchField()) {
db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
\'SELECT random();\'
......@@ -323,6 +324,7 @@ function system_install() {
);
}
// Don't use {} around pg_proc table.
if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'")->fetchField()) {
db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
\'SELECT $1 || $2;\'
......
......@@ -754,7 +754,7 @@ function user_admin_role() {
function user_admin_role_validate($form, &$form_state) {
if ($form_state['values']['name']) {
if ($form_state['values']['op'] == t('Save role')) {
$existing_role = (bool) db_query_range("SELECT 1 FROM {role} WHERE name = :name AND rid != :rid", array(':name' => $form_state['values']['name'], ':rid' => $form_state['values']['rid']), 0, 1)->fetchField();
$existing_role = (bool) db_query_range("SELECT 1 FROM {role} WHERE name = :name AND rid <> :rid", array(':name' => $form_state['values']['name'], ':rid' => $form_state['values']['rid']), 0, 1)->fetchField();
if ($existing_role) {
form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name'])));
}
......
......@@ -945,7 +945,7 @@ function user_user_validate(&$edit, &$account, $category = NULL) {
if ($error = user_validate_name($edit['name'])) {
form_set_error('name', $error);
}
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid != :uid AND LOWER(name) = LOWER(:name)", array(':uid' => $uid, ':name' => $edit['name']), 0, 1)->fetchField()) {
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:name)", array(':uid' => $uid, ':name' => $edit['name']), 0, 1)->fetchField()) {
form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
}
}
......@@ -954,7 +954,7 @@ function user_user_validate(&$edit, &$account, $category = NULL) {
if ($error = user_validate_mail($edit['mail'])) {
form_set_error('mail', $error);
}
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid != :uid AND LOWER(mail) = LOWER(:mail)", array(':uid' => $uid, ':mail' => $edit['mail']), 0, 1)->fetchField()) {
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(mail) = LOWER(:mail)", array(':uid' => $uid, ':mail' => $edit['mail']), 0, 1)->fetchField()) {
// Format error message dependent on whether the user is logged in or not.
if ($GLOBALS['user']->uid) {
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $edit['mail'])));
......@@ -1117,7 +1117,7 @@ function user_block_view($delta = '') {
case 'new':
if (user_access('access content')) {
// Retrieve a list of new users who have subsequently accessed the site successfully.
$items = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
$output = theme('user_list', $items);
$block['subject'] = t('Who\'s new');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment