namespace Sernatur { namespace DB { using Postgres; using Wrapper; public class Empresa : GLib.Object { public string rut_empresa { get; set; default = ""; } public string nombre_empresa { get; set; default = ""; } public string contacto { get; set; default = ""; } public uint telefono { get; set; default = 0; } public Empresa (string rut_empresa = "", string nombre_empresa = "", string contacto = "", uint telefono = 0) { this.rut_empresa = rut_empresa; this.nombre_empresa = nombre_empresa; this.contacto = contacto; this.telefono = telefono; } public static Empresa[]? get_all_empresas(Database conn) { var res = conn.exec (" SELECT rut_empresa, nombre_empresa, contacto, telefono FROM 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); Empresa[] empresas = {}; int n = res.get_n_tuples (); for (int i = 0; i < n; i++) { try { var empresa = 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") ); empresas += empresa; } catch (Error e) { #if DEBUG error (e.message); #else warning (e.message); #endif } } return empresas; } } } }