Changeset 822 for branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
- Timestamp:
- May 3, 2017, 12:53:06 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
r786 r822 1 1 /* 2 * Author : David Saggiorato3 * Gérald Fenoy2 * Authors : David Saggiorato 3 * Gérald Fenoy 4 4 * Copyright 2015 GeoLabs SARL. All rights reserved. 5 5 * … … 23 23 */ 24 24 25 #ifdef RELY_ON_DB26 25 #include "ogr_api.h" 27 26 #include "ogrsf_frmts.h" … … 52 51 53 52 /** 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 */ 60 char* _createInitString(maps* conf,const char* key){ 60 61 char* res=NULL; 61 char keywords[ 5][9]={62 char keywords[6][14]={ 62 63 "dbname", 63 64 "host", 64 65 "port", 65 66 "user", 66 "password" 67 "password", 68 "active_schema" 67 69 }; 68 70 int i=0; 69 maps* cconf=getMaps(conf, "database");71 maps* cconf=getMaps(conf,key); 70 72 int len=0; 71 for(i=0;i< 5;i++){73 for(i=0;i<6;i++){ 72 74 map* tmp=getMap(cconf->content,keywords[i]); 75 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 76 fflush(stderr); 73 77 if(tmp!=NULL){ 78 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 79 fflush(stderr); 74 80 if(res==NULL){ 75 81 res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char)); … … 83 89 len+=strlen(res1); 84 90 res[len]=0; 91 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 92 fflush(stderr); 85 93 free(res1); 86 94 } 87 95 } 88 } 96 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 97 fflush(stderr); 98 } 99 fprintf(stderr,"%s %d \n",__FILE__,__LINE__); 100 fflush(stderr); 89 101 map* tmp=getMap(cconf->content,"type"); 90 102 if(tmp!=NULL){ … … 98 110 99 111 /** 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 */ 117 char* createInitString(maps* conf){ 118 return _createInitString(conf,"database"); 119 } 120 121 /** 122 * Connect to a db backend. 101 123 * 102 124 * @param conf the maps containing the setting of the main.cfg file 103 125 * @see createInitString 104 126 */ 105 void init_sql(maps* conf){106 char* sqlInitString= createInitString(conf);127 void _init_sql(maps* conf,const char* key){ 128 char* sqlInitString=_createInitString(conf,key); 107 129 OGRSFDriver *poDriver = NULL; 108 130 OGRRegisterAll(); … … 129 151 #endif 130 152 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 */ 161 void init_sql(maps* conf){ 162 return _init_sql(conf,"database"); 131 163 } 132 164 … … 158 190 159 191 /** 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 */ 198 OGRLayer *fetchSql(maps* conf,const char* sqlQuery){ 199 OGRLayer *res=NULL; 200 res = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL); 201 return res; 202 } 203 204 void cleanFetchSql(maps* conf,OGRLayer *objects){ 205 if( objects != NULL ){ 206 zoo_DS->ReleaseResultSet( objects ); 207 objects=NULL; 208 } 209 } 210 211 /** 160 212 * Execute a SQL query to the SQL Database Backend. 161 213 * … … 165 217 */ 166 218 int execSql(maps* conf,const char* sqlQuery){ 219 int res=-1; 167 220 zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL); 168 221 if( zoo_ResultSet != NULL ){ 169 return 1; 170 } 171 return -1; 222 res=1; 223 } 224 zoo_DS->ReleaseResultSet( zoo_ResultSet ); 225 return res; 172 226 } 173 227 … … 260 314 } 261 315 316 #ifdef RELY_ON_DB 262 317 /** 263 318 * Update the current status of the running service.
Note: See TracChangeset
for help on using the changeset viewer.