namespace Sernatur { namespace DB { using Postgres; using Wrapper; public class Turista : GLib.Object { public string rut_turista { get; set; default = ""; } public string nombre_turista { get; set; default = ""; } public string fecha_nacimento { get; set; default = ""; } public ContactoEmergencia contacto_emergencia { get; set; default = null; } public Turista (string rut_turista = "", string nombre_turista = "", string fecha_nacimento = "", ContactoEmergencia? contacto_emergencia = null) { this.rut_turista = rut_turista; this.nombre_turista = nombre_turista; this.fecha_nacimento = fecha_nacimento; this.contacto_emergencia = contacto_emergencia; } public static Turista[]? get_all_turistas(Database conn) { var res = conn.exec (" SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento, C.id_contacto, C.telefono_emergencia, C.nombre_emergencia FROM turista T JOIN contacto_emergencia C ON (T.id_contacto = C.id_contacto) "); 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); Turista[] turistas = {}; int n = res.get_n_tuples (); for (int i = 0; i < n; i++) { try { var turista = new Turista (wra.get_string_n (i, "rut_turista"), wra.get_string_n (i, "nombre_turista"), wra.get_string_n (i, "fecha_nacimento"), new ContactoEmergencia (wra.get_int_n (i, "id_contacto"), wra.get_int_n (i, "telefono_emergencia"), wra.get_string_n (i, "nombre_emergencia") ) ); turistas += turista; } catch (Error e) { #if DEBUG error (e.message); #else warning (e.message); #endif } } return turistas; } } } }