Commit 5de5daa7 authored by Olivier Bertrand's avatar Olivier Bertrand

Fix MDEV-12220: Crash when doing UPDATE or DELETE on an external

table (ODBC, JDBC, MYSQL) with a WHERE clause on an indexed column.
Also fix a bugs in TDBEXT::MakeCommand (use of uninitialised Quote)
Add in this function the eventual Schema (database) prefixing.
  modified:   storage/connect/connect.cc
  modified:   storage/connect/tabext.cpp

Typo
  modified:   storage/connect/tabjdbc.h
parent 5bc538dd
......@@ -858,8 +858,9 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
sprintf(g->Message, MSG(TABLE_NO_INDEX), ptdb->GetName());
return RC_FX;
} else if (x == 2) {
// Remote index
if (op != OP_SAME && ptdb->ReadKey(g, op, kr))
// Remote index. Only used in read mode
if ((ptdb->GetMode() == MODE_READ || ptdb->GetMode() == MODE_READX)
&& op != OP_SAME && ptdb->ReadKey(g, op, kr))
return RC_FX;
goto rnd;
......
......@@ -434,15 +434,16 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt)
/***********************************************************************/
bool TDBEXT::MakeCommand(PGLOBAL g)
{
char *p, *stmt, name[68], *body = NULL;
char *p, *stmt, name[132], *body = NULL, *schmp = NULL;
char *qrystr = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 1);
bool qtd = Quoted > 0;
char q = qtd ? *Quote : ' ';
int i = 0, k = 0;
// Make a lower case copy of the originale query and change
// back ticks to the data source identifier quoting character
do {
qrystr[i] = (Qrystr[i] == '`') ? *Quote : tolower(Qrystr[i]);
qrystr[i] = (Qrystr[i] == '`') ? q : tolower(Qrystr[i]);
} while (Qrystr[i++]);
if (To_CondFil && (p = strstr(qrystr, " where "))) {
......@@ -459,27 +460,50 @@ bool TDBEXT::MakeCommand(PGLOBAL g)
strlwr(strcat(strcat(strcpy(name, " "), Name), " "));
if (strstr(" update delete low_priority ignore quick from ", name)) {
strlwr(strcat(strcat(strcpy(name, Quote), Name), Quote));
k += 2;
if (Quote) {
strlwr(strcat(strcat(strcpy(name, Quote), Name), Quote));
k += 2;
} else {
strcpy(g->Message, "Quoted must be specified");
return true;
} // endif Quote
} else
strlwr(strcpy(name, Name)); // Not a keyword
if ((p = strstr(qrystr, name))) {
for (i = 0; i < p - qrystr; i++)
stmt[i] = (Qrystr[i] == '`') ? *Quote : Qrystr[i];
stmt[i] = (Qrystr[i] == '`') ? q : Qrystr[i];
stmt[i] = 0;
k += i + (int)strlen(Name);
if (qtd && *(p - 1) == ' ')
if (Schema && *Schema)
schmp = Schema;
if (qtd && *(p - 1) == ' ') {
if (schmp)
strcat(strcat(stmt, schmp), ".");
strcat(strcat(strcat(stmt, Quote), TableName), Quote);
else
} else {
if (schmp) {
if (qtd && *(p - 1) != ' ') {
stmt[i - 1] = 0;
strcat(strcat(strcat(stmt, schmp), "."), Quote);
} else
strcat(strcat(stmt, schmp), ".");
} // endif schmp
strcat(stmt, TableName);
} // endif's
i = (int)strlen(stmt);
do {
stmt[i++] = (Qrystr[k] == '`') ? *Quote : Qrystr[k];
stmt[i++] = (Qrystr[k] == '`') ? q : Qrystr[k];
} while (Qrystr[k++]);
if (body)
......
/*************** Tabjdbc H Declares Source Code File (.H) **************/
/* Name: TABJDBC.H Version 1.0 */
/* Name: TABJDBC.H Version 1.1 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2016 */
/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */
/* */
/* This file contains the TDBJDBC classes declares. */
/***********************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment