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 3
3
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4
4
\echo Use " CREATE EXTENSION pg_show_plans" to load this file. \quit
5
5
6
- CREATE FUNCTION my_function ()
6
+ CREATE FUNCTION my_function (integer , text )
7
7
RETURNS cstring
8
8
AS ' MODULE_PATHNAME'
9
9
LANGUAGE C;
Original file line number Diff line number Diff line change 2
2
#include "fmgr.h"
3
3
4
4
#include "funcapi.h"
5
+ #include "utils/builtins.h"
5
6
#include "miscadmin.h"
6
7
#include "storage/ipc.h"
7
8
#include "storage/lwlock.h"
8
9
#include "storage/shmem.h"
10
+ #include "utils/elog.h"
9
11
10
12
/* Constants and Macros */
11
13
PG_MODULE_MAGIC ;
@@ -116,5 +118,34 @@ pgsw_shmem_startup(void)
116
118
Datum
117
119
my_function (PG_FUNCTION_ARGS )
118
120
{
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 );
120
151
}
You can’t perform that action at this time.
0 commit comments