Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In _db_query(), when a query error happens, the error messages are displayed twice. First at the point of the pg_query()/mysql_query() call and then at the track_errors() call. Since there is an error handling/reporting process in place, the query calls should suppress error output by placing @'s in front of them. The attached patch does that for both the database.mysql.inc and database.pgsql.inc files.
Comment | File | Size | Author |
---|---|---|---|
database.silence.query.diff | 1.2 KB | danielc | |
Comments
Comment #1
danielc CreditAttribution: danielc commentedCan this please be applied to 4-6 and HEAD?
Comment #2
Dries CreditAttribution: Dries commentedHow can we reproduce this? No matter what I do, I only see each error reported once.
(We try to avoid the use of @ to surpress errors.)
Comment #3
danielc CreditAttribution: danielc commentedAh! It's just happening with PostgreSQL. I noticed it there and assumed the same issue existed with MySQL. Sorry for the confusion. Please commit to database.pgsql.inc only.
Comment #4
danielc CreditAttribution: danielc commentedAdd "pgsql" to title.
Test script:
<?php
// so we don't need to include bootstrap
function variable_get($name, $default) {
return $default;
}
ini_set('include_path', 'd:/webroot/drupal/includes');
require_once 'database.pgsql.inc';
$db_url = 'pgsql://usr:pw@localhost/drupal';
$active_db = db_connect($db_url);
_db_query('a REALLY bad query');
Comment #5
danielc CreditAttribution: danielc commentedThe test script got ripped out. Perhaps because I used an opening PHP tag w/o a closing one. Let's try again:
Comment #6
Dries CreditAttribution: Dries commentedWe're not fond of using '@'. I'll await feedback from Adrian, who maintains the PostgreSQL port. He might be able to suggest an alternative/better fix.
Comment #7
danielc CreditAttribution: danielc commentedJudicious use of @ is important. For example, they're a bad idea when including files. At the same time, there is no downside to suppressing error messages for function calls when failures of the given function are handled -- which they are in this case.
Comment #8
Cvbge CreditAttribution: Cvbge commentedTo test this I've created simple block:
When the block was displayed the error was logged and displayed too:
But prefixing pg_query() with @ didn't change anything, the error was still displayed on the page.
Comment #9
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedDowngrading to minor and setting to "needs work".
Comment #10
Jaza CreditAttribution: Jaza commentedMoving to 6.x-dev.
Comment #11
klando CreditAttribution: klando commenteddb_query("set client_min_messages=FATAL");
will remove part of the message (there is other level of error messages)
warning: pg_query() [function.pg-query]: Query failed: in /usr/share/drupal6/includes/database.pgsql.inc on line 155.
user warning: query: HELLO WORLD in /usr/share/drupal6/includes/common.inc(1478) : eval()'d code on line 4.
I hope it can be set on pg_connect or around
Comment #12
dpearcefl CreditAttribution: dpearcefl commentedIs this still a problem in current D6?
Comment #13
dpearcefl CreditAttribution: dpearcefl commentedComment #14
aspilicious CreditAttribution: aspilicious commentedI'm going to close this as it is rly rly rly old and nobody reported back.
Please reopen if needed :)