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.

76 lines
2.9KB

  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 TotalVehiculos class based on the database table
  20. */
  21. public class TotalVehiculos : Object {
  22. /**
  23. * The total of vehicles
  24. */
  25. public uint total_veh { get; set; default = 0; }
  26. /**
  27. * Initialize the TotalVehiculos class
  28. * @param total_veh The total of vehicles
  29. */
  30. public TotalVehiculos (uint total_veh = 0) {
  31. this.total_veh = total_veh;
  32. }
  33. /**
  34. * Get all tuples and fields from database
  35. * @param conn.db.The database conn.db.ction to use
  36. * @return Returns a list of TotalVehiculos
  37. */
  38. public static List<TotalVehiculos> get_all_vehicle_totals (Connection conn) {
  39. var res = conn.db.exec ("
  40. SELECT TotalVeh FROM TOTAL_VEHICULOS
  41. ");
  42. if (res.get_status () != ExecStatus.TUPLES_OK) {
  43. #if DEBUG
  44. error (conn.db.get_error_message ());
  45. #else
  46. warning (conn.db.get_error_message ());
  47. return new List<TotalVehiculos> ();
  48. #endif
  49. }
  50. var wra = new ResultWrapper (res);
  51. List<TotalVehiculos> list = new List<TotalVehiculos> ();
  52. int n = res.get_n_tuples ();
  53. for (int i = 0; i < n; i++) {
  54. try {
  55. var total = new TotalVehiculos (wra.get_int_n (i, "TotalVeh"));
  56. list.append (total);
  57. }
  58. catch (Error e) {
  59. #if DEBUG
  60. error (e.message);
  61. #else
  62. warning (e.message);
  63. #endif
  64. }
  65. }
  66. return list;
  67. }
  68. }
  69. }
  70. }