diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2019-01-24 23:49:57 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2019-01-24 23:49:57 +0100 |
commit | a4834755ecbc3643a12c40334a12f2ec75080622 (patch) | |
tree | f40d5bedb2dce94ce330760499a75df32b24a866 | |
parent | 547ce1b22a9962b673af381a271377aefc2dca4e (diff) | |
download | mariadb-git-a4834755ecbc3643a12c40334a12f2ec75080622.tar.gz |
- Fix MDEV-18192: CONNECT Engine JDBC not able to issue
simple UPDATE statement from trigger or stored procedure
modified: storage/connect/tabext.cpp
modified: storage/connect/tabext.h
modified: storage/connect/tabjdbc.cpp
- JSONColumns: Copy locally constant strings to fix error in OEM modules
modified: storage/connect/tabjson.cpp
-rw-r--r-- | storage/connect/tabext.cpp | 39 | ||||
-rw-r--r-- | storage/connect/tabext.h | 1 | ||||
-rw-r--r-- | storage/connect/tabjdbc.cpp | 59 | ||||
-rw-r--r-- | storage/connect/tabjson.cpp | 4 |
4 files changed, 76 insertions, 27 deletions
diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index f2d5eb0e69d..292f67ed5e8 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -446,6 +446,43 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) } // end of MakeSQL /***********************************************************************/ +/* Remove the NAME_CONST functions that are added by procedures. */ +/***********************************************************************/ +void TDBEXT::RemoveConst(PGLOBAL g, char *stmt) +{ + char *p, *p2; + char val[1025], nval[1025]; + int n, nc; + + while ((p = strstr(stmt, "NAME_CONST"))) + if ((n = sscanf(p, "%*[^,],%1024[^)])%n", val, &nc))) { + if (trace(33)) + htrc("p=%s\nn=%d val=%s nc=%d\n", p, n, val, nc); + + *p = 0; + + if ((p2 = strstr(val, "'"))) { + if ((n = sscanf(p2, "%*['\\]%1024[^'\\]", nval))) { + if (trace(33)) + htrc("p2=%s\nn=%d nval=%s\n", p2, n, nval); + + strcat(strcat(strcat(strcat(stmt, "'"), nval), "'"), p + nc); + } else + break; + + } else + strcat(strcat(strcat(strcat(stmt, "("), val), ")"), p + nc); + + if (trace(33)) + htrc("stmt=%s\n", stmt); + + } else + break; + + return; +} // end of RemoveConst + +/***********************************************************************/ /* MakeCommand: make the Update or Delete statement to send to the */ /* MySQL server. Limited to remote values and filtering. */ /***********************************************************************/ @@ -524,6 +561,8 @@ bool TDBEXT::MakeCommand(PGLOBAL g) stmt[i++] = (Qrystr[k] == '`') ? q : Qrystr[k]; } while (Qrystr[k++]); + RemoveConst(g, stmt); + if (body) strcat(stmt, body); diff --git a/storage/connect/tabext.h b/storage/connect/tabext.h index 6b67c2ab5ed..21e3796ea7c 100644 --- a/storage/connect/tabext.h +++ b/storage/connect/tabext.h @@ -130,6 +130,7 @@ protected: virtual bool MakeSQL(PGLOBAL g, bool cnt); //virtual bool MakeInsert(PGLOBAL g); virtual bool MakeCommand(PGLOBAL g); + void RemoveConst(PGLOBAL g, char *stmt); int Decode(PCSZ utf, char *buf, size_t n); // Members diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index adb3fc4fb51..27814af3dbe 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -558,33 +558,42 @@ bool TDBJDBC::OpenDB(PGLOBAL g) this, Tdb_No, Use, Mode); if (Use == USE_OPEN) { - /*******************************************************************/ - /* Table already open, just replace it at its beginning. */ - /*******************************************************************/ - if (Memory == 1) { - if ((Qrp = Jcp->AllocateResult(g, this))) - Memory = 2; // Must be filled - else - Memory = 0; // Allocation failed, don't use it - - } else if (Memory == 2) - Memory = 3; // Ok to use memory result - - if (Memory < 3) { - // Method will depend on cursor type - if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0) - if (Mode != MODE_READX) { - Jcp->Close(); - return true; - } else - Rbuf = 0; + if (Mode == MODE_READ || Mode == MODE_READX) { + /*****************************************************************/ + /* Table already open, just replace it at its beginning. */ + /*****************************************************************/ + if (Memory == 1) { + if ((Qrp = Jcp->AllocateResult(g, this))) + Memory = 2; // Must be filled + else + Memory = 0; // Allocation failed, don't use it - } else - Rbuf = Qrp->Nblin; + } else if (Memory == 2) + Memory = 3; // Ok to use memory result + + if (Memory < 3) { + // Method will depend on cursor type + if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0) + if (Mode != MODE_READX) { + Jcp->Close(); + return true; + } else + Rbuf = 0; + + } else + Rbuf = Qrp->Nblin; + + CurNum = 0; + Fpos = 0; + Curpos = 1; + } else if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { + // new update coming from a trigger or procedure + Query = NULL; + SetCondFil(NULL); + Qrystr = To_Def->GetStringCatInfo(g, "Query_String", "?"); + } else { //if (Mode == MODE_INSERT) + } // endif Mode - CurNum = 0; - Fpos = 0; - Curpos = 1; return false; } // endif use diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index c0d36efcf42..3b326a570eb 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -110,8 +110,8 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) buftyp, fldtyp, length, false, false); crp = qrp->Colresp->Next->Next->Next->Next->Next->Next; - crp->Name = "Nullable"; - crp->Next->Name = "Jpath"; + crp->Name = PlugDup(g, "Nullable"); + crp->Next->Name = PlugDup(g, "Jpath"); if (info || !qrp) return qrp; |