forked from ehb54/us3_sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
us3_noise_procs.sql
726 lines (547 loc) · 20.5 KB
/
us3_noise_procs.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
--
-- us3_noise_procs.sql
--
-- Script to set up the MySQL stored procedures for the US3 system
-- These are related to the noise tables
-- Run as us3admin
--
DELIMITER $$
-- Verifies that the user has permission to view or modify
-- the specified noise
DROP FUNCTION IF EXISTS verify_noise_permission$$
CREATE FUNCTION verify_noise_permission( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseID INT )
RETURNS INT
READS SQL DATA
BEGIN
DECLARE count_noise INT;
DECLARE count_permissions INT;
DECLARE status INT;
CALL config();
SET status = @ERROR;
SET @US3_LAST_ERROR = 'MySQL: error verifying noise permission';
SELECT COUNT(*)
INTO count_noise
FROM noise
WHERE noiseID = p_noiseID;
SELECT COUNT(*)
INTO count_permissions
FROM noise, modelPerson
WHERE noise.noiseID = p_noiseID
AND noise.modelID = modelPerson.modelID
AND personID = @US3_ID;
IF ( count_noise = 0 ) THEN
SET @US3_LAST_ERRNO = @NO_NOISE;
SET @US3_LAST_ERROR = 'MySQL: the specified noise file does not exist';
SET status = @NO_NOISE;
ELSEIF ( verify_userlevel( p_personGUID, p_password, @US3_ADMIN ) = @OK ) THEN
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SET status = @OK;
ELSEIF ( ( verify_user( p_personGUID, p_password ) = @OK ) &&
( count_permissions > 0 ) ) THEN
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SET status = @OK;
ELSE
SET @US3_LAST_ERRNO = @NOTPERMITTED;
SET @US3_LAST_ERROR = 'MySQL: you do not have permission to view or modify this noise file';
SET status = @NOTPERMITTED;
END IF;
RETURN( status );
END$$
-- Returns the count of noise files associated with p_ID
-- If p_ID = 0, retrieves count of all noise files in db
-- Regular user can only get count of his own noise files
DROP FUNCTION IF EXISTS count_noise$$
CREATE FUNCTION count_noise( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_ID INT )
RETURNS INT
READS SQL DATA
BEGIN
DECLARE count_noise INT;
CALL config();
SET count_noise = 0;
IF ( verify_userlevel( p_personGUID, p_password, @US3_ADMIN ) = @OK ) THEN
-- This is an admin; he can get more info
IF ( p_ID > 0 ) THEN
SELECT COUNT(*)
INTO count_noise
FROM modelPerson, noise
WHERE personID = p_ID
AND modelPerson.modelID = noise.modelID;
ELSE
SELECT COUNT(*)
INTO count_noise
FROM noise;
END IF;
ELSEIF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
IF ( (p_ID != 0) && (p_ID != @US3_ID) ) THEN
-- Uh oh, can't do that
SET @US3_LAST_ERRNO = @NOTPERMITTED;
SET @US3_LAST_ERROR = 'MySQL: you do not have permission to view those noise files';
ELSE
-- This person is asking about his own noise files
-- Ignore p_ID and return user's own
SELECT COUNT(*)
INTO count_noise
FROM modelPerson, noise
WHERE modelPerson.modelID = noise.modelID
AND personID = @US3_ID;
END IF;
END IF;
RETURN( count_noise );
END$$
-- Returns the count of noise files associated with p_ID with a given editedDataID
-- p_ID cannot be 0
-- Admin user can get count of noise files that belong to others
DROP FUNCTION IF EXISTS count_noise_by_editID$$
CREATE FUNCTION count_noise_by_editID( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_ID INT,
p_editID INT )
RETURNS INT
READS SQL DATA
BEGIN
DECLARE count_noise INT;
CALL config();
SET count_noise = 0;
IF ( p_ID <= 0 ) THEN
-- Gotta have a real ID
RETURN ( 0 );
ELSEIF ( verify_userlevel( p_personGUID, p_password, @US3_ADMIN ) = @OK ) THEN
-- This is an admin; he can get more info
SELECT COUNT(*)
INTO count_noise
FROM modelPerson, noise
WHERE personID = p_ID
AND modelPerson.modelID = noise.modelID
AND editedDataID = p_editID;
ELSEIF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
IF ( (p_ID != 0) && (p_ID != @US3_ID) ) THEN
-- Uh oh, can't do that
SET @US3_LAST_ERRNO = @NOTPERMITTED;
SET @US3_LAST_ERROR = 'MySQL: you do not have permission to view those noise files';
ELSE
-- This person is asking about his own noise files
-- Ignore p_ID and return user's own
SELECT COUNT(*)
INTO count_noise
FROM modelPerson, noise
WHERE personID = @US3_ID
AND modelPerson.modelID = noise.modelID
AND editedDataID = p_editID;
END IF;
END IF;
RETURN( count_noise );
END$$
-- INSERTs a new noise file with the specified information
DROP PROCEDURE IF EXISTS new_noise$$
CREATE PROCEDURE new_noise ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseGUID CHAR(36),
p_editedDataID INT(11),
p_modelID INT(11),
p_modelGUID CHAR(36),
p_noiseType ENUM( 'ri_noise', 'ti_noise' ),
p_description TEXT,
p_xml LONGTEXT ) -- an xml file
MODIFIES SQL DATA
BEGIN
DECLARE l_editID INT;
DECLARE l_modelID INT;
DECLARE l_modelID_count INT;
DECLARE l_modelGUID CHAR(36);
DECLARE l_modelGUID_count INT;
DECLARE duplicate_key TINYINT DEFAULT 0;
DECLARE null_field TINYINT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR 1062
SET duplicate_key = 1;
DECLARE CONTINUE HANDLER FOR 1048
SET null_field = 1;
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SET @LAST_INSERT_ID = 0;
-- Verify that the editedDataID exists, and we have permissions
SET l_editID = 1; -- default to special "unassigned" record
IF ( verify_editData_permission( p_personGUID, p_password, p_editedDataID ) = @OK ) THEN
SET l_editID = p_editedDataID;
END IF;
-- User can specify either modelID or modelGUID
SELECT COUNT(*)
INTO l_modelGUID_count
FROM model
WHERE modelGUID = p_modelGUID
LIMIT 1; -- should be exactly 1, if p_modelGUID is supplied
SELECT COUNT(*)
INTO l_modelID_count
FROM model
WHERE modelID = p_modelID
LIMIT 1; -- should be exactly 1, if p_modelID is supplied
IF ( l_modelGUID_count = 1 ) THEN -- prefer the GUID
SET l_modelGUID = p_modelGUID;
SELECT modelID
INTO l_modelID
FROM model
WHERE modelGUID = p_modelGUID
LIMIT 1;
ELSEIF ( l_modelID_count = 1 ) THEN
SET l_modelID = p_modelID;
SELECT modelGUID
INTO l_modelGUID
FROM model
WHERE modelID = p_modelID;
ELSE
-- noise file doesn't belong to any model
SET l_modelID = 0;
SET l_modelGUID = p_modelGUID;
END IF;
IF ( verify_model_permission( p_personGUID, p_password, l_modelID ) != @OK ) THEN
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( l_modelGUID_count = 0 && l_modelID_count = 0 ) THEN
SET @US3_LAST_ERROR = "MySQL: the model was not found in the database";
SET @US3_LAST_ERRNO = @NO_MODEL;
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( check_GUID ( p_personGUID, p_password, p_noiseGUID ) = @OK ) THEN
INSERT INTO noise SET
noiseGUID = p_noiseGUID,
editedDataID = l_editID,
modelID = l_modelID,
modelGUID = l_modelGUID,
noiseType = p_noiseType,
description = p_description,
xml = p_xml,
timeEntered = NOW();
IF ( duplicate_key = 1 ) THEN
SET @US3_LAST_ERRNO = @INSERTDUP;
SET @US3_LAST_ERROR = "MySQL: Duplicate entry for noiseGUID field";
ELSEIF ( null_field = 1 ) THEN
SET @US3_LAST_ERRNO = @INSERTNULL;
SET @US3_LAST_ERROR = "MySQL: NULL value for noiseGUID field";
ELSE
SET @LAST_INSERT_ID = LAST_INSERT_ID();
END IF;
END IF;
SELECT @US3_LAST_ERRNO AS status;
END$$
-- UPDATEs an existing noise with the specified information
DROP PROCEDURE IF EXISTS update_noise$$
CREATE PROCEDURE update_noise ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseID INT(11),
p_noiseGUID CHAR(36),
p_editedDataID INT(11),
p_modelID INT(11),
p_modelGUID CHAR(36),
p_noiseType ENUM( 'ri_noise', 'ti_noise' ),
p_description TEXT,
p_xml LONGTEXT ) -- an xml file
MODIFIES SQL DATA
BEGIN
DECLARE l_editID INT;
DECLARE l_modelID INT;
DECLARE l_modelID_count INT;
DECLARE l_modelGUID CHAR(36);
DECLARE l_modelGUID_count INT;
DECLARE duplicate_key TINYINT DEFAULT 0;
DECLARE null_field TINYINT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR 1062
SET duplicate_key = 1;
DECLARE CONTINUE HANDLER FOR 1048
SET null_field = 1;
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SET @LAST_INSERT_ID = 0;
-- Verify that the editedDataID exists, and we have permissions
SET l_editID = 1; -- default to special "unassigned" record
IF ( verify_editData_permission( p_personGUID, p_password, p_editedDataID ) = @OK ) THEN
SET l_editID = p_editedDataID;
END IF;
-- User can specify either modelID or modelGUID
SELECT COUNT(*)
INTO l_modelGUID_count
FROM model
WHERE modelGUID = p_modelGUID
LIMIT 1; -- should be exactly 1, if p_modelGUID is supplied
SELECT COUNT(*)
INTO l_modelID_count
FROM model
WHERE modelID = p_modelID
LIMIT 1; -- should be exactly 1, if p_modelID is supplied
IF ( l_modelGUID_count = 1 ) THEN -- prefer the GUID
SET l_modelGUID = p_modelGUID;
SELECT modelID
INTO l_modelID
FROM model
WHERE modelGUID = p_modelGUID
LIMIT 1;
ELSEIF ( l_modelID_count = 1 ) THEN
SET l_modelID = p_modelID;
SELECT modelGUID
INTO l_modelGUID
FROM model
WHERE modelID = p_modelID;
ELSE
-- noise file doesn't belong to any model
SET l_modelID = 0;
SET l_modelGUID = p_modelGUID;
END IF;
IF ( verify_model_permission( p_personGUID, p_password, l_modelID ) != @OK ) THEN
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( l_modelGUID_count = 0 && l_modelID_count = 0 ) THEN
SET @US3_LAST_ERROR = "MySQL: the model was not found in the database";
SET @US3_LAST_ERRNO = @NO_MODEL;
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( check_GUID ( p_personGUID, p_password, p_noiseGUID ) = @OK ) THEN
UPDATE noise SET
noiseGUID = p_noiseGUID,
editedDataID = l_editID,
modelID = l_modelID,
modelGUID = l_modelGUID,
noiseType = p_noiseType,
description = p_description,
xml = p_xml,
timeEntered = NOW()
WHERE noiseID = p_noiseID;
IF ( duplicate_key = 1 ) THEN
SET @US3_LAST_ERRNO = @INSERTDUP;
SET @US3_LAST_ERROR = "MySQL: Duplicate entry for noiseGUID field";
ELSEIF ( null_field = 1 ) THEN
SET @US3_LAST_ERRNO = @INSERTNULL;
SET @US3_LAST_ERROR = "MySQL: NULL value for noiseGUID field";
ELSE
SET @LAST_INSERT_ID = LAST_INSERT_ID();
END IF;
END IF;
SELECT @US3_LAST_ERRNO AS status;
END$$
-- Returns the noiseID associated with the given noiseGUID
DROP PROCEDURE IF EXISTS get_noiseID$$
CREATE PROCEDURE get_noiseID ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseGUID CHAR(36) )
READS SQL DATA
BEGIN
DECLARE count_noise INT;
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SET count_noise = 0;
IF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
SELECT COUNT(*)
INTO count_noise
FROM noise
WHERE noiseGUID = p_noiseGUID;
IF ( TRIM( p_noiseGUID ) = '' ) THEN
SET @US3_LAST_ERRNO = @EMPTY;
SET @US3_LAST_ERROR = CONCAT( 'MySQL: The noiseGUID parameter to the ',
'get_noiseID function cannot be empty' );
ELSEIF ( count_noise < 1 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
SELECT @OK AS status;
SELECT noiseID
FROM noise
WHERE noiseGUID = p_noiseGUID;
END IF;
END IF;
END$$
-- Returns the noiseID and description of all noise files associated with p_ID
-- If p_ID = 0, retrieves information about all noise files in db
-- Regular user can only get info about his own noise files
DROP PROCEDURE IF EXISTS get_noise_desc$$
CREATE PROCEDURE get_noise_desc ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_ID INT )
READS SQL DATA
BEGIN
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
IF ( verify_userlevel( p_personGUID, p_password, @US3_ADMIN ) = @OK ) THEN
-- This is an admin; he can get more info
IF ( count_noise( p_personGUID, p_password, p_ID ) < 1 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
SELECT @OK AS status;
IF ( p_ID > 0 ) THEN
SELECT noiseID, noiseGUID, editedDataID, noise.modelID, noiseType, modelGUID,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM modelPerson, noise
WHERE modelPerson.modelID = noise.modelID
AND modelPerson.personID = p_ID
ORDER BY timeEntered DESC;
ELSE
SELECT noiseID, noiseGUID, editedDataID, noise.modelID, noiseType, modelGUID,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM modelPerson, noise
WHERE modelPerson.modelID = noise.modelID
ORDER BY timeEntered DESC;
END IF;
END IF;
ELSEIF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
IF ( (p_ID != 0) && (p_ID != @US3_ID) ) THEN
-- Uh oh, can't do that
SET @US3_LAST_ERRNO = @NOTPERMITTED;
SET @US3_LAST_ERROR = 'MySQL: you do not have permission to view this noise';
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( count_noise( p_personGUID, p_password, @US3_ID ) < 1 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
-- Ok, user wants his own info
SELECT @OK AS status;
SELECT noiseID, noiseGUID, editedDataID, noise.modelID, noiseType, modelGUID,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM modelPerson, noise
WHERE modelPerson.modelID = noise.modelID
AND modelPerson.personID = @US3_ID
ORDER BY timeEntered DESC;
END IF;
END IF;
END$$
-- Returns the noiseID and description of all noise files associated with p_ID and editID
-- Unlike get_noise_desc, in this function p_ID cannot be 0
-- Admin can view p_ID/editID combinations that belong to anyone
DROP PROCEDURE IF EXISTS get_noise_desc_by_editID$$
CREATE PROCEDURE get_noise_desc_by_editID ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_ID INT,
p_editID INT )
READS SQL DATA
BEGIN
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
IF ( p_ID <= 0 ) THEN
-- Gotta have a real ID
SET @US3_LAST_ERRNO = @EMPTY;
SET @US3_LAST_ERROR = 'MySQL: The ID cannot be 0';
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( verify_userlevel( p_personGUID, p_password, @US3_ADMIN ) = @OK ) THEN
-- This is an admin; he can get more info
IF ( count_noise_by_editID( p_personGUID, p_password, p_ID, p_editID ) < 1 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
SELECT @OK AS status;
SELECT noiseID, noiseGUID, editedDataID, noise.modelID, noiseType, modelGUID,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM modelPerson, noise
WHERE modelPerson.personID = p_ID
AND modelPerson.modelID = noise.modelID
AND editedDataID = p_editID
ORDER BY timeEntered DESC;
END IF;
ELSEIF ( verify_user( p_personGUID, p_password ) = @OK ) THEN
IF ( (p_ID != 0) && (p_ID != @US3_ID) ) THEN
-- Uh oh, can't do that
SET @US3_LAST_ERRNO = @NOTPERMITTED;
SET @US3_LAST_ERROR = 'MySQL: you do not have permission to view this noise';
SELECT @US3_LAST_ERRNO AS status;
ELSEIF ( count_noise_by_editID( p_personGUID, p_password, @US3_ID, p_editID ) < 1 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
-- Ok, user wants his own info
SELECT @OK AS status;
SELECT noiseID, noiseGUID, editedDataID, noise.modelID, noiseType, modelGUID,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM modelPerson, noise
WHERE modelPerson.personID = @US3_ID
AND modelPerson.modelID = noise.modelID
AND editedDataID = p_editID
ORDER BY timeEntered DESC;
END IF;
END IF;
END$$
-- Returns a more complete list of information about one noise file
DROP PROCEDURE IF EXISTS get_noise_info$$
CREATE PROCEDURE get_noise_info ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseID INT )
READS SQL DATA
BEGIN
DECLARE count_noise INT;
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SELECT COUNT(*)
INTO count_noise
FROM noise
WHERE noiseID = p_noiseID;
IF ( verify_noise_permission( p_personGUID, p_password, p_noiseID ) = @OK ) THEN
IF ( count_noise = 0 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
SELECT @OK AS status;
SELECT noiseGUID, editedDataID, modelID, modelGUID, noiseType, xml,
timestamp2UTC( timeEntered ) AS UTC_timeEntered,
MD5( xml ) AS checksum, LENGTH( xml ) AS size, description
FROM noise
WHERE noiseID = p_noiseID;
END IF;
ELSE
SELECT @US3_LAST_ERRNO AS status;
END IF;
END$$
-- get noise ID, type by modelID
DROP PROCEDURE IF EXISTS get_noiseTypesIDs$$
CREATE PROCEDURE get_noiseTypesIDs ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_modelID INT )
READS SQL DATA
BEGIN
DECLARE count_noise INT;
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
SELECT COUNT(*)
INTO count_noise
FROM noise
WHERE modelID = p_modelID;
IF ( count_noise = 0 ) THEN
SET @US3_LAST_ERRNO = @NOROWS;
SET @US3_LAST_ERROR = 'MySQL: no rows returned';
SELECT @US3_LAST_ERRNO AS status;
ELSE
SELECT @OK AS status;
SELECT noiseID, noiseType, timeEntered
FROM noise
WHERE modelID = p_modelID;
END IF;
END$$
-- DELETEs a noise file
DROP PROCEDURE IF EXISTS delete_noise$$
CREATE PROCEDURE delete_noise ( p_personGUID CHAR(36),
p_password VARCHAR(80),
p_noiseID INT )
MODIFIES SQL DATA
BEGIN
CALL config();
SET @US3_LAST_ERRNO = @OK;
SET @US3_LAST_ERROR = '';
IF ( verify_noise_permission( p_personGUID, p_password, p_noiseID ) = @OK ) THEN
DELETE FROM noise
WHERE noiseID = p_noiseID;
END IF;
SELECT @US3_LAST_ERRNO AS status;
END$$