File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 33-- complain if script is sourced in psql, rather than via CREATE EXTENSION
44\echo Use " CREATE EXTENSION pg_show_plans" to load this file. \quit
55
6- CREATE FUNCTION my_function ()
6+ CREATE FUNCTION my_function (integer , text )
77RETURNS cstring
88AS ' MODULE_PATHNAME'
99LANGUAGE C;
Original file line number Diff line number Diff line change 22#include "fmgr.h"
33
44#include "funcapi.h"
5+ #include "utils/builtins.h"
56#include "miscadmin.h"
67#include "storage/ipc.h"
78#include "storage/lwlock.h"
89#include "storage/shmem.h"
10+ #include "utils/elog.h"
911
1012/* Constants and Macros */
1113PG_MODULE_MAGIC ;
@@ -116,5 +118,34 @@ pgsw_shmem_startup(void)
116118Datum
117119my_function (PG_FUNCTION_ARGS )
118120{
119- PG_RETURN_CSTRING ("Hello from my_function()!" );
121+ const Oid user_id = PG_GETARG_INT32 (0 );
122+ const char * cmd_type = text_to_cstring (PG_GETARG_TEXT_PP (1 ));
123+
124+ pgswHashKey hash_key ;
125+ pgswHashEntry * hash_entry ;
126+
127+ pgswHashEntry * test_entry ;
128+
129+ hash_key .userId = user_id ;
130+ hash_entry = (pgswHashEntry * )hash_search (pgsw_hash ,
131+ & hash_key ,
132+ HASH_ENTER_NULL ,
133+ NULL );
134+ hash_entry -> denyCmd [CMD_DELETE ] = true;
135+ hash_entry -> denyCmd [CMD_UNKNOWN ] = true;
136+ hash_entry -> denyCmd [CMD_SELECT ] = false;
137+
138+ test_entry = (pgswHashEntry * )hash_search (pgsw_hash ,
139+ & hash_key ,
140+ HASH_ENTER_NULL ,
141+ NULL );
142+ if (test_entry -> denyCmd [CMD_DELETE ] && test_entry -> denyCmd [CMD_UNKNOWN ])
143+ {
144+ elog (NOTICE , "everything is fine!" );
145+ }
146+ if (!test_entry -> denyCmd [CMD_SELECT ])
147+ {
148+ elog (NOTICE , "DEFINITELY OK!" );
149+ }
150+ PG_RETURN_CSTRING (cmd_type );
120151}
You can’t perform that action at this time.
0 commit comments