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.

89 lines
3.6KB

  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 ContactoEmergencia class based on the database table
  20. */
  21. public class ContactoEmergencia : Object {
  22. /**
  23. * The id of the contact
  24. */
  25. public uint id_contacto { get; set; default = 0; }
  26. /**
  27. * The contact's phone number
  28. */
  29. public uint telefono_emergencia { get; set; default = 0; }
  30. /**
  31. * The contact's name
  32. */
  33. public string nombre_emergencia { get; set; default = ""; }
  34. /**
  35. * Initialize the ContactoEmergencia class
  36. * @param id_contacto The id of the contact
  37. * @param telefono_emergencia The contact's phone number
  38. * @param nombre_emergencia The contact's name
  39. */
  40. public ContactoEmergencia (uint id_contacto = 0, uint telefono_emergencia = 0, string nombre_emergencia = "") {
  41. this.id_contacto = id_contacto;
  42. this.telefono_emergencia = telefono_emergencia;
  43. this.nombre_emergencia = nombre_emergencia;
  44. }
  45. /**
  46. * Get all tuples and fields from database
  47. * @param conn.db.The database conn.db.ction to use
  48. * @return Returns a list of ContactoEmergencia
  49. */
  50. public static List<ContactoEmergencia> get_all_contactos (Connection conn) {
  51. var res = conn.db.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia");
  52. if (res.get_status () != ExecStatus.TUPLES_OK) {
  53. #if DEBUG
  54. error (conn.db.get_error_message ());
  55. #else
  56. warning (conn.db.get_error_message ());
  57. return new List<ContactoEmergencia> ();
  58. #endif
  59. }
  60. var wra = new ResultWrapper (res);
  61. List<ContactoEmergencia> list = new List<ContactoEmergencia> ();
  62. int n = res.get_n_tuples ();
  63. for (int i = 0; i < n; i++) {
  64. try {
  65. var contacto = new ContactoEmergencia (wra.get_int_n (i, "id_contacto"),
  66. wra.get_int_n (i, "telefono_emergencia"),
  67. wra.get_string_n (i, "nombre_emergencia")
  68. );
  69. list.append (contacto);
  70. }
  71. catch (Error e) {
  72. #if DEBUG
  73. error (e.message);
  74. #else
  75. warning (e.message);
  76. #endif
  77. }
  78. }
  79. return list;
  80. }
  81. }
  82. }
  83. }