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

Method MakeCommand

storage/connect/tabext.cpp:569–673  ·  view source on GitHub ↗

/ MakeCommand: make the Update or Delete statement to send to the */ MySQL server. Limited to remote values and filtering. */ /

Source from the content-addressed store, hash-verified

567/* MySQL server. Limited to remote values and filtering. */
568/***********************************************************************/
569bool TDBEXT::MakeCommand(PGLOBAL g)
570{
571 PCSZ schmp = NULL;
572 char *p, *stmt, name[132], *body = NULL;
573 char *qrystr = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 1);
574 bool qtd = Quoted > 0;
575 char q = qtd ? *Quote : ' ';
576 int i = 0, k = 0;
577 size_t stmt_sz = 0;
578
579 // Make a lower case copy of the originale query and change
580 // back ticks to the data source identifier quoting character
581 do {
582 qrystr[i] = (Qrystr[i] == '`') ? q : tolower(Qrystr[i]);
583 } while (Qrystr[i++]);
584
585 if (To_CondFil && (p = strstr(qrystr, " where "))) {
586 p[7] = 0; // Remove where clause
587 Qrystr[(p - qrystr) + 7] = 0;
588 body = To_CondFil->Body;
589 stmt_sz = strlen(qrystr) + strlen(body) + 64;
590 } else
591 stmt_sz = strlen(Qrystr) + 64;
592 stmt = (char*)PlugSubAlloc(g, NULL, stmt_sz);
593
594 // Check whether the table name is equal to a keyword
595 // If so, it must be quoted in the original query
596 snprintf(name, sizeof(name), " %s ", Name);
597 strlwr(name);
598
599 if (strstr(" update delete low_priority ignore quick from ", name)) {
600 if (Quote) {
601 snprintf(name, sizeof(name), "%s%s%s", Quote, Name, Quote);
602 strlwr(name);
603 k += 2;
604 } else {
605 safe_strcpy(g->Message, sizeof(g->Message), "Quoted must be specified");
606 return true;
607 } // endif Quote
608
609 } else {
610 safe_strcpy(name, sizeof(name), Name); // Not a keyword
611 strlwr(name);
612 }
613
614 if ((p = strstr(qrystr, name))) {
615 for (i = 0; i < p - qrystr; i++)
616 stmt[i] = (Qrystr[i] == '`') ? q : Qrystr[i];
617
618 stmt[i] = 0;
619
620 k += i + (int)strlen(Name);
621
622 if (Schema && *Schema)
623 schmp = Schema;
624
625 if (qtd && *(p - 1) == ' ') {
626 if (schmp) {

Callers

nothing calls this directly

Calls 6

PlugSubAllocFunction · 0.85
strlwrFunction · 0.85
safe_strcpyFunction · 0.85
safe_strcatFunction · 0.85
htrcFunction · 0.70
GetSizeMethod · 0.45

Tested by

no test coverage detected