Hi !
I'm reading the source of PDO PostgreSQL driver and i see that there's
an empty function, _pdo_pgsql_notice, which is very interesting ! I
think that it is used when PostgreSQL throw Notices.
But, nothing is done...
I want to know if somebody know why the content of the function is
commented:
static void _pdo_pgsql_notice(pdo_dbh_t *dbh, const char message) /
{{{ /
{
/ pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; */
}
(line 98 of /etc/pdo_pgsql/pgsql_driver.c - PHP 5.2 - r272374)
How can I store the content of "message" into a field of the
PDOStatement ? I view that there's only a "pdo_dbh_t" param, I may just
store this message into a field of the PDO class ?
Thanks in advance.
Samuel.
To use PostgreSQL's Notices with PDO, i'm modifying the source for
trying to store into "errmsg" (which I can get with PDO::errorInfo) the
notice.
The "_pdo_pgsql_notice" function is called everytime that there's an
notice. The notice message is in the "message" var. This what i had
tried:
static void _pdo_pgsql_notice(pdo_dbh_t *dbh, const char message) /
{{{ */
{
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle
*)dbh->driver_data;
pdo_pgsql_error_info *einfo = &H->einfo;
einfo->errcode = 1;
if (einfo->errmsg) {
pefree(einfo->errmsg, dbh->is_persistent);
einfo->errmsg = NULL;
}
einfo->errmsg = _pdo_pgsql_trim_message(message,
dbh->is_persistent);
}
And in "pdo_pgsql_fetch_error_func", i've added an else condition to
view if errmsg is null are not...
if (einfo->errcode) {
add_next_index_long(info, einfo->errcode);
add_next_index_string(info, einfo->errmsg, 1);
} else {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC,
"einfo->errcode is false : %s , %s", einfo->errcode, einfo->errmsg);
}
And, I've a function which send some notices (when I throw exception
from "_pdo_pgsql_notice" with the "message" var, I see the notice ! :-)
But, einfo->errcode is null !
-> Fatal error: Uncaught exception 'PDOException' with message
'einfo->errcode is false : (null) , (null)'
in /etc/php-5.2.10/test/pgsql_notice.php:22
Stack trace:
#0 /etc/php-5.2.10/test/pgsql_notice.php(22): PDO->errorInfo()
#1 {main}
thrown in /etc/php-5.2.10/test/pgsql_notice.php on line 22
Is anyone can help me ?
Thanks a lot !
Samuel. (French)
Le mardi 06 octobre 2009 à 07:22 +0200, Samuel ROZE a écrit :
Hi !
I'm reading the source of PDO PostgreSQL driver and i see that there's
an empty function, _pdo_pgsql_notice, which is very interesting ! I
think that it is used when PostgreSQL throw Notices.
But, nothing is done...I want to know if somebody know why the content of the function is
commented:static void _pdo_pgsql_notice(pdo_dbh_t *dbh, const char message) /
{{{ /
{
/ pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; */
}(line 98 of /etc/pdo_pgsql/pgsql_driver.c - PHP 5.2 - r272374)
How can I store the content of "message" into a field of the
PDOStatement ? I view that there's only a "pdo_dbh_t" param, I may just
store this message into a field of the PDO class ?Thanks in advance.
Samuel.
Samuel ROZE ha scritto:
To use PostgreSQL's Notices with PDO, i'm modifying the source for
trying to store into "errmsg" (which I can get with PDO::errorInfo) the
notice.
I might find some time to look at it shortly. Not sure using "errmsg" is
appropriate though, as notices are usually returning additional
information, not error messages.
Please allow some time for me to check how they are currently dealt with
in the pgsql extension and to see how they can be implemented in the
PDO driver.
Cheers
Matteo Beccati
Hi,
I might find some time to look at it shortly. Not sure using "errmsg" is
appropriate though, as notices are usually returning additional
information, not error messages.
I think i'll have to make a "noticemsg" var, but I don't
know how implement a new "noticeInfo" (or somethink like
that) function to get this value. The better way is to
create a new array "notices" (or a function which returns an
array) into the PDOStatement, because the notice is
generally linked to the statement. But, sometimes not...
Please allow some time for me to check how they are currently dealt with
in the pgsql extension and to see how they can be implemented in the
PDO driver.
Actually, the PosgreSQL driver for PDO don't report
notices.. The content of "_pdo_pgsql_notice" is commented !
Thanks a lot for the time you passed/you'll pass !
Samuel.
Hi,
Please allow some time for me to check how they are currently dealt with
in the pgsql extension and to see how they can be implemented in the
PDO driver.Actually, the PosgreSQL driver for PDO don't report
notices.. The content of "_pdo_pgsql_notice" is commented !Thanks a lot for the time you passed/you'll pass !
Here's a proof of concept patch you can apply to the PHP_5_3 branch:
http://www.beccati.com/misc/php/pdo_pgsql_notices_php5_3.patch
I still need to clean it up a bit and discuss it with the team, but
here's how it currently works:
$db = new PDO(...);
$db->setAttribute(PDO::PGSQL_ATTR_ENABLE_NOTICES, true);
$db->exec($query); // works with $db->query() too
$aNotices = $db->pgsqlGetNotices();
And you will get an array of the notices raised by the last query.
To sum up:
- Notices are disabled by default, minimising the overhead
- Unlike the pgsql extension which returns the most recent one, multiple
notices can be fetched - A new query will reset the stored notices
- Available on the base class because
exec()
doesn't return a PDOStatement
Hope this helps
Cheers
Matteo Beccati
Thanks all lot for your work ! It is be what I want !
I'll view it this evening and I probably will transform it for PHP 5.2
(which is my version) and put it here.
At tonight ! :-)
Samuel.
Le mercredi 07 octobre 2009 à 00:31 +0200, Matteo Beccati a écrit :
Hi,
Please allow some time for me to check how they are currently dealt with
in the pgsql extension and to see how they can be implemented in the
PDO driver.Actually, the PosgreSQL driver for PDO don't report
notices.. The content of "_pdo_pgsql_notice" is commented !Thanks a lot for the time you passed/you'll pass !
Here's a proof of concept patch you can apply to the PHP_5_3 branch:
http://www.beccati.com/misc/php/pdo_pgsql_notices_php5_3.patch
I still need to clean it up a bit and discuss it with the team, but
here's how it currently works:$db = new PDO(...);
$db->setAttribute(PDO::PGSQL_ATTR_ENABLE_NOTICES, true);$db->exec($query); // works with $db->query() too
$aNotices = $db->pgsqlGetNotices();And you will get an array of the notices raised by the last query.
To sum up:
- Notices are disabled by default, minimising the overhead
- Unlike the pgsql extension which returns the most recent one, multiple
notices can be fetched- A new query will reset the stored notices
- Available on the base class because
exec()
doesn't return a PDOStatementHope this helps
Cheers
Matteo Beccati
Well, i've show the patch this morning... It's great ! The allocation of
the HashTable when use setAttribute might not be really a good job but
other, in my mind, is !
See you afternoon for PHP 5.2 path. :-)
Samuel.
Le mercredi 07 octobre 2009 à 00:31 +0200, Matteo Beccati a écrit :
Hi,
Please allow some time for me to check how they are currently dealt with
in the pgsql extension and to see how they can be implemented in the
PDO driver.Actually, the PosgreSQL driver for PDO don't report
notices.. The content of "_pdo_pgsql_notice" is commented !Thanks a lot for the time you passed/you'll pass !
Here's a proof of concept patch you can apply to the PHP_5_3 branch:
http://www.beccati.com/misc/php/pdo_pgsql_notices_php5_3.patch
I still need to clean it up a bit and discuss it with the team, but
here's how it currently works:$db = new PDO(...);
$db->setAttribute(PDO::PGSQL_ATTR_ENABLE_NOTICES, true);$db->exec($query); // works with $db->query() too
$aNotices = $db->pgsqlGetNotices();And you will get an array of the notices raised by the last query.
To sum up:
- Notices are disabled by default, minimising the overhead
- Unlike the pgsql extension which returns the most recent one, multiple
notices can be fetched- A new query will reset the stored notices
- Available on the base class because
exec()
doesn't return a PDOStatementHope this helps
Cheers
Hi,
Well, i've show the patch this morning... It's great ! The allocation of
the HashTable when use setAttribute might not be really a good job but
other, in my mind, is !
Yeah, I'm not very happy about it either. It was just a proof of concept
after all ;)
Cheers
Matteo Beccati
Le mercredi 07 octobre 2009 à 07:57 +0200, Samuel ROZE a écrit :
Well, i've show the patch this morning... It's great ! The allocation of
the HashTable when use setAttribute might not be really a good job but
other, in my mind, is !See you afternoon for PHP 5.2 path. :-)
Well, I've done a patch for PHP 5.2 branch:
http://www.d-sites.com/wp-content/uploads/2009/10/pdo_pgsql_notices_php5.2.patch
It is working but there are two memory leaks when running with CGI:
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(105) : Freeing
0x01C43A80 (24 bytes), script=pgsql_notice.php
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(55) : Freeing
0x01C43AF0 (22 bytes), script=pgsql_notice.php
=== Total 2 memory leaks detected ===
Joined, the pgsql_driver.c file.
hi,
The idea is good and matches my thoughts on this topic.
Some comments:
- no driver specific API, so getNotices instaed of get<driver>Notices
- common attribute name as well and maybe a better naming ATTR_LOG_NOTICES?
5.2 is also only for security fixes. Can you try to produce a patch
against 5.3 and trunk please?
Cheers,
Le mercredi 07 octobre 2009 à 07:57 +0200, Samuel ROZE a écrit :
Well, i've show the patch this morning... It's great ! The allocation of
the HashTable when use setAttribute might not be really a good job but
other, in my mind, is !See you afternoon for PHP 5.2 path. :-)
Well, I've done a patch for PHP 5.2 branch:
http://www.d-sites.com/wp-content/uploads/2009/10/pdo_pgsql_notices_php5.2.patchIt is working but there are two memory leaks when running with CGI:
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(105) : Freeing
0x01C43A80 (24 bytes), script=pgsql_notice.php
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(55) : Freeing
0x01C43AF0 (22 bytes), script=pgsql_notice.php
=== Total 2 memory leaks detected ===Joined, the pgsql_driver.c file.
--
--
Pierre
Le mercredi 07 octobre 2009 à 15:47 +0200, Pierre Joye a écrit :
The idea is good and matches my thoughts on this topic.
Some comments:
- no driver specific API, so getNotices instaed of get<driver>Notices
It was discuss, it need hours to implement this method to all
drivers...
- common attribute name as well and maybe a better naming ATTR_LOG_NOTICES?
Why not, but it must be in the same time that the last question
5.2 is also only for security fixes. Can you try to produce a patch
against 5.3 and trunk please?
There's the patch of Matteo Beccati at this address for PHP 5.3:
http://www.beccati.com/misc/php/pdo_pgsql_notices_php5_3.patch
I can make another for the trunk, why not :-). I'll probably try to make
this functionality as global today or tomorrow.
Thanks for your feedback.
Samuel.
Cheers,
Le mercredi 07 octobre 2009 à 07:57 +0200, Samuel ROZE a écrit :
Well, i've show the patch this morning... It's great ! The allocation of
the HashTable when use setAttribute might not be really a good job but
other, in my mind, is !See you afternoon for PHP 5.2 path. :-)
Well, I've done a patch for PHP 5.2 branch:
http://www.d-sites.com/wp-content/uploads/2009/10/pdo_pgsql_notices_php5.2.patchIt is working but there are two memory leaks when running with CGI:
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(105) : Freeing
0x01C43A80 (24 bytes), script=pgsql_notice.php
[Wed Oct 7 15:20:10 2009] Script: 'pgsql_notice.php'
/usr/src/php-5.2.10/ext/pdo_pgsql/pgsql_driver.c(55) : Freeing
0x01C43AF0 (22 bytes), script=pgsql_notice.php
=== Total 2 memory leaks detected ===Joined, the pgsql_driver.c file.
Samuel ROZE ha scritto:
Le mercredi 07 octobre 2009 à 15:47 +0200, Pierre Joye a écrit :
5.2 is also only for security fixes. Can you try to produce a patch
against 5.3 and trunk please?There's the patch of Matteo Beccati at this address for PHP 5.3:
http://www.beccati.com/misc/php/pdo_pgsql_notices_php5_3.patchI can make another for the trunk, why not :-). I'll probably try to make
this functionality as global today or tomorrow.
Cool, I'll leave that to you and I'll make myself available for reviewing.
Cheers
Matteo Beccati