-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnlyStructureSprocsAndFuncs27012020.sql
4674 lines (2883 loc) · 151 KB
/
OnlyStructureSprocsAndFuncs27012020.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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- MySQL dump 10.13 Distrib 8.0.17, for Win64 (x86_64)
--
-- Host: 10.10.1.3 Database: humans
-- ------------------------------------------------------
-- Server version 8.0.12
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `APItoDB`
--
DROP TABLE IF EXISTS `APItoDB`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `APItoDB` (
`APItoDB_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`APItoDBRoute` varchar(80) NOT NULL,
`APItoDBSpoName` varchar(80) DEFAULT NULL,
`SpoFieldNamesAndTypes` text,
PRIMARY KEY (`APItoDB_id`),
UNIQUE KEY `APItoDB-id_UNIQUE` (`APItoDB_id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COMMENT='Database which registers the various api path and connects them to Sprocs';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `adresses`
--
DROP TABLE IF EXISTS `adresses`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `adresses` (
`AdressID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id of adress',
`Person` int(11) NOT NULL COMMENT 'Person living on this adress or person that has lived on this adress',
`AdressStreet` varchar(80) NOT NULL COMMENT 'Street',
`AdressCity` varchar(80) NOT NULL COMMENT 'City',
`AdressZipcode` varchar(6) DEFAULT NULL COMMENT 'Zipcode',
`AdressProvince` varchar(80) DEFAULT NULL COMMENT 'Province',
`AdressCountry` varchar(80) NOT NULL COMMENT 'Country',
`AdressIsCurrent` tinyint(1) NOT NULL COMMENT 'Signifies if this is the current adress ',
`AdressMovedIn` date DEFAULT NULL COMMENT 'Date the person moved in to this adress',
`AdressMovedOut` date DEFAULT NULL COMMENT 'Date the person moved out of this adress',
PRIMARY KEY (`AdressID`),
KEY `FK_ADRESSES_PERSONS_PersonID` (`Person`),
CONSTRAINT `FK_ADRESSES_PERSONS_PersonID` FOREIGN KEY (`Person`) REFERENCES `persons` (`personid`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COMMENT='Table to contain all adresses of a person through time';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Temporary view structure for view `allpersons`
--
DROP TABLE IF EXISTS `allpersons`;
/*!50001 DROP VIEW IF EXISTS `allpersons`*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW `allpersons` AS SELECT
1 AS `PersonID`,
1 AS `PersonGivvenName`,
1 AS `PersonFamilyName`,
1 AS `PersonDateOfBirth`,
1 AS `PersonPlaceOfBirth`,
1 AS `PersonDateOfDeath`,
1 AS `PersonPlaceOfDeath`,
1 AS `PersonIsMale`,
1 AS `PersonPhoto`*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table `archive`
--
DROP TABLE IF EXISTS `archive`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `archive` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`createdAt` bigint(20) DEFAULT NULL,
`fromModel` varchar(255) DEFAULT NULL,
`originalRecord` longtext,
`originalRecordId` longtext,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `documents`
--
DROP TABLE IF EXISTS `documents`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `documents` (
`DocumentId` int(11) NOT NULL,
`PersonId` int(11) NOT NULL,
`Type` varchar(45) NOT NULL,
`Store` varchar(45) DEFAULT NULL,
`IdOnStore` varchar(45) DEFAULT NULL,
PRIMARY KEY (`DocumentId`),
UNIQUE KEY `DocumentId_UNIQUE` (`DocumentId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Metadata for documents stored on disc and connected to persons via this metadata';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `humans`
--
DROP TABLE IF EXISTS `humans`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `humans` (
`createdAt` bigint(20) DEFAULT NULL,
`updatedAt` bigint(20) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `persons`
--
DROP TABLE IF EXISTS `persons`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `persons` (
`PersonID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Column with PersonID also primary key and autoincrement',
`PersonGivvenName` varchar(25) NOT NULL COMMENT 'Givven name of a person',
`PersonFamilyName` varchar(50) NOT NULL COMMENT 'Familyname of a person',
`PersonDateOfBirth` date NOT NULL COMMENT 'Date of birth of a person',
`PersonPlaceOfBirth` varchar(50) NOT NULL COMMENT 'Place of birth of a person',
`PersonDateOfDeath` date DEFAULT NULL COMMENT 'Date of death of a person',
`PersonPlaceOfDeath` varchar(80) DEFAULT NULL COMMENT 'Place of death of a person',
`PersonIsMale` tinyint(1) NOT NULL COMMENT 'Signifies if a person is a male or a female',
`PersonPhoto` longblob COMMENT 'Photo of a person',
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Field to determine for a pending change whether or not the record has been edited by another user ',
PRIMARY KEY (`PersonID`),
KEY `FamilyName` (`PersonFamilyName`)
) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1 COMMENT='Table that contains data for a natural person';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `relationnames`
--
DROP TABLE IF EXISTS `relationnames`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `relationnames` (
`RelationnameID` int(11) NOT NULL AUTO_INCREMENT,
`RelationnameName` varchar(50) NOT NULL,
`Relationtype` int(11) NOT NULL,
PRIMARY KEY (`RelationnameID`),
UNIQUE KEY `RelationnameName_UNIQUE` (`RelationnameName`),
KEY `FK_RELATIONNAMES_RELATIONTYPES_RelationtypeID` (`Relationtype`),
CONSTRAINT `FK_RELATIONNAMES_RELATIONTYPES_RelationtypeID` FOREIGN KEY (`Relationtype`) REFERENCES `relationtypes` (`relationtypeid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 COMMENT='Table to contain the relation names which fit within relation types';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `relations`
--
DROP TABLE IF EXISTS `relations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `relations` (
`RelationID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Relation ID',
`RelationName` int(11) NOT NULL COMMENT 'Type of relation',
`RelationPerson` int(11) NOT NULL COMMENT 'Person who is having the relation',
`RelationWithPerson` int(11) NOT NULL COMMENT 'Person the relation is with',
PRIMARY KEY (`RelationID`),
KEY `FK_RELATIONS_PERSONS_PersonID` (`RelationPerson`),
KEY `FK_RELATIONS_RELATIONNAMES_RelationnameID` (`RelationName`),
KEY `FK_RELATIONS_PERSONS_copy_PersonID` (`RelationWithPerson`),
CONSTRAINT `FK_RELATIONS_PERSONS_PersonID` FOREIGN KEY (`RelationPerson`) REFERENCES `persons` (`personid`),
CONSTRAINT `FK_RELATIONS_RELATIONNAMES_RelationnameID` FOREIGN KEY (`RelationName`) REFERENCES `relationnames` (`relationnameid`)
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=latin1 COMMENT='Table to express relations between natural persons';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `relationtypes`
--
DROP TABLE IF EXISTS `relationtypes`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `relationtypes` (
`RelationtypeID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id of the relationtype',
`RelationTypeName` varchar(50) DEFAULT NULL COMMENT 'Name of the relation type',
PRIMARY KEY (`RelationtypeID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 COMMENT='Table to contain the type of relations a relationname belongs to';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `test`
--
DROP TABLE IF EXISTS `test`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `test` (
`createdAt` bigint(20) DEFAULT NULL,
`updatedAt` bigint(20) DEFAULT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`text` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `testlog`
--
DROP TABLE IF EXISTS `testlog`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `testlog` (
`TestLog` varchar(1024) DEFAULT NULL,
`TestlogID` int(11) NOT NULL AUTO_INCREMENT,
`TestLogDateTime` datetime NOT NULL,
PRIMARY KEY (`TestlogID`)
) ENGINE=MyISAM AUTO_INCREMENT=27026 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `transnos`
--
DROP TABLE IF EXISTS `transnos`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `transnos` (
`TransNoID` int(11) NOT NULL AUTO_INCREMENT,
`SystemName` varchar(45) DEFAULT NULL,
`TransNoDateTime` datetime NOT NULL,
PRIMARY KEY (`TransNoID`),
UNIQUE KEY `idtransnos_UNIQUE` (`TransNoID`)
) ENGINE=MyISAM AUTO_INCREMENT=9563 DEFAULT CHARSET=latin1 COMMENT='Table to register transaction numbers and the systems these are used by and provide seed for next transactionnumber';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping routines for database 'humans'
--
/*!50003 DROP FUNCTION IF EXISTS `fGetFather` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `fGetFather`(PersonIdIn INT) RETURNS int(11)
READS SQL DATA
DETERMINISTIC
COMMENT 'Function to get the PersonId of the Father of a person with PersonIdIn.'
BEGIN
DECLARE RetVal INT;
DECLARE NewTranNo INT;
SET NewTranNo = GetTranNo("fGetFather");
-- Schrijf start van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. Start FUNC: fGetFather() voor persoon: ', IFNULL(PersonIdIn, '')),
TestLogDateTime = NOW();
select RelationWithPerson INTO RetVal from relations where RelationPerson= PersonIdIn and RelationName = "1";
-- Schrijf einde van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. End FUNC: fGetFather() voor persoon: ', IFNULL(PersonIdIn, ''), '. Father found= ',IFNULL(RetVal, '')),
TestLogDateTime = NOW();
RETURN RetVal;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `fGetMother` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `fGetMother`(PersonIdIn INT) RETURNS int(11)
READS SQL DATA
DETERMINISTIC
COMMENT 'Function to get the PersonId of the Mother of a person with PersonIdIn.'
BEGIN
DECLARE RetVal INT;
DECLARE NewTranNo INT;
SET NewTranNo = GetTranNo("fGetMother");
-- Schrijf start van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. Start FUNC: fGetMother() voor persoon: ', IFNULL(PersonIdIn, '')),
TestLogDateTime = NOW();
select RelationWithPerson INTO RetVal from relations where RelationPerson= PersonIdIn and RelationName = "2";
-- Schrijf einde van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. End FUNC: fGetMother() voor persoon: ', IFNULL(PersonIdIn, ''), '. Mother found= ',IFNULL(RetVal, '')),
TestLogDateTime = NOW();
RETURN RetVal;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `fGetParmNamesAndTypes` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `fGetParmNamesAndTypes`(`SpecificNameIn` CHAR(60), `TransNoIn` INT) RETURNS text CHARSET utf8
DETERMINISTIC
SQL SECURITY INVOKER
COMMENT 'Function to return parameter names and type of a specific SPROC'
BEGIN
DECLARE done INT default FALSE;
DECLARE ReturnValue text;
DECLARE ParmName, ParmType CHAR(20);
DECLARE Cursor1 CURSOR for select PARAMETER_NAME, DATA_TYPE from information_schema.parameters where SPECIFIC_NAME = SpecificNameIn;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(TransNoIn, 'null'), 'In GetParmNamesAndTypes(). SpecificNameIn= ', SpecificNameIn), TestLogDateTime = NOW();
OPEN Cursor1;
SET ReturnValue="{'parms':";
read_loop: LOOP
FETCH cursor1 INTO ParmName, ParmType;
IF done THEN
LEAVE read_loop;
END IF;
SET ReturnValue = concat(ReturnValue, '{"Name":"', ParmName, '" , "type":"', ParmType, '"},');
SET ParmName= "";
SET ParmType= "";
END LOOP;
SET ReturnValue = SUBSTR(ReturnValue, 1, LENGTH(ReturnValue)-1);
SET ReturnValue = concat(ReturnValue, '}');
RETURN ReturnValue;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `fGetPartner` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `fGetPartner`(PersonIdIn INT) RETURNS int(11)
READS SQL DATA
DETERMINISTIC
COMMENT 'Function to get the PersonId of the parner of a person with PersonIdIn.'
BEGIN
DECLARE Partner INT;
DECLARE NewTranNo INT;
SET NewTranNo = GetTranNo("fGetPartner");
-- Schrijf start van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. Start FUNC: fGetPartner() voor persoon: ', IFNULL(PersonIdIn, '')),
TestLogDateTime = NOW();
select RelationWithPerson INTO Partner from relations where RelationPerson= PersonIdIn and RelationName = "3";
-- Schrijf einde van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. End FUNC: fGetPartner() voor persoon: ', IFNULL(PersonIdIn, ''), '. Partner found= ',IFNULL(Partner, '')),
TestLogDateTime = NOW();
RETURN Partner;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `fPersonsArePartners` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `fPersonsArePartners`(PersonIn1 INT, PersonIn2 INT) RETURNS int(11)
READS SQL DATA
DETERMINISTIC
COMMENT 'Function returns true if two persons are eachothers partner'
BEGIN
DECLARE NewTranNo INT;
DECLARE RecCount INT;
DECLARE ArePartners BOOL;
SET NewTranNo = GetTranNo("PersonsArePartners");
-- Schrijf start van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. Start FUNC: PersonsArePartners() voor persoon: ', IFNULL(PersonIn1, 'null'), ' en voor persoon: ', IFNULL(PersonIn2, 'null')),
TestLogDateTime = NOW();
select count(*) from relations where RelationPerson= PersonIn1 and RelationWithPerson = PersonIn2 and RelationName = "3" into RecCount;
IF RecCount > 0 THEN
SET ArePartners = true;
ELSE
SET ArePartners = false;
END IF;
-- Schrijf einde van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTranNo, 'null'), '. End FUNC: PersonsArePartners(). Persoon ', IFNULL(PersonIn1, ''), ' en persoon ',IFNULL(PersonIn2, ''), ' zijn partners= ', IFNULL(ArePartners, 'null')),
TestLogDateTime = NOW();
RETURN ArePartners;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `GetTranNo` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `GetTranNo`(`SystemNameIn` VARCHAR(50)) RETURNS int(11)
DETERMINISTIC
SQL SECURITY INVOKER
COMMENT 'Function to get a transactionnumber while at the same time storing the last number and the system it was used for.'
BEGIN
DECLARE LastTranNo INT;
INSERT INTO humans.transnos
SET SystemName = SystemNameIn,
TransNoDateTime = NOW();
SET LastTranNo = LAST_INSERT_ID();
RETURN LastTranNo;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RecordHasBeenChangedBySomebodyElse` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `RecordHasBeenChangedBySomebodyElse`(`PersonIdIn` INT, `DateTimeIn` DATETIME) RETURNS tinyint(1)
DETERMINISTIC
SQL SECURITY INVOKER
COMMENT 'Function to check, based om a timestamp, whether or not a record has been changed by somebody else.'
BEGIN
DECLARE ReturnValue tinyint(1);
DECLARE StoredDateTime timestamp;
SELECT persons.Timestamp FROM persons WHERE PersonID = PersonIdIn INTO StoredDateTime;
IF StoredDateTime <> DateTimeIn THEN
SET ReturnValue = TRUE;
ELSE
SET ReturnValue = FALSE;
END IF;
RETURN ReturnValue;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP FUNCTION IF EXISTS `RowCountForFamilyTree` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `RowCountForFamilyTree`() RETURNS int(11)
READS SQL DATA
DETERMINISTIC
COMMENT 'Function to count the number of rows in the FamilyTree table'
BEGIN
DECLARE RowCountToBeReturned INT(11);
SELECT count(*) FROM FamilyTree INTO RowCountToBeReturned;
RETURN RowCountToBeReturned;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `AbstractDBtoAPInfo` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `AbstractDBtoAPInfo`()
DETERMINISTIC
SQL SECURITY INVOKER
BEGIN
-- CompletedOk defines the result of a database transaction, like this:
-- 0 = Transaction finished without problems.
-- 1 =
-- 2 = Transaction aborted due to problems during update and rollback performed
-- ...
DECLARE CompletedOk int;
-- NewTransNo is autonumber counter fetched from a seperate table and used for logging in a seperate log table
DECLARE NewTransNo int;
-- TransResult is used to count the number of seperate database operations and rissen with each step
DECLARE TransResult int;
-- RecCount is used to count the number of related records in depended tables.
DECLARE RecCount int;
-- Number of records in the result set
DECLARE n INT;
-- Counter to go from first record to last record
DECLARE i INT;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SET CompletedOk = 2;
INSERT INTO humans.testlog
SET TestLog = CONCAT("Transaction-", IFNULL(NewTransNo, "null"), ". ", "Error occured in SPROC: AbstractDBtoAPInfo(). Rollback executed. CompletedOk= ", CompletedOk),
TestLogDateTime = NOW();
SELECT CompletedOk;
END;
main_proc:
BEGIN
SET CompletedOk = 0;
SET TransResult = 0;
SET NewTransNo = GetTranNo("AbstractDBtoAPInfo");
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). TransResult= ', TransResult, '. Start SPROC: AbstractDBtoAPInfo().'),
TestLogDateTime = NOW();
select count(*) from mysql.proc where Db="humans" and type="PROCEDURE" into n;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). Opslaan aantal sprocs in n, n= ', n),
TestLogDateTime = NOW();
set i=0;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). Startwaarde van teller i= ', i),
TestLogDateTime = NOW();
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). Start deletion of all records in the APItoDB table.'),
TestLogDateTime = NOW();
truncate table humans.APItoDB;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). Start get names of all SPROCs in the humans DB.'),
TestLogDateTime = NOW();
insert into humans.APItoDB (APItoDBRoute) select name as APItoDBRoute from mysql.proc where Db="humans" and type="PROCEDURE";
WHILE i<n do
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). Looping, i= ', i, ', n= ', n),
TestLogDateTime = NOW();
select APItoDBRoute, APItoDB_id into @NameOfRecordToUpdate, @IDofRecordToUpdate from humans.APItoDB limit i,1;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. In AbstractDBtoAPinfo(). In loop. Name of record to update= ', @NameOfRecordToUpdate, ', IDofRecordToUpdate= ', @IDofRecordToUpdate),
TestLogDateTime = NOW();
update humans.APItoDB set SpoFieldNamesAndTypes = GetParmNamesandTypes(@NameOfRecordToUpdate, NewTransNo) where humans.APItoDB.APItoDB_id = @IDofRecordToUpdate;
set i=i+1;
end while;
SET TransResult = TransResult + 1;
SET RecCount = n;
SELECT CompletedOk, RecCount AS APItoDBRecsGevonden;
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. TransResult= ', TransResult, '. Einde SPROC: AbstractDBtoAPInfo(). CompletedOk= ', CompletedOk, '. APItoDB records aangemaakt=', RecCount),
TestLogDateTime = NOW();
END;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `AddPersonDetails` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `AddPersonDetails`(IN `PersonGivvenNameIn` VARCHAR(25), IN `PersonFamilyNameIn` VARCHAR(50), IN `PersonDateOfBirthIn` DATETIME, IN `PersonPlaceOfBirthIn` VARCHAR(50), IN `PersonDateOfDeathIn` DATETIME, IN `PersonPlaceOfDeathIn` VARCHAR(50), IN `PersonIsMaleIn` TINYINT(1), IN `PersonPhotoIn` LONGBLOB, IN `TimestampIn` TIMESTAMP, IN `PersonPartnerIdIn` INT(11), IN `PersonPartnerIn` VARCHAR(50), IN `PersonFatherIdIn` INT(11), IN `PersonFatherIn` VARCHAR(50), IN `PersonMotherIdIn` INT(11), IN `PersonMotherIn` VARCHAR(50))
SQL SECURITY INVOKER
COMMENT 'To add a specific person'
BEGIN
-- CompletedOk defines the result of a database transaction, like this:
-- 0 = Transaction finished without problems.
-- 1 = Transaction aborted due to intermediate changes (possibly from other users) in the mean time
-- 2 = Transaction aborted due to problems during update and rollback performed
DECLARE CompletedOk INT;
-- NewTransNo is autonumber counter fetched from a seperate table and used for logging in a seperate log table
DECLARE NewTransNo INT;
-- TransResult is used to count the number of seperate database operations and rissen with each step
DECLARE TransResult INT;
-- RecCount is used to count the number of related records in depended tables.
DECLARE RecCount int;
-- LastRecInserted is the autonumber ID value for each addition
DECLARE LastRecIdInserted INT(11);
DECLARE FullNamePerson varchar(100);
-- DECLARE MessageText text;
-- DECLARE ReturnedSqlState int;
-- DECLARE MySqlErrNo int;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
-- SET MessageText = MESSAGE_TEXT;
-- SET ReturnedSqlState = RETURNED_SQLSTATE;
-- SET MySQLErrNo = MYSQL_ERRNO;
-- GET CURRENT DIAGNOSTICS CONDITION 1 MessageText : MESSAGE_TEXT, ReturnedSqlState : RETURNED_SQLSTATE, MySqlErrNo : MYSQL_ERRNO;
ROLLBACK;
SET CompletedOk = 2;
INSERT INTO humans.testlog
SET TestLog = CONCAT("Transaction-", IFNULL(NewTransNo, "null"), ". ", "Error occured. Rollback executed. CompletedOk= ", CompletedOk),
TestLogDateTime = NOW();
SELECT CompletedOk;
END;
main_proc:
BEGIN
START TRANSACTION;
SET CompletedOk = 0;
SET TransResult = 0;
SET NewTransNo = GetTranNo("NewPersonDetails");
INSERT INTO humans.testlog
SET TestLog = CONCAT('TransAction-', IFNULL(NewTransNo, 'null'), '. TransResult= ', TransResult, '. Start insert for person.'),
TestLogDateTime = NOW();
/*
FDE03111963
Commented out because this SPO is copied and paste from the update sproc where you take into account other can have
edited the record in the mean time. Which is not the case for completely new records
IF RecordHasBeenChangedBySomebodyElse(PersonIdIn, TimeStampIn) THEN
SET CompletedOk = 1;
INSERT INTO humans.testLog
SET TestLog = CONCAT("Transaction-", IFNULL(NewTransNo, "null"), ". ", "Records has been changed in mean time. Update aborted."),
TestLogDateTime = NOW();
SELECT CompletedOk;
CALL GetPersonDetails(PersonIdIn);
LEAVE main_proc;
END IF;
*/
INSERT INTO humans.persons (
PersonGivvenName,
PersonFamilyName,
PersonDateOfBirth,
PersonPlaceOfBirth,
PersonDateOfDeath,
PersonPlaceOfDeath,
PersonIsMale)
VALUES
(PersonGivvenNameIn,
PersonFamilyNameIn,
PersonDateOfBirthIn,
PersonPlaceOfBirthIn,
PersonDateOfDeathIn,
PersonPlaceOfDeathIn,
PersonIsMaleIn);
SET LastRecIdInserted = LAST_INSERT_ID();
COMMIT;
SET TransResult = 1;
INSERT INTO humans.testlog
SET TestLog = concat("TransAction-", IFNULL(NewTransNo, "null"), ". ",
"Adding new person=> ",
"PersonIdIn= ", LastRecIdInserted, ", ",
"PersonGivvenNameIn= ", IFNULL(PersonGivvenNameIn, "null"), ", ",
"PersonFamilyNameIn= ", IFNULL(PersonFamilyNameIn, "null"), ", ",
"PersonDateOfBirthIn= ", IFNULL(PersonDateOfBirthIn, "null"), ", ",
"PersonPlaceOfBirthIn= ", IFNULL(PersonPlaceOfBirthIn, "null"), ", ",
"PersonDateOfDeathIn= ", IFNULL(PersonDateOfDeathIn, "null"), ", ",
"PersonPlaceOfDeathIn= ", IFNULL(PersonPlaceOfDeathIn, "null"), ", ",
"PersonIsMaleIn= ", IFNULL(PersonIsMaleIn, "null"), ", ",
"PersonPhotoIn= ", IFNULL(PersonPhotoIn, "null"), ", ",
"PersonPartnerIdIn= ", IFNULL(PersonPartnerIdIn, "null"), ", ",
"PersonPartnerIn= ", IFNULL(PersonPartnerIn, "null"), ", ",
"PersonFatherIdIn= ", IFNULL(PersonFatherIdIn, "null"), ", ",
"PersonFatherIn= ", IFNULL(PersonFatherIn, "null"), ", ",
"PersonMotherIdIn= ", IFNULL(PersonMotherIdIn, "null"), ", ",
"PersonMotherIn= ", IFNULL(PersonMotherIn, "null"), "."),
TestLogDateTime = NOW();
SET RecCount = 0;
INSERT INTO humans.testlog
SET TestLog = CONCAT("TransAction-", IFNULL(NewTransNo, 'null'), ". TransResult= ", TransResult, ". Gegevens zijn toegevoegd van Persoon ID= ", LastRecIdInserted),
TestLogDateTime = NOW();
SELECT CompletedOk, LastRecIdInserted;
CALL GetPersonDetails(LastRecIdINserted);
END;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `API_GetAPItoDBDetails` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `API_GetAPItoDBDetails`()
SQL SECURITY INVOKER
COMMENT 'To get the details of SPROCs which can be reached through API'
BEGIN
-- CompletedOk defines the result of a database transaction, like this:
-- 0 = Transaction finished without problems.
-- 1 =
-- 2 = Transaction aborted due to problems during update and rollback performed
-- ...
DECLARE CompletedOk int;
-- NewTransNo is autonumber counter fetched from a seperate table and used for logging in a seperate log table
DECLARE NewTransNo int;
-- TransResult is used to count the number of seperate database operations and rissen with each step
DECLARE TransResult int;
-- RecCount is used to count the number of related records in depended tables.
DECLARE RecCount int;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SET CompletedOk = 2;
INSERT INTO humans.testlog
SET TestLog = CONCAT("Transaction-", IFNULL(NewTransNo, "null"), ". ", "Error occured in SPROC: API_GetAPItoDBDetails(). Rollback executed. CompletedOk= ", CompletedOk),
TestLogDateTime = NOW();
SELECT CompletedOk;
END;
main_proc:
BEGIN
SET CompletedOk = 0;
SET TransResult = 0;
SET NewTransNo = GetTranNo("API_GetAPItoDBDetails");
-- Schrijf start van deze SQL transactie naar log
INSERT INTO humans.testlog
SET TestLog = CONCAT('===> Start Transaction= TransAction-', IFNULL(NewTransNo, 'null')), TestLogDateTime = NOW();
-- SELECT CompletedOk, APItoDBRoute, SpoFieldNamesAndTypes from APItoDB where APItoDBRoute like 'API_%';
SELECT CompletedOk, APItoDBRoute, SpoFieldNamesAndTypes from APItoDB;
INSERT INTO humans.testlog
SET TestLog = CONCAT('<=== End Transaction= TransAction-', IFNULL(NewTransNo, 'null'), 'Select all from APItoDB succesful'), TestLogDateTime = NOW();
END ;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `Clean_temptable_and_testlog` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `Clean_temptable_and_testlog`()
BEGIN
-- ----------------------------------------------------------------------------------------------------------------------------------------------
-- Author: Frans Dekkers (GoNomics)
-- Date: 05-01-2020