70 lines
1.8 KiB
Vala
70 lines
1.8 KiB
Vala
namespace LibSernatur {
|
|
namespace DB {
|
|
using Postgres;
|
|
using Wrapper;
|
|
|
|
public class Guia : GLib.Object {
|
|
public string rut_guia { get; set; default = ""; }
|
|
public string nombre_guia { get; set; default = ""; }
|
|
public string calle { get; set; default = ""; }
|
|
public uint numero { get; set; default = 0; }
|
|
public Ciudad ciudad { get; set; default = null; }
|
|
|
|
public Guia (string rut_guia = "", string nombre_guia = "", string calle = "", uint numero = 0, Ciudad? ciudad = null) {
|
|
this.rut_guia = rut_guia;
|
|
this.nombre_guia = nombre_guia;
|
|
this.calle = calle;
|
|
this.numero = numero;
|
|
this.ciudad = ciudad;
|
|
}
|
|
|
|
public static Guia[]? get_all_guias(Database conn) {
|
|
var res = conn.exec ("
|
|
SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero,
|
|
C.id_ciudad, C.nombre_ciudad,
|
|
R.id_region, R.nombre_region
|
|
FROM guia G
|
|
JOIN ciudad C ON (G.id_ciudad = C.id_ciudad)
|
|
JOIN region R ON (C.id_region = R.id_region)
|
|
");
|
|
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);
|
|
Guia[] guias = {};
|
|
int n = res.get_n_tuples ();
|
|
for (int i = 0; i < n; i++) {
|
|
try {
|
|
var guia = new Guia (wra.get_string_n (i, "rut_guia"),
|
|
wra.get_string_n (i, "nombre_guia"),
|
|
wra.get_string_n (i, "calle"),
|
|
wra.get_int_n (i, "numero"),
|
|
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")
|
|
)
|
|
)
|
|
);
|
|
guias += guia;
|
|
}
|
|
catch (Error e) {
|
|
#if DEBUG
|
|
error (e.message);
|
|
#else
|
|
warning (e.message);
|
|
#endif
|
|
}
|
|
}
|
|
return guias;
|
|
}
|
|
}
|
|
}
|
|
}
|