a lot of work

This commit is contained in:
2019-01-19 13:44:30 -03:00
parent 404b68b791
commit 3aaf811190
50 changed files with 1959 additions and 378 deletions

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Arrienda class based on the database table
*/
public class Arrienda : GLib.Object {
public class Arrienda : Object {
/**
* The price
*/
@@ -54,11 +54,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Arrienda
*/
public static List<Arrienda> get_all_arriendas (Database conn) {
var res = conn.exec ("
public static List<Arrienda> get_all_arriendas (Connection conn) {
var res = conn.db.exec ("
SELECT A.precio, A.fecha_devolucion,
V.patente, V.ano_vehiculo, V.marca, V.capacidad,
E.rut_empresa, E.nombre_empresa, E.contacto, E.telefono
@@ -68,9 +68,9 @@ JOIN empresa E ON (A.rut_empresa = E.rut_empresa)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Arrienda> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Asociado class based on the database table
*/
public class Asociado : GLib.Object {
public class Asociado : Object {
public string fecha_llegada { get; set; default = ""; }
public string hora_llegada { get; set; default = ""; }
public string fecha_salida { get; set; default = ""; }
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Asociado
*/
public static List<Asociado> get_all_asociados (Database conn) {
var res = conn.exec ("
public static List<Asociado> get_all_asociados (Connection conn) {
var res = conn.db.exec ("
SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida,
T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
@@ -70,9 +70,9 @@ JOIN region R2 ON (C2.id_region = R2.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Asociado> ();
#endif
}
@@ -99,7 +99,72 @@ JOIN region R2 ON (C2.id_region = R2.id_region)
)
),
new Lugar (wra.get_int_n (i, "id_lugar"),
wra.get_string_n (i, "nombre_lugar"),
wra.get_int_n (i, "valor_entrada"),
wra.get_int_n (i, "nivel"),
new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"),
wra.get_string_n (i, "nombre_ciudad_lugar"),
new Region (wra.get_int_n (i, "id_region_lugar"),
wra.get_string_n (i, "nombre_region_lugar")
)
)
)
);
list.append (asociado);
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
#endif
}
}
return list;
}
/**
* Get all tuples and fields from database
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Asociado based off a tour id
*/
public static List<Asociado> get_all_asociados_by_tour (Connection conn, Tour tour) throws PostgresError, DBError {
if (tour.id_tour == 0) {
throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!"));
}
var res = conn.db.exec (Query.get_query (conn, Query.Type.SELECT_ALL_ASSOCIATED_BY_TOUR, tour));
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.db.get_error_message ());
#else
warning (conn.db.get_error_message ());
return new List<Asociado> ();
#endif
}
var wra = new ResultWrapper (res);
List<Asociado> list = new List<Asociado> ();
int n = res.get_n_tuples ();
for (int i = 0; i < n; i++) {
try {
var asociado = new Asociado (wra.get_string_n (i, "fecha_llegada"),
wra.get_string_n (i, "hora_llegada"),
wra.get_string_n (i, "fecha_salida"),
wra.get_string_n (i, "hora_salida"),
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 Lugar (wra.get_int_n (i, "id_lugar"),
wra.get_string_n (i, "nombre_lugar"),
wra.get_int_n (i, "valor_entrada"),
wra.get_int_n (i, "nivel"),
new Ciudad (wra.get_int_n (i, "id_ciudad_lugar"),

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Categoria class based on the database table
*/
public class Categoria : GLib.Object {
public class Categoria : Object {
/**
* The id of the category
*/
@@ -42,18 +42,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Categoria
*/
public static List<Categoria> get_all_categorias (Database conn) {
var res = conn.exec ("
public static List<Categoria> get_all_categorias (Connection conn) {
var res = conn.db.exec ("
SELECT id_categoria, descripcion_categoria FROM categoria
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Categoria> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Ciudad class based on the database table
*/
public class Ciudad : GLib.Object {
public class Ciudad : Object {
/**
* The id of the city
*/
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Ciudad
*/
public static List<Ciudad> get_all_ciudades (Database conn) {
var res = conn.exec ("
public static List<Ciudad> get_all_ciudades (Connection conn) {
var res = conn.db.exec ("
SELECT C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM ciudad C
@@ -60,9 +60,9 @@ JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Ciudad> ();
#endif
}
@@ -93,12 +93,12 @@ JOIN region R ON (C.id_region = R.id_region)
/**
* Get all tuples and fields from database that are within a certain region
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @param region_id The id of the region to filter that results
* @return Returns a list of Ciudad
*/
public static List<Ciudad> get_all_ciudades_in_region(Database conn, uint region_id) {
var res = conn.exec ("
public static List<Ciudad> get_all_ciudades_in_region(Connection conn, uint region_id) {
var res = conn.db.exec ("
SELECT C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
FROM ciudad C
@@ -107,9 +107,9 @@ WHERE (R.id_region = " + region_id.to_string () + ")
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Ciudad> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The ContactoEmergencia class based on the database table
*/
public class ContactoEmergencia : GLib.Object {
public class ContactoEmergencia : Object {
/**
* The id of the contact
*/
@@ -48,16 +48,16 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of ContactoEmergencia
*/
public static List<ContactoEmergencia> get_all_contactos (Database conn) {
var res = conn.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia");
public static List<ContactoEmergencia> get_all_contactos (Connection conn) {
var res = conn.db.exec ("SELECT id_contacto, telefono_emergencia, nombre_emergencia FROM contacto_emergencia");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<ContactoEmergencia> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Descuento class based on the database table
*/
public class Descuento : GLib.Object {
public class Descuento : Object {
/**
* The id of the discount
*/
@@ -48,18 +48,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Descuento
*/
public static List<Descuento> get_all_descuentos (Database conn) {
var res = conn.exec ("
public static List<Descuento> get_all_descuentos (Connection conn) {
var res = conn.db.exec ("
SELECT id_descuento, descripcion_descuento, porcentaje FROM descuento
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Descuento> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Empresa class based on the database table
*/
public class Empresa : GLib.Object {
public class Empresa : Object {
/**
* The RUT of the company
*/
@@ -54,18 +54,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Empresa
*/
public static List<Empresa> get_all_empresas (Database conn) {
var res = conn.exec ("
public static List<Empresa> get_all_empresas (Connection conn) {
var res = conn.db.exec ("
SELECT rut_empresa, nombre_empresa, contacto, telefono FROM empresa
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Empresa> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Enfermedad class based on the database table
*/
public class Enfermedad : GLib.Object {
public class Enfermedad : Object {
/**
* The id of the illness
*/
@@ -42,18 +42,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Enfermedad
*/
public static List<Enfermedad> get_all_enfermedades (Database conn) {
var res = conn.exec ("
public static List<Enfermedad> get_all_enfermedades (Connection conn) {
var res = conn.db.exec ("
SELECT id_enfermedad, descripcion_enfermedad FROM enfermedad
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Enfermedad> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Esepcialidad class based on the database table
*/
public class Especialidad : GLib.Object {
public class Especialidad : Object {
/**
* The id of the specialty
*/
@@ -42,18 +42,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Especialidad
*/
public static List<Especialidad> get_all_especialidades (Database conn) {
var res = conn.exec ("
public static List<Especialidad> get_all_especialidades (Connection conn) {
var res = conn.db.exec ("
SELECT id_especialidad, descripcion_especialidad FROM especialidad
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Especialidad> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Guia class based on the database table
*/
public class Guia : GLib.Object {
public class Guia : Object {
/**
* The RUT of the guide
*/
@@ -60,11 +60,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Guia
*/
public static List<Guia> get_all_guias (Database conn) {
var res = conn.exec ("
public static List<Guia> get_all_guias (Connection conn) {
var res = conn.db.exec ("
SELECT G.rut_guia, G.nombre_guia, G.calle, G.numero,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
@@ -74,9 +74,9 @@ JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Guia> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Lugar class based on the database table
*/
public class Lugar : GLib.Object {
public class Lugar : Object {
/**
* The id of the place
*/
@@ -60,11 +60,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Lugar
*/
public static List<Lugar> get_all_lugares (Database conn) {
var res = conn.exec ("
public static List<Lugar> get_all_lugares (Connection conn) {
var res = conn.db.exec ("
SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region
@@ -74,9 +74,9 @@ JOIN region R ON (C.id_region = R.id_region)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Lugar> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Participa class based on the database table
*/
public class Participa : GLib.Object {
public class Participa : Object {
/**
* The tour
*/
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Participa
*/
public static List<Participa> get_all_participas (Database conn) {
var res = conn.exec ("
public static List<Participa> get_all_participas (Connection conn) {
var res = conn.db.exec ("
SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
@@ -71,9 +71,9 @@ JOIN categoria C3 ON (P.id_categoria = C3.id_categoria)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Participa> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Posee class based on the database table
*/
public class Posee : GLib.Object {
public class Posee : Object {
/**
* The specialty level
*/
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Posee
*/
public static List<Posee> get_all_posees (Database conn) {
var res = conn.exec ("
public static List<Posee> get_all_posees (Connection conn) {
var res = conn.db.exec ("
SELECT P.nivel_especialidad,
G.rut_guia, G.nombre_guia, G.calle, G.numero,
C.id_ciudad, C.nombre_ciudad,
@@ -66,9 +66,9 @@ JOIN especialidad E ON (P.id_especialidad = E.id_especialidad)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Posee> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Realiza class based on the database table
*/
public class Realiza : GLib.Object {
public class Realiza : Object {
/**
* The tour
*/
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Realiza
*/
public static List<Realiza> get_all_realizas (Database conn) {
var res = conn.exec ("
public static List<Realiza> get_all_realizas (Connection conn) {
var res = conn.db.exec ("
SELECT T.id_tour, T.nombre_tour, T.costo_indiv, T.costo_grupal, T.minima_personas,
C.id_ciudad, C.nombre_ciudad,
R.id_region, R.nombre_region,
@@ -69,9 +69,9 @@ JOIN descuento D ON (RE.id_descuento = D.id_descuento)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Realiza> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Region class based on the database table
*/
public class Region : GLib.Object {
public class Region : Object {
/**
* The id of the region
*/
@@ -42,18 +42,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Region
*/
public static List<Region> get_all_regiones (Database conn) {
var res = conn.exec ("
public static List<Region> get_all_regiones (Connection conn) {
var res = conn.db.exec ("
SELECT id_region, nombre_region FROM region
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Region> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The RegionesSinDescuento class based on the database table
*/
public class RegionesSinDescuento : GLib.Object {
public class RegionesSinDescuento : Object {
/**
* The name of the region
*/
@@ -41,18 +41,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of RegionesSinDescuento
*/
public static List<RegionesSinDescuento> get_all_regions_without_discount (Database conn) {
var res = conn.exec ("
public static List<RegionesSinDescuento> get_all_regions_without_discount (Connection conn) {
var res = conn.db.exec ("
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<RegionesSinDescuento> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The RequerirAuto class based on the database table
*/
public class RequerirAuto : GLib.Object {
public class RequerirAuto : Object {
/**
* The chofer
*/
@@ -48,11 +48,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of RequerirAuto
*/
public static List<RequerirAuto> get_all_requerir_autos (Database conn) {
var res = conn.exec ("
public static List<RequerirAuto> get_all_requerir_autos (Connection conn) {
var res = conn.db.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,
@@ -66,9 +66,9 @@ Join vehiculo V ON (R.patente = V.patente)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<RequerirAuto> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The TieneEnfermedad class based on the database table
*/
public class TieneEnfermedad : GLib.Object {
public class TieneEnfermedad : Object {
/**
* The tourist
*/
@@ -42,11 +42,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TieneEnfermedad
*/
public static List<TieneEnfermedad> get_all_tiene_enfermedades (Database conn) {
var res = conn.exec ("
public static List<TieneEnfermedad> get_all_tiene_enfermedades (Connection conn) {
var res = conn.db.exec ("
SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
C.id_contacto, C.telefono_emergencia, C.nombre_emergencia,
E.id_enfermedad, E.descripcion_enfermedad
@@ -57,9 +57,9 @@ JOIN enfermedad E ON (TE.id_enfermedad = E.id_enfermedad)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TieneEnfermedad> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The TotalArriendos class based on the database table
*/
public class TotalArriendos : GLib.Object {
public class TotalArriendos : Object {
/**
* The total of rented vehicles
*/
@@ -36,18 +36,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalArriendos
*/
public static List<TotalArriendos> get_all_rent_totals (Database conn) {
var res = conn.exec ("
public static List<TotalArriendos> get_all_rent_totals (Connection conn) {
var res = conn.db.exec ("
SELECT TotalArriendo FROM TOTAL_ARRIENDOS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalArriendos> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The TotalCoordinadores class based on the database table
*/
public class TotalCoordinadores : GLib.Object {
public class TotalCoordinadores : Object {
/**
* The id of the region
*/
@@ -48,18 +48,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalCoordinadores
*/
public static List<TotalCoordinadores> get_all_coordinator_totals (Database conn) {
var res = conn.exec ("
public static List<TotalCoordinadores> get_all_coordinator_totals (Connection conn) {
var res = conn.db.exec ("
SELECT idT, nombreT, TotalCoordinadores FROM TOTAL_COORDINADORES
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalCoordinadores> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The TotalTuristas class based on the database table
*/
public class TotalTuristas : GLib.Object {
public class TotalTuristas : Object {
/**
* The id of the tour
*/
@@ -48,18 +48,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalTuristas
*/
public static List<TotalTuristas> get_all_tourist_totals (Database conn) {
var res = conn.exec ("
public static List<TotalTuristas> get_all_tourist_totals (Connection conn) {
var res = conn.db.exec ("
SELECT idT, nombreT, TotalTuristas FROM TOTAL_TURISTAS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalTuristas> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The TotalVehiculos class based on the database table
*/
public class TotalVehiculos : GLib.Object {
public class TotalVehiculos : Object {
/**
* The total of vehicles
*/
@@ -36,18 +36,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalVehiculos
*/
public static List<TotalVehiculos> get_all_vehicle_totals (Database conn) {
var res = conn.exec ("
public static List<TotalVehiculos> get_all_vehicle_totals (Connection conn) {
var res = conn.db.exec ("
SELECT TotalVeh FROM TOTAL_VEHICULOS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalVehiculos> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Tour class based on the database table
*/
public class Tour : GLib.Object {
public class Tour : Object {
/**
* The tour id
*/
@@ -69,13 +69,13 @@ namespace LibSernatur {
* @param conn The database connection to use
* @return Returns a list of Tour
*/
public static List<Tour> get_all_tours (Database conn) {
var res = conn.exec (Query.get_query (Query.Type.SELECT_ALL_TOURS, null));
public static List<Tour> get_all_tours (Connection conn) throws PostgresError {
var res = conn.db.exec (Query.get_query (conn, Query.Type.SELECT_ALL_TOURS, null));
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Tour> ();
#endif
}
@@ -116,16 +116,51 @@ namespace LibSernatur {
* @param tour The tour to update
* @throws DBError Thrown if the data in the object is invalid
*/
public static void update_tour (Database conn, Tour tour) throws DBError {
public static void update_tour (Connection conn, Tour tour) throws PostgresError, DBError {
if (tour.id_tour == 0) {
throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!"));
}
var res = conn.exec (Query.get_query (Query.Type.UPDATE_TOUR, tour));
var res = conn.db.exec (Query.get_query (conn, Query.Type.UPDATE_TOUR, tour));
if (res.get_status () != ExecStatus.COMMAND_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
#endif
}
}
/**
* Insert a tour in the database
* @param conn The database connection
* @param tour The tour to insert
* @return Returns the id of the tuple inserted
* @throws DBError Thrown if the data in the object is invalid
*/
public static uint insert_tour (Connection conn, Tour tour) throws PostgresError, DBError {
if (tour.id_tour != 0) {
throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!"));
}
var res = conn.db.exec (Query.get_query (conn, Query.Type.INSERT_TOUR, tour));
// This uses TUPLES_OK because it returns a result which is hte id of the inserted tour
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.db.get_error_message ());
#else
warning (conn.db.get_error_message ());
#endif
}
var wra = new ResultWrapper (res);
try {
return wra.get_int_n (0, "id_tour");
}
catch (Error e) {
#if DEBUG
error (e.message);
#else
warning (e.message);
return 0;
#endif
}
}
@@ -136,19 +171,19 @@ namespace LibSernatur {
* @param tour The tour to update
* @throws DBError Thrown if the data in the object is invalid
*/
public static void delete_tour (Database conn, Tour tour) throws DBError {
public static void delete_tour (Connection conn, Tour tour) throws PostgresError, DBError {
if (tour.id_tour == 0) {
throw new DBError.INVALID_VALUE (dgettext (null, "The id of the tour is invalid!"));
}
var res = conn.exec (Query.get_query (Query.Type.DELETE_TOUR, tour));
var res = conn.db.exec (Query.get_query (conn, Query.Type.DELETE_TOUR, tour));
if (res.get_status () != ExecStatus.COMMAND_OK) {
if (res.get_error_field (FieldCode.SQLSTATE) == "23503") {
throw new DBError.FOREIGN_KEY_CONSTAINT (res.get_error_field (FieldCode.MESSAGE_PRIMARY));
}
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
#endif
}
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Turista class based on the database table
*/
public class Turista : GLib.Object {
public class Turista : Object {
/**
* The RUT of the tourist
*/
@@ -54,11 +54,11 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Turista
*/
public static List<Turista> get_all_turistas (Database conn) {
var res = conn.exec ("
public static List<Turista> get_all_turistas (Connection conn) {
var res = conn.db.exec ("
SELECT T.rut_turista, T.nombre_turista, T.fecha_nacimento,
C.id_contacto, C.telefono_emergencia, C.nombre_emergencia
FROM turista T
@@ -66,9 +66,9 @@ 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 ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Turista> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The ValoresTours class based on the database table
*/
public class ValoresTours : GLib.Object {
public class ValoresTours : Object {
/**
* The id of the tour
*/
@@ -48,18 +48,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of ValoresTours
*/
public static List<ValoresTours> get_all_tour_sales (Database conn) {
var res = conn.exec ("
public static List<ValoresTours> get_all_tour_sales (Connection conn) {
var res = conn.db.exec ("
SELECT idT, nombreT, TotalVentas FROM VALORES_TOURS
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<ValoresTours> ();
#endif
}

View File

@@ -20,7 +20,7 @@ namespace LibSernatur {
/**
* The Vehiculo class based on the database table
*/
public class Vehiculo : GLib.Object {
public class Vehiculo : Object {
/**
* The license plate
*/
@@ -54,18 +54,18 @@ namespace LibSernatur {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Vehiculo
*/
public static List<Vehiculo> get_all_vehiculos (Database conn) {
var res = conn.exec ("
public static List<Vehiculo> get_all_vehiculos (Connection conn) {
var res = conn.db.exec ("
SELECT patente, ano_vehiculo, marca, capacidad FROM vehiculo
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Vehiculo> ();
#endif
}

View File

@@ -24,21 +24,21 @@ namespace LibSernatur {
/**
* The Q1 class based on the database table
*/
public class Q1 : GLib.Object {
public class Q1 : Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of RegionesSinDescuento
*/
public static List<RegionesSinDescuento> get_regions_without_discount (Database conn) {
var res = conn.exec ("
public static List<RegionesSinDescuento> get_regions_without_discount (Connection conn) {
var res = conn.db.exec ("
SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELECT MAX(cantidad) FROM REGIONES_SINDESCUENTO))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<RegionesSinDescuento> ();
#endif
}
@@ -68,7 +68,7 @@ SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELE
/**
* The Q2 class based on the database table
*/
public class Q2 : GLib.Object {
public class Q2 : Object {
/**
* The name of the tour
*/
@@ -90,19 +90,19 @@ SELECT nombreRegion, cantidad FROM REGIONES_SINDESCUENTO WHERE (cantidad = (SELE
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Q2
*/
public static List<Q2> get_value_received (Database conn) {
var res = conn.exec ("
public static List<Q2> get_value_received (Connection conn) {
var res = conn.db.exec ("
SELECT V.nombreT, (V.TotalVentas - COALESCE(MAX(T.TotalDescuentos), 0)) AS ValorTotalRecibido
FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.nombreT, V.TotalVentas)
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Q2> ();
#endif
}
@@ -132,22 +132,22 @@ FROM VALORES_TOURS V FULL JOIN TOUR_DESCUENTOS T ON (T.idT = V.idT) GROUP BY (V.
/**
* The Q3 class based on the database table
*/
public class Q3 : GLib.Object {
public class Q3 : Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalCoordinadores
*/
public static List<TotalCoordinadores> get_total_coordinators (Database conn) {
var res = conn.exec ("
public static List<TotalCoordinadores> get_total_coordinators (Connection conn) {
var res = conn.db.exec ("
SELECT nombreT, TotalCoordinadores
FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinadores) FROM TOTAL_COORDINADORES))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalCoordinadores> ();
#endif
}
@@ -178,21 +178,21 @@ FROM TOTAL_COORDINADORES WHERE (TotalCoordinadores = (SELECT MAX(TotalCoordinado
/**
* The Q4 class based on the database table
*/
public class Q4 : GLib.Object {
public class Q4 : Object {
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of TotalTuristas
*/
public static List<TotalTuristas> get_total_tourists (Database conn) {
var res = conn.exec ("
public static List<TotalTuristas> get_total_tourists (Connection conn) {
var res = conn.db.exec ("
SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT MAX(TotalTuristas) FROM TOTAL_TURISTAS))
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<TotalTuristas> ();
#endif
}
@@ -223,7 +223,7 @@ SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT
/**
* The Q5 class based on the database table
*/
public class Q5 : GLib.Object {
public class Q5 : Object {
/**
* The percentage of cars that were rented and used
*/
@@ -239,20 +239,20 @@ SELECT nombreT, TotalTuristas FROM TOTAL_TURISTAS WHERE (TotalTuristas = (SELECT
/**
* Get all tuples and fields from database
* @param conn The database connection to use
* @param conn.db.The database conn.db.ction to use
* @return Returns a list of Q5
*/
public static List<Q5> get_percentage (Database conn) {
var res = conn.exec ("
public static List<Q5> get_percentage (Connection conn) {
var res = conn.db.exec ("
SELECT
(cast(T1.totalarriendo AS DECIMAL(3,2)) / cast(T2.totalveh AS DECIMAL(3,2))) AS porcentaje
FROM total_arriendos AS T1, total_vehiculos AS T2
");
if (res.get_status () != ExecStatus.TUPLES_OK) {
#if DEBUG
error (conn.get_error_message ());
error (conn.db.get_error_message ());
#else
warning (conn.get_error_message ());
warning (conn.db.get_error_message ());
return new List<Q5> ();
#endif
}