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

Method MakeCommand

storage/connect/tabmysql.cpp:676–724  ·  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

674/* MySQL server. Limited to remote values and filtering. */
675/***********************************************************************/
676bool TDBMYSQL::MakeCommand(PGLOBAL g)
677 {
678 Query = new(g) STRING(g, strlen(Qrystr) + 64);
679
680 if (Quoted > 0 || stricmp(Name, TableName)) {
681 char *p, *qrystr, name[68];
682 bool qtd = Quoted > 0;
683
684
685 // Make a lower case copy of the originale query
686 qrystr = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 5);
687 strlwr(strcpy(qrystr, Qrystr));
688
689 // Check whether the table name is equal to a keyword
690 // If so, it must be quoted in the original query
691 strlwr(strcat(strcat(strcpy(name, "`"), Name), "`"));
692
693 if (!strstr("`update`delete`low_priority`ignore`quick`from`", name))
694 strlwr(strcpy(name, Name)); // Not a keyword
695
696 if ((p = strstr(qrystr, name))) {
697 Query->Set(Qrystr, (uint)(p - qrystr));
698
699 if (qtd && *(p-1) == ' ') {
700 Query->Append('`');
701 Query->Append(TableName);
702 Query->Append('`');
703 } else
704 Query->Append(TableName);
705
706 Query->Append(Qrystr + (p - qrystr) + strlen(name));
707
708 if (Query->IsTruncated()) {
709 snprintf(g->Message, sizeof(g->Message), "MakeCommand: Out of memory");
710 return true;
711 } else
712 strlwr(strcpy(qrystr, Query->GetStr()));
713
714 } else {
715 snprintf(g->Message, sizeof(g->Message), "Cannot use this %s command",
716 (Mode == MODE_UPDATE) ? "UPDATE" : "DELETE");
717 return true;
718 } // endif p
719
720 } else
721 (void)Query->Set(Qrystr);
722
723 return false;
724 } // end of MakeCommand
725
726#if 0
727/***********************************************************************/

Callers

nothing calls this directly

Calls 4

PlugSubAllocFunction · 0.85
strlwrFunction · 0.85
SetMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected