/ MakeCommand: make the Update or Delete statement to send to the */ MySQL server. Limited to remote values and filtering. */ /
| 567 | /* MySQL server. Limited to remote values and filtering. */ |
| 568 | /***********************************************************************/ |
| 569 | bool 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) { |
nothing calls this directly
no test coverage detected