Changeset 16277 for trunk/ippTools/src/pstamptool.c
- Timestamp:
- Feb 1, 2008, 2:40:03 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pstamptool.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pstamptool.c
r16134 r16277 36 36 static bool pendingReqMode(pxConfig *config); 37 37 static bool processedReqMode(pxConfig *config); 38 #ifdef notyet39 38 static bool addJobMode(pxConfig *config); 39 static bool listJobMode(pxConfig *config); 40 40 static bool pendingJobMode(pxConfig *config); 41 42 static bool copydoneMode(pxConfig *config); 43 44 static bool copydoneCompleteExp(pxConfig *config); 45 static psArray *pzGetPendingCameras(pxConfig *config); 46 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); 47 #endif // notyet 41 static bool processedJobMode(pxConfig *config); 48 42 49 43 # define MODECASE(caseName, func) \ … … 71 65 MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode); 72 66 MODECASE(PSTAMPTOOL_MODE_PROCESSEDREQ, processedReqMode); 67 MODECASE(PSTAMPTOOL_MODE_ADDJOB, addJobMode); 68 MODECASE(PSTAMPTOOL_MODE_LISTJOB, listJobMode); 69 MODECASE(PSTAMPTOOL_MODE_PENDINGJOB, pendingJobMode); 70 MODECASE(PSTAMPTOOL_MODE_PROCESSEDJOB, processedJobMode); 73 71 default: 74 72 psAbort("invalid option (this should not happen)"); … … 206 204 } 207 205 208 char *query ="INSERT INTO ps Request"206 char *query ="INSERT INTO pstampRequest" 209 207 " (state, uri)" 210 208 " VALUES( 'new', '%s')"; … … 224 222 } 225 223 224 psS64 req_id = psDBLastInsertID(config->dbh); 225 printf("%ld\n", req_id); 226 226 227 return true; 227 228 } … … 241 242 "SELECT" 242 243 " *" 243 " FROM ps Request"244 " FROM pstampRequest" 244 245 " WHERE state = 'new'" 245 246 ); 246 247 247 248 if (config->where) { 248 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "ps Request");249 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampRequest"); 249 250 psStringAppend(&query, " AND %s", whereClause); 250 251 psFree(whereClause); … … 288 289 289 290 // negative simple so the default is true 290 if (!ippdbPrintMetadatas(stdout, output, "p zPendingExp", !simple)) {291 if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) { 291 292 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 292 293 psFree(output); … … 298 299 return true; 299 300 } 301 300 302 static bool processedReqMode(pxConfig *config) 301 303 { … … 325 327 // XXX: check state for a legal value 326 328 327 char *query ="UPDATE ps Request"329 char *query ="UPDATE pstampRequest" 328 330 " SET state = '%s'" 329 331 " WHERE req_id = '%s'"; … … 337 339 psU64 affected = psDBAffectedRows(config->dbh); 338 340 if (affected != 1) { 339 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" PRIu64 " rows were modified", 341 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 342 PRIu64 " rows were modified", affected); 343 return false; 344 } 345 346 return true; 347 } 348 static bool addJobMode(pxConfig *config) 349 { 350 bool status; 351 352 PS_ASSERT_PTR_NON_NULL(config, false); 353 354 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 355 if (!status) { 356 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri"); 357 return false; 358 } 359 if (!uri) { 360 psError(PS_ERR_UNKNOWN, true, "-uri is required"); 361 return false; 362 } 363 364 psString req_id = psMetadataLookupStr(&status, config->args, "-req_id"); 365 if (!status) { 366 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -req_id"); 367 return false; 368 } 369 if (!req_id) { 370 psError(PS_ERR_UNKNOWN, true, "-req_id is required"); 371 return false; 372 } 373 374 psString outputBase = psMetadataLookupStr(&status, config->args, "-outputBase"); 375 if (!status) { 376 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -outputBase"); 377 return false; 378 } 379 if (!outputBase) { 380 psError(PS_ERR_UNKNOWN, true, "-outputBase is required"); 381 return false; 382 } 383 384 psString argString = psMetadataLookupStr(&status, config->args, "-args"); 385 if (!status) { 386 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -args"); 387 return false; 388 } 389 if (!argString) { 390 psError(PS_ERR_UNKNOWN, true, "-args is required"); 391 return false; 392 } 393 394 char *query ="INSERT INTO pstampJob" 395 " (req_id, state, uri, outputBase, args)" 396 " VALUES( %s, 'new', '%s', '%s', '%s')"; 397 398 if (!p_psDBRunQuery(config->dbh, query, req_id, uri, outputBase, argString)) { 399 psError(PS_ERR_UNKNOWN, false, "database error"); 400 psFree(query); 401 return false; 402 } 403 404 psU64 affected = psDBAffectedRows(config->dbh); 405 if (affected != 1) { 406 psError(PS_ERR_UNKNOWN, false, 407 "should have affected one row but %" PRIu64 " rows were modified", 340 408 affected); 341 409 return false; 342 410 } 343 411 344 return true; 345 } 412 psS64 job_id = psDBLastInsertID(config->dbh); 413 printf("%ld\n", job_id); 414 415 return true; 416 } 417 418 static bool listJobMode(pxConfig *config) 419 { 420 PS_ASSERT_PTR_NON_NULL(config, false); 421 422 bool status = false; 423 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 424 if (!status) { 425 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 426 return false; 427 } 428 429 psString query = NULL; 430 431 psString req_id = psMetadataLookupStr(&status, config->args, "-req_id"); 432 psString job_id = psMetadataLookupStr(&status, config->args, "-job_id"); 433 434 if (req_id) { 435 psStringAppend(&query, 436 "SELECT" 437 " *" 438 " FROM pstampJob" 439 " WHERE req_id = %s", req_id 440 ); 441 } else if (job_id) { 442 psStringAppend(&query, 443 "SELECT" 444 " *" 445 " FROM pstampJob" 446 " WHERE job_id = %s", job_id 447 ); 448 } else { 449 fprintf(stderr, "either req_id or job_id must be specified\n"); 450 exit (1); 451 } 452 453 // treat limit == 0 as "no limit" 454 if (limit) { 455 psString limitString = psDBGenerateLimitSQL(limit); 456 psStringAppend(&query, " %s", limitString); 457 psFree(limitString); 458 } 459 460 if (!p_psDBRunQuery(config->dbh, query)) { 461 psError(PS_ERR_UNKNOWN, false, "database error"); 462 psFree(query); 463 return false; 464 } 465 psFree(query); 466 467 psArray *output = p_psDBFetchResult(config->dbh); 468 if (!output) { 469 psError(PS_ERR_UNKNOWN, false, "database error"); 470 return false; 471 } 472 if (!psArrayLength(output)) { 473 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 474 psFree(output); 475 return true; 476 } 477 478 bool simple = false; 479 { 480 bool status = false; 481 simple = psMetadataLookupBool(&status, config->args, "-simple"); 482 if (!status) { 483 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 484 psFree(output); 485 return false; 486 } 487 } 488 489 // negative simple so the default is true 490 if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) { 491 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 492 psFree(output); 493 return false; 494 } 495 496 psFree(output); 497 498 return true; 499 } 500 501 static bool pendingJobMode(pxConfig *config) 502 { 503 PS_ASSERT_PTR_NON_NULL(config, false); 504 505 bool status = false; 506 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 507 if (!status) { 508 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 509 return false; 510 } 511 512 psString query = psStringCopy( 513 "SELECT" 514 " *" 515 " FROM pstampJob" 516 " WHERE state = 'new'" 517 ); 518 519 if (config->where) { 520 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "pstampJob"); 521 psStringAppend(&query, " AND %s", whereClause); 522 psFree(whereClause); 523 } 524 525 // treat limit == 0 as "no limit" 526 if (limit) { 527 psString limitString = psDBGenerateLimitSQL(limit); 528 psStringAppend(&query, " %s", limitString); 529 psFree(limitString); 530 } 531 532 if (!p_psDBRunQuery(config->dbh, query)) { 533 psError(PS_ERR_UNKNOWN, false, "database error"); 534 psFree(query); 535 return false; 536 } 537 psFree(query); 538 539 psArray *output = p_psDBFetchResult(config->dbh); 540 if (!output) { 541 psError(PS_ERR_UNKNOWN, false, "database error"); 542 return false; 543 } 544 if (!psArrayLength(output)) { 545 psTrace("pstamptool", PS_LOG_INFO, "no rows found"); 546 psFree(output); 547 return true; 548 } 549 550 bool simple = false; 551 { 552 bool status = false; 553 simple = psMetadataLookupBool(&status, config->args, "-simple"); 554 if (!status) { 555 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 556 psFree(output); 557 return false; 558 } 559 } 560 561 // negative simple so the default is true 562 if (!ippdbPrintMetadatas(stdout, output, "pstampJob", !simple)) { 563 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 564 psFree(output); 565 return false; 566 } 567 568 psFree(output); 569 570 return true; 571 } 572 573 static bool processedJobMode(pxConfig *config) 574 { 575 bool status; 576 577 PS_ASSERT_PTR_NON_NULL(config, false); 578 579 psString job_id = psMetadataLookupStr(&status, config->args, "-job_id"); 580 if (!status) { 581 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -job_id"); 582 return false; 583 } 584 if (!job_id) { 585 psError(PS_ERR_UNKNOWN, true, "-job_id is required"); 586 return false; 587 } 588 psString state = psMetadataLookupStr(&status, config->args, "-state"); 589 if (!status) { 590 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -state"); 591 return false; 592 } 593 if (!state) { 594 psError(PS_ERR_UNKNOWN, true, "-state is required"); 595 return false; 596 } 597 psString jobStatus = psMetadataLookupStr(&status, config->args, "-status"); 598 if (!status) { 599 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -status"); 600 return false; 601 } 602 603 psString statusStr = NULL; 604 if (!jobStatus) { 605 statusStr = psStringCopy(""); 606 } else { 607 psStringAppend(&statusStr, ", status = '%s'", jobStatus); 608 } 609 610 611 // XXX: check state for a legal value 612 613 char *query ="UPDATE pstampJob" 614 " SET state = '%s' %s" 615 " WHERE job_id = '%s'"; 616 617 if (!p_psDBRunQuery(config->dbh, query, state, statusStr, job_id)) { 618 psError(PS_ERR_UNKNOWN, false, "database error"); 619 psFree(query); 620 return false; 621 } 622 psFree(statusStr); 623 624 psU64 affected = psDBAffectedRows(config->dbh); 625 if (affected != 1) { 626 psError(PS_ERR_UNKNOWN, false, "should have affected one row but %" 627 PRIu64 " rows were modified", affected); 628 return false; 629 } 630 631 return true; 632 }
Note:
See TracChangeset
for help on using the changeset viewer.
