-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheatmap.sql
More file actions
2443 lines (2252 loc) · 67.5 KB
/
heatmap.sql
File metadata and controls
2443 lines (2252 loc) · 67.5 KB
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
/*------------BASE DE DATOS--------*/
drop database if exists heatmap;
create database heatmap;
use heatmap;
/*-------Tablas------*/
drop table if exists usuario;
create table usuario (
idusuario int not null,
nombre nvarchar (90) not null,
apellido nvarchar(90) not null,
usuario nvarchar(90) not null,
pasword nvarchar(90) not null,
correo nvarchar(90) not null,
fechaNac date not null,
sexo char(1) not null,
telefono nvarchar(120),
imagen nvarchar(90),
tipo char(1) not null,
idubicacion int,
confirmacion nvarchar(90) not null,
tokenpsw nvarchar(90),
cierre date,
antiguedad datetime not null,
primary key(idusuario));
drop table if exists relusuarios;
create table relusuarios(
idrelusuarios int not null,
idUsuario1 int not null,
idUsuario2 int not null,
primary key (idrelusuarios),
foreign key(idUsuario1)
references usuario(idusuario),
foreign key(idUsuario2)
references usuario(idusuario));
drop table if exists conversacion;
create table conversacion (
idConversacion int not null,
título nvarchar (90),
primary key(idConversacion));
drop table if exists mensajes;
create table mensajes (
idMensajes int not null,
idConversacion int not null,
Mensaje nvarchar(90) not null,
fecha_hora timestamp not null,
remitente int not null,
receptor int not null,
primary key (idMensajes),
foreign key(idConversacion)
references conversacion(idConversacion));
drop table if exists menu;
create table menu(
idmenu int not null,
menu nvarchar(90) not null,
titulo nvarchar(90) not null,
ruta nvarchar(90) not null,
icono nvarchar(90) not null,
posicion decimal(2,1) not null,
primary key(idmenu));
drop table if exists relusrmenu;
create table relusrmenu(
idrel int not null,
idmenu int not null,
tipo char(1) not null,
primary key (idrel));
drop table if exists ubicacion;
create table ubicacion(
idubicacion int not null,
coordenadax double not null,
coordenaday double not null,
primary key (idubicacion));
drop table if exists lugar;
create table lugar(
idlugar int not null,
titulo nvarchar(90) not null,
imagen nvarchar(90) not null,
idusuario int not null,
idubicacion int not null,
primary key (idlugar),
foreign key(idubicacion)
references ubicacion(idubicacion),
foreign key (idusuario)
references usuario(idusuario));
drop table if exists reportedelictivo;
create table reportedelictivo (
idreportedel int not null,
idubicacion int not null,
titulo nvarchar(90) not null,
descripcion text not null,
tipo nvarchar(90) not null,
fecha date not null,
hora time not null,
idusuario int not null,
primary key (idreportedel),
foreign key(idubicacion)
references ubicacion(idubicacion),
foreign key (idusuario)
references usuario(idusuario));
drop table if exists rutas;
create table rutas (
idruta int not null,
titulo nvarchar(90) not null,
puntoA nvarchar(90) not null,
puntoB nvarchar(90) not null,
idusuario int not null,
primary key (idruta),
foreign key (idusuario)
references usuario(idusuario));
drop table if exists anuncio;
create table anuncio (
idanuncio int not null,
titulo nvarchar(90) not null,
descripcion text not null,
imagen nvarchar(90) not null,
hr_ab nvarchar(5) not null,
hr_cerr nvarchar(5) not null,
calificacion int(1) not null,
idusuario int not null,
idubicacion int not null,
primary key (idanuncio),
foreign key(idubicacion)
references ubicacion(idubicacion),
foreign key (idusuario)
references usuario(idusuario));
drop table if exists categoria;
create table categoria (
idcat int not null,
titulo nvarchar(90) not null,
imagen nvarchar(90) not null,
color nvarchar(90) not null,
posicion int not null,
primary key (idcat));
drop table if exists relubicat;
create table relubicat(
idrel int not null,
idcat int not null,
idanuncio int not null,
primary key (idrel),
foreign key (idcat)
references categoria(idcat));
drop table if exists lenguaje;
create table lenguaje (
idleng int not null,
leng nvarchar(10) not null,
sLenguaje nvarchar(120) not null,
sCambiarLenguaje nvarchar(120) not null,
sBienvenido nvarchar(120) not null,
sContenidoIndex text not null,
sIniciarSesion nvarchar(120) not null,
sCerrarSesion nvarchar(120) not null,
sUsuario nvarchar(120) not null,
sPlaceHolderUsuario nvarchar(120) not null,
sContrasena nvarchar(120) not null,
sEntrar nvarchar(120) not null,
sOlvidarContrasena1 nvarchar(120) not null,
sOlvidarContrasena2 nvarchar(120) not null,
sBuscarCorreo nvarchar(120) not null,
sNuevaContrasena nvarchar(120) not null,
sConfirmarContrasena nvarchar(120) not null,
sNoTienesUnaCuentaEnHeatmap nvarchar(120) not null,
sRegistrateAqui nvarchar(120) not null,
sRegistrate nvarchar(120) not null,
sNombre nvarchar(120) not null,
sApellido nvarchar(120) not null,
sCorreo nvarchar(120) not null,
sSexo nvarchar(120) not null,
sMasculino nvarchar(120) not null,
sFemenino nvarchar(120) not null,
sTelefono nvarchar(120) not null,
sImagen nvarchar(120) not null,
sFechaNacimiento nvarchar(120) not null,
sUsuarioContrasenaIncorrecto nvarchar(120) not null,
sUsuarioAgregado nvarchar(120) not null,
sUsuarioModificado nvarchar(120) not null,
sUsuarioBorrado nvarchar(120) not null,
sUsuarioBorradoSi nvarchar(120) not null,
sUsuarioBorradoNo nvarchar(120) not null,
sUsuarioEncontrado nvarchar(120) not null,
sUsuarioYaExiste nvarchar(120) not null,
sUsuarioNoExiste nvarchar(120) not null,
sUsuarioNoValido nvarchar(120) not null,
sUsuarioConfirmadoSi nvarchar(120) not null,
sUsuarioConfirmadoNo nvarchar(120) not null,
sContrasenaCambiadaSi nvarchar(120) not null,
sContrasenaCambiadaNo nvarchar(120) not null,
sLugarAgregado nvarchar(120) not null,
sLugarModificado nvarchar(120) not null,
sLugarBorrado nvarchar(120) not null,
sLugarYaExiste nvarchar(120) not null,
sLugarNoExiste nvarchar(120) not null,
sReporteAgregado nvarchar(120) not null,
sReporteModificado nvarchar(120) not null,
sReporteBorrado nvarchar(120) not null,
sReporteYaExiste nvarchar(120) not null,
sReporteNoExiste nvarchar(120) not null,
sAnuncioAgregado nvarchar(120) not null,
sAnuncioModificado nvarchar(120) not null,
sAnuncioBorrado nvarchar(120) not null,
sAnuncioYaExiste nvarchar(120) not null,
sAnuncioNoExiste nvarchar(120) not null,
sAnuncioCategoriaAgregado nvarchar(120) not null,
sTelefonoYaExiste nvarchar(120) not null,
sTelefonoNoValido nvarchar(120) not null,
sCorreoYaExiste nvarchar(120) not null,
sCorreoNoValido nvarchar(120) not null,
sCoordenadaNoValida nvarchar(120) not null,
sFechaNoValida nvarchar(120) not null,
sHorarioNoValido nvarchar(120) not null,
sSexoNoValido nvarchar(120) not null,
sNoCamposVacios nvarchar(120) not null,
sError nvarchar(120) not null,
sMapa nvarchar(120) not null,
sMapaGeneral nvarchar(120) not null,
sMapaDelictivo nvarchar(120) not null,
sMapaLugares nvarchar(120) not null,
sMapaAnuncios nvarchar(120) not null,
sSinConversacion nvarchar(120) not null,
sSinResultadosDeBusqueda nvarchar(120) not null,
sNuevoContacto nvarchar(120) not null,
sAlta nvarchar(120) not null,
sAltaReporteDelictivo nvarchar(120) not null,
sAltaReporteDelictivoAqui nvarchar(120) not null,
sAltaLugar nvarchar(120) not null,
sAltaLugarAqui nvarchar(120) not null,
sAltaAnuncio nvarchar(120) not null,
sAltaAnuncioAqui nvarchar(120) not null,
sTitulo nvarchar(120) not null,
sLugar nvarchar(120) not null,
sTipoSiniestro nvarchar(120) not null,
sFechaAcontecimiento nvarchar(120) not null,
sHoraAcontecimiento nvarchar(120) not null,
sHorarioAbre nvarchar(120) not null,
sHorarioCierra nvarchar(120) not null,
sDescripcion nvarchar(120) not null,
sEstadisticas nvarchar(120) not null,
sAmigos nvarchar(120) not null,
sAmigo nvarchar(120) not null,
sUbicacion nvarchar(120) not null,
sConversacion nvarchar(120) not null,
sMensajes nvarchar(120) not null,
sEnviar nvarchar(120) not null,
sCompartirLugar nvarchar(120) not null,
sCalificarLugar nvarchar(120) not null,
sCalificacion nvarchar(120) not null,
sCategorias nvarchar(120) not null,
sCategoriaNoExiste nvarchar(120) not null,
sComida nvarchar(120) not null,
sEntretenimiento nvarchar(120) not null,
sServicios nvarchar(120) not null,
sLunes nvarchar(120) not null,
sMartes nvarchar(120) not null,
sMiercoles nvarchar(120) not null,
sJueves nvarchar(120) not null,
sViernes nvarchar(120) not null,
sSabado nvarchar(120) not null,
sDomingo nvarchar(120) not null,
sConfiguracion nvarchar(120) not null,
sMiPerfil nvarchar(120) not null,
sMembresia nvarchar(120) not null,
sAdministrarCuenta nvarchar(120) not null,
sErrorPagina nvarchar(120) not null,
sCorreoEnviadoRegistroAlert nvarchar(120) not null,
sCorreoEnviadoRegistroTitulo nvarchar(120) not null,
sCorreoEnviadoRegistroCuerpo text not null,
sCorreoEnviadoPaswordAlert nvarchar(120) not null,
sCorreoEnviadoPaswordTitulo nvarchar(120) not null,
sCorreoEnviadoPaswordCuerpo text not null,
sContrasenaNoValida nvarchar(120) not null,
sNombreLargo nvarchar(120) not null,
sContrasenaFormato text not null,
sCamposObligatorios nvarchar(120) not null,
sContrasenaIgualNo nvarchar(120) not null,
sDelitosPorMes nvarchar(120) not null,
sReporteMp nvarchar(120) not null,
sTipoDelito nvarchar(120) not null,
sSeleccionarCombobox nvarchar(120) not null,
sTipo1 nvarchar(120) not null,
sTipo2 nvarchar(120) not null,
sTipo3 nvarchar(120) not null,
sTipo4 nvarchar(120) not null,
sFecha nvarchar(120) not null,
sTipoNoValido nvarchar(120) not null,
sMostrarContrasena nvarchar(120) not null,
sCorreoCambioPasword nvarchar(120) not null,
sCorreoCambioPaswordBody text not null,
sCorreoCambioPaswordTitle nvarchar(120) not null,
sBuscar nvarchar(120) not null,
sCambioDeContrasenaCuerpo text not null,
sCambioDeContrasenaAlert nvarchar(120) not null,
sContrasenaCambiada nvarchar(120) not null,
sRutas nvarchar(120) not null,
sRutasEnHeatmap nvarchar(120) not null,
sRutasDesde nvarchar(120) not null,
sRutasHasta nvarchar(120) not null,
sRutasTipo nvarchar(120) not null,
sRutasMapa nvarchar(120) not null,
sRutasTipo1 nvarchar(120) not null,
sRutasTipo2 nvarchar(120) not null,
sRutasObtenerRuta nvarchar(120) not null,
sRutasPuntoNoValido nvarchar(120) not null,
sRutasPunto nvarchar(120) not null,
sBuscador nvarchar(120) not null,
sForo nvarchar(120) not null,
sConvCon nvarchar(120) not null,
sBuscarNo nvarchar(120) not null,
sAltaRuta nvarchar(120) not null,
sRutaYaExiste nvarchar(120) not null,
sRutaNoExiste nvarchar(120) not null,
primary key (idLeng));
------------------------------------------------------------------------------------
/*--------------------------FUNCTIONS------------------------------*/
drop function if exists f_IdUbicacion;
delimiter //
create function f_IdUbicacion (p_coordenadax nvarchar(90), p_coordenaday nvarchar(90)) returns int
begin
declare idexiste int;
declare idsub int;
if((f_DecimalValido(p_coordenadax)=1) and(f_DecimalValido(p_coordenaday)=1))then
set idexiste = (select idubicacion from ubicacion where coordenadax=p_coordenadax
and coordenaday=p_coordenaday);
if (idexiste>0) then
return idexiste;
else
set idsub = (select max(idubicacion) from ubicacion);
if(idsub is null)then
set idsub=0;
end if;
insert into ubicacion values((idsub+1),p_coordenadax, p_coordenaday);
return (idsub+1);
end if;
end if;
end
//
delimiter ;
drop function if exists f_IdMenulist;
delimiter //
create function f_IdMenulist(p_menu nvarchar(90),
p_titulo nvarchar(90), p_ruta nvarchar(90),
p_icono nvarchar(90), p_posicion decimal(2,1)) returns int
begin
declare id int;
set id= (select idmenu from menu where menu=p_menu and
titulo=p_titulo);
if(id is null)then
set id = (select max(idmenu) from menu);
if(id is null)then
set id =0;
end if;
set id=id+1;
insert into menu values(id,p_menu,p_titulo,p_ruta,p_icono,p_posicion);
end if;
return id;
end
// delimiter ;
drop function if exists f_IdUsuario;
delimiter //
create function f_IdUsuario(p_usuario nvarchar(90)) returns int
begin
declare id int;
if (p_usuario is not null or (!(p_usuario='')))then
set id=(select idusuario from usuario where usuario=p_usuario);
if (id is null)then
set id=(select idusuario from usuario where correo=p_usuario);
if (id is null)then
set id=(select idusuario from usuario where telefono=p_usuario);
if (id is null)then
set id=0;
end if;
end if;
end if;
end if;
return id;
end
// delimiter ;
drop function if exists f_CorreoValido;
delimiter //
create function f_CorreoValido(p_correo nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare dbarroba int;
declare ind int;
set valido=1;
set n= length(p_correo);
if(n>=5)then
while(n>0)do
if(substr(p_correo,n,1)=' ')then
set valido=0;
set n=0;
end if;
set n=n-1;
end while;
if(valido=1)then
if(!(f_CaracterValido(substr(p_correo,1,1))=1 and
(f_LetraValida(substr(p_correo,(length(p_correo)),1)))=1))then
set valido=0;
end if;
if(valido=1)then
set valido=0;
set n=2;
while(n<((length(p_correo))-1))do
if(substr(p_correo,n,1)='@')then
set valido=1;
set ind=n;
set n=((length(p_correo))-1);
end if;
set n=n+1;
end while;
if(valido=1)then
set n=length(p_correo);
while(n>ind)do
if(substr(p_correo,n,1)='@')then
set valido=0;
set n=0;
end if;
set n=n-1;
end while;
if(valido=1)then
set valido=0;
set n=length(p_correo);
set n=n-1;
while(n>(ind+1))do
if(substr(p_correo,n,1)='.')then
set valido=1;
set n=0;
end if;
set n=n-1;
end while;
end if;
end if;
end if;
end if;
else
set valido=0;
end if;
return valido;
end
// delimiter ;
drop function if exists f_UsuarioValido;
delimiter //
create function f_UsuarioValido(p_usuario nvarchar(90)) returns int
begin
declare caracteres nvarchar(90);
declare valido int;
declare n int;
declare i int;
set caracteres='´`*/+.{}[]^~¬°"#$%&()=¿?¡!><@ ';
set valido=0;
set i=(length(p_usuario));
set n=(length(caracteres));
if(i>4)then
set valido=1;
while(i>0)do
while(n>0)do
if((substr(p_usuario,i,1))=(substr(caracteres,n,1)))then
set valido=0;
set n=0;
set i=0;
end if;
set n=(n-1);
end while;
set n=(length(caracteres));
set i=(i-1);
end while;
end if;
return valido;
end
// delimiter ;
drop function if exists f_NumeroValido;
delimiter //
create function f_NumeroValido(p_numero nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare numeros nvarchar(90);
set numeros='0123456789';
if(length(p_numero)=1)then
set valido=0;
set n=length(numeros);
while (n>0)do
if(((substr(p_numero,1,1))=(substr(numeros,n,1))))then
set valido=1;
set n=0;
end if;
set n=n-1;
end while;
else
set valido=0;
end if;
return valido;
end
// delimiter ;
drop function if exists f_LetraValida;
delimiter //
create function f_LetraValida(p_caracter nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare caracteres nvarchar(90);
set caracteres='QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm';
if(length(p_caracter)=1)then
set valido=0;
set n=length(caracteres);
while (n>0)do
if(((substr(p_caracter,1,1))=(substr(caracteres,n,1))))then
set valido=1;
set n=0;
end if;
set n=n-1;
end while;
else
set valido=0;
end if;
return valido;
end
// delimiter ;
drop function if exists f_CaracterValido;
delimiter //
create function f_CaracterValido(p_caracter nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare caracteres nvarchar(90);
set caracteres='0123456789QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm';
if(length(p_caracter)=1)then
set valido=0;
set n=length(caracteres);
while (n>0)do
if(((substr(p_caracter,1,1))=(substr(caracteres,n,1))))then
set valido=1;
set n=0;
end if;
set n=n-1;
end while;
else
set valido=0;
end if;
return valido;
end
// delimiter ;
drop function if exists f_TelefonoValido;
delimiter //
create function f_TelefonoValido(p_telefono nvarchar(90)) returns int
begin
declare valido int;
declare n int;
set valido=0;
set n = (length(p_telefono));
if(n>=10 and n<15)then
while(n>0)do
if((f_NumeroValido(substr(p_telefono,n,1)))=1) then
set valido=1;
set n=0;
end if;
set n=(n-1);
end while;
if(valido=1)then
set n = (length(p_telefono));
while (n>0)do
if(!(substr(p_telefono,n,1)='+' or
(f_NumeroValido(substr(p_telefono,n,1)))=1))then
set valido=0;
set n=0;
end if;
set n=(n-1);
end while;
end if;
else
set valido=0;
end if;
return valido;
end
// delimiter ;
drop function if exists f_DecimalValido;
delimiter //
create function f_DecimalValido(p_decimal nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare np int;
set valido=1;
set n=(length(p_decimal));
set np=(length(p_decimal));
while(n>1)do
if(!((substr(p_decimal,n,1)='.') or
((f_NumeroValido(substr(p_decimal,n,1)))=1)))then
set valido=0;
set n=0;
end if;
set n=n-1;
end while;
if(valido=1)then
set n = 1;
while (n<(length(p_decimal)))do
if(substr(p_decimal,n,1)='.')then
set np=n;
set n=(length(p_decimal));
end if;
set n=n+1;
end while;
set n=np+1;
while (n<=(length(p_decimal)))do
if(substr(p_decimal,n,1)='.')then
set valido=0;
set n=((length(p_decimal))+1);
end if;
set n=n+1;
end while;
if(valido=1)then
if(substr(p_decimal,1,1)='-' or
substr(p_decimal,1,1)='+' or
substr(p_decimal,1,1)='.' or
(f_NumeroValido(substr(p_decimal,1,1)))=1)then
set valido=1;
else
set valido=0;
end if;
end if;
end if;
return valido;
end
// delimiter ;
drop function if exists f_TelefonoValido;
delimiter //
create function f_TelefonoValido(p_telefono nvarchar(90)) returns int
begin
declare valido int;
declare n int;
declare np int;
set valido=1;
set n=(length(p_telefono));
set np=(length(p_telefono));
while(n>1)do
if(!((substr(p_telefono,n,1)='(') or
(substr(p_telefono,n,1)=')') or
(substr(p_telefono,n,1)=' ') or
((f_NumeroValido(substr(p_telefono,n,1)))=1)))then
set valido=0;
set n=0;
end if;
set n=n-1;
end while;
if(valido=1)then
if(substr(p_telefono,1,1)='+' or
(f_NumeroValido(substr(p_telefono,1,1)))=1)then
set valido=1;
else
set valido=0;
end if;
end if;
return valido;
end
// delimiter ;
drop function if exists f_HorarioValido;
delimiter //
create function f_HorarioValido(p_horario nvarchar(90)) returns int
begin
declare valido int;
declare n int;
set n=length(p_horario);
set valido=0;
if (n=4 or n=5)then
set valido=0;
if(substr(p_horario,2,1)=':' and n=4
and f_NumeroValido(substr(p_horario,1,1))=1
and f_NumeroValido(substr(p_horario,3,1))=1
and f_NumeroValido(substr(p_horario,4,1))=1)then
set valido=1;
else
if(substr(p_horario,3,1)=':' and n=5
and f_NumeroValido(substr(p_horario,1,1))=1
and f_NumeroValido(substr(p_horario,2,1))=1
and f_NumeroValido(substr(p_horario,4,1))=1
and f_NumeroValido(substr(p_horario,5,1))=1)then
set valido=1;
end if;
end if;
end if;
return valido;
end
// delimiter ;
drop function if exists f_FechaValida;
delimiter //
create function f_FechaValida(p_fecha nvarchar(90)) returns int
begin
declare valido int;
declare n int;
set valido=0;
set n = (length(p_fecha));
if(n=10 and substr(p_fecha,5,1)='-'
and substr(p_fecha,8,1)='-'
and f_NumeroValido(substr(p_fecha,1,1))=1
and f_NumeroValido(substr(p_fecha,2,1))=1
and f_NumeroValido(substr(p_fecha,3,1))=1
and f_NumeroValido(substr(p_fecha,4,1))=1
and f_NumeroValido(substr(p_fecha,7,1))=1
and f_NumeroValido(substr(p_fecha,6,1))=1
and f_NumeroValido(substr(p_fecha,9,1))=1
and f_NumeroValido(substr(p_fecha,10,1))=1)then
set valido=1;
end if;
return valido;
end
// delimiter ;
drop function if exists f_Amigos;
delimiter //
create function f_Amigos( idUsu int, idfriend int) returns nvarchar(90)
begin
declare suma int;
declare multi int;
declare conver nvarchar(90);
declare tipofinal int;
declare cuenta int;
declare cuenta2 int;
set cuenta= (select idrelusuarios from relusuarios where idusuario1=idUsu and idusuario2=idfriend);
set cuenta2= (select idrelusuarios from relusuarios where idusuario1=idfriend and idusuario2=idUsu);
set suma= cuenta+cuenta2;
set multi= cuenta*cuenta2;
set conver= concat(suma,'-',multi);
return conver;
end
// delimiter ;
/*--------------------------PROCEDIMIENTOS-------------------------*/
drop procedure if exists sp_AltaUsuario;
delimiter //
/*------Validar que un correo no sea un usuario, ni que un usuario sea un correo-------*/
create procedure sp_AltaUsuario (in p_usuario nvarchar(90),
in p_pasword nvarchar(90),in p_correo nvarchar(90),in p_nombre nvarchar(90),
in p_apellido nvarchar(90), in p_fechaNac nvarchar(10),
in p_sexo nvarchar(90), in p_imagen nvarchar(120), in p_tel nvarchar(15),
in p_coorx nvarchar(90),in p_coory nvarchar(90),in p_codigo nvarchar(35))
begin
declare ids int;
declare v_tel nvarchar(90);
declare v_im nvarchar(120);
declare v_ub int;
if(!(p_usuario='' or p_pasword =''or p_correo='' or p_nombre='' or
p_apellido = '' or p_nombre = '' or p_apellido=''or
p_fechaNac='' or p_sexo='' or p_codigo='' or
p_usuario is null or p_pasword is null or p_correo is null or p_nombre is null or
p_apellido is null or p_nombre is null or p_apellido is null or
p_fechaNac is null or p_sexo is null or p_codigo is null ))then
if( f_UsuarioValido(p_usuario)=1)then
if( f_CorreoValido(p_correo)=1)then
if (p_sexo='M' or p_sexo='F') then
if(f_FechaValida(p_fechaNac)=1)then
if((f_IdUsuario(p_usuario)) = 0 ) then
if((f_IdUsuario(p_correo)) = 0 ) then
if((f_IdUsuario(p_tel)) = 0 ) then
if (((p_coorx='')and(p_coory='')) or ((p_coorx is null)and(p_coory is null)) or
((f_DecimalValido(p_coorx)=1)and(f_DecimalValido(p_coory)=1))) then
if (p_tel='' or p_tel is null or f_TelefonoValido(p_tel)=1) then
if (p_tel='' or p_tel is null ) then
set v_tel='';
else
set v_tel=p_tel;
end if;
if(p_imagen='' or p_imagen is null)then
if(p_sexo='M')then
set v_im='http://i.imgur.com/6cY0syl.png';
else
set v_im='http://i.imgur.com/BzNupgP.png';
end if;
else
set v_im=p_imagen;
end if;
if((((p_coorx='')and(p_coory='')) or ((p_coorx is null)and(p_coory is null))))then
set v_ub=null;
else
set v_ub=f_IdUbicacion(p_coorx,p_coory);
end if;
set ids=(select max(idusuario) from usuario);
if(ids is null)then
set ids=0;
end if;
insert into usuario values((ids+1), p_nombre, p_apellido,
p_usuario, p_pasword, p_correo,p_fechaNac, p_sexo, v_tel,v_im ,'E',v_ub,p_codigo,null, null, now());
select 1 as 'idStatus', 'sUsuarioAgregado'
as 'mensaje', u.* from usuario as u where idusuario=(ids+1);
else
select 0 as 'idStatus', 'sTelefonoNoValido' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sCoordenadaNoValida' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sTelefonoYaExiste' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sCorreoYaExiste' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sUsuarioYaExiste' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sFechaNoValida' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sSexoNoValido' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sCorreoNoValido' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sUsuarioNoValido' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sNoCamposVacios' as 'mensaje';
end if;
end
//
delimiter ;
drop procedure if exists sp_Chat;
delimiter //
create procedure sp_Chat(in idUsu int, in idfriend int)
begin
declare suma int;
declare multi int;
declare conver nvarchar(90);
declare tipofinal int;
declare cuenta int;
declare cuenta2 int;
set cuenta= (select idrelusuarios from relusuarios where idusuario1=idUsu and idusuario2=idfriend);
set cuenta2= (select idrelusuarios from relusuarios where idusuario1=idfriend and idusuario2=idUsu);
set suma= cuenta+cuenta2;
set multi= cuenta*cuenta2;
set conver= concat(suma,'-',multi);
select suma as 'sum' , multi as 'multi';
end
// delimiter ;
drop procedure if exists sp_ConsultaUsuario;
delimiter //
create procedure sp_ConsultaUsuario (in p_usuario nvarchar(90))
begin
declare id int;
set id =f_IdUsuario(p_usuario);
if id > 0 then
select 1 as 'idStatus', 'sUsuarioEncontrado' as 'mensaje', u.* from usuario as u where idusuario=id;
else
select 0 as 'idStatus', 'sUsuarioNoExiste' as 'mensaje';
end if;
end
//
delimiter ;
/*-----Validar el nusuario antes de modificar el usuario-----*/
drop procedure if exists sp_ModificaUsuario;
delimiter //
create procedure sp_ModificaUsuario (in p_usuario nvarchar(90),
in p_nusuario nvarchar(90),
in p_nombre nvarchar(90), in p_apellido nvarchar(90),
in p_fechaNac nvarchar(10), in p_sexo char(1), in p_imagen nvarchar(120),
in p_tel nvarchar(15),in p_coorx nvarchar(90),in p_coory nvarchar(90))
begin
declare id int;
declare v_tel nvarchar(90);
declare v_im nvarchar(120);
declare v_ub int;
if(!(p_usuario='' or p_nusuario=''
or p_nombre='' or
p_apellido = '' or p_nombre = '' or p_apellido=''or
p_fechaNac='' or p_sexo='' or
p_usuario is null or p_nusuario is null
or p_nombre is null or
p_apellido is null or p_nombre is null or p_apellido is null or
p_fechaNac is null or p_sexo is null))then
if( f_UsuarioValido(p_nusuario)=1)then
if (p_sexo='M' or p_sexo='F') then
if(f_FechaValida(p_fechaNac)=1)then
set id = (select idusuario from usuario where usuario=p_usuario);
if (id > 0) then
if((f_IdUsuario(p_nusuario))=0 or (p_usuario=p_nusuario))then
if((f_IdUsuario(p_tel))=0 or f_IdUsuario(p_usuario)=f_IdUsuario(p_tel))then
if (((p_coorx='')and(p_coory='')) or
((p_coorx is null)and(p_coory is null)) or
((f_DecimalValido(p_coorx)=1)and(f_DecimalValido(p_coory)=1))) then
if (p_tel='' or p_tel is null or f_TelefonoValido(p_tel)=1) then
if (p_tel='' or p_tel is null ) then
set v_tel='';
else
set v_tel=p_tel;
end if;
if(p_imagen='' or p_imagen is null)then
if(p_sexo='M')then
set v_im='http://i.imgur.com/6cY0syl.png';
else
set v_im='http://i.imgur.com/BzNupgP.png';
end if;
else
set v_im=p_imagen;
end if;
if((((p_coorx='')and(p_coory='')) or ((p_coorx is null)and(p_coory is null))))then
set v_ub=null;
else
set v_ub=f_IdUbicacion(p_coorx,p_coory);
end if;
update usuario set usuario=p_nusuario, nombre=p_nombre, apellido=p_apellido,
fechaNac=p_fechaNac, sexo=p_sexo, imagen=v_im, telefono=v_tel, idubicacion=v_ub where idusuario=id;
select 1 as 'idStatus', 'sUsuarioModificado';
else
select 0 as 'idStatus', 'sTelefonoNoValido' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sCoordenadaNoValida' as 'mensaje' ;
end if;
else
select 0 as 'idStatus', 'sTelefonoYaExiste' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sUsuarioYaExiste' as 'mensaje';
end if;
else
select 0 as 'idStatus','sUsuarioNoExiste' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sFechaNoValida' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sSexoNoValido' as 'mensaje';
end if;
else
select 0 as 'idStatus', 'sUsuarioNoValido' as 'mensaje';
end if;
else
select 0 as 'idStatus','sNoCamposVacios' as 'mensaje';
end if;
end
//
delimiter ;
drop procedure if exists sp_ConfirmacionBajaUsuario;
delimiter //
create procedure sp_ConfirmacionBajaUsuario (in p_usuario nvarchar(90),
in p_pasword nvarchar(90))
begin
declare id int;
set id=(select idusuario from usuario where usuario=p_usuario and pasword=p_pasword);
if id > 0 then