diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-03-13 23:59:29 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-03-13 23:59:29 (GMT) |
commit | 8d8e5c02096f59a7227308a591fc5050ea5d92ff (patch) | |
tree | 15b5bc10b963d492d4393b83ccfd347230d6b41e /src/arch | |
parent | bde67ccf58fc858d5d0db4929db149ea12f50f96 (diff) |
Given more flexibility to the field names of locations in XML databases.
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/vmpa.c | 36 | ||||
-rw-r--r-- | src/arch/vmpa.h | 10 |
2 files changed, 32 insertions, 14 deletions
diff --git a/src/arch/vmpa.c b/src/arch/vmpa.c index 3b1bcec..7231c2c 100644 --- a/src/arch/vmpa.c +++ b/src/arch/vmpa.c @@ -553,6 +553,7 @@ vmpa2t *string_to_vmpa_virt(const char *buffer) /****************************************************************************** * * * Paramètres : addr = localisation dont la définition est à consulter. * +* base = tronc commun pour les champs de la base de données. * * values = tableau d'éléments à compléter. [OUT] * * count = nombre de descriptions renseignées. [OUT] * * * @@ -564,7 +565,7 @@ vmpa2t *string_to_vmpa_virt(const char *buffer) * * ******************************************************************************/ -bool setup_load_for_vmpa(const vmpa2t *addr, bound_value **values, size_t *count) +bool setup_load_for_vmpa(const vmpa2t *addr, const char *base, bound_value **values, size_t *count) { bound_value *value; /* Valeur à éditer / définir */ @@ -573,12 +574,14 @@ bool setup_load_for_vmpa(const vmpa2t *addr, bound_value **values, size_t *count value = &(*values)[*count - 2]; - value->name = "phys"; + asprintf(&value->name, "%s%sphys", base != NULL ? base : "", base != NULL ? "_" : ""); + value->built_name = true; value->type = SQLITE_NATIVE; value = &(*values)[*count - 1]; - value->name = "virt"; + asprintf(&value->name, "%s%svirt", base != NULL ? base : "", base != NULL ? "_" : ""); + value->built_name = true; value->type = SQLITE_NATIVE; return true; @@ -589,6 +592,7 @@ bool setup_load_for_vmpa(const vmpa2t *addr, bound_value **values, size_t *count /****************************************************************************** * * * Paramètres : addr = localisation dont la définition est à définir. * +* base = tronc commun pour les champs de la base de données. * * values = tableau d'éléments à consulter. * * count = nombre de descriptions renseignées. * * * @@ -600,11 +604,17 @@ bool setup_load_for_vmpa(const vmpa2t *addr, bound_value **values, size_t *count * * ******************************************************************************/ -bool load_vmpa(vmpa2t *addr, const bound_value *values, size_t count) +bool load_vmpa(vmpa2t *addr, const char *base, const bound_value *values, size_t count) { + char *name; /* Désignation complète */ const bound_value *value; /* Valeur à intégrer */ - value = find_bound_value(values, count, "phys"); + asprintf(&name, "%s%sphys", base != NULL ? base : "", base != NULL ? "_" : ""); + + value = find_bound_value(values, count, name); + + free(name); + if (value == NULL) return false; switch (value->type) @@ -623,7 +633,12 @@ bool load_vmpa(vmpa2t *addr, const bound_value *values, size_t count) } - value = find_bound_value(values, count, "virt"); + asprintf(&name, "%s%svirt", base != NULL ? base : "", base != NULL ? "_" : ""); + + value = find_bound_value(values, count, name); + + free(name); + if (value == NULL) return false; switch (value->type) @@ -650,6 +665,7 @@ bool load_vmpa(vmpa2t *addr, const bound_value *values, size_t count) /****************************************************************************** * * * Paramètres : addr = adresse virtuelle ou physique à traiter. * +* base = tronc commun pour les champs de la base de données. * * values = couples de champs et de valeurs à lier. [OUT] * * count = nombre de ces couples. [OUT] * * * @@ -661,14 +677,15 @@ bool load_vmpa(vmpa2t *addr, const bound_value *values, size_t count) * * ******************************************************************************/ -bool prepare_vmpa_db_statement(const vmpa2t *addr, bound_value **values, size_t *count) +bool prepare_vmpa_db_statement(const vmpa2t *addr, const char *base, 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 = "phys"; + asprintf(&value->name, "%s%sphys", base != NULL ? base : "", base != NULL ? "_" : ""); + value->built_name = true; if (addr->physical != VMPA_NO_PHYSICAL) { @@ -683,7 +700,8 @@ bool prepare_vmpa_db_statement(const vmpa2t *addr, bound_value **values, size_t *values = (bound_value *)realloc(*values, ++(*count) * sizeof(bound_value)); value = &(*values)[*count - 1]; - value->name = "virt"; + asprintf(&value->name, "%s%svirt", base != NULL ? base : "", base != NULL ? "_" : ""); + value->built_name = true; if (addr->virtual != VMPA_NO_VIRTUAL) { diff --git a/src/arch/vmpa.h b/src/arch/vmpa.h index cfb9ab5..9905241 100644 --- a/src/arch/vmpa.h +++ b/src/arch/vmpa.h @@ -135,18 +135,18 @@ vmpa2t *string_to_vmpa_phy(const char *); vmpa2t *string_to_vmpa_virt(const char *); /* Définition du tronc commun pour les créations SQLite */ -#define SQLITE_VMPA_CREATE \ - "phys INTEGER, " \ +#define SQLITE_SIMPLE_VMPA_CREATE \ + "phys INTEGER, " \ "virt INTEGER" /* Décrit les colonnes utiles à un chargement de données. */ -bool setup_load_for_vmpa(const vmpa2t *, bound_value **, size_t *); +bool setup_load_for_vmpa(const vmpa2t *, const char *, bound_value **, size_t *); /* Charge les valeurs utiles pour une localisation. */ -bool load_vmpa(vmpa2t *, const bound_value *, size_t); +bool load_vmpa(vmpa2t *, const char *, const bound_value *, size_t); /* Constitue les champs destinés à une insertion / modification. */ -bool prepare_vmpa_db_statement(const vmpa2t *, bound_value **, size_t *); +bool prepare_vmpa_db_statement(const vmpa2t *, const char *, bound_value **, size_t *); |