From d1491e0860efc2ea3bd85a9f68cd83f18b575ae0 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 17 Jul 2020 15:03:53 +0200 Subject: [PATCH] Use JSON arrays in dbpf --- documentation/RELEASE_NOTES.md | 3 +-- modules/database/src/ioc/db/dbTest.c | 33 ++++++---------------------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/documentation/RELEASE_NOTES.md b/documentation/RELEASE_NOTES.md index 6464c7470..fb6f691e3 100644 --- a/documentation/RELEASE_NOTES.md +++ b/documentation/RELEASE_NOTES.md @@ -35,8 +35,7 @@ when reading empty arrays from an input link. #### Array support for dbpf -The dbpf function now accepts arrays, including empty arrays, as a quoted -whitespace separated list of values. +The dbpf function now accepts arrays, including empty arrays as a JSON string. #### Scalar records reading from empty arrays diff --git a/modules/database/src/ioc/db/dbTest.c b/modules/database/src/ioc/db/dbTest.c index a312abbf7..9368bfc71 100644 --- a/modules/database/src/ioc/db/dbTest.c +++ b/modules/database/src/ioc/db/dbTest.c @@ -40,6 +40,7 @@ #include "recGbl.h" #include "recSup.h" #include "special.h" +#include "dbConvertJSON.h" #define MAXLINE 80 #define MAXMESS 128 @@ -381,39 +382,19 @@ long dbpf(const char *pname,const char *pvalue) } if (addr.no_elements > 1) { + dbrType = addr.dbr_field_type; if (addr.dbr_field_type == DBR_CHAR || addr.dbr_field_type == DBR_UCHAR) { - dbrType = addr.dbr_field_type; n = (long)strlen(pvalue) + 1; } else { - const char *p = pvalue; - - for (n = 0; *p && n < addr.no_elements; n++) { - while (isspace(*p)) p++; - while (*p && !isspace(*p)) { - if (p[0] == '\\' && p[1]) p++; - p++; - } - } - p = pvalue; - array = calloc(n, MAX_STRING_SIZE); + n = addr.no_elements; + array = calloc(n, dbValueSize(dbrType)); if (!array) { printf("Out of memory\n"); return -1; } - for (n = 0; *p && n < addr.no_elements; n++) { - char* c = &array[n*MAX_STRING_SIZE]; - while (isspace(*p)) p++; - pvalue = p; - while (*p && !isspace(*p)) { - if (p[0] == '\\' && p[1]) p++; - if (c >= &array[(n+1)*MAX_STRING_SIZE]-1) { - printf("Value [%ld] %.*s too long\n", n, (int)(p-pvalue), pvalue); - free(array); - return -1; - } - *c++=*p++; - } - } + status = dbPutConvertJSON(pvalue, dbrType, array, &n); + if (status) + return status; pvalue = array; } }