Changeset e0795d09a594dd276dd59643a85230388401fb06
- Timestamp:
- 07/01/08 14:14:22
(5 years ago)
- Author:
- Theo Schlossnagle <jesus@omniti.com>
- git-committer:
- Theo Schlossnagle <jesus@omniti.com> 1214921662 +0000
- git-parent:
[7710784460d9831062155d3e99f3bf22e4d978b0]
- git-author:
- Theo Schlossnagle <jesus@omniti.com> 1214921662 +0000
- Message:
fix up insert function for config info, refs #26
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r7710784 |
re0795d0 |
|
| 149 | 149 | whence timestamptz not null, |
|---|
| 150 | 150 | config xml not null, |
|---|
| 151 | | PRIMARY KEY (remote_address,node_type) |
|---|
| | 151 | PRIMARY KEY (remote_address,node_type,whence) |
|---|
| 152 | 152 | ); |
|---|
| 153 | 153 | |
|---|
| … | … | |
| 213 | 213 | -- Trigger Function to log dock status Changes |
|---|
| 214 | 214 | |
|---|
| | 215 | CREATE OR REPLACE FUNCTION stratcon.update_config( |
|---|
| | 216 | v_remote_address_in inet, |
|---|
| | 217 | v_node_type_in text, |
|---|
| | 218 | v_whence_in timestamptz, |
|---|
| | 219 | v_config_in xml) RETURNS void |
|---|
| | 220 | AS $$ |
|---|
| | 221 | DECLARE |
|---|
| | 222 | v_config xml; |
|---|
| | 223 | BEGIN |
|---|
| | 224 | select config into v_config from stratcon.current_node_config |
|---|
| | 225 | where remote_address = v_remote_address_in |
|---|
| | 226 | and node_type = v_node_type_in; |
|---|
| | 227 | IF FOUND THEN |
|---|
| | 228 | IF v_config::text = v_config_in::text THEN |
|---|
| | 229 | RETURN; |
|---|
| | 230 | END IF; |
|---|
| | 231 | delete from stratcon.current_node_config |
|---|
| | 232 | where _address = v_remote_address_in |
|---|
| | 233 | and node_type = v_node_type_in; |
|---|
| | 234 | END IF; |
|---|
| | 235 | insert into stratcon.current_node_config |
|---|
| | 236 | (remote_address, node_type, whence, config) |
|---|
| | 237 | values (v_remote_address_in, v_node_type_in, v_whence_in, v_config_in); |
|---|
| | 238 | insert into stratcon.current_node_config_changelog |
|---|
| | 239 | (remote_address, node_type, whence, config) |
|---|
| | 240 | values (v_remote_address_in, v_node_type_in, v_whence_in, v_config_in); |
|---|
| | 241 | END |
|---|
| | 242 | $$ LANGUAGE plpgsql; |
|---|
| | 243 | |
|---|
| 215 | 244 | CREATE TRIGGER loading_dock_status_s_change_log |
|---|
| 216 | 245 | AFTER INSERT ON stratcon.loading_dock_status_s |
|---|
| … | … | |
| 248 | 277 | $$ |
|---|
| 249 | 278 | LANGUAGE plpgsql; |
|---|
| 250 | | |
|---|
| 251 | | |
|---|
| 252 | | -- Trigger Function to log node config change |
|---|
| 253 | | |
|---|
| 254 | | CREATE TRIGGER current_node_config_changelog |
|---|
| 255 | | AFTER INSERT ON stratcon.current_node_config |
|---|
| 256 | | FOR EACH ROW |
|---|
| 257 | | EXECUTE PROCEDURE stratcon.current_node_config_changelog(); |
|---|
| 258 | | |
|---|
| 259 | | |
|---|
| 260 | | CREATE OR REPLACE FUNCTION stratcon.current_node_config_changelog() RETURNS trigger |
|---|
| 261 | | AS $$ |
|---|
| 262 | | DECLARE |
|---|
| 263 | | v_config xml; |
|---|
| 264 | | |
|---|
| 265 | | BEGIN |
|---|
| 266 | | |
|---|
| 267 | | IF TG_OP = 'INSERT' THEN |
|---|
| 268 | | SELECT config FROM stratcon.current_node_config WHERE remote_address = NEW.remote_address AND node_type= NEW.node_type |
|---|
| 269 | | AND whence = (SELECT max(whence) FROM stratcon.current_node_config_changelog |
|---|
| 270 | | WHERE remote_address = NEW.remote_address AND node_type= NEW.node_type and whence <> NEW.whence ) |
|---|
| 271 | | INTO v_config; |
|---|
| 272 | | |
|---|
| 273 | | IF v_config IS DISTINCT FROM NEW.config THEN |
|---|
| 274 | | |
|---|
| 275 | | INSERT INTO stratcon.current_node_config_changelog (remote_address,node_type,whence,config) |
|---|
| 276 | | VALUES (NEW.remote_address,NEW.node_type,NEW.whence,NEW.config); |
|---|
| 277 | | |
|---|
| 278 | | END IF; |
|---|
| 279 | | |
|---|
| 280 | | ELSE |
|---|
| 281 | | RAISE EXCEPTION 'Something wrong with stratcon.current_node_config_changelog'; |
|---|
| 282 | | END IF; |
|---|
| 283 | | |
|---|
| 284 | | RETURN NULL; |
|---|
| 285 | | |
|---|
| 286 | | END |
|---|
| 287 | | $$ |
|---|
| 288 | | LANGUAGE plpgsql; |
|---|
| 289 | 279 | |
|---|
| 290 | 280 | |
|---|