summaryrefslogtreecommitdiff
path: root/src/analysis/db/items/bookmark.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/items/bookmark.c')
-rw-r--r--src/analysis/db/items/bookmark.c175
1 files changed, 58 insertions, 117 deletions
diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c
index a8182ce..c9d7b7a 100644
--- a/src/analysis/db/items/bookmark.c
+++ b/src/analysis/db/items/bookmark.c
@@ -30,10 +30,6 @@
#include "../collection-int.h"
#include "../item-int.h"
-#include "../misc/rlestr.h"
-
-
-
@@ -58,7 +54,6 @@ struct _GDbBookmarkClass
};
-
/* Initialise la classe des signets dans une zone de texte. */
static void g_db_bookmark_class_init(GDbBookmarkClass *);
@@ -71,8 +66,6 @@ static void g_db_bookmark_dispose(GDbBookmark *);
/* Procède à la libération totale de la mémoire. */
static void g_db_bookmark_finalize(GDbBookmark *);
-
-
/* Effectue la comparaison entre deux signets de collection. */
static gint g_db_bookmark_cmp(GDbBookmark *, GDbBookmark *);
@@ -83,18 +76,16 @@ static bool g_db_bookmark_recv_from_fd(GDbBookmark *, int, int);
static bool g_db_bookmark_send_to_fd(const GDbBookmark *, int, int);
/* Constitue les champs destinés à une insertion / modification. */
-static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *, bool, bound_value **, size_t *);
-
-
+static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *, bound_value **, size_t *);
+/* Charge les valeurs utiles pour un signet. */
+static bool g_db_bookmark_load(GDbBookmark *, const bound_value *, size_t);
/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */
-
-
/* Collection dédiée aux signets (instance) */
struct _GBookmarkCollection
{
@@ -122,12 +113,12 @@ static void g_bookmark_collection_dispose(GBookmarkCollection *);
/* Procède à la libération totale de la mémoire. */
static void g_bookmark_collection_finalize(GBookmarkCollection *);
+/* Crée la table des signets dans une base de données. */
+static bool g_bookmark_collection_create_db_table(const GBookmarkCollection *, sqlite3 *);
+
/* Décrit les colonnes utiles à un chargement de données. */
static bool g_bookmark_collection_setup_load(GBookmarkCollection *, bound_value **, size_t *);
-/* Charge les valeurs utiles pour une localisation. */
-static bool g_bookmark_collection_load_item(GBookmarkCollection *, const bound_value *, size_t);
-
/* Détermine si un élément est déjà présent ou non. */
static GDbItem *g_bookmark_collection_has_key(GBookmarkCollection *, va_list *);
@@ -172,6 +163,7 @@ static void g_db_bookmark_class_init(GDbBookmarkClass *klass)
item->send = (send_db_item_fc)g_db_bookmark_send_to_fd;
item->prepare_stmt = (prepare_db_statement)g_db_bookmark_prepare_db_statement;
+ item->load = (load_db_item_fc)g_db_bookmark_load;
}
@@ -227,6 +219,8 @@ static void g_db_bookmark_dispose(GDbBookmark *bookmark)
static void g_db_bookmark_finalize(GDbBookmark *bookmark)
{
+ exit_rle_string(&bookmark->comment);
+
G_OBJECT_CLASS(g_db_bookmark_parent_class)->finalize(G_OBJECT(bookmark));
}
@@ -260,11 +254,6 @@ GDbBookmark *g_db_bookmark_new(const vmpa2t *addr, const char *comment)
}
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : a = premier élément à analyser. *
@@ -287,8 +276,10 @@ static gint g_db_bookmark_cmp(GDbBookmark *a, GDbBookmark *b)
if (result == 0)
result = cmp_rle_string(&a->comment, &b->comment);
- return result;
+ if (result == 0)
+ result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->cmp(G_DB_ITEM(a), G_DB_ITEM(b));
+ return result;
}
@@ -314,10 +305,10 @@ static bool g_db_bookmark_recv_from_fd(GDbBookmark *bookmark, int fd, int flags)
status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->recv(G_DB_ITEM(bookmark), fd, flags);
if (!status) return false;
- if (!recv_vmpa(&bookmark->addr, fd, 0))
+ if (!recv_vmpa(&bookmark->addr, fd, flags))
return false;
- if (!recv_rle_string(&bookmark->comment, fd, 0))
+ if (!recv_rle_string(&bookmark->comment, fd, flags))
return false;
return true;
@@ -346,10 +337,6 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl
status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->send(G_DB_ITEM(bookmark), fd, MSG_MORE | flags);
if (!status) return false;
-
- printf("<sending> FROM %s...\n", __FUNCTION__);
-
-
if (!send_vmpa(&bookmark->addr, fd, MSG_MORE | flags))
return false;
@@ -363,10 +350,9 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl
/******************************************************************************
* *
-* Paramètres : item = base d'éléments sur laquelle s'appuyer. *
-* create = indique si la préparation vise une création ou non. *
-* values = couples de champs et de valeurs à lier. [OUT] *
-* count = nombre de ces couples. [OUT] *
+* Paramètres : bookmark = base d'éléments sur laquelle s'appuyer. *
+* values = couples de champs et de valeurs à lier. [OUT] *
+* count = nombre de ces couples. [OUT] *
* *
* Description : Constitue les champs destinés à une insertion / modification.*
* *
@@ -376,36 +362,51 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl
* *
******************************************************************************/
-static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *bookmark, bool create, bound_value **values, size_t *count)
+static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *bookmark, bound_value **values, size_t *count)
{
bool status; /* Bilan d'opération initiale */
- bound_value *value; /* Valeur à éditer / définir */
- status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->prepare_stmt(G_DB_ITEM(bookmark), create, values, count);
+ status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->prepare_stmt(G_DB_ITEM(bookmark), values, count);
if (!status) return false;
- status = prepare_vmpa_db_statement(&bookmark->addr, create, values, count);
+ status = prepare_vmpa_db_statement(&bookmark->addr, values, count);
if (!status) return false;
- *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value));
- value = &(*values)[*count - 1];
-
- value->name = "comment";
- value->type = SQLITE_TEXT;
- value->cstring = g_db_bookmark_get_comment(bookmark);
- value->delete = SQLITE_STATIC;
+ status &= prepare_db_statement_for_rle_string(&bookmark->comment, "comment", values, count);
+ if (!status) return false;
return true;
}
+/******************************************************************************
+* *
+* Paramètres : bookmark = bascule d'affichage à charger depuis les réponses.*
+* values = tableau d'éléments à consulter. *
+* count = nombre de descriptions renseignées. *
+* *
+* Description : Charge les valeurs utiles pour un signet. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static bool g_db_bookmark_load(GDbBookmark *bookmark, const bound_value *values, size_t count)
+{
+ bool result; /* Bilan à faire remonter */
+ result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->load(G_DB_ITEM(bookmark), values, count);
+ result &= load_vmpa(&bookmark->addr, values, count);
+ result &= load_rle_string(&bookmark->comment, "comment", values, count);
+ return result;
+}
/******************************************************************************
@@ -500,8 +501,8 @@ static void g_bookmark_collection_class_init(GBookmarkCollectionClass *klass)
collec = G_DB_COLLECTION_CLASS(klass);
+ collec->create_table = (collec_create_db_table_fc)g_bookmark_collection_create_db_table;
collec->setup_load = (collec_setup_load_fc)g_bookmark_collection_setup_load;
- collec-> load_item = (collec_load_item)g_bookmark_collection_load_item;
collec->has_key = (collec_has_key_fc)g_bookmark_collection_has_key;
}
@@ -553,7 +554,7 @@ static void g_bookmark_collection_dispose(GBookmarkCollection *collec)
/******************************************************************************
* *
-* Paramètres : bookmark = instance d'objet GLib à traiter. *
+* Paramètres : collec = instance d'objet GLib à traiter. *
* *
* Description : Procède à la libération totale de la mémoire. *
* *
@@ -593,17 +594,10 @@ GBookmarkCollection *g_bookmark_collection_new(void)
}
-
-
-
-
-
-
-
-
/******************************************************************************
* *
-* Paramètres : db = accès à la base de données. *
+* Paramètres : collec = ensemble d'éléments spectateur des opérations. *
+* db = accès à la base de données. *
* *
* Description : Crée la table des signets dans une base de données. *
* *
@@ -613,16 +607,16 @@ GBookmarkCollection *g_bookmark_collection_new(void)
* *
******************************************************************************/
-bool create_bookmark_db_table(sqlite3 *db)
+static bool g_bookmark_collection_create_db_table(const GBookmarkCollection *collec, sqlite3 *db)
{
char *sql; /* Requête à exécuter */
int ret; /* Bilan de la création */
char *msg; /* Message d'erreur */
sql = "CREATE TABLE Bookmarks (" \
- SQLITE_DB_ITEM_CREATE \
- SQLITE_VMPA_CREATE \
- "comment TEXT" \
+ SQLITE_DB_ITEM_CREATE ", " \
+ SQLITE_VMPA_CREATE ", " \
+ SQLITE_RLESTR_CREATE("comment") \
");";
ret = sqlite3_exec(db, sql, NULL, NULL, &msg);
@@ -637,9 +631,6 @@ bool create_bookmark_db_table(sqlite3 *db)
}
-
-
-
/******************************************************************************
* *
* Paramètres : collec = ensemble d'éléments à consulter. *
@@ -656,69 +647,19 @@ bool create_bookmark_db_table(sqlite3 *db)
static bool g_bookmark_collection_setup_load(GBookmarkCollection *collec, bound_value **values, size_t *count)
{
- // TODO : classe supérieure
+ bool status; /* Bilan d'une préparation */
+
+ status = G_DB_COLLECTION_CLASS(g_bookmark_collection_parent_class)->setup_load(G_DB_COLLECTION(collec), \
+ values, count);
+ if (!status) return false;
if (!setup_load_for_vmpa(NULL, values, count))
return false;
- *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value));
-
- (*values)[*count - 1].name = "comment";
-
- return true;
-
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : collec = ensemble d'éléments à compléter. *
-* values = tableau d'éléments à consulter. *
-* count = nombre de descriptions renseignées. *
-* *
-* Description : Charge les valeurs utiles pour une localisation. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool g_bookmark_collection_load_item(GBookmarkCollection *collec, const bound_value *values, size_t count)
-{
- vmpa2t addr; /* Localisation d'un signet */
- const char *comment; /* Eventuel commentaire associé*/
- const bound_value *value; /* Valeur à intégrer */
- GDbBookmark *new; /* Nouvel élément à intégrer */
-
- if (!load_vmpa(&addr, values, count))
+ if (!setup_load_of_rle_string(NULL, "comment", values, count))
return false;
- value = find_bound_value(values, count, "comment");
- if (value == NULL) return false;
-
- switch (value->type)
- {
- case SQLITE_TEXT:
- comment = value->cstring;
- break;
-
- case SQLITE_NULL:
- comment = NULL;
- break;
-
- default:
- return false;
- break;
-
- }
-
- new = g_db_bookmark_new(&addr, comment);
-
- printf(" LOAD new bm :: %p\n", new);
-
- return g_db_collection_add_item(G_DB_COLLECTION(collec), G_DB_ITEM(new));
+ return true;
}