summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2002-05-20 01:02:29 +0000
committerYasuo Ohgaki <yohgaki@php.net>2002-05-20 01:02:29 +0000
commitc6873da40164d9bdbeaf8f441cd5c3f7ce95d817 (patch)
treef5311cc11468dcb3f622938c5561ff8d1800dad0 /ext/pgsql
parent2c9f3460dc87dc86d84c197e096b8e9e61d1c591 (diff)
downloadphp-git-c6873da40164d9bdbeaf8f441cd5c3f7ce95d817.tar.gz
Improve large object performance. pg_lo_read() and pg_lo_read_all() should perform
much better now. Fixed Old API support for pg_lo_import().
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 6e3c186e54..2ec9304914 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -1851,12 +1851,14 @@ PHP_FUNCTION(pg_lo_close)
}
/* }}} */
+#define PGSQL_LO_READ_BUF_SIZE 8192
+
/* {{{ proto string pg_lo_read(resource large_object [, int len])
Read a large object */
PHP_FUNCTION(pg_lo_read)
{
zval **pgsql_id, **len;
- int buf_len = 1024, nbytes;
+ int buf_len = PGSQL_LO_READ_BUF_SIZE, nbytes;
char *buf;
pgLofp *pgsql;
@@ -1925,9 +1927,8 @@ PHP_FUNCTION(pg_lo_read_all)
zval **pgsql_id;
int i, tbytes;
volatile int nbytes;
- char buf[8192];
+ char buf[PGSQL_LO_READ_BUF_SIZE];
pgLofp *pgsql;
- int output=1;
switch(ZEND_NUM_ARGS()) {
case 1:
@@ -1943,11 +1944,9 @@ PHP_FUNCTION(pg_lo_read_all)
ZEND_FETCH_RESOURCE(pgsql, pgLofp *, pgsql_id, -1, "PostgreSQL large object", le_lofp);
tbytes = 0;
- while ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, 8192))>0) {
- for(i=0; i<nbytes; i++) {
- if (output) { (void) PUTC(buf[i]); }
- }
- tbytes += i;
+ while ((nbytes = lo_read((PGconn *)pgsql->conn, pgsql->lofd, buf, PGSQL_LO_READ_BUF_SIZE))>0) {
+ php_body_write(buf, nbytes TSRMLS_CC);
+ tbytes += nbytes;
}
RETURN_LONG(tbytes);
}
@@ -1974,7 +1973,7 @@ PHP_FUNCTION(pg_lo_import)
CHECK_DEFAULT_LINK(id);
}
else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc TSRMLS_CC,
- "rs", &pgsql_link, &file_in, &name_len) == SUCCESS) {
+ "sr", &file_in, &name_len, &pgsql_link ) == SUCCESS) {
php_error(E_NOTICE, "Old API for %s() is used.", get_active_function_name(TSRMLS_C));
}
else {