Changeset 854 for branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
- Timestamp:
- Nov 21, 2017, 10:24:14 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
r851 r854 70 70 int i=0; 71 71 maps* cconf=getMaps(conf,key); 72 if(cconf==NULL) 72 if(cconf==NULL){ 73 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 73 74 return "-1"; 75 } 74 76 int len=0; 75 77 for(i=0;i<6;i++){ … … 119 121 int _init_sql(maps* conf,const char* key){ 120 122 char* sqlInitString=_createInitString(conf,key); 123 fprintf(stderr,"Try to connect to: %s %s !\n",key,sqlInitString); 124 fflush(stderr); 121 125 if(strncmp(sqlInitString,"-1",2)==0) 122 126 return -1; 127 fprintf(stderr,"Try to connect to: %s !\n",key); 128 fflush(stderr); 123 129 OGRSFDriver *poDriver = NULL; 124 130 OGRRegisterAll(); … … 195 201 */ 196 202 void close_sql(maps* conf,int cid){ 197 if( zoo_ResultSet != NULL ) 203 if( zoo_ResultSet != NULL ){ 198 204 zoo_DS[cid]->ReleaseResultSet( zoo_ResultSet ); 199 if(zoo_DS!=NULL){ 205 zoo_ResultSet=NULL; 206 } 207 if(zoo_DS!=NULL && zoo_DS[cid]!=NULL){ 200 208 #if GDAL_VERSION_MAJOR >= 2 201 209 GDALClose(zoo_DS[cid]); … … 223 231 */ 224 232 OGRLayer *fetchSql(maps* conf,int cid,const char* sqlQuery){ 225 if(zoo_DS [cid]==NULL)233 if(zoo_DS==NULL || zoo_DS[cid]==NULL) 226 234 return NULL; 227 235 OGRLayer *res=NULL; … … 250 258 int execSql(maps* conf,int cid,const char* sqlQuery){ 251 259 int res=-1; 260 if(zoo_DS == NULL || zoo_DS[cid]==NULL) 261 return -1; 252 262 zoo_ResultSet = zoo_DS[cid]->ExecuteSQL( sqlQuery, NULL, NULL); 253 263 if( zoo_ResultSet != NULL ){ … … 371 381 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char)); 372 382 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 ){ 383 if(zoo_ds_nb==0){ 380 384 init_sql(conf); 381 385 zoo_ds_nb++; 382 386 } 383 execSql(conf,zoo_ds_nb-1,sqlQuery); 384 cleanUpResultSet(conf,zoo_ds_nb-1); 385 free(sqlQuery); 387 execSql(conf,0,sqlQuery); 388 cleanUpResultSet(conf,0); 389 close_sql(conf,0); 390 free(sqlQuery); 391 setMapInMaps(conf,"lenv","ds_nb","0"); 386 392 return 0; 387 393 } … … 439 445 int zoo_ds_nb=getCurrentId(conf); 440 446 map *schema=getMapFromMaps(conf,"database","schema"); 447 OGRFeature *poFeature = NULL; 448 const char *tmp1=NULL; 449 int hasRes=-1; 441 450 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char)); 442 451 sprintf(sqlQuery, … … 454 463 } 455 464 execSql(conf,zoo_ds_nb-1,sqlQuery); 456 OGRFeature *poFeature = NULL;457 const char *tmp1;458 int hasRes=-1;459 465 if(zoo_ResultSet!=NULL){ 460 466 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ … … 472 478 if(hasRes<0) 473 479 tmp1=NULL; 474 else 475 cleanUpResultSet(conf,zoo_ds_nb-1); 480 cleanUpResultSet(conf,zoo_ds_nb-1); 476 481 free(sqlQuery); 477 482 return (char*)tmp1; … … 534 539 //close_sql(conf,zoo_ds_nb-1); 535 540 free(sqlQuery); 536 end_sql();541 //end_sql(); 537 542 } 538 543 … … 555 560 zoo_ds_nb++; 556 561 } 557 execSql(conf,zoo_ds_nb-1,sqlQuery); 562 if(execSql(conf,zoo_ds_nb-1,sqlQuery)<0) 563 return NULL; 558 564 OGRFeature *poFeature = NULL; 559 565 const char *tmp1;
Note: See TracChangeset
for help on using the changeset viewer.