add place editor

This commit is contained in:
2019-01-19 20:05:18 -03:00
parent 994acf957a
commit 84c10aae90
13 changed files with 927 additions and 100 deletions

View File

@@ -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
}
}
}
}
}