libdsdb3  3.0
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups
dbog_retriever.c
Go to the documentation of this file.
1 /*******************************************************************************
2 *
3 * COPYRIGHT (C) 2010 Battelle Memorial Institute. All Rights Reserved.
4 *
5 ********************************************************************************
6 *
7 * Author:
8 * name: Krista Gaustad
9 * phone: (509) 375-5950
10 * email: krista.gaustad@pnl.gov
11 *
12 ********************************************************************************
13 *
14 * REPOSITORY INFORMATION:
15 * $Revision: 12566 $
16 * $Author: ermold $
17 * $Date: 2012-02-05 03:08:12 +0000 (Sun, 05 Feb 2012) $
18 *
19 *******************************************************************************/
20 
21 /** @file dbog_retriever.c
22  * Retriever object group functions.
23  */
24 
25 #include "dbconn.h"
26 #include <strings.h>
27 
28 /** @privatesection */
29 
30 /**
31  * Get all coordinate system dimensions defined for a process.
32  *
33  * The returned rows will be sorted by coordinate system ID and then by
34  * dimension order. The following macros can be used to access the collumn
35  * values for each row:
36  *
37  * - RetCoordDim_SystemID(dbres,row)
38  * - RetCoordDim_Order(dbres,row)
39  * - RetCoordDim_Name(dbres,row)
40  * - RetCoordDim_Interval(dbres,row)
41  * - RetCoordDim_Units(dbres,row)
42  * - RetCoordDIM_SubGroupID(dbres,row)
43  * - RetCoordDim_ID(dbres,row)
44  *
45  * Error messages from this function are sent to the message handler
46  * (see msngr_init_log() and msngr_init_mail()).
47  *
48  * @return Database Query Status
49  * - DB_NO_ERROR
50  * - DB_NULL_RESULT
51  * - DB_BAD_RESULT
52  * - DB_MEM_ERROR
53  * - DB_ERROR
54  */
55 DBStatus retog_get_coord_dims(
56  DBConn *dbconn,
57  const char *proc_type,
58  const char *proc_name,
59  DBResult **result)
60 {
61  const char *command = "SELECT * FROM get_ret_coord_dims_with_ids($1,$2)";
62  const char *params[2];
63 
64  params[0] = proc_type;
65  params[1] = proc_name;
66 
67  return(dbconn_query(dbconn, command, 2, params, result));
68 }
69 
70 /**
71  * Get all coordinate systems defined for a process.
72  *
73  * The returned rows will be sorted by coordinate system ID. The following
74  * macros can be used to access the collumn values for each row:
75  *
76  * - RetCoordSystem_ID(dbres,row)
77  * - RetCoordSystem_Name(dbres,row)
78  *
79  * Error messages from this function are sent to the message handler
80  * (see msngr_init_log() and msngr_init_mail()).
81  *
82  * @return Database Query Status
83  * - DB_NO_ERROR
84  * - DB_NULL_RESULT
85  * - DB_BAD_RESULT
86  * - DB_MEM_ERROR
87  * - DB_ERROR
88  */
89 DBStatus retog_get_coord_systems(
90  DBConn *dbconn,
91  const char *proc_type,
92  const char *proc_name,
93  DBResult **result)
94 {
95  const char *command = "SELECT * FROM get_ret_coord_systems_with_ids($1,$2)";
96  const char *params[2];
97 
98  params[0] = proc_type;
99  params[1] = proc_name;
100 
101  return(dbconn_query(dbconn, command, 2, params, result));
102 }
103 
104 /**
105  * Get all datastream variable names for all coordinate system dimensions
106  * defined for a process.
107  *
108  * The returned rows will be sorted by coordinate system dimension ID,
109  * datastream ID, and then by variable name priority. The following
110  * macros can be used to access the collumn values for each row:
111  *
112  * - RetCoordDimVar_CoordDimID(dbres,row)
113  * - RetCoordDimVar_DsID(dbres,row)
114  * - RetCoordDimVar_Priority(dbres,row)
115  * - RetCoordDimVar_Name(dbres,row)
116  *
117  * Error messages from this function are sent to the message handler
118  * (see msngr_init_log() and msngr_init_mail()).
119  *
120  * @return Database Query Status
121  * - DB_NO_ERROR
122  * - DB_NULL_RESULT
123  * - DB_BAD_RESULT
124  * - DB_MEM_ERROR
125  * - DB_ERROR
126  */
127 DBStatus retog_get_coord_var_names(
128  DBConn *dbconn,
129  const char *proc_type,
130  const char *proc_name,
131  DBResult **result)
132 {
133  const char *command = "SELECT * FROM get_ret_coord_var_names_with_ids($1,$2)";
134  const char *params[2];
135 
136  params[0] = proc_type;
137  params[1] = proc_name;
138 
139  return(dbconn_query(dbconn, command, 2, params, result));
140 }
141 
142 /**
143  * Get all retriever datastreams defined for a process.
144  *
145  * The returned rows will be sorted by subgroup ID and then by subgroup
146  * priority. The following macros can be used to access the collumn values
147  * for each row:
148  *
149  * - RetDs_DsID(dbres,row)
150  * - RetDs_SubGroupID(dbres,row)
151  * - RetDs_SubGroupPriority(dbres,row)
152  * - RetDs_Name(dbres,row)
153  * - RetDs_Level(dbres,row)
154  * - RetDs_Site(dbres,row)
155  * - RetDs_Fac(dbres,row)
156  * - RetDs_SiteDep(dbres,row)
157  * - RetDs_FacDep(dbres,row)
158  * - RetDs_BegDateDep(dbres,row)
159  * - RetDs_EndDateDep(dbres,row)
160  *
161  * Error messages from this function are sent to the message handler
162  * (see msngr_init_log() and msngr_init_mail()).
163  *
164  * @return Database Query Status
165  * - DB_NO_ERROR
166  * - DB_NULL_RESULT
167  * - DB_BAD_RESULT
168  * - DB_MEM_ERROR
169  * - DB_ERROR
170  */
171 DBStatus retog_get_datastreams(
172  DBConn *dbconn,
173  const char *proc_type,
174  const char *proc_name,
175  DBResult **result)
176 {
177  const char *command = "SELECT * FROM get_ret_datastreams_with_ids($1,$2)";
178  const char *params[2];
179 
180  params[0] = proc_type;
181  params[1] = proc_name;
182 
183  return(dbconn_query(dbconn, command, 2, params, result));
184 }
185 
186 /**
187  * Get all retriever groups and subgroups defined for a process.
188  *
189  * The returned rows will be sorted by datastream group ID and then by
190  * subgroup order. The following macros can be used to access the collumn
191  * values for each row:
192  *
193  * - Ret_GroupID(dbres,row)
194  * - Ret_GroupName(dbres,row)
195  * - Ret_SubGroupID(dbres,row)
196  * - Ret_SubGroupName(dbres,row)
197  * - Ret_SubGroupOrder(dbres,row)
198  *
199  * Error messages from this function are sent to the message handler
200  * (see msngr_init_log() and msngr_init_mail()).
201  *
202  * @return Database Query Status
203  * - DB_NO_ERROR
204  * - DB_NULL_RESULT
205  * - DB_BAD_RESULT
206  * - DB_MEM_ERROR
207  * - DB_ERROR
208  */
209 DBStatus retog_get_groups(
210  DBConn *dbconn,
211  const char *proc_type,
212  const char *proc_name,
213  DBResult **result)
214 {
215  const char *command = "SELECT * FROM get_ret_subgroups_with_ids($1,$2)";
216  const char *params[2];
217 
218  params[0] = proc_type;
219  params[1] = proc_name;
220 
221  return(dbconn_query(dbconn, command, 2, params, result));
222 }
223 
224 /**
225  * Get all retriever variables defined for a process.
226  *
227  * The returned rows will be sorted by datastream group ID and then by
228  * variable ID. The following macros can be used to access the collumn
229  * values for each row:
230  *
231  * - RetVar_VarID(dbres,row)
232  * - RetVar_Name(dbres,row)
233  * - RetVar_GroupID(dbres,row)
234  * - RetVar_CoordSystemID(dbres,row)
235  * - RetVar_Units(dbres,row)
236  * - RetVar_DataType(dbres,row)
237  * - RetVar_StartOffset(dbres,row)
238  * - RetVar_EndOffset(dbres,row)
239  * - RetVar_Max(dbres,row)
240  * - RetVar_Min(dbres,row)
241  * - RetVar_Delta(dbres,row)
242  * - RetVar_ReqToRun(dbres,row)
243  * - RetVar_QCFlag(dbres,row)
244  * - RetVar_QCReqToRun(dbres,row)
245  *
246  * Error messages from this function are sent to the message handler
247  * (see msngr_init_log() and msngr_init_mail()).
248  *
249  * @return Database Query Status
250  * - DB_NO_ERROR
251  * - DB_NULL_RESULT
252  * - DB_BAD_RESULT
253  * - DB_MEM_ERROR
254  * - DB_ERROR
255  */
256 DBStatus retog_get_variables(
257  DBConn *dbconn,
258  const char *proc_type,
259  const char *proc_name,
260  DBResult **result)
261 {
262  const char *command = "SELECT * FROM get_ret_variables_with_ids($1,$2)";
263  const char *params[2];
264 
265  params[0] = proc_type;
266  params[1] = proc_name;
267 
268  return(dbconn_query(dbconn, command, 2, params, result));
269 }
270 
271 /**
272  * Get all dimension names defined for all retriever variables.
273  *
274  * The returned rows will be sorted by variable ID and then by dimension
275  * order. The following macros can be used to access the collumn values
276  * for each row:
277  *
278  * - RetVarDim_VarID(dbres,row)
279  * - RetVarDim_Order(dbres,row)
280  * - RetVarDim_Name(dbres,row)
281  *
282  * Error messages from this function are sent to the message handler
283  * (see msngr_init_log() and msngr_init_mail()).
284  *
285  * @return Database Query Status
286  * - DB_NO_ERROR
287  * - DB_NULL_RESULT
288  * - DB_BAD_RESULT
289  * - DB_MEM_ERROR
290  * - DB_ERROR
291  */
292 DBStatus retog_get_var_dims(
293  DBConn *dbconn,
294  const char *proc_type,
295  const char *proc_name,
296  DBResult **result)
297 {
298  const char *command = "SELECT * FROM get_ret_var_dims_with_ids($1,$2)";
299  const char *params[2];
300 
301  params[0] = proc_type;
302  params[1] = proc_name;
303 
304  return(dbconn_query(dbconn, command, 2, params, result));
305 }
306 
307 /**
308  * Get all input variable names defined for all retriever variables.
309  *
310  * The returned rows will be sorted by variable ID, datastream ID, and then
311  * by variable name priority. The following macros can be used to access the
312  * collumn values for each row:
313  *
314  * - RetVarName_VarID(dbres,row)
315  * - RetVarName_DsID(dbres,row)
316  * - RetVarName_Priority(dbres,row)
317  * - RetVarName_Name(dbres,row)
318  *
319  * Error messages from this function are sent to the message handler
320  * (see msngr_init_log() and msngr_init_mail()).
321  *
322  * @return Database Query Status
323  * - DB_NO_ERROR
324  * - DB_NULL_RESULT
325  * - DB_BAD_RESULT
326  * - DB_MEM_ERROR
327  * - DB_ERROR
328  */
329 DBStatus retog_get_var_names(
330  DBConn *dbconn,
331  const char *proc_type,
332  const char *proc_name,
333  DBResult **result)
334 {
335  const char *command = "SELECT * FROM get_ret_var_names_with_ids($1,$2)";
336  const char *params[2];
337 
338  params[0] = proc_type;
339  params[1] = proc_name;
340 
341  return(dbconn_query(dbconn, command, 2, params, result));
342 }
343 
344 /**
345  * Get all output datastreams and variables defined for all retriever variables.
346  *
347  * The returned rows will be sorted by variable ID. The following macros can
348  * be used to access the collumn values for each row:
349  *
350  * - RetVarOut_VarID(dbres,row)
351  * - RetVarOut_DsName(dbres,row)
352  * - RetVarOut_DsLevel(dbres,row)
353  * - RetVarOut_VarName(dbres,row)
354  *
355  * Error messages from this function are sent to the message handler
356  * (see msngr_init_log() and msngr_init_mail()).
357  *
358  * @return Database Query Status
359  * - DB_NO_ERROR
360  * - DB_NULL_RESULT
361  * - DB_BAD_RESULT
362  * - DB_MEM_ERROR
363  * - DB_ERROR
364  */
365 DBStatus retog_get_var_outputs(
366  DBConn *dbconn,
367  const char *proc_type,
368  const char *proc_name,
369  DBResult **result)
370 {
371  const char *command = "SELECT * FROM get_ret_var_outputs_with_ids($1,$2)";
372  const char *params[2];
373 
374  params[0] = proc_type;
375  params[1] = proc_name;
376 
377  return(dbconn_query(dbconn, command, 2, params, result));
378 }
379 
380 /*******************************************************************************
381 ********************************************************************************
382 * Old Database Calls.
383 ********************************************************************************
384 *******************************************************************************/
385 
386 
387 /******************************************************************************
388 * Retriever DS VarNames
389 */
390 
391 DBStatus retrieverog_get_varnames(
392  DBConn *dbconn,
393  const char *proc_type,
394  const char *proc_name,
395  const char *datastream_name,
396  const char *datastream_level,
397  const char *subgroup_name,
398  const char *site,
399  const char *facility,
400  const char *site_dependency,
401  const char *facility_dependency,
402  time_t begin_date_dependency,
403  const char *group_name,
404  const char *vargroup_name,
405  DBResult **result)
406 {
407  const char *command = "SELECT * FROM get_ret_var_names($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
408  const char *params[12];
409  char time_string[32];
410 
411  params[0] = proc_type;
412  params[1] = proc_name;
413  params[2] = datastream_name;
414  params[3] = datastream_level;
415  params[4] = subgroup_name;
416  params[5] = site;
417  params[6] = facility;
418  params[7] = site_dependency;
419  params[8] = facility_dependency;
420  params[10] = group_name;
421  params[11] = vargroup_name;
422 
423 
424  if (begin_date_dependency) {
425  params[9] = dbconn_time_to_text(dbconn, begin_date_dependency, time_string);
426  if (!params[9]) {
427  *result = 0;
428  return(DB_ERROR);
429  }
430  }
431  else {
432  params[9] = (const char *)NULL;
433  }
434 
435  return(dbconn_query(dbconn, command, 12, params, result));
436 }
437 
438 /******************************************************************************
439 * Retriever DS VarDimNames
440 */
441 DBStatus retrieverog_get_vardimnames(
442  DBConn *dbconn,
443  const char *proc_type,
444  const char *proc_name,
445  const char *datastream_name,
446  const char *datastream_level,
447  const char *subgroup_name,
448  const char *site,
449  const char *facility,
450  const char *site_dependency,
451  const char *facility_dependency,
452  time_t begin_date_dependency,
453  const char *coord_system_name,
454  const char *dimname,
455  DBResult **result)
456 {
457  const char *command = "SELECT * FROM get_ret_var_dim_names($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)";
458  const char *params[12];
459  char time_string[32];
460 
461  params[0] = proc_type;
462  params[1] = proc_name;
463  params[2] = datastream_name;
464  params[3] = datastream_level;
465  params[4] = subgroup_name;
466  params[5] = site;
467  params[6] = facility;
468  params[7] = site_dependency;
469  params[8] = facility_dependency;
470  params[10] = coord_system_name;
471  params[11] = dimname;
472 
473  if (begin_date_dependency) {
474  params[9] = dbconn_time_to_text(dbconn, begin_date_dependency, time_string);
475  if (!params[9]) {
476  *result = 0;
477  return(DB_ERROR);
478  }
479  }
480  else {
481  params[9] = (const char *)NULL;
482  }
483 
484 
485  return(dbconn_query(dbconn, command, 12, params, result));
486 }
487 
488 /******************************************************************************
489 * Retriever DS CoordDims
490 */
491 DBStatus retrieverog_get_coord_dims(
492  DBConn *dbconn,
493  const char *proc_type,
494  const char *proc_name,
495  const char *ret_coord_system_name,
496  DBResult **result)
497 {
498  const char *command = "SELECT * FROM get_ret_coord_dims($1,$2,$3)";
499  const char *params[3];
500 
501  params[0] = proc_type;
502  params[1] = proc_name;
503  params[2] = ret_coord_system_name;
504 
505  return(dbconn_query(dbconn, command, 3, params, result));
506 }
507 
508 /******************************************************************************
509 * Retriever DS VarGroups
510 */
511 
512 DBStatus retrieverog_get_vargroups(
513  DBConn *dbconn,
514  const char *ds_group_name,
515  const char *proc_type,
516  const char *proc_name,
517  DBResult **result)
518 {
519  const char *command = "SELECT * FROM get_ret_var_groups($1,$2,$3)";
520  const char *params[3];
521 
522  params[0] = ds_group_name;
523  params[1] = proc_type;
524  params[2] = proc_name;
525 
526  return(dbconn_query(dbconn, command, 3, params, result));
527 }
528 
529 /******************************************************************************
530 * Retriever DS Datastreams
531 */
532 
533 DBStatus retrieverog_get_datastreams(
534  DBConn *dbconn,
535  const char *proc_type,
536  const char *proc_name,
537  const char *ds_subgroup_name,
538  DBResult **result)
539 {
540  const char *command = "SELECT * FROM get_ret_datastreams($1,$2,$3)";
541  const char *params[3];
542 
543  params[0] = proc_type;
544  params[1] = proc_name;
545  params[2] = ds_subgroup_name;
546 
547  return(dbconn_query(dbconn, command, 3, params, result));
548 }
549 
550 /******************************************************************************
551 * Retriever DS SubGroups by Group
552 */
553 
554 DBStatus retrieverog_get_ds_subgroups_by_group(
555  DBConn *dbconn,
556  const char *proc_type,
557  const char *proc_name,
558  const char *group_name,
559  DBResult **result)
560 {
561  const char *command = "SELECT * FROM get_ret_ds_subgroups_by_group($1,$2,$3)";
562  const char *params[3];
563 
564  params[0] = proc_type;
565  params[1] = proc_name;
566  params[2] = group_name;
567 
568  return(dbconn_query(dbconn, command, 3, params, result));
569 }
570 
571 /******************************************************************************
572 * Retriever DS SubGroup Name
573 */
574 
575 DBStatus retrieverog_select_ds_subgroup_name(
576  DBConn *dbconn,
577  const char *proc_type,
578  const char *proc_name,
579  int subgroup_id,
580  char **result)
581 {
582  const char *command = "SELECT * FROM select_ret_ds_subgroup_name($1,$2,$3)";
583  const char *params[3];
584  char pstring[1024];
585 
586  params[0] = proc_type;
587  params[1] = proc_name;
588 
589  if (subgroup_id) {
590  sprintf(pstring,"%d",subgroup_id);
591  if (!params[2]) {
592  *result = 0;
593  return(DB_ERROR);
594  }
595  params[2]=(const char *)pstring;
596  }
597  else {
598  params[2] = (const char *)NULL;
599  }
600 
601  return(dbconn_query_text(dbconn, command, 3, params, result));
602 }
603 
604 /******************************************************************************
605 * Retriever DS SubGroups
606 */
607 
608 DBStatus retrieverog_get_ds_subgroups(
609  DBConn *dbconn,
610  const char *proc_type,
611  const char *proc_name,
612  DBResult **result)
613 {
614  const char *command = "SELECT * FROM get_ret_ds_subgroups($1,$2)";
615  const char *params[2];
616 
617  params[0] = proc_type;
618  params[1] = proc_name;
619 
620  return(dbconn_query(dbconn, command, 2, params, result));
621 }
622 
623 /******************************************************************************
624 * Retriever DS Groups
625 */
626 
627 DBStatus retrieverog_get_ds_groups(
628  DBConn *dbconn,
629  const char *proc_type,
630  const char *proc_name,
631  DBResult **result)
632 {
633  const char *command = "SELECT * FROM get_ret_ds_groups($1,$2)";
634  const char *params[2];
635 
636  params[0] = proc_type;
637  params[1] = proc_name;
638  return(dbconn_query(dbconn, command, 2, params, result));
639 }
640