namespace Sernatur { namespace DB { using Postgres; using Wrapper; public class Ciudad : GLib.Object { public uint id_ciudad { get; set; default = 0; } public string nombre_ciudad { get; set; default = ""; } public Region region { get; set; default = null; } public Ciudad (uint id_ciudad = 0, string nombre_ciudad = "", Region? region = null) { this.id_ciudad = id_ciudad; this.nombre_ciudad = nombre_ciudad; this.region = region; } public static Ciudad[]? get_all_ciudades(Database conn) { var res = conn.exec (" SELECT C.id_ciudad, C.nombre_ciudad, R.id_region, R.nombre_region FROM ciudad C 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); Ciudad[] ciudades = {}; int n = res.get_n_tuples (); for (int i = 0; i < n; i++) { try { var ciudad = 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") ) ); ciudades += ciudad; } catch (Error e) { #if DEBUG error (e.message); #else warning (e.message); #endif } } return ciudades; } } } }