gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
7.3KB

  1. -- pldbg.sql
  2. -- This script creates the data types and functions defined by the PL debugger API
  3. --
  4. -- Copyright (c) 2004-2018 EnterpriseDB Corporation. All Rights Reserved.
  5. --
  6. -- Licensed under the Artistic License v2.0, see
  7. -- https://opensource.org/licenses/artistic-license-2.0
  8. -- for full details
  9. \echo Installing pldebugger as unpackaged objects. If you are using PostgreSQL
  10. \echo version 9.1 or above, use "CREATE EXTENSION pldbgapi" instead.
  11. CREATE TYPE breakpoint AS ( func OID, linenumber INTEGER, targetName TEXT );
  12. CREATE TYPE frame AS ( level INT, targetname TEXT, func OID, linenumber INTEGER, args TEXT );
  13. CREATE TYPE var AS ( name TEXT, varClass char, lineNumber INTEGER, isUnique bool, isConst bool, isNotNull bool, dtype OID, value TEXT );
  14. CREATE TYPE proxyInfo AS ( serverVersionStr TEXT, serverVersionNum INT, proxyAPIVer INT, serverProcessID INT );
  15. CREATE FUNCTION pldbg_oid_debug( functionOID OID ) RETURNS INTEGER AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  16. -- for backwards-compatibility
  17. CREATE FUNCTION plpgsql_oid_debug( functionOID OID ) RETURNS INTEGER AS $$ SELECT pldbg_oid_debug($1) $$ LANGUAGE sql STRICT;
  18. CREATE FUNCTION pldbg_abort_target( session INTEGER ) RETURNS SETOF boolean AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  19. CREATE FUNCTION pldbg_attach_to_port( portNumber INTEGER ) RETURNS INTEGER AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  20. CREATE FUNCTION pldbg_continue( session INTEGER ) RETURNS breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  21. CREATE FUNCTION pldbg_create_listener() RETURNS INTEGER AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  22. CREATE FUNCTION pldbg_deposit_value( session INTEGER, varName TEXT, lineNumber INTEGER, value TEXT ) RETURNS boolean AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  23. CREATE FUNCTION pldbg_drop_breakpoint( session INTEGER, func OID, linenumber INTEGER ) RETURNS boolean AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  24. CREATE FUNCTION pldbg_get_breakpoints( session INTEGER ) RETURNS SETOF breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  25. CREATE FUNCTION pldbg_get_source( session INTEGER, func OID ) RETURNS TEXT AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  26. CREATE FUNCTION pldbg_get_stack( session INTEGER ) RETURNS SETOF frame AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  27. CREATE FUNCTION pldbg_get_proxy_info( ) RETURNS proxyInfo AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  28. CREATE FUNCTION pldbg_get_variables( session INTEGER ) RETURNS SETOF var AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  29. CREATE FUNCTION pldbg_select_frame( session INTEGER, frame INTEGER ) RETURNS breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  30. CREATE FUNCTION pldbg_set_breakpoint( session INTEGER, func OID, linenumber INTEGER ) RETURNS boolean AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  31. CREATE FUNCTION pldbg_set_global_breakpoint( session INTEGER, func OID, linenumber INTEGER, targetPID INTEGER ) RETURNS boolean AS '$libdir/plugin_debugger' LANGUAGE C;
  32. CREATE FUNCTION pldbg_step_into( session INTEGER ) RETURNS breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  33. CREATE FUNCTION pldbg_step_over( session INTEGER ) RETURNS breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  34. CREATE FUNCTION pldbg_wait_for_breakpoint( session INTEGER ) RETURNS breakpoint AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  35. CREATE FUNCTION pldbg_wait_for_target( session INTEGER ) RETURNS INTEGER AS '$libdir/plugin_debugger' LANGUAGE C STRICT;
  36. /*
  37. * pldbg_get_target_info() function can be used to return information about
  38. * a function.
  39. *
  40. * Deprecated. This is used by the pgAdmin debugger GUI, but new applications
  41. * should just query the catalogs directly.
  42. */
  43. CREATE TYPE targetinfo AS ( target OID, schema OID, nargs INT, argTypes oidvector, targetName NAME, argModes "char"[], argNames TEXT[], targetLang OID, fqName TEXT, returnsSet BOOL, returnType OID,
  44. -- The following columns are only needed when running in an EnterpriseDB
  45. -- server. On PostgreSQL, we return just dummy values for them.
  46. --
  47. -- 'isFunc' and 'pkg' only make sense on EnterpriseDB. 'isfunc' is true
  48. -- if the function is a regular function, not a stored procedure or a
  49. -- function that was created implictly to back a trigger created with the
  50. -- Oracle-compatible CREATE TRIGGER syntax. If the function belongs to a
  51. -- package, 'pkg' is the package's OID, or 0 otherwise.
  52. --
  53. -- 'argDefVals' is a representation of the function's argument DEFAULTs.
  54. -- That would be nice to have on PostgreSQL as well. Unfortunately our
  55. -- current implementation relies on an EDB-only function to get that
  56. -- information, so we cannot just use it as is. TODO: rewrite that using
  57. -- pg_get_expr(pg_proc.proargdefaults).
  58. isFunc BOOL,
  59. pkg OID,
  60. argDefVals TEXT[]
  61. );
  62. -- Create the pldbg_get_target_info() function. We use an inline code block
  63. -- so that we can check and create it slightly differently if running on
  64. -- an EnterpriseDB server.
  65. DO $do$
  66. declare
  67. isedb bool;
  68. createstmt text;
  69. begin
  70. isedb = (SELECT version() LIKE '%EnterpriseDB%');
  71. createstmt := $create_stmt$
  72. CREATE FUNCTION pldbg_get_target_info(signature text, targetType "char") returns targetinfo AS $$
  73. SELECT p.oid AS target,
  74. pronamespace AS schema,
  75. pronargs::int4 AS nargs,
  76. -- The returned argtypes column is of type oidvector, but unlike
  77. -- proargtypes, it's supposed to include OUT params. So we
  78. -- essentially have to return proallargtypes, converted to an
  79. -- oidvector. There is no oid[] -> oidvector cast, so we have to
  80. -- do it via text.
  81. CASE WHEN proallargtypes IS NOT NULL THEN
  82. translate(proallargtypes::text, ',{}', ' ')::oidvector
  83. ELSE
  84. proargtypes
  85. END AS argtypes,
  86. proname AS targetname,
  87. proargmodes AS argmodes,
  88. proargnames AS proargnames,
  89. prolang AS targetlang,
  90. quote_ident(nspname) || '.' || quote_ident(proname) AS fqname,
  91. proretset AS returnsset,
  92. prorettype AS returntype,
  93. $create_stmt$;
  94. -- Add the three EDB-columns to the query (as dummies if we're installing
  95. -- to PostgreSQL)
  96. IF isedb THEN
  97. createstmt := createstmt ||
  98. $create_stmt$
  99. p.protype='0' AS isfunc,
  100. CASE WHEN n.nspparent <> 0 THEN n.oid ELSE 0 END AS pkg,
  101. edb_get_func_defvals(p.oid) AS argdefvals
  102. $create_stmt$;
  103. ELSE
  104. createstmt := createstmt ||
  105. $create_stmt$
  106. 't'::bool AS isfunc,
  107. 0::oid AS pkg,
  108. NULL::text[] AS argdefvals
  109. $create_stmt$;
  110. END IF;
  111. -- End of conditional part
  112. createstmt := createstmt ||
  113. $create_stmt$
  114. FROM pg_proc p, pg_namespace n
  115. WHERE p.pronamespace = n.oid
  116. AND p.oid = $1::oid
  117. -- We used to support querying by function name or trigger name/oid as well,
  118. -- but that was never used in the client, so the support for that has been
  119. -- removed. The targeType argument remains as a legacy of that. You're
  120. -- expected to pass 'o' as target type, but it doesn't do anything.
  121. AND $2 = 'o'
  122. $$ LANGUAGE SQL;
  123. $create_stmt$;
  124. execute createstmt;
  125. -- Add a couple of EDB specific functions
  126. IF isedb THEN
  127. CREATE FUNCTION edb_oid_debug(functionOID oid) RETURNS integer AS $$
  128. select pldbg_oid_debug($1);
  129. $$ LANGUAGE SQL;
  130. CREATE FUNCTION pldbg_get_pkg_cons(packageOID oid) RETURNS oid AS $$
  131. select oid from pg_proc where pronamespace=$1 and proname='cons';
  132. $$ LANGUAGE SQL;
  133. END IF;
  134. end;
  135. $do$;
上海开阖软件有限公司 沪ICP备12045867号-1