summaryrefslogtreecommitdiff
path: root/src/analysis/db/collection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/collection.c')
-rw-r--r--src/analysis/db/collection.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c
index adf607d..a99c2de 100644
--- a/src/analysis/db/collection.c
+++ b/src/analysis/db/collection.c
@@ -310,12 +310,15 @@ bool g_db_collection_unpack(GDbCollection *collec, packed_buffer *pbuf, sqlite3
{
if (collec->binary != NULL && g_db_item_is_active(item))
result = g_db_item_apply(item, collec->binary);
- if (db != NULL)
- result &= g_db_collection_store_item(collec, item, db);
- }
- if (!result)
- /* TODO : retirer l'élément */;
+ if (result && db != NULL)
+ result = g_db_collection_store_item(collec, item, db);
+
+ /* En cas d'erreur, il faut retirer l'élément */
+ if (!result)
+ _g_db_collection_remove_item(collec, item, true, false);
+
+ }
break;
@@ -331,7 +334,7 @@ bool g_db_collection_unpack(GDbCollection *collec, packed_buffer *pbuf, sqlite3
{
/* Côté client */
if (db == NULL)
- result = _g_db_collection_remove_item(collec, item, false);
+ result = _g_db_collection_remove_item(collec, item, false, true);
/* Côté serveur */
else
@@ -613,6 +616,7 @@ bool _g_db_collection_add_item(GDbCollection *collec, GDbItem *item, bool lock)
* Paramètres : collec = ensemble d'éléments à considérer. *
* item = élément de collection à manipuler. *
* lock = indique si le verrou d'écriture doit être posé. *
+* signal = émet un événement pour signaler le retrait. *
* *
* Description : Procède au retrait d'un nouvel élément dans la collection. *
* *
@@ -622,7 +626,7 @@ bool _g_db_collection_add_item(GDbCollection *collec, GDbItem *item, bool lock)
* *
******************************************************************************/
-bool _g_db_collection_remove_item(GDbCollection *collec, GDbItem *item, bool lock)
+bool _g_db_collection_remove_item(GDbCollection *collec, GDbItem *item, bool lock, bool signal)
{
bool result; /* Bilan à faire remonter */
GList *found; /* Test de présence existante */
@@ -633,7 +637,7 @@ bool _g_db_collection_remove_item(GDbCollection *collec, GDbItem *item, bool loc
if (lock)
g_db_collection_wlock(collec);
- found = g_list_find_custom(collec->items, item, (GCompareFunc)g_db_item_compare_with_timestamp);
+ found = g_list_find_custom(collec->sorted, item, (GCompareFunc)g_db_item_compare_with_timestamp);
result = (found != NULL);
@@ -641,11 +645,18 @@ bool _g_db_collection_remove_item(GDbCollection *collec, GDbItem *item, bool loc
{
internal = G_DB_ITEM(found->data);
+ collec->sorted = g_list_delete_link(collec->sorted, found);
+
+ found = g_list_find(collec->items, item);
+ assert(found != NULL);
+
collec->items = g_list_delete_link(collec->items, found);
- g_signal_emit_by_name(collec, "content-changed", DBA_REM_ITEM, internal);
+ if (signal)
+ g_signal_emit_by_name(collec, "content-changed", DBA_REM_ITEM, internal);
g_object_unref(G_OBJECT(internal));
+ g_object_unref(G_OBJECT(internal));
}
@@ -1036,7 +1047,7 @@ bool g_db_collection_load_all_items(GDbCollection *collec, sqlite3 *db)
break;
case SQLITE_FLOAT:
- assert(0); /* TODO */
+ assert(0);
break;
case SQLITE_TEXT:
@@ -1044,7 +1055,7 @@ bool g_db_collection_load_all_items(GDbCollection *collec, sqlite3 *db)
break;
case SQLITE_BLOB:
- assert(0); /* TODO */
+ assert(0);
break;
case SQLITE_NULL: