namespace Sernatur { namespace DB { using Postgres; using Wrapper; public class Arrienda : GLib.Object { public uint precio { get; set; default = 0; } public string fecha_devolucion { get; set; default = ""; } public Vehiculo vehiculo { get; set; default = null; } public Empresa empresa { get; set; default = null; } public Arrienda (uint precio = 0, string fecha_devolucion = "", Vehiculo? vehiculo = null, Empresa? empresa = null) { this.precio = precio; this.fecha_devolucion = fecha_devolucion; this.vehiculo = vehiculo; this.empresa = empresa; } public static Arrienda[]? get_all_arriendas(Database conn) { var res = conn.exec (" SELECT A.precio, A.fecha_devolucion, V.patente, V.ano_vehiculo, V.marca, V.capacidad, E.rut_empresa, E.nombre_empresa, E.contacto, E.telefono FROM arrienda A JOIN vehiculo V ON (A.patente = V.patente) JOIN empresa E ON (A.rut_empresa = E.rut_empresa) "); if (res.get_status () != ExecStatus.TUPLES_OK) { #if DEBUG error (conn.get_error_message ()); #else warning (conn.get_error_message ()); return null; #endif } var wra = new ResultWrapper (res); Arrienda[] arriendas = {}; int n = res.get_n_tuples (); for (int i = 0; i < n; i++) { try { var arrienda = new Arrienda (wra.get_int_n (i, "precio"), wra.get_string_n (i, "fecha_devolucion"), new Vehiculo (wra.get_string_n (i, "patente"), wra.get_int_n (i, "ano_vehiculo"), wra.get_string_n (i, "marca"), wra.get_int_n (i, "capacidad") ), new Empresa (wra.get_string_n (i, "rut_empresa"), wra.get_string_n (i, "nombre_empresa"), wra.get_string_n (i, "contacto"), wra.get_int_n (i, "telefono") ) ); arriendas += arrienda; } catch (Error e) { #if DEBUG error (e.message); #else warning (e.message); #endif } } return arriendas; } } } }