VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/core/testbox.pgsql@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.0 KB
Line 
1-- $Id: testbox.pgsql 98103 2023-01-17 14:15:46Z vboxsync $
2--- @file
3-- VBox Test Manager Database Stored Procedures - TestBoxes.
4--
5
6--
7-- Copyright (C) 2012-2023 Oracle and/or its affiliates.
8--
9-- This file is part of VirtualBox base platform packages, as
10-- available from https://www.virtualbox.org.
11--
12-- This program is free software; you can redistribute it and/or
13-- modify it under the terms of the GNU General Public License
14-- as published by the Free Software Foundation, in version 3 of the
15-- License.
16--
17-- This program is distributed in the hope that it will be useful, but
18-- WITHOUT ANY WARRANTY; without even the implied warranty of
19-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20-- General Public License for more details.
21--
22-- You should have received a copy of the GNU General Public License
23-- along with this program; if not, see <https://www.gnu.org/licenses>.
24--
25-- The contents of this file may alternatively be used under the terms
26-- of the Common Development and Distribution License Version 1.0
27-- (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28-- in the VirtualBox distribution, in which case the provisions of the
29-- CDDL are applicable instead of those of the GPL.
30--
31-- You may elect to license modified versions of this file under the
32-- terms and conditions of either the GPL or the CDDL or both.
33--
34-- SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35--
36
37
38--
39-- Old type signatures.
40--
41DROP FUNCTION IF EXISTS TestBoxLogic_addEntry(a_uidAuthor INTEGER,
42 a_ip inet,
43 a_uuidSystem uuid,
44 a_sName TEXT,
45 a_sDescription TEXT,
46 a_idSchedGroup INTEGER,
47 a_fEnabled BOOLEAN,
48 a_enmLomKind LomKind_T,
49 a_ipLom inet,
50 a_pctScaleTimeout INTEGER, -- Actually smallint, but default typing fun.
51 a_sComment TEXT,
52 a_enmPendingCmd TestBoxCmd_T,
53 OUT r_idTestBox INTEGER,
54 OUT r_idGenTestBox INTEGER,
55 OUT r_tsEffective TIMESTAMP WITH TIME ZONE);
56DROP FUNCTION IF EXISTS TestBoxLogic_editEntry(a_uidAuthor INTEGER,
57 a_idTestBox INTEGER,
58 a_ip inet,
59 a_uuidSystem uuid,
60 a_sName TEXT,
61 a_sDescription TEXT,
62 a_idSchedGroup INTEGER,
63 a_fEnabled BOOLEAN,
64 a_enmLomKind LomKind_T,
65 a_ipLom inet,
66 a_pctScaleTimeout INTEGER, -- Actually smallint, but default typing fun.
67 a_sComment TEXT,
68 a_enmPendingCmd TestBoxCmd_T,
69 OUT r_idGenTestBox INTEGER,
70 OUT r_tsEffective TIMESTAMP WITH TIME ZONE);
71DROP FUNCTION IF EXISTS TestBoxLogic_removeEntry(INTEGER, INTEGER, BOOLEAN);
72DROP FUNCTION IF EXISTS TestBoxLogic_addGroupEntry(a_uidAuthor INTEGER,
73 a_idTestBox INTEGER,
74 a_idSchedGroup INTEGER,
75 a_iSchedPriority INTEGER,
76 OUT r_tsEffective TIMESTAMP WITH TIME ZONE);
77DROP FUNCTION IF EXISTS TestBoxLogic_editGroupEntry(a_uidAuthor INTEGER,
78 a_idTestBox INTEGER,
79 a_idSchedGroup INTEGER,
80 a_iSchedPriority INTEGER,
81 OUT r_tsEffective INTEGER);
82
83
84---
85-- Checks if the test box name is unique, ignoring a_idTestCaseIgnore.
86-- Raises exception if duplicates are found.
87--
88-- @internal
89--
90CREATE OR REPLACE FUNCTION TestBoxLogic_checkUniqueName(a_sName TEXT, a_idTestBoxIgnore INTEGER)
91 RETURNS VOID AS $$
92 DECLARE
93 v_cRows INTEGER;
94 BEGIN
95 SELECT COUNT(*) INTO v_cRows
96 FROM TestBoxes
97 WHERE sName = a_sName
98 AND tsExpire = 'infinity'::TIMESTAMP
99 AND idTestBox <> a_idTestBoxIgnore;
100 IF v_cRows <> 0 THEN
101 RAISE EXCEPTION 'Duplicate test box name "%" (% times)', a_sName, v_cRows;
102 END IF;
103 END;
104$$ LANGUAGE plpgsql;
105
106
107---
108-- Checks that the given scheduling group exists.
109-- Raises exception if it doesn't.
110--
111-- @internal
112--
113CREATE OR REPLACE FUNCTION TestBoxLogic_checkSchedGroupExists(a_idSchedGroup INTEGER)
114 RETURNS VOID AS $$
115 DECLARE
116 v_cRows INTEGER;
117 BEGIN
118 SELECT COUNT(*) INTO v_cRows
119 FROM SchedGroups
120 WHERE idSchedGroup = a_idSchedGroup
121 AND tsExpire = 'infinity'::TIMESTAMP;
122 IF v_cRows <> 1 THEN
123 IF v_cRows = 0 THEN
124 RAISE EXCEPTION 'Scheduling group with ID % was not found', a_idSchedGroup;
125 END IF;
126 RAISE EXCEPTION 'Integrity error in SchedGroups: % current rows with idSchedGroup=%', v_cRows, a_idSchedGroup;
127 END IF;
128 END;
129$$ LANGUAGE plpgsql;
130
131
132---
133-- Checks that the given testbxo + scheduling group pair does not currently exists.
134-- Raises exception if it does.
135--
136-- @internal
137--
138CREATE OR REPLACE FUNCTION TestBoxLogic_checkTestBoxNotInSchedGroup(a_idTestBox INTEGER, a_idSchedGroup INTEGER)
139 RETURNS VOID AS $$
140 DECLARE
141 v_cRows INTEGER;
142 BEGIN
143 SELECT COUNT(*) INTO v_cRows
144 FROM TestBoxesInSchedGroups
145 WHERE idTestBox = a_idTestBox
146 AND idSchedGroup = a_idSchedGroup
147 AND tsExpire = 'infinity'::TIMESTAMP;
148 IF v_cRows <> 0 THEN
149 RAISE EXCEPTION 'TestBox % is already a member of scheduling group %', a_idTestBox, a_idSchedGroup;
150 END IF;
151 END;
152$$ LANGUAGE plpgsql;
153
154
155---
156-- Historize a row.
157-- @internal
158--
159CREATE OR REPLACE FUNCTION TestBoxLogic_historizeEntry(a_idGenTestBox INTEGER, a_tsExpire TIMESTAMP WITH TIME ZONE)
160 RETURNS VOID AS $$
161 DECLARE
162 v_cUpdatedRows INTEGER;
163 BEGIN
164 UPDATE TestBoxes
165 SET tsExpire = a_tsExpire
166 WHERE idGenTestBox = a_idGenTestBox
167 AND tsExpire = 'infinity'::TIMESTAMP;
168 GET DIAGNOSTICS v_cUpdatedRows = ROW_COUNT;
169 IF v_cUpdatedRows <> 1 THEN
170 IF v_cUpdatedRows = 0 THEN
171 RAISE EXCEPTION 'Test box generation ID % is no longer valid', a_idGenTestBox;
172 END IF;
173 RAISE EXCEPTION 'Integrity error in TestBoxes: % current rows with idGenTestBox=%', v_cUpdatedRows, a_idGenTestBox;
174 END IF;
175 END;
176$$ LANGUAGE plpgsql;
177
178
179---
180-- Historize a in-scheduling-group row.
181-- @internal
182--
183CREATE OR REPLACE FUNCTION TestBoxLogic_historizeGroupEntry(a_idTestBox INTEGER,
184 a_idSchedGroup INTEGER,
185 a_tsExpire TIMESTAMP WITH TIME ZONE)
186 RETURNS VOID AS $$
187 DECLARE
188 v_cUpdatedRows INTEGER;
189 BEGIN
190 UPDATE TestBoxesInSchedGroups
191 SET tsExpire = a_tsExpire
192 WHERE idTestBox = a_idTestBox
193 AND idSchedGroup = a_idSchedGroup
194 AND tsExpire = 'infinity'::TIMESTAMP;
195 GET DIAGNOSTICS v_cUpdatedRows = ROW_COUNT;
196 IF v_cUpdatedRows <> 1 THEN
197 IF v_cUpdatedRows = 0 THEN
198 RAISE EXCEPTION 'TestBox ID % / SchedGroup ID % is no longer a valid combination', a_idTestBox, a_idSchedGroup;
199 END IF;
200 RAISE EXCEPTION 'Integrity error in TestBoxesInSchedGroups: % current rows for % / %',
201 v_cUpdatedRows, a_idTestBox, a_idSchedGroup;
202 END IF;
203 END;
204$$ LANGUAGE plpgsql;
205
206
207---
208-- Translate string via the string table.
209--
210-- @returns NULL if a_sValue is NULL, otherwise a string ID.
211--
212CREATE OR REPLACE FUNCTION TestBoxLogic_lookupOrFindString(a_sValue TEXT)
213 RETURNS INTEGER AS $$
214 DECLARE
215 v_idStr INTEGER;
216 v_cRows INTEGER;
217 BEGIN
218 IF a_sValue IS NULL THEN
219 RETURN NULL;
220 END IF;
221
222 SELECT idStr
223 INTO v_idStr
224 FROM TestBoxStrTab
225 WHERE sValue = a_sValue;
226 GET DIAGNOSTICS v_cRows = ROW_COUNT;
227 IF v_cRows = 0 THEN
228 INSERT INTO TestBoxStrTab (sValue)
229 VALUES (a_sValue)
230 RETURNING idStr INTO v_idStr;
231 END IF;
232 RETURN v_idStr;
233 END;
234$$ LANGUAGE plpgsql;
235
236
237---
238-- Only adds the user settable parts of the row, i.e. not what TestBoxLogic_updateOnSignOn touches.
239--
240CREATE OR REPLACE function TestBoxLogic_addEntry(a_uidAuthor INTEGER,
241 a_ip inet,
242 a_uuidSystem uuid,
243 a_sName TEXT,
244 a_sDescription TEXT,
245 a_fEnabled BOOLEAN,
246 a_enmLomKind LomKind_T,
247 a_ipLom inet,
248 a_pctScaleTimeout INTEGER, -- Actually smallint, but default typing fun.
249 a_sComment TEXT,
250 a_enmPendingCmd TestBoxCmd_T,
251 OUT r_idTestBox INTEGER,
252 OUT r_idGenTestBox INTEGER,
253 OUT r_tsEffective TIMESTAMP WITH TIME ZONE
254 ) AS $$
255 DECLARE
256 v_idStrDescription INTEGER;
257 v_idStrComment INTEGER;
258 BEGIN
259 PERFORM TestBoxLogic_checkUniqueName(a_sName, -1);
260
261 SELECT TestBoxLogic_lookupOrFindString(a_sDescription) INTO v_idStrDescription;
262 SELECT TestBoxLogic_lookupOrFindString(a_sComment) INTO v_idStrComment;
263
264 INSERT INTO TestBoxes (
265 tsEffective, -- 1
266 uidAuthor, -- 2
267 ip, -- 3
268 uuidSystem, -- 4
269 sName, -- 5
270 idStrDescription, -- 6
271 fEnabled, -- 7
272 enmLomKind, -- 8
273 ipLom, -- 9
274 pctScaleTimeout, -- 10
275 idStrComment, -- 11
276 enmPendingCmd ) -- 12
277 VALUES (CURRENT_TIMESTAMP, -- 1
278 a_uidAuthor, -- 2
279 a_ip, -- 3
280 a_uuidSystem, -- 4
281 a_sName, -- 5
282 v_idStrDescription, -- 6
283 a_fEnabled, -- 7
284 a_enmLomKind, -- 8
285 a_ipLom, -- 9
286 a_pctScaleTimeout, -- 10
287 v_idStrComment, -- 11
288 a_enmPendingCmd ) -- 12
289 RETURNING idTestBox, idGenTestBox, tsEffective INTO r_idTestBox, r_idGenTestBox, r_tsEffective;
290 END;
291$$ LANGUAGE plpgsql;
292
293
294CREATE OR REPLACE function TestBoxLogic_addGroupEntry(a_uidAuthor INTEGER,
295 a_idTestBox INTEGER,
296 a_idSchedGroup INTEGER,
297 a_iSchedPriority INTEGER,
298 OUT r_tsEffective TIMESTAMP WITH TIME ZONE
299 ) AS $$
300 BEGIN
301 PERFORM TestBoxLogic_checkSchedGroupExists(a_idSchedGroup);
302 PERFORM TestBoxLogic_checkTestBoxNotInSchedGroup(a_idTestBox, a_idSchedGroup);
303
304 INSERT INTO TestBoxesInSchedGroups (
305 idTestBox,
306 idSchedGroup,
307 tsEffective,
308 tsExpire,
309 uidAuthor,
310 iSchedPriority)
311 VALUES (a_idTestBox,
312 a_idSchedGroup,
313 CURRENT_TIMESTAMP,
314 'infinity'::TIMESTAMP,
315 a_uidAuthor,
316 a_iSchedPriority)
317 RETURNING tsEffective INTO r_tsEffective;
318 END;
319$$ LANGUAGE plpgsql;
320
321
322---
323-- Only adds the user settable parts of the row, i.e. not what TestBoxLogic_updateOnSignOn touches.
324--
325CREATE OR REPLACE function TestBoxLogic_editEntry(a_uidAuthor INTEGER,
326 a_idTestBox INTEGER,
327 a_ip inet,
328 a_uuidSystem uuid,
329 a_sName TEXT,
330 a_sDescription TEXT,
331 a_fEnabled BOOLEAN,
332 a_enmLomKind LomKind_T,
333 a_ipLom inet,
334 a_pctScaleTimeout INTEGER, -- Actually smallint, but default typing fun.
335 a_sComment TEXT,
336 a_enmPendingCmd TestBoxCmd_T,
337 OUT r_idGenTestBox INTEGER,
338 OUT r_tsEffective TIMESTAMP WITH TIME ZONE
339 ) AS $$
340 DECLARE
341 v_Row TestBoxes%ROWTYPE;
342 v_idStrDescription INTEGER;
343 v_idStrComment INTEGER;
344 BEGIN
345 PERFORM TestBoxLogic_checkUniqueName(a_sName, a_idTestBox);
346
347 SELECT TestBoxLogic_lookupOrFindString(a_sDescription) INTO v_idStrDescription;
348 SELECT TestBoxLogic_lookupOrFindString(a_sComment) INTO v_idStrComment;
349
350 -- Fetch and historize the current row - there must be one.
351 UPDATE TestBoxes
352 SET tsExpire = CURRENT_TIMESTAMP
353 WHERE idTestBox = a_idTestBox
354 AND tsExpire = 'infinity'::TIMESTAMP
355 RETURNING * INTO STRICT v_Row;
356
357 -- Modify the row with the new data.
358 v_Row.uidAuthor := a_uidAuthor;
359 v_Row.ip := a_ip;
360 v_Row.uuidSystem := a_uuidSystem;
361 v_Row.sName := a_sName;
362 v_Row.idStrDescription := v_idStrDescription;
363 v_Row.fEnabled := a_fEnabled;
364 v_Row.enmLomKind := a_enmLomKind;
365 v_Row.ipLom := a_ipLom;
366 v_Row.pctScaleTimeout := a_pctScaleTimeout;
367 v_Row.idStrComment := v_idStrComment;
368 v_Row.enmPendingCmd := a_enmPendingCmd;
369 v_Row.tsEffective := v_Row.tsExpire;
370 r_tsEffective := v_Row.tsExpire;
371 v_Row.tsExpire := 'infinity'::TIMESTAMP;
372
373 -- Get a new generation ID.
374 SELECT NEXTVAL('TestBoxGenIdSeq') INTO v_Row.idGenTestBox;
375 r_idGenTestBox := v_Row.idGenTestBox;
376
377 -- Insert the modified row.
378 INSERT INTO TestBoxes VALUES (v_Row.*);
379 END;
380$$ LANGUAGE plpgsql;
381
382
383CREATE OR REPLACE function TestBoxLogic_editGroupEntry(a_uidAuthor INTEGER,
384 a_idTestBox INTEGER,
385 a_idSchedGroup INTEGER,
386 a_iSchedPriority INTEGER,
387 OUT r_tsEffective TIMESTAMP WITH TIME ZONE
388 ) AS $$
389 DECLARE
390 v_Row TestBoxesInSchedGroups%ROWTYPE;
391 v_idStrDescription INTEGER;
392 v_idStrComment INTEGER;
393 BEGIN
394 PERFORM TestBoxLogic_checkSchedGroupExists(a_idSchedGroup);
395
396 -- Fetch and historize the current row - there must be one.
397 UPDATE TestBoxesInSchedGroups
398 SET tsExpire = CURRENT_TIMESTAMP
399 WHERE idTestBox = a_idTestBox
400 AND idSchedGroup = a_idSchedGroup
401 AND tsExpire = 'infinity'::TIMESTAMP
402 RETURNING * INTO STRICT v_Row;
403
404 -- Modify the row with the new data.
405 v_Row.uidAuthor := a_uidAuthor;
406 v_Row.iSchedPriority := a_iSchedPriority;
407 v_Row.tsEffective := v_Row.tsExpire;
408 r_tsEffective := v_Row.tsExpire;
409 v_Row.tsExpire := 'infinity'::TIMESTAMP;
410
411 -- Insert the modified row.
412 INSERT INTO TestBoxesInSchedGroups VALUES (v_Row.*);
413 END;
414$$ LANGUAGE plpgsql;
415
416
417CREATE OR REPLACE FUNCTION TestBoxLogic_removeEntry(a_uidAuthor INTEGER, a_idTestBox INTEGER, a_fCascade BOOLEAN)
418 RETURNS VOID AS $$
419 DECLARE
420 v_Row TestBoxes%ROWTYPE;
421 v_tsEffective TIMESTAMP WITH TIME ZONE;
422 v_Rec RECORD;
423 v_sErrors TEXT;
424 BEGIN
425 --
426 -- Check preconditions.
427 --
428 IF a_fCascade <> TRUE THEN
429 -- @todo implement checks which throws useful exceptions.
430 ELSE
431 RAISE EXCEPTION 'CASCADE test box deletion is not implemented';
432 END IF;
433
434 --
435 -- Delete all current groups, skipping history since we're also deleting the testbox.
436 --
437 UPDATE TestBoxesInSchedGroups
438 SET tsExpire = CURRENT_TIMESTAMP
439 WHERE idTestBox = a_idTestBox
440 AND tsExpire = 'infinity'::TIMESTAMP;
441
442 --
443 -- To preserve the information about who deleted the record, we try to
444 -- add a dummy record which expires immediately. I say try because of
445 -- the primary key, we must let the new record be valid for 1 us. :-(
446 --
447 SELECT * INTO STRICT v_Row
448 FROM TestBoxes
449 WHERE idTestBox = a_idTestBox
450 AND tsExpire = 'infinity'::TIMESTAMP;
451
452 v_tsEffective := CURRENT_TIMESTAMP - INTERVAL '1 microsecond';
453 IF v_Row.tsEffective < v_tsEffective THEN
454 PERFORM TestBoxLogic_historizeEntry(v_Row.idGenTestBox, v_tsEffective);
455
456 v_Row.tsEffective := v_tsEffective;
457 v_Row.tsExpire := CURRENT_TIMESTAMP;
458 v_Row.uidAuthor := a_uidAuthor;
459 SELECT NEXTVAL('TestBoxGenIdSeq') INTO v_Row.idGenTestBox;
460 INSERT INTO TestBoxes VALUES (v_Row.*);
461 ELSE
462 PERFORM TestBoxLogic_historizeEntry(v_Row.idGenTestBox, CURRENT_TIMESTAMP);
463 END IF;
464
465 EXCEPTION
466 WHEN NO_DATA_FOUND THEN
467 RAISE EXCEPTION 'Test box with ID % does not currently exist', a_idTestBox;
468 WHEN TOO_MANY_ROWS THEN
469 RAISE EXCEPTION 'Integrity error in TestBoxes: Too many current rows for %', a_idTestBox;
470 END;
471$$ LANGUAGE plpgsql;
472
473
474CREATE OR REPLACE FUNCTION TestBoxLogic_removeGroupEntry(a_uidAuthor INTEGER, a_idTestBox INTEGER, a_idSchedGroup INTEGER)
475 RETURNS VOID AS $$
476 DECLARE
477 v_Row TestBoxesInSchedGroups%ROWTYPE;
478 v_tsEffective TIMESTAMP WITH TIME ZONE;
479 BEGIN
480 --
481 -- To preserve the information about who deleted the record, we try to
482 -- add a dummy record which expires immediately. I say try because of
483 -- the primary key, we must let the new record be valid for 1 us. :-(
484 --
485 SELECT * INTO STRICT v_Row
486 FROM TestBoxesInSchedGroups
487 WHERE idTestBox = a_idTestBox
488 AND idSchedGroup = a_idSchedGroup
489 AND tsExpire = 'infinity'::TIMESTAMP;
490
491 v_tsEffective := CURRENT_TIMESTAMP - INTERVAL '1 microsecond';
492 IF v_Row.tsEffective < v_tsEffective THEN
493 PERFORM TestBoxLogic_historizeGroupEntry(a_idTestBox, a_idSchedGroup, v_tsEffective);
494
495 v_Row.tsEffective := v_tsEffective;
496 v_Row.tsExpire := CURRENT_TIMESTAMP;
497 v_Row.uidAuthor := a_uidAuthor;
498 INSERT INTO TestBoxesInSchedGroups VALUES (v_Row.*);
499 ELSE
500 PERFORM TestBoxLogic_historizeGroupEntry(a_idTestBox, a_idSchedGroup, CURRENT_TIMESTAMP);
501 END IF;
502
503 EXCEPTION
504 WHEN NO_DATA_FOUND THEN
505 RAISE EXCEPTION 'TestBox #% does is not currently a member of scheduling group #%', a_idTestBox, a_idSchedGroup;
506 WHEN TOO_MANY_ROWS THEN
507 RAISE EXCEPTION 'Integrity error in TestBoxesInSchedGroups: Too many current rows for % / %',
508 a_idTestBox, a_idSchedGroup;
509 END;
510$$ LANGUAGE plpgsql;
511
512
513---
514-- Sign on update
515--
516CREATE OR REPLACE function TestBoxLogic_updateOnSignOn(a_idTestBox INTEGER,
517 a_ip inet,
518 a_sOs TEXT,
519 a_sOsVersion TEXT,
520 a_sCpuVendor TEXT,
521 a_sCpuArch TEXT,
522 a_sCpuName TEXT,
523 a_lCpuRevision bigint,
524 a_cCpus INTEGER, -- Actually smallint, but default typing fun.
525 a_fCpuHwVirt boolean,
526 a_fCpuNestedPaging boolean,
527 a_fCpu64BitGuest boolean,
528 a_fChipsetIoMmu boolean,
529 a_fRawMode boolean,
530 a_cMbMemory bigint,
531 a_cMbScratch bigint,
532 a_sReport TEXT,
533 a_iTestBoxScriptRev INTEGER,
534 a_iPythonHexVersion INTEGER,
535 OUT r_idGenTestBox INTEGER
536 ) AS $$
537 DECLARE
538 v_Row TestBoxes%ROWTYPE;
539 v_idStrOs INTEGER;
540 v_idStrOsVersion INTEGER;
541 v_idStrCpuVendor INTEGER;
542 v_idStrCpuArch INTEGER;
543 v_idStrCpuName INTEGER;
544 v_idStrReport INTEGER;
545 BEGIN
546 SELECT TestBoxLogic_lookupOrFindString(a_sOs) INTO v_idStrOs;
547 SELECT TestBoxLogic_lookupOrFindString(a_sOsVersion) INTO v_idStrOsVersion;
548 SELECT TestBoxLogic_lookupOrFindString(a_sCpuVendor) INTO v_idStrCpuVendor;
549 SELECT TestBoxLogic_lookupOrFindString(a_sCpuArch) INTO v_idStrCpuArch;
550 SELECT TestBoxLogic_lookupOrFindString(a_sCpuName) INTO v_idStrCpuName;
551 SELECT TestBoxLogic_lookupOrFindString(a_sReport) INTO v_idStrReport;
552
553 -- Fetch and historize the current row - there must be one.
554 UPDATE TestBoxes
555 SET tsExpire = CURRENT_TIMESTAMP
556 WHERE idTestBox = a_idTestBox
557 AND tsExpire = 'infinity'::TIMESTAMP
558 RETURNING * INTO STRICT v_Row;
559
560 -- Modify the row with the new data.
561 v_Row.uidAuthor := NULL;
562 v_Row.ip := a_ip;
563 v_Row.idStrOs := v_idStrOs;
564 v_Row.idStrOsVersion := v_idStrOsVersion;
565 v_Row.idStrCpuVendor := v_idStrCpuVendor;
566 v_Row.idStrCpuArch := v_idStrCpuArch;
567 v_Row.idStrCpuName := v_idStrCpuName;
568 v_Row.lCpuRevision := a_lCpuRevision;
569 v_Row.cCpus := a_cCpus;
570 v_Row.fCpuHwVirt := a_fCpuHwVirt;
571 v_Row.fCpuNestedPaging := a_fCpuNestedPaging;
572 v_Row.fCpu64BitGuest := a_fCpu64BitGuest;
573 v_Row.fChipsetIoMmu := a_fChipsetIoMmu;
574 v_Row.fRawMode := a_fRawMode;
575 v_Row.cMbMemory := a_cMbMemory;
576 v_Row.cMbScratch := a_cMbScratch;
577 v_Row.idStrReport := v_idStrReport;
578 v_Row.iTestBoxScriptRev := a_iTestBoxScriptRev;
579 v_Row.iPythonHexVersion := a_iPythonHexVersion;
580 v_Row.tsEffective := v_Row.tsExpire;
581 v_Row.tsExpire := 'infinity'::TIMESTAMP;
582
583 -- Get a new generation ID.
584 SELECT NEXTVAL('TestBoxGenIdSeq') INTO v_Row.idGenTestBox;
585 r_idGenTestBox := v_Row.idGenTestBox;
586
587 -- Insert the modified row.
588 INSERT INTO TestBoxes VALUES (v_Row.*);
589 END;
590$$ LANGUAGE plpgsql;
591
592
593---
594-- Set new command.
595--
596CREATE OR REPLACE function TestBoxLogic_setCommand(a_uidAuthor INTEGER,
597 a_idTestBox INTEGER,
598 a_enmOldCmd TestBoxCmd_T,
599 a_enmNewCmd TestBoxCmd_T,
600 a_sComment TEXT,
601 OUT r_idGenTestBox INTEGER,
602 OUT r_tsEffective TIMESTAMP WITH TIME ZONE
603 ) AS $$
604 DECLARE
605 v_Row TestBoxes%ROWTYPE;
606 v_idStrComment INTEGER;
607 BEGIN
608 SELECT TestBoxLogic_lookupOrFindString(a_sComment) INTO v_idStrComment;
609
610 -- Fetch and historize the current row - there must be one.
611 UPDATE TestBoxes
612 SET tsExpire = CURRENT_TIMESTAMP
613 WHERE idTestBox = a_idTestBox
614 AND tsExpire = 'infinity'::TIMESTAMP
615 AND enmPendingCmd = a_enmOldCmd
616 RETURNING * INTO STRICT v_Row;
617
618 -- Modify the row with the new data.
619 v_Row.enmPendingCmd := a_enmNewCmd;
620 IF v_idStrComment IS NOT NULL THEN
621 v_Row.idStrComment := v_idStrComment;
622 END IF;
623 v_Row.tsEffective := v_Row.tsExpire;
624 r_tsEffective := v_Row.tsExpire;
625 v_Row.tsExpire := 'infinity'::TIMESTAMP;
626
627 -- Get a new generation ID.
628 SELECT NEXTVAL('TestBoxGenIdSeq') INTO v_Row.idGenTestBox;
629 r_idGenTestBox := v_Row.idGenTestBox;
630
631 -- Insert the modified row.
632 INSERT INTO TestBoxes VALUES (v_Row.*);
633 END;
634$$ LANGUAGE plpgsql;
635
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette