sernatur/lib/db/requerir_auto.vala
2019-01-05 00:28:18 -03:00

78 lines
2.2 KiB
Vala

namespace LibSernatur {
namespace DB {
using Postgres;
using Wrapper;
public class RequerirAuto : GLib.Object {
public string chofer { get; set; default = ""; }
public Tour tour { get; set; default = null; }
public Vehiculo vehiculo { get; set; default = null; }
public RequerirAuto (string chofer = "", Tour? tour = null, Vehiculo? vehiculo = null) {
this.chofer = chofer;
this.tour = tour;
this.vehiculo = vehiculo;
}
public static RequerirAuto[]? get_all_requerir_autos(Database conn) {
var res = conn.exec ("
SELECT R.chofer,
T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R2.id_region, R2.nombre_region,
V.patente, V.ano_vehiculo, V.marca, V.capacidad
FROM requerir_auto R
JOIN tour T ON (R.id_tour = T.id_tour)
JOIN ciudad C ON (T.id_ciudad = C.id_ciudad)
JOIN region R2 ON (C.id_region = R2.id_region)
Join vehiculo V ON (R.patente = V.patente)
");
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);
RequerirAuto[] requerir_autos = {};
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var requerir_auto = new RequerirAuto (wra.get_string_n (i, "chofer"),
new Tour (wra.get_int_n (i, "id_tour"),
wra.get_string_n (i, "nombre_tour"),
wra.get_int_n (i, "costo_indiv"),
wra.get_int_n (i, "costo_grupal"),
wra.get_int_n (i, "minima_personas"),
new Ciudad (wra.get_int_n (i, "id_ciudad"),
wra.get_string_n (i, "nombre_ciudad"),
new Region (wra.get_int_n (i, "id_region"),
wra.get_string_n (i, "nombre_region")
)
)
),
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")
)
);
requerir_autos += requerir_auto;
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return requerir_autos;
}
}
}
}