From 0180c7cd3421f0e473758d5cfca9cd1a9bfd120f Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 12 Apr 2013 22:49:27 +0200 Subject: Added new function to set the value in a eDBfieldMap struct This slightly changes the eDBmappingGetValue() function to reuse some of the same look-up logic for eDBmappingSetValue() Signed-off-by: David Sommerseth --- database/eurephiadb_mapping.c | 43 ++++++++++++++++++++++++++++++++++++++----- database/eurephiadb_mapping.h | 1 + 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/database/eurephiadb_mapping.c b/database/eurephiadb_mapping.c index 52c2909..311dbd4 100644 --- a/database/eurephiadb_mapping.c +++ b/database/eurephiadb_mapping.c @@ -423,15 +423,15 @@ long int eDBmappingFieldsPresent(eDBfieldMap *map) { /** - * Retrieves the value of a field in a eDBfieldMap pointer chain. + * Looks up a given fieldMap entry to a given field * * @param map eDBfieldMap with the values * @param field_id The field ID to retrieve the value from * - * @return Returns const char * to the value in the eDBfieldMap on success, or NULL if either the - * value is not found or if the value is not set. + * @returns the pointer to the fieldMap entry on success, otherwise NULL */ -const char *eDBmappingGetValue(eDBfieldMap *map, long field_id) { +static eDBfieldMap *_eDBmappingGetFieldMapEntry(eDBfieldMap *map, long long field_id) +{ eDBfieldMap *ptr = NULL; if( map == NULL ) { @@ -440,9 +440,42 @@ const char *eDBmappingGetValue(eDBfieldMap *map, long field_id) { for( ptr = map; ptr != NULL; ptr = ptr->next ) { if( ptr->field_id == field_id ) { - return ptr->value; + return ptr; } } return NULL; } +/** + * Retrieves the value of a field in a eDBfieldMap pointer chain. + * + * @param map eDBfieldMap with the values + * @param field_id The field ID to retrieve the value from + * + * @return Returns const char * to the value in the eDBfieldMap on success, or NULL if either the + * value is not found or if the value is not set. + */ +const char *eDBmappingGetValue(eDBfieldMap *map, long long field_id) { + eDBfieldMap *ptr = _eDBmappingGetFieldMapEntry(map, field_id); + return (ptr != NULL ? ptr->value : NULL); +} + + +/** + * Sets the value of a field in a eDBfieldMap pointer chain. + * + * @param map eDBfieldMap with the values + * @param field_id The field ID to modify + * @param value String pointer to the value to use + * + * @return Returns 1 on success, otherwise 0 + */ +int eDBmappingSetValue(eDBfieldMap *map, long long field_id, char *value) { + eDBfieldMap *ptr = _eDBmappingGetFieldMapEntry(map, field_id); + if( ptr != NULL ) { + ptr->value = strdup_nullsafe(value); + return 1; + } + return 0; +} + diff --git a/database/eurephiadb_mapping.h b/database/eurephiadb_mapping.h index b6a6410..a6db6b4 100644 --- a/database/eurephiadb_mapping.h +++ b/database/eurephiadb_mapping.h @@ -269,6 +269,7 @@ eDBfieldMap *eDBxmlMapping(eurephiaCTX *ctx, eDBfieldMap *dbmap, const char *tbl const char *eDBmkSortKeyString(eDBfieldMap *tfmap, const char *skeys_str); long int eDBmappingFieldsPresent(eDBfieldMap *map); const char *eDBmappingGetValue(eDBfieldMap *map, long long field_id); +int eDBmappingSetValue(eDBfieldMap *map, long long field_id, char *value); #endif // HAVE_LIBXML2 #endif // !EUREPHIADB_MAPPING_H -- cgit