Re: [PHP-DEV] Modifications for Postgres driver

2001-06-19 Thread Jon Parise

On Tue, Jun 19, 2001 at 02:04:59AM +0200, Georg von Zezschwitz wrote:

 I found it as easy as expected to write a patch that
 makes Postgres driver behave like the other drivers, of
 cause with full backward compatibility by making the
 row number parameter optional.

Neat. =)
 
 Now, is there a chance to get this into the offical source?

Sure.  Just submit your patch to this list, and it will be
reviewed.  It looks like the PostgreSQL extension is currently
maintainer (primarily) by Jouni Ahto and Zeev, so you'll probably
want to get their stamp of appoval, too.
 
 Whom should I contact? I'm willing to update the documentation
 in English and German if the patch should be used - but where
 to I get it? Could anybody name me a person with CVS access?

A documentation update would also be very helpful.  If no one
else has time to look at your patch, I will (I'm an avid
PostgreSQL user), and I can commit it if no one else finds the
time.

-- 
Jon Parise ([EMAIL PROTECTED])  .  Rochester Inst. of Technology
http://www.csh.rit.edu/~jon/  :  Computer Science House Member

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Modifications for Postgres driver

2001-06-19 Thread Jon Parise

On Tue, Jun 19, 2001 at 04:28:42PM +0200, Georg von Zezschwitz wrote:

 Now, the patch for PHP 4.0.5 is attached, together with
 a description.
 
 Could anybody with CVS access test it / apply it?

I committed it earlier this afternoon.
 
 I think who writes the code should also do some documentation.
 I do not know the source format of the documentation and
 where to get it - could somebody mail me the Postgres-Doc-
 Sources?
 
It's in cvs, as part of the 'phpdoc' module.  I'd point you to
the cvs web interface, but it appears to be unavailable at the
moment.

-- 
Jon Parise ([EMAIL PROTECTED])  .  Rochester Inst. of Technology
http://www.csh.rit.edu/~jon/  :  Computer Science House Member

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Modifications for Postgres driver

2001-06-19 Thread Georg von Zezschwitz

Hi!

I wrote:
 What I disliked (like the PEAR people) is the missing of a
 row counter when fetching rows from Postgres result tables.
 
 The mysql/ODBC/Adabas/some-other - way is:
 
 $dbr = xxx_exec ($connection, $query);
 while (list ($a, $b, $c) = xxx_fetch_row ($dbr)) {
... // Great, I have my results
 }
 
 The traditional and only Postgres way is:
 
 $dbr = xxx_exec ($connection, $query); 
 $cnt = pg_num_rows ($dbr);
 for ($i = 0; $i  $cnt; $i++) {
   list ($a, $b, $c) = pg_fetch_row ($dbr, $i)
 }

Now, the patch for PHP 4.0.5 is attached, together with
a description.

Could anybody with CVS access test it / apply it?

I think who writes the code should also do some documentation.
I do not know the source format of the documentation and
where to get it - could somebody mail me the Postgres-Doc-
Sources?

Thanks a lot,


Georg

 snip - description --

The patch enables the Postgresql-driver to do the
row counting within the driver when iterating through
an array. It does this by adding a row counter to
the internal data structure of the postgres result
set.

Instead of writing:

  $dbr = pg_exec ($connection, $query);
  $cnt = pg_numrows ($dbr);
  for ($i = 0; $i  $cnt; $i++) {
list ($a, $b, $c) = pg_fetch_row ($dbr, $i)
...  // Got the data here
  }

one *can* write:

  $dbr = pg_exec ($connection, $query);
  while (list ($a, $b, $c) = pg_fetch_row ($dbr)) {
 ... // Great, I have my results
  } 

This unifies the behaviour with other PHP database drivers
and helps the PEAR-libary developers (see notes there).

Moreover, one can e.g. write:

  $dbr = pg_exec (SELECT MAX(id)+1 FROM table);
  // Try to get the new id 
  if (! ($newid = pg_result ($dbr, 0))) 
$newid = 1;  // No row found
  // Insert with the new id here

instead of verifying first if a row is available.


This is a description of the API change:

The following functions have a different syntax

PG_RESULT

Old syntax: pg_result (resultset, row, field)
New syntax: pg_result (resultset, [row,] field)

Change:
If row is ommited, the result is taken from the current data
row. If no row has been fetched yet, the first row will be
fetched. If there is no result row, false will be silently
returned without an error message.
Traditional behaviour is not affected.


PG_FETCH_ROW / PG_FETCH_ARRAY / PG_FETCH_OBJECT

Old syntax: pg_fetch_func (resultset, row [, resulttype])
New syntax: pg_fetch_func (resultset, [row [, resulttype]])

Change:
If row is ommited, the next row is fetched.
If row is ommited, and the last row is reached, no error will
be written, but silently false returned. Traditional behaviour
not affected.
It is not possible to ommit the row but to specify a resulttype.


PG_FIELDPRTLEN / PG_FIELDISNULL

Old syntax: pg_fieldfunc (resultset, row, field)
New syntax: pg_fieldfunc (resultset, [row,] field)

Change:
If row is ommited, the result is taken from the current data
row. If no row has been fetched yet, the first row will be
fetched. If there is no result row, false will be silently
returned without an error message.
Traditional behaviour is not affected.

 snip - patch --

diff -r -c php-4.0.5.orig/ext/pgsql/pgsql.c php-4.0.5/ext/pgsql/pgsql.c
*** php-4.0.5.orig/ext/pgsql/pgsql.cWed Apr  4 23:51:58 2001
--- php-4.0.5/ext/pgsql/pgsql.c Wed Jun 20 13:20:38 2001
***
*** 713,718 
--- 713,719 
pg_result = (pgsql_result_handle *) 
emalloc(sizeof(pgsql_result_handle));
pg_result-conn = pgsql;
pg_result-result = pgsql_result;
+   pg_result-row = -1;
ZEND_REGISTER_RESOURCE(return_value, pg_result, 
le_result);
/*
return_value-value.lval = 
zend_list_insert(pg_result,le_result);
***
*** 1010,1029 
zval **result, **row, **field=NULL;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
!   int field_offset;

!   if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, result, row, 
field)==FAILURE) {
WRONG_PARAM_COUNT;
}

ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, result, -1, PostgreSQL 
result, le_result);
  
pgsql_result = pg_result-result;
!   
!   convert_to_long_ex(row);
!   if (Z_LVAL_PP(row)  0 || Z_LVAL_PP(row) = PQntuples(pgsql_result)) {
!   php_error(E_WARNING,Unable to jump to row %d on PostgreSQL result 
index %d, Z_LVAL_PP(row), Z_LVAL_PP(result));
!   RETURN_FALSE;
}
switch(Z_TYPE_PP(field)) {
case IS_STRING:
--- 1011,1040 
zval **result, **row, **field=NULL;
PGresult *pgsql_result;
pgsql_result_handle *pg_result;
!   int field_offset, pgsql_row;

!   if ((ZEND_NUM_ARGS() != 3 ||