Este proyecto es una aplicación para trabajar con un base de datos Postgresql por el ramo de base de datos. https://cromer.cl/sernatur
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.8KB

  1. /*
  2. * Copyright 2018-2019 Chris Cromer
  3. *
  4. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  5. *
  6. * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  7. *
  8. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  9. *
  10. * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  11. *
  12. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  13. */
  14. namespace LibSernatur {
  15. namespace DB {
  16. using Postgres;
  17. using Wrapper;
  18. /**
  19. * The TieneEnfermedad class based on the database table
  20. */
  21. public class TieneEnfermedad : Object {
  22. /**
  23. * The tourist
  24. */
  25. public Turista turista { get; set; default = null; }
  26. /**
  27. * The illness
  28. */
  29. public Enfermedad enfermedad { get; set; default = null; }
  30. /**
  31. * Initialize the TieneEnfermedad class
  32. * @param turista The tourist
  33. * @param enfermedad The illness
  34. */
  35. public TieneEnfermedad (Turista? turista = null, Enfermedad? enfermedad = null) {
  36. this.turista = turista;
  37. this.enfermedad = enfermedad;
  38. }
  39. /**
  40. * Get all tuples and fields from database
  41. * @param conn.db.The database conn.db.ction to use
  42. * @return Returns a list of TieneEnfermedad
  43. */
  44. public static List<TieneEnfermedad> get_all_tiene_enfermedades (Connection conn) {
  45. var res = conn.db.exec ("
  46. SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
  47. C.id_contacto, C.telefono_emergencia, C.nombre_emergencia,
  48. E.id_enfermedad, E.descripcion_enfermedad
  49. FROM tiene_enfermedad TE
  50. JOIN turista T ON (TE.rut_turista = T.rut_turista)
  51. JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto)
  52. JOIN enfermedad E ON (TE.id_enfermedad = E.id_enfermedad)
  53. ");
  54. if (res.get_status () != ExecStatus.TUPLES_OK) {
  55. #if DEBUG
  56. error (conn.db.get_error_message ());
  57. #else
  58. warning (conn.db.get_error_message ());
  59. return new List<TieneEnfermedad> ();
  60. #endif
  61. }
  62. var wra = new ResultWrapper (res);
  63. List<TieneEnfermedad> list = new List<TieneEnfermedad> ();
  64. int n = res.get_n_tuples ();
  65. for (int i = 0; i < n; i++) {
  66. try {
  67. var tiene_enfermedad = new TieneEnfermedad (
  68. new Turista (wra.get_string_n (i, "rut_turista"),
  69. wra.get_string_n (i, "nombre_turista"),
  70. wra.get_string_n (i, "fecha_nacimento"),
  71. new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
  72. wra.get_int_n (i, "telefono_emergencia"),
  73. wra.get_string_n (i, "nombre_emergencia")
  74. )
  75. ),
  76. new Enfermedad (wra.get_int_n (i, "id_enfermedad"),
  77. wra.get_string_n (i, "descripcion_enfermedad")
  78. )
  79. );
  80. list.append (tiene_enfermedad);
  81. }
  82. catch (Error e) {
  83. #if DEBUG
  84. error (e.message);
  85. #else
  86. warning (e.message);
  87. #endif
  88. }
  89. }
  90. return list;
  91. }
  92. }
  93. }
  94. }