/ MakeWQL: make the WQL statement use with WMI ExecQuery. */ /
| 501 | /* MakeWQL: make the WQL statement use with WMI ExecQuery. */ |
| 502 | /***********************************************************************/ |
| 503 | char *TDBWMI::MakeWQL(PGLOBAL g) |
| 504 | { |
| 505 | char *colist, *wql/*, *pw = NULL*/; |
| 506 | int len, ncol = 0; |
| 507 | bool first = true, noloc = false; |
| 508 | PCOL colp; |
| 509 | |
| 510 | // Normal WQL statement to retrieve results |
| 511 | for (colp = Columns; colp; colp = colp->GetNext()) |
| 512 | if (!colp->IsSpecial() && (colp->GetColUse(U_P | U_J_EXT) || noloc)) |
| 513 | ncol++; |
| 514 | |
| 515 | if (ncol) { |
| 516 | size_t colist_sz = (NAM_LEN + 4) * ncol; |
| 517 | colist = (char*)PlugSubAlloc(g, NULL, colist_sz); |
| 518 | |
| 519 | for (colp = Columns; colp; colp = colp->GetNext()) |
| 520 | if (!colp->IsSpecial()) { |
| 521 | if (colp->GetResultType() == TYPE_DATE) |
| 522 | ((DTVAL*)colp->GetValue())->SetFormat(g, "YYYYMMDDhhmmss", 19); |
| 523 | |
| 524 | if (colp->GetColUse(U_P | U_J_EXT) || noloc) { |
| 525 | if (first) { |
| 526 | snprintf(colist, colist_sz, colp->GetName()); |
| 527 | first = false; |
| 528 | } else { |
| 529 | strcat(strcat(colist, ", "), colp->GetName()); |
| 530 | safe_strcat(colist, colist_sz, ", "); |
| 531 | safe_strcat(colist, colist_sz, colp->GetName()); |
| 532 | } |
| 533 | |
| 534 | } // endif ColUse |
| 535 | |
| 536 | } // endif Special |
| 537 | |
| 538 | } else { |
| 539 | // ncol == 0 can occur for queries such that sql count(*) from... |
| 540 | // for which we will count the rows from sql * from... |
| 541 | colist = (char*)PlugSubAlloc(g, NULL, 2); |
| 542 | snprintf(colist, 2, "*"); |
| 543 | } // endif ncol |
| 544 | |
| 545 | // Below 14 is length of 'select ' + length of ' from ' + 1 |
| 546 | len = (strlen(colist) + strlen(Wclass) + 14); |
| 547 | len += (To_CondFil ? strlen(To_CondFil->Body) + 7 : 0); |
| 548 | wql = (char*)PlugSubAlloc(g, NULL, len); |
| 549 | snprintf(wql, len, "SELECT %s FROM %s", colist, Wclass); |
| 550 | |
| 551 | if (To_CondFil) { |
| 552 | safe_strcat(wql, len, " WHERE "); |
| 553 | safe_strcat(wql, len, To_CondFil->Body); |
| 554 | } |
| 555 | |
| 556 | return wql; |
| 557 | } // end of MakeWQL |
| 558 | |
| 559 | /***********************************************************************/ |
| 560 | /* GetWMIInfo: Get info for the WMI class. */ |
nothing calls this directly
no test coverage detected