MCPcopy Create free account
hub / github.com/MariaDB/server / MakeWQL

Method MakeWQL

storage/connect/tabwmi.cpp:503–557  ·  view source on GitHub ↗

/ MakeWQL: make the WQL statement use with WMI ExecQuery. */ /

Source from the content-addressed store, hash-verified

501/* MakeWQL: make the WQL statement use with WMI ExecQuery. */
502/***********************************************************************/
503char *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. */

Callers

nothing calls this directly

Calls 7

PlugSubAllocFunction · 0.85
safe_strcatFunction · 0.85
IsSpecialMethod · 0.80
GetNextMethod · 0.45
SetFormatMethod · 0.45
GetValueMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected