summaryrefslogtreecommitdiff
path: root/src/analysis/db/items/bookmark.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2014-10-16 22:04:29 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2014-10-16 22:04:29 (GMT)
commit6d34dbbb00da0c276261d0e1ce4bf862f22fd8e0 (patch)
treea5d3c8644691934ba84a91919f7db177f70743f1 /src/analysis/db/items/bookmark.c
parente75f44a99c8f984af4c47fa9a2c8e7e9841700d8 (diff)
Stored a bookmark into the data base and saved the archive.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@414 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/db/items/bookmark.c')
-rw-r--r--src/analysis/db/items/bookmark.c61
1 files changed, 49 insertions, 12 deletions
diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c
index c28a837..6ff386c 100644
--- a/src/analysis/db/items/bookmark.c
+++ b/src/analysis/db/items/bookmark.c
@@ -75,6 +75,9 @@ static bool g_db_bookmark_recv_from_fd(GDbBookmark *, int, int);
/* Exporte la définition d'un signet dans un flux réseau. */
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 *);
+
@@ -97,10 +100,8 @@ bool create_bookmark_db_table(sqlite3 *db)
char *msg; /* Message d'erreur */
sql = "CREATE TABLE Bookmarks (" \
- "id INT PRIMARY KEY NOT NULL, " \
- "user TEXT NOT NULL, " \
- "created INT NOT NULL, " \
- "address INT NOT NULL, " \
+ SQLITE_DB_ITEM_CREATE \
+ SQLITE_VMPA_CREATE \
"comment TEXT" \
");";
@@ -157,6 +158,8 @@ static void g_db_bookmark_class_init(GDbBookmarkClass *klass)
item->recv = (recv_db_item_fc)g_db_bookmark_recv_from_fd;
item->send = (send_db_item_fc)g_db_bookmark_send_to_fd;
+ item->prepare_stmt = (prepare_db_statement)g_db_bookmark_prepare_db_statement;
+
}
@@ -235,13 +238,7 @@ GDbBookmark *g_db_bookmark_new(const vmpa2t *addr, const char *comment)
result = g_object_new(G_TYPE_DB_BOOKMARK, NULL);
-
-
-
- /* TODO */
-
- //dup addr;
-
+ copy_vmpa(&result->addr, addr);
g_db_bookmark_set_comment(result, comment);
@@ -351,6 +348,46 @@ 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] *
+* *
+* Description : Constitue les champs destinés à une insertion / modification.*
+* *
+* Retour : Etat du besoin en sauvegarde. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *bookmark, bool create, 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);
+ if (!status) return false;
+
+ status = prepare_vmpa_db_statement(&bookmark->addr, create, 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;
+
+ return true;
+
+}
+
+
+
@@ -370,7 +407,7 @@ static bool g_db_bookmark_send_to_fd(const GDbBookmark *bookmark, int fd, int fl
* *
******************************************************************************/
-vmpa2t *g_db_bookmark_get_address(GDbBookmark *bookmark)
+const vmpa2t *g_db_bookmark_get_address(GDbBookmark *bookmark)
{
return &bookmark->addr;