44 static void _dqrdb_destroy_dqr(
DQR *dqr)
47 if (dqr->
id) free((
void *)dqr->
id);
48 if (dqr->
desc) free((
void *)dqr->
desc);
57 static DQR *_dqrdb_create_dqr(
65 const char *code_desc,
76 if (!desc) desc =
"NULL";
77 if (!ds_name) ds_name =
"NULL";
78 if (!var_name) var_name =
"NULL";
79 if (!color) color =
"NULL";
80 if (!code_desc) code_desc =
"NULL";
82 if (!(dqr->
id = strdup(
id)) ||
83 !(dqr->
desc = strdup(desc)) ||
84 !(dqr->
ds_name = strdup(ds_name)) ||
85 !(dqr->
var_name = strdup(var_name)) ||
86 !(dqr->
color = strdup(color)) ||
89 _dqrdb_destroy_dqr(dqr);
94 dqr->
code = atoi(code);
148 "Could not create DQRDB connection\n"
149 " -> memory allocation error\n");
151 return((
DQRDB *)NULL);
164 return((
DQRDB *)NULL);
234 for (attempts = 1;; attempts++) {
242 "Could not connect to DQRDB\n"
243 " -> exceeded maximum number of retry attempts: %d\n",
334 for (i = 0; dqrs[i]; i++) {
335 _dqrdb_destroy_dqr(dqrs[i]);
374 const char *facility,
375 const char *dsc_name,
376 const char *dsc_level,
377 const char *var_name,
382 const char *command =
"SELECT * FROM get_dqrs($1,$2,$3,$4,$5,$6,$7)";
383 const char *params[7];
392 *dqrs = (
DQR **)NULL;
394 params[0] = dsc_name;
395 params[1] = dsc_level;
397 params[3] = facility;
398 params[4] = var_name;
407 params[5] = (
const char *)NULL;
417 params[6] = (
const char *)NULL;
424 *dqrs = (
DQR **)calloc(dbres->
nrows + 1,
sizeof(
DQR *));
428 "Could not get list of DQRs for: %s%s%s.%s:%s\n"
429 " -> memory allocation error\n",
430 site, dsc_name, facility, dsc_level, var_name);
436 for (row = 0; row < dbres->
nrows; row++) {
438 (*dqrs)[row] = _dqrdb_create_dqr(
453 "Could not get list of DQRs for: %s%s%s.%s:%s\n"
454 " -> memory allocation error\n",
455 site, dsc_name, facility, dsc_level, var_name);
458 *dqrs = (
DQR **)NULL;
467 (*dqrs)[dbres->
nrows] = (
DQR *)NULL;
500 for (i = 0; dqrs[i]; i++) {
503 length = strlen(dqrs[i]->
id);
504 if (id_width < length) { id_width = length; }
507 if (dqrs[i]->ds_name) {
508 length = strlen(dqrs[i]->ds_name);
509 if (ds_width < length) { ds_width = length; }
512 if (dqrs[i]->var_name) {
513 length = strlen(dqrs[i]->var_name);
514 if (var_width < length) { var_width = length; }
517 if (dqrs[i]->color) {
518 length = strlen(dqrs[i]->color);
519 if (color_width < length) { color_width = length; }
522 if (dqrs[i]->code_desc) {
523 length = strlen(dqrs[i]->code_desc);
524 if (desc_width < length) { desc_width = length; }
528 sprintf(format1,
"%%-%ds | %%-%ds | %%-%ds ", id_width, ds_width, var_width);
529 sprintf(format2,
"| %%-%ds | %%-%ds ", color_width, desc_width);
531 fprintf(fp, format1,
"id",
"datastream",
"variable");
532 fprintf(fp,
"| code ");
533 fprintf(fp, format2,
"color",
"code_desc");
534 fprintf(fp,
"| start time | end time\n");
536 for (i = 0; dqrs[i]; i++) {
537 fprintf(fp, format1, dqrs[i]->
id, dqrs[i]->ds_name, dqrs[i]->var_name);
539 if (dqrs[i]->code < 0) {
540 fprintf(fp,
"| %d ", dqrs[i]->code);
543 fprintf(fp,
"| %d ", dqrs[i]->code);
546 fprintf(fp, format2, dqrs[i]->color, dqrs[i]->code_desc);
548 fprintf(fp,
"| %s | %s\n",