Mapper
values_search.c
Go to the documentation of this file.
1 #include <sqlhdr.h>
2 #include <sqliapi.h>
3 #line 1 "values_search.ec"
4 #include "prototypes_new.h"
5 /*
6  * EXEC SQL include sqlca.h;
7  */
8 #line 2 "values_search.ec"
9 
10 #line 2 "values_search.ec"
11 #line 1 "/opt/informix/incl/esql/sqlca.h"
12 /****************************************************************************
13  *
14  * Licensed Material - Property Of IBM
15  *
16  * "Restricted Materials of IBM"
17  *
18  * IBM Informix Client SDK
19  * Copyright IBM Corporation 1997, 2008. All rights reserved.
20  *
21  * Title: sqlca.h
22  * Description: SQL Control Area
23  *
24  ***************************************************************************
25  */
26 
27 #ifndef SQLCA_INCL
28 #define SQLCA_INCL
29 
30 #include "ifxtypes.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct sqlca_s
37  {
38  int4 sqlcode;
39 #ifdef DB2CLI
40  char sqlerrm[600]; /* error message parameters */
41 #else /* DB2CLI */
42  char sqlerrm[72]; /* error message parameters */
43 #endif /* DB2CLI */
44  char sqlerrp[8];
45  int4 sqlerrd[6];
46  /* 0 - estimated number of rows returned */
47  /* 1 - serial value after insert or ISAM error code */
48  /* 2 - number of rows processed */
49  /* 3 - estimated cost */
50  /* 4 - offset of the error into the SQL statement */
51  /* 5 - rowid after insert */
52 #ifdef _FGL_
53  char sqlawarn[8];
54 #else
55  struct sqlcaw_s
56  {
57  char sqlwarn0; /* = W if any of sqlwarn[1-7] = W */
58  char sqlwarn1; /* = W if any truncation occurred or
59  database has transactions or
60  no privileges revoked */
61  char sqlwarn2; /* = W if a null value returned or
62  ANSI database */
63  char sqlwarn3; /* = W if no. in select list != no. in into list or
64  turbo backend or no privileges granted */
65  char sqlwarn4; /* = W if no where clause on prepared update, delete or
66  incompatible float format */
67  char sqlwarn5; /* = W if non-ANSI statement */
68  char sqlwarn6; /* = W if server is in data replication secondary mode */
69  char sqlwarn7; /* = W if database locale is different from proc_locale
70  = W if backend XPS and if explain avoid_execute is set
71  (for select, insert, delete and update only)
72  */
73  } sqlwarn;
74 #endif
76 
77 /* NOTE: 4gl assumes that the sqlwarn structure can be defined as
78  * sqlawarn -- an 8 character string, because single-char
79  * variables are not recognized in 4gl.
80  *
81  * If this structure should change, the code generated by 4gl compiler
82  * must also change
83  */
84 
85 #define SQLNOTFOUND 100
86 
87 #ifndef IFX_THREAD
88 #ifdef DB2CLI
89 #define sqlca ifmxsqlca
90 extern struct sqlca_s sqlca;
91 #else /* DB2CLI */
92 extern struct sqlca_s sqlca;
93 #endif /* DB2CLI */
94 
95 #ifndef DRDAHELP
96 extern int4 SQLCODE;
97 #endif
98 
99 extern char SQLSTATE[];
100 #else /* IFX_THREAD */
101 extern int4 * ifx_sqlcode(void);
102 extern struct sqlca_s * ifx_sqlca(void);
103 /* ifx_sqlstate() declared in sqlhdr.h */
104 #define SQLCODE (*(ifx_sqlcode()))
105 #define SQLSTATE ((char *)(ifx_sqlstate()))
106 #define sqlca (*(ifx_sqlca()))
107 #endif /* IFX_THREAD */
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* SQLCA_INCL */
114 
115 #line 103 "/opt/informix/incl/esql/sqlca.h"
116 #line 3 "values_search.ec"
117 
118 void change_date_time(int *,int *,int *,int *);
119 
120 int values_search(char *hb5,char *parm,struct stim begin_date,struct stim
121 end_date,struct stn_values *stn_values)
122 
123 {
124 
125 int i,j,jtotal,k;
126 int zdate;
127 
128 /*
129  * EXEC SQL BEGIN DECLARE SECTION;
130  */
131 #line 14 "values_search.ec"
132 #line 15 "values_search.ec"
133 int edate, bdate;
134 int eyr, emo, edy;
135 int byr, bmo, bdy;
136 int etime, btime;
137 int year, month, day, ptime;
138  char pe1[2], pe2[2], dur[2], t[2], s[2], e[2], p[2], shb5[10];
139 extern struct recsingle_rec
140  {
141  char id[6];
142  char pe1[2];
143  char pe2[2];
144  char dur[2];
145  char t[2];
146  char s[2];
147  char e[2];
148  char p[2];
149  int cal_yr;
150  int mon;
151  int zday;
152  int ztime;
153  double value;
154  char info[2];
155  } rec_single;
156 /*
157  * EXEC SQL END DECLARE SECTION;
158  */
159 #line 41 "values_search.ec"
160 
161 
162 pe1[1]=0;
163 pe2[1]=0;
164 dur[1]=0;
165 t[1]=0;
166 s[1]=0;
167 e[1]=0;
168 p[1]=0;
169 
170 strcpy(shb5,hb5);
171 pe1[0]=parm[0];
172 pe2[0]=parm[1];
173 dur[0]=parm[2];
174 t[0]=parm[3];
175 s[0]=parm[4];
176 e[0]=parm[5];
177 p[0]=parm[6];
178 
179 
180 eyr=end_date.year;
181 emo=end_date.month;
182 edy=end_date.day;
183 etime=end_date.hour*10000;
184 
185 byr=begin_date.year;
186 bmo=begin_date.month;
187 bdy=begin_date.day;
188 btime=begin_date.hour*10000;
189 
190 year=byr;
191 month=bmo;
192 day=bdy;
193 ptime=btime;
194 jtotal=0;
195 
196 /*printf("into value search %d %d %d %d\n",eyr,emo,edy,etime);*/
197 
198 for(;;) {
199 
200  /*printf("%s %s %s %s %s %s %s %s %d %d %d %d\n",
201  shb5,pe1,pe2,dur,t,s,e,p,year,month,day,ptime);*/
202 
203 /*
204  * EXEC SQL select *
205  * into :rec_single
206  * from rawval
207  * where id=:shb5 and
208  * pe1=:pe1 and
209  * pe2=:pe2 and
210  * dur=:dur and
211  * t=:t and
212  * s=:s and
213  * e=:e and
214  * p=:p and
215  * cal_yr=:year and
216  * mon=:month and
217  * zday=:day and
218  * ztime=:ptime;
219  */
220 #line 84 "values_search.ec"
221  {
222 #line 98 "values_search.ec"
223  static const char *sqlcmdtxt[] =
224 #line 98 "values_search.ec"
225  {
226 #line 98 "values_search.ec"
227  "select * from rawval where id = ? and pe1 = ? and pe2 = ? and dur = ? and t = ? and s = ? and e = ? and p = ? and cal_yr = ? and mon = ? and zday = ? and ztime = ?",
228  0
229  };
230 #line 98 "values_search.ec"
231 static ifx_cursor_t _SQ0 = {0};
232  static ifx_sqlvar_t _sqibind[] =
233  {
234  { 100, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
235  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
236  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
237  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
238  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
239  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
240  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
241  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
242  { 102, sizeof(year), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
243  { 102, sizeof(month), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
244  { 102, sizeof(day), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
245  { 102, sizeof(ptime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
246 #line 98 "values_search.ec"
247  };
248  static ifx_sqlvar_t _sqobind[] =
249  {
250  { 100, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
251  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
252  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
253  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
254  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
255  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
256  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
257  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
258  { 102, sizeof((rec_single).cal_yr), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
259  { 102, sizeof((rec_single).mon), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
260  { 102, sizeof((rec_single).zday), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
261  { 102, sizeof((rec_single).ztime), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
262  { 105, sizeof((rec_single).value), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
263  { 100, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
264 #line 98 "values_search.ec"
265  };
266 #line 98 "values_search.ec"
267  _sqibind[0].sqldata = shb5;
268 #line 98 "values_search.ec"
269  _sqibind[1].sqldata = pe1;
270 #line 98 "values_search.ec"
271  _sqibind[2].sqldata = pe2;
272 #line 98 "values_search.ec"
273  _sqibind[3].sqldata = dur;
274 #line 98 "values_search.ec"
275  _sqibind[4].sqldata = t;
276 #line 98 "values_search.ec"
277  _sqibind[5].sqldata = s;
278 #line 98 "values_search.ec"
279  _sqibind[6].sqldata = e;
280 #line 98 "values_search.ec"
281  _sqibind[7].sqldata = p;
282 #line 98 "values_search.ec"
283  _sqibind[8].sqldata = (char *) &year;
284 #line 98 "values_search.ec"
285  _sqibind[9].sqldata = (char *) &month;
286 #line 98 "values_search.ec"
287  _sqibind[10].sqldata = (char *) &day;
288 #line 98 "values_search.ec"
289  _sqibind[11].sqldata = (char *) &ptime;
290 #line 98 "values_search.ec"
291  _sqobind[0].sqldata = (rec_single).id;
292 #line 98 "values_search.ec"
293  _sqobind[1].sqldata = (rec_single).pe1;
294 #line 98 "values_search.ec"
295  _sqobind[2].sqldata = (rec_single).pe2;
296 #line 98 "values_search.ec"
297  _sqobind[3].sqldata = (rec_single).dur;
298 #line 98 "values_search.ec"
299  _sqobind[4].sqldata = (rec_single).t;
300 #line 98 "values_search.ec"
301  _sqobind[5].sqldata = (rec_single).s;
302 #line 98 "values_search.ec"
303  _sqobind[6].sqldata = (rec_single).e;
304 #line 98 "values_search.ec"
305  _sqobind[7].sqldata = (rec_single).p;
306 #line 98 "values_search.ec"
307  _sqobind[8].sqldata = (char *) &(rec_single).cal_yr;
308 #line 98 "values_search.ec"
309  _sqobind[9].sqldata = (char *) &(rec_single).mon;
310 #line 98 "values_search.ec"
311  _sqobind[10].sqldata = (char *) &(rec_single).zday;
312 #line 98 "values_search.ec"
313  _sqobind[11].sqldata = (char *) &(rec_single).ztime;
314 #line 98 "values_search.ec"
315  _sqobind[12].sqldata = (char *) &(rec_single).value;
316 #line 98 "values_search.ec"
317  _sqobind[13].sqldata = (rec_single).info;
318 #line 98 "values_search.ec"
319  sqli_slct(ESQLINTVERSION, &_SQ0,sqlcmdtxt,12,_sqibind,14,_sqobind,0,(ifx_literal_t *)0,(ifx_namelist_t *)0,0);
320 #line 98 "values_search.ec"
321  }
322 
323  if(sqlca.sqlcode < 0)
324  return(sqlca.sqlcode);
325 
326  if(sqlca.sqlcode == 0) {
327 
328 
329  zdate=rec_single.cal_yr*10000+rec_single.mon*100+rec_single.zday;
330 
331  stn_values[jtotal].zdate=zdate;
332 
333  stn_values[jtotal].ztime=rec_single.ztime;
334 
335  stn_values[jtotal].value=rec_single.value;
336 
337  stn_values[jtotal++].qual=rec_single.info[0];
338 
339  }
340 
341  if(year==eyr && month==emo && day==edy && ptime==etime)
342  break;
343 
344  change_date_time(&year,&month,&day,&ptime);
345 
346  if(jtotal > 9600)
347  break;
348 
349  }
350 
351 return(jtotal);
352 
353 }
354 
355 void change_date_time(int *year,int *month, int *day,int *ztime)
356 
357 {
358 
359 extern int mday[];
360 char buf[10];
361 int hour,min;
362 
363 if (!((*year)%4))
364  mday[1]=29;
365 else
366  mday[1]=28;
367 
368 /*
369 if ((*year)==1972 || (*year)==1976 || (*year)==1980 ||
370  (*year)==1984 || (*year)==1988 || (*year)==1992 ||
371  (*year)==1996 || (*year)==2000 || (*year)==2004 ||
372  (*year)==2008 || (*year)==2012 || (*year)==2016)
373  mday[1]=29;
374 else
375  mday[1]=28;
376 */
377 
378 hour=*ztime/10000;
379 min=(*ztime-hour*10000)/100;
380 
381 if(min==0)
382  *ztime=(hour-1)*10000+5900;
383 
384 else
385  *ztime=*ztime-100;
386 
387 if(*ztime < 0) {
388 
389  *ztime=235900;
390  (*day)--;
391 
392  }
393 
394 if(*day <= 0) {
395 
396  (*month)--;
397  if(*month==0) {
398 
399  (*year)--;
400  *month=12;
401 
402  }
403 
404  *day=mday[*month-1];
405 
406  }
407 
408 else if(*day > mday[*month-1]) {
409 
410  *(month)++;
411 
412  if(*month > 12) {
413 
414  (*year)++;
415  *month=1;
416 
417  }
418 
419  *day=1;
420 
421  }
422 
423 
424 return;
425 }
426 
427 #line 202 "values_search.ec"
int emo
Definition: calfma_qtrly.c:123
int bdy
Definition: calfma_qtrly.c:124
int eyr
Definition: calfma_qtrly.c:123
int edy
Definition: calfma_qtrly.c:123
int bmo
Definition: calfma_qtrly.c:124
int byr
Definition: calfma_qtrly.c:124
static int i
int hour
Definition: display_data.c:26
int day
Definition: display_data.c:26
int year
Definition: display_data.c:26
int month
Definition: display_data.c:26
int mday[]
Definition: fmap_qtrly.c:519
char * mon[]
struct stat buf
Definition: is_file_closed.c:8
int4 SQLCODE
struct sqlca_s ifx_sqlca_t
char SQLSTATE[]
struct sqlca_s sqlca
void change_date_time(int *, int *, int *, int *)
int values_search(char *hb5, char *parm, struct stim begin_date, struct stim end_date, struct stn_values *stn_values)
int j
Definition: mapp2h.h:48
int k
Definition: mapp2h.h:48
float value
char sqlwarn5
Definition: db.c:65
char sqlwarn3
Definition: db.c:61
char sqlwarn4
Definition: db.c:63
char sqlwarn7
Definition: db.c:67
char sqlwarn1
Definition: db.c:57
char sqlwarn6
Definition: db.c:66
char sqlwarn2
Definition: db.c:59
char sqlwarn0
Definition: db.c:56
Definition: db.c:43
long sqlerrd[6]
Definition: db.c:47
struct sqlca_s::sqlcaw_s sqlwarn
long sqlcode
Definition: db.c:44
char sqlerrm[72]
Definition: db.c:45
char sqlerrp[8]
Definition: db.c:46
Definition: misc.h:93
int day
Definition: misc.h:97
int year
Definition: misc.h:95
int hour
Definition: misc.h:98
int month
Definition: misc.h:96
char qual
Definition: hydro_data.h:36
float value
Definition: hydro_data.h:35