add place editor
This commit is contained in:
@@ -62,16 +62,10 @@ namespace LibSernatur {
|
||||
* Get all tuples and fields from database
|
||||
* @param conn The database connection to use
|
||||
* @return Returns a list of Lugar
|
||||
* @throws PostgresError If there is a problem with with escaping strings
|
||||
*/
|
||||
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
|
||||
FROM lugar L
|
||||
JOIN ciudad C ON (L.id_ciudad = C.id_ciudad)
|
||||
JOIN region R ON (C.id_region = R.id_region)
|
||||
");
|
||||
public static List<Lugar> get_all_lugares (Connection conn) throws PostgresError {
|
||||
var res = conn.db.exec (Query.get_query (conn, Query.Type.SELECT_ALL_PLACES, null));
|
||||
if (res.get_status () != ExecStatus.TUPLES_OK) {
|
||||
#if DEBUG
|
||||
error (conn.db.get_error_message ());
|
||||
@@ -109,6 +103,63 @@ JOIN region R ON (C.id_region = R.id_region)
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a place in the database
|
||||
* @param conn The database connection
|
||||
* @param lugar The place to update
|
||||
* @throws PostgresError Thrown if there is a problem with escaping strings
|
||||
* @throws DBError Thrown if an invalid value is passed
|
||||
*/
|
||||
public static void update_place (Connection conn, Lugar lugar) throws PostgresError, DBError {
|
||||
if (lugar.id_lugar == 0) {
|
||||
throw new DBError.INVALID_VALUE (_ ("The id of the place is invalid!"));
|
||||
}
|
||||
var res = conn.db.exec (Query.get_query (conn, Query.Type.UPDATE_PLACE, lugar));
|
||||
if (res.get_status () != ExecStatus.COMMAND_OK) {
|
||||
#if DEBUG
|
||||
error (conn.db.get_error_message ());
|
||||
#else
|
||||
warning (conn.db.get_error_message ());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a place in the database
|
||||
* @param conn The database connection
|
||||
* @param lugar The place to insert
|
||||
* @return Returns the id of the tuple inserted
|
||||
* @throws PostgresError Thrown if there is a problem with escaping strings
|
||||
* @throws DBError Thrown if an invalid value is passed
|
||||
*/
|
||||
public static uint insert_place (Connection conn, Lugar lugar) throws PostgresError, DBError {
|
||||
if (lugar.id_lugar != 0) {
|
||||
throw new DBError.INVALID_VALUE (_ ("The id of the place is invalid!"));
|
||||
}
|
||||
var res = conn.db.exec (Query.get_query (conn, Query.Type.INSERT_PLACE, lugar));
|
||||
// This uses TUPLES_OK because it returns a result which is the 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_lugar");
|
||||
}
|
||||
catch (Error e) {
|
||||
#if DEBUG
|
||||
error (e.message);
|
||||
#else
|
||||
warning (e.message);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,9 @@ namespace LibSernatur {
|
||||
INSERT_TOUR,
|
||||
UPDATE_TOUR,
|
||||
DELETE_TOUR,
|
||||
SELECT_ALL_PLACES,
|
||||
INSERT_PLACE,
|
||||
UPDATE_PLACE,
|
||||
SELECT_ALL_ASSOCIATED,
|
||||
SELECT_ALL_ASSOCIATED_BY_TOUR
|
||||
}
|
||||
@@ -118,6 +121,39 @@ RETURNING id_tour";
|
||||
DELETE FROM tour
|
||||
WHERE id_tour = " + tour.id_tour.to_string ();
|
||||
|
||||
case SELECT_ALL_PLACES:
|
||||
return "
|
||||
SELECT L.id_lugar, L.nombre_lugar, L.valor_entrada, L.nivel,
|
||||
C.id_ciudad, C.nombre_ciudad,
|
||||
R.id_region, R.nombre_region
|
||||
FROM lugar L
|
||||
JOIN ciudad C ON (L.id_ciudad = C.id_ciudad)
|
||||
JOIN region R ON (C.id_region = R.id_region)";
|
||||
|
||||
case UPDATE_PLACE:
|
||||
Lugar lugar = (Lugar) t;
|
||||
return "
|
||||
UPDATE lugar SET
|
||||
nombre_lugar = '" + conn.escape (lugar.nombre_lugar) + "',
|
||||
valor_entrada = " + lugar.valor_entrada.to_string () + ",
|
||||
nivel = " + lugar.nivel.to_string () + ",
|
||||
id_ciudad = " + lugar.ciudad.id_ciudad.to_string () + "
|
||||
WHERE id_lugar = " + lugar.id_lugar.to_string ();
|
||||
|
||||
case INSERT_PLACE:
|
||||
Lugar lugar = (Lugar) t;
|
||||
return "
|
||||
INSERT INTO lugar
|
||||
(nombre_lugar, valor_entrada, nivel, id_ciudad)
|
||||
VALUES
|
||||
(
|
||||
'" + conn.escape (lugar.nombre_lugar) + "',
|
||||
" + lugar.valor_entrada.to_string () + ",
|
||||
" + lugar.nivel.to_string () + ",
|
||||
" + lugar.ciudad.id_ciudad.to_string () + "
|
||||
)
|
||||
RETURNING id_lugar";
|
||||
|
||||
case SELECT_ALL_ASSOCIATED:
|
||||
return "
|
||||
SELECT A.fecha_llegada, A.hora_llegada, A.fecha_salida, A.hora_salida,
|
||||
|
Reference in New Issue
Block a user