source: branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c @ 850

Last change on this file since 850 was 850, checked in by djay, 7 years ago

Fix various memory leaks and enhance the callback support. Add the prohibited keyword to the callback section to avoid calling callback for such services.

  • Property svn:keywords set to Id
File size: 18.6 KB
Line 
1/*
2 * Authors : David Saggiorato
3 *           Gérald Fenoy
4 *  Copyright 2015 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "ogr_api.h"
26#include "ogrsf_frmts.h"
27#include "ogr_p.h"
28#include "response_print.h"
29#if GDAL_VERSION_MAJOR >= 2
30#include <gdal_priv.h>
31#endif
32
33#include "sqlapi.h"
34#include <fcgi_stdio.h>
35#include <stdlib.h>
36
37/**
38 * Global GDALDataset pointer
39 */
40#if GDAL_VERSION_MAJOR >=2
41GDALDataset
42#else
43OGRDataSource
44#endif
45 **zoo_DS = NULL;
46
47/**
48 * Global OGRLayer pointer pointing to the lastest result set
49 */
50OGRLayer *zoo_ResultSet = NULL;
51
52/**
53 * Create a GDAL / OGR string for connecting to a db backend defined in the
54 * key section.
55 *
56 * @param conf the maps containing the setting of the main.cfg file
57 * @param key the name of the section containing the connection setting
58 * @return the OGR connection string
59 */
60char* _createInitString(maps* conf,const char* key){
61  char* res=NULL;
62  char keywords[6][14]={
63    "dbname",
64    "host",
65    "port",
66    "user",
67    "password",
68    "active_schema"   
69  };
70  int i=0;
71  maps* cconf=getMaps(conf,key);
72  if(cconf==NULL)
73    return "-1";
74  int len=0;
75  for(i=0;i<6;i++){
76    map* tmp=getMap(cconf->content,keywords[i]);
77    if(tmp!=NULL){
78      if(res==NULL){
79        res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char));
80        sprintf(res,"%s='%s'",keywords[i],tmp->value);
81        len+=strlen(res);
82      }else{
83        char* res1=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
84        sprintf(res1," %s='%s'",keywords[i],tmp->value);
85        res=(char*)realloc(res,(len+strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
86        memcpy(res+len,res1,(strlen(keywords[i])+strlen(tmp->value)+5)*sizeof(char));
87        len+=strlen(res1);
88        res[len]=0;
89        free(res1);
90      }
91    }
92  }
93  map* tmp=getMap(cconf->content,"type");
94  if(tmp!=NULL){
95    char* fres=(char*)malloc((strlen(res)+strlen(tmp->value)+2)*sizeof(char));
96    sprintf(fres,"%s:%s",tmp->value,res);
97    free(res);
98    return fres;
99  }
100  return res;
101}
102
103/**
104 * Create a GDAL / OGR string for connecting to the db backend
105 *
106 * @param conf the maps containing the setting of the main.cfg file
107 * @return the OGR connection string
108 */
109char* createInitString(maps* conf){
110  return _createInitString(conf,"database");
111}
112
113/**
114 * Connect to a db backend.
115 *
116 * @param conf the maps containing the setting of the main.cfg file
117 * @see createInitString
118 */
119int _init_sql(maps* conf,const char* key){
120  char* sqlInitString=_createInitString(conf,key);
121  if(strncmp(sqlInitString,"-1",2)==0)
122    return -1;
123  OGRSFDriver *poDriver = NULL;
124  OGRRegisterAll();
125  int zoo_ds_nb=0;
126  map* dsNb=getMapFromMaps(conf,"lenv","ds_nb");
127  if(dsNb==NULL){
128    setMapInMaps(conf,"lenv","ds_nb","1");
129  }else{
130    zoo_ds_nb=atoi(dsNb->value);
131    char* tmp=(char*)malloc(11*sizeof(char));
132    sprintf(tmp,"%d",zoo_ds_nb+1);
133    setMapInMaps(conf,"lenv","ds_nb",(const char*)tmp);
134    free(tmp);
135  }
136  if(zoo_DS==NULL)
137    zoo_DS=
138#if GDAL_VERSION_MAJOR >= 2
139      (GDALDataset**) malloc(sizeof(GDALDataset*))
140#else
141      (OGRDataSource**) malloc(sizeof(OGRDataSource*))
142#endif
143      ;
144  else
145    zoo_DS=     
146#if GDAL_VERSION_MAJOR >= 2
147      (GDALDataset**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(GDALDataset*))
148#else
149      (OGRDataSource**)realloc(zoo_DS,(zoo_ds_nb+1)*sizeof(OGRDataSource*))
150#endif
151      ;
152 
153#if GDAL_VERSION_MAJOR >= 2
154  zoo_DS[zoo_ds_nb] = (GDALDataset*) GDALOpenEx( sqlInitString,
155                                      GDAL_OF_UPDATE | GDAL_OF_VECTOR,
156                                      NULL, NULL, NULL );
157#else
158  zoo_DS[zoo_ds_nb] = OGRSFDriverRegistrar::Open(sqlInitString,false,&poDriver);
159#endif
160  if( zoo_DS[zoo_ds_nb] == NULL ){
161#ifdef DEBUG
162    fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString);
163    fflush(stderr);
164#endif
165    free(sqlInitString);
166    setMapInMaps(conf,"lenv","dbIssue","1");
167    setMapInMaps(conf,"lenv","message",_("Failed to connect to the database backend"));
168    return -2;
169  }
170#ifdef DEBUG
171  fprintf(stderr,"sqlInitString: %s SUCEED !\n",sqlInitString);
172  fflush(stderr);
173#endif
174  fprintf(stderr,"sqlInitString: %s SUCEED %d !\n",sqlInitString,zoo_ds_nb);
175  fflush(stderr); 
176  free(sqlInitString);
177  zoo_ds_nb++;
178  return zoo_ds_nb;
179}
180
181/**
182 * Connect to the db backend.
183 *
184 * @param conf the maps containing the setting of the main.cfg file
185 * @see createInitString
186 */
187int init_sql(maps* conf){
188  return _init_sql(conf,"database");
189}
190
191/**
192 * Close any connection to the db backend.
193 *
194 * @param conf the maps containing the setting of the main.cfg file
195 */
196void close_sql(maps* conf,int cid){
197  if( zoo_ResultSet != NULL )
198    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
199  if(zoo_DS!=NULL){
200#if GDAL_VERSION_MAJOR >= 2
201    GDALClose(zoo_DS[cid]);
202#else
203    OGRDataSource::DestroyDataSource( zoo_DS[cid] );
204#endif
205    zoo_DS[cid]=NULL;
206  }
207}
208
209/**
210 * Call OGRCleanupAll.
211 *
212 */
213void end_sql(){
214  OGRCleanupAll();
215}
216
217/**
218 * Fetch a tuple set by executing a SQL query to the Database Backend.
219 *
220 * @param conf the maps containing the setting of the main.cfg file
221 * @param sqlQuery the SQL query to run
222 * @return NULL in case of failure or an OGRLayer pointer if the query succeed.
223 */
224OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){
225  if(zoo_DS[cid]==NULL)
226    return NULL;
227  OGRLayer *res=NULL;
228#ifdef DEBUG
229  fprintf(stderr,"************************* %s %s %d\n\n",sqlQuery,__FILE__,__LINE__);
230  fflush(stderr);
231#endif
232  res = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
233  return res;
234}
235
236void cleanFetchSql(maps* conf,int cid,OGRLayer *objects){
237  if( objects != NULL ){
238    zoo_DS[cid]->ReleaseResultSet( objects );
239    objects=NULL;
240  }
241}
242
243/**
244 * Execute a SQL query to the SQL Database Backend.
245 *
246 * @param conf the maps containing the setting of the main.cfg file
247 * @param sqlQuery the SQL query to run
248 * @return -1 in case of failure and 1 if the query succeed.
249 */
250int execSql(maps* conf,int cid,const char* sqlQuery){
251  int res=-1;
252  zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL);
253  if( zoo_ResultSet != NULL ){
254    res=1;
255  }
256  return res;
257}
258
259/**
260 * Clean any memory allocated by executing a request
261 *
262 * @param conf the maps containing the setting of the main.cfg file
263 * @param sqlQuery the SQL query to run
264 * @return -1 in case of failure and 1 if the query succeed.
265 */
266void cleanUpResultSet(const maps* conf,int cid){
267  if( zoo_ResultSet != NULL ){
268    zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet );
269    zoo_ResultSet=NULL;
270  }
271}
272
273#ifdef RELY_ON_DB
274int getCurrentId(maps* conf){
275  int res=0;
276  map* dsNb=getMapFromMaps(conf,"lenv","ds_nb");
277  if(dsNb!=NULL)
278    res=atoi(dsNb->value);
279  return res;
280}
281
282/**
283 * Record a file stored during ZOO-Kernel execution
284 *
285 * @param conf the maps containing the setting of the main.cfg file
286 * @param filename the file's name
287 * @param type the type (Intput,Output,Response)
288 * @param name the maps containing the setting of the main.cfg file
289 */
290void recordStoredFile(maps* conf,const char* filename,const char* type,const char* name){
291  int zoo_ds_nb=getCurrentId(conf);
292  map *uusid=getMapFromMaps(conf,"lenv","usid");
293  map *schema=getMapFromMaps(conf,"database","schema");
294  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(uusid->value)+strlen(filename)+strlen(type)+(name!=NULL?strlen(name):2)+68+1)*sizeof(char));
295  if(name!=NULL)
296    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s','%s');",schema->value,uusid->value,filename,type,name);
297  else
298    sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type);
299  execSql(conf,zoo_ds_nb-1,sqlQuery);
300  free(sqlQuery);
301  cleanUpResultSet(conf,zoo_ds_nb-1);
302}
303
304/**
305 * Insert the reference tuple corresponding to the running service
306 *
307 * @param conf the maps containing the setting of the main.cfg file
308 */
309void recordServiceStatus(maps* conf){
310  int zoo_ds_nb=getCurrentId(conf);
311  map *sid=getMapFromMaps(conf,"lenv","sid");
312  map *osid=getMapFromMaps(conf,"lenv","osid");
313  map *uusid=getMapFromMaps(conf,"lenv","usid");
314  map *schema=getMapFromMaps(conf,"database","schema");
315  char *sqlQuery=(char*)malloc((strlen(schema->value)+
316                                strlen(uusid->value)+
317                                strlen(osid->value)+
318                                strlen(sid->value)+
319                                strlen(wpsStatus[2])+66+1)*sizeof(char));
320  sprintf(sqlQuery,
321          "INSERT INTO %s.services (uuid,sid,osid,fstate)"
322          "VALUES ('%s','%s','%s','%s');",
323          schema->value,
324          uusid->value,
325          sid->value,
326          osid->value,
327          wpsStatus[2]);
328  execSql(conf,zoo_ds_nb-1,sqlQuery);
329  free(sqlQuery);
330  cleanUpResultSet(conf,zoo_ds_nb-1);
331}
332
333/**
334 * Store the content of the result file
335 *
336 * @param conf the maps containing the setting of the main.cfg file
337 * @param filename the file's name
338 */
339void recordResponse(maps* conf,char* filename){
340  int zoo_ds_nb=getCurrentId(conf);
341  FILE *file = fopen (filename, "rb");
342  fseek (file, 0, SEEK_END);
343  long flen = ftell (file);
344  fseek (file, 0, SEEK_SET);
345  char *tmps = (char *) malloc ((flen + 1) * sizeof (char));
346  fread (tmps, flen, 1, file);
347  tmps[flen]=0;
348  fclose(file);
349  map *sid=getMapFromMaps(conf,"lenv","usid");
350  map *schema=getMapFromMaps(conf,"database","schema");
351  char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+57+1)*sizeof(char));
352  sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
353  execSql(conf,zoo_ds_nb-1,sqlQuery);
354  free(sqlQuery);
355  free(tmps);
356  cleanUpResultSet(conf,zoo_ds_nb-1);
357}
358
359/**
360 * Update the current status of the running service.
361 *
362 * @param conf the map containing the setting of the main.cfg file
363 * @return 0 on success, -2 if shmget failed, -1 if shmat failed
364 */
365int _updateStatus(maps* conf){
366  int zoo_ds_nb=getCurrentId(conf);
367  map *sid=getMapFromMaps(conf,"lenv","usid");
368  map *p=getMapFromMaps(conf,"lenv","status");
369  map *msg=getMapFromMaps(conf,"lenv","message");
370  map *schema=getMapFromMaps(conf,"database","schema");
371  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char));
372  sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value);
373  if( zoo_ds_nb==
374#ifdef META_DB
375      1
376#else
377      0
378#endif
379      ){
380    init_sql(conf);
381    zoo_ds_nb++;
382  }
383  execSql(conf,zoo_ds_nb-1,sqlQuery);
384  cleanUpResultSet(conf,zoo_ds_nb-1);
385  free(sqlQuery);
386  return 0;
387}
388
389/**
390 * Get the ongoing status of a running service
391 *
392 * @param conf the maps containing the setting of the main.cfg file
393 * @param pid the service identifier (usid key from the [lenv] section)
394 * @return the reported status char* (MESSAGE|POURCENTAGE)
395 */
396char* _getStatus(maps* conf,char* pid){
397  int zoo_ds_nb=getCurrentId(conf);
398  int created=-1;
399  map *schema=getMapFromMaps(conf,"database","schema");
400  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
401  sprintf(sqlQuery,"select status||'|'||message from %s.services where uuid=$$%s$$;",schema->value,pid);
402  if( zoo_ds_nb==
403#ifdef META_DB
404      1
405#else
406      0
407#endif
408      ){
409    init_sql(conf);
410    zoo_ds_nb++;
411    created=1;
412  }
413  execSql(conf,zoo_ds_nb-1,sqlQuery);
414  OGRFeature  *poFeature = NULL;
415  const char *tmp1;
416  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
417    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
418      if( poFeature->IsFieldSet( iField ) ){
419        tmp1=strdup(poFeature->GetFieldAsString( iField ));
420      }
421      else
422        tmp1=NULL;
423    }
424    OGRFeature::DestroyFeature( poFeature );
425  }
426  cleanUpResultSet(conf,zoo_ds_nb-1);
427  free(sqlQuery);
428  return (char*)tmp1;
429}
430
431/**
432 * Read the cache file of a running service
433 *
434 * @param conf the maps containing the setting of the main.cfg file
435 * @param pid the service identifier (usid key from the [lenv] section)
436 * @return the reported status char* (temporary/final result)
437 */
438char* _getStatusFile(maps* conf,char* pid){
439  int zoo_ds_nb=getCurrentId(conf);
440  map *schema=getMapFromMaps(conf,"database","schema");
441  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char));
442  sprintf(sqlQuery,
443          "select content from %s.responses where uuid=$$%s$$"
444          " order by creation_time desc limit 1",schema->value,pid);
445  if( zoo_ds_nb==
446#ifdef META_DB
447      1
448#else
449      0
450#endif
451      ){
452    init_sql(conf);
453    zoo_ds_nb++;
454  }
455  execSql(conf,zoo_ds_nb-1,sqlQuery);
456  OGRFeature  *poFeature = NULL;
457  const char *tmp1;
458  int hasRes=-1;
459  if(zoo_ResultSet!=NULL){
460      while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
461        for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
462          if( poFeature->IsFieldSet( iField ) ){
463            tmp1=strdup(poFeature->GetFieldAsString( iField ));
464            hasRes=1;
465          }
466          else
467            tmp1=NULL;
468        }
469        OGRFeature::DestroyFeature( poFeature );
470      }
471  }
472  if(hasRes<0)
473    tmp1=NULL;
474  else
475    cleanUpResultSet(conf,zoo_ds_nb-1);
476  free(sqlQuery);
477  return (char*)tmp1;
478}
479
480/**
481 * Delete a service reference from the database.
482 *
483 * @param conf the map containing the setting of the main.cfg file
484 * @param pid the service identifier (usid key from the [lenv] section)
485 */
486void removeService(maps* conf,char* pid){
487  int zoo_ds_nb=getCurrentId(conf);
488  map *schema=getMapFromMaps(conf,"database","schema");
489  char *sqlQuery=(char*)
490    malloc((strlen(pid)+strlen(schema->value)+38+1)
491           *sizeof(char));
492  if( zoo_ds_nb==
493#ifdef META_DB
494      1
495#else
496      0
497#endif
498      ){
499    init_sql(conf);
500    zoo_ds_nb++;
501  }
502  sprintf(sqlQuery,
503          "DELETE FROM %s.services where uuid=$$%s$$;",
504          schema->value,pid);
505  execSql(conf,zoo_ds_nb-1,sqlQuery);
506  cleanUpResultSet(conf,zoo_ds_nb-1);
507  close_sql(conf,zoo_ds_nb-1);
508  free(sqlQuery);
509  end_sql();
510}
511
512/**
513 * Stop handling status repport.
514 *
515 * @param conf the map containing the setting of the main.cfg file
516 */
517void unhandleStatus(maps* conf){
518  int zoo_ds_nb=getCurrentId(conf);
519  map *schema=getMapFromMaps(conf,"database","schema");
520  map *sid=getMapFromMaps(conf,"lenv","usid");
521  map *fstate=getMapFromMaps(conf,"lenv","fstate");
522  char *sqlQuery=(char*)malloc((strlen(sid->value)+
523                                strlen(schema->value)+
524                                (fstate!=NULL?
525                                 strlen(fstate->value):
526                                 6)
527                                +66+1)*sizeof(char));
528  sprintf(sqlQuery,
529          "UPDATE %s.services set end_time=now(), fstate=$$%s$$"
530          " where uuid=$$%s$$;",
531          schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value);
532  execSql(conf,zoo_ds_nb-1,sqlQuery);
533  cleanUpResultSet(conf,zoo_ds_nb-1);
534  close_sql(conf,zoo_ds_nb-1);
535  free(sqlQuery);
536  end_sql();
537}
538
539/**
540 * Read the sid identifier attached of a service if any
541 *
542 * @param conf the maps containing the setting of the main.cfg file
543 * @param pid the service identifier (usid key from the [lenv] section)
544 * @return the sid value
545 */
546char* getStatusId(maps* conf,char* pid){
547  int zoo_ds_nb=getCurrentId(conf);
548  map *schema=getMapFromMaps(conf,"database","schema");
549  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
550  sprintf(sqlQuery,
551          "select osid from %s.services where uuid=$$%s$$",
552          schema->value,pid);
553  if( zoo_ds_nb==0 ){
554    init_sql(conf);
555    zoo_ds_nb++;
556  }
557  execSql(conf,zoo_ds_nb-1,sqlQuery);
558  OGRFeature  *poFeature = NULL;
559  const char *tmp1;
560  int hasRes=-1;
561  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
562    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
563      if( poFeature->IsFieldSet( iField ) ){
564        tmp1=zStrdup(poFeature->GetFieldAsString( iField ));
565        hasRes=1;
566        break;
567      }
568    }
569    OGRFeature::DestroyFeature( poFeature );
570  }
571  if(hasRes<0)
572    tmp1=NULL;
573  free(sqlQuery);
574  cleanUpResultSet(conf,zoo_ds_nb-1);
575  return (char*)tmp1;
576}
577
578/**
579 * Read the Result file (.res).
580 *
581 * @param conf the maps containing the setting of the main.cfg file
582 * @param pid the service identifier (usid key from the [lenv] section)
583 */
584void readFinalRes(maps* conf,char* pid,map* statusInfo){
585  int zoo_ds_nb=getCurrentId(conf);
586  map *schema=getMapFromMaps(conf,"database","schema");
587  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
588  sprintf(sqlQuery,
589          "select fstate from %s.services where uuid=$$%s$$",
590          schema->value,pid);
591  if( zoo_DS == NULL )
592    init_sql(conf);
593  execSql(conf,zoo_ds_nb-1,sqlQuery);
594  OGRFeature  *poFeature = NULL;
595  int hasRes=-1;
596  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
597    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
598      if( poFeature->IsFieldSet( iField ) ){
599        addToMap(statusInfo,"Status",poFeature->GetFieldAsString( iField ));
600        hasRes=1;
601        break;
602      }
603    }
604    OGRFeature::DestroyFeature( poFeature );
605  }
606  if(hasRes<0)
607    addToMap(statusInfo,"Status","Failed");
608  free(sqlQuery);
609  return;
610}
611
612/**
613 * Check if a service is running.
614 *
615 * @param conf the maps containing the setting of the main.cfg file
616 * @param pid the unique service identifier (usid from the lenv section)
617 * @return 1 in case the service is still running, 0 otherwise
618 */
619int isRunning(maps* conf,char* pid){
620  int res=0;
621  int zoo_ds_nb=getCurrentId(conf);
622  map *schema=getMapFromMaps(conf,"database","schema");
623  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char));
624  sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid);
625  if( zoo_ds_nb == 0 ){
626    init_sql(conf);
627    zoo_ds_nb++;
628  }
629  execSql(conf,zoo_ds_nb-1,sqlQuery);
630  OGRFeature  *poFeature = NULL;
631  const char *tmp1;
632  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
633    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
634      if( poFeature->IsFieldSet( iField ) && 
635          atoi(poFeature->GetFieldAsString( iField ))>0 ){
636        res=1;
637        break;
638      }
639    }
640    OGRFeature::DestroyFeature( poFeature );
641  }
642  cleanUpResultSet(conf,zoo_ds_nb-1);
643  free(sqlQuery);
644  return res;
645}
646
647#endif
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png