Changeset 654 for trunk/zoo-project/zoo-kernel/sqlapi.c
- Timestamp:
- Jun 15, 2015, 1:47:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/sqlapi.c
r652 r654 227 227 map *schema=getMapFromMaps(conf,"database","schema"); 228 228 char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+51+1)*sizeof(char)); 229 sprintf(sqlQuery," UPDATE %s.services set response=$$%s$$ where uuid=$$%s$$;",schema->value,tmps,sid->value);229 sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value); 230 230 execSql(conf,sqlQuery); 231 231 cleanUpResultSet(conf); … … 292 292 char* _getStatusFile(maps* conf,char* pid){ 293 293 map *schema=getMapFromMaps(conf,"database","schema"); 294 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 295 sprintf(sqlQuery,"select response from %s.services where uuid=$$%s$$;",schema->value,pid); 294 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char)); 295 sprintf(sqlQuery, 296 "select content from %s.responses where uuid=$$%s$$" 297 " order by creation_time desc limit 1",schema->value,pid); 296 298 if( zoo_DS == NULL ) 297 299 init_sql(conf); … … 318 320 319 321 /** 320 * Stop handling status repport.322 * Delete a service reference from the database. 321 323 * 322 324 * @param conf the map containing the setting of the main.cfg file 323 */ 324 void unhandleStatus(maps* conf){ 325 map *sid=getMapFromMaps(conf,"lenv","usid"); 326 char *sqlQuery=(char*)malloc((strlen(sid->value)+52+1)*sizeof(char)); 327 sprintf(sqlQuery,"UPDATE services set end_time=now() where uuid=$$%s$$;",sid->value); 325 * @param pid the service identifier (usid key from the [lenv] section) 326 */ 327 void removeService(maps* conf,char* pid){ 328 map *schema=getMapFromMaps(conf,"database","schema"); 329 char *sqlQuery=(char*) 330 malloc((strlen(pid)+strlen(schema->value)+38+1) 331 *sizeof(char)); 332 if( zoo_DS == NULL ) 333 init_sql(conf); 334 sprintf(sqlQuery, 335 "DELETE FROM %s.services where uuid=$$%s$$;", 336 schema->value,pid); 328 337 execSql(conf,sqlQuery); 329 338 cleanUpResultSet(conf); … … 332 341 } 333 342 343 /** 344 * Stop handling status repport. 345 * 346 * @param conf the map containing the setting of the main.cfg file 347 */ 348 void unhandleStatus(maps* conf){ 349 map *schema=getMapFromMaps(conf,"database","schema"); 350 map *sid=getMapFromMaps(conf,"lenv","usid"); 351 map *fstate=getMapFromMaps(conf,"lenv","fstate"); 352 char *sqlQuery=(char*)malloc((strlen(sid->value)+ 353 strlen(schema->value)+ 354 (fstate!=NULL? 355 strlen(fstate->value): 356 6) 357 +66+1)*sizeof(char)); 358 sprintf(sqlQuery, 359 "UPDATE %s.services set end_time=now(), fstate=$$%s$$" 360 " where uuid=$$%s$$;", 361 schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value); 362 execSql(conf,sqlQuery); 363 cleanUpResultSet(conf); 364 close_sql(conf); 365 end_sql(); 366 } 367 368 /** 369 * Read the sid identifier attached of a service if any 370 * 371 * @param conf the maps containing the setting of the main.cfg file 372 * @param pid the service identifier (usid key from the [lenv] section) 373 * @return the sid value 374 */ 375 char* getStatusId(maps* conf,char* pid){ 376 map *schema=getMapFromMaps(conf,"database","schema"); 377 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 378 sprintf(sqlQuery, 379 "select osid from %s.services where uuid=$$%s$$", 380 schema->value,pid); 381 if( zoo_DS == NULL ) 382 init_sql(conf); 383 execSql(conf,sqlQuery); 384 OGRFeature *poFeature = NULL; 385 const char *tmp1; 386 int hasRes=-1; 387 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 388 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 389 if( poFeature->IsFieldSet( iField ) ){ 390 tmp1=zStrdup(poFeature->GetFieldAsString( iField )); 391 hasRes=1; 392 break; 393 } 394 } 395 OGRFeature::DestroyFeature( poFeature ); 396 } 397 if(hasRes<0) 398 tmp1=NULL; 399 return (char*)tmp1; 400 } 401 402 /** 403 * Read the Result file (.res). 404 * 405 * @param conf the maps containing the setting of the main.cfg file 406 * @param pid the service identifier (usid key from the [lenv] section) 407 */ 408 void readFinalRes(maps* conf,char* pid,map* statusInfo){ 409 map *schema=getMapFromMaps(conf,"database","schema"); 410 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char)); 411 sprintf(sqlQuery, 412 "select fstate from %s.services where uuid=$$%s$$", 413 schema->value,pid); 414 if( zoo_DS == NULL ) 415 init_sql(conf); 416 execSql(conf,sqlQuery); 417 OGRFeature *poFeature = NULL; 418 int hasRes=-1; 419 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 420 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 421 if( poFeature->IsFieldSet( iField ) ){ 422 addToMap(statusInfo,"Status",poFeature->GetFieldAsString( iField )); 423 hasRes=1; 424 break; 425 } 426 } 427 OGRFeature::DestroyFeature( poFeature ); 428 } 429 if(hasRes<0) 430 addToMap(statusInfo,"Status","Failed"); 431 return; 432 } 433 434 /** 435 * Check if a service is running. 436 * 437 * @param conf the maps containing the setting of the main.cfg file 438 * @param pid the unique service identifier (usid from the lenv section) 439 * @return 1 in case the service is still running, 0 otherwise 440 */ 441 int isRunning(maps* conf,char* pid){ 442 int res=0; 443 map *schema=getMapFromMaps(conf,"database","schema"); 444 char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char)); 445 sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid); 446 if( zoo_DS == NULL ) 447 init_sql(conf); 448 execSql(conf,sqlQuery); 449 OGRFeature *poFeature = NULL; 450 const char *tmp1; 451 while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){ 452 for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){ 453 if( poFeature->IsFieldSet( iField ) && 454 atoi(poFeature->GetFieldAsString( iField ))>0 ){ 455 res=1; 456 break; 457 } 458 } 459 OGRFeature::DestroyFeature( poFeature ); 460 } 461 cleanUpResultSet(conf); 462 return res; 463 } 464 334 465 #endif
Note: See TracChangeset
for help on using the changeset viewer.