summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2013-04-12 22:49:27 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2013-04-12 22:49:27 +0200
commit0180c7cd3421f0e473758d5cfca9cd1a9bfd120f (patch)
treee8366c52f635020f89d62d32035455b2b296db7b
parent60800a7030c7aa3a9e1a1b6155abc4079a0e34f1 (diff)
downloadeurephia-0180c7cd3421f0e473758d5cfca9cd1a9bfd120f.tar.gz
eurephia-0180c7cd3421f0e473758d5cfca9cd1a9bfd120f.tar.xz
eurephia-0180c7cd3421f0e473758d5cfca9cd1a9bfd120f.zip
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 <dazo@users.sourceforge.net>
-rw-r--r--database/eurephiadb_mapping.c43
-rw-r--r--database/eurephiadb_mapping.h1
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