diff options
| author | Zeev Suraski <zeev@php.net> | 2000-05-31 20:40:28 +0000 |
|---|---|---|
| committer | Zeev Suraski <zeev@php.net> | 2000-05-31 20:40:28 +0000 |
| commit | a00a1d12eac157905d6f67361814a695687a7d32 (patch) | |
| tree | b1675dbb6759e08b1848e64ac38c0d65c755d012 /ext/pgsql/pgsql.c | |
| parent | 7bb2af41e36bc3e39f058dc293578a0a260f40c3 (diff) | |
| download | php-git-a00a1d12eac157905d6f67361814a695687a7d32.tar.gz | |
@- Added pg_trace() and pg_untrace (Dominic J. Eidson & Zeev)
Diffstat (limited to 'ext/pgsql/pgsql.c')
| -rw-r--r-- | ext/pgsql/pgsql.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 09988311e5..fbe0d6fe4c 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -48,6 +48,8 @@ function_entry pgsql_functions[] = { PHP_FE(pg_cmdtuples, NULL) PHP_FE(pg_dbname, NULL) PHP_FE(pg_errormessage, NULL) + PHP_FE(pg_trace, NULL) + PHP_FE(pg_untrace, NULL) PHP_FE(pg_options, NULL) PHP_FE(pg_port, NULL) PHP_FE(pg_tty, NULL) @@ -1103,6 +1105,91 @@ PHP_FUNCTION(pg_getlastoid) } /* }}} */ + +/* {{{ proto bool pg_trace(string filename [, string mode [, resource connection]]) + Enable tracing a PostgresSQL connection */ +PHP_FUNCTION(pg_trace) +{ + zval **z_filename, **z_mode, **z_pgsql_link; + int id = -1; + PGconn *pgsql; + char *mode = "w"; + int issock, socketd; + FILE *fp; + PGLS_FETCH(); + + id = PGG(default_link); + + switch (ZEND_NUM_ARGS()) { + case 1: + if (zend_get_parameters_ex(1, &z_filename)==FAILURE) { + RETURN_FALSE; + } + break; + case 2: + if (zend_get_parameters_ex(2, &z_filename, &z_mode)==FAILURE) { + RETURN_FALSE; + } + convert_to_string_ex(z_mode); + mode = Z_STRVAL_PP(z_mode); + break; + case 3: + if (zend_get_parameters_ex(3, &z_filename, &z_mode, &z_pgsql_link)==FAILURE) { + RETURN_FALSE; + } + convert_to_string_ex(z_mode); + mode = Z_STRVAL_PP(z_mode); + break; + default: + ZEND_WRONG_PARAM_COUNT(); + break; + } + + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, z_pgsql_link, id, "PostgreSQL link", le_link, le_plink); + convert_to_string_ex(z_filename); + + fp = php_fopen_wrapper(Z_STRVAL_PP(z_filename), mode, ENFORCE_SAFE_MODE, &issock, &socketd, NULL); + + if (!fp) { + php_error(E_WARNING, "Unable to open %s for logging", Z_STRVAL_PP(z_filename)); + RETURN_FALSE; + } + + PQtrace(pgsql, fp); + ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_fopen()); + RETURN_TRUE; +} + + +/* {{{ proto bool pg_untrace([int connection]) + Disable tracing of a PostgreSQL connection */ +PHP_FUNCTION(pg_untrace) +{ + zval **pgsql_link; + int id = -1; + PGconn *pgsql; + PGLS_FETCH(); + + switch (ZEND_NUM_ARGS()) { + case 0: + id = PGG(default_link); + break; + case 1: + if (zend_get_parameters_ex(1, &pgsql_link)==FAILURE) { + RETURN_FALSE; + } + break; + default: + ZEND_WRONG_PARAM_COUNT(); + break; + } + + ZEND_FETCH_RESOURCE2(pgsql, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink); + PQuntrace(pgsql); + RETURN_TRUE; +} + + /* {{{ proto int pg_locreate(int connection) Create a large object */ PHP_FUNCTION(pg_locreate) |
