pgsql _db_query() shows each query error twice

danielc - April 4, 2005 - 04:27
Project:Drupal
Version:6.x-dev
Component:database system
Category:bug report
Priority:minor
Assigned:Unassigned
Status:needs work
Description

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.

AttachmentSizeStatusTest resultOperations
database.silence.query.diff1.2 KBIgnoredNoneNone

#1

danielc - April 8, 2005 - 00:43

Can this please be applied to 4-6 and HEAD?

#2

Dries - April 8, 2005 - 11:41

How 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.)

#3

danielc - April 8, 2005 - 13:36

Ah! 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.

#4

danielc - April 23, 2005 - 14:35
Title:_db_query() shows each query error twice» pgsql _db_query() shows each query error twice

Add "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');

#5

danielc - April 23, 2005 - 14:37

The test script got ripped out. Perhaps because I used an opening PHP tag w/o a closing one. Let's try again:

<?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://dropper:ak17q8l10@localhost/drupal';
$active_db = db_connect($db_url);
_db_query('a REALLY bad query');
?>

#6

Dries - April 25, 2005 - 18:02

We'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.

#7

danielc - April 25, 2005 - 18:40

Judicious 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.

#8

Cvbge - August 16, 2005 - 18:12

To test this I've created simple block:

<?php
echo "This is a test";
db_query("HELLO WORLD");
?>

When the block was displayed the error was logged and displayed too:
warning: pg_query(): Query failed: ERROR:  syntax error at or near "HELLO" at character 1 in ..../includes/database.pgsql.inc on line 45.

user error:
query: HELLO WORLD in ..../includes/database.pgsql.inc on line 62.

But prefixing pg_query() with @ didn't change anything, the error was still displayed on the page.

#9

killes@www.drop.org - January 17, 2006 - 15:30
Priority:normal» minor
Status:needs review» needs work

Downgrading to minor and setting to "needs work".

#10

Jaza - January 18, 2007 - 01:03
Version:x.y.z» 6.x-dev

Moving to 6.x-dev.

#11

klando - November 15, 2007 - 23:54

db_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

 
 

Drupal is a registered trademark of Dries Buytaert.