Skip to content

Commit 6a22f58

Browse files
committed
Commit my code
1 parent 679a301 commit 6a22f58

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pg_sqlwall--1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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)
77
RETURNS cstring
88
AS 'MODULE_PATHNAME'
99
LANGUAGE C;

pg_sqlwall.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
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 */
1113
PG_MODULE_MAGIC;
@@ -116,5 +118,34 @@ pgsw_shmem_startup(void)
116118
Datum
117119
my_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
}

0 commit comments

Comments
 (0)