Index: doc/TODO =================================================================== RCS file: /projects/cvsroot/pgsql/doc/TODO,v retrieving revision 1.2180 diff -c -r1.2180 TODO *** doc/TODO 5 May 2007 15:40:01 -0000 1.2180 --- doc/TODO 7 May 2007 18:45:19 -0000 *************** *** 1436,1442 **** * Remove or relicense modules that are not under the BSD license, if possible * %Remove memory/file descriptor freeing before ereport(ERROR) * Acquire lock on a relation before building a relcache entry for it - * %Promote debug_query_string into a server-side function current_query() * Allow cross-compiling by generating the zic database on the target system * Improve NLS maintenance of libpgport messages linked onto applications * Allow ecpg to work with MSVC and BCC --- 1436,1441 ---- Index: doc/src/FAQ/TODO.html =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/FAQ/TODO.html,v retrieving revision 1.681 diff -c -r1.681 TODO.html *** doc/src/FAQ/TODO.html 5 May 2007 15:40:01 -0000 1.681 --- doc/src/FAQ/TODO.html 7 May 2007 18:45:20 -0000 *************** *** 1278,1284 ****
  • Remove or relicense modules that are not under the BSD license, if possible
  • %Remove memory/file descriptor freeing before ereport(ERROR)
  • Acquire lock on a relation before building a relcache entry for it -
  • %Promote debug_query_string into a server-side function current_query()
  • Allow cross-compiling by generating the zic database on the target system
  • Improve NLS maintenance of libpgport messages linked onto applications
  • Allow ecpg to work with MSVC and BCC --- 1278,1283 ---- Index: doc/src/sgml/func.sgml =================================================================== RCS file: /projects/cvsroot/pgsql/doc/src/sgml/func.sgml,v retrieving revision 1.379 diff -c -r1.379 func.sgml *** doc/src/sgml/func.sgml 7 May 2007 07:53:26 -0000 1.379 --- doc/src/sgml/func.sgml 7 May 2007 18:45:29 -0000 *************** *** 10233,10238 **** --- 10233,10244 ---- + current_query + name + text of the currently executing query + + + inet_client_addr() inet address of the remote connection Index: src/backend/utils/adt/misc.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/misc.c,v retrieving revision 1.56 diff -c -r1.56 misc.c *** src/backend/utils/adt/misc.c 5 Jan 2007 22:19:41 -0000 1.56 --- src/backend/utils/adt/misc.c 7 May 2007 18:45:30 -0000 *************** *** 29,34 **** --- 29,35 ---- #include "storage/pmsignal.h" #include "storage/procarray.h" #include "utils/builtins.h" + #include "tcop/tcopprot.h" #define atooid(x) ((Oid) strtoul((x), NULL, 10)) *************** *** 72,77 **** --- 73,103 ---- /* + * current_query() + * Expose the current query to the user (useful in stored procedures) + */ + Datum + current_query(PG_FUNCTION_ARGS) + { + int len; + text *result; + + if (debug_query_string) + { + len = strlen(debug_query_string); + result = (text *) palloc(VARHDRSZ + len); + SET_VARSIZE(result, VARHDRSZ + len); + memcpy((void *) VARDATA(result), (void *) debug_query_string, len); + + PG_RETURN_TEXT_P(result); + } + else + { + PG_RETURN_NULL(); + } + } + + /* * Functions to send signals to other backends. */ static bool --- 392,397 ---- Index: src/include/catalog/pg_proc.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/catalog/pg_proc.h,v retrieving revision 1.454 diff -c -r1.454 pg_proc.h *** src/include/catalog/pg_proc.h 2 Apr 2007 03:49:40 -0000 1.454 --- src/include/catalog/pg_proc.h 7 May 2007 18:45:38 -0000 *************** *** 1142,1147 **** --- 1142,1149 ---- DATA(insert OID = 861 ( current_database PGNSP PGUID 12 1 0 f f t f i 0 19 "" _null_ _null_ _null_ current_database - _null_ )); DESCR("returns the current database"); + DATA(insert OID = 868 ( current_query PGNSP PGUID 12 1 0 f f f f v 0 2278 "" _null_ _null_ _null_ current_query - _null_ )); + DESCR("returns the currently executing query"); DATA(insert OID = 862 ( int4_mul_cash PGNSP PGUID 12 1 0 f f t f i 2 790 "23 790" _null_ _null_ _null_ int4_mul_cash - _null_ )); DESCR("multiply"); Index: src/include/utils/builtins.h =================================================================== RCS file: /projects/cvsroot/pgsql/src/include/utils/builtins.h,v retrieving revision 1.291 diff -c -r1.291 builtins.h *** src/include/utils/builtins.h 2 Apr 2007 03:49:41 -0000 1.291 --- src/include/utils/builtins.h 7 May 2007 18:45:39 -0000 *************** *** 421,426 **** --- 421,427 ---- extern Datum nullvalue(PG_FUNCTION_ARGS); extern Datum nonnullvalue(PG_FUNCTION_ARGS); extern Datum current_database(PG_FUNCTION_ARGS); + extern Datum current_query(PG_FUNCTION_ARGS); extern Datum pg_cancel_backend(PG_FUNCTION_ARGS); extern Datum pg_reload_conf(PG_FUNCTION_ARGS); extern Datum pg_tablespace_databases(PG_FUNCTION_ARGS);