add tour place editor
This commit is contained in:
@@ -34,8 +34,8 @@ namespace LibSernatur {
|
||||
* @param hora_llegada The time of arrival
|
||||
* @param fecha_salida The date of departure
|
||||
* @param hora_salida The time of departure
|
||||
* @param tour The tour taken
|
||||
* @param lugar The place visisted
|
||||
* @param tour The tour associated
|
||||
* @param lugar The place associated
|
||||
*/
|
||||
public Asociado (string fecha_llegada = "", string hora_llegada = "", string fecha_salida = "", string hora_salida = "", Tour? tour = null, Lugar? lugar = null) {
|
||||
this.fecha_llegada = fecha_llegada;
|
||||
@@ -175,6 +175,51 @@ namespace LibSernatur {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert an association in the database
|
||||
* @param conn The database connection
|
||||
* @param asociado The association to insert
|
||||
* @throws PostgresError Thrown if there is a problem with escaping strings
|
||||
* @throws DBError Thrown if an invalid value is passed
|
||||
*/
|
||||
public static void insert_asociado (Connection conn, Asociado asociado) throws PostgresError, DBError {
|
||||
if (asociado.tour.id_tour == 0 || asociado.lugar.id_lugar == 0) {
|
||||
throw new DBError.INVALID_VALUE (_ ("The id of the tour or the place is invalid!"));
|
||||
}
|
||||
var res = conn.db.exec (Query.get_query (conn, Query.Type.INSERT_ASSOCIATED, asociado));
|
||||
if (res.get_status () != ExecStatus.COMMAND_OK) {
|
||||
#if DEBUG
|
||||
error (conn.db.get_error_message ());
|
||||
#else
|
||||
warning (conn.db.get_error_message ());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an association in the database
|
||||
* @param conn The database connection
|
||||
* @param asociado The association to delete
|
||||
* @throws PostgresError Thrown if there is a problem with escaping strings
|
||||
* @throws DBError Thrown if an invalid value is passed
|
||||
*/
|
||||
public static void delete_associated (Connection conn, Asociado asociado) throws PostgresError, DBError {
|
||||
if (asociado.tour.id_tour == 0 || asociado.lugar.id_lugar == 0) {
|
||||
throw new DBError.INVALID_VALUE (_ ("The id of the tour or place is invalid!"));
|
||||
}
|
||||
var res = conn.db.exec (Query.get_query (conn, Query.Type.DELETE_TOUR, asociado));
|
||||
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.db.get_error_message ());
|
||||
#else
|
||||
warning (conn.db.get_error_message ());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -171,7 +171,7 @@ namespace LibSernatur {
|
||||
/**
|
||||
* Delete a tour in the database
|
||||
* @param conn The database connection
|
||||
* @param tour The tour to update
|
||||
* @param tour The tour to delete
|
||||
* @throws PostgresError Thrown if there is a problem with escaping strings
|
||||
* @throws DBError Thrown if an invalid value is passed
|
||||
*/
|
||||
|
@@ -32,7 +32,9 @@ namespace LibSernatur {
|
||||
INSERT_PLACE,
|
||||
UPDATE_PLACE,
|
||||
SELECT_ALL_ASSOCIATED,
|
||||
SELECT_ALL_ASSOCIATED_BY_TOUR
|
||||
SELECT_ALL_ASSOCIATED_BY_TOUR,
|
||||
INSERT_ASSOCIATED,
|
||||
DELETE_ASSOCIATED
|
||||
}
|
||||
|
||||
public static string get_query (Connection conn, Type type, T? t) throws PostgresError {
|
||||
@@ -190,6 +192,30 @@ JOIN ciudad C2 ON (L.id_ciudad = C2.id_ciudad)
|
||||
JOIN region R2 ON (C2.id_region = R2.id_region)
|
||||
WHERE t.id_tour = " + tour.id_tour.to_string ();
|
||||
|
||||
case INSERT_ASSOCIATED:
|
||||
Asociado asociado = (Asociado) t;
|
||||
return "
|
||||
INSERT INTO asociado
|
||||
(id_tour, id_lugar, fecha_llegada, hora_llegada, fecha_salida, hora_salida)
|
||||
VALUES
|
||||
(
|
||||
" + asociado.tour.id_tour.to_string () + ",
|
||||
" + asociado.lugar.id_lugar.to_string () + ",
|
||||
'" + conn.escape (asociado.fecha_llegada) + "',
|
||||
'" + conn.escape (asociado.hora_llegada) + "',
|
||||
'" + conn.escape (asociado.fecha_salida) + "',
|
||||
'" + conn.escape (asociado.hora_salida) + "'
|
||||
)";
|
||||
|
||||
case DELETE_ASSOCIATED:
|
||||
Asociado asociado = (Asociado) t;
|
||||
return "
|
||||
DELETE FROM associated
|
||||
WHERE (
|
||||
id_tour = " + asociado.tour.id_tour.to_string () + " AND
|
||||
id_lugar = " + asociado.lugar.id_lugar.to_string () + "
|
||||
)";
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
Reference in New Issue
Block a user