mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-29 13:07:50 +00:00
[#2166] Added session value setter functions
src/bin/admin/tests/pgsql_tests.sh.in pgsql_upgrade_6_2_to_7_0() - added session variable tests src/share/database/scripts/pgsql/dhcpdb_create.pgsql src/share/database/scripts/pgsql/upgrade_6.2_to_7.0.sh.in Added set_session_value functions Cleaned up get_session_* functions Whitespace cleanup src/share/database/scripts/pgsql/dhcpdb_drop.pgsql Added session variable functions
This commit is contained in:
parent
658a424d03
commit
ab3fcdd674
@ -310,6 +310,28 @@ pgsql_upgrade_6_2_to_7_0() {
|
|||||||
pgsql_execute "$select_sql"
|
pgsql_execute "$select_sql"
|
||||||
|
|
||||||
assert_eq 0 "${EXIT_CODE}" "the dhcp6_server table is broken or missing. (expected status code %d, returned %d)"
|
assert_eq 0 "${EXIT_CODE}" "the dhcp6_server table is broken or missing. (expected status code %d, returned %d)"
|
||||||
|
|
||||||
|
# Verify that session variable setting is present and functional.
|
||||||
|
# First we try fetching big and small int values that do not exist, we should get 0.
|
||||||
|
# Then we set an integer value and fetch it as big and small.
|
||||||
|
session_sql="\
|
||||||
|
select get_session_small_int('kea.test_val'); \
|
||||||
|
select get_session_small_int('kea.test_val'); \
|
||||||
|
select set_session_value('kea.test_val', '987'); \
|
||||||
|
select get_session_value('kea.test_val'); \
|
||||||
|
select get_session_big_int('kea.test_val'); \
|
||||||
|
select get_session_small_int('kea.test_val'); \
|
||||||
|
select set_session_value('kea.test_val', cast('984' as SMALLINT)); \
|
||||||
|
select get_session_small_int('kea.test_val'); \
|
||||||
|
select set_session_value('kea.test_val', cast('1984' as BIGINT)); \
|
||||||
|
select get_session_big_int('kea.test_val'); \
|
||||||
|
"
|
||||||
|
run_command \
|
||||||
|
pgsql_execute "$session_sql"
|
||||||
|
|
||||||
|
assert_eq 0 "${EXIT_CODE}" "session variable handling broken. (expected status code %d, returned %d)"
|
||||||
|
clean_out=`echo ${OUTPUT} | tr '\n' ' '`
|
||||||
|
assert_str_eq "0 0 987 987 987 984 1984 " "${clean_out}" "session variable output incorrect"
|
||||||
}
|
}
|
||||||
|
|
||||||
pgsql_upgrade_test() {
|
pgsql_upgrade_test() {
|
||||||
|
@ -580,7 +580,7 @@ CREATE TABLE lease4_stat (
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Create v4 insert trigger procedure
|
-- Create v4 insert trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease4_insert () RETURNS trigger AS $stat_lease4_insert$
|
CREATE OR REPLACE FUNCTION proc_stat_lease4_insert() RETURNS trigger AS $stat_lease4_insert$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NEW.state < 2 THEN
|
IF NEW.state < 2 THEN
|
||||||
UPDATE lease4_stat
|
UPDATE lease4_stat
|
||||||
@ -604,7 +604,7 @@ AFTER INSERT ON lease4
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Create v4 update trigger procedure
|
-- Create v4 update trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease4_update () RETURNS trigger AS $stat_lease4_update$
|
CREATE OR REPLACE FUNCTION proc_stat_lease4_update() RETURNS trigger AS $stat_lease4_update$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.state != NEW.state THEN
|
IF OLD.state != NEW.state THEN
|
||||||
IF OLD.state < 2 THEN
|
IF OLD.state < 2 THEN
|
||||||
@ -638,7 +638,7 @@ AFTER UPDATE ON lease4
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Create the v4 delete trigger procedure
|
-- Create the v4 delete trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease4_delete () RETURNS trigger AS $stat_lease4_delete$
|
CREATE OR REPLACE FUNCTION proc_stat_lease4_delete() RETURNS trigger AS $stat_lease4_delete$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.state < 2 THEN
|
IF OLD.state < 2 THEN
|
||||||
-- Decrement the state count if record exists
|
-- Decrement the state count if record exists
|
||||||
@ -667,7 +667,7 @@ CREATE TABLE lease6_stat (
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Create v6 insert trigger procedure
|
-- Create v6 insert trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease6_insert () RETURNS trigger AS $stat_lease6_insert$
|
CREATE OR REPLACE FUNCTION proc_stat_lease6_insert() RETURNS trigger AS $stat_lease6_insert$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF NEW.state < 2 THEN
|
IF NEW.state < 2 THEN
|
||||||
UPDATE lease6_stat
|
UPDATE lease6_stat
|
||||||
@ -694,7 +694,7 @@ AFTER INSERT ON lease6
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Create v6 update trigger procedure
|
-- Create v6 update trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease6_update () RETURNS trigger AS $stat_lease6_update$
|
CREATE OR REPLACE FUNCTION proc_stat_lease6_update() RETURNS trigger AS $stat_lease6_update$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.state != NEW.state THEN
|
IF OLD.state != NEW.state THEN
|
||||||
IF OLD.state < 2 THEN
|
IF OLD.state < 2 THEN
|
||||||
@ -910,7 +910,7 @@ UPDATE schema_version
|
|||||||
-- Upgrade to schema 6.1 begins here:
|
-- Upgrade to schema 6.1 begins here:
|
||||||
|
|
||||||
-- Fix v4 update trigger procedure
|
-- Fix v4 update trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease4_update () RETURNS trigger AS $stat_lease4_update$
|
CREATE OR REPLACE FUNCTION proc_stat_lease4_update() RETURNS trigger AS $stat_lease4_update$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.subnet_id != NEW.subnet_id OR OLD.state != NEW.state THEN
|
IF OLD.subnet_id != NEW.subnet_id OR OLD.state != NEW.state THEN
|
||||||
IF OLD.state < 2 THEN
|
IF OLD.state < 2 THEN
|
||||||
@ -938,7 +938,7 @@ $stat_lease4_update$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Fix the v4 delete trigger procedure
|
-- Fix the v4 delete trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease4_delete () RETURNS trigger AS $stat_lease4_delete$
|
CREATE OR REPLACE FUNCTION proc_stat_lease4_delete() RETURNS trigger AS $stat_lease4_delete$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.state < 2 THEN
|
IF OLD.state < 2 THEN
|
||||||
-- Decrement the state count if record exists
|
-- Decrement the state count if record exists
|
||||||
@ -953,7 +953,7 @@ $stat_lease4_delete$ LANGUAGE plpgsql;
|
|||||||
|
|
||||||
--
|
--
|
||||||
-- Fix v6 update trigger procedure
|
-- Fix v6 update trigger procedure
|
||||||
CREATE OR REPLACE FUNCTION proc_stat_lease6_update () RETURNS trigger AS $stat_lease6_update$
|
CREATE OR REPLACE FUNCTION proc_stat_lease6_update() RETURNS trigger AS $stat_lease6_update$
|
||||||
BEGIN
|
BEGIN
|
||||||
IF OLD.subnet_id != NEW.subnet_id OR
|
IF OLD.subnet_id != NEW.subnet_id OR
|
||||||
OLD.lease_type != NEW.lease_type OR
|
OLD.lease_type != NEW.lease_type OR
|
||||||
@ -1715,13 +1715,67 @@ CREATE TRIGGER dhcp4_audit_modification_ts_update
|
|||||||
CREATE INDEX dhcp4_audit_idx1 ON dhcp4_audit (modification_type);
|
CREATE INDEX dhcp4_audit_idx1 ON dhcp4_audit (modification_type);
|
||||||
CREATE INDEX dhcp4_audit_idx2 ON dhcp4_audit (revision_id);
|
CREATE INDEX dhcp4_audit_idx2 ON dhcp4_audit (revision_id);
|
||||||
|
|
||||||
|
|
||||||
|
-- Stores a TEXT value to a session variable
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value TEXT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value TEXT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, value, false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;$$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Stores a BIGINT value to a session variable
|
||||||
|
-- Note the value converted to TEXT and then stored as Postgresql does
|
||||||
|
-- not support any other data type in session variables.
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value BIGINT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value BIGINT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, cast(value as text), false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;$$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Stores a SMALLINT value to a session variable
|
||||||
|
-- Note the value converted to TEXT and then stored as Postgresql does
|
||||||
|
-- not support any other data type in session variables.
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value SMALLINT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value SMALLINT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, cast(value as text), false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;$$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
-- Fetches a text value from the session configuration.
|
-- Fetches a text value from the session configuration.
|
||||||
-- param name name of the session variable to fetch
|
-- param name name of the session variable to fetch
|
||||||
-- If the name is not found it returns NULL.
|
-- If the name is not found it returns NULL.
|
||||||
-- Postgresql allows you to store custom session values
|
-- Postgresql allows you to store custom session values
|
||||||
-- but throws an exception if they have not first been
|
-- but throws an exception if they have not first been
|
||||||
-- set. This allows us to be a bit more graceful.
|
-- set. This allows us to be a bit more graceful.
|
||||||
CREATE OR REPLACE FUNCTION get_session_value(name text)
|
CREATE OR REPLACE FUNCTION get_session_value(name TEXT)
|
||||||
RETURNS TEXT
|
RETURNS TEXT
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -1731,9 +1785,11 @@ BEGIN
|
|||||||
RETURN(text_value);
|
RETURN(text_value);
|
||||||
|
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN OTHERS THEN
|
WHEN undefined_object THEN
|
||||||
RAISE NOTICE 'get_session_value(%) failed, sqlstate: %', name, sqlstate;
|
-- Variable has not been initialized so return NULL
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'get_session_value(%, TEXT) failed, sqlstate: %', name, sqlstate;
|
||||||
END;$$
|
END;$$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
@ -1772,8 +1828,7 @@ AS $$
|
|||||||
DECLARE
|
DECLARE
|
||||||
int_value SMALLINT := 0;
|
int_value SMALLINT := 0;
|
||||||
text_value TEXT := '';
|
text_value TEXT := '';
|
||||||
BEGIN
|
BEGIN text_value = get_session_value(name);
|
||||||
text_value = get_session_value(name);
|
|
||||||
IF text_value is NULL or text_value = '' THEN
|
IF text_value is NULL or text_value = '' THEN
|
||||||
RETURN(0);
|
RETURN(0);
|
||||||
END IF;
|
END IF;
|
||||||
@ -1840,8 +1895,8 @@ BEGIN
|
|||||||
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
||||||
|
|
||||||
-- Update pertienent session variables.
|
-- Update pertienent session variables.
|
||||||
PERFORM set_config('kea.audit_revision_id', cast(audit_revision_id as text), false);
|
PERFORM set_session_value('kea.audit_revision_id', audit_revision_id);
|
||||||
PERFORM set_config('kea.cascade_transaction', cast(cascade_transaction as text), false);
|
PERFORM set_session_value('kea.cascade_transaction', cascade_transaction);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;$$;
|
END;$$;
|
||||||
@ -1988,7 +2043,7 @@ BEGIN
|
|||||||
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
||||||
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
||||||
-- prior to 9.2 or we tell people how to edit the conf file.
|
-- prior to 9.2 or we tell people how to edit the conf file.
|
||||||
PERFORM set_config('kea.depend_on_known_indirectly', cast(depend_on_known_indirectly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_indirectly', depend_on_known_indirectly);
|
||||||
|
|
||||||
-- Bail if the class is updated without re-positioning.
|
-- Bail if the class is updated without re-positioning.
|
||||||
IF(
|
IF(
|
||||||
@ -2077,7 +2132,7 @@ END;$$;
|
|||||||
-- Trigger procedure to position an inserted class within the class hierarchy
|
-- Trigger procedure to position an inserted class within the class hierarchy
|
||||||
-- and create audit.
|
-- and create audit.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AINS () RETURNS trigger AS $dhcp4_client_class_AINS$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AINS() RETURNS trigger AS $dhcp4_client_class_AINS$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, NULL);
|
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, NULL);
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'create');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'create');
|
||||||
@ -2104,10 +2159,10 @@ CREATE TRIGGER dhcp4_client_class_AINS
|
|||||||
-- values will be compared with the new dependencies after an update.
|
-- values will be compared with the new dependencies after an update.
|
||||||
-- If they change, an error will be signaled.
|
-- If they change, an error will be signaled.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AUPD () RETURNS trigger AS $dhcp4_client_class_AUPD$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AUPD() RETURNS trigger AS $dhcp4_client_class_AUPD$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM set_config('kea.depend_on_known_directly', cast(OLD.depend_on_known_directly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_directly', OLD.depend_on_known_directly);
|
||||||
PERFORM set_config('kea.client_class_id', cast(NEW.id as text), false);
|
PERFORM set_session_value('kea.client_class_id', NEW.id);
|
||||||
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'update');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'update');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -2123,7 +2178,7 @@ CREATE TRIGGER dhcp4_client_class_AUPD
|
|||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
-- Trigger procedure to create the audit entry for client class delete.
|
-- Trigger procedure to create the audit entry for client class delete.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_ADEL () RETURNS trigger AS $dhcp4_client_class_ADEL$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_ADEL() RETURNS trigger AS $dhcp4_client_class_ADEL$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', OLD.id, 'delete');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', OLD.id, 'delete');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -2449,8 +2504,8 @@ BEGIN
|
|||||||
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
||||||
|
|
||||||
-- Update pertienent session variables.
|
-- Update pertienent session variables.
|
||||||
PERFORM set_config('kea.audit_revision_id', cast(audit_revision_id as text), false);
|
PERFORM set_session_value('kea.audit_revision_id', audit_revision_id);
|
||||||
PERFORM set_config('kea.cascade_transaction', cast(cascade_transaction as text), false);
|
PERFORM set_session_value('kea.cascade_transaction', cascade_transaction);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;$$;
|
END;$$;
|
||||||
@ -2592,7 +2647,7 @@ BEGIN
|
|||||||
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
||||||
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
||||||
-- prior to 9.2 or we tell people how to edit the conf file.
|
-- prior to 9.2 or we tell people how to edit the conf file.
|
||||||
PERFORM set_config('kea.depend_on_known_indirectly', cast(depend_on_known_indirectly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_indirectly', depend_on_known_indirectly);
|
||||||
|
|
||||||
-- Bail if the class is updated without re-positioning.
|
-- Bail if the class is updated without re-positioning.
|
||||||
IF(
|
IF(
|
||||||
@ -2681,7 +2736,7 @@ END;$$;
|
|||||||
-- Trigger procedure to position an inserted class within the class hierarchy
|
-- Trigger procedure to position an inserted class within the class hierarchy
|
||||||
-- and create audit.
|
-- and create audit.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AINS () RETURNS trigger AS $dhcp6_client_class_AINS$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AINS() RETURNS trigger AS $dhcp6_client_class_AINS$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, NULL);
|
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, NULL);
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'create');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'create');
|
||||||
@ -2707,10 +2762,10 @@ CREATE TRIGGER dhcp6_client_class_AINS
|
|||||||
-- values will be compared with the new dependencies after an update.
|
-- values will be compared with the new dependencies after an update.
|
||||||
-- If they change, an error will be signaled.
|
-- If they change, an error will be signaled.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AUPD () RETURNS trigger AS $dhcp6_client_class_AUPD$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AUPD() RETURNS trigger AS $dhcp6_client_class_AUPD$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM set_config('kea.depend_on_known_directly', cast(OLD.depend_on_known_directly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_directly', OLD.depend_on_known_directly);
|
||||||
PERFORM set_config('kea.client_class_id', cast(NEW.id as text), false);
|
PERFORM set_session_value('kea.client_class_id', NEW.id);
|
||||||
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'update');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'update');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -2726,7 +2781,7 @@ CREATE TRIGGER dhcp6_client_class_AUPD
|
|||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
-- Trigger procedure to create the audit entry for client class delete.
|
-- Trigger procedure to create the audit entry for client class delete.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_ADEL () RETURNS trigger AS $dhcp6_client_class_ADEL$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_ADEL() RETURNS trigger AS $dhcp6_client_class_ADEL$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', OLD.id, 'delete');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', OLD.id, 'delete');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
@ -165,5 +165,6 @@ DROP FUNCTION IF EXISTS modification_ts_update();
|
|||||||
DROP FUNCTION IF EXISTS get_session_small_int(name text);
|
DROP FUNCTION IF EXISTS get_session_small_int(name text);
|
||||||
DROP FUNCTION IF EXISTS get_session_big_int(name text);
|
DROP FUNCTION IF EXISTS get_session_big_int(name text);
|
||||||
DROP FUNCTION IF EXISTS get_session_value(name text);
|
DROP FUNCTION IF EXISTS get_session_value(name text);
|
||||||
|
DROP FUNCTION IF EXISTS set_session_value(name text, value TEXT);
|
||||||
|
DROP FUNCTION IF EXISTS set_session_value(name text, value BIGINT);
|
||||||
|
DROP FUNCTION IF EXISTS set_session_value(name text, value SMALLINT);
|
||||||
|
@ -721,13 +721,66 @@ CREATE TRIGGER dhcp4_audit_modification_ts_update
|
|||||||
CREATE INDEX dhcp4_audit_idx1 ON dhcp4_audit (modification_type);
|
CREATE INDEX dhcp4_audit_idx1 ON dhcp4_audit (modification_type);
|
||||||
CREATE INDEX dhcp4_audit_idx2 ON dhcp4_audit (revision_id);
|
CREATE INDEX dhcp4_audit_idx2 ON dhcp4_audit (revision_id);
|
||||||
|
|
||||||
|
-- Stores a TEXT value to a session variable
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value TEXT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value TEXT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS \$\$
|
||||||
|
DECLARE
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, value, false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;\$\$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Stores a BIGINT value to a session variable
|
||||||
|
-- Note the value converted to TEXT and then stored as Postgresql does
|
||||||
|
-- not support any other data type in session variables.
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value BIGINT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value BIGINT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS \$\$
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, cast(value as text), false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;\$\$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Stores a SMALLINT value to a session variable
|
||||||
|
-- Note the value converted to TEXT and then stored as Postgresql does
|
||||||
|
-- not support any other data type in session variables.
|
||||||
|
-- name name of session variable to set
|
||||||
|
-- value SMALLINT value to store
|
||||||
|
CREATE OR REPLACE FUNCTION set_session_value(name text, value SMALLINT)
|
||||||
|
RETURNS VOID
|
||||||
|
AS \$\$
|
||||||
|
BEGIN
|
||||||
|
PERFORM set_config(name, cast(value as text), false);
|
||||||
|
RETURN;
|
||||||
|
|
||||||
|
EXCEPTION
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'set_session_value(%) : value:[%] failed, sqlstate: %', name, value, sqlstate;
|
||||||
|
END;\$\$
|
||||||
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
-- Fetches a text value from the session configuration.
|
-- Fetches a text value from the session configuration.
|
||||||
-- param name name of the session variable to fetch
|
-- param name name of the session variable to fetch
|
||||||
-- If the name is not found it returns NULL.
|
-- If the name is not found it returns NULL.
|
||||||
-- Postgresql allows you to store custom session values
|
-- Postgresql allows you to store custom session values
|
||||||
-- but throws an exception if they have not first been
|
-- but throws an exception if they have not first been
|
||||||
-- set. This allows us to be a bit more graceful.
|
-- set. This allows us to be a bit more graceful.
|
||||||
CREATE OR REPLACE FUNCTION get_session_value(name text)
|
CREATE OR REPLACE FUNCTION get_session_value(name TEXT)
|
||||||
RETURNS TEXT
|
RETURNS TEXT
|
||||||
AS \$\$
|
AS \$\$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -735,11 +788,12 @@ DECLARE
|
|||||||
BEGIN
|
BEGIN
|
||||||
text_value = current_setting(name);
|
text_value = current_setting(name);
|
||||||
RETURN(text_value);
|
RETURN(text_value);
|
||||||
|
|
||||||
EXCEPTION
|
EXCEPTION
|
||||||
WHEN OTHERS THEN
|
WHEN undefined_object THEN
|
||||||
RAISE NOTICE 'get_session_value(%) failed, sqlstate: %', name, sqlstate;
|
-- Variable has not been initialized so return NULL
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
WHEN OTHERS THEN
|
||||||
|
RAISE EXCEPTION 'get_session_value(%, TEXT) failed, sqlstate: %', name, sqlstate;
|
||||||
END;\$\$
|
END;\$\$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql;
|
||||||
|
|
||||||
@ -846,8 +900,8 @@ BEGIN
|
|||||||
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
||||||
|
|
||||||
-- Update pertienent session variables.
|
-- Update pertienent session variables.
|
||||||
PERFORM set_config('kea.audit_revision_id', cast(audit_revision_id as text), false);
|
PERFORM set_session_value('kea.audit_revision_id', audit_revision_id);
|
||||||
PERFORM set_config('kea.cascade_transaction', cast(cascade_transaction as text), false);
|
PERFORM set_session_value('kea.cascade_transaction', cascade_transaction);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;\$\$;
|
END;\$\$;
|
||||||
@ -994,7 +1048,7 @@ BEGIN
|
|||||||
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
||||||
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
||||||
-- prior to 9.2 or we tell people how to edit the conf file.
|
-- prior to 9.2 or we tell people how to edit the conf file.
|
||||||
PERFORM set_config('kea.depend_on_known_indirectly', cast(depend_on_known_indirectly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_indirectly', depend_on_known_indirectly);
|
||||||
|
|
||||||
-- Bail if the class is updated without re-positioning.
|
-- Bail if the class is updated without re-positioning.
|
||||||
IF(
|
IF(
|
||||||
@ -1083,7 +1137,7 @@ END;\$\$;
|
|||||||
-- Trigger procedure to position an inserted class within the class hierarchy
|
-- Trigger procedure to position an inserted class within the class hierarchy
|
||||||
-- and create audit.
|
-- and create audit.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AINS () RETURNS trigger AS \$dhcp4_client_class_AINS\$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AINS() RETURNS trigger AS \$dhcp4_client_class_AINS\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, NULL);
|
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, NULL);
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'create');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'create');
|
||||||
@ -1110,10 +1164,10 @@ CREATE TRIGGER dhcp4_client_class_AINS
|
|||||||
-- values will be compared with the new dependencies after an update.
|
-- values will be compared with the new dependencies after an update.
|
||||||
-- If they change, an error will be signaled.
|
-- If they change, an error will be signaled.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AUPD () RETURNS trigger AS \$dhcp4_client_class_AUPD\$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_AUPD() RETURNS trigger AS \$dhcp4_client_class_AUPD\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM set_config('kea.depend_on_known_directly', cast(OLD.depend_on_known_directly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_directly', OLD.depend_on_known_directly);
|
||||||
PERFORM set_config('kea.client_class_id', cast(NEW.id as text), false);
|
PERFORM set_session_value('kea.client_class_id', NEW.id);
|
||||||
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
PERFORM setClientClass4Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'update');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', NEW.id, 'update');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -1129,7 +1183,7 @@ CREATE TRIGGER dhcp4_client_class_AUPD
|
|||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
-- Trigger procedure to create the audit entry for client class delete.
|
-- Trigger procedure to create the audit entry for client class delete.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_ADEL () RETURNS trigger AS \$dhcp4_client_class_ADEL\$
|
CREATE OR REPLACE FUNCTION func_dhcp4_client_class_ADEL() RETURNS trigger AS \$dhcp4_client_class_ADEL\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM createAuditEntryDHCP4('dhcp4_client_class', OLD.id, 'delete');
|
PERFORM createAuditEntryDHCP4('dhcp4_client_class', OLD.id, 'delete');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -1455,8 +1509,8 @@ BEGIN
|
|||||||
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
VALUES (audit_ts, srv_id, audit_log_message) returning id INTO audit_revision_id;
|
||||||
|
|
||||||
-- Update pertienent session variables.
|
-- Update pertienent session variables.
|
||||||
PERFORM set_config('kea.audit_revision_id', cast(audit_revision_id as text), false);
|
PERFORM set_session_value('kea.audit_revision_id', audit_revision_id);
|
||||||
PERFORM set_config('kea.cascade_transaction', cast(cascade_transaction as text), false);
|
PERFORM set_session_value('kea.cascade_transaction', cascade_transaction);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;\$\$;
|
END;\$\$;
|
||||||
@ -1598,7 +1652,7 @@ BEGIN
|
|||||||
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
-- Note this does not work prior to Postgres 9.2 unless the variables are
|
||||||
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
-- defined in postgresql.conf. I think for now we put up with CB not supported
|
||||||
-- prior to 9.2 or we tell people how to edit the conf file.
|
-- prior to 9.2 or we tell people how to edit the conf file.
|
||||||
PERFORM set_config('kea.depend_on_known_indirectly', cast(depend_on_known_indirectly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_indirectly', depend_on_known_indirectly);
|
||||||
|
|
||||||
-- Bail if the class is updated without re-positioning.
|
-- Bail if the class is updated without re-positioning.
|
||||||
IF(
|
IF(
|
||||||
@ -1687,7 +1741,7 @@ END;\$\$;
|
|||||||
-- Trigger procedure to position an inserted class within the class hierarchy
|
-- Trigger procedure to position an inserted class within the class hierarchy
|
||||||
-- and create audit.
|
-- and create audit.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AINS () RETURNS trigger AS \$dhcp6_client_class_AINS\$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AINS() RETURNS trigger AS \$dhcp6_client_class_AINS\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, NULL);
|
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, NULL);
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'create');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'create');
|
||||||
@ -1713,10 +1767,10 @@ CREATE TRIGGER dhcp6_client_class_AINS
|
|||||||
-- values will be compared with the new dependencies after an update.
|
-- values will be compared with the new dependencies after an update.
|
||||||
-- If they change, an error will be signaled.
|
-- If they change, an error will be signaled.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AUPD () RETURNS trigger AS \$dhcp6_client_class_AUPD\$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_AUPD() RETURNS trigger AS \$dhcp6_client_class_AUPD\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM set_config('kea.depend_on_known_directly', cast(OLD.depend_on_known_directly as text), false);
|
PERFORM set_session_value('kea.depend_on_known_directly', OLD.depend_on_known_directly);
|
||||||
PERFORM set_config('kea.client_class_id', cast(NEW.id as text), false);
|
PERFORM set_session_value('kea.client_class_id', NEW.id);
|
||||||
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
PERFORM setClientClass6Order(NEW.id, NEW.follow_class_name, OLD.follow_class_name);
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'update');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', NEW.id, 'update');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
@ -1732,7 +1786,7 @@ CREATE TRIGGER dhcp6_client_class_AUPD
|
|||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
-- Trigger procedure to create the audit entry for client class delete.
|
-- Trigger procedure to create the audit entry for client class delete.
|
||||||
-- -----------------------------------------------------------------------
|
-- -----------------------------------------------------------------------
|
||||||
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_ADEL () RETURNS trigger AS \$dhcp6_client_class_ADEL\$
|
CREATE OR REPLACE FUNCTION func_dhcp6_client_class_ADEL() RETURNS trigger AS \$dhcp6_client_class_ADEL\$
|
||||||
BEGIN
|
BEGIN
|
||||||
PERFORM createAuditEntryDHCP6('dhcp6_client_class', OLD.id, 'delete');
|
PERFORM createAuditEntryDHCP6('dhcp6_client_class', OLD.id, 'delete');
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user