Ignore:
Timestamp:
May 3, 2017, 12:53:06 PM (7 years ago)
Author:
djay
Message:

Commit the minimal requirements for remote HPC support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c

    r786 r822  
    11/*
    2  * Author : David Saggiorato
    3  *          Gérald Fenoy
     2 * Authors : David Saggiorato
     3 *           Gérald Fenoy
    44 *  Copyright 2015 GeoLabs SARL. All rights reserved.
    55 *
     
    2323 */
    2424
    25 #ifdef RELY_ON_DB
    2625#include "ogr_api.h"
    2726#include "ogrsf_frmts.h"
     
    5251
    5352/**
    54  * Create a GDAL / OGR string for connecting to the db backend
    55  * (do not support active_schema)
    56  *
    57  * @param conf the maps containing the setting of the main.cfg file
    58  */
    59 char* createInitString(maps* conf){
     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){
    6061  char* res=NULL;
    61   char keywords[5][9]={
     62  char keywords[6][14]={
    6263    "dbname",
    6364    "host",
    6465    "port",
    6566    "user",
    66     "password"
     67    "password",
     68    "active_schema"   
    6769  };
    6870  int i=0;
    69   maps* cconf=getMaps(conf,"database");
     71  maps* cconf=getMaps(conf,key);
    7072  int len=0;
    71   for(i=0;i<5;i++){
     73  for(i=0;i<6;i++){
    7274    map* tmp=getMap(cconf->content,keywords[i]);
     75    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     76    fflush(stderr);
    7377    if(tmp!=NULL){
     78      fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     79      fflush(stderr);
    7480      if(res==NULL){
    7581        res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char));
     
    8389        len+=strlen(res1);
    8490        res[len]=0;
     91        fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     92        fflush(stderr);
    8593        free(res1);
    8694      }
    8795    }
    88   }
     96    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     97    fflush(stderr);
     98  }
     99  fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
     100  fflush(stderr);
    89101  map* tmp=getMap(cconf->content,"type");
    90102  if(tmp!=NULL){
     
    98110
    99111/**
    100  * Connect to the db backend.
     112 * Create a GDAL / OGR string for connecting to the db backend
     113 *
     114 * @param conf the maps containing the setting of the main.cfg file
     115 * @return the OGR connection string
     116 */
     117char* createInitString(maps* conf){
     118  return _createInitString(conf,"database");
     119}
     120
     121/**
     122 * Connect to a db backend.
    101123 *
    102124 * @param conf the maps containing the setting of the main.cfg file
    103125 * @see createInitString
    104126 */
    105 void init_sql(maps* conf){
    106   char* sqlInitString=createInitString(conf);
     127void _init_sql(maps* conf,const char* key){
     128  char* sqlInitString=_createInitString(conf,key);
    107129  OGRSFDriver *poDriver = NULL;
    108130  OGRRegisterAll();
     
    129151#endif
    130152  free(sqlInitString);
     153}
     154
     155/**
     156 * Connect to the db backend.
     157 *
     158 * @param conf the maps containing the setting of the main.cfg file
     159 * @see createInitString
     160 */
     161void init_sql(maps* conf){
     162  return _init_sql(conf,"database");
    131163}
    132164
     
    158190
    159191/**
     192 * Fetch a tuple set by executing a SQL query to the Database Backend.
     193 *
     194 * @param conf the maps containing the setting of the main.cfg file
     195 * @param sqlQuery the SQL query to run
     196 * @return NULL in case of failure or an OGRLayer pointer if the query succeed.
     197 */
     198OGRLayer *fetchSql(maps* conf,const char* sqlQuery){
     199  OGRLayer *res=NULL;
     200  res = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
     201  return res;
     202}
     203
     204void cleanFetchSql(maps* conf,OGRLayer *objects){
     205  if( objects != NULL ){
     206    zoo_DS->ReleaseResultSet( objects );
     207    objects=NULL;
     208  }
     209}
     210
     211/**
    160212 * Execute a SQL query to the SQL Database Backend.
    161213 *
     
    165217 */
    166218int execSql(maps* conf,const char* sqlQuery){
     219  int res=-1;
    167220  zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
    168221  if( zoo_ResultSet != NULL ){
    169     return 1;
    170   }
    171   return -1;
     222    res=1;
     223  }
     224  zoo_DS->ReleaseResultSet( zoo_ResultSet );
     225  return res;
    172226}
    173227
     
    260314}
    261315
     316#ifdef RELY_ON_DB
    262317/**
    263318 * Update the current status of the running service.
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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