summaryrefslogtreecommitdiff
path: root/src/analysis/db/misc/rlestr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/db/misc/rlestr.c')
-rw-r--r--src/analysis/db/misc/rlestr.c166
1 files changed, 84 insertions, 82 deletions
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c
index 631b1e9..9986967 100644
--- a/src/analysis/db/misc/rlestr.c
+++ b/src/analysis/db/misc/rlestr.c
@@ -26,6 +26,7 @@
#include <endian.h>
#include <malloc.h>
+#include <sqlite3.h>
#include <string.h>
@@ -33,25 +34,6 @@
-
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <time.h>
-#include <unistd.h>
-
-
-
-
-
-
-
-
-
-
-
-
/******************************************************************************
* *
* Paramètres : str = représentation de chaîne à traiter. *
@@ -180,8 +162,9 @@ int cmp_rle_string(const rle_string *s1, const rle_string *s2)
/******************************************************************************
* *
-* Paramètres : str = informations à constituer. [OUT] *
-* fd = flux ouvert en lecture pour l'importation. *
+* Paramètres : str = informations à constituer. [OUT] *
+* fd = flux ouvert en lecture pour l'importation. *
+* flags = éventuelles options de réception supplémentaires. *
* *
* Description : Importe la définition d'une chaîne de caractères. *
* *
@@ -191,23 +174,25 @@ int cmp_rle_string(const rle_string *s1, const rle_string *s2)
* *
******************************************************************************/
-bool load_rle_string(rle_string *str, int fd)
+bool recv_rle_string(rle_string *str, int fd, int flags)
{
-#if 0
uint32_t val32; /* Valeur sur 32 bits */
- ssize_t got; /* Quantité de données reçues */
+ bool status; /* Bilan d'une opération */
- got = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL);
- if (got != sizeof(uint32_t)) return false;
+ str->data = NULL;
+ str->length = 0;
+
+ status = safe_recv(fd, &val32, sizeof(uint32_t), MSG_WAITALL | flags);
+ if (!status) return false;
- str->length = le32toh(val32);
+ str->length = be32toh(val32);
if (str->length > 0)
{
str->data = (char *)malloc(str->length + 1);
- got = safe_recv(fd, str->data, str->length + 1, MSG_WAITALL);
- if (got != (str->length + 1))
+ status = safe_recv(fd, str->data, str->length + 1, MSG_WAITALL | flags);
+ if (!status)
{
unset_rle_string(str);
return false;
@@ -216,7 +201,7 @@ bool load_rle_string(rle_string *str, int fd)
str->data[str->length] = '\0';
}
-#endif
+
return true;
}
@@ -224,8 +209,9 @@ bool load_rle_string(rle_string *str, int fd)
/******************************************************************************
* *
-* Paramètres : str = informations à sauvegarer. *
-* fd = flux ouvert en écriture pour l'exportation. *
+* Paramètres : str = informations à sauvegarer. *
+* fd = flux ouvert en écriture pour l'exportation. *
+* flags = éventuelles options d'envoi supplémentaires. *
* *
* Description : Exporte la définition d'une chaîne de caractères. *
* *
@@ -235,44 +221,70 @@ bool load_rle_string(rle_string *str, int fd)
* *
******************************************************************************/
-bool store_rle_string(const rle_string *str, int fd)
+bool send_rle_string(const rle_string *str, int fd, int flags)
{
-#if 0
- ssize_t got; /* Quantité de données reçues */
+ bool status; /* Bilan d'une opération */
- got = safe_send(fd, (uint32_t []) { htole32(str->length) }, sizeof(uint32_t), MSG_WAITALL);
- if (got != sizeof(uint32_t)) return false;
+ status = safe_send(fd, (uint32_t []) { htobe32(str->length) }, sizeof(uint32_t), MSG_MORE | flags);
+ if (!status) return false;
if (str->length > 0)
{
- got = safe_send(fd, str->data, str->length + 1, MSG_WAITALL);
- if (got != (str->length + 1)) return false;
+ status = safe_send(fd, str->data, str->length + 1, flags);
+ if (!status) return false;
}
-#endif
+
return true;
}
+/* ---------------------------------------------------------------------------------- */
+/* MANIPULATIONS AVEC UNE BASE DE DONNEES */
+/* ---------------------------------------------------------------------------------- */
+/******************************************************************************
+* *
+* Paramètres : str = chaîne de caractères aux informations inutiles. *
+* name = désignation personnalisée du champ dans la BD. *
+* 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 : Bilan de l'opération : succès ou non. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+bool prepare_db_statement_for_rle_string(const rle_string *str, const char *name, bound_value **values, size_t *count)
+{
+ bound_value *value; /* Valeur à éditer / définir */
+ *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value));
+ value = &(*values)[*count - 1];
+ value->name = name;
+ value->type = SQLITE_TEXT;
+ value->cstring = get_rle_string(str);
+ value->delete = SQLITE_STATIC;
+ return true;
-
-
+}
/******************************************************************************
* *
-* Paramètres : str = informations à constituer. [OUT] *
-* fd = flux ouvert en lecture pour l'importation. *
-* flags = éventuelles options de réception supplémentaires. *
+* Paramètres : str = chaîne de caractères aux informations inutiles. *
+* name = désignation personnalisée du champ dans la BD. *
+* values = tableau d'éléments à compléter. [OUT] *
+* count = nombre de descriptions renseignées. [OUT] *
* *
-* Description : Importe la définition d'une chaîne de caractères. *
+* Description : Décrit les colonnes utiles à une chaîne de caractères. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -280,46 +292,26 @@ bool store_rle_string(const rle_string *str, int fd)
* *
******************************************************************************/
-bool recv_rle_string(rle_string *str, int fd, int flags)
+bool setup_load_of_rle_string(const rle_string *str, const char *name, bound_value **values, size_t *count)
{
- uint32_t val32; /* Valeur sur 32 bits */
- bool status; /* Bilan d'une opération */
-
- str->data = NULL;
- str->length = 0;
-
- status = safe_recv(fd, &val32, sizeof(uint32_t), flags);
- if (!status) return false;
-
- str->length = be32toh(val32);
-
- if (str->length > 0)
- {
- str->data = (char *)malloc(str->length + 1);
-
- status = safe_recv(fd, str->data, str->length + 1, flags);
- if (!status)
- {
- unset_rle_string(str);
- return false;
- }
-
- str->data[str->length] = '\0';
+ *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value));
- }
+ (*values)[*count - 1].name = name;
return true;
+
}
/******************************************************************************
* *
-* Paramètres : str = informations à sauvegarer. *
-* fd = flux ouvert en écriture pour l'exportation. *
-* flags = éventuelles options d'envoi supplémentaires. *
+* Paramètres : str = chaîne de caractères à compléter. *
+* name = désignation personnalisée du champ dans la BD. *
+* values = tableau d'éléments à consulter. *
+* count = nombre de descriptions renseignées. *
* *
-* Description : Exporte la définition d'une chaîne de caractères. *
+* Description : Charge les valeurs utiles pour une chaîne de caractères. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -327,17 +319,27 @@ bool recv_rle_string(rle_string *str, int fd, int flags)
* *
******************************************************************************/
-bool send_rle_string(const rle_string *str, int fd, int flags)
+bool load_rle_string(rle_string *str, const char *name, const bound_value *values, size_t count)
{
- bool status; /* Bilan d'une opération */
+ const bound_value *value; /* Valeur à intégrer */
- status = safe_send(fd, (uint32_t []) { htobe32(str->length) }, sizeof(uint32_t), MSG_MORE | flags);
- if (!status) return false;
+ value = find_bound_value(values, count, name);
+ if (value == NULL) return false;
- if (str->length > 0)
+ switch (value->type)
{
- status = safe_send(fd, str->data, str->length + 1, flags);
- if (!status) return false;
+ case SQLITE_TEXT:
+ set_rle_string(str, value->cstring);
+ break;
+
+ case SQLITE_NULL:
+ set_rle_string(str, NULL);
+ break;
+
+ default:
+ return false;
+ break;
+
}
return true;