From fa7bbe5a73bcb96164a20fbb461d82675a2c486e Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 7 May 2018 00:56:45 +0200 Subject: - Fix MDEV-15735 CONNECT [filamtxt.cpp:429]: Suspicious condition modified: storage/connect/filamtxt.cpp - Fix MDEV-15577 CONNECT engine JDBC remote index prevents UPDATE Fixed in TDBJDBC::OpenDB because query can be null for updates modified: storage/connect/tabjdbc.cpp - Fix wrong updates of 10.3 distribution modified: storage/connect/ha_connect.cc modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp - Typo from 10.3 modified: storage/connect/mycat.cc modified: storage/connect/tabext.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/user_connect.cc --- storage/connect/filamtxt.cpp | 2 +- storage/connect/ha_connect.cc | 13 ++++--------- storage/connect/jsonudf.cpp | 10 ++++------ storage/connect/mycat.cc | 7 ++----- storage/connect/tabext.cpp | 2 +- storage/connect/tabjdbc.cpp | 2 +- storage/connect/tabjson.cpp | 14 +++++++------- storage/connect/tabtbl.cpp | 2 +- 8 files changed, 21 insertions(+), 31 deletions(-) diff --git a/storage/connect/filamtxt.cpp b/storage/connect/filamtxt.cpp index 7c222eb3c80..490ca3a5fba 100644 --- a/storage/connect/filamtxt.cpp +++ b/storage/connect/filamtxt.cpp @@ -427,7 +427,7 @@ int TXTFAM::DeleteSortedRows(PGLOBAL g) for (i = 0; i < Posar->GetNval(); i++) { if ((irc = InitDelete(g, Posar->GetIntValue(ix[i]), - Sosar->GetIntValue(ix[i])) == RC_FX)) + Sosar->GetIntValue(ix[i]))) == RC_FX) goto err; // Now delete the sorted rows diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 1bb689000f8..9627a85eee4 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -108,13 +108,8 @@ #define MYSQL_SERVER 1 #define DONT_DEFINE_VOID #include -#include "sql_class.h" -#include "create_options.h" -#include "mysql_com.h" -#include "field.h" #include "sql_parse.h" #include "sql_base.h" -#include #include "sql_partition.h" #undef OFFSET @@ -175,7 +170,7 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0007 March 11, 2018"; + char version[]= "Version 1.06.0007 May 01, 2018"; #if defined(__WIN__) char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__; char slash= '\\'; @@ -238,7 +233,7 @@ uint GetWorkSize(void); void SetWorkSize(uint); extern "C" const char *msglang(void); -static char *strz(PGLOBAL g, LEX_STRING &ls); +static char *strz(PGLOBAL g, LEX_CSTRING &ls); static void PopUser(PCONNECT xp); static PCONNECT GetUser(THD *thd, PCONNECT xp); @@ -1322,7 +1317,7 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef) if (!stricmp(opname, "Connect")) { LEX_CSTRING cnc= (tshp) ? tshp->connect_string - : table->s->connect_string; + : table->s->connect_string; if (cnc.length) opval= strz(xp->g, cnc); @@ -5571,7 +5566,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, } // endif p } else if (ttp != TAB_ODBC || !(fnc & (FNC_TABLE | FNC_COL))) - tab = (char *) table_s->table_name.str; // Default value + tab = (char*) table_s->table_name.str; // Default value } // endif tab diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index ca51712af0c..b10060c7541 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -41,8 +41,6 @@ static PJSON JsonNew(PGLOBAL g, JTYP type); static PJVAL JvalNew(PGLOBAL g, JTYP type, void *vp = NULL); static PJSNX JsnxNew(PGLOBAL g, PJSON jsp, int type, int len = 64); -void json_array_deinit(UDF_INIT* initid); - static uint JsonGrpSize = 10; /*********************************************************************************/ @@ -1669,7 +1667,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) int j = 0, n = args->attribute_lengths[i]; my_bool b; // true if attribute is zero terminated PSZ p; - const char *s = args->attributes[i]; + PCSZ s = args->attributes[i]; if (s && *s && (n || *s == '\'')) { if ((b = (!n || !s[n]))) @@ -1688,7 +1686,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) } // endif *s if (n < 1) - return (char*) "Key"; + return "Key"; if (!b) { if ((p = (PSZ)PlgDBSubAlloc(g, NULL, n + 1))) { @@ -1702,10 +1700,10 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) } // endif s - return (char*) s; + return s; } // endif count - return (char*) "Key"; + return "Key"; } // end of MakeKey /*********************************************************************************/ diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index dd04d667e58..5aef6d9c660 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -18,7 +18,7 @@ /* ------------- */ /* Version 1.6 */ /* */ -/* Author: Olivier Bertrand 2012 - 2017 */ +/* Author: Olivier Bertrand 2012 - 2018 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -31,10 +31,7 @@ #define DONT_DEFINE_VOID #include -#if defined(__WIN__) -//#include -//#include -#elif defined(UNIX) +#if defined(UNIX) #include #include #endif diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index 7be6c0e8328..139e4199ed9 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -286,7 +286,7 @@ bool TDBEXT::MakeSrcdef(PGLOBAL g) char *catp = strstr(Srcdef, "%s"); if (catp) { - char *fil1= 0, *fil2; + char *fil1 = 0, *fil2; PCSZ ph = ((EXTDEF*)To_Def)->Phpos; if (!ph) diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index adbfb2168ae..275b5edaeae 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -572,7 +572,7 @@ bool TDBJDBC::OpenDB(PGLOBAL g) if (Memory < 3) { // Method will depend on cursor type - if ((Rbuf = Jcp->Rewind(Query->GetStr())) < 0) + if ((Rbuf = Query ? Jcp->Rewind(Query->GetStr()) : 0) < 0) if (Mode != MODE_READX) { Jcp->Close(); return true; diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index 6151d924a9f..9e4f5ab987d 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -195,7 +195,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL); if (!(tdp->Database = SetPath(g, db))) - return 0ULL; + return 0; tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; @@ -243,14 +243,14 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); if (tjsp->MakeDocument(g)) - return 0ULL; + return 0; jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; } else { if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) if (!mgo) { sprintf(g->Message, "LRECL must be specified for pretty=%d", tdp->Pretty); - return 0ULL; + return 0; } else tdp->Lrecl = 8192; // Should be enough @@ -269,14 +269,14 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); #else sprintf(g->Message, "Mongo %s Driver not available", "C"); - return 0ULL; + return 0; #endif } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { #if defined(JAVA_SUPPORT) tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else sprintf(g->Message, "Mongo %s Driver not available", "Java"); - return 0ULL; + return 0; #endif } else { // Driver not specified #if defined(CMGO_SUPPORT) @@ -285,7 +285,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return 0ULL; + return 0; #endif } // endif Driver @@ -304,7 +304,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) tjnp->SetG(G); if (tjnp->OpenDB(g)) - return 0ULL; + return 0; switch (tjnp->ReadDB(g)) { case RC_EF: diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index b2dbdd70e06..77f0a1c4001 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -232,7 +232,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) { int n; uint sln; - const char *scs; + const char *scs; PTABLE tp, tabp; PCOL colp; PTBLDEF tdp = (PTBLDEF)To_Def; -- cgit v1.2.1 From c0fd3be2728d55e8979246d5a18928e2e827614b Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 28 Jun 2018 23:33:02 +0200 Subject: - Fix MDEV-16167 Cannot insert unsigned values into a VEC table modified: storage/connect/filamvct.cpp modified: storage/connect/tabvct.cpp --- storage/connect/filamvct.cpp | 22 ++++++++++++++-------- storage/connect/tabvct.cpp | 6 ++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/storage/connect/filamvct.cpp b/storage/connect/filamvct.cpp index 244acfdc5c8..a660461e9ee 100644 --- a/storage/connect/filamvct.cpp +++ b/storage/connect/filamvct.cpp @@ -515,7 +515,8 @@ bool VCTFAM::AllocateBuffer(PGLOBAL g) for (; cp; cp = (PVCTCOL)cp->Next) cp->Blk = AllocValBlock(g, NewBlock + Nrec * cp->Deplac, cp->Buf_Type, Nrec, cp->Format.Length, - cp->Format.Prec, chk); + cp->Format.Prec, chk, true, + cp->IsUnsigned()); return InitInsert(g); // Initialize inserting } else { @@ -549,7 +550,8 @@ bool VCTFAM::AllocateBuffer(PGLOBAL g) for (; cp; cp = (PVCTCOL)cp->Next) if (!cp->IsSpecial()) // Not a pseudo column cp->Blk = AllocValBlock(g, NULL, cp->Buf_Type, Nrec, - cp->Format.Length, cp->Format.Prec); + cp->Format.Length, cp->Format.Prec, + true, true, cp->IsUnsigned()); } //endif mode @@ -1516,7 +1518,8 @@ bool VCMFAM::AllocateBuffer(PGLOBAL g) for (cp = (PVCTCOL)Tdbp->GetColumns(); cp; cp = (PVCTCOL)cp->Next) if (!cp->IsSpecial()) { // Not a pseudo column cp->Blk = AllocValBlock(g, (void*)1, cp->Buf_Type, Nrec, - cp->Format.Length, cp->Format.Prec); + cp->Format.Length, cp->Format.Prec, + true, true, cp->IsUnsigned()); cp->AddStatus(BUF_MAPPED); } // endif IsSpecial @@ -2067,7 +2070,7 @@ bool VECFAM::AllocateBuffer(PGLOBAL g) for (cp = (PVCTCOL)tdbp->Columns; cp; cp = (PVCTCOL)cp->Next) cp->Blk = AllocValBlock(g, To_Bufs[cp->Index - 1], cp->Buf_Type, Nrec, cp->Format.Length, - cp->Format.Prec, chk); + cp->Format.Prec, chk, true, cp->IsUnsigned()); return InitInsert(g); } else { @@ -2116,7 +2119,8 @@ bool VECFAM::AllocateBuffer(PGLOBAL g) for (cp = (PVCTCOL)tdbp->Columns; cp; cp = (PVCTCOL)cp->Next) if (!cp->IsSpecial()) // Not a pseudo column cp->Blk = AllocValBlock(g, NULL, cp->Buf_Type, Nrec, - cp->Format.Length, cp->Format.Prec); + cp->Format.Length, cp->Format.Prec, + true, true, cp->IsUnsigned()); } // endif mode @@ -2887,7 +2891,8 @@ bool VMPFAM::AllocateBuffer(PGLOBAL g) for (cp = (PVCTCOL)Tdbp->GetColumns(); cp; cp = (PVCTCOL)cp->Next) if (!cp->IsSpecial()) { // Not a pseudo column cp->Blk = AllocValBlock(g, (void*)1, cp->Buf_Type, Nrec, - cp->Format.Length, cp->Format.Prec); + cp->Format.Length, cp->Format.Prec, + true, true, cp->IsUnsigned()); cp->AddStatus(BUF_MAPPED); } // endif IsSpecial @@ -3669,7 +3674,7 @@ bool BGVFAM::AllocateBuffer(PGLOBAL g) for (; cp; cp = (PVCTCOL)cp->Next) cp->Blk = AllocValBlock(g, NewBlock + Nrec * cp->Deplac, cp->Buf_Type, Nrec, cp->Format.Length, - cp->Format.Prec, chk); + cp->Format.Prec, chk, true, cp->IsUnsigned()); InitInsert(g); // Initialize inserting @@ -3717,7 +3722,8 @@ bool BGVFAM::AllocateBuffer(PGLOBAL g) for (; cp; cp = (PVCTCOL)cp->Next) if (!cp->IsSpecial()) // Not a pseudo column cp->Blk = AllocValBlock(g, NULL, cp->Buf_Type, Nrec, - cp->Format.Length, cp->Format.Prec); + cp->Format.Length, cp->Format.Prec, + true, true, cp->IsUnsigned()); } //endif mode diff --git a/storage/connect/tabvct.cpp b/storage/connect/tabvct.cpp index 11b344ef652..40d020202ea 100644 --- a/storage/connect/tabvct.cpp +++ b/storage/connect/tabvct.cpp @@ -456,13 +456,11 @@ bool VCTCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) if (tdbp->Txfp->GetAmType() == TYPE_AM_VMP && ok) { Blk = AllocValBlock(g, (void*)1, Buf_Type, tdbp->Txfp->Nrec, - Format.Length, - Format.Prec, check); + Format.Length, Format.Prec, check, true, Unsigned); Status |= BUF_MAPPED; // Will point into mapped file } else Blk = AllocValBlock(g, NULL, Buf_Type, tdbp->Txfp->Nrec, - Format.Length, - Format.Prec, check); + Format.Length, Format.Prec, check, true, Unsigned); } // endif Mode return false; -- cgit v1.2.1 From 15194de2c2846fcbb5d9feb7b6d993b281ac6e1f Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 8 Aug 2018 12:10:30 +0200 Subject: - Fix MDEV-16672 Connect: Warnings with 10.0 filamtxt.cpp: DOSFAM::RenameTempFile: Change sprintf to snprintf. filamvct.cpp: VECFAM::RenameTempFile: Change sprintf to snprintf. javaconn.cpp: Add JAVAConn::GetUTFString function. Use it instead of env->GetStringUTFChars. Fix wrong identation. javaconn.h: Add GetUTFString declaration. jdbconn.cpp: Use GetUTFString function instead of env->GetStringUTFChars. jmgoconn.cpp: Use GetUTFString function instead of env->GetStringUTFChars. Fix wrong identation. jsonudf.cpp: change 139 to BMX line 4631. tabjmg.cpp: Add ReleaseStringUTF. Fix wrong identation. tabpivot.cpp: Fix wrong identation. tabutil.cpp: TDBPRX::GetSubTable: Change sprintf to snprintf. modified: storage/connect/filamtxt.cpp modified: storage/connect/filamvct.cpp modified: storage/connect/javaconn.cpp modified: storage/connect/javaconn.h modified: storage/connect/jdbconn.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjmg.cpp modified: storage/connect/tabpivot.cpp modified: storage/connect/tabutil.cpp - Fix MDEV-16895 CONNECT engine's get_error_message can cause buffer overflow and server crash with long queries ha_connect_cc: Update version. get_error_message: Remove charset conversion. modified: storage/connect/ha_connect.cc - Fix a server crash on inserting bigint to a JDBC table JDBConn::SetUUID: Suppress check on ctyp that causes a server crash because ctyp can be negative and this triggers an DEBUG_ASSERT on return. modified: storage/connect/jdbconn.cpp - Delete an assert(qrp) from JCATPARM *AllocCatInfo that is called with qrp=NULL from JDBConn::SetUUID. Also delete a clone of this function that was duplicated in javaconn.cpp. modified: storage/connect/javaconn.cpp modified: storage/connect/jdbconn.cpp - Update some (disabled) tests and results to avoid failure modified: storage/connect/mysql-test/connect/r/jdbc.result modified: storage/connect/mysql-test/connect/r/json_java_2.result modified: storage/connect/mysql-test/connect/r/json_java_3.result modified: storage/connect/mysql-test/connect/r/mongo_java_2.result modified: storage/connect/mysql-test/connect/r/mongo_java_3.result modified: storage/connect/mysql-test/connect/r/xml2.result modified: storage/connect/mysql-test/connect/t/json_java_2.test modified: storage/connect/mysql-test/connect/t/json_java_3.test modified: storage/connect/mysql-test/connect/t/mongo_java_2.test modified: storage/connect/mysql-test/connect/t/mongo_java_3.test modified: storage/connect/mysql-test/connect/t/xml2.test --- storage/connect/filamtxt.cpp | 4 +- storage/connect/filamvct.cpp | 6 +- storage/connect/ha_connect.cc | 24 +-- storage/connect/javaconn.cpp | 41 ++--- storage/connect/javaconn.h | 1 + storage/connect/jdbconn.cpp | 38 ++--- storage/connect/jmgoconn.cpp | 7 +- storage/connect/jsonudf.cpp | 7 +- storage/connect/mysql-test/connect/r/jdbc.result | 3 +- .../mysql-test/connect/r/json_java_2.result | 1 - .../mysql-test/connect/r/json_java_3.result | 1 - .../mysql-test/connect/r/mongo_java_2.result | 1 - .../mysql-test/connect/r/mongo_java_3.result | 1 - storage/connect/mysql-test/connect/r/xml2.result | 31 ---- .../connect/mysql-test/connect/t/json_java_2.test | 2 + .../connect/mysql-test/connect/t/json_java_3.test | 2 + .../connect/mysql-test/connect/t/mongo_java_2.test | 2 + .../connect/mysql-test/connect/t/mongo_java_3.test | 2 + storage/connect/mysql-test/connect/t/xml2.test | 36 ++--- storage/connect/tabjmg.cpp | 11 +- storage/connect/tabpivot.cpp | 166 ++++++++++----------- storage/connect/tabutil.cpp | 2 +- 22 files changed, 166 insertions(+), 223 deletions(-) diff --git a/storage/connect/filamtxt.cpp b/storage/connect/filamtxt.cpp index 490ca3a5fba..ca48fc765a1 100644 --- a/storage/connect/filamtxt.cpp +++ b/storage/connect/filamtxt.cpp @@ -1173,11 +1173,11 @@ int DOSFAM::RenameTempFile(PGLOBAL g) remove(filetemp); // May still be there from previous error if (rename(filename, filetemp)) { // Save file for security - sprintf(g->Message, MSG(RENAME_ERROR), + snprintf(g->Message, MAX_STR, MSG(RENAME_ERROR), filename, filetemp, strerror(errno)); throw 51; } else if (rename(tempname, filename)) { - sprintf(g->Message, MSG(RENAME_ERROR), + snprintf(g->Message, MAX_STR, MSG(RENAME_ERROR), tempname, filename, strerror(errno)); rc = rename(filetemp, filename); // Restore saved file throw 52; diff --git a/storage/connect/filamvct.cpp b/storage/connect/filamvct.cpp index a660461e9ee..e8a4ba890bf 100644 --- a/storage/connect/filamvct.cpp +++ b/storage/connect/filamvct.cpp @@ -353,7 +353,7 @@ int VCTFAM::Cardinality(PGLOBAL g) } // endif split - return (Block) ? ((Block - 1) * Nrec + Last) : 0; + return (Block) ? ((Block - 1) * Nrec + Last) : 0; } // end of Cardinality /***********************************************************************/ @@ -2458,11 +2458,11 @@ int VECFAM::RenameTempFile(PGLOBAL g) remove(filetemp); // May still be there from previous error if (rename(filename, filetemp)) { // Save file for security - sprintf(g->Message, MSG(RENAME_ERROR), + snprintf(g->Message, MAX_STR, MSG(RENAME_ERROR), filename, filetemp, strerror(errno)); rc = RC_FX; } else if (rename(tempname, filename)) { - sprintf(g->Message, MSG(RENAME_ERROR), + snprintf(g->Message, MAX_STR, MSG(RENAME_ERROR), tempname, filename, strerror(errno)); rc = rename(filetemp, filename); // Restore saved file rc = RC_FX; diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 9627a85eee4..4dff4bc31ce 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,7 +170,7 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0007 May 01, 2018"; + char version[]= "Version 1.06.0007 August 06, 2018"; #if defined(__WIN__) char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__; char slash= '\\'; @@ -3303,23 +3303,15 @@ bool ha_connect::get_error_message(int error, String* buf) { DBUG_ENTER("ha_connect::get_error_message"); - if (xp && xp->g) { - PGLOBAL g= xp->g; - char msg[3072]; // MAX_STR * 3 - uint dummy_errors; - uint32 len= copy_and_convert(msg, strlen(g->Message) * 3, - system_charset_info, - g->Message, strlen(g->Message), - &my_charset_latin1, - &dummy_errors); + if (xp && xp->g) { + PGLOBAL g = xp->g; - if (trace(1)) - htrc("GEM(%d): len=%u %s\n", error, len, g->Message); + if (trace(1)) + htrc("GEM(%d): %s\n", error, g->Message); - msg[len]= '\0'; - buf->copy(msg, (uint)strlen(msg), system_charset_info); - } else - buf->copy("Cannot retrieve msg", 19, system_charset_info); + buf->append(g->Message); + } else + buf->append("Cannot retrieve error message"); DBUG_RETURN(false); } // end of get_error_message diff --git a/storage/connect/javaconn.cpp b/storage/connect/javaconn.cpp index d1be0ca1848..f05db1892d9 100644 --- a/storage/connect/javaconn.cpp +++ b/storage/connect/javaconn.cpp @@ -81,29 +81,6 @@ GETDEF JAVAConn::GetDefaultJavaVMInitArgs = NULL; #define DEBUG_ONLY(f) ((void)0) #endif // !_DEBUG -/***********************************************************************/ -/* Allocate the structure used to refer to the result set. */ -/***********************************************************************/ -static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, PCSZ db, - PCSZ tab, PQRYRES qrp) -{ - JCATPARM *cap; - -#if defined(_DEBUG) - assert(qrp); -#endif - - if ((cap = (JCATPARM *)PlgDBSubAlloc(g, NULL, sizeof(JCATPARM)))) { - memset(cap, 0, sizeof(JCATPARM)); - cap->Id = fid; - cap->Qrp = qrp; - cap->DB = db; - cap->Tab = tab; - } // endif cap - - return cap; -} // end of AllocCatInfo - /***********************************************************************/ /* JAVAConn construction/destruction. */ /***********************************************************************/ @@ -138,6 +115,16 @@ JAVAConn::JAVAConn(PGLOBAL g, PCSZ wrapper) // EndCom(); // } // end of ~JAVAConn +char *JAVAConn::GetUTFString(jstring s) +{ + char *str; + const char *utf = env->GetStringUTFChars(s, nullptr); + + str = PlugDup(m_G, utf); + env->ReleaseStringUTFChars(s, utf); + env->DeleteLocalRef(s); + return str; +} // end of GetUTFString /***********************************************************************/ /* Screen for errors. */ @@ -152,17 +139,15 @@ bool JAVAConn::Check(jint rc) "toString", "()Ljava/lang/String;"); if (exc != nullptr && tid != nullptr) { - jstring s = (jstring)env->CallObjectMethod(exc, tid); - const char *utf = env->GetStringUTFChars(s, (jboolean)false); - env->DeleteLocalRef(s); - Msg = PlugDup(m_G, utf); + s = (jstring)env->CallObjectMethod(exc, tid); + Msg = GetUTFString(s); } else Msg = "Exception occured"; env->ExceptionClear(); } else if (rc < 0) { s = (jstring)env->CallObjectMethod(job, errid); - Msg = (char*)env->GetStringUTFChars(s, (jboolean)false); + Msg = GetUTFString(s); } else Msg = NULL; diff --git a/storage/connect/javaconn.h b/storage/connect/javaconn.h index 54b7c4e92b7..73812f6ab3b 100644 --- a/storage/connect/javaconn.h +++ b/storage/connect/javaconn.h @@ -90,6 +90,7 @@ public: // Java operations protected: + char *GetUTFString(jstring s); bool gmID(PGLOBAL g, jmethodID& mid, const char *name, const char *sig); bool Check(jint rc = 0); diff --git a/storage/connect/jdbconn.cpp b/storage/connect/jdbconn.cpp index 33414ca74c2..e0aca3333e6 100644 --- a/storage/connect/jdbconn.cpp +++ b/storage/connect/jdbconn.cpp @@ -322,10 +322,6 @@ static JCATPARM *AllocCatInfo(PGLOBAL g, JCATINFO fid, PCSZ db, { JCATPARM *cap; -#if defined(_DEBUG) - assert(qrp); -#endif - if ((cap = (JCATPARM *)PlgDBSubAlloc(g, NULL, sizeof(JCATPARM)))) { memset(cap, 0, sizeof(JCATPARM)); cap->Id = fid; @@ -707,21 +703,14 @@ bool JDBConn::SetUUID(PGLOBAL g, PTDBJDBC tjp) goto err; } // endif rc - // Returns 666 is case of error - //jtyp = env->CallIntMethod(job, typid, 5, nullptr); + // Should return 666 is case of error (not done yet) + ctyp = (int)env->CallIntMethod(job, intfldid, 5, nullptr); - //if (Check((jtyp == 666) ? -1 : 1)) { - // sprintf(g->Message, "Getting jtyp: %s", Msg); + //if (Check((ctyp == 666) ? -1 : 1)) { + // sprintf(g->Message, "Getting ctyp: %s", Msg); // goto err; //} // endif ctyp - ctyp = (int)env->CallIntMethod(job, intfldid, 5, nullptr); - - if (Check(ctyp)) { - sprintf(g->Message, "Getting ctyp: %s", Msg); - goto err; - } // endif ctyp - if (ctyp == 1111) ((PJDBCCOL)colp)->uuid = true; @@ -836,11 +825,11 @@ bool JDBConn::Connect(PJPARM sop) jstring s = (jstring)env->CallObjectMethod(job, qcid); if (s != nullptr) { - char *qch = (char*)env->GetStringUTFChars(s, (jboolean)false); + char *qch = GetUTFString(s); m_IDQuoteChar[0] = *qch; } else { s = (jstring)env->CallObjectMethod(job, errid); - Msg = (char*)env->GetStringUTFChars(s, (jboolean)false); + Msg = GetUTFString(s); } // endif s } // endif qcid @@ -1018,7 +1007,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) cn = nullptr; if (cn) { - field = env->GetStringUTFChars(cn, (jboolean)false); + field = GetUTFString(cn); val->SetValue_psz((PSZ)field); } else val->Reset(); @@ -1092,8 +1081,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val) cn = nullptr; if (cn) { - const char *field = env->GetStringUTFChars(cn, (jboolean)false); - val->SetValue_psz((PSZ)field); + val->SetValue_psz((PSZ)GetUTFString(cn)); } else val->Reset(); @@ -1372,19 +1360,19 @@ bool JDBConn::SetParam(JDBCCOL *colp) for (i = 0, n = 0; i < size; i++) { crp = qrp->Colresp; js = (jstring)env->GetObjectArrayElement(s, n++); - sval = (PSZ)env->GetStringUTFChars(js, 0); + sval = GetUTFString(js); crp->Kdata->SetValue(sval, i); crp = crp->Next; js = (jstring)env->GetObjectArrayElement(s, n++); - sval = (PSZ)env->GetStringUTFChars(js, 0); + sval = GetUTFString(js); crp->Kdata->SetValue(sval, i); crp = crp->Next; js = (jstring)env->GetObjectArrayElement(s, n++); - sval = (PSZ)env->GetStringUTFChars(js, 0); + sval = GetUTFString(js); crp->Kdata->SetValue(sval, i); crp = crp->Next; js = (jstring)env->GetObjectArrayElement(s, n++); - sval = (PSZ)env->GetStringUTFChars(js, 0); + sval = GetUTFString(js); crp->Kdata->SetValue(sval, i); } // endfor i @@ -1470,7 +1458,7 @@ bool JDBConn::SetParam(JDBCCOL *colp) return NULL; } // endif label - name = env->GetStringUTFChars(label, (jboolean)false); + name = GetUTFString(label); crp = qrp->Colresp; // Column_Name crp->Kdata->SetValue((char*)name, i); n = env->GetIntArrayElements(val, 0); diff --git a/storage/connect/jmgoconn.cpp b/storage/connect/jmgoconn.cpp index 0f5b18df4b4..bd1ddadd80d 100644 --- a/storage/connect/jmgoconn.cpp +++ b/storage/connect/jmgoconn.cpp @@ -522,7 +522,7 @@ PSZ JMgoConn::GetDocument(void) jdc = (jstring)env->CallObjectMethod(job, getdocid); if (jdc) - doc = (PSZ)env->GetStringUTFChars(jdc, (jboolean)false); + doc = (PSZ)GetUTFString(jdc); } // endif getdocid @@ -690,7 +690,7 @@ jobject JMgoConn::MakeDoc(PGLOBAL g, PJNCOL jcp) } // endif Jncolp - return parent; + return parent; } // end of MakeDoc /***********************************************************************/ @@ -807,9 +807,10 @@ PSZ JMgoConn::GetColumnValue(PSZ path) fn = (jstring)env->CallObjectMethod(job, objfldid, jn); if (fn) - fld = (PSZ)env->GetStringUTFChars(fn, (jboolean)false); + fld = (PSZ)GetUTFString(fn); } // endif objfldid return fld; } // end of GetColumnValue + diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index b10060c7541..b78d68fddb9 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1620,7 +1620,7 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, if (AllocSarea(g, ml)) { char errmsg[MAX_STR]; - snprintf(errmsg, sizeof(errmsg)-1, MSG(WORK_AREA), g->Message); + snprintf(errmsg, sizeof(errmsg) - 1, MSG(WORK_AREA), g->Message); strcpy(g->Message, errmsg); return true; } // endif SareaAlloc @@ -1667,7 +1667,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) int j = 0, n = args->attribute_lengths[i]; my_bool b; // true if attribute is zero terminated PSZ p; - PCSZ s = args->attributes[i]; + PCSZ s = args->attributes[i]; if (s && *s && (n || *s == '\'')) { if ((b = (!n || !s[n]))) @@ -4632,7 +4632,7 @@ char *jbin_array(UDF_INIT *initid, UDF_ARGS *args, char *result, bsp = NULL; if (!bsp && (bsp = JbinAlloc(g, args, initid->max_length, NULL))) - strncpy(bsp->Msg, g->Message, 139); + strncpy(bsp->Msg, g->Message, BMX); // Keep result of constant function g->Xchk = (initid->const_item) ? bsp : NULL; @@ -5852,3 +5852,4 @@ long long countin(UDF_INIT *initid, UDF_ARGS *args, char *result, free(str2); return n; } // end of countin + diff --git a/storage/connect/mysql-test/connect/r/jdbc.result b/storage/connect/mysql-test/connect/r/jdbc.result index 895b4070d70..a16f2791e8f 100644 --- a/storage/connect/mysql-test/connect/r/jdbc.result +++ b/storage/connect/mysql-test/connect/r/jdbc.result @@ -238,8 +238,7 @@ DROP TABLE t1, connect.emp; CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,message varchar(255) flag=2) ENGINE=CONNECT TABLE_TYPE=JDBC CONNECTION='jdbc:mariadb://localhost:PORT/connect' OPTION_LIST='User=root,Execsrc=1'; SELECT * FROM t2 WHERE command='drop table tx1'; command number message -drop table tx1 0 Execute: java.sql.SQLSyntaxErrorException: Unknown table 'connect.tx1' -Query is : drop table tx1 +drop table tx1 0 Execute: java.sql.SQLSyntaxErrorException: (conn:24) Unknown table 'connect.tx1' SELECT * FROM t2 WHERE command = 'create table tx1 (a int not null, b char(32), c double(8,2))'; command number message create table tx1 (a int not null, b char(32), c double(8,2)) 0 Affected rows diff --git a/storage/connect/mysql-test/connect/r/json_java_2.result b/storage/connect/mysql-test/connect/r/json_java_2.result index 6c578b35d6f..4bbac236200 100644 --- a/storage/connect/mysql-test/connect/r/json_java_2.result +++ b/storage/connect/mysql-test/connect/r/json_java_2.result @@ -1,4 +1,3 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; set connect_enable_mongo=1; # # Test the MONGO table type diff --git a/storage/connect/mysql-test/connect/r/json_java_3.result b/storage/connect/mysql-test/connect/r/json_java_3.result index 4c5fc94fca6..eb8bfc022d6 100644 --- a/storage/connect/mysql-test/connect/r/json_java_3.result +++ b/storage/connect/mysql-test/connect/r/json_java_3.result @@ -1,4 +1,3 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; set connect_enable_mongo=1; # # Test the MONGO table type diff --git a/storage/connect/mysql-test/connect/r/mongo_java_2.result b/storage/connect/mysql-test/connect/r/mongo_java_2.result index 67c67653e88..bc186d7137e 100644 --- a/storage/connect/mysql-test/connect/r/mongo_java_2.result +++ b/storage/connect/mysql-test/connect/r/mongo_java_2.result @@ -1,4 +1,3 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar'; set connect_enable_mongo=1; # # Test the MONGO table type diff --git a/storage/connect/mysql-test/connect/r/mongo_java_3.result b/storage/connect/mysql-test/connect/r/mongo_java_3.result index 665178bd3ea..30c696fc9eb 100644 --- a/storage/connect/mysql-test/connect/r/mongo_java_3.result +++ b/storage/connect/mysql-test/connect/r/mongo_java_3.result @@ -1,4 +1,3 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar'; set connect_enable_mongo=1; # # Test the MONGO table type diff --git a/storage/connect/mysql-test/connect/r/xml2.result b/storage/connect/mysql-test/connect/r/xml2.result index eea53bf55c7..b8075fa1928 100644 --- a/storage/connect/mysql-test/connect/r/xml2.result +++ b/storage/connect/mysql-test/connect/r/xml2.result @@ -333,37 +333,6 @@ DROP TABLE t1; # # Testing Cyrillic # -CREATE TABLE t1 -( -c CHAR(16) CHARACTER SET utf8 -) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' - OPTION_LIST='xmlsup=libxml2,rownode=b'; -SELECT * FROM t1; -c БВГДЕЖЗ -INSERT INTO t1 VALUES ('ИКЛМН'); -SELECT c, HEX(c) FROM t1; -c БВГДЕЖЗ -HEX(c) D091D092D093D094D095D096D097 -c ИКЛМН -HEX(c) D098D09AD09BD09CD09D -DROP TABLE t1; -CREATE TABLE t1 -( -c CHAR(16) CHARACTER SET cp1251 -) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' - OPTION_LIST='xmlsup=libxml2,rownode=b'; -SELECT * FROM t1; -c БВГДЕЖЗ -c ИКЛМН -INSERT INTO t1 VALUES ('ОПРСТ'); -SELECT c, HEX(c) FROM t1; -c БВГДЕЖЗ -HEX(c) C1C2C3C4C5C6C7 -c ИКЛМН -HEX(c) C8CACBCCCD -c ОПРСТ -HEX(c) CECFD0D1D2 -DROP TABLE t1; # # Testing that the underlying file is created with a proper Encoding # diff --git a/storage/connect/mysql-test/connect/t/json_java_2.test b/storage/connect/mysql-test/connect/t/json_java_2.test index bb32eff4e94..2f64d8e2eed 100644 --- a/storage/connect/mysql-test/connect/t/json_java_2.test +++ b/storage/connect/mysql-test/connect/t/json_java_2.test @@ -1,7 +1,9 @@ -- source jdbconn.inc -- source mongo.inc +--disable_query_log eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo2.jar'; +--enable_query_log let $DRV= Java; let $VERS= 2; let $TYPE= JSON; diff --git a/storage/connect/mysql-test/connect/t/json_java_3.test b/storage/connect/mysql-test/connect/t/json_java_3.test index 29e66cd5a1c..cee8343772a 100644 --- a/storage/connect/mysql-test/connect/t/json_java_3.test +++ b/storage/connect/mysql-test/connect/t/json_java_3.test @@ -1,7 +1,9 @@ -- source jdbconn.inc -- source mongo.inc +--disable_query_log eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo3.jar'; +--enable_query_log let $DRV= Java; let $VERS= 3; let $TYPE= JSON; diff --git a/storage/connect/mysql-test/connect/t/mongo_java_2.test b/storage/connect/mysql-test/connect/t/mongo_java_2.test index 21da5dce68f..7dcd028185e 100644 --- a/storage/connect/mysql-test/connect/t/mongo_java_2.test +++ b/storage/connect/mysql-test/connect/t/mongo_java_2.test @@ -1,7 +1,9 @@ -- source jdbconn.inc -- source mongo.inc +--disable_query_log eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo2.jar'; +--enable_query_log let $DRV= Java; let $VERS= 2; let $TYPE= MONGO; diff --git a/storage/connect/mysql-test/connect/t/mongo_java_3.test b/storage/connect/mysql-test/connect/t/mongo_java_3.test index b7584adcc7e..aab16d5e003 100644 --- a/storage/connect/mysql-test/connect/t/mongo_java_3.test +++ b/storage/connect/mysql-test/connect/t/mongo_java_3.test @@ -1,7 +1,9 @@ -- source jdbconn.inc -- source mongo.inc +--disable_query_log eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo3.jar'; +--enable_query_log let $DRV= Java; let $VERS= 3; let $TYPE= MONGO; diff --git a/storage/connect/mysql-test/connect/t/xml2.test b/storage/connect/mysql-test/connect/t/xml2.test index 0f26b8ab5c0..7bbc3dbd87c 100644 --- a/storage/connect/mysql-test/connect/t/xml2.test +++ b/storage/connect/mysql-test/connect/t/xml2.test @@ -240,24 +240,24 @@ DROP TABLE t1; --echo # --echo # Testing Cyrillic --echo # -CREATE TABLE t1 -( - c CHAR(16) CHARACTER SET utf8 -) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' - OPTION_LIST='xmlsup=libxml2,rownode=b'; -SELECT * FROM t1; -INSERT INTO t1 VALUES ('ИКЛМН'); -SELECT c, HEX(c) FROM t1; -DROP TABLE t1; -CREATE TABLE t1 -( - c CHAR(16) CHARACTER SET cp1251 -) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' - OPTION_LIST='xmlsup=libxml2,rownode=b'; -SELECT * FROM t1; -INSERT INTO t1 VALUES ('ОПРСТ'); -SELECT c, HEX(c) FROM t1; -DROP TABLE t1; +#CREATE TABLE t1 +#( +# c CHAR(16) CHARACTER SET utf8 +#) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' +# OPTION_LIST='xmlsup=libxml2,rownode=b'; +#SELECT * FROM t1; +#INSERT INTO t1 VALUES ('ИКЛМН'); +#SELECT c, HEX(c) FROM t1; +#DROP TABLE t1; +#CREATE TABLE t1 +#( +# c CHAR(16) CHARACTER SET cp1251 +#) ENGINE=CONNECT TABLE_TYPE=XML FILE_NAME='cp1251.xml' +# OPTION_LIST='xmlsup=libxml2,rownode=b'; +#SELECT * FROM t1; +#INSERT INTO t1 VALUES ('ОПРСТ'); +#SELECT c, HEX(c) FROM t1; +#DROP TABLE t1; --echo # diff --git a/storage/connect/tabjmg.cpp b/storage/connect/tabjmg.cpp index ba3e1c3e7c0..850d9e5fa9b 100644 --- a/storage/connect/tabjmg.cpp +++ b/storage/connect/tabjmg.cpp @@ -72,7 +72,7 @@ bool JMGDISC::Find(PGLOBAL g) bool JMGDISC::ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt, int ncol, int k) { - const char *key; + const char *key, *utf; char colname[65]; char fmt[129]; bool rc = true; @@ -101,7 +101,10 @@ bool JMGDISC::ColDesc(PGLOBAL g, jobject obj, char *pcn, char *pfmt, continue; jkey = (jstring)Jcp->env->CallObjectMethod(Jcp->job, bvnameid); - key = Jcp->env->GetStringUTFChars(jkey, (jboolean)false); + utf = Jcp->env->GetStringUTFChars(jkey, nullptr); + key = PlugDup(g, utf); + Jcp->env->ReleaseStringUTFChars(jkey, utf); + Jcp->env->DeleteLocalRef(jkey); if (pcn) { strncpy(colname, pcn, 64); @@ -457,8 +460,8 @@ PSZ JMGCOL::GetJpath(PGLOBAL g, bool proj) } else *p2++ = *p1; - *p2 = 0; - return projpath; + *p2 = 0; + return projpath; } else return Jpath; diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp index da5d134f347..9121a0453e5 100644 --- a/storage/connect/tabpivot.cpp +++ b/storage/connect/tabpivot.cpp @@ -107,12 +107,12 @@ bool PIVAID::SkipColumn(PCOLRES crp, char *skc) /***********************************************************************/ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) { - char *p, *query, *colname, *skc, buf[64]; - int ndif, nblin, w = 0; - bool b = false; - PVAL valp; - PQRYRES qrp; - PCOLRES *pcrp, crp, fncrp = NULL; + char *p, *query, *colname, *skc, buf[64]; + int ndif, nblin, w = 0; + bool b = false; + PVAL valp; + PQRYRES qrp; + PCOLRES *pcrp, crp, fncrp = NULL; try { // Are there columns to skip? @@ -186,7 +186,7 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } // endif picol - // Prepare the column list + // Prepare the column list for (pcrp = &Qryp->Colresp; crp = *pcrp; ) if (SkipColumn(crp, skc)) { // Ignore this column @@ -205,95 +205,95 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } else pcrp = &crp->Next; - if (!Rblkp) { - strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); - goto err; - } else if (!fncrp) { - strcpy(g->Message, MSG(NO_DEF_FNCCOL)); - goto err; - } // endif + if (!Rblkp) { + strcpy(g->Message, MSG(NO_DEF_PIVOTCOL)); + goto err; + } else if (!fncrp) { + strcpy(g->Message, MSG(NO_DEF_FNCCOL)); + goto err; + } // endif - if (Tabsrc) { - Myc.Close(); - b = false; + if (Tabsrc) { + Myc.Close(); + b = false; - // Before calling sort, initialize all - nblin = Qryp->Nblin; + // Before calling sort, initialize all + nblin = Qryp->Nblin; - Index.Size = nblin * sizeof(int); - Index.Sub = TRUE; // Should be small enough + Index.Size = nblin * sizeof(int); + Index.Sub = TRUE; // Should be small enough - if (!PlgDBalloc(g, NULL, Index)) - goto err; + if (!PlgDBalloc(g, NULL, Index)) + goto err; - Offset.Size = (nblin + 1) * sizeof(int); - Offset.Sub = TRUE; // Should be small enough + Offset.Size = (nblin + 1) * sizeof(int); + Offset.Sub = TRUE; // Should be small enough - if (!PlgDBalloc(g, NULL, Offset)) - goto err; + if (!PlgDBalloc(g, NULL, Offset)) + goto err; - ndif = Qsort(g, nblin); + ndif = Qsort(g, nblin); - if (ndif < 0) // error - goto err; + if (ndif < 0) // error + goto err; - } else { - // The query was limited, we must get pivot column values - // Returned values must be in their original character set - // if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX) - // goto err; + } else { + // The query was limited, we must get pivot column values + // Returned values must be in their original character set + // if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX) + // goto err; - query = (char*)PlugSubAlloc(g, NULL, 0); - sprintf(query, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname); - PlugSubAlloc(g, NULL, strlen(query) + 1); - Myc.FreeResult(); + query = (char*)PlugSubAlloc(g, NULL, 0); + sprintf(query, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname); + PlugSubAlloc(g, NULL, strlen(query) + 1); + Myc.FreeResult(); - // Send the source command to MySQL - if (Myc.ExecSQL(g, query, &w) == RC_FX) - goto err; + // Send the source command to MySQL + if (Myc.ExecSQL(g, query, &w) == RC_FX) + goto err; - // We must have a storage query to get pivot column values - if (!(qrp = Myc.GetResult(g, true))) - goto err; + // We must have a storage query to get pivot column values + if (!(qrp = Myc.GetResult(g, true))) + goto err; - Myc.Close(); - b = false; + Myc.Close(); + b = false; - // Get the column list - crp = qrp->Colresp; - Rblkp = crp->Kdata; - ndif = qrp->Nblin; - } // endif Tabsrc + // Get the column list + crp = qrp->Colresp; + Rblkp = crp->Kdata; + ndif = qrp->Nblin; + } // endif Tabsrc - // Allocate the Value used to retieve column names - if (!(valp = AllocateValue(g, Rblkp->GetType(), - Rblkp->GetVlen(), - Rblkp->GetPrec()))) - goto err; + // Allocate the Value used to retieve column names + if (!(valp = AllocateValue(g, Rblkp->GetType(), + Rblkp->GetVlen(), + Rblkp->GetPrec()))) + goto err; - // Now make the functional columns - for (int i = 0; i < ndif; i++) { - if (i) { - crp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); - memcpy(crp, fncrp, sizeof(COLRES)); - } else - crp = fncrp; - - // Get the value that will be the generated column name - if (Tabsrc) - valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]); - else - valp->SetValue_pvblk(Rblkp, i); - - colname = valp->GetCharString(buf); - crp->Name = PlugDup(g, colname); - crp->Flag = 1; - - // Add this column - *pcrp = crp; - crp->Next = NULL; - pcrp = &crp->Next; - } // endfor i + // Now make the functional columns + for (int i = 0; i < ndif; i++) { + if (i) { + crp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES)); + memcpy(crp, fncrp, sizeof(COLRES)); + } else + crp = fncrp; + + // Get the value that will be the generated column name + if (Tabsrc) + valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]); + else + valp->SetValue_pvblk(Rblkp, i); + + colname = valp->GetCharString(buf); + crp->Name = PlugDup(g, colname); + crp->Flag = 1; + + // Add this column + *pcrp = crp; + crp->Next = NULL; + pcrp = &crp->Next; + } // endfor i // We added ndif columns and removed 2 (picol and fncol) Qryp->Nbcol += (ndif - 2); @@ -306,10 +306,10 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } // end catch err: - if (b) - Myc.Close(); + if (b) + Myc.Close(); - return NULL; + return NULL; } // end of MakePivotColumns /***********************************************************************/ diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp index 59666d4e127..325f36b1e19 100644 --- a/storage/connect/tabutil.cpp +++ b/storage/connect/tabutil.cpp @@ -429,7 +429,7 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) char buf[MAX_STR]; strcpy(buf, g->Message); - sprintf(g->Message, "Error accessing %s.%s: %s", db, name, buf); + snprintf(g->Message, MAX_STR, "Error accessing %s.%s: %s", db, name, buf); hc->tshp = NULL; goto err; } // endif Define -- cgit v1.2.1 From ad09ea0df0bfb6549ab85dc8c882b32ed763bffe Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 14 Oct 2018 17:56:02 +0200 Subject: - Implement the CHECK TABLE statement and accept REPAIR and ANALYZE modified: storage/connect/connect.cc modified: storage/connect/ha_connect.cc modified: storage/connect/ha_connect.h modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabmysql.cpp modified: storage/connect/tabodbc.cpp - MDEV-17212: Test if NumResultCols is implemented by the data source modified: storage/connect/odbconn.cpp - Change error type in Optimize modified: storage/connect/ha_connect.cc - Update version date modified: storage/connect/ha_connect.cc - Fix truncating error messages on first unrecognized latin1 character modified: storage/connect/ha_connect.cc - Fix MDEV-17343 Reject multi-table UPDATE/DELETE commands that crash on some systems modified: storage/connect/ha_connect.cc modified: storage/connect/tabext.cpp - Try fix some failing tests modified: storage/connect/mysql-test/connect/r/jdbc_postgresql.result modified: storage/connect/mysql-test/connect/r/odbc_postgresql.result - Typo modified: storage/connect/global.h --- storage/connect/connect.cc | 2 +- storage/connect/global.h | 4 +- storage/connect/ha_connect.cc | 109 ++++++++++++++++----- storage/connect/ha_connect.h | 6 +- .../mysql-test/connect/r/jdbc_postgresql.result | 2 +- .../mysql-test/connect/r/odbc_postgresql.result | 18 ++-- storage/connect/odbconn.cpp | 10 +- storage/connect/tabext.cpp | 6 ++ storage/connect/tabjdbc.cpp | 9 +- storage/connect/tabmysql.cpp | 11 ++- storage/connect/tabodbc.cpp | 13 ++- 11 files changed, 131 insertions(+), 59 deletions(-) diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index f9bcffd4fdc..2460449ac62 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -255,7 +255,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, try { if (!c1) { - if (mode == MODE_INSERT) +// if (mode == MODE_INSERT) or CHECK TABLE // Allocate all column blocks for that table tdbp->ColDB(g, NULL, 0); diff --git a/storage/connect/global.h b/storage/connect/global.h index 472d09408c3..36e8a311124 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -1,7 +1,7 @@ /***********************************************************************/ /* GLOBAL.H: Declaration file used by all CONNECT implementations. */ /* (C) Copyright MariaDB Corporation Ab */ -/* Author Olivier Bertrand 1993-2017 */ +/* Author Olivier Bertrand 1993-2018 */ /***********************************************************************/ /***********************************************************************/ @@ -192,7 +192,7 @@ typedef struct _global { /* Global structure */ PACTIVITY Activityp; char Message[MAX_STR]; ulong More; /* Used by jsonudf */ - int Createas; /* To pass info to created table */ + int Createas; /* To pass multi to ext tables */ void *Xchk; /* indexes in create/alter */ short Alchecked; /* Checked for ALTER */ short Mrr; /* True when doing mrr */ diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 4dff4bc31ce..27deefc45e5 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,12 +170,12 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0007 August 06, 2018"; + char version[] = "Version 1.06.0008 October 06, 2018"; #if defined(__WIN__) - char compver[]= "Version 1.06.0007 " __DATE__ " " __TIME__; - char slash= '\\'; + char compver[] = "Version 1.06.0008 " __DATE__ " " __TIME__; + char slash = '\\'; #else // !__WIN__ - char slash= '/'; + char slash = '/'; #endif // !__WIN__ } // extern "C" @@ -3290,7 +3290,59 @@ ha_rows ha_connect::records() } // end of records -/** +int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt) +{ + int rc = HA_ADMIN_OK; + PGLOBAL g = ((table && table->in_use) ? GetPlug(table->in_use, xp) : + (xp) ? xp->g : NULL); + DBUG_ENTER("ha_connect::check"); + + if (!g || !table || xmod != MODE_READ) + DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR); + + // Do not close the table if it was opened yet (possible?) + if (IsOpened()) { + if (IsPartitioned() && CheckColumnList(g)) // map can have been changed + rc = HA_ADMIN_CORRUPT; + else if (tdbp->OpenDB(g)) // Rewind table + rc = HA_ADMIN_CORRUPT; + + } else if (xp->CheckQuery(valid_query_id)) { + tdbp = NULL; // Not valid anymore + + if (OpenTable(g, false)) + rc = HA_ADMIN_CORRUPT; + + } else // possible? + DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR); + + if (rc == HA_ADMIN_OK) { + TABTYPE type = GetTypeID(GetStringOption("Type", "*")); + + if (IsFileType(type)) { + if (check_opt->flags & T_MEDIUM) { + // TO DO + do { + if ((rc = CntReadNext(g, tdbp)) == RC_FX) + break; + + } while (rc != RC_EF); + + rc = (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT; + } else if (check_opt->flags & T_EXTEND) { + // TO DO + } // endif's flags + + } // endif file type + + } else + PushWarning(g, thd, 1); + + DBUG_RETURN(rc); +} // end of check + + + /** Return an error message specific to this handler. @param error error code previously returned by handler @@ -3309,7 +3361,8 @@ bool ha_connect::get_error_message(int error, String* buf) if (trace(1)) htrc("GEM(%d): %s\n", error, g->Message); - buf->append(g->Message); + buf->append(ErrConvString(g->Message, strlen(g->Message), + &my_charset_latin1).ptr()); } else buf->append("Cannot retrieve error message"); @@ -3424,7 +3477,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); rc = 0; } else - rc = HA_ERR_INTERNAL_ERROR; + rc = HA_ERR_CRASHED_ON_USAGE; // Table must be repaired } // endif rc @@ -3440,7 +3493,10 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*) rc = HA_ERR_INTERNAL_ERROR; } // end catch - return rc; + if (rc) + my_message(ER_WARN_DATA_OUT_OF_RANGE, g->Message, MYF(0)); + + return rc; } // end of optimize /** @@ -4501,14 +4557,16 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, // case SQLCOM_REPLACE_SELECT: // newmode= MODE_UPDATE; // To be checked // break; - case SQLCOM_DELETE: - case SQLCOM_DELETE_MULTI: - case SQLCOM_TRUNCATE: + case SQLCOM_DELETE_MULTI: + *cras = true; + case SQLCOM_DELETE: + case SQLCOM_TRUNCATE: newmode= MODE_DELETE; break; - case SQLCOM_UPDATE: - case SQLCOM_UPDATE_MULTI: - newmode= MODE_UPDATE; + case SQLCOM_UPDATE_MULTI: + *cras = true; + case SQLCOM_UPDATE: + newmode= MODE_UPDATE; break; case SQLCOM_SELECT: case SQLCOM_OPTIMIZE: @@ -4533,8 +4591,10 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, newmode= MODE_ANY; break; // } // endif partitioned - - default: + case SQLCOM_REPAIR: // TODO implement it + newmode = MODE_UPDATE; + break; + default: htrc("Unsupported sql_command=%d\n", thd_sql_command(thd)); strcpy(g->Message, "CONNECT Unsupported command"); my_message(ER_NOT_ALLOWED_COMMAND, g->Message, MYF(0)); @@ -4546,17 +4606,17 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, switch (thd_sql_command(thd)) { case SQLCOM_CREATE_TABLE: *chk= true; - *cras= true; + case SQLCOM_UPDATE_MULTI: + case SQLCOM_DELETE_MULTI: + *cras= true; case SQLCOM_INSERT: case SQLCOM_LOAD: case SQLCOM_INSERT_SELECT: // case SQLCOM_REPLACE: // case SQLCOM_REPLACE_SELECT: case SQLCOM_DELETE: - case SQLCOM_DELETE_MULTI: case SQLCOM_TRUNCATE: case SQLCOM_UPDATE: - case SQLCOM_UPDATE_MULTI: case SQLCOM_SELECT: case SQLCOM_OPTIMIZE: case SQLCOM_SET_OPTION: @@ -4584,8 +4644,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, break; // } // endif partitioned - case SQLCOM_CHECK: // TODO implement it - case SQLCOM_END: // Met in procedures: IF(EXISTS(SELECT... + case SQLCOM_CHECK: // TODO implement it + case SQLCOM_ANALYZE: // TODO implement it + case SQLCOM_END: // Met in procedures: IF(EXISTS(SELECT... newmode= MODE_READ; break; default: @@ -4867,7 +4928,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) #endif // 0 if (cras) - g->Createas= 1; // To tell created table to ignore FLAG + g->Createas= 1; // To tell external tables of a multi-table command if (trace(1)) { #if 0 @@ -7247,10 +7308,10 @@ maria_declare_plugin(connect) PLUGIN_LICENSE_GPL, connect_init_func, /* Plugin Init */ connect_done_func, /* Plugin Deinit */ - 0x0107, /* version number (1.05) */ + 0x0106, /* version number (1.06) */ NULL, /* status variables */ connect_system_variables, /* system variables */ - "1.06.0007", /* string version */ + "1.06.0008", /* string version */ MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index f0fa9b70513..6bce46ead95 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -347,11 +347,7 @@ PFIL CondFilter(PGLOBAL g, Item *cond); //PFIL CheckFilter(PGLOBAL g); /** admin commands - called from mysql_admin_table */ -virtual int check(THD* thd, HA_CHECK_OPT* check_opt) -{ - // TODO: implement it - return HA_ADMIN_OK; // Just to avoid error message with checktables -} // end of check +virtual int check(THD* thd, HA_CHECK_OPT* check_opt); /** Number of rows in table. It will only be called if diff --git a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result index 7969672dd66..f9510064b35 100644 --- a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result +++ b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result @@ -1,4 +1,4 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.3/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; CREATE TABLE t2 ( command varchar(128) not null, number int(5) not null flag=1, diff --git a/storage/connect/mysql-test/connect/r/odbc_postgresql.result b/storage/connect/mysql-test/connect/r/odbc_postgresql.result index 3426d23e29c..dc23dbdb990 100644 --- a/storage/connect/mysql-test/connect/r/odbc_postgresql.result +++ b/storage/connect/mysql-test/connect/r/odbc_postgresql.result @@ -99,9 +99,9 @@ Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Bu mtr public t1 a 4 int4 10 4 0 10 0 mtr public t2 a 4 int4 10 4 0 10 0 mtr public v1 a 4 int4 10 4 0 10 1 -mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0 -mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0 -mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1 +mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1 DROP TABLE t1; # All columns in the schemas "public" and "schema1" CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.%.%'; @@ -110,16 +110,16 @@ Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Bu mtr public t1 a 4 int4 10 4 0 10 0 mtr public t2 a 4 int4 10 4 0 10 0 mtr public v1 a 4 int4 10 4 0 10 1 -mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0 -mtr schema1 t2 a 1 bpchar 10 60 NULL NULL 0 -mtr schema1 v1 a 1 bpchar 10 60 NULL NULL 1 +mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 t2 a 1 bpchar 10 40 NULL NULL 0 +mtr schema1 v1 a 1 bpchar 10 40 NULL NULL 1 DROP TABLE t1; # All tables "t1" in all schemas CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.%.t1'; SELECT * FROM t1 ORDER BY Table_Schema, Table_Name; Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks mtr public t1 a 4 int4 10 4 0 10 0 -mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0 +mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 DROP TABLE t1; # Table "t1" in the schema "public" CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.public.t1'; @@ -131,14 +131,14 @@ DROP TABLE t1; CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='%.schema1.t1'; SELECT * FROM t1 ORDER BY Table_Schema, Table_Name; Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks -mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0 +mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 DROP TABLE t1; # All tables "t1" in all schemas (Catalog name is ignored by PostgreSQL) CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='DSN=ConnectEnginePostgresql;UID=mtr;PWD=mtr' CATFUNC=Columns TABNAME='xxx.%.t1'; SELECT * FROM t1 ORDER BY Table_Schema, Table_Name; Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks mtr public t1 a 4 int4 10 4 0 10 0 -mtr schema1 t1 a 1 bpchar 10 60 NULL NULL 0 +mtr schema1 t1 a 1 bpchar 10 40 NULL NULL 0 DROP TABLE t1; # # Checking tables diff --git a/storage/connect/odbconn.cpp b/storage/connect/odbconn.cpp index f7b1a43a95d..6687513fa6c 100644 --- a/storage/connect/odbconn.cpp +++ b/storage/connect/odbconn.cpp @@ -2354,11 +2354,11 @@ int ODBConn::GetCatInfo(CATPARM *cap) if (!Check(rc)) ThrowDBX(rc, fnc, hstmt); - rc = SQLNumResultCols(hstmt, &ncol); - - // n because we no more ignore the first column - if ((n = (UWORD)qrp->Nbcol) > (UWORD)ncol) - ThrowDBX(MSG(COL_NUM_MISM)); + // Some data source do not implement SQLNumResultCols + if (Check(SQLNumResultCols(hstmt, &ncol))) + // n because we no more ignore the first column + if ((n = (UWORD)qrp->Nbcol) > (UWORD)ncol) + ThrowDBX(MSG(COL_NUM_MISM)); // Unconditional to handle STRBLK's pval = (PVAL *)PlugSubAlloc(g, NULL, n * sizeof(PVAL)); diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index 139e4199ed9..f2d5eb0e69d 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -125,6 +125,12 @@ EXTDEF::EXTDEF(void) /***********************************************************************/ bool EXTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { + if (g->Createas) { + strcpy(g->Message, + "Multiple-table UPDATE/DELETE commands are not supported"); + return true; + } // endif multi + Desc = NULL; Tabname = GetStringCatInfo(g, "Name", (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index 275b5edaeae..adb3fc4fb51 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -1157,8 +1157,9 @@ bool TDBXJDC::OpenDB(PGLOBAL g) /* Get the command to execute. */ /*********************************************************************/ if (!(Cmdlist = MakeCMD(g))) { - Jcp->Close(); - return true; + // Next lines commented out because of CHECK TABLE + //Jcp->Close(); + //return true; } // endif Query Rows = 1; @@ -1189,8 +1190,10 @@ int TDBXJDC::ReadDB(PGLOBAL g) Fpos++; // Used for progress info Cmdlist = (Nerr > Mxr) ? NULL : Cmdlist->Next; return RC_OK; - } else + } else { + PushWarning(g, this, 1); return RC_EF; + } // endif Cmdlist } // end of ReadDB diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 605b3822430..ceffafac02c 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -1587,8 +1587,9 @@ bool TDBMYEXC::OpenDB(PGLOBAL g) /* Get the command to execute. */ /*********************************************************************/ if (!(Cmdlist = MakeCMD(g))) { - Myc.Close(); - return true; + // Next lines commented out because of CHECK TABLE + //Myc.Close(); + //return true; } // endif Cmdlist return false; @@ -1647,8 +1648,10 @@ int TDBMYEXC::ReadDB(PGLOBAL g) ++N; return RC_OK; - } else - return RC_EF; + } else { + PushWarning(g, this, 1); + return RC_EF; + } // endif Cmdlist } // end of ReadDB diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index f7bc3934fbd..fddfb0c0420 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -1249,9 +1249,10 @@ bool TDBXDBC::OpenDB(PGLOBAL g) /* Get the command to execute. */ /*********************************************************************/ if (!(Cmdlist = MakeCMD(g))) { - Ocp->Close(); - return true; - } // endif Query + // Next lines commented out because of CHECK TABLE + //Ocp->Close(); + //return true; + } // endif Cmdlist Rows = 1; return false; @@ -1274,8 +1275,10 @@ int TDBXDBC::ReadDB(PGLOBAL g) Fpos++; // Used for progress info Cmdlist = (Nerr > Mxr) ? NULL : Cmdlist->Next; return RC_OK; - } else - return RC_EF; + } else { + PushWarning(g, this, 1); + return RC_EF; + } // endif Cmdlist } // end of ReadDB -- cgit v1.2.1 From 28000d814135cd6bfe2174004e2b56c9b3308711 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 14 Oct 2018 19:39:21 +0200 Subject: Restore mysql_exec.result --- storage/connect/mysql-test/connect/r/mysql_exec.result | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/storage/connect/mysql-test/connect/r/mysql_exec.result b/storage/connect/mysql-test/connect/r/mysql_exec.result index c0400bc82e7..cc77240503b 100644 --- a/storage/connect/mysql-test/connect/r/mysql_exec.result +++ b/storage/connect/mysql-test/connect/r/mysql_exec.result @@ -35,6 +35,8 @@ insert ignore into t1(id) values(NULL) 1 1 Affected rows Warning 0 1364 Field 'msg' doesn't have a default value update t1 set msg = 'Four' where id = 4 0 1 Affected rows select * from t1 0 2 Result set columns +Warnings: +Warning 1105 Result set columns # # Checking Using Procedure # @@ -48,9 +50,13 @@ CALL p1('insert ignore into t1(id) values(NULL)'); command warnings number message insert ignore into t1(id) values(NULL) 1 1 Affected rows Warning 0 1364 Field 'msg' doesn't have a default value +Warnings: +Warning 1105 Affected rows CALL p1('update t1 set msg = "Five" where id = 5'); command warnings number message update t1 set msg = "Five" where id = 5 0 1 Affected rows +Warnings: +Warning 1105 Affected rows DROP PROCEDURE p1; DROP TABLE t1; connection slave; -- cgit v1.2.1 From 4a572631aa68d363e517216388dd814bc253b1b6 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Tue, 4 Dec 2018 23:26:47 +0100 Subject: - Make PlugSubAlloc to be exportable Suppress unused parameter from PlugSubSet modified: storage/connect/global.h modified: storage/connect/plugutil.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/user_connect.cc - Fix a bug making column catalog XML tables fail modified: storage/connect/tabxml.cpp - Comment out wrong message modified: storage/connect/ha_connect.cc - Update error message when sorting an ODBC table fails modified: storage/connect/tabodbc.cpp - Add error message when gettting an address from an OEM fails. modified: storage/connect/reldef.cpp - Make some modifications useful for OEM module writting Export discovery functions for CSV, JDBC and XML Remove unuseful include from tabjson.h Move TDBXML::data_charset function from header file to source modified: storage/connect/tabfmt.h modified: storage/connect/tabjson.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h - Update test result modified: storage/connect/mysql-test/connect/r/jdbc_oracle.result --- storage/connect/global.h | 6 +- storage/connect/ha_connect.cc | 11 +- storage/connect/jsonudf.cpp | 12 +- .../mysql-test/connect/r/jdbc_oracle.result | 18 +- storage/connect/plugutil.cpp | 28 +- storage/connect/reldef.cpp | 11 +- storage/connect/tabdos.cpp | 29 +- storage/connect/tabfmt.h | 2 +- storage/connect/tabjson.cpp | 10 +- storage/connect/tabjson.h | 6 +- storage/connect/tabodbc.cpp | 317 +++++++++++---------- storage/connect/tabxml.cpp | 13 +- storage/connect/tabxml.h | 5 +- storage/connect/user_connect.cc | 4 +- 14 files changed, 251 insertions(+), 221 deletions(-) diff --git a/storage/connect/global.h b/storage/connect/global.h index 36e8a311124..dc1e149745f 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -219,11 +219,11 @@ DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir); DllExport BOOL PlugIsAbsolutePath(LPCSTR path); DllExport bool AllocSarea(PGLOBAL, uint); DllExport void FreeSarea(PGLOBAL); -DllExport BOOL PlugSubSet(PGLOBAL, void *, uint); +DllExport BOOL PlugSubSet(void *, uint); +DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t); DllExport char *PlugDup(PGLOBAL g, const char *str); DllExport void *MakePtr(void *, OFFSET); DllExport void htrc(char const *fmt, ...); -//DllExport int GetTraceValue(void); DllExport uint GetTraceValue(void); #if defined(__cplusplus) @@ -233,6 +233,6 @@ DllExport uint GetTraceValue(void); /***********************************************************************/ /* Non exported routine declarations. */ /***********************************************************************/ -void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw +//void *PlugSubAlloc(PGLOBAL, void *, size_t); // Does throw /*-------------------------- End of Global.H --------------------------*/ diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 27deefc45e5..bcb02adf932 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,12 +170,12 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[] = "Version 1.06.0008 October 06, 2018"; + char version[]= "Version 1.06.0008 October 06, 2018"; #if defined(__WIN__) - char compver[] = "Version 1.06.0008 " __DATE__ " " __TIME__; - char slash = '\\'; + char compver[]= "Version 1.06.0008 " __DATE__ " " __TIME__; + char slash= '\\'; #else // !__WIN__ - char slash = '/'; + char slash= '/'; #endif // !__WIN__ } // extern "C" @@ -4191,7 +4191,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) rc= rnd_next(buf); } else { PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp); - strcpy(g->Message, "Not supported by this table type"); +// strcpy(g->Message, "Not supported by this table type"); my_message(ER_ILLEGAL_HA, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; } // endif SetRecpos @@ -4606,6 +4606,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, switch (thd_sql_command(thd)) { case SQLCOM_CREATE_TABLE: *chk= true; + break; case SQLCOM_UPDATE_MULTI: case SQLCOM_DELETE_MULTI: *cras= true; diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index b78d68fddb9..42b276b6090 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -3056,7 +3056,7 @@ my_bool json_array_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) PGLOBAL g = (PGLOBAL)initid->ptr; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JAR); g->N = (int)n; return false; @@ -3099,7 +3099,7 @@ void json_array_grp_clear(UDF_INIT *initid, char*, char*) { PGLOBAL g = (PGLOBAL)initid->ptr; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JAR); g->N = GetJsonGroupSize(); } // end of json_array_grp_clear @@ -3133,7 +3133,7 @@ my_bool json_object_grp_init(UDF_INIT *initid, UDF_ARGS *args, char *message) PGLOBAL g = (PGLOBAL)initid->ptr; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JOB); g->N = (int)n; return false; @@ -3170,7 +3170,7 @@ void json_object_grp_clear(UDF_INIT *initid, char*, char*) { PGLOBAL g = (PGLOBAL)initid->ptr; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Activityp = (PACTIVITY)JsonNew(g, TYPE_JOB); g->N = GetJsonGroupSize(); } // end of json_object_grp_clear @@ -4419,7 +4419,7 @@ char *json_file(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); fn = MakePSZ(g, args, 0); if (args->arg_count > 1) { @@ -5663,7 +5663,7 @@ char *jbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result, if (bsp && !bsp->Changed) goto fin; - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Xchk = NULL; fn = MakePSZ(g, args, 0); pretty = (args->arg_count > 2 && args->args[2]) ? (int)*(longlong*)args->args[2] : 3; diff --git a/storage/connect/mysql-test/connect/r/jdbc_oracle.result b/storage/connect/mysql-test/connect/r/jdbc_oracle.result index 2e36891a037..ec314c5f072 100644 --- a/storage/connect/mysql-test/connect/r/jdbc_oracle.result +++ b/storage/connect/mysql-test/connect/r/jdbc_oracle.result @@ -8,12 +8,19 @@ SELECT * FROM t2 WHERE command = 'drop table employee'; command number message drop table employee 0 Execute: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist +Warnings: +Warning 1105 Execute: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist + SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary number(8,2))'; command number message create table employee (id int not null, name varchar(32), title char(16), salary number(8,2)) 0 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)"; command number message insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows +Warnings: +Warning 1105 Affected rows CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables CONNECTION='jdbc:oracle:thin:@localhost:1521:xe' OPTION_LIST='User=system,Password=manager'; @@ -27,8 +34,8 @@ OPTION_LIST='User=system,Password=manager'; SELECT * FROM t1; Table_Cat Table_Schema Table_Name Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Radix Nullable Remarks NULL SYSTEM EMPLOYEE ID 3 NUMBER 38 0 0 10 0 NULL -NULL SYSTEM EMPLOYEE NAME 12 VARCHAR2 32 0 0 10 1 NULL -NULL SYSTEM EMPLOYEE TITLE 1 CHAR 16 0 0 10 1 NULL +NULL SYSTEM EMPLOYEE NAME 12 VARCHAR2 32 0 NULL 10 1 NULL +NULL SYSTEM EMPLOYEE TITLE 1 CHAR 16 0 NULL 10 1 NULL NULL SYSTEM EMPLOYEE SALARY 3 NUMBER 8 0 2 10 1 NULL DROP TABLE t1; CREATE SERVER 'oracle' FOREIGN DATA WRAPPER 'oracle.jdbc.driver.OracleDriver' OPTIONS ( @@ -52,7 +59,7 @@ Note 1105 EMPLOYEE: 1 affected rows SELECT * FROM t1; ID NAME TITLE SALARY 4567 Trump Engineer 12560.50 -6214 Clinton Retired 0.00 +6214 Clinton Retired NULL DELETE FROM t1 WHERE id = 6214; Warnings: Note 1105 EMPLOYEE: 1 affected rows @@ -63,8 +70,7 @@ DROP TABLE t1; SELECT * FROM t2 WHERE command = 'drop table employee'; command number message drop table employee 0 Affected rows +Warnings: +Warning 1105 Affected rows DROP TABLE t2; DROP SERVER 'oracle'; -SET GLOBAL connect_jvm_path=NULL; -SET GLOBAL connect_class_path=NULL; -SET GLOBAL time_zone = SYSTEM; diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index 887527e38ab..048f00be75f 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -514,27 +514,31 @@ void FreeSarea(PGLOBAL g) /* Here there should be some verification done such as validity of */ /* the address and size not larger than memory size. */ /***********************************************************************/ -BOOL PlugSubSet(PGLOBAL g __attribute__((unused)), void *memp, uint size) +BOOL PlugSubSet(void *memp, uint size) { PPOOLHEADER pph = (PPOOLHEADER)memp; pph->To_Free = (OFFSET)sizeof(POOLHEADER); pph->FreeBlk = size - pph->To_Free; - return FALSE; } /* end of PlugSubSet */ +/***********************************************************************/ +/* Use it to export a function that do throwing. */ +/***********************************************************************/ +void *DoThrow(int n) +{ + throw n; +} /* end of DoThrow */ + /***********************************************************************/ /* Program for sub-allocating one item in a storage area. */ -/* Note: SubAlloc routines of OS/2 are no more used to increase the */ -/* code portability and avoid problems when a grammar compiled under */ -/* one version of OS/2 is used under another version. */ -/* The simple way things are done here is also based on the fact */ -/* that no freeing of suballocated blocks is permitted in Plug. */ +/* The simple way things are done here is based on the fact */ +/* that no freeing of suballocated blocks is permitted in CONNECT. */ /***********************************************************************/ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) - { - PPOOLHEADER pph; /* Points on area header. */ +{ + PPOOLHEADER pph; /* Points on area header. */ if (!memp) /*******************************************************************/ @@ -559,8 +563,8 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) if (trace(1)) htrc("PlugSubAlloc: %s\n", g->Message); - throw 1234; - } /* endif size OS32 code */ + DoThrow(1234); + } /* endif size OS32 code */ /*********************************************************************/ /* Do the suballocation the simplest way. */ @@ -574,7 +578,7 @@ void *PlugSubAlloc(PGLOBAL g, void *memp, size_t size) memp, pph->To_Free, pph->FreeBlk); return (memp); - } /* end of PlugSubAlloc */ +} /* end of PlugSubAlloc */ /***********************************************************************/ /* Program for sub-allocating and copying a string in a storage area. */ diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index e4f169575f8..30d8063d1a6 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -522,8 +522,15 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) // Get the function returning an instance of the external DEF class if (!(getdef = (XGETDEF)GetProcAddress((HINSTANCE)Hdll, getname))) { - sprintf(g->Message, MSG(PROCADD_ERROR), GetLastError(), getname); - FreeLibrary((HMODULE)Hdll); + char buf[256]; + DWORD rc = GetLastError(); + + sprintf(g->Message, MSG(PROCADD_ERROR), rc, getname); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0, + (LPTSTR)buf, sizeof(buf), NULL); + strcat(strcat(g->Message, ": "), buf); + FreeLibrary((HMODULE)Hdll); return NULL; } // endif getdef #else // !__WIN__ diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp index 29cbbb35765..e336be8325b 100644 --- a/storage/connect/tabdos.cpp +++ b/storage/connect/tabdos.cpp @@ -2045,24 +2045,25 @@ int TDBDOS::GetMaxSize(PGLOBAL g) if (!Cardinality(NULL)) { int len = GetFileLength(g); - if (len >= 0) { - int rec; + if (len >= 0) { + int rec; - if (trace(1)) - htrc("Estimating lines len=%d ending=%d/n", - len, ((PDOSDEF)To_Def)->Ending); + if (trace(1)) + htrc("Estimating lines len=%d ending=%d/n", + len, ((PDOSDEF)To_Def)->Ending); - /*****************************************************************/ - /* Estimate the number of lines in the table (if not known) by */ - /* dividing the file length by minimum record length. */ - /*****************************************************************/ - rec = EstimatedLength() + ((PDOSDEF)To_Def)->Ending; - MaxSize = (len + rec - 1) / rec; + /*****************************************************************/ + /* Estimate the number of lines in the table (if not known) by */ + /* dividing the file length by minimum record length. */ + /*****************************************************************/ + rec = (AvgLen <= 0 ? rec = EstimatedLength() : AvgLen) + + ((PDOSDEF)To_Def)->Ending; + MaxSize = (len + rec - 1) / rec; - if (trace(1)) - htrc("avglen=%d MaxSize%d\n", rec, MaxSize); + if (trace(1)) + htrc("avglen=%d MaxSize%d\n", rec, MaxSize); - } // endif len + } // endif len } else MaxSize = Cardinality(g); diff --git a/storage/connect/tabfmt.h b/storage/connect/tabfmt.h index 396bba568ff..10f0757c60b 100644 --- a/storage/connect/tabfmt.h +++ b/storage/connect/tabfmt.h @@ -13,7 +13,7 @@ typedef class TDBFMT *PTDBFMT; /***********************************************************************/ /* Functions used externally. */ /***********************************************************************/ -PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info); +DllExport PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info); /***********************************************************************/ /* CSV table. */ diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index 9e4f5ab987d..d20e793ff88 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -299,7 +299,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) memset(G, 0, sizeof(GLOBAL)); G->Sarea_Size = tdp->Lrecl * 10; G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); - PlugSubSet(G, G->Sarea, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); G->jump_level = 0; tjnp->SetG(G); @@ -670,7 +670,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) memset(G, 0, sizeof(GLOBAL)); G->Sarea_Size = Lrecl * 10; G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); - PlugSubSet(G, G->Sarea, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); G->jump_level = 0; ((TDBJSN*)tdbp)->G = G; } else { @@ -963,7 +963,7 @@ int TDBJSN::ReadDB(PGLOBAL g) return rc; // Recover the memory used for parsing - PlugSubSet(G, G->Sarea, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); if ((Row = ParseJson(G, To_Line, strlen(To_Line), &Pretty, &Comma))) { Row = FindRow(g); @@ -1079,13 +1079,13 @@ int TDBJSN::MakeTopTree(PGLOBAL g, PJSON jsp) } // end of PrepareWriting /***********************************************************************/ -/* WriteDB: Data Base write routine for DOS access method. */ +/* WriteDB: Data Base write routine for JSON access method. */ /***********************************************************************/ int TDBJSN::WriteDB(PGLOBAL g) { int rc = TDBDOS::WriteDB(g); - PlugSubSet(G, G->Sarea, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); Row->Clear(); return rc; } // end of WriteDB diff --git a/storage/connect/tabjson.h b/storage/connect/tabjson.h index 2ff72905e86..fcbfe4ed1ec 100644 --- a/storage/connect/tabjson.h +++ b/storage/connect/tabjson.h @@ -1,11 +1,11 @@ /*************** tabjson H Declares Source Code File (.H) **************/ /* Name: tabjson.h Version 1.3 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */ /* */ /* This file contains the JSON classes declares. */ /***********************************************************************/ -#include "osutil.h" +//#include "osutil.h" // Unuseful and bad for OEM #include "block.h" #include "colblk.h" #include "json.h" @@ -16,7 +16,7 @@ typedef class JSONDEF *PJDEF; typedef class TDBJSON *PJTDB; typedef class JSONCOL *PJCOL; class TDBJSN; -PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); +DllExport PQRYRES JSONColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool); /***********************************************************************/ /* The JSON tree node. Can be an Object or an Array. */ diff --git a/storage/connect/tabodbc.cpp b/storage/connect/tabodbc.cpp index fddfb0c0420..0fa117c3d2f 100644 --- a/storage/connect/tabodbc.cpp +++ b/storage/connect/tabodbc.cpp @@ -5,7 +5,7 @@ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 2000-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2000-2018 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -95,23 +95,23 @@ bool ExactInfo(void); /* Constructor. */ /***********************************************************************/ ODBCDEF::ODBCDEF(void) - { +{ Connect = NULL; Catver = 0; UseCnc = false; - } // end of ODBCDEF constructor +} // end of ODBCDEF constructor /***********************************************************************/ /* DefineAM: define specific AM block values from XDB file. */ /***********************************************************************/ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) - { +{ Desc = Connect = GetStringCatInfo(g, "Connect", NULL); if (!Connect && !Catfunc) { sprintf(g->Message, "Missing connection for ODBC table %s", Name); return true; - } // endif Connect + } // endif Connect if (EXTDEF::DefineAM(g, am, poff)) return true; @@ -123,13 +123,13 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Qto= GetIntCatInfo("QueryTimeout", DEFAULT_QUERY_TIMEOUT); UseCnc = GetBoolCatInfo("UseDSN", false); return false; - } // end of DefineAM +} // end of DefineAM /***********************************************************************/ /* GetTable: makes a new Table Description Block. */ /***********************************************************************/ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m) - { +{ PTDB tdbp = NULL; /*********************************************************************/ @@ -158,10 +158,10 @@ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m) tdbp = new(g) TDBMUL(tdbp); else if (Multiple == 2) strcpy(g->Message, MSG(NO_ODBC_MUL)); - } // endswitch Catfunc + } // endswitch Catfunc return tdbp; - } // end of GetTable +} // end of GetTable /* -------------------------- Class TDBODBC -------------------------- */ @@ -169,7 +169,7 @@ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m) /* Implementation of the TDBODBC class. */ /***********************************************************************/ TDBODBC::TDBODBC(PODEF tdp) : TDBEXT(tdp) - { +{ Ocp = NULL; Cnp = NULL; @@ -191,19 +191,19 @@ TDBODBC::TDBODBC(PODEF tdp) : TDBEXT(tdp) Ops.UseCnc = false; } // endif tdp - } // end of TDBODBC standard constructor +} // end of TDBODBC standard constructor TDBODBC::TDBODBC(PTDBODBC tdbp) : TDBEXT(tdbp) - { +{ Ocp = tdbp->Ocp; // is that right ? Cnp = tdbp->Cnp; Connect = tdbp->Connect; Ops = tdbp->Ops; - } // end of TDBODBC copy constructor +} // end of TDBODBC copy constructor // Method PTDB TDBODBC::Clone(PTABS t) - { +{ PTDB tp; PODBCCOL cp1, cp2; PGLOBAL g = t->G; // Is this really useful ??? @@ -213,18 +213,18 @@ PTDB TDBODBC::Clone(PTABS t) for (cp1 = (PODBCCOL)Columns; cp1; cp1 = (PODBCCOL)cp1->GetNext()) { cp2 = new(g) ODBCCOL(cp1, tp); // Make a copy NewPointer(t, cp1, cp2); - } // endfor cp1 + } // endfor cp1 return tp; - } // end of CopyOne +} // end of CopyOne /***********************************************************************/ /* Allocate ODBC column description block. */ /***********************************************************************/ PCOL TDBODBC::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) - { +{ return new(g) ODBCCOL(cdp, this, cprec, n); - } // end of MakeCol +} // end of MakeCol /***********************************************************************/ /* Extract the filename from connect string and return it. */ @@ -232,7 +232,7 @@ PCOL TDBODBC::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) /* with a place holder to be used by SetFile. */ /***********************************************************************/ PCSZ TDBODBC::GetFile(PGLOBAL g) - { +{ if (Connect) { char *p1, *p2; int i; @@ -263,18 +263,18 @@ PCSZ TDBODBC::GetFile(PGLOBAL g) memcpy(MulConn, Connect, p1 - Connect); MulConn[p1 - Connect] = '\0'; strcat(strcat(MulConn, "%s"), (p2) ? p2 : ";"); - } // endif p1 + } // endif p1 - } // endif Connect + } // endif Connect return (DBQ) ? DBQ : (PSZ)"???"; - } // end of GetFile +} // end of GetFile /***********************************************************************/ /* Set DBQ and get the new file name into the connect string. */ /***********************************************************************/ void TDBODBC::SetFile(PGLOBAL g, PCSZ fn) - { +{ if (MulConn) { int n = strlen(MulConn) + strlen(fn) - 1; @@ -283,20 +283,20 @@ void TDBODBC::SetFile(PGLOBAL g, PCSZ fn) // of having to reallocate it is reduced. BufSize = n + 6; Connect = (char*)PlugSubAlloc(g, NULL, BufSize); - } // endif n + } // endif n // Make the complete connect string sprintf(Connect, MulConn, fn); - } // endif MultConn + } // endif MultConn DBQ = PlugDup(g, fn); - } // end of SetFile +} // end of SetFile /***********************************************************************/ /* MakeInsert: make the Insert statement used with ODBC connection. */ /***********************************************************************/ bool TDBODBC::MakeInsert(PGLOBAL g) - { +{ PCSZ schmp = NULL; char *catp = NULL, buf[NAM_LEN * 3]; int len = 0; @@ -377,7 +377,7 @@ bool TDBODBC::MakeInsert(PGLOBAL g) } else Query->Append(buf); - } // endfor colp + } // endfor colp Query->Append(") VALUES ("); @@ -390,32 +390,32 @@ bool TDBODBC::MakeInsert(PGLOBAL g) Query->RepLast(')'); return oom; - } // end of MakeInsert +} // end of MakeInsert /***********************************************************************/ /* ODBC Bind Parameter function. */ /***********************************************************************/ bool TDBODBC::BindParameters(PGLOBAL g) - { - PODBCCOL colp; +{ + PODBCCOL colp; - for (colp = (PODBCCOL)Columns; colp; colp = (PODBCCOL)colp->Next) { - colp->AllocateBuffers(g, 0); + for (colp = (PODBCCOL)Columns; colp; colp = (PODBCCOL)colp->Next) { + colp->AllocateBuffers(g, 0); - if (Ocp->BindParam(colp)) - return true; + if (Ocp->BindParam(colp)) + return true; - } // endfor colp + } // endfor colp - return false; - } // end of BindParameters + return false; +} // end of BindParameters #if 0 /***********************************************************************/ /* MakeUpdate: make the SQL statement to send to ODBC connection. */ /***********************************************************************/ char *TDBODBC::MakeUpdate(PGLOBAL g) - { +{ char *qc, *stmt = NULL, cmd[8], tab[96], end[1024]; stmt = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64); @@ -440,60 +440,60 @@ char *TDBODBC::MakeUpdate(PGLOBAL g) strcat(stmt, end); return stmt; - } // end of MakeUpdate +} // end of MakeUpdate /***********************************************************************/ /* MakeDelete: make the SQL statement to send to ODBC connection. */ /***********************************************************************/ char *TDBODBC::MakeDelete(PGLOBAL g) - { - char *qc, *stmt = NULL, cmd[8], from[8], tab[96], end[512]; - - stmt = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64); - memset(end, 0, sizeof(end)); - - if (sscanf(Qrystr, "%s %s `%[^`]`%511c", cmd, from, tab, end) > 2 || - sscanf(Qrystr, "%s %s \"%[^\"]\"%511c", cmd, from, tab, end) > 2) - qc = Ocp->GetQuoteChar(); - else if (sscanf(Qrystr, "%s %s %s%511c", cmd, from, tab, end) > 2) - qc = (Quoted) ? Quote : ""; - else { - strcpy(g->Message, "Cannot use this DELETE command"); - return NULL; - } // endif sscanf - - assert(!stricmp(cmd, "delete") && !stricmp(from, "from")); - strcat(strcat(strcat(strcpy(stmt, "DELETE FROM "), qc), TableName), qc); - - if (*end) { - for (int i = 0; end[i]; i++) - if (end[i] == '`') - end[i] = *qc; - - strcat(stmt, end); - } // endif end - - return stmt; - } // end of MakeDelete +{ + char *qc, *stmt = NULL, cmd[8], from[8], tab[96], end[512]; + + stmt = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64); + memset(end, 0, sizeof(end)); + + if (sscanf(Qrystr, "%s %s `%[^`]`%511c", cmd, from, tab, end) > 2 || + sscanf(Qrystr, "%s %s \"%[^\"]\"%511c", cmd, from, tab, end) > 2) + qc = Ocp->GetQuoteChar(); + else if (sscanf(Qrystr, "%s %s %s%511c", cmd, from, tab, end) > 2) + qc = (Quoted) ? Quote : ""; + else { + strcpy(g->Message, "Cannot use this DELETE command"); + return NULL; + } // endif sscanf + + assert(!stricmp(cmd, "delete") && !stricmp(from, "from")); + strcat(strcat(strcat(strcpy(stmt, "DELETE FROM "), qc), TableName), qc); + + if (*end) { + for (int i = 0; end[i]; i++) + if (end[i] == '`') + end[i] = *qc; + + strcat(stmt, end); + } // endif end + + return stmt; +} // end of MakeDelete #endif // 0 /***********************************************************************/ /* ResetSize: call by TDBMUL when calculating size estimate. */ /***********************************************************************/ void TDBODBC::ResetSize(void) - { +{ MaxSize = -1; if (Ocp && Ocp->IsOpen()) Ocp->Close(); - } // end of ResetSize +} // end of ResetSize /***********************************************************************/ /* ODBC Cardinality: returns table size in number of rows. */ /***********************************************************************/ int TDBODBC::Cardinality(PGLOBAL g) - { +{ if (!g) return (Mode == MODE_ANY && !Srcdef) ? 1 : 0; @@ -526,7 +526,7 @@ int TDBODBC::Cardinality(PGLOBAL g) Cardinal = 10; // To make MySQL happy return Cardinal; - } // end of Cardinality +} // end of Cardinality /***********************************************************************/ /* ODBC Access Method opening routine. */ @@ -535,7 +535,7 @@ int TDBODBC::Cardinality(PGLOBAL g) /* join block of next table if it exists or else are discarted. */ /***********************************************************************/ bool TDBODBC::OpenDB(PGLOBAL g) - { +{ bool rc = true; if (trace(1)) @@ -571,7 +571,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) Fpos = 0; Curpos = 1; return false; - } // endif use + } // endif use /*********************************************************************/ /* Open an ODBC connection for this table. */ @@ -593,7 +593,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) Use = USE_OPEN; // Do it now in case we are recursively called /*********************************************************************/ - /* Make the command and allocate whatever is used for getting results. */ + /* Make the command and allocate whatever is used for getting results*/ /*********************************************************************/ if (Mode == MODE_READ || Mode == MODE_READX) { if (Memory > 1 && !Srcdef) { @@ -624,7 +624,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) } else return true; - } // endif Memory + } // endif Memory if (!(rc = MakeSQL(g, false))) { for (PODBCCOL colp = (PODBCCOL)Columns; colp; @@ -635,7 +635,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) rc = (Mode == MODE_READ) ? ((Rows = Ocp->ExecDirectSQL(Query->GetStr(), (PODBCCOL)Columns)) < 0) : false; - } // endif rc + } // endif rc } else if (Mode == MODE_INSERT) { if (!(rc = MakeInsert(g))) { @@ -645,7 +645,7 @@ bool TDBODBC::OpenDB(PGLOBAL g) } else rc = BindParameters(g); - } // endif rc + } // endif rc } else if (Mode == MODE_UPDATE || Mode == MODE_DELETE) { rc = false; // wait for CheckCond before calling MakeCommand(g); @@ -655,30 +655,30 @@ bool TDBODBC::OpenDB(PGLOBAL g) if (rc) { Ocp->Close(); return true; - } // endif rc + } // endif rc /*********************************************************************/ /* Reset statistics values. */ /*********************************************************************/ num_read = num_there = num_eq[0] = num_eq[1] = 0; return false; - } // end of OpenDB +} // end of OpenDB #if 0 /***********************************************************************/ /* GetRecpos: return the position of last read record. */ /***********************************************************************/ int TDBODBC::GetRecpos(void) - { +{ return Fpos; - } // end of GetRecpos +} // end of GetRecpos #endif // 0 /***********************************************************************/ /* SetRecpos: set the position of next read record. */ /***********************************************************************/ bool TDBODBC::SetRecpos(PGLOBAL g, int recpos) - { +{ if (Ocp->m_Full) { Fpos = 0; CurNum = recpos - 1; @@ -696,14 +696,15 @@ bool TDBODBC::SetRecpos(PGLOBAL g, int recpos) } // endif recpos } else { - strcpy(g->Message, "This action requires a scrollable cursor"); + strcpy(g->Message, + "This action requires Memory setting or a scrollable cursor"); return true; } // endif's // Indicate the table position was externally set Placed = true; return false; - } // end of SetRecpos +} // end of SetRecpos /***********************************************************************/ /* Data Base indexed read routine for ODBC access method. */ @@ -721,7 +722,7 @@ bool TDBODBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) Rows = Ocp->ExecDirectSQL((char*)Query->GetStr(), (PODBCCOL)Columns); Mode = MODE_READ; return (Rows < 0); - } // endif key + } // endif key return false; } else { @@ -737,7 +738,7 @@ bool TDBODBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) if ((To_CondFil = hc->CheckCond(g, To_CondFil, Cond))) PlugSubAlloc(g, NULL, strlen(To_CondFil->Body) + 1); - } // endif active_index + } // endif active_index if (To_CondFil) if (Query->Append(" AND ") || Query->Append(To_CondFil->Body)) { @@ -762,7 +763,7 @@ bool TDBODBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr) /* VRDNDOS: Data Base read routine for odbc access method. */ /***********************************************************************/ int TDBODBC::ReadDB(PGLOBAL g) - { +{ int rc; if (trace(2)) @@ -784,7 +785,7 @@ int TDBODBC::ReadDB(PGLOBAL g) } else return RC_FX; // Error - } // endif Mode + } // endif Mode /*********************************************************************/ /* Now start the reading process. */ @@ -813,7 +814,7 @@ int TDBODBC::ReadDB(PGLOBAL g) Qrp->Nblin++; Fpos++; // Used for memory and pos - } // endif rc + } // endif rc } // endif Placed @@ -821,13 +822,13 @@ int TDBODBC::ReadDB(PGLOBAL g) htrc(" Read: Rbuf=%d rc=%d\n", Rbuf, rc); return rc; - } // end of ReadDB +} // end of ReadDB /***********************************************************************/ /* Data Base Insert write routine for ODBC access method. */ /***********************************************************************/ int TDBODBC::WriteDB(PGLOBAL g) - { +{ int n = Ocp->ExecuteSQL(); if (n < 0) { @@ -837,13 +838,13 @@ int TDBODBC::WriteDB(PGLOBAL g) AftRows += n; return RC_OK; - } // end of WriteDB +} // end of WriteDB /***********************************************************************/ /* Data Base delete line routine for ODBC access method. */ /***********************************************************************/ int TDBODBC::DeleteDB(PGLOBAL g, int irc) - { +{ if (irc == RC_FX) { if (!Query && MakeCommand(g)) return RC_FX; @@ -863,13 +864,13 @@ int TDBODBC::DeleteDB(PGLOBAL g, int irc) } else return RC_OK; // Ignore - } // end of DeleteDB +} // end of DeleteDB /***********************************************************************/ /* Data Base close routine for ODBC access method. */ /***********************************************************************/ void TDBODBC::CloseDB(PGLOBAL g) - { +{ if (Ocp) Ocp->Close(); @@ -877,7 +878,7 @@ void TDBODBC::CloseDB(PGLOBAL g) if (trace(1)) htrc("ODBC CloseDB: closing %s\n", Name); - } // end of CloseDB +} // end of CloseDB /* --------------------------- ODBCCOL ------------------------------- */ @@ -886,33 +887,33 @@ void TDBODBC::CloseDB(PGLOBAL g) /***********************************************************************/ ODBCCOL::ODBCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) : EXTCOL(cdp, tdbp, cprec, i, am) - { +{ // Set additional ODBC access method information for column. Slen = 0; StrLen = &Slen; Sqlbuf = NULL; - } // end of ODBCCOL constructor +} // end of ODBCCOL constructor /***********************************************************************/ /* ODBCCOL private constructor. */ /***********************************************************************/ ODBCCOL::ODBCCOL(void) : EXTCOL() - { +{ Slen = 0; StrLen = &Slen; Sqlbuf = NULL; - } // end of ODBCCOL constructor +} // end of ODBCCOL constructor /***********************************************************************/ /* ODBCCOL constructor used for copying columns. */ /* tdbp is the pointer to the new table descriptor. */ /***********************************************************************/ ODBCCOL::ODBCCOL(ODBCCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp) - { +{ Slen = col1->Slen; StrLen = col1->StrLen; Sqlbuf = col1->Sqlbuf; - } // end of ODBCCOL copy constructor +} // end of ODBCCOL copy constructor /***********************************************************************/ /* ReadColumn: when SQLFetch is used there is nothing to do as the */ @@ -920,7 +921,7 @@ ODBCCOL::ODBCCOL(ODBCCOL *col1, PTDB tdbp) : EXTCOL(col1, tdbp) /* when calculating MaxSize (Bufp is NULL even when Rows is not). */ /***********************************************************************/ void ODBCCOL::ReadColumn(PGLOBAL g) - { +{ PTDBODBC tdbp = (PTDBODBC)To_Tdb; int i = tdbp->Fpos - 1, n = tdbp->CurNum; @@ -953,7 +954,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g) else Value->SetValue_pvblk(Blkp, n); - } // endif Bufp + } // endif Bufp if (Buf_Type == TYPE_DATE) { struct tm dbtime; @@ -980,7 +981,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g) htrc("ODBC Column %s: rows=%d buf=%p type=%d value=%s\n", Name, tdbp->Rows, Bufp, Buf_Type, Value->GetCharString(buf)); - } // endif trace + } // endif trace put: if (tdbp->Memory != 2) @@ -997,7 +998,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g) } else Crp->Kdata->SetValue(Value, i); - } // end of ReadColumn +} // end of ReadColumn /***********************************************************************/ /* AllocateBuffers: allocate the extended buffer for SQLExtendedFetch */ @@ -1005,7 +1006,7 @@ void ODBCCOL::ReadColumn(PGLOBAL g) /* for the ending null character. */ /***********************************************************************/ void ODBCCOL::AllocateBuffers(PGLOBAL g, int rows) - { +{ if (Buf_Type == TYPE_DATE) Sqlbuf = (TIMESTAMP_STRUCT*)PlugSubAlloc(g, NULL, sizeof(TIMESTAMP_STRUCT)); @@ -1019,31 +1020,31 @@ void ODBCCOL::AllocateBuffers(PGLOBAL g, int rows) Blkp = AllocValBlock(g, NULL, Buf_Type, rows, GetBuflen(), GetScale(), true, false, false); Bufp = Blkp->GetValPointer(); - } // endelse + } // endelse if (rows > 1) StrLen = (SQLLEN *)PlugSubAlloc(g, NULL, rows * sizeof(SQLLEN)); - } // end of AllocateBuffers +} // end of AllocateBuffers /***********************************************************************/ /* Returns the buffer to use for Fetch or Extended Fetch. */ /***********************************************************************/ void *ODBCCOL::GetBuffer(DWORD rows) - { +{ if (rows && To_Tdb) { assert(rows == (DWORD)((TDBODBC*)To_Tdb)->Rows); return Bufp; } else return (Buf_Type == TYPE_DATE) ? Sqlbuf : Value->GetTo_Val(); - } // end of GetBuffer +} // end of GetBuffer /***********************************************************************/ /* Returns the buffer length to use for Fetch or Extended Fetch. */ /***********************************************************************/ SWORD ODBCCOL::GetBuflen(void) - { +{ SWORD flen; switch (Buf_Type) { @@ -1059,13 +1060,13 @@ SWORD ODBCCOL::GetBuflen(void) } // endswitch Buf_Type return flen; - } // end of GetBuflen +} // end of GetBuflen /***********************************************************************/ /* WriteColumn: make sure the bind buffer is updated. */ /***********************************************************************/ void ODBCCOL::WriteColumn(PGLOBAL g) - { +{ /*********************************************************************/ /* Do convert the column value if necessary. */ /*********************************************************************/ @@ -1095,7 +1096,7 @@ void ODBCCOL::WriteColumn(PGLOBAL g) *StrLen = (Value->IsNull()) ? SQL_NULL_DATA : (IsTypeChar(Buf_Type)) ? SQL_NTS : 0; - } // end of WriteColumn +} // end of WriteColumn /* -------------------------- Class TDBXDBC -------------------------- */ @@ -1119,7 +1120,7 @@ TDBXDBC::TDBXDBC(PTDBXDBC tdbp) : TDBODBC(tdbp) } // end of TDBXDBC copy constructor PTDB TDBXDBC::Clone(PTABS t) - { +{ PTDB tp; PXSRCCOL cp1, cp2; PGLOBAL g = t->G; // Is this really useful ??? @@ -1129,29 +1130,29 @@ PTDB TDBXDBC::Clone(PTABS t) for (cp1 = (PXSRCCOL)Columns; cp1; cp1 = (PXSRCCOL)cp1->GetNext()) { cp2 = new(g) XSRCCOL(cp1, tp); // Make a copy NewPointer(t, cp1, cp2); - } // endfor cp1 + } // endfor cp1 return tp; - } // end of CopyOne +} // end of CopyOne /***********************************************************************/ /* Allocate XSRC column description block. */ /***********************************************************************/ PCOL TDBXDBC::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) - { +{ PXSRCCOL colp = new(g) XSRCCOL(cdp, this, cprec, n); if (!colp->Flag) Cmdcol = colp->GetName(); return colp; - } // end of MakeCol +} // end of MakeCol /***********************************************************************/ /* MakeCMD: make the SQL statement to send to ODBC connection. */ /***********************************************************************/ PCMD TDBXDBC::MakeCMD(PGLOBAL g) - { +{ PCMD xcmd = NULL; if (To_CondFil) { @@ -1171,14 +1172,14 @@ PCMD TDBXDBC::MakeCMD(PGLOBAL g) xcmd = new(g) CMD(g, Srcdef); return xcmd; - } // end of MakeCMD +} // end of MakeCMD #if 0 /***********************************************************************/ /* ODBC Bind Parameter function. */ /***********************************************************************/ bool TDBXDBC::BindParameters(PGLOBAL g) - { +{ PODBCCOL colp; for (colp = (PODBCCOL)Columns; colp; colp = (PODBCCOL)colp->Next) { @@ -1190,19 +1191,19 @@ bool TDBXDBC::BindParameters(PGLOBAL g) } // endfor colp return false; - } // end of BindParameters +} // end of BindParameters #endif // 0 /***********************************************************************/ /* XDBC GetMaxSize: returns table size (not always one row). */ /***********************************************************************/ int TDBXDBC::GetMaxSize(PGLOBAL g) - { +{ if (MaxSize < 0) MaxSize = 10; // Just a guess return MaxSize; - } // end of GetMaxSize +} // end of GetMaxSize /***********************************************************************/ /* ODBC Access Method opening routine. */ @@ -1211,7 +1212,7 @@ int TDBXDBC::GetMaxSize(PGLOBAL g) /* join block of next table if it exists or else are discarted. */ /***********************************************************************/ bool TDBXDBC::OpenDB(PGLOBAL g) - { +{ bool rc = false; if (trace(1)) @@ -1221,7 +1222,7 @@ bool TDBXDBC::OpenDB(PGLOBAL g) if (Use == USE_OPEN) { strcpy(g->Message, "Multiple execution is not allowed"); return true; - } // endif use + } // endif use /*********************************************************************/ /* Open an ODBC connection for this table. */ @@ -1243,7 +1244,7 @@ bool TDBXDBC::OpenDB(PGLOBAL g) if (Mode != MODE_READ && Mode != MODE_READX) { strcpy(g->Message, "No INSERT/DELETE/UPDATE of XDBC tables"); return true; - } // endif Mode + } // endif Mode /*********************************************************************/ /* Get the command to execute. */ @@ -1256,13 +1257,13 @@ bool TDBXDBC::OpenDB(PGLOBAL g) Rows = 1; return false; - } // end of OpenDB +} // end of OpenDB /***********************************************************************/ /* ReadDB: Data Base read routine for xdbc access method. */ /***********************************************************************/ int TDBXDBC::ReadDB(PGLOBAL g) - { +{ if (Cmdlist) { if (!Query) Query = new(g)STRING(g, 0, Cmdlist->Cmd); @@ -1280,25 +1281,25 @@ int TDBXDBC::ReadDB(PGLOBAL g) return RC_EF; } // endif Cmdlist - } // end of ReadDB +} // end of ReadDB /***********************************************************************/ -/* Data Base delete line routine for ODBC access method. */ +/* Data Base write line routine for XDBC access method. */ /***********************************************************************/ int TDBXDBC::WriteDB(PGLOBAL g) - { +{ strcpy(g->Message, "Execsrc tables are read only"); return RC_FX; - } // end of DeleteDB +} // end of DeleteDB /***********************************************************************/ -/* Data Base delete line routine for ODBC access method. */ +/* Data Base delete line routine for XDBC access method. */ /***********************************************************************/ int TDBXDBC::DeleteDB(PGLOBAL g, int irc) - { +{ strcpy(g->Message, MSG(NO_ODBC_DELETE)); return RC_FX; - } // end of DeleteDB +} // end of DeleteDB /* --------------------------- XSRCCOL ------------------------------- */ @@ -1307,25 +1308,25 @@ int TDBXDBC::DeleteDB(PGLOBAL g, int irc) /***********************************************************************/ XSRCCOL::XSRCCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am) : ODBCCOL(cdp, tdbp, cprec, i, am) - { +{ // Set additional ODBC access method information for column. Flag = cdp->GetOffset(); - } // end of XSRCCOL constructor +} // end of XSRCCOL constructor /***********************************************************************/ /* XSRCCOL constructor used for copying columns. */ /* tdbp is the pointer to the new table descriptor. */ /***********************************************************************/ XSRCCOL::XSRCCOL(XSRCCOL *col1, PTDB tdbp) : ODBCCOL(col1, tdbp) - { +{ Flag = col1->Flag; - } // end of XSRCCOL copy constructor +} // end of XSRCCOL copy constructor /***********************************************************************/ /* ReadColumn: set column value according to Flag. */ /***********************************************************************/ void XSRCCOL::ReadColumn(PGLOBAL g) - { +{ PTDBXDBC tdbp = (PTDBXDBC)To_Tdb; switch (Flag) { @@ -1335,15 +1336,15 @@ void XSRCCOL::ReadColumn(PGLOBAL g) default: Value->SetValue_psz("Invalid Flag"); break; } // endswitch Flag - } // end of ReadColumn +} // end of ReadColumn /***********************************************************************/ /* WriteColumn: Should never be called. */ /***********************************************************************/ void XSRCCOL::WriteColumn(PGLOBAL g) - { +{ // Should never be called - } // end of WriteColumn +} // end of WriteColumn /* ---------------------------TDBDRV class --------------------------- */ @@ -1351,9 +1352,9 @@ void XSRCCOL::WriteColumn(PGLOBAL g) /* GetResult: Get the list of ODBC drivers. */ /***********************************************************************/ PQRYRES TDBDRV::GetResult(PGLOBAL g) - { +{ return ODBCDrivers(g, Maxres, false); - } // end of GetResult +} // end of GetResult /* ---------------------------TDBSRC class --------------------------- */ @@ -1361,9 +1362,9 @@ PQRYRES TDBDRV::GetResult(PGLOBAL g) /* GetResult: Get the list of ODBC data sources. */ /***********************************************************************/ PQRYRES TDBSRC::GetResult(PGLOBAL g) - { +{ return ODBCDataSources(g, Maxres, false); - } // end of GetResult +} // end of GetResult /* ---------------------------TDBOTB class --------------------------- */ @@ -1371,7 +1372,7 @@ PQRYRES TDBSRC::GetResult(PGLOBAL g) /* TDBOTB class constructor. */ /***********************************************************************/ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) - { +{ Dsn = tdp->GetConnect(); Schema = tdp->GetTabschema(); Tab = tdp->GetTabname(); @@ -1381,15 +1382,15 @@ TDBOTB::TDBOTB(PODEF tdp) : TDBDRV(tdp) Ops.Cto = tdp->Cto; Ops.Qto = tdp->Qto; Ops.UseCnc = tdp->UseCnc; - } // end of TDBOTB constructor +} // end of TDBOTB constructor /***********************************************************************/ /* GetResult: Get the list of ODBC tables. */ /***********************************************************************/ PQRYRES TDBOTB::GetResult(PGLOBAL g) - { +{ return ODBCTables(g, Dsn, Schema, Tab, Tabtyp, Maxres, false, &Ops); - } // end of GetResult +} // end of GetResult /* ---------------------------TDBOCL class --------------------------- */ @@ -1405,8 +1406,8 @@ TDBOCL::TDBOCL(PODEF tdp) : TDBOTB(tdp) /* GetResult: Get the list of ODBC table columns. */ /***********************************************************************/ PQRYRES TDBOCL::GetResult(PGLOBAL g) - { +{ return ODBCColumns(g, Dsn, Schema, Tab, Colpat, Maxres, false, &Ops); - } // end of GetResult +} // end of GetResult /* ------------------------ End of Tabodbc --------------------------- */ diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index c96e0844497..fa4854bb618 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -681,6 +681,14 @@ PTDB TDBXML::Clone(PTABS t) return tp; } // end of Clone +/***********************************************************************/ +/* Must not be in tabxml.h because of OEM tables */ +/***********************************************************************/ +const CHARSET_INFO *TDBXML::data_charset() +{ + return &my_charset_utf8_general_ci; +} // end of data_charset + /***********************************************************************/ /* Allocate XML column description block. */ /***********************************************************************/ @@ -2209,8 +2217,9 @@ void XPOSCOL::WriteColumn(PGLOBAL g) TDBXCT::TDBXCT(PXMLDEF tdp) : TDBCAT(tdp) { Topt = tdp->GetTopt(); - Db = (char*)tdp->GetDB(); - Tabn = tdp->Tabname; + //Db = (char*)tdp->GetDB(); + Db = (char*)tdp->Schema; + Tabn = tdp->Tabname; } // end of TDBXCT constructor /***********************************************************************/ diff --git a/storage/connect/tabxml.h b/storage/connect/tabxml.h index f55b7d98de7..102767e965a 100644 --- a/storage/connect/tabxml.h +++ b/storage/connect/tabxml.h @@ -9,6 +9,8 @@ typedef class XMLDEF *PXMLDEF; typedef class TDBXML *PTDBXML; typedef class XMLCOL *PXMLCOL; +DllExport PQRYRES XMLColumns(PGLOBAL, char *, char *, PTOS, bool); + /* --------------------------- XML classes --------------------------- */ /***********************************************************************/ @@ -100,8 +102,7 @@ class DllExport TDBXML : public TDBASE { virtual int DeleteDB(PGLOBAL g, int irc); virtual void CloseDB(PGLOBAL g); virtual int CheckWrite(PGLOBAL g) {Checked = true; return 0;} - virtual const CHARSET_INFO *data_charset() - {return &my_charset_utf8_general_ci;} + virtual const CHARSET_INFO *data_charset(); protected: // Members diff --git a/storage/connect/user_connect.cc b/storage/connect/user_connect.cc index e2d3b664aeb..a2a8faf9b38 100644 --- a/storage/connect/user_connect.cc +++ b/storage/connect/user_connect.cc @@ -107,7 +107,7 @@ bool user_connect::user_init() g= PlugInit(NULL, worksize); // Check whether the initialization is complete - if (!g || !g->Sarea || PlugSubSet(g, g->Sarea, g->Sarea_Size) + if (!g || !g->Sarea || PlugSubSet(g->Sarea, g->Sarea_Size) || !(dup= PlgMakeUser(g))) { if (g) printf("%s\n", g->Message); @@ -172,7 +172,7 @@ bool user_connect::CheckCleanup(bool force) } // endif worksize - PlugSubSet(g, g->Sarea, g->Sarea_Size); + PlugSubSet(g->Sarea, g->Sarea_Size); g->Xchk = NULL; g->Createas = 0; g->Alchecked = 0; -- cgit v1.2.1 From 60525ad348f92b85c788ca514cab60ac74a36652 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 5 Dec 2018 16:36:25 +0100 Subject: Modified to avoid make index error (AVG_ROW_LENGTH=5) --- storage/connect/mysql-test/connect/r/part_table.result | 4 ++-- storage/connect/mysql-test/connect/t/part_table.test | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/storage/connect/mysql-test/connect/r/part_table.result b/storage/connect/mysql-test/connect/r/part_table.result index f3a556ae784..4c74f1a6f49 100644 --- a/storage/connect/mysql-test/connect/r/part_table.result +++ b/storage/connect/mysql-test/connect/r/part_table.result @@ -23,7 +23,7 @@ id msg CREATE TABLE xt3 ( id INT KEY NOT NULL, msg VARCHAR(32)) -ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=10; +ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5; Warnings: Warning 1105 No file name. Table will use xt3.csv INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); @@ -92,7 +92,7 @@ id msg EXPLAIN PARTITIONS SELECT * FROM t1 WHERE id = 81; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 3 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where DELETE FROM t1; Warnings: Note 1105 xt1: 4 affected rows diff --git a/storage/connect/mysql-test/connect/t/part_table.test b/storage/connect/mysql-test/connect/t/part_table.test index 5edd5766bd6..8c0eb4cac70 100644 --- a/storage/connect/mysql-test/connect/t/part_table.test +++ b/storage/connect/mysql-test/connect/t/part_table.test @@ -22,7 +22,7 @@ SELECT * FROM xt2; CREATE TABLE xt3 ( id INT KEY NOT NULL, msg VARCHAR(32)) -ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=10; +ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5; INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); SELECT * FROM xt3; -- cgit v1.2.1 From c2482c76dc4b164839d540818db1a61b9a0ce5f0 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 5 Dec 2018 19:01:37 +0100 Subject: Modified because different result on Windows and Linux --- storage/connect/mysql-test/connect/r/part_table.result | 5 ++--- storage/connect/mysql-test/connect/t/part_table.test | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/storage/connect/mysql-test/connect/r/part_table.result b/storage/connect/mysql-test/connect/r/part_table.result index 4c74f1a6f49..80127fac70c 100644 --- a/storage/connect/mysql-test/connect/r/part_table.result +++ b/storage/connect/mysql-test/connect/r/part_table.result @@ -89,10 +89,9 @@ id msg 60 sixty 81 eighty one 72 seventy two -EXPLAIN PARTITIONS SELECT * FROM t1 WHERE id = 81; -id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where +id msg +81 eighty one DELETE FROM t1; Warnings: Note 1105 xt1: 4 affected rows diff --git a/storage/connect/mysql-test/connect/t/part_table.test b/storage/connect/mysql-test/connect/t/part_table.test index 8c0eb4cac70..37133b96ca5 100644 --- a/storage/connect/mysql-test/connect/t/part_table.test +++ b/storage/connect/mysql-test/connect/t/part_table.test @@ -47,7 +47,7 @@ INSERT INTO t1 VALUES(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eight INSERT INTO t1 VALUES(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight'); SELECT partition_name, table_rows FROM information_schema.partitions WHERE table_name = 't1'; SELECT * FROM t1; -EXPLAIN PARTITIONS +#EXPLAIN PARTITIONS deleted because it returns differeent key on Windows and Linux SELECT * FROM t1 WHERE id = 81; DELETE FROM t1; DROP TABLE t1; -- cgit v1.2.1 From 547ce1b22a9962b673af381a271377aefc2dca4e Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Wed, 2 Jan 2019 10:44:03 +0100 Subject: - Fix a few bug mainly concerning discovery and call from OEM (and prepare new table types) modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h - Fix wrong line estimate modified: storage/connect/mysql-test/connect/r/part_table.result modified: storage/connect/mysql-test/connect/t/part_table.test --- .../connect/mysql-test/connect/r/part_table.result | 7 +- .../connect/mysql-test/connect/t/part_table.test | 4 +- storage/connect/tabjson.cpp | 42 ++-- storage/connect/tabjson.h | 2 +- storage/connect/tabxml.cpp | 279 +++++++++++---------- storage/connect/tabxml.h | 1 + 6 files changed, 188 insertions(+), 147 deletions(-) diff --git a/storage/connect/mysql-test/connect/r/part_table.result b/storage/connect/mysql-test/connect/r/part_table.result index 80127fac70c..ee17a1d32b9 100644 --- a/storage/connect/mysql-test/connect/r/part_table.result +++ b/storage/connect/mysql-test/connect/r/part_table.result @@ -23,7 +23,7 @@ id msg CREATE TABLE xt3 ( id INT KEY NOT NULL, msg VARCHAR(32)) -ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5; +ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6; Warnings: Warning 1105 No file name. Table will use xt3.csv INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); @@ -89,9 +89,10 @@ id msg 60 sixty 81 eighty one 72 seventy two +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE id = 81; -id msg -81 eighty one +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where DELETE FROM t1; Warnings: Note 1105 xt1: 4 affected rows diff --git a/storage/connect/mysql-test/connect/t/part_table.test b/storage/connect/mysql-test/connect/t/part_table.test index 37133b96ca5..0fb2a11f0f9 100644 --- a/storage/connect/mysql-test/connect/t/part_table.test +++ b/storage/connect/mysql-test/connect/t/part_table.test @@ -22,7 +22,7 @@ SELECT * FROM xt2; CREATE TABLE xt3 ( id INT KEY NOT NULL, msg VARCHAR(32)) -ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5; +ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6; INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two'); SELECT * FROM xt3; @@ -47,7 +47,7 @@ INSERT INTO t1 VALUES(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eight INSERT INTO t1 VALUES(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight'); SELECT partition_name, table_rows FROM information_schema.partitions WHERE table_name = 't1'; SELECT * FROM t1; -#EXPLAIN PARTITIONS deleted because it returns differeent key on Windows and Linux +EXPLAIN PARTITIONS SELECT * FROM t1 WHERE id = 81; DELETE FROM t1; DROP TABLE t1; diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index d20e793ff88..c0d36efcf42 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -1,6 +1,6 @@ /************* tabjson C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabjson Version 1.5 */ -/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */ +/* PROGRAM NAME: tabjson Version 1.6 */ +/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */ /* This program are the JSON class DB execution routines. */ /***********************************************************************/ @@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg) int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) { + char filename[_MAX_PATH]; bool mgo = (GetTypeID(topt->type) == TAB_MONGO); PCSZ level = GetStringTableOption(g, topt, "Level", NULL); @@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) return 0; } // endif Fn + if (tdp->Fn) { + // We used the file name relative to recorded datapath + PlugSetPath(filename, tdp->Fn, tdp->GetPath()); + tdp->Fn = PlugDup(g, filename); + } // endif Fn + if (trace(1)) htrc("File %s objname=%s pretty=%d lvl=%d\n", tdp->Fn, tdp->Objname, tdp->Pretty, lvl); @@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) strncpy(colname, jpp->GetKey(), 64); fmt[bf] = 0; - if (Find(g, jpp->GetVal(), MY_MIN(lvl, 0))) + if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0))) goto err; } // endfor jpp @@ -385,7 +392,7 @@ err: return 0; } // end of GetColumns -bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) +bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j) { char *p, *pc = colname + strlen(colname); int ars; @@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) job = (PJOB)jsp; for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) { - if (*jrp->GetKey() != '$') { - strncat(strncat(fmt, sep, 128), jrp->GetKey(), 128); - strncat(strncat(colname, "_", 64), jrp->GetKey(), 64); + PCSZ k = jrp->GetKey(); + + if (*k != '$') { + strncat(strncat(fmt, sep, 128), k, 128); + strncat(strncat(colname, "_", 64), k, 64); } // endif Key - if (Find(g, jrp->GetVal(), j + 1)) + if (Find(g, jrp->GetVal(), k, j + 1)) return true; *p = *pc = 0; @@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) case TYPE_JAR: jar = (PJAR)jsp; - if (all || (tdp->Xcol && !stricmp(tdp->Xcol, colname))) + if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key))) ars = jar->GetSize(false); else ars = MY_MIN(jar->GetSize(false), 1); for (int k = 0; k < ars; k++) { - if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) { + if (!tdp->Xcol || stricmp(tdp->Xcol, key)) { sprintf(buf, "%d", k); if (tdp->Uri) @@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j) } else strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); - if (Find(g, jar->GetValue(k), j)) + if (Find(g, jar->GetValue(k), "", j)) return true; *p = *pc = 0; @@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g) n++; } // endif jcp - pjcp = jcp; + if (jcp) + pjcp = jcp; + } // end of AddColumn @@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void) /***********************************************************************/ /* DefineAM: define specific AM block values. */ /***********************************************************************/ -bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) +bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { Schema = GetStringCatInfo(g, "DBname", Schema); Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT); @@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff) Sep = *GetStringCatInfo(g, "Separator", "."); Accept = GetBoolCatInfo("Accept", false); - if (Uri = GetStringCatInfo(g, "Connect", NULL)) { + // Don't use url as uri when called from REST OEM module + if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) Collname = GetStringCatInfo(g, "Name", (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); @@ -2340,7 +2352,7 @@ void TDBJSON::CloseDB(PGLOBAL g) TDBJCL::TDBJCL(PJDEF tdp) : TDBCAT(tdp) { Topt = tdp->GetTopt(); - Db = tdp->Schema; + Db = tdp->Schema; Dsn = tdp->Uri; } // end of TDBJCL constructor diff --git a/storage/connect/tabjson.h b/storage/connect/tabjson.h index fcbfe4ed1ec..8721a2a5ab7 100644 --- a/storage/connect/tabjson.h +++ b/storage/connect/tabjson.h @@ -52,7 +52,7 @@ public: // Functions int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt); - bool Find(PGLOBAL g, PJVAL jvp, int j); + bool Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j); void AddColumn(PGLOBAL g); // Members diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index fa4854bb618..d808bd5ecd4 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -163,8 +163,11 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) return NULL; tdp->Tabname = tab; + tdp->Tabname = (char*)GetStringTableOption(g, topt, "Tabname", tab); + tdp->Rowname = (char*)GetStringTableOption(g, topt, "Rownode", NULL); tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false); tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL); + tdp->Skip = GetBooleanTableOption(g, topt, "Skipnull", false); if (!(op = GetStringTableOption(g, topt, "Xmlsup", NULL))) #if defined(__WIN__) @@ -280,7 +283,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) if (!vp->atp) node = vp->nl->GetItem(g, vp->k++, tdp->Usedom ? node : NULL); - strncat(fmt, colname, XLEN(fmt)); + if (!j) + strncat(fmt, colname, XLEN(fmt)); + strncat(fmt, "/", XLEN(fmt)); strncat(xcol->Name, "_", XLEN(xcol->Name)); j++; @@ -302,6 +307,7 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) case RC_INFO: PushWarning(g, txmp); case RC_OK: + xcol->Cbn = !strlen(buf); break; default: goto err; @@ -327,9 +333,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) xcp->Len = MY_MAX(xcp->Len, xcol->Len); xcp->Scale = MY_MAX(xcp->Scale, xcol->Scale); - xcp->Cbn |= xcol->Cbn; + xcp->Cbn |= (xcol->Cbn || !xcol->Len); xcp->Found = true; - } else { + } else if(xcol->Len || !tdp->Skip) { // New column xcp = new(g) XMCOL(g, xcol, fmt, i); length[0] = MY_MAX(length[0], strlen(xcol->Name)); @@ -344,7 +350,8 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) n++; } // endif xcp - pxcp = xcp; + if (xcp) + pxcp = xcp; if (vp->atp) vp->atp = vp->atp->GetNext(g); @@ -445,6 +452,7 @@ XMLDEF::XMLDEF(void) Usedom = false; Zipped = false; Mulentries = false; + Skip = false; } // end of XMLDEF constructor /***********************************************************************/ @@ -814,127 +822,141 @@ bool TDBXML::Initialize(PGLOBAL g) } // endif Bufdone #if !defined(UNIX) - if (!Root) try { + if (!Root) try { #else - if (!Root) { + if (!Root) { #endif - char tabpath[64], filename[_MAX_PATH]; - - // We used the file name relative to recorded datapath - PlugSetPath(filename, Xfile, GetPath()); - - // Load or re-use the table file - rc = LoadTableFile(g, filename); - - if (rc == RC_OK) { - // Get root node - if (!(Root = Docp->GetRoot(g))) { - // This should never happen as load should have failed - strcpy(g->Message, MSG(EMPTY_DOC)); - goto error; - } // endif Root - - // If tabname is not an Xpath, - // construct one that will find it anywhere - if (!strchr(Tabname, '/')) - strcat(strcpy(tabpath, "//"), Tabname); - else - strcpy(tabpath, Tabname); - - // Evaluate table xpath - if ((TabNode = Root->SelectSingleNode(g, tabpath))) { - if (TabNode->GetType() != XML_ELEMENT_NODE) { - sprintf(g->Message, MSG(BAD_NODE_TYPE), TabNode->GetType()); - goto error; - } // endif Type - - } else if (Mode == MODE_INSERT && XmlDB) { - // We are adding a new table to a multi-table file - - // If XmlDB is not an Xpath, - // construct one that will find it anywhere - if (!strchr(XmlDB, '/')) - strcat(strcpy(tabpath, "//"), XmlDB); - else - strcpy(tabpath, XmlDB); - - if (!(DBnode = Root->SelectSingleNode(g, tabpath))) { - // DB node does not exist yet; we cannot create it - // because we don't know where it should be placed - sprintf(g->Message, MSG(MISSING_NODE), XmlDB, Xfile); - goto error; - } // endif DBnode - - if (!(TabNode = DBnode->AddChildNode(g, Tabname))) { - sprintf(g->Message, MSG(FAIL_ADD_NODE), Tabname); - goto error; - } // endif TabNode - - DBnode->AddText(g, "\n"); - } else - TabNode = Root; // Try this ? - - } else if (rc == RC_NF || rc == RC_EF) { - // The XML file does not exist or is void - if (Mode == MODE_INSERT) { - // New Document - char buf[64]; - - // Create the XML node - if (Docp->NewDoc(g, "1.0")) { - strcpy(g->Message, MSG(NEW_DOC_FAILED)); - goto error; - } // endif NewDoc - - // Now we can link the Xblock - To_Xb = Docp->LinkXblock(g, Mode, rc, filename); - - // Add a CONNECT comment node - strcpy(buf, " Created by the MariaDB CONNECT Storage Engine"); - Docp->AddComment(g, buf); - - if (XmlDB) { - // This is a multi-table file - DBnode = Root = Docp->NewRoot(g, XmlDB); - DBnode->AddText(g, "\n"); - TabNode = DBnode->AddChildNode(g, Tabname); - DBnode->AddText(g, "\n"); - } else - TabNode = Root = Docp->NewRoot(g, Tabname); - - if (TabNode == NULL || Root == NULL) { - strcpy(g->Message, MSG(XML_INIT_ERROR)); - goto error; - } else if (SetTabNode(g)) - goto error; - - } else { - sprintf(g->Message, MSG(FILE_UNFOUND), Xfile); - - if (Mode == MODE_READ) { - PushWarning(g, this); - Void = true; - } // endif Mode - - goto error; - } // endif Mode - - } else if (rc == RC_INFO) { - // Loading failed - sprintf(g->Message, MSG(LOADING_FAILED), Xfile); - goto error; - } else // (rc == RC_FX) - goto error; - - // Get row node list - if (Rowname) - Nlist = TabNode->SelectNodes(g, Rowname); - else - Nlist = TabNode->GetChildElements(g); - - Docp->SetNofree(true); // For libxml2 + char tabpath[64], filename[_MAX_PATH]; + + // We used the file name relative to recorded datapath + PlugSetPath(filename, Xfile, GetPath()); + + // Load or re-use the table file + rc = LoadTableFile(g, filename); + + if (rc == RC_OK) { + // Get root node + if (!(Root = Docp->GetRoot(g))) { + // This should never happen as load should have failed + strcpy(g->Message, MSG(EMPTY_DOC)); + goto error; + } // endif Root + + // If tabname is not an Xpath, + // construct one that will find it anywhere + if (!strchr(Tabname, '/')) + strcat(strcpy(tabpath, "//"), Tabname); + else + strcpy(tabpath, Tabname); + + // Evaluate table xpath + if ((TabNode = Root->SelectSingleNode(g, tabpath))) { + if (TabNode->GetType() != XML_ELEMENT_NODE) { + sprintf(g->Message, MSG(BAD_NODE_TYPE), TabNode->GetType()); + goto error; + } // endif Type + + } else if (Mode == MODE_INSERT && XmlDB) { + // We are adding a new table to a multi-table file + + // If XmlDB is not an Xpath, + // construct one that will find it anywhere + if (!strchr(XmlDB, '/')) + strcat(strcpy(tabpath, "//"), XmlDB); + else + strcpy(tabpath, XmlDB); + + if (!(DBnode = Root->SelectSingleNode(g, tabpath))) { + // DB node does not exist yet; we cannot create it + // because we don't know where it should be placed + sprintf(g->Message, MSG(MISSING_NODE), XmlDB, Xfile); + goto error; + } // endif DBnode + + if (!(TabNode = DBnode->AddChildNode(g, Tabname))) { + sprintf(g->Message, MSG(FAIL_ADD_NODE), Tabname); + goto error; + } // endif TabNode + + DBnode->AddText(g, "\n"); + } else { + TabNode = Root; // Try this ? + Tabname = TabNode->GetName(g); + } // endif's + + } else if (rc == RC_NF || rc == RC_EF) { + // The XML file does not exist or is void + if (Mode == MODE_INSERT) { + // New Document + char buf[64]; + + // Create the XML node + if (Docp->NewDoc(g, "1.0")) { + strcpy(g->Message, MSG(NEW_DOC_FAILED)); + goto error; + } // endif NewDoc + + // Now we can link the Xblock + To_Xb = Docp->LinkXblock(g, Mode, rc, filename); + + // Add a CONNECT comment node + strcpy(buf, " Created by the MariaDB CONNECT Storage Engine"); + Docp->AddComment(g, buf); + + if (XmlDB) { + // This is a multi-table file + DBnode = Root = Docp->NewRoot(g, XmlDB); + DBnode->AddText(g, "\n"); + TabNode = DBnode->AddChildNode(g, Tabname); + DBnode->AddText(g, "\n"); + } else + TabNode = Root = Docp->NewRoot(g, Tabname); + + if (TabNode == NULL || Root == NULL) { + strcpy(g->Message, MSG(XML_INIT_ERROR)); + goto error; + } else if (SetTabNode(g)) + goto error; + + } else { + sprintf(g->Message, MSG(FILE_UNFOUND), Xfile); + + if (Mode == MODE_READ) { + PushWarning(g, this); + Void = true; + } // endif Mode + + goto error; + } // endif Mode + + } else if (rc == RC_INFO) { + // Loading failed + sprintf(g->Message, MSG(LOADING_FAILED), Xfile); + goto error; + } else // (rc == RC_FX) + goto error; + + if (!Rowname) { + for (PXNODE n = TabNode->GetChild(g); n; n = n->GetNext(g)) + if (n->GetType() == XML_ELEMENT_NODE) { + Rowname = n->GetName(g); + break; + } // endif Type + + if (!Rowname) + Rowname = TabNode->GetName(g); + } // endif Rowname + + // Get row node list + if (strcmp(Rowname, Tabname)) + Nlist = TabNode->SelectNodes(g, Rowname); + else + Nrow = 1; + + + Docp->SetNofree(true); // For libxml2 #if defined(__WIN__) - } catch(_com_error e) { + } catch (_com_error e) { // We come here if a DOM command threw an error char buf[128]; @@ -1221,10 +1243,14 @@ int TDBXML::ReadDB(PGLOBAL g) htrc("TDBXML ReadDB: Irow=%d RowNode=%p\n", Irow, RowNode); // Get the new row node - if ((RowNode = Nlist->GetItem(g, Irow, RowNode)) == NULL) { - sprintf(g->Message, MSG(MISSING_ROWNODE), Irow); - return RC_FX; - } // endif RowNode + if (Nlist) { + if ((RowNode = Nlist->GetItem(g, Irow, RowNode)) == NULL) { + sprintf(g->Message, MSG(MISSING_ROWNODE), Irow); + return RC_FX; + } // endif RowNode + + } else + RowNode = TabNode; if (Colname && Coltype == 2) Clist = RowNode->SelectNodes(g, Colname, Clist); @@ -1279,6 +1305,7 @@ int TDBXML::WriteDB(PGLOBAL g) /***********************************************************************/ int TDBXML::DeleteDB(PGLOBAL g, int irc) { + // TODO: Handle null Nlist if (irc == RC_FX) { // Delete all rows for (Irow = 0; Irow < Nrow; Irow++) diff --git a/storage/connect/tabxml.h b/storage/connect/tabxml.h index 102767e965a..fb3913f08ea 100644 --- a/storage/connect/tabxml.h +++ b/storage/connect/tabxml.h @@ -52,6 +52,7 @@ class DllExport XMLDEF : public TABDEF { /* Logical table description */ bool Usedom; /* True: DOM, False: libxml2 */ bool Zipped; /* True: Zipped XML file(s) */ bool Mulentries; /* True: multiple entries in zip file*/ + bool Skip; /* Skip null columns */ }; // end of XMLDEF #if defined(INCLUDE_TDBXML) -- cgit v1.2.1 From a4834755ecbc3643a12c40334a12f2ec75080622 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 24 Jan 2019 23:49:57 +0100 Subject: - 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 --- storage/connect/tabext.cpp | 39 ++++++++++++++++++++++++++++++ storage/connect/tabext.h | 1 + storage/connect/tabjdbc.cpp | 59 ++++++++++++++++++++++++++------------------- 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 @@ -445,6 +445,43 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) return false; } // 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; -- cgit v1.2.1 From 27fec12faee216d0b232c5d196d73dac32f70748 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 26 Jan 2019 18:11:45 +0100 Subject: - Make user and password defined in CREATE TABLE have precedence on the ones specified in a Federated Server. modified: storage/connect/tabjdbc.cpp - Typo modified: storage/connect/tabext.cpp modified: storage/connect/tabext.h modified: storage/connect/tabjdbc.cpp modified: storage/connect/tabjson.cpp --- storage/connect/tabext.cpp | 4 ++-- storage/connect/tabext.h | 4 ++-- storage/connect/tabjdbc.cpp | 8 ++++---- storage/connect/tabjson.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index 292f67ed5e8..e9c7b2490d8 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -1,7 +1,7 @@ /************* Tabext C++ Functions Source Code File (.CPP) ************/ -/* Name: TABEXT.CPP Version 1.0 */ +/* Name: TABEXT.CPP Version 1.1 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */ /* */ /* This file contains the TBX, TDB and OPJOIN classes functions. */ /***********************************************************************/ diff --git a/storage/connect/tabext.h b/storage/connect/tabext.h index 21e3796ea7c..5fef1b9ece0 100644 --- a/storage/connect/tabext.h +++ b/storage/connect/tabext.h @@ -1,7 +1,7 @@ /*************** Tabext H Declares Source Code File (.H) ***************/ -/* Name: TABEXT.H Version 1.0 */ +/* Name: TABEXT.H Version 1.1 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2017 - 2019 */ /* */ /* This is the EXTDEF, TABEXT and EXTCOL classes definitions. */ /***********************************************************************/ diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index 27814af3dbe..c6b2802c1f6 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -1,11 +1,11 @@ /************* TabJDBC C++ Program Source Code File (.CPP) *************/ /* PROGRAM NAME: TABJDBC */ /* ------------- */ -/* Version 1.2 */ +/* Version 1.3 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 2016-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2016-2019 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -185,10 +185,10 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b) } else // host is a URL Url = PlugDup(g, server->host); - if (server->username) + if (!Username && server->username) Username = PlugDup(g, server->username); - if (server->password) + if (!Password && server->password) Password = PlugDup(g, server->password); return RC_NF; diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index 3b326a570eb..afab52aa282 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -1,6 +1,6 @@ /************* tabjson C++ Program Source Code File (.CPP) *************/ -/* PROGRAM NAME: tabjson Version 1.6 */ -/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */ +/* PROGRAM NAME: tabjson Version 1.7 */ +/* (C) Copyright to the author Olivier BERTRAND 2014 - 2019 */ /* This program are the JSON class DB execution routines. */ /***********************************************************************/ -- cgit v1.2.1 From 0f388dd4d060b9aac2b2f856cc48440e3cd9c136 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 27 Jan 2019 15:10:03 +0100 Subject: - Enable CONNECT tables to have triggers Update version number modified: storage/connect/ha_connect.cc --- storage/connect/ha_connect.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index bcb02adf932..344e4708419 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,9 +170,9 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0008 October 06, 2018"; + char version[] = "Version 1.06.0009 January 27, 2019"; #if defined(__WIN__) - char compver[]= "Version 1.06.0008 " __DATE__ " " __TIME__; + char compver[]= "Version 1.06.0009 " __DATE__ " " __TIME__; char slash= '\\'; #else // !__WIN__ char slash= '/'; @@ -1914,9 +1914,11 @@ int ha_connect::OpenTable(PGLOBAL g, bool del) break; } // endswitch xmode - if (xmod != MODE_INSERT || tdbp->GetAmType() == TYPE_AM_MYSQL - || tdbp->GetAmType() == TYPE_AM_ODBC - || tdbp->GetAmType() == TYPE_AM_JDBC) { + // g->More is 1 when executing commands from triggers + if (!g->More && (xmod != MODE_INSERT + || tdbp->GetAmType() == TYPE_AM_MYSQL + || tdbp->GetAmType() == TYPE_AM_ODBC + || tdbp->GetAmType() == TYPE_AM_JDBC)) { // Get the list of used fields (columns) char *p; unsigned int k1, k2, n1, n2; @@ -4674,7 +4676,10 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) PGLOBAL g= GetPlug(thd, xp); DBUG_ENTER("ha_connect::start_stmt"); - if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) + if (table->triggers) + g->More = 1; // We don't know which columns are used by the trigger + + if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Action will depend on lock_type @@ -7312,7 +7317,7 @@ maria_declare_plugin(connect) 0x0106, /* version number (1.06) */ NULL, /* status variables */ connect_system_variables, /* system variables */ - "1.06.0008", /* string version */ + "1.06.0009", /* string version */ MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; -- cgit v1.2.1 From 990f8e8146bfccb4739d385752f0127dab74dbdf Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sun, 3 Feb 2019 12:34:30 +0100 Subject: - Fix MDEV-13136: enhance CREATE SERVER MyServerName FOREIGN DATA WRAPPER to work with CONNECT engine modified: storage/connect/tabjdbc.cpp - Add a function to retrieve User variable value (DEVELOPMENT only) modified: storage/connect/ha_connect.cc modified: storage/connect/jsonudf.cpp modified: storage/connect/jsonudf.h modified: storage/connect/tabjdbc.cpp --- storage/connect/ha_connect.cc | 34 ++++++++++++++++++++++++++------ storage/connect/jsonudf.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ storage/connect/jsonudf.h | 5 +++++ storage/connect/tabjdbc.cpp | 22 ++++++++++++++------- 4 files changed, 94 insertions(+), 13 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 344e4708419..c92ba36d1f7 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -204,6 +204,26 @@ pthread_mutex_t parmut; pthread_mutex_t usrmut; pthread_mutex_t tblmut; +#if defined(DEVELOPMENT) +char *GetUserVariable(PGLOBAL g, const uchar *varname); + +char *GetUserVariable(PGLOBAL g, const uchar *varname) +{ + char buf[1024]; + bool b; + THD *thd= current_thd; + CHARSET_INFO *cs = system_charset_info; + String *str= NULL, tmp(buf, sizeof(buf), cs); + HASH uvars = thd->user_vars; + user_var_entry *uvar = (user_var_entry*)my_hash_search(&uvars, varname, 0); + + if (uvar) + str = uvar->val_str(&b, &tmp, NOT_FIXED_DEC); + + return str ? PlugDup(g, str->ptr()) : NULL; +}; // end of GetUserVariable +#endif // DEVELOPMENT + /***********************************************************************/ /* Utility functions. */ /***********************************************************************/ @@ -4633,7 +4653,9 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, break; case SQLCOM_CREATE_VIEW: case SQLCOM_DROP_VIEW: - newmode= MODE_ANY; + case SQLCOM_CREATE_TRIGGER: + case SQLCOM_DROP_TRIGGER: + newmode= MODE_ANY; break; case SQLCOM_ALTER_TABLE: *chk= true; @@ -6255,12 +6277,12 @@ int ha_connect::create(const char *name, TABLE *table_arg, TABLE *st= table; // Probably unuseful THD *thd= ha_thd(); LEX_CSTRING cnc = table_arg->s->connect_string; -#ifdef WITH_PARTITION_STORAGE_ENGINE - partition_info *part_info= table_arg->part_info; -#else +#if defined(WITH_PARTITION_STORAGE_ENGINE) + partition_info *part_info= table_arg->part_info; +#else // !WITH_PARTITION_STORAGE_ENGINE #define part_info 0 -#endif // WITH_PARTITION_STORAGE_ENGINE - xp= GetUser(thd, xp); +#endif // !WITH_PARTITION_STORAGE_ENGINE + xp= GetUser(thd, xp); PGLOBAL g= xp->g; DBUG_ENTER("ha_connect::create"); diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 42b276b6090..3e9b6ad625f 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -5806,6 +5806,52 @@ char *envar(UDF_INIT *initid, UDF_ARGS *args, char *result, return str; } // end of envar +#if defined(DEVELOPMENT) +extern char *GetUserVariable(PGLOBAL g, const uchar *varname); + +/*********************************************************************************/ +/* Utility function returning a user variable value. */ +/*********************************************************************************/ +my_bool uvar_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + unsigned long reslen, memlen; + + if (args->arg_count != 1) { + strcpy(message, "Unique argument must be a user variable name"); + return true; + } else + CalcLen(args, false, reslen, memlen, true); + + initid->maybe_null = true; + return JsonInit(initid, args, message, true, reslen, memlen, 2048); +} // end of uvar_init + +char *uvar(UDF_INIT *initid, UDF_ARGS *args, char *result, + unsigned long *res_length, char *is_null, char *) +{ + char *str, varname[256]; + PGLOBAL g = (PGLOBAL)initid->ptr; + int n = MY_MIN(args->lengths[0], sizeof(varname) - 1); + + PlugSubSet(g->Sarea, g->Sarea_Size); + memcpy(varname, args->args[0], n); + varname[n] = 0; + + if (!(str = GetUserVariable(g, (const uchar*)&varname))) { + *res_length = 0; + *is_null = 1; + } else + *res_length = strlen(str); + + return str; +} // end of uvar + +void uvar_deinit(UDF_INIT* initid) +{ + JsonFreeMem((PGLOBAL)initid->ptr); +} // end of uvar_deinit +#endif // DEVELOPMENT + /*********************************************************************************/ /* Returns the distinct number of B occurences in A. */ /*********************************************************************************/ diff --git a/storage/connect/jsonudf.h b/storage/connect/jsonudf.h index 23e8c0e1aed..ee56869a111 100644 --- a/storage/connect/jsonudf.h +++ b/storage/connect/jsonudf.h @@ -238,6 +238,11 @@ extern "C" { DllExport my_bool envar_init(UDF_INIT*, UDF_ARGS*, char*); DllExport char *envar(UDF_EXEC_ARGS); +#if defined(DEVELOPMENT) + DllExport my_bool uvar_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport char *uvar(UDF_EXEC_ARGS); +#endif // DEVELOPMENT + DllExport my_bool countin_init(UDF_INIT*, UDF_ARGS*, char*); DllExport long long countin(UDF_EXEC_ARGS); } // extern "C" diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index c6b2802c1f6..789daff6fcd 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -72,7 +72,6 @@ #include "tabext.h" #include "tabjdbc.h" #include "tabmul.h" -//#include "reldef.h" #include "tabcol.h" #include "valblk.h" #include "ha_connect.h" @@ -89,6 +88,9 @@ extern int num_read, num_there, num_eq[2]; // Statistics /* External function. */ /***********************************************************************/ bool ExactInfo(void); +#if defined(DEVELOPMENT) +extern char *GetUserVariable(PGLOBAL g, const uchar *varname); +#endif // DEVELOPMENT /* -------------------------- Class JDBCDEF -------------------------- */ @@ -147,10 +149,6 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b) return RC_FX; Tabname = p; -// } else if (b) { -// // Otherwise, straight server name, -// Tabname = GetStringCatInfo(g, "Name", NULL); -// Tabname = GetStringCatInfo(g, "Tabname", Tabname); } // endif if (trace(1)) @@ -165,6 +163,11 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b) return RC_FX; } // endif server +#if defined(DEVELOPMENT) + if (*server->host == '@') { + Url = GetUserVariable(g, (const uchar*)&server->host[1]); + } else +#endif // 0 if (strncmp(server->host, "jdbc:", 5)) { // Now make the required URL Url = (PSZ)PlugSubAlloc(g, NULL, 0); @@ -191,6 +194,9 @@ int JDBCDEF::ParseURL(PGLOBAL g, char *url, bool b) if (!Password && server->password) Password = PlugDup(g, server->password); + Driver = PlugDup(g, GetListOption(g, "Driver", server->owner, NULL)); + Wrapname = PlugDup(g, GetListOption(g, "Wrapper", server->owner, NULL)); + Memory = atoi(GetListOption(g, "Memory", server->owner, "0")); return RC_NF; } // endif @@ -208,7 +214,6 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) if (EXTDEF::DefineAM(g, am, poff)) return true; - Driver = GetStringCatInfo(g, "Driver", NULL); Desc = Url = GetStringCatInfo(g, "Connect", NULL); if (!Url && !Catfunc) { @@ -228,7 +233,10 @@ bool JDBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) return true; } // endif rc - Wrapname = GetStringCatInfo(g, "Wrapper", NULL); + // Default values may have been set in ParseURL + Memory = GetIntCatInfo("Memory", Memory); + Driver = GetStringCatInfo(g, "Driver", Driver); + Wrapname = GetStringCatInfo(g, "Wrapper", Wrapname); return false; } // end of DefineAM -- cgit v1.2.1 From 0a43be392930144aca5c883fe868c4cab1d433fb Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 4 Mar 2019 12:18:35 +0100 Subject: - Fix MDEV-18292: CONNECT Engine JDBC not able to issue simple UPDATE statement from trigger or stored procedure Was not fixed when the same table was called several times with different modes. Fixed by checking if a new statement is compatible in the start_stmt function. It nows do the same checks than external_lock. modified: storage/connect/ha_connect.cc modified: storage/connect/ha_connect.h - typo modified: storage/connect/user_connect.cc --- storage/connect/ha_connect.cc | 81 +++++++++++++++++++---------------------- storage/connect/ha_connect.h | 1 + storage/connect/user_connect.cc | 1 + 3 files changed, 40 insertions(+), 43 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index c92ba36d1f7..5326d12975a 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -3663,7 +3663,7 @@ int ha_connect::update_row(const uchar *old_data, const uchar *new_data) // Check values for possible change in indexed column if ((rc= CheckRecord(g, old_data, new_data))) - DBUG_RETURN(rc); + DBUG_RETURN(rc); if (CntUpdateRow(g, tdbp)) { DBUG_PRINT("update_row", ("%s", g->Message)); @@ -4698,9 +4698,6 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) PGLOBAL g= GetPlug(thd, xp); DBUG_ENTER("ha_connect::start_stmt"); - if (table->triggers) - g->More = 1; // We don't know which columns are used by the trigger - if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); @@ -4714,7 +4711,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) case TL_WRITE: case TL_WRITE_ONLY: newmode= MODE_WRITE; - break; + break; case TL_READ: case TL_READ_WITH_SHARED_LOCKS: case TL_READ_HIGH_PRIORITY: @@ -4728,8 +4725,24 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) break; } // endswitch mode - xmod= CheckMode(g, thd, newmode, &chk, &cras); - DBUG_RETURN((xmod == MODE_ERROR) ? HA_ERR_INTERNAL_ERROR : 0); + if (newmode == MODE_ANY) { + if (CloseTable(g)) { + // Make error a warning to avoid crash + push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); + rc= 0; + } // endif Close + + locked= 0; + xmod= MODE_ANY; // For info commands + DBUG_RETURN(rc); + } // endif MODE_ANY + + newmode= CheckMode(g, thd, newmode, &chk, &cras); + + if (newmode == MODE_ERROR) + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + + DBUG_RETURN(check_stmt(g, newmode, cras)); } // end of start_stmt /** @@ -4911,22 +4924,16 @@ int ha_connect::external_lock(THD *thd, int lock_type) // Make it a warning to avoid crash push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); rc= 0; - //my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); - //rc = HA_ERR_INTERNAL_ERROR; } // endif Close locked= 0; -// m_lock_type= lock_type; xmod= MODE_ANY; // For info commands DBUG_RETURN(rc); - } // endif MODE_ANY - else - if (check_privileges(thd, options, table->s->db.str)) { + } else if (check_privileges(thd, options, table->s->db.str)) { strcpy(g->Message, "This operation requires the FILE privilege"); htrc("%s\n", g->Message); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); - } // endif check_privileges - + } // endif check_privileges DBUG_ASSERT(table && table->s); @@ -4936,42 +4943,30 @@ int ha_connect::external_lock(THD *thd, int lock_type) if (newmode == MODE_ERROR) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); - // If this is the start of a new query, cleanup the previous one + DBUG_RETURN(check_stmt(g, newmode, cras)); +} // end of external_lock + + +int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) +{ + int rc= 0; + DBUG_ENTER("ha_connect::check_lock"); + + // If this is the start of a new query, cleanup the previous one if (xp->CheckCleanup()) { tdbp= NULL; valid_info= false; - } // endif CheckCleanup - -#if 0 - if (xcheck) { - // This must occur after CheckCleanup - if (!g->Xchk) { - g->Xchk= new(g) XCHK; - ((PCHK)g->Xchk)->oldsep= GetBooleanOption("Sepindex", false); - ((PCHK)g->Xchk)->oldpix= GetIndexInfo(); - } // endif Xchk - - } else - g->Xchk= NULL; -#endif // 0 + } // endif CheckCleanup if (cras) g->Createas= 1; // To tell external tables of a multi-table command - if (trace(1)) { -#if 0 - htrc("xcheck=%d cras=%d\n", xcheck, cras); - - if (xcheck) - htrc("oldsep=%d oldpix=%p\n", - ((PCHK)g->Xchk)->oldsep, ((PCHK)g->Xchk)->oldpix); -#endif // 0 + if (trace(1)) htrc("Calling CntCheckDB db=%s cras=%d\n", GetDBName(NULL), cras); - } // endif trace // Set or reset the good database environment if (CntCheckDB(g, this, GetDBName(NULL))) { - htrc("%p external_lock: %s\n", this, g->Message); + htrc("%p check_lock: %s\n", this, g->Message); rc= HA_ERR_INTERNAL_ERROR; // This can NOT be called without open called first, but // the table can have been closed since then @@ -4984,7 +4979,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) else tdbp= NULL; - } // endif tdbp + } // endif tdbp xmod= newmode; @@ -4992,10 +4987,10 @@ int ha_connect::external_lock(THD *thd, int lock_type) } // endif tdbp if (trace(1)) - htrc("external_lock: rc=%d\n", rc); + htrc("check_lock: rc=%d\n", rc); DBUG_RETURN(rc); -} // end of external_lock +} // end of check_stmt /** diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index 6bce46ead95..f34c6ba890a 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -507,6 +507,7 @@ private: protected: bool check_privileges(THD *thd, PTOS options, const char *dbn, bool quick=false); MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras); + int check_stmt(PGLOBAL g, MODE newmode, bool cras); char *GetDBfromName(const char *name); // Members diff --git a/storage/connect/user_connect.cc b/storage/connect/user_connect.cc index a2a8faf9b38..ec591f9e4ef 100644 --- a/storage/connect/user_connect.cc +++ b/storage/connect/user_connect.cc @@ -177,6 +177,7 @@ bool user_connect::CheckCleanup(bool force) g->Createas = 0; g->Alchecked = 0; g->Mrr = 0; + g->More = 0; last_query_id= thdp->query_id; if (trace(65) && !force) -- cgit v1.2.1 From 66197aa0d5f13019065a0460b0645963223da063 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 4 Mar 2019 12:26:47 +0100 Subject: Typo --- storage/connect/ha_connect.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 5326d12975a..0130e627c88 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -3663,7 +3663,7 @@ int ha_connect::update_row(const uchar *old_data, const uchar *new_data) // Check values for possible change in indexed column if ((rc= CheckRecord(g, old_data, new_data))) - DBUG_RETURN(rc); + DBUG_RETURN(rc); if (CntUpdateRow(g, tdbp)) { DBUG_PRINT("update_row", ("%s", g->Message)); @@ -4712,7 +4712,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) case TL_WRITE_ONLY: newmode= MODE_WRITE; break; - case TL_READ: + case TL_READ: case TL_READ_WITH_SHARED_LOCKS: case TL_READ_HIGH_PRIORITY: case TL_READ_NO_INSERT: @@ -4950,7 +4950,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) { int rc= 0; - DBUG_ENTER("ha_connect::check_lock"); + DBUG_ENTER("ha_connect::check_stmt"); // If this is the start of a new query, cleanup the previous one if (xp->CheckCleanup()) { @@ -4966,7 +4966,7 @@ int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) // Set or reset the good database environment if (CntCheckDB(g, this, GetDBName(NULL))) { - htrc("%p check_lock: %s\n", this, g->Message); + htrc("%p check_stmt: %s\n", this, g->Message); rc= HA_ERR_INTERNAL_ERROR; // This can NOT be called without open called first, but // the table can have been closed since then @@ -4987,7 +4987,7 @@ int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) } // endif tdbp if (trace(1)) - htrc("check_lock: rc=%d\n", rc); + htrc("check_stmt: rc=%d\n", rc); DBUG_RETURN(rc); } // end of check_stmt -- cgit v1.2.1 From ec4795add694349c191b5f2e8d5f1c7e64008441 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 27 Jun 2019 17:54:28 +0200 Subject: In CONNECT version 1.6.10 NOSQL facility is enhanced by a new way to retrieve NOSQL data. In addition to files and Mongo collections, JSON as well as XML and CSV data can be retrieved from the net as answers from REST queries. Because it uses and external package (cpprestsdk) this is currently available only to MariaDB servers compiled from source. -- Add the REST support when Microsoft Casablanca package (cpprestsdk) is installed. -- Also include some changes specific to MariaDB 10.3. modified: storage/connect/CMakeLists.txt -- Add conditional REST support -- Added string options HTTP and URI. -- Added added internal table type TAB_REST. modified: storage/connect/ha_connect.cc modified: storage/connect/mycat.cc modified: storage/connect/mycat.h modified: storage/connect/plgdbsem.h -- Fix MDEV-19648 Variable connect_conv_size doesn't change -- Change Variable wrong block parameter from 8169 to 1. -- Also change connect_conv_size default value to 1024. modified: storage/connect/ha_connect.cc -- Avoid possible buffer overflow -- In particular by the function ShowValue. modified: storage/connect/tabdos.cpp modified: storage/connect/tabfmt.cpp modified: storage/connect/value.cpp modified: storage/connect/value.h -- Add some cast to avoid some compiler warnings modified: storage/connect/filamdbf.cpp -- Fix some C++ error modified: storage/connect/javaconn.cpp modified: storage/connect/jmgoconn.cpp modified: storage/connect/plugutil.cpp -- Miscellaneous Typo and warning suppressing changes modified: storage/connect/connect.cpp modified: storage/connect/connect.h modified: storage/connect/filamvct.cpp modified: storage/connect/inihandl.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/libdoc.cpp modified: storage/connect/tabjson.cpp modified: storage/connect/tabtbl.cpp modified: storage/connect/tabxml.cpp modified: storage/connect/user_connect.cc modified: storage/connect/user_connect.h -- Update failing test results and disbling modified: storage/connect/mysql-test/connect/disabled.def modified: storage/connect/mysql-test/connect/r/dir.result modified: storage/connect/mysql-test/connect/r/grant.result modified: storage/connect/mysql-test/connect/r/jdbc.result modified: storage/connect/mysql-test/connect/r/jdbc_postgresql.result modified: storage/connect/mysql-test/connect/r/xml.result modified: storage/connect/mysql-test/connect/r/xml2.result modified: storage/connect/mysql-test/connect/r/xml2_mult.result modified: storage/connect/mysql-test/connect/r/xml_mult.result -- Add an option modified: storage/connect/mysql-test/connect/t/grant.test --- storage/connect/CMakeLists.txt | 70 +++- storage/connect/connect.cc | 2 +- storage/connect/connect.h | 2 +- storage/connect/filamdbf.cpp | 4 +- storage/connect/filamvct.cpp | 5 - storage/connect/ha_connect.cc | 465 ++++++++++++--------- storage/connect/ha_connect.h | 8 +- storage/connect/inihandl.cpp | 2 +- storage/connect/javaconn.cpp | 2 +- storage/connect/jmgoconn.cpp | 5 +- storage/connect/jsonudf.cpp | 11 +- storage/connect/libdoc.cpp | 2 +- storage/connect/mycat.cc | 31 +- storage/connect/mycat.h | 6 +- storage/connect/mysql-test/connect/disabled.def | 23 +- storage/connect/mysql-test/connect/r/dir.result | 2 +- storage/connect/mysql-test/connect/r/grant.result | 2 +- storage/connect/mysql-test/connect/r/jdbc.result | 12 + .../mysql-test/connect/r/jdbc_postgresql.result | 10 +- storage/connect/mysql-test/connect/r/xml.result | 2 +- storage/connect/mysql-test/connect/r/xml2.result | 2 +- .../connect/mysql-test/connect/r/xml2_mult.result | 8 +- .../connect/mysql-test/connect/r/xml_mult.result | 8 +- storage/connect/mysql-test/connect/t/grant.test | 2 +- storage/connect/plgdbsem.h | 6 +- storage/connect/plugutil.cpp | 2 +- storage/connect/restget.cpp | 87 ++++ storage/connect/tabdos.cpp | 71 ++-- storage/connect/tabfmt.cpp | 13 +- storage/connect/tabjson.cpp | 2 +- storage/connect/tabrest.cpp | 133 ++++++ storage/connect/tabrest.h | 29 ++ storage/connect/tabtbl.cpp | 2 +- storage/connect/tabxml.cpp | 2 +- storage/connect/user_connect.cc | 4 +- storage/connect/user_connect.h | 2 +- storage/connect/value.cpp | 97 ++--- storage/connect/value.h | 16 +- 38 files changed, 752 insertions(+), 400 deletions(-) create mode 100644 storage/connect/restget.cpp create mode 100644 storage/connect/tabrest.cpp create mode 100644 storage/connect/tabrest.h diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 782d1f44bdf..153512b994c 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -11,7 +11,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA SET(CONNECT_PLUGIN_STATIC "connect") SET(CONNECT_PLUGIN_DYNAMIC "connect") @@ -40,6 +40,10 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS) add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT ) +macro(DISABLE_WARNING W) + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-error=${W}") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-${W}" DEBUG) +endmacro() # # OS specific C flags, definitions and source files. @@ -47,14 +51,15 @@ add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT ) IF(UNIX) MY_CHECK_AND_SET_COMPILER_FLAG("-Wall -Wmissing-declarations") if(NOT WITH_WARNINGS) - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-function") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-variable") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-value") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-parentheses") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-misleading-indentation") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-format-truncation") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough") + DISABLE_WARNING("unused-function") + DISABLE_WARNING("unused-variable") + DISABLE_WARNING("unused-value") + DISABLE_WARNING("parentheses") + DISABLE_WARNING("strict-aliasing") + DISABLE_WARNING("misleading-indentation") + DISABLE_WARNING("format-truncation") + DISABLE_WARNING("implicit-fallthrough") + DISABLE_WARNING("type-limits") endif(NOT WITH_WARNINGS) add_definitions( -DUNIX -DLINUX -DUBUNTU ) @@ -113,6 +118,7 @@ IF(CONNECT_WITH_LIBXML2) FIND_PACKAGE(LibXml2) IF (LIBXML2_FOUND) INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) + SET(ZLIB_LIBRARY "z") # see ZLIB_INCLUDE_DIR below SET(XML_LIBRARY ${LIBXML2_LIBRARIES}) SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h) add_definitions(-DLIBXML2_SUPPORT) @@ -128,7 +134,6 @@ IF(WIN32) OPTION(CONNECT_WITH_MSXML "Compile CONNECT storage engine with MSXML support" ON) IF(CONNECT_WITH_MSXML) add_definitions(-DMSX6 -DDOMDOC_SUPPORT) - message(STATUS "MSXML library version: msxml6") SET(MSXML_FOUND 1) SET(CONNECT_SOURCES ${CONNECT_SOURCES} domdoc.cpp domdoc.h) ENDIF(CONNECT_WITH_MSXML) @@ -168,7 +173,8 @@ IF(CONNECT_WITH_ODBC) # the library 'libiodbc' gets compiled with 'sql'h. # This will also need changes in the sources (e.g. #include ). - find_path(ODBC_INCLUDE_DIR sql.h + find_file(ODBC_INCLUDES sql.h + PATHS /usr/include /usr/include/odbc /usr/local/include @@ -178,7 +184,7 @@ IF(CONNECT_WITH_ODBC) #"C:/Program Files/Microsoft SDKs/Windows/v7.0A/include" #"C:/Program Files/Microsoft SDKs/Windows/v6.0a/include" #"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include" - DOC "Specify the directory containing sql.h." + DOC "Specify the path to sql.h." ) find_library(ODBC_LIBRARY @@ -197,9 +203,10 @@ IF(CONNECT_WITH_ODBC) DOC "Specify the ODBC driver manager library here." ) - mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR) + mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDES) - IF(ODBC_INCLUDE_DIR AND ODBC_LIBRARY) + IF(ODBC_INCLUDES AND ODBC_LIBRARY) + get_filename_component(ODBC_INCLUDE_DIR "${ODBC_INCLUDES}" PATH) set(CMAKE_REQUIRED_LIBRARIES ${ODBC_LIBRARY}) set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIR}) CHECK_CXX_SOURCE_COMPILES( @@ -305,6 +312,24 @@ IF(CONNECT_WITH_MONGO) ENDIF(CONNECT_WITH_MONGO) +# +# REST +# + +#OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) + +IF(CONNECT_WITH_REST) + MESSAGE(STATUS "=====> REST support is ON") + FIND_PACKAGE(cpprestsdk) + IF (cpprestsdk_FOUND) + MESSAGE(STATUS "=====> cpprestsdk found") + SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) + add_definitions(-DREST_SUPPORT) + ELSE(NOT cpprestsdk_FOUND) + MESSAGE(STATUS "=====> cpprestsdk package not found") + ENDIF (cpprestsdk_FOUND) +ENDIF(CONNECT_WITH_ZIP) + # # XMAP # @@ -330,6 +355,14 @@ IF(NOT TARGET connect) RETURN() ENDIF() +# Don't link with bundled zlib and systel libxml2 at the same time. +# System libxml2 uses system zlib, might conflict with the bundled one. +IF (XML_LIBRARY AND BUILD_BUNDLED_ZLIB) + GET_PROPERTY(INCS TARGET connect PROPERTY INCLUDE_DIRECTORIES) + LIST(REMOVE_ITEM INCS ${ZLIB_INCLUDE_DIR}) + SET_PROPERTY(TARGET connect PROPERTY INCLUDE_DIRECTORIES ${INCS}) +ENDIF() + IF(WIN32) IF (libmongoc-1.0_FOUND) SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS @@ -338,14 +371,7 @@ IF(WIN32) # Install some extra files that belong to connect engine - # install ha_connect.lib - GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION) - STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION}) - IF(CMAKE_CONFIGURATION_TYPES) - STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" - CONNECT_LIB ${CONNECT_LIB}) - ENDIF() - INSTALL(FILES ${CONNECT_LIB} + INSTALL(FILES "$/ha_connect.lib" DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF(WIN32) diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index 2460449ac62..b1078de8eaa 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /***********************************************************************/ /* Author Olivier BERTRAND bertrandop@gmail.com 2004-2017 */ diff --git a/storage/connect/connect.h b/storage/connect/connect.h index 2bca8bf54cb..cf0373ba635 100644 --- a/storage/connect/connect.h +++ b/storage/connect/connect.h @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /**************** Cnt H Declares Source Code File (.H) *****************/ /* Name: CONNECT.H Version 2.4 */ diff --git a/storage/connect/filamdbf.cpp b/storage/connect/filamdbf.cpp index 893e3da0d46..c8bab2b53a4 100644 --- a/storage/connect/filamdbf.cpp +++ b/storage/connect/filamdbf.cpp @@ -447,7 +447,7 @@ int DBFFAM::Cardinality(PGLOBAL g) if (rln && Lrecl != rln) { // This happens always on some Linux platforms - sprintf(g->Message, MSG(BAD_LRECL), Lrecl, rln); + sprintf(g->Message, MSG(BAD_LRECL), Lrecl, (ushort)rln); if (Accept) { Lrecl = rln; @@ -967,7 +967,7 @@ int DBMFAM::Cardinality(PGLOBAL g) if (rln && Lrecl != rln) { // This happens always on some Linux platforms - sprintf(g->Message, MSG(BAD_LRECL), Lrecl, rln); + sprintf(g->Message, MSG(BAD_LRECL), Lrecl, (ushort)rln); if (Accept) { Lrecl = rln; diff --git a/storage/connect/filamvct.cpp b/storage/connect/filamvct.cpp index e8a4ba890bf..6d0779b150a 100644 --- a/storage/connect/filamvct.cpp +++ b/storage/connect/filamvct.cpp @@ -65,11 +65,6 @@ extern int num_read, num_there; // Statistics static int num_write; -#if defined(UNIX) -// Add dummy strerror (NGC) -char *strerror(int num); -#endif // UNIX - /***********************************************************************/ /* Header containing block info for not split VEC tables. */ /* Block and last values can be calculated from NumRec and Nrec. */ diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 0130e627c88..eb5356e81c3 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /** @file ha_connect.cc @@ -164,18 +164,18 @@ /***********************************************************************/ /* Initialize the ha_connect static members. */ /***********************************************************************/ -#define SZCONV 8192 +#define SZCONV 1024 // Default TEXT conversion size #define SZWORK 67108864 // Default work area size 64M #define SZWMIN 4194304 // Minimum work area size 4M #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[] = "Version 1.06.0009 January 27, 2019"; + char version[]= "Version 1.06.0010 June 21, 2019"; #if defined(__WIN__) - char compver[]= "Version 1.06.0009 " __DATE__ " " __TIME__; - char slash= '\\'; + char compver[]= "Version 1.06.0010 " __DATE__ " " __TIME__; + char slash= '\\'; #else // !__WIN__ - char slash= '/'; + char slash= '/'; #endif // !__WIN__ } // extern "C" @@ -212,13 +212,13 @@ char *GetUserVariable(PGLOBAL g, const uchar *varname) char buf[1024]; bool b; THD *thd= current_thd; - CHARSET_INFO *cs = system_charset_info; + CHARSET_INFO *cs= system_charset_info; String *str= NULL, tmp(buf, sizeof(buf), cs); - HASH uvars = thd->user_vars; - user_var_entry *uvar = (user_var_entry*)my_hash_search(&uvars, varname, 0); + HASH uvars= thd->user_vars; + user_var_entry *uvar= (user_var_entry*)my_hash_search(&uvars, varname, 0); if (uvar) - str = uvar->val_str(&b, &tmp, NOT_FIXED_DEC); + str= uvar->val_str(&b, &tmp, NOT_FIXED_DEC); return str ? PlugDup(g, str->ptr()) : NULL; }; // end of GetUserVariable @@ -231,6 +231,9 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); PQRYRES VirColumns(PGLOBAL g, bool info); PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info); PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info); +#if defined(REST_SUPPORT) +PQRYRES RESTColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); +#endif // REST_SUPPORT #if defined(JAVA_SUPPORT) PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ url, PTOS topt, bool info); #endif // JAVA_SUPPORT @@ -252,9 +255,7 @@ char *GetJavaWrapper(void); uint GetWorkSize(void); void SetWorkSize(uint); extern "C" const char *msglang(void); - static char *strz(PGLOBAL g, LEX_CSTRING &ls); - static void PopUser(PCONNECT xp); static PCONNECT GetUser(THD *thd, PCONNECT xp); static PGLOBAL GetPlug(THD *thd, PCONNECT& lxp); @@ -352,7 +353,7 @@ static MYSQL_THDVAR_UINT(work_size, static MYSQL_THDVAR_INT(conv_size, PLUGIN_VAR_RQCMDARG, // opt "Size used when converting TEXT columns.", - NULL, NULL, SZCONV, 0, 65500, 8192); + NULL, NULL, SZCONV, 0, 65500, 1); /** Type conversion: @@ -583,6 +584,8 @@ ha_create_table_option connect_table_option_list[]= HA_TOPTION_STRING("FILTER", filter), HA_TOPTION_STRING("OPTION_LIST", oplist), HA_TOPTION_STRING("DATA_CHARSET", data_charset), + HA_TOPTION_STRING("HTTP", http), + HA_TOPTION_STRING("URI", uri), HA_TOPTION_NUMBER("LRECL", lrecl, 0, 0, INT_MAX32, 1), HA_TOPTION_NUMBER("BLOCK_SIZE", elements, 0, 0, INT_MAX32, 1), //HA_TOPTION_NUMBER("ESTIMATE", estimate, 0, 0, INT_MAX32, 1), @@ -1027,6 +1030,19 @@ TABTYPE ha_connect::GetRealType(PTOS pos) if (type == TAB_UNDEF) type= pos->srcdef ? TAB_MYSQL : pos->tabname ? TAB_PRX : TAB_DOS; +#if defined(REST_SUPPORT) + else if (pos->http) + switch (type) { + case TAB_JSON: + case TAB_XML: + case TAB_CSV: + type= TAB_REST; + break; + case TAB_REST: + type= TAB_NIY; + break; + } // endswitch type +#endif // REST_SUPPORT } else type= TAB_UNDEF; @@ -1222,6 +1238,10 @@ PCSZ GetStringTableOption(PGLOBAL g, PTOS options, PCSZ opname, PCSZ sdef) opval = options->filter; else if (!stricmp(opname, "Data_charset")) opval= options->data_charset; + else if (!stricmp(opname, "Http") || !stricmp(opname, "URL")) + opval= options->http; + else if (!stricmp(opname, "Uri")) + opval= options->uri; if (!opval && options->oplist) opval= GetListOption(g, opname, options->oplist); @@ -1337,7 +1357,7 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef) if (!stricmp(opname, "Connect")) { LEX_CSTRING cnc= (tshp) ? tshp->connect_string - : table->s->connect_string; + : table->s->connect_string; if (cnc.length) opval= strz(xp->g, cnc); @@ -1798,13 +1818,13 @@ bool ha_connect::CheckVirtualIndex(TABLE_SHARE *s) bool ha_connect::IsPartitioned(void) { #ifdef WITH_PARTITION_STORAGE_ENGINE - if (tshp) + if (tshp) return tshp->partition_info_str_len > 0; else if (table && table->part_info) return true; else #endif - return false; + return false; } // end of IsPartitioned @@ -1815,7 +1835,9 @@ PCSZ ha_connect::GetDBName(PCSZ name) const char *ha_connect::GetTableName(void) { - return tshp ? tshp->table_name.str : table_share->table_name.str; + const char *path= tshp ? tshp->path.str : table_share->path.str; + const char *name= strrchr(path, slash); + return name ? name + 1 : path; } // end of GetTableName char *ha_connect::GetPartName(void) @@ -1935,10 +1957,10 @@ int ha_connect::OpenTable(PGLOBAL g, bool del) } // endswitch xmode // g->More is 1 when executing commands from triggers - if (!g->More && (xmod != MODE_INSERT + if (!g->More && (xmod != MODE_INSERT || tdbp->GetAmType() == TYPE_AM_MYSQL - || tdbp->GetAmType() == TYPE_AM_ODBC - || tdbp->GetAmType() == TYPE_AM_JDBC)) { + || tdbp->GetAmType() == TYPE_AM_ODBC + || tdbp->GetAmType() == TYPE_AM_JDBC)) { // Get the list of used fields (columns) char *p; unsigned int k1, k2, n1, n2; @@ -3364,7 +3386,7 @@ int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt) } // end of check - /** +/** Return an error message specific to this handler. @param error error code previously returned by handler @@ -3386,7 +3408,7 @@ bool ha_connect::get_error_message(int error, String* buf) buf->append(ErrConvString(g->Message, strlen(g->Message), &my_charset_latin1).ptr()); } else - buf->append("Cannot retrieve error message"); + buf->append("Cannot retrieve error message"); DBUG_RETURN(false); } // end of get_error_message @@ -3518,7 +3540,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*) if (rc) my_message(ER_WARN_DATA_OUT_OF_RANGE, g->Message, MYF(0)); - return rc; + return rc; } // end of optimize /** @@ -3663,7 +3685,7 @@ int ha_connect::update_row(const uchar *old_data, const uchar *new_data) // Check values for possible change in indexed column if ((rc= CheckRecord(g, old_data, new_data))) - DBUG_RETURN(rc); + DBUG_RETURN(rc); if (CntUpdateRow(g, tdbp)) { DBUG_PRINT("update_row", ("%s", g->Message)); @@ -4444,6 +4466,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, const char *dbn, bool case TAB_XML: case TAB_INI: case TAB_VEC: + case TAB_REST: case TAB_JSON: if (options->filename && *options->filename) { if (!quick) { @@ -4582,10 +4605,10 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, case SQLCOM_DELETE_MULTI: *cras = true; case SQLCOM_DELETE: - case SQLCOM_TRUNCATE: + case SQLCOM_TRUNCATE: newmode= MODE_DELETE; break; - case SQLCOM_UPDATE_MULTI: + case SQLCOM_UPDATE_MULTI: *cras = true; case SQLCOM_UPDATE: newmode= MODE_UPDATE; @@ -4698,7 +4721,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) PGLOBAL g= GetPlug(thd, xp); DBUG_ENTER("ha_connect::start_stmt"); - if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) + if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true)) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Action will depend on lock_type @@ -4711,8 +4734,8 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) case TL_WRITE: case TL_WRITE_ONLY: newmode= MODE_WRITE; - break; - case TL_READ: + break; + case TL_READ: case TL_READ_WITH_SHARED_LOCKS: case TL_READ_HIGH_PRIORITY: case TL_READ_NO_INSERT: @@ -4733,11 +4756,11 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) } // endif Close locked= 0; - xmod= MODE_ANY; // For info commands + xmod= MODE_ANY; // For info commands DBUG_RETURN(rc); } // endif MODE_ANY - newmode= CheckMode(g, thd, newmode, &chk, &cras); + newmode= CheckMode(g, thd, newmode, &chk, &cras); if (newmode == MODE_ERROR) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); @@ -4929,11 +4952,12 @@ int ha_connect::external_lock(THD *thd, int lock_type) locked= 0; xmod= MODE_ANY; // For info commands DBUG_RETURN(rc); - } else if (check_privileges(thd, options, table->s->db.str)) { - strcpy(g->Message, "This operation requires the FILE privilege"); - htrc("%s\n", g->Message); - DBUG_RETURN(HA_ERR_INTERNAL_ERROR); - } // endif check_privileges + } else if (check_privileges(thd, options, table->s->db.str)) { + strcpy(g->Message, "This operation requires the FILE privilege"); + htrc("%s\n", g->Message); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif check_privileges + DBUG_ASSERT(table && table->s); @@ -4956,18 +4980,18 @@ int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) if (xp->CheckCleanup()) { tdbp= NULL; valid_info= false; - } // endif CheckCleanup + } // endif CheckCleanup if (cras) - g->Createas= 1; // To tell external tables of a multi-table command + g->Createas= 1; // To tell external tables of a multi-table command - if (trace(1)) - htrc("Calling CntCheckDB db=%s cras=%d\n", GetDBName(NULL), cras); + if (trace(1)) + htrc("Calling CntCheckDB db=%s cras=%d\n", GetDBName(NULL), cras); // Set or reset the good database environment if (CntCheckDB(g, this, GetDBName(NULL))) { - htrc("%p check_stmt: %s\n", this, g->Message); - rc= HA_ERR_INTERNAL_ERROR; + htrc("%p check_stmt: %s\n", this, g->Message); + rc= HA_ERR_INTERNAL_ERROR; // This can NOT be called without open called first, but // the table can have been closed since then } else if (!tdbp || xp->CheckQuery(valid_query_id) || xmod != newmode) { @@ -4979,7 +5003,7 @@ int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) else tdbp= NULL; - } // endif tdbp + } // endif tdbp xmod= newmode; @@ -4987,7 +5011,7 @@ int ha_connect::check_stmt(PGLOBAL g, MODE newmode, bool cras) } // endif tdbp if (trace(1)) - htrc("check_stmt: rc=%d\n", rc); + htrc("check_stmt: rc=%d\n", rc); DBUG_RETURN(rc); } // end of check_stmt @@ -5511,7 +5535,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, PCSZ fncn= "?"; PCSZ user, fn, db, host, pwd, sep, tbl, src; PCSZ col, ocl, rnk, pic, fcl, skc, zfn; - char *tab, *dsn, *shm, *dpath; + char *tab, *dsn, *shm, *dpath, *url; #if defined(__WIN__) PCSZ nsp= NULL, cls= NULL; #endif // __WIN__ @@ -5527,7 +5551,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(JAVA_SUPPORT) PJPARM sjp= NULL; PCSZ driver= NULL; - char *url= NULL; #endif // JAVA_SUPPORT uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL); bool bif, ok= false, dbf= false; @@ -5547,7 +5570,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, String sql(buf, sizeof(buf), system_charset_info); sql.copy(STRING_WITH_LEN("CREATE TABLE whatever ("), system_charset_info); - user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= zfn= dsn= NULL; + user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= zfn= NULL; + dsn= url= NULL; // Get the useful create options ttp= GetTypeID(topt->type); @@ -5558,7 +5582,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, fncn= topt->catfunc; fnc= GetFuncID(fncn); sep= topt->separator; - mul = (int)topt->multiple; + mul= (int)topt->multiple; tbl= topt->tablist; col= topt->colist; @@ -5596,9 +5620,11 @@ static int connect_assisted_discovery(handlerton *, THD* thd, cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0")); #endif // PROMPT_OK #if defined(ZIP_SUPPORT) - zfn = GetListOption(g, "Zipfile", topt->oplist, NULL); + zfn= GetListOption(g, "Zipfile", topt->oplist, NULL); #endif // ZIP_SUPPORT - } else { + } + else + { host= "localhost"; user= ((ttp == TAB_ODBC || ttp == TAB_JDBC) ? NULL : "root"); } // endif option_list @@ -5609,14 +5635,25 @@ static int connect_assisted_discovery(handlerton *, THD* thd, try { // Check table type if (ttp == TAB_UNDEF) { - topt->type = (src) ? "MYSQL" : (tab) ? "PROXY" : "DOS"; - ttp = GetTypeID(topt->type); + topt->type= (src) ? "MYSQL" : (tab) ? "PROXY" : "DOS"; + ttp= GetTypeID(topt->type); sprintf(g->Message, "No table_type. Was set to %s", topt->type); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); - } else if (ttp == TAB_NIY) { + } + else if (ttp == TAB_NIY) { sprintf(g->Message, "Unsupported table type %s", topt->type); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; +#if defined(REST_SUPPORT) + } else if (topt->http) { + switch (ttp) { + case TAB_JSON: + case TAB_XML: + case TAB_CSV: + ttp= TAB_REST; + break; + } // endswitch type +#endif // REST_SUPPORT } // endif ttp if (!tab) { @@ -5626,39 +5663,39 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (!tbl) { strcpy(g->Message, "Missing table list"); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif tbl - tab = PlugDup(g, tbl); + tab= PlugDup(g, tbl); - if ((p = strchr(tab, ','))) - *p = 0; + if ((p= strchr(tab, ','))) + *p= 0; - if ((p = strchr(tab, '.'))) { - *p = 0; - db = tab; - tab = p + 1; + if ((p= strchr(tab, '.'))) { + *p= 0; + db= tab; + tab= p + 1; } // endif p } else if (ttp != TAB_ODBC || !(fnc & (FNC_TABLE | FNC_COL))) - tab = (char*) table_s->table_name.str; // Default value + tab= (char*)table_s->table_name.str; // Default value } // endif tab switch (ttp) { #if defined(ODBC_SUPPORT) case TAB_ODBC: - dsn = strz(g, create_info->connect_string); + dsn= strz(g, create_info->connect_string); if (fnc & (FNC_DSN | FNC_DRIVER)) { - ok = true; + ok= true; #if defined(PROMPT_OK) } else if (!stricmp(thd->main_security_ctx.host, "localhost") && cop == 1) { if ((dsn = ODBCCheckConnection(g, dsn, cop)) != NULL) { thd->make_lex_string(&create_info->connect_string, dsn, strlen(dsn)); - ok = true; + ok= true; } // endif dsn #endif // PROMPT_OK @@ -5666,13 +5703,13 @@ static int connect_assisted_discovery(handlerton *, THD* thd, sprintf(g->Message, "Missing %s connection string", topt->type); } else { // Store ODBC additional parameters - sop = (POPARM)PlugSubAlloc(g, NULL, sizeof(ODBCPARM)); - sop->User = (char*)user; - sop->Pwd = (char*)pwd; - sop->Cto = cto; - sop->Qto = qto; - sop->UseCnc = cnc; - ok = true; + sop= (POPARM)PlugSubAlloc(g, NULL, sizeof(ODBCPARM)); + sop->User= (char*)user; + sop->Pwd= (char*)pwd; + sop->Cto= cto; + sop->Qto= qto; + sop->UseCnc= cnc; + ok= true; } // endif's supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER); @@ -5681,31 +5718,31 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(JAVA_SUPPORT) case TAB_JDBC: if (fnc & FNC_DRIVER) { - ok = true; - } else if (!(url = strz(g, create_info->connect_string))) { + ok= true; + } else if (!(url= strz(g, create_info->connect_string))) { strcpy(g->Message, "Missing URL"); } else { // Store JDBC additional parameters int rc; - PJDBCDEF jdef = new(g) JDBCDEF(); + PJDBCDEF jdef= new(g) JDBCDEF(); jdef->SetName(create_info->alias.str); - sjp = (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM)); - sjp->Driver = driver; + sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM)); + sjp->Driver= driver; // sjp->Properties = prop; - sjp->Fsize = 0; - sjp->Scrollable = false; - - if ((rc = jdef->ParseURL(g, url, false)) == RC_OK) { - sjp->Url = url; - sjp->User = (char*)user; - sjp->Pwd = (char*)pwd; - ok = true; + sjp->Fsize= 0; + sjp->Scrollable= false; + + if ((rc= jdef->ParseURL(g, url, false)) == RC_OK) { + sjp->Url= url; + sjp->User= (char*)user; + sjp->Pwd= (char*)pwd; + ok= true; } else if (rc == RC_NF) { if (jdef->GetTabname()) - tab = (char*)jdef->GetTabname(); + tab= (char*)jdef->GetTabname(); - ok = jdef->SetParms(sjp); + ok= jdef->SetParms(sjp); } // endif rc } // endif's @@ -5714,7 +5751,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, break; #endif // JAVA_SUPPORT case TAB_DBF: - dbf = true; + dbf= true; // fall through case TAB_CSV: if (!fn && fnc != FNC_NO) @@ -5722,55 +5759,55 @@ static int connect_assisted_discovery(handlerton *, THD* thd, else if (sep && strlen(sep) > 1) sprintf(g->Message, "Invalid separator %s", sep); else - ok = true; + ok= true; break; case TAB_MYSQL: - ok = true; + ok= true; if (create_info->connect_string.str && create_info->connect_string.length) { - PMYDEF mydef = new(g) MYSQLDEF(); + PMYDEF mydef= new(g) MYSQLDEF(); - dsn = strz(g, create_info->connect_string); + dsn= strz(g, create_info->connect_string); mydef->SetName(create_info->alias.str); if (!mydef->ParseURL(g, dsn, false)) { if (mydef->GetHostname()) - host = mydef->GetHostname(); + host= mydef->GetHostname(); if (mydef->GetUsername()) - user = mydef->GetUsername(); + user= mydef->GetUsername(); if (mydef->GetPassword()) - pwd = mydef->GetPassword(); + pwd= mydef->GetPassword(); if (mydef->GetTabschema()) - db = mydef->GetTabschema(); + db= mydef->GetTabschema(); if (mydef->GetTabname()) - tab = (char*)mydef->GetTabname(); + tab= (char*)mydef->GetTabname(); if (mydef->GetPortnumber()) - port = mydef->GetPortnumber(); + port= mydef->GetPortnumber(); } else - ok = false; + ok= false; } else if (!user) - user = "root"; + user= "root"; if (ok && CheckSelf(g, table_s, host, db, tab, src, port)) - ok = false; + ok= false; break; #if defined(__WIN__) case TAB_WMI: - ok = true; + ok= true; break; #endif // __WIN__ case TAB_PIVOT: - supfnc = FNC_NO; + supfnc= FNC_NO; case TAB_PRX: case TAB_TBL: case TAB_XCL: @@ -5779,12 +5816,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, (!db || !stricmp(db, table_s->db.str))) sprintf(g->Message, "A %s table cannot refer to itself", topt->type); else - ok = true; + ok= true; break; case TAB_OEM: if (topt->module && topt->subtype) - ok = true; + ok= true; else strcpy(g->Message, "Missing OEM module or subtype"); @@ -5793,24 +5830,33 @@ static int connect_assisted_discovery(handlerton *, THD* thd, case TAB_XML: #endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT case TAB_JSON: - dsn = strz(g, create_info->connect_string); + dsn= strz(g, create_info->connect_string); if (!fn && !zfn && !mul && !dsn) sprintf(g->Message, "Missing %s file name", topt->type); else - ok = true; + ok= true; break; #if defined(JAVA_SUPPORT) case TAB_MONGO: if (!topt->tabname) - topt->tabname = tab; + topt->tabname= tab; - ok = true; + ok= true; break; #endif // JAVA_SUPPORT +#if defined(REST_SUPPORT) + case TAB_REST: + if (!topt->http) + sprintf(g->Message, "Missing %s HTTP address", topt->type); + else + ok= true; + + break; +#endif // REST_SUPPORT case TAB_VIR: - ok = true; + ok= true; break; default: sprintf(g->Message, "Cannot get column info for table type %s", topt->type); @@ -5821,12 +5867,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (ok && !(supfnc & fnc)) { sprintf(g->Message, "Unsupported catalog function %s for table type %s", fncn, topt->type); - ok = false; + ok= false; } // endif supfnc if (src && fnc != FNC_NO) { strcpy(g->Message, "Cannot make catalog table from srcdef"); - ok = false; + ok= false; } // endif src if (ok) { @@ -5834,23 +5880,23 @@ static int connect_assisted_discovery(handlerton *, THD* thd, char *dft, *xtra, *key, *fmt; int i, len, prec, dec, typ, flg; - if (!(dpath = SetPath(g, table_s->db.str))) { - rc = HA_ERR_INTERNAL_ERROR; + if (!(dpath= SetPath(g, table_s->db.str))) { + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif dpath if (src && ttp != TAB_PIVOT && ttp != TAB_ODBC && ttp != TAB_JDBC) { - qrp = SrcColumns(g, host, db, user, pwd, src, port); + qrp= SrcColumns(g, host, db, user, pwd, src, port); if (qrp && ttp == TAB_OCCUR) if (OcrSrcCols(g, qrp, col, ocl, rnk)) { - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif OcrSrcCols } else switch (ttp) { case TAB_DBF: - qrp = DBFColumns(g, dpath, fn, fnc == FNC_COL); + qrp= DBFColumns(g, dpath, fn, fnc == FNC_COL); break; #if defined(ODBC_SUPPORT) case TAB_ODBC: @@ -5858,21 +5904,21 @@ static int connect_assisted_discovery(handlerton *, THD* thd, case FNC_NO: case FNC_COL: if (src) { - qrp = ODBCSrcCols(g, dsn, (char*)src, sop); - src = NULL; // for next tests + qrp= ODBCSrcCols(g, dsn, (char*)src, sop); + src= NULL; // for next tests } else - qrp = ODBCColumns(g, dsn, shm, tab, NULL, + qrp= ODBCColumns(g, dsn, shm, tab, NULL, mxr, fnc == FNC_COL, sop); break; case FNC_TABLE: - qrp = ODBCTables(g, dsn, shm, tab, NULL, mxr, true, sop); + qrp= ODBCTables(g, dsn, shm, tab, NULL, mxr, true, sop); break; case FNC_DSN: - qrp = ODBCDataSources(g, mxr, true); + qrp= ODBCDataSources(g, mxr, true); break; case FNC_DRIVER: - qrp = ODBCDrivers(g, mxr, true); + qrp= ODBCDrivers(g, mxr, true); break; default: sprintf(g->Message, "invalid catfunc %s", fncn); @@ -5887,23 +5933,23 @@ static int connect_assisted_discovery(handlerton *, THD* thd, case FNC_NO: case FNC_COL: if (src) { - qrp = JDBCSrcCols(g, (char*)src, sjp); - src = NULL; // for next tests + qrp= JDBCSrcCols(g, (char*)src, sjp); + src= NULL; // for next tests } else - qrp = JDBCColumns(g, shm, tab, NULL, mxr, fnc == FNC_COL, sjp); + qrp= JDBCColumns(g, shm, tab, NULL, mxr, fnc == FNC_COL, sjp); break; case FNC_TABLE: -// qrp = JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp); - qrp = JDBCTables(g, shm, tab, NULL, mxr, true, sjp); +// qrp= JDBCTables(g, shm, tab, tabtyp, mxr, true, sjp); + qrp= JDBCTables(g, shm, tab, NULL, mxr, true, sjp); break; #if 0 case FNC_DSN: - qrp = JDBCDataSources(g, mxr, true); + qrp= JDBCDataSources(g, mxr, true); break; #endif // 0 case FNC_DRIVER: - qrp = JDBCDrivers(g, mxr, true); + qrp= JDBCDrivers(g, mxr, true); break; default: sprintf(g->Message, "invalid catfunc %s", fncn); @@ -5913,56 +5959,61 @@ static int connect_assisted_discovery(handlerton *, THD* thd, break; #endif // JAVA_SUPPORT case TAB_MYSQL: - qrp = MyColumns(g, thd, host, db, user, pwd, tab, + qrp= MyColumns(g, thd, host, db, user, pwd, tab, NULL, port, fnc == FNC_COL); break; case TAB_CSV: - qrp = CSVColumns(g, dpath, topt, fnc == FNC_COL); + qrp= CSVColumns(g, dpath, topt, fnc == FNC_COL); break; #if defined(__WIN__) case TAB_WMI: - qrp = WMIColumns(g, nsp, cls, fnc == FNC_COL); + qrp= WMIColumns(g, nsp, cls, fnc == FNC_COL); break; #endif // __WIN__ case TAB_PRX: case TAB_TBL: case TAB_XCL: case TAB_OCCUR: - bif = fnc == FNC_COL; - qrp = TabColumns(g, thd, db, tab, bif); + bif= fnc == FNC_COL; + qrp= TabColumns(g, thd, db, tab, bif); if (!qrp && bif && fnc != FNC_COL) // tab is a view - qrp = MyColumns(g, thd, host, db, user, pwd, tab, NULL, port, false); + qrp= MyColumns(g, thd, host, db, user, pwd, tab, NULL, port, false); if (qrp && ttp == TAB_OCCUR && fnc != FNC_COL) if (OcrColumns(g, qrp, col, ocl, rnk)) { - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif OcrColumns break; case TAB_PIVOT: - qrp = PivotColumns(g, tab, src, pic, fcl, skc, host, db, user, pwd, port); + qrp= PivotColumns(g, tab, src, pic, fcl, skc, host, db, user, pwd, port); break; case TAB_VIR: - qrp = VirColumns(g, fnc == FNC_COL); + qrp= VirColumns(g, fnc == FNC_COL); break; case TAB_JSON: - qrp = JSONColumns(g, db, dsn, topt, fnc == FNC_COL); + qrp= JSONColumns(g, db, dsn, topt, fnc == FNC_COL); break; #if defined(JAVA_SUPPORT) case TAB_MONGO: - url = strz(g, create_info->connect_string); - qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL); + url= strz(g, create_info->connect_string); + qrp= MGOColumns(g, db, url, topt, fnc == FNC_COL); break; #endif // JAVA_SUPPORT #if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT) case TAB_XML: - qrp = XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL); + qrp= XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL); break; #endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT - case TAB_OEM: - qrp = OEMColumns(g, topt, tab, (char*)db, fnc == FNC_COL); +#if defined(REST_SUPPORT) + case TAB_REST: + qrp= RESTColumns(g, topt, tab, (char *)db, fnc == FNC_COL); + break; +#endif // REST_SUPPORT + case TAB_OEM: + qrp= OEMColumns(g, topt, tab, (char*)db, fnc == FNC_COL); break; default: strcpy(g->Message, "System error during assisted discovery"); @@ -5970,33 +6021,33 @@ static int connect_assisted_discovery(handlerton *, THD* thd, } // endswitch ttp if (!qrp) { - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif !qrp if (fnc != FNC_NO || src || ttp == TAB_PIVOT) { // Catalog like table for (crp = qrp->Colresp; !rc && crp; crp = crp->Next) { - cnm = (ttp == TAB_PIVOT) ? crp->Name : encode(g, crp->Name); - typ = crp->Type; - len = crp->Length; - dec = crp->Prec; - flg = crp->Flag; - v = (crp->Kdata->IsUnsigned()) ? 'U' : crp->Var; - tm = (crp->Kdata->IsNullable()) ? 0 : NOT_NULL_FLAG; + cnm= (ttp == TAB_PIVOT) ? crp->Name : encode(g, crp->Name); + typ= crp->Type; + len= crp->Length; + dec= crp->Prec; + flg= crp->Flag; + v= (crp->Kdata->IsUnsigned()) ? 'U' : crp->Var; + tm= (crp->Kdata->IsNullable()) ? 0 : NOT_NULL_FLAG; if (!len && typ == TYPE_STRING) - len = 256; // STRBLK's have 0 length + len= 256; // STRBLK's have 0 length // Now add the field if (add_field(&sql, cnm, typ, len, dec, NULL, tm, NULL, NULL, NULL, NULL, flg, dbf, v)) - rc = HA_ERR_OUT_OF_MEM; + rc= HA_ERR_OUT_OF_MEM; } // endfor crp } else { - char *schem = NULL; - char *tn = NULL; + char *schem= NULL; + char *tn= NULL; // Not a catalog table if (!qrp->Nblin) { @@ -6005,57 +6056,57 @@ static int connect_assisted_discovery(handlerton *, THD* thd, else strcpy(g->Message, "Fail to retrieve columns"); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif !nblin for (i = 0; !rc && i < qrp->Nblin; i++) { - typ = len = prec = dec = 0; - tm = NOT_NULL_FLAG; - cnm = (char*)"noname"; - dft = xtra = key = fmt = tn = NULL; - v = ' '; - rem = NULL; - - for (crp = qrp->Colresp; crp; crp = crp->Next) + typ= len = prec = dec = 0; + tm= NOT_NULL_FLAG; + cnm= (char*)"noname"; + dft= xtra= key= fmt= tn= NULL; + v= ' '; + rem= NULL; + + for (crp= qrp->Colresp; crp; crp= crp->Next) switch (crp->Fld) { case FLD_NAME: if (ttp == TAB_PRX || (ttp == TAB_CSV && topt->data_charset && (!stricmp(topt->data_charset, "UTF8") || !stricmp(topt->data_charset, "UTF-8")))) - cnm = crp->Kdata->GetCharValue(i); + cnm= crp->Kdata->GetCharValue(i); else - cnm = encode(g, crp->Kdata->GetCharValue(i)); + cnm= encode(g, crp->Kdata->GetCharValue(i)); break; case FLD_TYPE: - typ = crp->Kdata->GetIntValue(i); - v = (crp->Nulls) ? crp->Nulls[i] : 0; + typ= crp->Kdata->GetIntValue(i); + v= (crp->Nulls) ? crp->Nulls[i] : 0; break; case FLD_TYPENAME: - tn = crp->Kdata->GetCharValue(i); + tn= crp->Kdata->GetCharValue(i); break; case FLD_PREC: // PREC must be always before LENGTH - len = prec = crp->Kdata->GetIntValue(i); + len= prec= crp->Kdata->GetIntValue(i); break; case FLD_LENGTH: - len = crp->Kdata->GetIntValue(i); + len= crp->Kdata->GetIntValue(i); break; case FLD_SCALE: - dec = (!crp->Kdata->IsNull(i)) ? crp->Kdata->GetIntValue(i) : -1; + dec= (!crp->Kdata->IsNull(i)) ? crp->Kdata->GetIntValue(i) : -1; break; case FLD_NULL: if (crp->Kdata->GetIntValue(i)) - tm = 0; // Nullable + tm= 0; // Nullable break; case FLD_FORMAT: - fmt = (crp->Kdata) ? crp->Kdata->GetCharValue(i) : NULL; + fmt= (crp->Kdata) ? crp->Kdata->GetCharValue(i) : NULL; break; case FLD_REM: - rem = crp->Kdata->GetCharValue(i); + rem= crp->Kdata->GetCharValue(i); break; // case FLD_CHARSET: // No good because remote table is already translated @@ -6064,19 +6115,19 @@ static int connect_assisted_discovery(handlerton *, THD* thd, // break; case FLD_DEFAULT: - dft = crp->Kdata->GetCharValue(i); + dft= crp->Kdata->GetCharValue(i); break; case FLD_EXTRA: - xtra = crp->Kdata->GetCharValue(i); + xtra= crp->Kdata->GetCharValue(i); // Auto_increment is not supported yet if (!stricmp(xtra, "AUTO_INCREMENT")) - xtra = NULL; + xtra= NULL; break; case FLD_KEY: if (ttp == TAB_VIR) - key = crp->Kdata->GetCharValue(i); + key= crp->Kdata->GetCharValue(i); break; case FLD_SCHEM: @@ -6085,10 +6136,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (schem && stricmp(schem, crp->Kdata->GetCharValue(i))) { sprintf(g->Message, "Several %s tables found, specify DBNAME", tab); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } else if (!schem) - schem = crp->Kdata->GetCharValue(i); + schem= crp->Kdata->GetCharValue(i); } // endif ttp #endif // ODBC_SUPPORT || JAVA_SUPPORT @@ -6099,10 +6150,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(ODBC_SUPPORT) if (ttp == TAB_ODBC) { int plgtyp; - bool w = false; // Wide character type + bool w= false; // Wide character type // typ must be PLG type, not SQL type - if (!(plgtyp = TranslateSQLType(typ, dec, prec, v, w))) { + if (!(plgtyp= TranslateSQLType(typ, dec, prec, v, w))) { if (GetTypeConv() == TPC_SKIP) { // Skip this column sprintf(g->Message, "Column %s skipped (unsupported type %d)", @@ -6111,12 +6162,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, continue; } else { sprintf(g->Message, "Unsupported SQL type %d", typ); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif type_conv } else - typ = plgtyp; + typ= plgtyp; switch (typ) { case TYPE_STRING: @@ -6131,10 +6182,10 @@ static int connect_assisted_discovery(handlerton *, THD* thd, prec += (dec + 2); // To be safe break; case TYPE_DECIM: - prec = len; + prec= len; break; default: - dec = 0; + dec= 0; } // endswitch typ } else @@ -6144,7 +6195,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, int plgtyp; // typ must be PLG type, not SQL type - if (!(plgtyp = TranslateJDBCType(typ, tn, dec, prec, v))) { + if (!(plgtyp= TranslateJDBCType(typ, tn, dec, prec, v))) { if (GetTypeConv() == TPC_SKIP) { // Skip this column sprintf(g->Message, "Column %s skipped (unsupported type %d)", @@ -6153,12 +6204,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd, continue; } else { sprintf(g->Message, "Unsupported SQL type %d", typ); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; goto err; } // endif type_conv } else - typ = plgtyp; + typ= plgtyp; switch (typ) { case TYPE_DOUBLE: @@ -6167,43 +6218,43 @@ static int connect_assisted_discovery(handlerton *, THD* thd, prec += (dec + 2); // To be safe break; default: - dec = 0; + dec= 0; } // endswitch typ } else #endif // ODBC_SUPPORT // Make the arguments as required by add_fields if (typ == TYPE_DOUBLE) - prec = len; + prec= len; if (typ == TYPE_DATE) - prec = 0; + prec= 0; // Now add the field if (add_field(&sql, cnm, typ, prec, dec, key, tm, rem, dft, xtra, fmt, 0, dbf, v)) - rc = HA_ERR_OUT_OF_MEM; + rc= HA_ERR_OUT_OF_MEM; } // endfor i } // endif fnc if (!rc) - rc = init_table_share(thd, table_s, create_info, &sql); + rc= init_table_share(thd, table_s, create_info, &sql); //g->jump_level--; //PopUser(xp); //return rc; } else { - rc = HA_ERR_UNSUPPORTED; + rc= HA_ERR_UNSUPPORTED; } // endif ok } catch (int n) { if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } catch (const char *msg) { strcpy(g->Message, msg); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } // end catch err: @@ -6271,13 +6322,13 @@ int ha_connect::create(const char *name, TABLE *table_arg, TABTYPE type; TABLE *st= table; // Probably unuseful THD *thd= ha_thd(); - LEX_CSTRING cnc = table_arg->s->connect_string; + LEX_CSTRING cnc= table_arg->s->connect_string; #if defined(WITH_PARTITION_STORAGE_ENGINE) - partition_info *part_info= table_arg->part_info; + partition_info *part_info= table_arg->part_info; #else // !WITH_PARTITION_STORAGE_ENGINE #define part_info 0 #endif // !WITH_PARTITION_STORAGE_ENGINE - xp= GetUser(thd, xp); + xp= GetUser(thd, xp); PGLOBAL g= xp->g; DBUG_ENTER("ha_connect::create"); @@ -6953,12 +7004,12 @@ bool ha_connect::NoFieldOptionChange(TABLE *tab) @retval HA_ALTER_ERROR Unexpected error. @retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported, must use copy. @retval HA_ALTER_INPLACE_EXCLUSIVE_LOCK Supported, but requires X lock. - @retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE + @retval HA_ALTER_INPLACE_COPY_LOCK Supported, but requires SNW lock during main phase. Prepare phase requires X lock. @retval HA_ALTER_INPLACE_SHARED_LOCK Supported, but requires SNW lock. - @retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE + @retval HA_ALTER_INPLACE_COPY_NO_LOCK Supported, concurrent reads/writes allowed. However, prepare phase requires X lock. @@ -7334,7 +7385,7 @@ maria_declare_plugin(connect) 0x0106, /* version number (1.06) */ NULL, /* status variables */ connect_system_variables, /* system variables */ - "1.06.0009", /* string version */ + "1.06.0010", /* string version */ MariaDB_PLUGIN_MATURITY_STABLE /* maturity */ } maria_declare_plugin_end; diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index f34c6ba890a..3727dc193c2 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /** @file ha_connect.h Author Olivier Bertrand @@ -32,6 +32,10 @@ /****************************************************************************/ #include "mycat.h" +#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) +bool MongoEnabled(void); +#endif // JAVA_SUPPORT || CMGO_SUPPORT + /****************************************************************************/ /* Structures used to pass info between CONNECT and ha_connect. */ /****************************************************************************/ @@ -508,7 +512,7 @@ protected: bool check_privileges(THD *thd, PTOS options, const char *dbn, bool quick=false); MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras); int check_stmt(PGLOBAL g, MODE newmode, bool cras); - char *GetDBfromName(const char *name); + char *GetDBfromName(const char *name); // Members static ulong num; // Tracable handler number diff --git a/storage/connect/inihandl.cpp b/storage/connect/inihandl.cpp index c039a980bcb..8e79aeac7ef 100644 --- a/storage/connect/inihandl.cpp +++ b/storage/connect/inihandl.cpp @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ #include "my_global.h" diff --git a/storage/connect/javaconn.cpp b/storage/connect/javaconn.cpp index f05db1892d9..f919344f20b 100644 --- a/storage/connect/javaconn.cpp +++ b/storage/connect/javaconn.cpp @@ -441,7 +441,7 @@ bool JAVAConn::Open(PGLOBAL g) //=============== load and initialize Java VM and JNI interface ============= rc = CreateJavaVM(&jvm, (void**)&env, &vm_args); // YES !! - delete options; // we then no longer need the initialisation options. + delete[] options; // we then no longer need the initialisation options. switch (rc) { case JNI_OK: diff --git a/storage/connect/jmgoconn.cpp b/storage/connect/jmgoconn.cpp index bd1ddadd80d..c80800bd897 100644 --- a/storage/connect/jmgoconn.cpp +++ b/storage/connect/jmgoconn.cpp @@ -272,7 +272,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, if (MakeSelector(g, filp, s)) { strcpy(g->Message, "Failed making selector"); - return NULL; + return true; } else s->Append('}'); @@ -340,7 +340,7 @@ bool JMgoConn::MakeCursor(PGLOBAL g, PTDB tdbp, PCSZ options, if (MakeSelector(g, filp, s)) { strcpy(g->Message, "Failed making selector"); - return NULL; + return true; } // endif Selector tdbp->SetFilter(NULL); // Not needed anymore @@ -813,4 +813,3 @@ PSZ JMgoConn::GetColumnValue(PSZ path) return fld; } // end of GetColumnValue - diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 3e9b6ad625f..dad86d51040 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1,6 +1,6 @@ /****************** jsonudf C++ Program Source Code File (.CPP) ******************/ -/* PROGRAM NAME: jsonudf Version 1.7 */ -/* (C) Copyright to the author Olivier BERTRAND 2015-2018 */ +/* PROGRAM NAME: jsonudf Version 1.8 */ +/* (C) Copyright to the author Olivier BERTRAND 2015-2019 */ /* This program are the JSON User Defined Functions . */ /*********************************************************************************/ @@ -1686,7 +1686,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) } // endif *s if (n < 1) - return "Key"; + return (PCSZ) "Key"; if (!b) { if ((p = (PSZ)PlgDBSubAlloc(g, NULL, n + 1))) { @@ -1703,7 +1703,7 @@ static PCSZ MakeKey(PGLOBAL g, UDF_ARGS *args, int i) return s; } // endif count - return "Key"; + return (PCSZ) "Key"; } // end of MakeKey /*********************************************************************************/ @@ -5819,7 +5819,7 @@ my_bool uvar_init(UDF_INIT *initid, UDF_ARGS *args, char *message) if (args->arg_count != 1) { strcpy(message, "Unique argument must be a user variable name"); return true; - } else + } else CalcLen(args, false, reslen, memlen, true); initid->maybe_null = true; @@ -5898,4 +5898,3 @@ long long countin(UDF_INIT *initid, UDF_ARGS *args, char *result, free(str2); return n; } // end of countin - diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp index 9b30b315441..58b0267bd6d 100644 --- a/storage/connect/libdoc.cpp +++ b/storage/connect/libdoc.cpp @@ -1035,7 +1035,7 @@ PXNODE XML2NODE::AddChildNode(PGLOBAL g, PCSZ name, PXNODE np) // If name has the format m[n] only m is taken as node name if ((p = strchr(pn, '['))) - p = BufAlloc(g, pn, p - pn); + p = BufAlloc(g, pn, int(p - pn)); else p = pn; diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index 5aef6d9c660..fae1682c7e1 100644 --- a/storage/connect/mycat.cc +++ b/storage/connect/mycat.cc @@ -11,14 +11,14 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /*************** Mycat CC Program Source Code File (.CC) ***************/ /* PROGRAM NAME: MYCAT */ /* ------------- */ -/* Version 1.6 */ +/* Version 1.7 */ /* */ -/* Author: Olivier Bertrand 2012 - 2018 */ +/* Author: Olivier Bertrand 2012 - 2019 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -93,6 +93,9 @@ #if defined(ZIP_SUPPORT) #include "tabzip.h" #endif // ZIP_SUPPORT +#if defined(REST_SUPPORT) +#include "tabrest.h" +#endif // Rest_SUPPORT #include "mycat.h" /***********************************************************************/ @@ -101,11 +104,9 @@ #if defined(__WIN__) extern "C" HINSTANCE s_hModule; // Saved module handle #endif // !__WIN__ - #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) bool MongoEnabled(void); #endif // JAVA_SUPPORT || CMGO_SUPPORT - PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info); /***********************************************************************/ @@ -181,7 +182,8 @@ bool IsFileType(TABTYPE type) case TAB_INI: case TAB_VEC: case TAB_JSON: -// case TAB_ZIP: + case TAB_REST: + // case TAB_ZIP: isfile= true; break; default: @@ -488,8 +490,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, printf("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type)); // If not specified get the type of this table - if (!type) - type= Hc->GetStringOption("Type","*"); + //if (!type) + // type= Hc->GetStringOption("Type","*"); return MakeTableDesc(g, tablep, type); } // end of GetTableDesc @@ -501,8 +503,8 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) { TABTYPE tc; - LPCSTR name = (PSZ)PlugDup(g, tablep->GetName()); - LPCSTR schema = (PSZ)PlugDup(g, tablep->GetSchema()); + LPCSTR name= (PSZ)PlugDup(g, tablep->GetName()); + LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema()); PRELDEF tdp= NULL; if (trace(1)) @@ -512,7 +514,11 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) /*********************************************************************/ /* Get a unique enum identifier for types. */ /*********************************************************************/ - tc= GetTypeID(am); + if (!am) { + tc= Hc->GetRealType(); + am= Hc->GetStringOption("Type","*"); + } else + tc= GetTypeID(am); switch (tc) { case TAB_FIX: @@ -551,6 +557,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) #if defined(ZIP_SUPPORT) case TAB_ZIP: tdp = new(g) ZIPDEF; break; #endif // ZIP_SUPPORT +#if defined(REST_SUPPORT) + case TAB_REST: tdp= new (g) RESTDEF; break; +#endif // REST_SUPPORT #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) case TAB_MONGO: if (MongoEnabled()) { diff --git a/storage/connect/mycat.h b/storage/connect/mycat.h index f0f889722dd..818e535b32d 100644 --- a/storage/connect/mycat.h +++ b/storage/connect/mycat.h @@ -11,10 +11,10 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /**************** MYCAT H Declares Source Code File (.H) ***************/ -/* Name: MYCAT.H Version 2.3 */ +/* Name: MYCAT.H Version 2.4 */ /* Author: Olivier Bertrand */ /* This file contains the CONNECT plugin MYCAT class definitions. */ /***********************************************************************/ @@ -50,6 +50,8 @@ struct ha_table_option_struct { const char *filter; const char *oplist; const char *data_charset; + const char *http; + const char *uri; ulonglong lrecl; ulonglong elements; //ulonglong estimate; diff --git a/storage/connect/mysql-test/connect/disabled.def b/storage/connect/mysql-test/connect/disabled.def index 0dcf030613d..827ed58b835 100644 --- a/storage/connect/mysql-test/connect/disabled.def +++ b/storage/connect/mysql-test/connect/disabled.def @@ -9,14 +9,15 @@ # Do not use any TAB characters for whitespace. # ############################################################################## -jdbc : Variable settings depend on machine configuration -jdbc_new : Variable settings depend on machine configuration -jdbc_oracle : Variable settings depend on machine configuration -jdbc_postgresql : Variable settings depend on machine configuration -json_mongo_c : Need MongoDB running and its C Driver installed -json_java_2 : Need MongoDB running and its Java Driver installed -json_java_3 : Need MongoDB running and its Java Driver installed -mongo_c : Need MongoDB running and its C Driver installed -mongo_java_2 : Need MongoDB running and its Java Driver installed -mongo_java_3 : Need MongoDB running and its Java Driver installed -tbl_thread : Bug MDEV-9844,10179,14214 03/01/2018 OB Option THREAD removed +infoschema-9739 : Crashes with MariaDB 10.0 +jdbc : Variable settings depend on machine configuration +jdbc_new : Variable settings depend on machine configuration +jdbc_oracle : Variable settings depend on machine configuration +jdbc_postgresql : Variable settings depend on machine configuration +json_mongo_c : Need MongoDB running and its C Driver installed +json_java_2 : Need MongoDB running and its Java Driver installed +json_java_3 : Need MongoDB running and its Java Driver installed +mongo_c : Need MongoDB running and its C Driver installed +mongo_java_2 : Need MongoDB running and its Java Driver installed +mongo_java_3 : Need MongoDB running and its Java Driver installed +tbl_thread : Bug MDEV-9844,10179,14214 03/01/2018 OB Option THREAD removed diff --git a/storage/connect/mysql-test/connect/r/dir.result b/storage/connect/mysql-test/connect/r/dir.result index e10bb458d62..139544b99e9 100644 --- a/storage/connect/mysql-test/connect/r/dir.result +++ b/storage/connect/mysql-test/connect/r/dir.result @@ -26,7 +26,7 @@ fname ftype size boys .txt 282 boyswin .txt 288 INSERT INTO t1 VALUES ('','','',''); -ERROR 22007: Incorrect double value: '' for column 'size' at row 1 +ERROR 22007: Incorrect double value: '' for column `test`.`t1`.`size` at row 1 DROP TABLE t1; CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.txt'; ERROR HY000: Cannot get column info for table type DIR diff --git a/storage/connect/mysql-test/connect/r/grant.result b/storage/connect/mysql-test/connect/r/grant.result index 118d75408be..c43ad3a5b79 100644 --- a/storage/connect/mysql-test/connect/r/grant.result +++ b/storage/connect/mysql-test/connect/r/grant.result @@ -26,7 +26,7 @@ fname VARCHAR(256) NOT NULL, ftype CHAR(4) NOT NULL, size DOUBLE(12,0) NOT NULL flag=5 ) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; -SELECT fname, ftype, size FROM t1 WHERE size>0; +SELECT fname, ftype, size FROM t1 WHERE size>0 AND ftype!='.opt'; fname ftype size t1 .frm 1081 connection user; diff --git a/storage/connect/mysql-test/connect/r/jdbc.result b/storage/connect/mysql-test/connect/r/jdbc.result index a16f2791e8f..0dbdf851860 100644 --- a/storage/connect/mysql-test/connect/r/jdbc.result +++ b/storage/connect/mysql-test/connect/r/jdbc.result @@ -239,22 +239,34 @@ CREATE TABLE t2 (command varchar(128) not null,number int(5) not null flag=1,mes SELECT * FROM t2 WHERE command='drop table tx1'; command number message drop table tx1 0 Execute: java.sql.SQLSyntaxErrorException: (conn:24) Unknown table 'connect.tx1' +Warnings: +Warning 1105 Execute: java.sql.SQLSyntaxErrorException: (conn:24) Unknown table 'connect.tx1' SELECT * FROM t2 WHERE command = 'create table tx1 (a int not null, b char(32), c double(8,2))'; command number message create table tx1 (a int not null, b char(32), c double(8,2)) 0 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM t2 WHERE command in ('insert into tx1 values(1,''The number one'',456.12)',"insert into tx1(a,b) values(2,'The number two'),(3,'The number three')"); command number message insert into tx1 values(1,'The number one',456.12) 1 Affected rows insert into tx1(a,b) values(2,'The number two'),(3,'The number three') 2 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM t2 WHERE command='update tx1 set c = 3.1416 where a = 2'; command number message update tx1 set c = 3.1416 where a = 2 1 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM t2 WHERE command='select * from tx1'; command number message select * from tx1 3 Result set column number +Warnings: +Warning 1105 Result set column number SELECT * FROM t2 WHERE command='delete from tx1 where a = 2'; command number message delete from tx1 where a = 2 1 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM connect.tx1; a b c 1 The number one 456.12 diff --git a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result index f9510064b35..bec1dc8725b 100644 --- a/storage/connect/mysql-test/connect/r/jdbc_postgresql.result +++ b/storage/connect/mysql-test/connect/r/jdbc_postgresql.result @@ -1,4 +1,4 @@ -SET GLOBAL connect_class_path='C:/MariaDB-10.3/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; +SET GLOBAL connect_class_path='C:/MariaDB-10.0/MariaDB/storage/connect/mysql-test/connect/std_data/JavaWrappers.jar;C:/Jconnectors/postgresql-42.2.1.jar'; CREATE TABLE t2 ( command varchar(128) not null, number int(5) not null flag=1, @@ -9,12 +9,18 @@ OPTION_LIST='Execsrc=1'; SELECT * FROM t2 WHERE command='drop table employee'; command number message drop table employee 0 Execute: org.postgresql.util.PSQLException: ERREUR: la table « employee » n'existe pas +Warnings: +Warning 1105 Execute: org.postgresql.util.PSQLException: ERREUR: la table employee n'existe pas SELECT * FROM t2 WHERE command = 'create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2))'; command number message create table employee (id int not null, name varchar(32), title char(16), salary decimal(8,2)) 0 Affected rows +Warnings: +Warning 1105 Affected rows SELECT * FROM t2 WHERE command = "insert into employee values(4567,'Johnson', 'Engineer', 12560.50)"; command number message insert into employee values(4567,'Johnson', 'Engineer', 12560.50) 1 Affected rows +Warnings: +Warning 1105 Affected rows CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JDBC CATFUNC=tables CONNECTION='jdbc:postgresql://localhost/test?user=postgres&password=tinono' OPTION_LIST='Tabtype=TABLE,Maxres=10'; @@ -63,4 +69,6 @@ DROP SERVER 'postgresql'; SELECT * FROM t2 WHERE command='drop table employee'; command number message drop table employee 0 Affected rows +Warnings: +Warning 1105 Affected rows DROP TABLE t2; diff --git a/storage/connect/mysql-test/connect/r/xml.result b/storage/connect/mysql-test/connect/r/xml.result index 99739b1ec10..6a0c9db27b3 100644 --- a/storage/connect/mysql-test/connect/r/xml.result +++ b/storage/connect/mysql-test/connect/r/xml.result @@ -323,7 +323,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 diff --git a/storage/connect/mysql-test/connect/r/xml2.result b/storage/connect/mysql-test/connect/r/xml2.result index b8075fa1928..f7bbc17c8a0 100644 --- a/storage/connect/mysql-test/connect/r/xml2.result +++ b/storage/connect/mysql-test/connect/r/xml2.result @@ -325,7 +325,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 diff --git a/storage/connect/mysql-test/connect/r/xml2_mult.result b/storage/connect/mysql-test/connect/r/xml2_mult.result index a9592e986c0..87d1118edd5 100644 --- a/storage/connect/mysql-test/connect/r/xml2_mult.result +++ b/storage/connect/mysql-test/connect/r/xml2_mult.result @@ -51,14 +51,14 @@ WEB XQuery Kick Start en Per Bothner 2003 49.99 WEB XQuery Kick Start en Kurt Cagle 2003 49.99 WEB Learning XML en Erik T. Ray 2003 39.95 Warnings: -Warning 1105 Mutiple values limited to 3 +Warning 1105 Multiple values limited to 3 # One line lost because the where clause is applied only on the first 3 rows SELECT category, title, author, price FROM bookstore WHERE author LIKE 'J%'; category title author price CHILDREN Harry Potter J K. Rowling 29.99 WEB XQuery Kick Start James McGovern 49.99 Warnings: -Warning 1105 Mutiple values limited to 3 +Warning 1105 Multiple values limited to 3 # # Testing concatenated values # @@ -91,12 +91,12 @@ CHILDREN Harry Potter en J K. Rowling 2005 29.99 WEB XQuery Kick Start en James McGovern, Per Bothner, Kurt Cagle, James Linn 2003 49.99 WEB Learning XML en Erik T. Ray 2003 39.95 Warnings: -Warning 1105 Mutiple values limited to 4 +Warning 1105 Multiple values limited to 4 # The where clause is applied on the concatenated column result SELECT category, title, author, price FROM bookstore WHERE author LIKE 'J%'; category title author price CHILDREN Harry Potter J K. Rowling 29.99 WEB XQuery Kick Start James McGovern, Per Bothner, Kurt Cagle, James Linn 49.99 Warnings: -Warning 1105 Mutiple values limited to 4 +Warning 1105 Multiple values limited to 4 DROP TABLE bookstore; diff --git a/storage/connect/mysql-test/connect/r/xml_mult.result b/storage/connect/mysql-test/connect/r/xml_mult.result index d89debadfab..9922b40060c 100644 --- a/storage/connect/mysql-test/connect/r/xml_mult.result +++ b/storage/connect/mysql-test/connect/r/xml_mult.result @@ -49,14 +49,14 @@ WEB XQuery Kick Start en Per Bothner 2003 49.99 WEB XQuery Kick Start en Kurt Cagle 2003 49.99 WEB Learning XML en Erik T. Ray 2003 39.95 Warnings: -Warning 1105 Mutiple values limited to 3 +Warning 1105 Multiple values limited to 3 # One line lost because the where clause is applied only on the first 3 rows SELECT category, title, author, price FROM bookstore WHERE author LIKE 'J%'; category title author price CHILDREN Harry Potter J K. Rowling 29.99 WEB XQuery Kick Start James McGovern 49.99 Warnings: -Warning 1105 Mutiple values limited to 3 +Warning 1105 Multiple values limited to 3 # # Testing concatenated values # @@ -89,12 +89,12 @@ CHILDREN Harry Potter en J K. Rowling 2005 29.99 WEB XQuery Kick Start en James McGovern, Per Bothner, Kurt Cagle, James Linn 2003 49.99 WEB Learning XML en Erik T. Ray 2003 39.95 Warnings: -Warning 1105 Mutiple values limited to 4 +Warning 1105 Multiple values limited to 4 # The where clause is applied on the concatenated column result SELECT category, title, author, price FROM bookstore WHERE author LIKE 'J%'; category title author price CHILDREN Harry Potter J K. Rowling 29.99 WEB XQuery Kick Start James McGovern, Per Bothner, Kurt Cagle, James Linn 49.99 Warnings: -Warning 1105 Mutiple values limited to 4 +Warning 1105 Multiple values limited to 4 DROP TABLE bookstore; diff --git a/storage/connect/mysql-test/connect/t/grant.test b/storage/connect/mysql-test/connect/t/grant.test index 738f156d8a4..c4a91904e73 100644 --- a/storage/connect/mysql-test/connect/t/grant.test +++ b/storage/connect/mysql-test/connect/t/grant.test @@ -28,7 +28,7 @@ CREATE TABLE t1 ( ) ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.*'; # "size>0" to skip directory names on Windows --replace_result $MYSQLD_DATADIR DATADIR/ -SELECT fname, ftype, size FROM t1 WHERE size>0; +SELECT fname, ftype, size FROM t1 WHERE size>0 AND ftype!='.opt'; --connection user SELECT user(); diff --git a/storage/connect/plgdbsem.h b/storage/connect/plgdbsem.h index 5446e0d2a07..f10ae209e9d 100644 --- a/storage/connect/plgdbsem.h +++ b/storage/connect/plgdbsem.h @@ -1,7 +1,7 @@ /************** PlgDBSem H Declares Source Code File (.H) **************/ -/* Name: PLGDBSEM.H Version 3.7 */ +/* Name: PLGDBSEM.H Version 3.8 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 1998-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 1998-2019 */ /* */ /* This file contains the CONNECT storage engine definitions. */ /***********************************************************************/ @@ -82,6 +82,7 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */ TAB_JDBC = 26, /* Table accessed via JDBC */ TAB_ZIP = 27, /* ZIP file info table */ TAB_MONGO = 28, /* Table retrieved from MongoDB */ + TAB_REST = 29, /* Table retrieved from Rest */ TAB_NIY = 30}; /* Table not implemented yet */ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */ @@ -400,6 +401,7 @@ typedef class VCTDEF *PVCTDEF; typedef class PIVOTDEF *PPIVOTDEF; typedef class DOMDEF *PDOMDEF; typedef class DIRDEF *PDIRDEF; +typedef class RESTDEF *PRESTDEF; typedef class OEMDEF *POEMDEF; typedef class COLCRT *PCOLCRT; typedef class COLDEF *PCOLDEF; diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index 048f00be75f..6790e7eb45c 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -526,7 +526,7 @@ BOOL PlugSubSet(void *memp, uint size) /***********************************************************************/ /* Use it to export a function that do throwing. */ /***********************************************************************/ -void *DoThrow(int n) +static void *DoThrow(int n) { throw n; } /* end of DoThrow */ diff --git a/storage/connect/restget.cpp b/storage/connect/restget.cpp new file mode 100644 index 00000000000..955e5f97fbc --- /dev/null +++ b/storage/connect/restget.cpp @@ -0,0 +1,87 @@ +/************* Restget C++ Program Source Code File (.CPP) *************/ +/* Adapted from the sample program of the Casablanca tutorial. */ +/* Copyright Olivier Bertrand 2019. */ +/***********************************************************************/ +#include +#include +#if defined(MARIADB) +#include +#else +#include "mini_global.h" +#endif + +using namespace utility::conversions; // String conversions utilities +using namespace web; // Common features like URIs. +using namespace web::http; // Common HTTP functionality +using namespace web::http::client; // HTTP client features +using namespace concurrency::streams; // Asynchronous streams + +#include "global.h" + + +/***********************************************************************/ +/* Make a local copy of the requested file. */ +/***********************************************************************/ +int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn) +{ + int rc= 0; + auto fileStream= std::make_shared(); + + if (!http || !fn) { + strcpy(g->Message, "Missing http or filename"); + return 2; + } // endif + + //std::string sfn(fn); + //auto wfn= to_string_t(sfn); + //rc= 0; + + // Open stream to output file. + pplx::task requestTask= + fstream::open_ostream(to_string_t(fn)) + .then([=](ostream outFile) { + *fileStream= outFile; + + // Create http_client to send the request. + http_client client(to_string_t(http)); + + if (uri) + { + // Build request URI and start the request. + uri_builder builder(to_string_t(uri)); + return client.request(methods::GET, builder.to_string()); + } + else + return client.request(methods::GET); + }) + + // Handle response headers arriving. + .then([=](http_response response) { +#if defined(DEVELOPMENT) + fprintf(stderr, "Received response status code:%u\n", + response.status_code()); +#endif // DEVELOPMENT + + // Write response body into the file. + return response.body().read_to_end(fileStream->streambuf()); + }) + + // Close the file stream. + .then([=](size_t) { return fileStream->close(); }); + + // Wait for all the outstanding I/O to complete and handle any exceptions + try + { + requestTask.wait(); + } + catch (const std::exception &e) + { +#if defined(DEVELOPMENT) + fprintf(stderr, "Error exception: %s\n", e.what()); +#endif // DEVELOPMENT + sprintf(g->Message, "Error exception: %s", e.what()); + rc= 1; + } // end try/catch + + return rc; +} // end of restGetFile \ No newline at end of file diff --git a/storage/connect/tabdos.cpp b/storage/connect/tabdos.cpp index e336be8325b..4f6e2c81744 100644 --- a/storage/connect/tabdos.cpp +++ b/storage/connect/tabdos.cpp @@ -1,11 +1,11 @@ /************* TabDos C++ Program Source Code File (.CPP) **************/ /* PROGRAM NAME: TABDOS */ /* ------------- */ -/* Version 4.9.3 */ +/* Version 4.9.4 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 1998-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 1998-2019 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -2045,25 +2045,24 @@ int TDBDOS::GetMaxSize(PGLOBAL g) if (!Cardinality(NULL)) { int len = GetFileLength(g); - if (len >= 0) { - int rec; + if (len >= 0) { + int rec; - if (trace(1)) - htrc("Estimating lines len=%d ending=%d/n", - len, ((PDOSDEF)To_Def)->Ending); + if (trace(1)) + htrc("Estimating lines len=%d ending=%d/n", + len, ((PDOSDEF)To_Def)->Ending); - /*****************************************************************/ - /* Estimate the number of lines in the table (if not known) by */ - /* dividing the file length by minimum record length. */ - /*****************************************************************/ - rec = (AvgLen <= 0 ? rec = EstimatedLength() : AvgLen) - + ((PDOSDEF)To_Def)->Ending; - MaxSize = (len + rec - 1) / rec; + /*****************************************************************/ + /* Estimate the number of lines in the table (if not known) by */ + /* dividing the file length by minimum record length. */ + /*****************************************************************/ + rec = EstimatedLength() + ((PDOSDEF)To_Def)->Ending; + MaxSize = (len + rec - 1) / rec; - if (trace(1)) - htrc("avglen=%d MaxSize%d\n", rec, MaxSize); + if (trace(1)) + htrc("avglen=%d MaxSize%d\n", rec, MaxSize); - } // endif len + } // endif len } else MaxSize = Cardinality(g); @@ -2493,8 +2492,10 @@ bool DOSCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) } // endif's Value, Buf_Type // Allocate the buffer used in WriteColumn for numeric columns - if (!Buf && IsTypeNum(Buf_Type)) - Buf = (char*)PlugSubAlloc(g, NULL, MY_MAX(32, Long + Dcm + 1)); + if (!Buf && IsTypeNum(Buf_Type)) + Buf = (char*)PlugSubAlloc(g, NULL, MY_MAX(64, Long + 1)); + else // Text columns do not need additional buffer + Buf = (char*)Value->GetTo_Val(); // Because Colblk's have been made from a copy of the original TDB in // case of Update, we must reset them to point to the original one. @@ -2604,8 +2605,8 @@ void DOSCOL::ReadColumn(PGLOBAL g) /***********************************************************************/ void DOSCOL::WriteColumn(PGLOBAL g) { - char *p, *p2, fmt[32]; - int i, k, len, field; + char *p, fmt[32]; + int i, k, n, len, field; PTDBDOS tdbp = (PTDBDOS)To_Tdb; if (trace(2)) @@ -2680,8 +2681,8 @@ void DOSCOL::WriteColumn(PGLOBAL g) case TYPE_DOUBLE: case TYPE_DECIM: strcpy(fmt, (Ldz) ? "%0*.*lf" : "%*.*lf"); - sprintf(Buf, fmt, field + ((Nod && Dcm) ? 1 : 0), - Dcm, Value->GetFloatValue()); + len = field + ((Nod && Dcm) ? 1 : 0); + snprintf(Buf, len, fmt, len, Dcm, Value->GetFloatValue()); len = strlen(Buf); if (Nod && Dcm) @@ -2700,35 +2701,37 @@ void DOSCOL::WriteColumn(PGLOBAL g) throw 31; } // endswitch BufType - p2 = Buf; + n = strlen(Buf); } else // Standard CONNECT format - p2 = Value->ShowValue(Buf, field); + n = Value->ShowValue(Buf, field); if (trace(1)) - htrc("new length(%p)=%d\n", p2, strlen(p2)); + htrc("new length(%p)=%d\n", Buf, n); + + if ((len = n) > field) { + char *p = Value->GetCharString(Buf); - if ((len = strlen(p2)) > field) { - sprintf(g->Message, MSG(VALUE_TOO_LONG), p2, Name, field); + sprintf(g->Message, MSG(VALUE_TOO_LONG), p, Name, field); throw 31; } else if (Dsp) for (i = 0; i < len; i++) - if (p2[i] == '.') - p2[i] = Dsp; + if (Buf[i] == '.') + Buf[i] = Dsp; if (trace(2)) - htrc("buffer=%s\n", p2); + htrc("buffer=%s\n", Buf); /*******************************************************************/ /* Updating must be done only when not in checking pass. */ /*******************************************************************/ if (Status) { memset(p, ' ', field); - memcpy(p, p2, len); + memcpy(p, Buf, len); if (trace(2)) htrc(" col write: '%.*s'\n", len, p); - } // endif Use + } // endif Status } else // BIN compressed table /*******************************************************************/ @@ -2739,7 +2742,7 @@ void DOSCOL::WriteColumn(PGLOBAL g) sprintf(g->Message, MSG(BIN_F_TOO_LONG), Name, Value->GetSize(), Long); throw 31; - } // endif + } // endif } // end of WriteColumn diff --git a/storage/connect/tabfmt.cpp b/storage/connect/tabfmt.cpp index 63fa2a63668..02720a3089a 100644 --- a/storage/connect/tabfmt.cpp +++ b/storage/connect/tabfmt.cpp @@ -1485,8 +1485,8 @@ void CSVCOL::ReadColumn(PGLOBAL g) /***********************************************************************/ void CSVCOL::WriteColumn(PGLOBAL g) { - char *p, buf[64]; - int flen; + char *p; + int n, flen; PTDBCSV tdbp = (PTDBCSV)To_Tdb; if (trace(2)) @@ -1508,13 +1508,14 @@ void CSVCOL::WriteColumn(PGLOBAL g) /*********************************************************************/ /* Get the string representation of the column value. */ /*********************************************************************/ - p = Value->ShowValue(buf); + p = Value->GetCharString(Buf); + n = strlen(p); if (trace(2)) - htrc("new length(%p)=%d\n", p, strlen(p)); + htrc("new length(%p)=%d\n", p, n); - if ((signed)strlen(p) > flen) { - sprintf(g->Message, MSG(BAD_FLD_LENGTH), Name, p, flen, + if (n > flen) { + sprintf(g->Message, MSG(BAD_FLD_LENGTH), Name, p, n, tdbp->RowNumber(g), tdbp->GetFile(g)); throw 34; } else if (Dsp) diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index afab52aa282..a8f76900cb4 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -572,7 +572,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Sep = *GetStringCatInfo(g, "Separator", "."); Accept = GetBoolCatInfo("Accept", false); - // Don't use url as uri when called from REST OEM module + // Don't use url as MONGO uri when called from REST if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) Collname = GetStringCatInfo(g, "Name", diff --git a/storage/connect/tabrest.cpp b/storage/connect/tabrest.cpp new file mode 100644 index 00000000000..e800411a36d --- /dev/null +++ b/storage/connect/tabrest.cpp @@ -0,0 +1,133 @@ +/*************** Rest C++ Program Source Code File (.CPP) **************/ +/* PROGRAM NAME: Rest Version 1.3 */ +/* (C) Copyright to the author Olivier BERTRAND 2018 - 2019 */ +/* This program is the REST OEM (Web API support) module definition. */ +/***********************************************************************/ + +/***********************************************************************/ +/* Definitions needed by the included files. */ +/***********************************************************************/ +#include // All MariaDB stuff + +/***********************************************************************/ +/* Include application header files: */ +/* global.h is header containing all global declarations. */ +/* plgdbsem.h is header containing the DB application declarations. */ +/* (x)table.h is header containing the TDBASE declarations. */ +/***********************************************************************/ +#include "global.h" +#include "plgdbsem.h" +#include "xtable.h" +#include "filamtxt.h" +#include "plgxml.h" +#include "tabdos.h" +#include "tabfmt.h" +#include "tabjson.h" +#include "tabrest.h" +#include "tabxml.h" + +/***********************************************************************/ +/* Get the file from the Web. */ +/***********************************************************************/ +int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn); + +#if defined(__WIN__) +static PCSZ slash= "\\"; +#else // !__WIN__ +static PCSZ slash= "/"; +#define stricmp strcasecmp +#endif // !__WIN__ + +/***********************************************************************/ +/* Return the columns definition to MariaDB. */ +/***********************************************************************/ +PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) +{ + PQRYRES qrp= NULL; + char filename[_MAX_PATH]; + PCSZ http, uri, fn, ftype; + + http= GetStringTableOption(g, tp, "Http", NULL); + uri= GetStringTableOption(g, tp, "Uri", NULL); + fn= GetStringTableOption(g, tp, "Filename", "rest.json"); + ftype = GetStringTableOption(g, tp, "Type", "JSON"); + + // We used the file name relative to recorded datapath + strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash); + strncat(filename, fn, _MAX_PATH); + + // Retrieve the file from the web and copy it locally + if (http && restGetFile(g, http, uri, filename)) { + // sprintf(g->Message, "Failed to get file at %s", http); + } else if (!stricmp(ftype, "XML")) + qrp= XMLColumns(g, db, tab, tp, info); + else if (!stricmp(ftype, "JSON")) + qrp= JSONColumns(g, db, NULL, tp, info); + else if (!stricmp(ftype, "CSV")) + qrp= CSVColumns(g, NULL, tp, info); + else + sprintf(g->Message, "Usupported file type %s", ftype); + + return qrp; +} // end of RESTColumns + +/* -------------------------- Class RESTDEF -------------------------- */ + +/***********************************************************************/ +/* DefineAM: define specific AM block values. */ +/***********************************************************************/ +bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) +{ + char filename[_MAX_PATH]; + TABTYPE type= GetTypeID(am); + + switch (type) { + case TAB_JSON: + case TAB_XML: + case TAB_CSV: + break; + default: + sprintf(g->Message, "Unsupported REST table type %s", am); + return true; + } // endswitch type + + Http= GetStringCatInfo(g, "Http", NULL); + Uri= GetStringCatInfo(g, "Uri", NULL); + Fn= GetStringCatInfo(g, "Filename", "rest.json"); + + // We used the file name relative to recorded datapath + PlugSetPath(filename, Fn, GetPath()); + + // Retrieve the file from the web and copy it locally + if (Http && restGetFile(g, Http, Uri, filename)) {} + else if (type == TAB_JSON) + Tdp= new (g) JSONDEF; + else if (type == TAB_XML) + Tdp= new (g) XMLDEF; + else if (type == TAB_CSV) + Tdp= new (g) CSVDEF; + else + sprintf(g->Message, "Unsupported REST table type %s", am); + + // Do make the table/view definition + if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST")) + Tdp= NULL; // Error occured + + // Return true in case of error + return (Tdp == NULL); +} // end of DefineAM + +/***********************************************************************/ +/* GetTable: makes a new Table Description Block. */ +/***********************************************************************/ +PTDB RESTDEF::GetTable(PGLOBAL g, MODE m) +{ + if (m != MODE_READ && m != MODE_READX) { + strcpy(g->Message, "REST tables are currently read only"); + return NULL; + } // endif m + + return Tdp->GetTable(g, m); // Leave file type do the job +} // end of GetTable + +/* ---------------------- End of Class RESTDEF ----------------------- */ diff --git a/storage/connect/tabrest.h b/storage/connect/tabrest.h new file mode 100644 index 00000000000..1725f256079 --- /dev/null +++ b/storage/connect/tabrest.h @@ -0,0 +1,29 @@ +/*************** TabRest H Declares Source Code File (.H) **************/ +/* Name: tabrest.h Version 1.0 */ +/* (C) Copyright to the author Olivier BERTRAND 2019 */ +/* This file contains the common tabrest classes declares. */ +/***********************************************************************/ +#pragma once + +/***********************************************************************/ +/* Restest table. */ +/***********************************************************************/ +class RESTDEF : public TABDEF { /* Table description */ +public: + // Constructor + RESTDEF(void) { Tdp = NULL; Http = Uri = Fn = NULL; } + + // Implementation + virtual const char *GetType(void) { return "REST"; } + + // Methods + virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); + virtual PTDB GetTable(PGLOBAL g, MODE m); + +protected: + // Members + PRELDEF Tdp; + PCSZ Http; /* Web connection HTTP */ + PCSZ Uri; /* Web connection URI */ + PCSZ Fn; /* The intermediate file name */ +}; // end of class RESTDEF diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index 77f0a1c4001..b2dbdd70e06 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -232,7 +232,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) { int n; uint sln; - const char *scs; + const char *scs; PTABLE tp, tabp; PCOL colp; PTBLDEF tdp = (PTBLDEF)To_Def; diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index d808bd5ecd4..19490d350e8 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -1880,7 +1880,7 @@ void XMULCOL::ReadColumn(PGLOBAL g) if (N > Tdbp->Limit) { N = Tdbp->Limit; - sprintf(g->Message, "Mutiple values limited to %d", Tdbp->Limit); + sprintf(g->Message, "Multiple values limited to %d", Tdbp->Limit); PushWarning(g, Tdbp); } // endif N diff --git a/storage/connect/user_connect.cc b/storage/connect/user_connect.cc index ec591f9e4ef..3bde2fa58eb 100644 --- a/storage/connect/user_connect.cc +++ b/storage/connect/user_connect.cc @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /** @file user_connect.cc @@ -178,7 +178,7 @@ bool user_connect::CheckCleanup(bool force) g->Alchecked = 0; g->Mrr = 0; g->More = 0; - last_query_id= thdp->query_id; + last_query_id= thdp->query_id; if (trace(65) && !force) printf("=====> Begin new query %llu\n", last_query_id); diff --git a/storage/connect/user_connect.h b/storage/connect/user_connect.h index 983d9adc478..22783d7fc12 100644 --- a/storage/connect/user_connect.h +++ b/storage/connect/user_connect.h @@ -11,7 +11,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ /** @file user_connect.h diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp index e159efaa989..d9330a68a15 100644 --- a/storage/connect/value.cpp +++ b/storage/connect/value.cpp @@ -1,7 +1,7 @@ /************* Value C++ Functions Source Code File (.CPP) *************/ -/* Name: VALUE.CPP Version 2.8 */ +/* Name: VALUE.CPP Version 2.9 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2001-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2001-2019 */ /* */ /* This file contains the VALUE and derived classes family functions. */ /* These classes contain values of different types. They are used so */ @@ -882,18 +882,16 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) /* TYPVAL ShowValue: get string representation of a typed value. */ /***********************************************************************/ template -char *TYPVAL::ShowValue(char *buf, int len) +int TYPVAL::ShowValue(char *buf, int len) { - sprintf(buf, Xfmt, len, Tval); - return buf; + return snprintf(buf, len + 1, Xfmt, len, Tval); } // end of ShowValue template <> -char *TYPVAL::ShowValue(char *buf, int len) +int TYPVAL::ShowValue(char *buf, int len) { - // TODO: use snprintf to avoid possible overflow - sprintf(buf, Xfmt, len, Prec, Tval); - return buf; + // TODO: use a more appropriate format to avoid possible truncation + return snprintf(buf, len + 1, Xfmt, len, Prec, Tval); } // end of ShowValue /***********************************************************************/ @@ -1588,10 +1586,17 @@ bool TYPVAL::GetBinValue(void *buf, int buflen, bool go) /***********************************************************************/ /* STRING ShowValue: get string representation of a char value. */ /***********************************************************************/ -char *TYPVAL::ShowValue(char *, int) - { - return Strp; - } // end of ShowValue +int TYPVAL::ShowValue(char *buf, int buflen) +{ + int len = (Null) ? 0 : strlen(Strp); + + if (buf && buf != Strp) { + memset(buf, ' ', buflen + 1); + memcpy(buf, Strp, MY_MIN(len, buflen)); + } // endif buf + + return len; +} // end of ShowValue /***********************************************************************/ /* STRING GetCharString: get string representation of a char value. */ @@ -1800,10 +1805,9 @@ void DECVAL::Reset(void) /***********************************************************************/ /* DECIMAL ShowValue: get string representation right justified. */ /***********************************************************************/ -char *DECVAL::ShowValue(char *buf, int len) +int DECVAL::ShowValue(char *buf, int len) { - sprintf(buf, Xfmt, len, Strp); - return buf; + return snprintf(buf, len + 1, Xfmt, len, Strp); } // end of ShowValue /***********************************************************************/ @@ -1868,14 +1872,13 @@ int DECVAL::CompareValue(PVAL vp) BINVAL::BINVAL(PGLOBAL g, void *p, int cl, int n) : VALUE(TYPE_BIN) { assert(g); -//Len = n; - Len = (g) ? n : (p) ? strlen((char*)p) : 0; + Len = n; Clen = cl; Binp = PlugSubAlloc(g, NULL, Clen + 1); memset(Binp, 0, Clen + 1); if (p) - memcpy(Binp, p, Len); + memcpy(Binp, p, MY_MIN(Len,Clen)); Chrp = NULL; } // end of BINVAL constructor @@ -2264,14 +2267,12 @@ bool BINVAL::GetBinValue(void *buf, int buflen, bool go) /***********************************************************************/ /* BINVAL ShowValue: get string representation of a binary value. */ /***********************************************************************/ -char *BINVAL::ShowValue(char *buf, int len) - { - //int n = MY_MIN(Len, len / 2); - - //sprintf(buf, GetXfmt(), n, Binp); - //return buf; - return (char*)Binp; - } // end of ShowValue +int BINVAL::ShowValue(char *buf, int len) +{ + memset(buf, 0, len + 1); + memcpy(buf, Binp, MY_MIN(len, Len)); + return Len; +} // end of ShowValue /***********************************************************************/ /* BINVAL GetCharString: get string representation of a binary value. */ @@ -2749,43 +2750,33 @@ char *DTVAL::GetCharString(char *p) /***********************************************************************/ /* DTVAL ShowValue: get string representation of a date value. */ /***********************************************************************/ -char *DTVAL::ShowValue(char *buf, int len) - { - if (Pdtp) { - char *p; +int DTVAL::ShowValue(char *buf, int len) +{ + int rv = 0; + if (Pdtp) { if (!Null) { - size_t m, n = 0; + size_t n = 0, m = len + 1; struct tm tm, *ptm = GetGmTime(&tm); - - - - if (Len < len) { - p = buf; - m = len; - } else { - p = Sdate; - m = Len + 1; - } // endif Len if (ptm) - n = strftime(p, m, Pdtp->OutFmt, ptm); + n = strftime(buf, m, Pdtp->OutFmt, ptm); if (!n) { - *p = '\0'; - strncat(p, "Error", m); - } // endif n + *buf = '\0'; + strncat(buf, "Error", m); + rv = 5; + } else + rv = (int)n; - } else { - p = buf; - *p = '\0'; // DEFAULT VALUE ??? - } // endif Null + } else + *buf = '\0'; // DEFAULT VALUE ??? - return p; } else - return TYPVAL::ShowValue(buf, len); + rv = TYPVAL::ShowValue(buf, len); - } // end of ShowValue + return rv; +} // end of ShowValue #if 0 // Not used by CONNECT /***********************************************************************/ diff --git a/storage/connect/value.h b/storage/connect/value.h index 6613e25100a..4f7d9a440fa 100644 --- a/storage/connect/value.h +++ b/storage/connect/value.h @@ -1,7 +1,7 @@ /**************** Value H Declares Source Code File (.H) ***************/ -/* Name: VALUE.H Version 2.3 */ +/* Name: VALUE.H Version 2.4 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2001-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2001-2019 */ /* */ /* This file contains the VALUE and derived classes declares. */ /***********************************************************************/ @@ -117,7 +117,7 @@ class DllExport VALUE : public BLOCK { virtual void SetValue_pvblk(PVBLK blk, int n) = 0; virtual void SetBinValue(void *p) = 0; virtual bool GetBinValue(void *buf, int buflen, bool go) = 0; - virtual char *ShowValue(char *buf, int len = 0) = 0; + virtual int ShowValue(char *buf, int len) = 0; virtual char *GetCharString(char *p) = 0; virtual bool IsEqual(PVAL vp, bool chktype) = 0; virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op); @@ -229,7 +229,7 @@ class DllExport TYPVAL : public VALUE { virtual void SetValue_pvblk(PVBLK blk, int n); virtual void SetBinValue(void *p); virtual bool GetBinValue(void *buf, int buflen, bool go); - virtual char *ShowValue(char *buf, int); + virtual int ShowValue(char *buf, int len); virtual char *GetCharString(char *p); virtual bool IsEqual(PVAL vp, bool chktype); virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op); @@ -302,7 +302,7 @@ class DllExport TYPVAL: public VALUE { virtual void SetBinValue(void *p); virtual int CompareValue(PVAL vp); virtual bool GetBinValue(void *buf, int buflen, bool go); - virtual char *ShowValue(char *buf, int); + virtual int ShowValue(char *buf, int len); virtual char *GetCharString(char *p); virtual bool IsEqual(PVAL vp, bool chktype); virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op); @@ -334,7 +334,7 @@ class DllExport DECVAL: public TYPVAL { // Methods virtual bool GetBinValue(void *buf, int buflen, bool go); - virtual char *ShowValue(char *buf, int); + virtual int ShowValue(char *buf, int len); virtual bool IsEqual(PVAL vp, bool chktype); virtual int CompareValue(PVAL vp); @@ -387,7 +387,7 @@ class DllExport BINVAL: public VALUE { virtual void SetBinValue(void *p); virtual bool GetBinValue(void *buf, int buflen, bool go); virtual int CompareValue(PVAL) {assert(false); return 0;} - virtual char *ShowValue(char *buf, int); + virtual int ShowValue(char *buf, int len); virtual char *GetCharString(char *p); virtual bool IsEqual(PVAL vp, bool chktype); virtual bool FormatValue(PVAL vp, PCSZ fmt); @@ -415,7 +415,7 @@ class DllExport DTVAL : public TYPVAL { virtual void SetValue_psz(PCSZ s); virtual void SetValue_pvblk(PVBLK blk, int n); virtual char *GetCharString(char *p); - virtual char *ShowValue(char *buf, int); + virtual int ShowValue(char *buf, int len); virtual bool FormatValue(PVAL vp, PCSZ fmt); bool SetFormat(PGLOBAL g, PCSZ fmt, int len, int year = 0); bool SetFormat(PGLOBAL g, PVAL valp); -- cgit v1.2.1 From 06b3715f26a35eeba13c102772c3409d33170e81 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Fri, 28 Jun 2019 11:53:58 +0200 Subject: Record some failing test results (dir,xml,xml2) --- storage/connect/mysql-test/connect/r/dir.result | 2 +- storage/connect/mysql-test/connect/r/xml.result | 100 +++++++++++------------ storage/connect/mysql-test/connect/r/xml2.result | 2 +- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/storage/connect/mysql-test/connect/r/dir.result b/storage/connect/mysql-test/connect/r/dir.result index 139544b99e9..e10bb458d62 100644 --- a/storage/connect/mysql-test/connect/r/dir.result +++ b/storage/connect/mysql-test/connect/r/dir.result @@ -26,7 +26,7 @@ fname ftype size boys .txt 282 boyswin .txt 288 INSERT INTO t1 VALUES ('','','',''); -ERROR 22007: Incorrect double value: '' for column `test`.`t1`.`size` at row 1 +ERROR 22007: Incorrect double value: '' for column 'size' at row 1 DROP TABLE t1; CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.txt'; ERROR HY000: Cannot get column info for table type DIR diff --git a/storage/connect/mysql-test/connect/r/xml.result b/storage/connect/mysql-test/connect/r/xml.result index 6a0c9db27b3..055a9d18e12 100644 --- a/storage/connect/mysql-test/connect/r/xml.result +++ b/storage/connect/mysql-test/connect/r/xml.result @@ -158,47 +158,47 @@ TRANSLATOR NULL PUBLISHER Eyrolles Paris DATEPUB 1998 SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml; -xml - - - - Jean-Christophe - Bernadac - - - François - Knab - - Construire une application XML - - Eyrolles - Paris - - 1999 - - - - William J. - Pardi - - - James - Guerin - - XML en Action - - Microsoft Press - Paris - - 1999 - - - Alain Michard - XML, Langage et Applications - Eyrolles Paris - 1998 - - +xml + + + + Jean-Christophe + Bernadac + + + François + Knab + + Construire une application XML + + Eyrolles + Paris + + 1999 + + + + William J. + Pardi + + + James + Guerin + + XML en Action + + Microsoft Press + Paris + + 1999 + + + Alain Michard + XML, Langage et Applications + Eyrolles Paris + 1998 + + DROP TABLE t1; # @@ -323,7 +323,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 @@ -374,7 +374,7 @@ INSERT INTO t1 VALUES (_cp1251 0xC0C1C2C3); Warnings: Level Warning Code 1105 -Message Com error: Unable to save character to 'iso-8859-1' encoding. +Message Com error: Unable to save character to 'iso-8859-1' encoding. INSERT INTO t1 VALUES ('&<>"\''); SELECT node, hex(node) FROM t1; @@ -383,11 +383,11 @@ hex(node) 263C3E2227 DROP TABLE t1; SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml'); SELECT CAST(@a AS CHAR CHARACTER SET latin1); -CAST(@a AS CHAR CHARACTER SET latin1) - - - - &<>"' - - +CAST(@a AS CHAR CHARACTER SET latin1) + + + + &<>"' + + diff --git a/storage/connect/mysql-test/connect/r/xml2.result b/storage/connect/mysql-test/connect/r/xml2.result index f7bbc17c8a0..b8075fa1928 100644 --- a/storage/connect/mysql-test/connect/r/xml2.result +++ b/storage/connect/mysql-test/connect/r/xml2.result @@ -325,7 +325,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 -- cgit v1.2.1 From 7628fd3c6e9cfaeafd423aa8fc22efba41782e90 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 22 Aug 2019 16:16:23 +0200 Subject: Include all changes made on 10.2 --- storage/connect/CMakeLists.txt | 82 +- storage/connect/array.cpp | 127 +- storage/connect/block.h | 4 +- storage/connect/global.h | 1 + storage/connect/ha_connect.cc | 257 +-- storage/connect/mini-global.h | 33 + storage/connect/mycat.cc | 149 +- storage/connect/mysql-test/connect/r/dir.result | 2 +- storage/connect/mysql-test/connect/r/xml.result | 100 +- storage/connect/mysql-test/connect/r/xml2.result | 2 +- storage/connect/osutil.h | 4 + storage/connect/plugutil.cpp | 36 +- storage/connect/reldef.cpp | 299 ++-- storage/connect/restget.cpp | 111 +- storage/connect/tabfmt.cpp | 2 + storage/connect/tabjdbc.cpp | 4 +- storage/connect/tabjson.cpp | 1929 +++++++++++----------- storage/connect/tabrest.cpp | 160 +- storage/connect/tabtbl.cpp | 2 +- 19 files changed, 1712 insertions(+), 1592 deletions(-) create mode 100644 storage/connect/mini-global.h diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 153512b994c..fd006e104c1 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -40,10 +40,6 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS) add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT ) -macro(DISABLE_WARNING W) - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-error=${W}") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-${W}" DEBUG) -endmacro() # # OS specific C flags, definitions and source files. @@ -51,15 +47,14 @@ endmacro() IF(UNIX) MY_CHECK_AND_SET_COMPILER_FLAG("-Wall -Wmissing-declarations") if(NOT WITH_WARNINGS) - DISABLE_WARNING("unused-function") - DISABLE_WARNING("unused-variable") - DISABLE_WARNING("unused-value") - DISABLE_WARNING("parentheses") - DISABLE_WARNING("strict-aliasing") - DISABLE_WARNING("misleading-indentation") - DISABLE_WARNING("format-truncation") - DISABLE_WARNING("implicit-fallthrough") - DISABLE_WARNING("type-limits") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-function") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-variable") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-value") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-parentheses") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-misleading-indentation") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-format-truncation") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough") endif(NOT WITH_WARNINGS) add_definitions( -DUNIX -DLINUX -DUBUNTU ) @@ -73,6 +68,10 @@ ELSE(NOT UNIX) tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h) # Add exception handling to the CONNECT project) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD") + SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD") SET(IPHLPAPI_LIBRARY iphlpapi.lib) IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang)) # Connect does not work with clang-cl @@ -118,7 +117,6 @@ IF(CONNECT_WITH_LIBXML2) FIND_PACKAGE(LibXml2) IF (LIBXML2_FOUND) INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) - SET(ZLIB_LIBRARY "z") # see ZLIB_INCLUDE_DIR below SET(XML_LIBRARY ${LIBXML2_LIBRARIES}) SET(CONNECT_SOURCES ${CONNECT_SOURCES} libdoc.cpp libdoc.h) add_definitions(-DLIBXML2_SUPPORT) @@ -173,8 +171,7 @@ IF(CONNECT_WITH_ODBC) # the library 'libiodbc' gets compiled with 'sql'h. # This will also need changes in the sources (e.g. #include ). - find_file(ODBC_INCLUDES sql.h - PATHS + find_path(ODBC_INCLUDE_DIR sql.h /usr/include /usr/include/odbc /usr/local/include @@ -184,7 +181,7 @@ IF(CONNECT_WITH_ODBC) #"C:/Program Files/Microsoft SDKs/Windows/v7.0A/include" #"C:/Program Files/Microsoft SDKs/Windows/v6.0a/include" #"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include" - DOC "Specify the path to sql.h." + DOC "Specify the directory containing sql.h." ) find_library(ODBC_LIBRARY @@ -203,10 +200,9 @@ IF(CONNECT_WITH_ODBC) DOC "Specify the ODBC driver manager library here." ) - mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDES) + mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR) - IF(ODBC_INCLUDES AND ODBC_LIBRARY) - get_filename_component(ODBC_INCLUDE_DIR "${ODBC_INCLUDES}" PATH) + IF(ODBC_INCLUDE_DIR AND ODBC_LIBRARY) set(CMAKE_REQUIRED_LIBRARIES ${ODBC_LIBRARY}) set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIR}) CHECK_CXX_SOURCE_COMPILES( @@ -316,19 +312,25 @@ ENDIF(CONNECT_WITH_MONGO) # REST # -#OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) +OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) IF(CONNECT_WITH_REST) MESSAGE(STATUS "=====> REST support is ON") FIND_PACKAGE(cpprestsdk) IF (cpprestsdk_FOUND) MESSAGE(STATUS "=====> cpprestsdk found") + IF(UNIX) +# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR}) +# If needed edit next line to set the path to libcpprest.so + SET(REST_LIBRARY -lcpprest) + MESSAGE (STATUS ${REST_LIBRARY}) + ENDIF(UNIX) SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) add_definitions(-DREST_SUPPORT) ELSE(NOT cpprestsdk_FOUND) MESSAGE(STATUS "=====> cpprestsdk package not found") ENDIF (cpprestsdk_FOUND) -ENDIF(CONNECT_WITH_ZIP) +ENDIF(CONNECT_WITH_REST) # # XMAP @@ -349,41 +351,32 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES} COMPONENT connect-engine RECOMPILE_FOR_EMBEDDED LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY} - ${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY}) + ${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY} ${REST_LIBRARY}) IF(NOT TARGET connect) RETURN() ENDIF() -# Don't link with bundled zlib and systel libxml2 at the same time. -# System libxml2 uses system zlib, might conflict with the bundled one. -IF (XML_LIBRARY AND BUILD_BUNDLED_ZLIB) - GET_PROPERTY(INCS TARGET connect PROPERTY INCLUDE_DIRECTORIES) - LIST(REMOVE_ITEM INCS ${ZLIB_INCLUDE_DIR}) - SET_PROPERTY(TARGET connect PROPERTY INCLUDE_DIRECTORIES ${INCS}) -ENDIF() - IF(WIN32) IF (libmongoc-1.0_FOUND) - SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS - "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") + SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS + "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") ENDIF(libmongoc-1.0_FOUND) +ENDIF(WIN32) # Install some extra files that belong to connect engine - - INSTALL(FILES "$/ha_connect.lib" +IF(WIN32) + # install ha_connect.lib + GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION) + STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION}) + IF(CMAKE_CONFIGURATION_TYPES) + STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" + CONNECT_LIB ${CONNECT_LIB}) + ENDIF() + INSTALL(FILES ${CONNECT_LIB} DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF(WIN32) -IF(MSVC) - # Temporarily disable "conversion from size_t .." - IF(CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") - ENDIF() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") - string(REPLACE "/permissive-" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -ENDIF() - IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND) # TODO: Find how to compile and install the java wrapper classes # Find required libraries and include directories @@ -394,3 +387,4 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF() + diff --git a/storage/connect/array.cpp b/storage/connect/array.cpp index cd1785b48ac..3478342a788 100644 --- a/storage/connect/array.cpp +++ b/storage/connect/array.cpp @@ -1,7 +1,7 @@ /************* Array C++ Functions Source Code File (.CPP) *************/ /* Name: ARRAY.CPP Version 2.3 */ /* */ -/* (C) Copyright to the author Olivier BERTRAND 2005-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 2005-2019 */ /* */ /* This file contains the XOBJECT derived class ARRAY functions. */ /* ARRAY is used for elaborate type of processing, such as sorting */ @@ -67,7 +67,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp); // avoid gcc warning /* MakeValueArray: Makes a value array from a value list. */ /***********************************************************************/ PARRAY MakeValueArray(PGLOBAL g, PPARM pp) - { +{ int n, valtyp = 0; size_t len = 0; PARRAY par; @@ -82,8 +82,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp) if ((valtyp = pp->Type) != TYPE_STRING) len = 1; - if (trace(1)) - htrc("valtyp=%d len=%d\n", valtyp, len); + xtrc(1, "valtyp=%d len=%d\n", valtyp, len); /*********************************************************************/ /* Firstly check the list and count the number of values in it. */ @@ -127,13 +126,13 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp) // Integer stored inside pp->Value par->AddValue(g, parmp->Intval); break; - } // endswitch valtyp + } // endswitch valtyp /*********************************************************************/ /* Send back resulting array. */ /*********************************************************************/ return par; - } // end of MakeValueArray +} // end of MakeValueArray /* -------------------------- Class ARRAY ---------------------------- */ @@ -151,6 +150,9 @@ ARRAY::ARRAY(PGLOBAL g, int type, int size, int length, int prec) Type = type; Xsize = -1; Len = 1; + X = 0; + Inf = 0; + Sup = 0; switch (type) { case TYPE_STRING: @@ -281,130 +283,109 @@ void ARRAY::Empty(void) /* Add a string element to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, PSZ strp) - { +{ if (Type != TYPE_STRING) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "CHAR"); return true; - } // endif Type - - if (trace(1)) - htrc(" adding string(%d): '%s'\n", Nval, strp); + } // endif Type -//Value->SetValue_psz(strp); -//Vblp->SetValue(valp, Nval++); + xtrc(1, " adding string(%d): '%s'\n", Nval, strp); Vblp->SetValue(strp, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Add a char pointer element to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, void *p) - { +{ if (Type != TYPE_PCHAR) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "PCHAR"); return true; - } // endif Type - - if (trace(1)) - htrc(" adding pointer(%d): %p\n", Nval, p); + } // endif Type + xtrc(1, " adding pointer(%d): %p\n", Nval, p); Vblp->SetValue((PSZ)p, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Add a short integer element to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, short n) - { +{ if (Type != TYPE_SHORT) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "SHORT"); return true; - } // endif Type - - if (trace(1)) - htrc(" adding SHORT(%d): %hd\n", Nval, n); + } // endif Type -//Value->SetValue(n); -//Vblp->SetValue(valp, Nval++); + xtrc(1, " adding SHORT(%d): %hd\n", Nval, n); Vblp->SetValue(n, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Add an integer element to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, int n) - { +{ if (Type != TYPE_INT) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "INTEGER"); return true; - } // endif Type + } // endif Type - if (trace(1)) - htrc(" adding int(%d): %d\n", Nval, n); - -//Value->SetValue(n); -//Vblp->SetValue(valp, Nval++); + xtrc(1, " adding int(%d): %d\n", Nval, n); Vblp->SetValue(n, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Add a double float element to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, double d) - { +{ if (Type != TYPE_DOUBLE) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(Type), "DOUBLE"); return true; - } // endif Type - - if (trace(1)) - htrc(" adding float(%d): %lf\n", Nval, d); + } // endif Type + xtrc(1, " adding float(%d): %lf\n", Nval, d); Value->SetValue(d); Vblp->SetValue(Value, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Add the value of a XOBJECT block to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, PXOB xp) - { - if (Type != xp->GetResultType()) { - sprintf(g->Message, MSG(ADD_BAD_TYPE), - GetTypeName(xp->GetResultType()), GetTypeName(Type)); - return true; - } // endif Type - - if (trace(1)) - htrc(" adding (%d) from xp=%p\n", Nval, xp); +{ + if (Type != xp->GetResultType()) { + sprintf(g->Message, MSG(ADD_BAD_TYPE), + GetTypeName(xp->GetResultType()), GetTypeName(Type)); + return true; + } // endif Type -//AddValue(xp->GetValue()); - Vblp->SetValue(xp->GetValue(), Nval++); - return false; - } // end of AddValue + xtrc(1, " adding (%d) from xp=%p\n", Nval, xp); + Vblp->SetValue(xp->GetValue(), Nval++); + return false; +} // end of AddValue /***********************************************************************/ /* Add a value to an array. */ /***********************************************************************/ bool ARRAY::AddValue(PGLOBAL g, PVAL vp) - { +{ if (Type != vp->GetType()) { sprintf(g->Message, MSG(ADD_BAD_TYPE), GetTypeName(vp->GetType()), GetTypeName(Type)); return true; - } // endif Type - - if (trace(1)) - htrc(" adding (%d) from vp=%p\n", Nval, vp); + } // endif Type + xtrc(1, " adding (%d) from vp=%p\n", Nval, vp); Vblp->SetValue(vp, Nval++); return false; - } // end of AddValue +} // end of AddValue /***********************************************************************/ /* Retrieve the nth value of the array. */ @@ -973,7 +954,7 @@ int ARRAY::BlockTest(PGLOBAL, int opc, int opm, /* MakeArrayList: Makes a value list from an SQL IN array (in work). */ /***********************************************************************/ PSZ ARRAY::MakeArrayList(PGLOBAL g) - { +{ char *p, *tp; int i; size_t z, len = 2; @@ -988,11 +969,9 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g) Value->SetValue_pvblk(Vblp, i); Value->Prints(g, tp, z); len += strlen(tp); - } // enfor i - - if (trace(1)) - htrc("Arraylist: len=%d\n", len); + } // enfor i + xtrc(1, "Arraylist: len=%d\n", len); p = (char *)PlugSubAlloc(g, NULL, len); strcpy(p, "("); @@ -1001,19 +980,17 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g) Value->Prints(g, tp, z); strcat(p, tp); strcat(p, (++i == Nval) ? ")" : ","); - } // enfor i - - if (trace(1)) - htrc("Arraylist: newlen=%d\n", strlen(p)); + } // enfor i + xtrc(1, "Arraylist: newlen=%d\n", strlen(p)); return p; - } // end of MakeArrayList +} // end of MakeArrayList /***********************************************************************/ /* Make file output of ARRAY contents. */ /***********************************************************************/ void ARRAY::Printf(PGLOBAL g, FILE *f, uint n) - { +{ char m[64]; int lim = MY_MIN(Nval,10); @@ -1035,19 +1012,19 @@ void ARRAY::Printf(PGLOBAL g, FILE *f, uint n) } else fprintf(f, "%sVALLST: numval=%d\n", m, Nval); - } // end of Printf +} // end of Printf /***********************************************************************/ /* Make string output of ARRAY contents. */ /***********************************************************************/ void ARRAY::Prints(PGLOBAL, char *ps, uint z) - { +{ if (z < 16) return; sprintf(ps, "ARRAY: type=%d\n", Type); // More to be implemented later - } // end of Prints +} // end of Prints /* -------------------------- Class MULAR ---------------------------- */ diff --git a/storage/connect/block.h b/storage/connect/block.h index 737c74c1293..2ca9586ee3f 100644 --- a/storage/connect/block.h +++ b/storage/connect/block.h @@ -38,9 +38,7 @@ typedef class BLOCK *PBLOCK; class DllExport BLOCK { public: void * operator new(size_t size, PGLOBAL g, void *p = NULL) { - if (trace(256)) - htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p); - + xtrc(256, "New BLOCK: size=%d g=%p p=%p\n", size, g, p); return (PlugSubAlloc(g, p, size)); } // end of new diff --git a/storage/connect/global.h b/storage/connect/global.h index dc1e149745f..fd26c87b800 100644 --- a/storage/connect/global.h +++ b/storage/connect/global.h @@ -224,6 +224,7 @@ DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t); DllExport char *PlugDup(PGLOBAL g, const char *str); DllExport void *MakePtr(void *, OFFSET); DllExport void htrc(char const *fmt, ...); +DllExport void xtrc(uint, char const* fmt, ...); DllExport uint GetTraceValue(void); #if defined(__cplusplus) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index eb5356e81c3..3398c7cabed 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -164,13 +164,13 @@ /***********************************************************************/ /* Initialize the ha_connect static members. */ /***********************************************************************/ -#define SZCONV 1024 // Default TEXT conversion size +#define SZCONV 1024 // Default converted text size #define SZWORK 67108864 // Default work area size 64M #define SZWMIN 4194304 // Minimum work area size 4M #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.06.0010 June 21, 2019"; + char version[]= "Version 1.06.0010 August 22, 2019"; #if defined(__WIN__) char compver[]= "Version 1.06.0010 " __DATE__ " " __TIME__; char slash= '\\'; @@ -241,7 +241,9 @@ int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v); void PushWarning(PGLOBAL g, THD *thd, int level); bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db, PCSZ tab, PCSZ src, int port); +#if defined(ZIP_SUPPORT) bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool); +#endif // ZIP_SUPPORT bool ExactInfo(void); #if defined(CMGO_SUPPORT) //void mongo_init(bool); @@ -994,11 +996,11 @@ static PCONNECT GetUser(THD *thd, PCONNECT xp) pthread_mutex_unlock(&usrmut); if (!xp) { - xp = new user_connect(thd); + xp= new user_connect(thd); if (xp->user_init()) { delete xp; - xp = NULL; + xp= NULL; } // endif user_init } // endif xp @@ -1146,48 +1148,48 @@ PCSZ GetListOption(PGLOBAL g, PCSZ opname, PCSZ oplist, PCSZ def) return (char*)def; char key[16], val[256]; - char *pv, *pn, *pk = (char*)oplist; - PCSZ opval = def; + char *pv, *pn, *pk= (char*)oplist; + PCSZ opval= def; int n; while (*pk == ' ') pk++; - for (; pk; pk = pn) { - pn = strchr(pk, ','); - pv = strchr(pk, '='); + for (; pk; pk= pn) { + pn= strchr(pk, ','); + pv= strchr(pk, '='); if (pv && (!pn || pv < pn)) { - n = MY_MIN(static_cast(pv - pk), sizeof(key) - 1); + n= MY_MIN(static_cast(pv - pk), sizeof(key) - 1); memcpy(key, pk, n); while (n && key[n - 1] == ' ') n--; - key[n] = 0; + key[n]= 0; while (*(++pv) == ' '); - n = MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1); + n= MY_MIN((pn ? pn - pv : strlen(pv)), sizeof(val) - 1); memcpy(val, pv, n); while (n && val[n - 1] == ' ') n--; - val[n] = 0; + val[n]= 0; } else { - n = MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1); + n= MY_MIN((pn ? pn - pk : strlen(pk)), sizeof(key) - 1); memcpy(key, pk, n); while (n && key[n - 1] == ' ') n--; - key[n] = 0; - val[0] = 0; + key[n]= 0; + val[0]= 0; } // endif pv if (!stricmp(opname, key)) { - opval = PlugDup(g, val); + opval= PlugDup(g, val); break; } else if (!pn) break; @@ -1235,7 +1237,7 @@ PCSZ GetStringTableOption(PGLOBAL g, PTOS options, PCSZ opname, PCSZ sdef) else if (!stricmp(opname, "Colist")) opval= options->colist; else if (!stricmp(opname, "Filter")) - opval = options->filter; + opval= options->filter; else if (!stricmp(opname, "Data_charset")) opval= options->data_charset; else if (!stricmp(opname, "Http") || !stricmp(opname, "URL")) @@ -1272,7 +1274,7 @@ bool GetBooleanTableOption(PGLOBAL g, PTOS options, PCSZ opname, bool bdef) else if (!stricmp(opname, "Header")) opval= (options->header != 0); // Is Boolean for some table types else if (!stricmp(opname, "Zipped")) - opval = options->zipped; + opval= options->zipped; else if (options->oplist) if ((pv= GetListOption(g, opname, options->oplist))) opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0); @@ -1366,8 +1368,8 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef) } else if (!stricmp(opname, "Query_String")) { // This escapes everything and returns a wrong query -// opval = thd_query_string(table->in_use)->str; - opval = (PCSZ)PlugSubAlloc(xp->g, NULL, +// opval= thd_query_string(table->in_use)->str; + opval= (PCSZ)PlugSubAlloc(xp->g, NULL, thd_query_string(table->in_use)->length + 1); strcpy((char*)opval, thd_query_string(table->in_use)->str); // sprintf((char*)opval, "%s", thd_query_string(table->in_use)->str); @@ -1388,7 +1390,7 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef) || !stricmp(opname, "filename") || !stricmp(opname, "optname") || !stricmp(opname, "entry"))) - opval = GetRealString(opval); + opval= GetRealString(opval); if (!opval) { if (sdef && !strcmp(sdef, "*")) { @@ -1517,7 +1519,7 @@ PFOS ha_connect::GetFieldOptionStruct(Field *fdp) void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) { const char *cp; - char *chset, v = 0; + char *chset, v= 0; ha_field_option_struct *fop; Field* fp; Field* *fldp; @@ -1569,7 +1571,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) pcf->Fieldfmt= NULL; } // endif fop - chset = (char *)fp->charset()->name; + chset= (char *)fp->charset()->name; switch (fp->type()) { case MYSQL_TYPE_BLOB: @@ -2075,10 +2077,10 @@ bool ha_connect::CheckColumnList(PGLOBAL g) } catch (int n) { if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); - brc = true; + brc= true; } catch (const char *msg) { strcpy(g->Message, msg); - brc = true; + brc= true; } // end catch return brc; @@ -2205,9 +2207,9 @@ int ha_connect::MakeRecord(char *buf) rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN); break; case TYPE_BIN: - p = value->GetCharValue(); - charset = &my_charset_bin; - rc = fp->store(p, strlen(p), charset, CHECK_FIELD_WARN); + p= value->GetCharValue(); + charset= &my_charset_bin; + rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN); break; case TYPE_DOUBLE: rc= fp->store(value->GetFloatValue()); @@ -2456,7 +2458,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL vop, char q, kfp= &table->key_info[active_index]; old_map= dbug_tmp_use_all_columns(table, table->write_set); - for (i = 0; i <= 1; i++) { + for (i= 0; i <= 1; i++) { if (ranges[i] == NULL) continue; @@ -2837,7 +2839,7 @@ PFIL ha_connect::CondFilter(PGLOBAL g, Item *cond) /***********************************************************************/ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) { - AMT tty = filp->Type; + AMT tty= filp->Type; char *body= filp->Body; char *havg= filp->Having; unsigned int i; @@ -2854,7 +2856,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if (cond->type() == COND::COND_ITEM) { char *pb0, *pb1, *pb2, *ph0= 0, *ph1= 0, *ph2= 0; - bool bb = false, bh = false; + bool bb= false, bh= false; Item_cond *cond_item= (Item_cond *)cond; if (x) @@ -2913,13 +2915,13 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) bb |= filp->Bd; bh |= filp->Hv; - filp->Bd = filp->Hv = false; + filp->Bd= filp->Hv= false; } else return NULL; if (bb) { strcpy(pb1, ")"); - filp->Bd = bb; + filp->Bd= bb; } else *pb0= 0; @@ -2927,13 +2929,13 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if (bb && bh && vop == OP_OR) { // Cannot or'ed a where clause with a having clause bb= bh= 0; - *pb0 = 0; - *ph0 = 0; + *pb0= 0; + *ph0= 0; } else if (bh) { strcpy(ph1, ")"); filp->Hv= bh; } else - *ph0 = 0; + *ph0= 0; } // endif havg @@ -2946,7 +2948,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) Item_func *condf= (Item_func *)cond; Item* *args= condf->arguments(); - filp->Bd = filp->Hv = false; + filp->Bd= filp->Hv= false; if (trace(1)) htrc("Func type=%d argnum=%d\n", condf->functype(), @@ -2962,10 +2964,10 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) case Item_func::GT_FUNC: vop= OP_GT; break; case Item_func::LIKE_FUNC: vop= OP_LIKE; - neg = ((Item_func_opt_neg *)condf)->negated; + neg= ((Item_func_opt_neg *)condf)->negated; break; case Item_func::ISNOTNULL_FUNC: - neg = true; + neg= true; // fall through case Item_func::ISNULL_FUNC: vop= OP_NULL; break; case Item_func::IN_FUNC: vop= OP_IN; /* fall through */ @@ -3023,12 +3025,12 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) } else { bool h; - fnm = filp->Chk(pField->field->field_name.str, &h); + fnm= filp->Chk(pField->field->field_name.str, &h); if (h && i && !ishav) return NULL; // Having should be col VOP arg else - ishav = h; + ishav= h; } // endif's @@ -3079,7 +3081,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) if (!x) { const char *p; - char *s = (ishav) ? havg : body; + char *s= (ishav) ? havg : body; uint j, k, n; // Append the value to the filter @@ -3136,37 +3138,37 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) strcat(s, "'}"); break; default: - j = strlen(s); - s[j++] = '\''; - p = res->ptr(); - n = res->length(); + j= strlen(s); + s[j++]= '\''; + p= res->ptr(); + n= res->length(); - for (k = 0; k < n; k++) { + for (k= 0; k < n; k++) { if (p[k] == '\'') - s[j++] = '\''; + s[j++]= '\''; - s[j++] = p[k]; + s[j++]= p[k]; } // endfor k - s[j++] = '\''; - s[j] = 0; + s[j++]= '\''; + s[j]= 0; } // endswitch field type } else { - j = strlen(s); - s[j++] = '\''; - p = res->ptr(); - n = res->length(); + j= strlen(s); + s[j++]= '\''; + p= res->ptr(); + n= res->length(); - for (k = 0; k < n; k++) { + for (k= 0; k < n; k++) { if (p[k] == '\'') - s[j++] = '\''; + s[j++]= '\''; - s[j++] = p[k]; + s[j++]= p[k]; } // endfor k - s[j++] = '\''; - s[j] = 0; + s[j++]= '\''; + s[j]= 0; } // endif tty break; @@ -3190,7 +3192,7 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) } // endif's Type if (!x) { - char *s = (ishav) ? havg : body; + char *s= (ishav) ? havg : body; if (!i) strcat(s, GetValStr(vop, neg)); @@ -3204,11 +3206,11 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) } // endfor i if (x) - filp->Op = vop; + filp->Op= vop; else if (ishav) - filp->Hv = true; + filp->Hv= true; else - filp->Bd = true; + filp->Bd= true; } else { if (trace(1)) @@ -3258,21 +3260,21 @@ const COND *ha_connect::cond_push(const COND *cond) PCFIL filp; int rc; - if ((filp = tdbp->GetCondFil()) && tdbp->GetCond() == cond && + if ((filp= tdbp->GetCondFil()) && tdbp->GetCond() == cond && filp->Idx == active_index && filp->Type == tty) goto fin; - filp = new(g) CONDFIL(active_index, tty); - rc = filp->Init(g, this); + filp= new(g) CONDFIL(active_index, tty); + rc= filp->Init(g, this); if (rc == RC_INFO) { - filp->Having = (char*)PlugSubAlloc(g, NULL, 256); - *filp->Having = 0; + filp->Having= (char*)PlugSubAlloc(g, NULL, 256); + *filp->Having= 0; } else if (rc == RC_FX) goto fin; - filp->Body = (char*)PlugSubAlloc(g, NULL, (x) ? 128 : 0); - *filp->Body = 0; + filp->Body= (char*)PlugSubAlloc(g, NULL, (x) ? 128 : 0); + *filp->Body= 0; if (CheckCond(g, filp, cond)) { if (filp->Having && strlen(filp->Having) > 255) @@ -3286,7 +3288,7 @@ const COND *ha_connect::cond_push(const COND *cond) if (!x) PlugSubAlloc(g, NULL, strlen(filp->Body) + 1); else - cond = NULL; // Does this work? + cond= NULL; // Does this work? tdbp->SetCondFil(filp); } else if (x && cond) @@ -3336,8 +3338,8 @@ ha_rows ha_connect::records() int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt) { - int rc = HA_ADMIN_OK; - PGLOBAL g = ((table && table->in_use) ? GetPlug(table->in_use, xp) : + int rc= HA_ADMIN_OK; + PGLOBAL g= ((table && table->in_use) ? GetPlug(table->in_use, xp) : (xp) ? xp->g : NULL); DBUG_ENTER("ha_connect::check"); @@ -3347,32 +3349,32 @@ int ha_connect::check(THD* thd, HA_CHECK_OPT* check_opt) // Do not close the table if it was opened yet (possible?) if (IsOpened()) { if (IsPartitioned() && CheckColumnList(g)) // map can have been changed - rc = HA_ADMIN_CORRUPT; + rc= HA_ADMIN_CORRUPT; else if (tdbp->OpenDB(g)) // Rewind table - rc = HA_ADMIN_CORRUPT; + rc= HA_ADMIN_CORRUPT; } else if (xp->CheckQuery(valid_query_id)) { - tdbp = NULL; // Not valid anymore + tdbp= NULL; // Not valid anymore if (OpenTable(g, false)) - rc = HA_ADMIN_CORRUPT; + rc= HA_ADMIN_CORRUPT; } else // possible? DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR); if (rc == HA_ADMIN_OK) { - TABTYPE type = GetTypeID(GetStringOption("Type", "*")); + TABTYPE type= GetTypeID(GetStringOption("Type", "*")); if (IsFileType(type)) { if (check_opt->flags & T_MEDIUM) { // TO DO do { - if ((rc = CntReadNext(g, tdbp)) == RC_FX) + if ((rc= CntReadNext(g, tdbp)) == RC_FX) break; } while (rc != RC_EF); - rc = (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT; + rc= (rc == RC_EF) ? HA_ADMIN_OK : HA_ADMIN_CORRUPT; } else if (check_opt->flags & T_EXTEND) { // TO DO } // endif's flags @@ -3400,7 +3402,7 @@ bool ha_connect::get_error_message(int error, String* buf) DBUG_ENTER("ha_connect::get_error_message"); if (xp && xp->g) { - PGLOBAL g = xp->g; + PGLOBAL g= xp->g; if (trace(1)) htrc("GEM(%d): %s\n", error, g->Message); @@ -3509,32 +3511,32 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT*) try { // Ignore error on the opt file dup->Check &= ~CHK_OPT; - tdbp = GetTDB(g); + tdbp= GetTDB(g); dup->Check |= CHK_OPT; if (tdbp && !tdbp->IsRemote()) { - bool dop = IsTypeIndexable(GetRealType(NULL)); - bool dox = (tdbp->GetDef()->Indexable() == 1); + bool dop= IsTypeIndexable(GetRealType(NULL)); + bool dox= (tdbp->GetDef()->Indexable() == 1); - if ((rc = ((PTDBASE)tdbp)->ResetTableOpt(g, dop, dox))) { + if ((rc= ((PTDBASE)tdbp)->ResetTableOpt(g, dop, dox))) { if (rc == RC_INFO) { push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); - rc = 0; + rc= 0; } else - rc = HA_ERR_CRASHED_ON_USAGE; // Table must be repaired + rc= HA_ERR_CRASHED_ON_USAGE; // Table must be repaired } // endif rc } else if (!tdbp) - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } catch (int n) { if (trace(1)) htrc("Exception %d: %s\n", n, g->Message); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } catch (const char *msg) { strcpy(g->Message, msg); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } // end catch if (rc) @@ -4234,7 +4236,7 @@ int ha_connect::rnd_pos(uchar *buf, uchar *pos) tdbp->SetFilter(NULL); rc= rnd_next(buf); } else { - PGLOBAL g = GetPlug((table) ? table->in_use : NULL, xp); + PGLOBAL g= GetPlug((table) ? table->in_use : NULL, xp); // strcpy(g->Message, "Not supported by this table type"); my_message(ER_ILLEGAL_HA, g->Message, MYF(0)); rc= HA_ERR_INTERNAL_ERROR; @@ -4318,12 +4320,12 @@ int ha_connect::info(uint flag) } else DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen - if (!(tdbp = GetTDB(g))) { + if (!(tdbp= GetTDB(g))) { my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); DBUG_RETURN(HA_ERR_INTERNAL_ERROR); } // endif tdbp - valid_info = false; + valid_info= false; } // endif tdbp if (!valid_info) { @@ -4603,13 +4605,13 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, // newmode= MODE_UPDATE; // To be checked // break; case SQLCOM_DELETE_MULTI: - *cras = true; + *cras= true; case SQLCOM_DELETE: case SQLCOM_TRUNCATE: newmode= MODE_DELETE; break; case SQLCOM_UPDATE_MULTI: - *cras = true; + *cras= true; case SQLCOM_UPDATE: newmode= MODE_UPDATE; break; @@ -4637,7 +4639,7 @@ MODE ha_connect::CheckMode(PGLOBAL g, THD *thd, break; // } // endif partitioned case SQLCOM_REPAIR: // TODO implement it - newmode = MODE_UPDATE; + newmode= MODE_UPDATE; break; default: htrc("Unsupported sql_command=%d\n", thd_sql_command(thd)); @@ -4836,7 +4838,7 @@ int ha_connect::external_lock(THD *thd, int lock_type) DBUG_RETURN(0); } else if (g->Xchk) { if (!tdbp) { - if (!(tdbp = GetTDB(g))) { + if (!(tdbp= GetTDB(g))) { // DBUG_RETURN(HA_ERR_INTERNAL_ERROR); causes assert error push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); DBUG_RETURN(0); @@ -5060,7 +5062,7 @@ THR_LOCK_DATA **ha_connect::store_lock(THD *, { if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK) lock.type=lock_type; - *to++ = &lock; + *to++= &lock; return to; } @@ -5337,7 +5339,7 @@ static bool add_field(String *sql, const char *field_name, int typ, int len, int dec, char *key, uint tm, const char *rem, char *dft, char *xtra, char *fmt, int flag, bool dbf, char v) { - char var = (len > 255) ? 'V' : v; + char var= (len > 255) ? 'V' : v; bool q, error= false; const char *type= PLGtoMYSQLtype(typ, dbf, var); @@ -5381,9 +5383,9 @@ static bool add_field(String *sql, const char *field_name, int typ, int len, error|= sql->append(" DEFAULT "); if (typ == TYPE_DATE) - q = (strspn(dft, "0123456789 -:/") == strlen(dft)); + q= (strspn(dft, "0123456789 -:/") == strlen(dft)); else - q = !IsTypeNum(typ); + q= !IsTypeNum(typ); if (q) { error|= sql->append("'"); @@ -5540,8 +5542,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, PCSZ nsp= NULL, cls= NULL; #endif // __WIN__ //int hdr, mxe; - int port = 0, mxr = 0, rc = 0, mul = 0, lrecl = 0; -//PCSZ tabtyp = NULL; + int port= 0, mxr= 0, rc= 0, mul= 0, lrecl= 0; +//PCSZ tabtyp= NULL; #if defined(ODBC_SUPPORT) POPARM sop= NULL; PCSZ ucnc= NULL; @@ -5605,7 +5607,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #endif // __WIN__ port= atoi(GetListOption(g, "port", topt->oplist, "0")); #if defined(ODBC_SUPPORT) -// tabtyp = GetListOption(g, "Tabtype", topt->oplist, NULL); +// tabtyp= GetListOption(g, "Tabtype", topt->oplist, NULL); mxr= atoi(GetListOption(g,"maxres", topt->oplist, "0")); cto= atoi(GetListOption(g,"ConnectTimeout", topt->oplist, "-1")); qto= atoi(GetListOption(g,"QueryTimeout", topt->oplist, "-1")); @@ -5622,9 +5624,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(ZIP_SUPPORT) zfn= GetListOption(g, "Zipfile", topt->oplist, NULL); #endif // ZIP_SUPPORT - } - else - { + } else { host= "localhost"; user= ((ttp == TAB_ODBC || ttp == TAB_JDBC) ? NULL : "root"); } // endif option_list @@ -5639,8 +5639,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, ttp= GetTypeID(topt->type); sprintf(g->Message, "No table_type. Was set to %s", topt->type); push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message); - } - else if (ttp == TAB_NIY) { + } else if (ttp == TAB_NIY) { sprintf(g->Message, "Unsupported table type %s", topt->type); rc= HA_ERR_INTERNAL_ERROR; goto err; @@ -5693,7 +5692,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, #if defined(PROMPT_OK) } else if (!stricmp(thd->main_security_ctx.host, "localhost") && cop == 1) { - if ((dsn = ODBCCheckConnection(g, dsn, cop)) != NULL) { + if ((dsn= ODBCCheckConnection(g, dsn, cop)) != NULL) { thd->make_lex_string(&create_info->connect_string, dsn, strlen(dsn)); ok= true; } // endif dsn @@ -5729,7 +5728,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, jdef->SetName(create_info->alias.str); sjp= (PJPARM)PlugSubAlloc(g, NULL, sizeof(JDBCPARM)); sjp->Driver= driver; - // sjp->Properties = prop; + // sjp->Properties= prop; sjp->Fsize= 0; sjp->Scrollable= false; @@ -6027,7 +6026,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd, if (fnc != FNC_NO || src || ttp == TAB_PIVOT) { // Catalog like table - for (crp = qrp->Colresp; !rc && crp; crp = crp->Next) { + for (crp= qrp->Colresp; !rc && crp; crp= crp->Next) { cnm= (ttp == TAB_PIVOT) ? crp->Name : encode(g, crp->Name); typ= crp->Type; len= crp->Length; @@ -6060,8 +6059,8 @@ static int connect_assisted_discovery(handlerton *, THD* thd, goto err; } // endif !nblin - for (i = 0; !rc && i < qrp->Nblin; i++) { - typ= len = prec = dec = 0; + for (i= 0; !rc && i < qrp->Nblin; i++) { + typ= len= prec= dec= 0; tm= NOT_NULL_FLAG; cnm= (char*)"noname"; dft= xtra= key= fmt= tn= NULL; @@ -6449,7 +6448,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, host= mydef->GetHostname(); if (mydef->GetTabschema()) - db = mydef->GetTabschema(); + db= mydef->GetTabschema(); if (mydef->GetTabname()) tab= mydef->GetTabname(); @@ -6532,7 +6531,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, } // endif type JSON if (type == TAB_CSV) { - const char *sep = options->separator; + const char *sep= options->separator; if (sep && strlen(sep) > 1) { sprintf(g->Message, "Invalid separator %s", sep); @@ -6732,16 +6731,17 @@ int ha_connect::create(const char *name, TABLE *table_arg, htrc("xchk=%p createas=%d\n", g->Xchk, g->Createas); if (options->zipped) { +#if defined(ZIP_SUPPORT) // Check whether the zip entry must be made from a file - PCSZ fn = GetListOption(g, "Load", options->oplist, NULL); + PCSZ fn= GetListOption(g, "Load", options->oplist, NULL); if (fn) { char zbuf[_MAX_PATH], buf[_MAX_PATH], dbpath[_MAX_PATH]; - PCSZ entry = GetListOption(g, "Entry", options->oplist, NULL); - PCSZ a = GetListOption(g, "Append", options->oplist, "NO"); - bool append = *a == '1' || *a == 'Y' || *a == 'y' || !stricmp(a, "ON"); - PCSZ m = GetListOption(g, "Mulentries", options->oplist, "NO"); - bool mul = *m == '1' || *m == 'Y' || *m == 'y' || !stricmp(m, "ON"); + PCSZ entry= GetListOption(g, "Entry", options->oplist, NULL); + PCSZ a= GetListOption(g, "Append", options->oplist, "NO"); + bool append= *a == '1' || *a == 'Y' || *a == 'y' || !stricmp(a, "ON"); + PCSZ m= GetListOption(g, "Mulentries", options->oplist, "NO"); + bool mul= *m == '1' || *m == 'Y' || *m == 'y' || !stricmp(m, "ON"); if (!entry && !mul) { my_message(ER_UNKNOWN_ERROR, "Missing entry name", MYF(0)); @@ -6758,7 +6758,10 @@ int ha_connect::create(const char *name, TABLE *table_arg, } // endif LoadFile } // endif fn - +#else // !ZIP_SUPPORT + my_message(ER_UNKNOWN_ERROR, "Option ZIP not supported", MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); +#endif // !ZIP_SUPPORT } // endif zipped // To check whether indexes have to be made or remade @@ -6809,7 +6812,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, if (SetDataPath(g, table_arg->s->db.str)) { my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); - rc = HA_ERR_INTERNAL_ERROR; + rc= HA_ERR_INTERNAL_ERROR; } else if (cat) { if (part_info) strncpy(partname, @@ -7153,7 +7156,7 @@ ha_connect::check_if_supported_inplace_alter(TABLE *altered_table, /* ALTER TABLE tbl_name CONVERT TO CHARACTER SET .. and - ALTER TABLE table_name DEFAULT CHARSET = .. most likely + ALTER TABLE table_name DEFAULT CHARSET= .. most likely change column charsets and so not supported in-place through old API. diff --git a/storage/connect/mini-global.h b/storage/connect/mini-global.h new file mode 100644 index 00000000000..f712795827c --- /dev/null +++ b/storage/connect/mini-global.h @@ -0,0 +1,33 @@ +/***********************************************************************/ +/* Definitions needed by the included files. */ +/***********************************************************************/ +#if !defined(MY_GLOBAL_H) +#define MY_GLOBAL_H +typedef unsigned int uint; +typedef unsigned int uint32; +typedef unsigned short ushort; +typedef unsigned long ulong; +typedef unsigned long DWORD; +typedef char *LPSTR; +typedef const char *LPCSTR; +typedef int BOOL; +#if defined(_WINDOWS) +typedef void *HANDLE; +#else +typedef int HANDLE; +#endif +typedef char *PSZ; +typedef const char *PCSZ; +typedef unsigned char BYTE; +typedef unsigned char uchar; +typedef long long longlong; +typedef unsigned long long ulonglong; +typedef char my_bool; +struct charset_info_st {}; +typedef const charset_info_st CHARSET_INFO; +#define FALSE 0 +#define TRUE 1 +#define Item char +#define MY_MAX(a,b) ((a>b)?(a):(b)) +#define MY_MIN(a,b) ((aGetName(), SVP(type)); +{ + PRELDEF tdp= NULL; - // If not specified get the type of this table + if (trace(1)) + htrc("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type)); + + // If not specified get the type of this table //if (!type) // type= Hc->GetStringOption("Type","*"); - return MakeTableDesc(g, tablep, type); - } // end of GetTableDesc + tdp= MakeTableDesc(g, tablep, type); + + if (trace(1)) + htrc("GetTableDesc: tdp=%p\n", tdp); + + return tdp; +} // end of GetTableDesc /***********************************************************************/ /* MakeTableDesc: make a table/view description. */ @@ -503,22 +510,22 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep, PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) { TABTYPE tc; - LPCSTR name= (PSZ)PlugDup(g, tablep->GetName()); - LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema()); + LPCSTR name= (PSZ)PlugDup(g, tablep->GetName()); + LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema()); PRELDEF tdp= NULL; - if (trace(1)) - printf("MakeTableDesc: name=%s schema=%s am=%s\n", - name, SVP(schema), SVP(am)); + if (trace(1)) + htrc("MakeTableDesc: name=%s schema=%s am=%s\n", + name, SVP(schema), SVP(am)); /*********************************************************************/ /* Get a unique enum identifier for types. */ /*********************************************************************/ - if (!am) { - tc= Hc->GetRealType(); - am= Hc->GetStringOption("Type","*"); - } else - tc= GetTypeID(am); + if (!am) { + tc= Hc->GetRealType(); + am= Hc->GetStringOption("Type","*"); + } else + tc= GetTypeID(am); switch (tc) { case TAB_FIX: @@ -533,49 +540,52 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am) case TAB_XML: tdp= new(g) XMLDEF; break; #endif // XML_SUPPORT #if defined(VCT_SUPPORT) - case TAB_VEC: tdp = new(g) VCTDEF; break; + case TAB_VEC: tdp = new(g) VCTDEF; break; #endif // VCT_SUPPORT #if defined(ODBC_SUPPORT) case TAB_ODBC: tdp= new(g) ODBCDEF; break; #endif // ODBC_SUPPORT #if defined(JAVA_SUPPORT) - case TAB_JDBC: tdp= new(g) JDBCDEF; break; + case TAB_JDBC: tdp= new(g) JDBCDEF; break; #endif // JAVA_SUPPORT #if defined(__WIN__) case TAB_MAC: tdp= new(g) MACDEF; break; case TAB_WMI: tdp= new(g) WMIDEF; break; #endif // __WIN__ case TAB_OEM: tdp= new(g) OEMDEF; break; - case TAB_TBL: tdp= new(g) TBLDEF; break; - case TAB_XCL: tdp= new(g) XCLDEF; break; - case TAB_PRX: tdp= new(g) PRXDEF; break; - case TAB_OCCUR: tdp= new(g) OCCURDEF; break; - case TAB_MYSQL: tdp= new(g) MYSQLDEF; break; + case TAB_TBL: tdp= new(g) TBLDEF; break; + case TAB_XCL: tdp= new(g) XCLDEF; break; + case TAB_PRX: tdp= new(g) PRXDEF; break; + case TAB_OCCUR: tdp= new(g) OCCURDEF; break; + case TAB_MYSQL: tdp= new(g) MYSQLDEF; break; case TAB_PIVOT: tdp= new(g) PIVOTDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_JSON: tdp= new(g) JSONDEF; break; #if defined(ZIP_SUPPORT) - case TAB_ZIP: tdp = new(g) ZIPDEF; break; + case TAB_ZIP: tdp = new(g) ZIPDEF; break; #endif // ZIP_SUPPORT #if defined(REST_SUPPORT) case TAB_REST: tdp= new (g) RESTDEF; break; #endif // REST_SUPPORT #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) - case TAB_MONGO: - if (MongoEnabled()) { - tdp = new(g) MGODEF; - break; - } // endif enabled - // fall through + case TAB_MONGO: + if (MongoEnabled()) { + tdp = new(g) MGODEF; + break; + } // endif enabled + // fall through #endif // JAVA_SUPPORT || CMGO_SUPPORT - default: - sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); + default: + sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); } // endswitch // Do make the table/view definition if (tdp && tdp->Define(g, this, name, schema, am)) tdp= NULL; + if (trace(1)) + htrc("Table %s made\n", am); + return tdp; } // end of MakeTableDesc @@ -588,26 +598,29 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type) PTDB tdbp= NULL; // LPCSTR name= tablep->GetName(); - if (trace(1)) - printf("GetTableDB: name=%s\n", tablep->GetName()); + if (trace(1)) + htrc("GetTableDB: name=%s\n", tablep->GetName()); // Look for the description of the requested table tdp= GetTableDesc(g, tablep, type); if (tdp) { - if (trace(1)) - printf("tdb=%p type=%s\n", tdp, tdp->GetType()); + if (trace(1)) + htrc("tdb=%p type=%s\n", tdp, tdp->GetType()); + + if (tablep->GetSchema()) + tdp->Database = SetPath(g, tablep->GetSchema()); + + if (trace(2)) + htrc("Going to get table...\n"); - if (tablep->GetSchema()) - tdp->Database = SetPath(g, tablep->GetSchema()); - tdbp= tdp->GetTable(g, mode); - } // endif tdp + } // endif tdp if (tdbp) { - if (trace(1)) - printf("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(), - tdbp->GetAmType()); + if (trace(1)) + htrc("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(), + tdbp->GetAmType()); tablep->SetTo_Tdb(tdbp); tdbp->SetTable(tablep); tdbp->SetMode(mode); diff --git a/storage/connect/mysql-test/connect/r/dir.result b/storage/connect/mysql-test/connect/r/dir.result index e10bb458d62..139544b99e9 100644 --- a/storage/connect/mysql-test/connect/r/dir.result +++ b/storage/connect/mysql-test/connect/r/dir.result @@ -26,7 +26,7 @@ fname ftype size boys .txt 282 boyswin .txt 288 INSERT INTO t1 VALUES ('','','',''); -ERROR 22007: Incorrect double value: '' for column 'size' at row 1 +ERROR 22007: Incorrect double value: '' for column `test`.`t1`.`size` at row 1 DROP TABLE t1; CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=DIR FILE_NAME='*.txt'; ERROR HY000: Cannot get column info for table type DIR diff --git a/storage/connect/mysql-test/connect/r/xml.result b/storage/connect/mysql-test/connect/r/xml.result index 055a9d18e12..6a0c9db27b3 100644 --- a/storage/connect/mysql-test/connect/r/xml.result +++ b/storage/connect/mysql-test/connect/r/xml.result @@ -158,47 +158,47 @@ TRANSLATOR NULL PUBLISHER Eyrolles Paris DATEPUB 1998 SELECT LOAD_FILE('MYSQLD_DATADIR/test/xsample2.xml') AS xml; -xml - - - - Jean-Christophe - Bernadac - - - François - Knab - - Construire une application XML - - Eyrolles - Paris - - 1999 - - - - William J. - Pardi - - - James - Guerin - - XML en Action - - Microsoft Press - Paris - - 1999 - - - Alain Michard - XML, Langage et Applications - Eyrolles Paris - 1998 - - +xml + + + + Jean-Christophe + Bernadac + + + François + Knab + + Construire une application XML + + Eyrolles + Paris + + 1999 + + + + William J. + Pardi + + + James + Guerin + + XML en Action + + Microsoft Press + Paris + + 1999 + + + Alain Michard + XML, Langage et Applications + Eyrolles Paris + 1998 + + DROP TABLE t1; # @@ -323,7 +323,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 @@ -374,7 +374,7 @@ INSERT INTO t1 VALUES (_cp1251 0xC0C1C2C3); Warnings: Level Warning Code 1105 -Message Com error: Unable to save character to 'iso-8859-1' encoding. +Message Com error: Unable to save character to 'iso-8859-1' encoding. INSERT INTO t1 VALUES ('&<>"\''); SELECT node, hex(node) FROM t1; @@ -383,11 +383,11 @@ hex(node) 263C3E2227 DROP TABLE t1; SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml'); SELECT CAST(@a AS CHAR CHARACTER SET latin1); -CAST(@a AS CHAR CHARACTER SET latin1) - - - - &<>"' - - +CAST(@a AS CHAR CHARACTER SET latin1) + + + + &<>"' + + diff --git a/storage/connect/mysql-test/connect/r/xml2.result b/storage/connect/mysql-test/connect/r/xml2.result index b8075fa1928..f7bbc17c8a0 100644 --- a/storage/connect/mysql-test/connect/r/xml2.result +++ b/storage/connect/mysql-test/connect/r/xml2.result @@ -325,7 +325,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 diff --git a/storage/connect/osutil.h b/storage/connect/osutil.h index 7e6b8823b9b..380e7bebb22 100644 --- a/storage/connect/osutil.h +++ b/storage/connect/osutil.h @@ -3,7 +3,11 @@ #define __OSUTIL_H__ #if defined(UNIX) || defined(UNIV_LINUX) +#if defined(MARIADB) #include "my_global.h" +#else +#include "mini-global.h" +#endif #include #include #include "os.h" diff --git a/storage/connect/plugutil.cpp b/storage/connect/plugutil.cpp index 6790e7eb45c..e74937b942a 100644 --- a/storage/connect/plugutil.cpp +++ b/storage/connect/plugutil.cpp @@ -2,11 +2,11 @@ /* */ /* PROGRAM NAME: PLUGUTIL */ /* ------------- */ -/* Version 3.0 */ +/* Version 3.1 */ /* */ /* COPYRIGHT: */ /* ---------- */ -/* (C) Copyright to the author Olivier BERTRAND 1993-2017 */ +/* (C) Copyright to the author Olivier BERTRAND 1993-2019 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ @@ -111,21 +111,31 @@ ACTIVITY defActivity = { /* Describes activity and language */ #endif // UNIX /**************************************************************************/ -/* Tracing output function. */ +/* Conditional tracing output function. */ /**************************************************************************/ -void htrc(char const *fmt, ...) - { - va_list ap; - va_start (ap, fmt); +void xtrc(uint x, char const *fmt, ...) +{ + if (GetTraceValue() & x) { + va_list ap; + va_start(ap, fmt); + + vfprintf(stderr, fmt, ap); + va_end(ap); + } // endif x +} // end of xtrc -//if (trace == 1) -// vfprintf(debug, fmt, ap); -//else - vfprintf(stderr, fmt, ap); +/**************************************************************************/ +/* Tracing output function. */ +/**************************************************************************/ +void htrc(char const* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); - va_end (ap); - } // end of htrc + vfprintf(stderr, fmt, ap); + va_end(ap); +} // end of htrc /***********************************************************************/ /* Plug initialization routine. */ diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index 30d8063d1a6..8ba8aac3621 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -81,51 +81,51 @@ RELDEF::RELDEF(void) /* This function return a pointer to the Table Option Struct. */ /***********************************************************************/ PTOS RELDEF::GetTopt(void) - { - return Hc->GetTableOptionStruct(); - } // end of GetTopt + { + return Hc->GetTableOptionStruct(); + } // end of GetTopt /***********************************************************************/ /* This function sets an integer table information. */ /***********************************************************************/ bool RELDEF::SetIntCatInfo(PCSZ what, int n) - { - return Hc->SetIntegerOption(what, n); - } // end of SetIntCatInfo + { + return Hc->SetIntegerOption(what, n); + } // end of SetIntCatInfo /***********************************************************************/ /* This function returns integer table information. */ /***********************************************************************/ int RELDEF::GetIntCatInfo(PCSZ what, int idef) - { - int n= Hc->GetIntegerOption(what); + { + int n= Hc->GetIntegerOption(what); - return (n == NO_IVAL) ? idef : n; - } // end of GetIntCatInfo + return (n == NO_IVAL) ? idef : n; + } // end of GetIntCatInfo /***********************************************************************/ /* This function returns Boolean table information. */ /***********************************************************************/ bool RELDEF::GetBoolCatInfo(PCSZ what, bool bdef) - { - bool b= Hc->GetBooleanOption(what, bdef); + { + bool b= Hc->GetBooleanOption(what, bdef); - return b; - } // end of GetBoolCatInfo + return b; + } // end of GetBoolCatInfo /***********************************************************************/ /* This function returns size catalog information. */ /***********************************************************************/ int RELDEF::GetSizeCatInfo(PCSZ what, PCSZ sdef) - { - char c; - PCSZ s; + { + char c; + PCSZ s; int i, n= 0; - if (!(s= Hc->GetStringOption(what))) - s= sdef; + if (!(s= Hc->GetStringOption(what))) + s= sdef; - if ((i= sscanf(s, " %d %c ", &n, &c)) == 2) + if ((i= sscanf(s, " %d %c ", &n, &c)) == 2) switch (toupper(c)) { case 'M': n *= 1024; @@ -141,41 +141,41 @@ int RELDEF::GetSizeCatInfo(PCSZ what, PCSZ sdef) /* This function sets char table information in buf. */ /***********************************************************************/ int RELDEF::GetCharCatInfo(PCSZ what, PCSZ sdef, char *buf, int size) - { - PCSZ s= Hc->GetStringOption(what); + { + PCSZ s= Hc->GetStringOption(what); - strncpy(buf, ((s) ? s : sdef), size); - return size; - } // end of GetCharCatInfo + strncpy(buf, ((s) ? s : sdef), size); + return size; + } // end of GetCharCatInfo /***********************************************************************/ /* To be used by any TDB's. */ /***********************************************************************/ bool RELDEF::Partitioned(void) - { - return Hc->IsPartitioned(); - } // end of Partitioned + { + return Hc->IsPartitioned(); + } // end of Partitioned /***********************************************************************/ /* This function returns string table information. */ /* Default parameter is "*" to get the handler default. */ /***********************************************************************/ char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef) - { - char *sval = NULL; - PCSZ name, s= Hc->GetStringOption(what, sdef); - - if (s) { + { + char *sval = NULL; + PCSZ name, s= Hc->GetStringOption(what, sdef); + + if (s) { if (!Hc->IsPartitioned() || (stricmp(what, "filename") && stricmp(what, "tabname") && stricmp(what, "connect"))) - sval= PlugDup(g, s); + sval= PlugDup(g, s); else sval= (char*)s; } else if (!stricmp(what, "filename")) { // Return default file name - PCSZ ftype= Hc->GetStringOption("Type", "*"); + PCSZ ftype= Hc->GetStringOption("Type", "*"); int i, n; if (IsFileType(GetTypeID(ftype))) { @@ -183,7 +183,7 @@ char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef) sval= (char*)PlugSubAlloc(g, NULL, strlen(name) + 12); strcat(strcpy(sval, name), "."); n= strlen(sval); - + // Fold ftype to lower case for (i= 0; i < 12; i++) if (!ftype[i]) { @@ -196,8 +196,8 @@ char *RELDEF::GetStringCatInfo(PGLOBAL g, PCSZ what, PCSZ sdef) } // endif s - return sval; - } // end of GetStringCatInfo + return sval; + } // end of GetStringCatInfo /* --------------------------- Class TABDEF -------------------------- */ @@ -223,14 +223,14 @@ TABDEF::TABDEF(void) /***********************************************************************/ /* Define: initialize the table definition block from XDB file. */ /***********************************************************************/ -bool TABDEF::Define(PGLOBAL g, PCATLG cat, - LPCSTR name, LPCSTR schema, LPCSTR am) +bool TABDEF::Define(PGLOBAL g, PCATLG cat, + LPCSTR name, LPCSTR schema, LPCSTR am) { int poff = 0; - Hc = ((MYCAT*)cat)->GetHandler(); - Name = (PSZ)name; - Schema = (PSZ)Hc->GetDBName(schema); + Hc = ((MYCAT*)cat)->GetHandler(); + Name = (PSZ)name; + Schema = (PSZ)Hc->GetDBName(schema); Cat = cat; Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL)); Elemt = GetIntCatInfo("Elements", 0); @@ -263,14 +263,14 @@ PCSZ TABDEF::GetPath(void) /* This function returns column table information. */ /***********************************************************************/ int TABDEF::GetColCatInfo(PGLOBAL g) - { - char *type= GetStringCatInfo(g, "Type", "*"); + { + char *type= GetStringCatInfo(g, "Type", "*"); char c, fty, eds; - int i, n, loff, poff, nof, nlg; - void *field= NULL; + int i, n, loff, poff, nof, nlg; + void *field= NULL; TABTYPE tc; PCOLDEF cdp, lcdp= NULL, tocols= NULL; - PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO)); + PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO)); memset(pcf, 0, sizeof(COLINFO)); @@ -278,33 +278,33 @@ int TABDEF::GetColCatInfo(PGLOBAL g) tc= (Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX; // Take care of the column definitions - i= poff= nof= nlg= 0; + i= poff= nof= nlg= 0; #if defined(__WIN__) - // Offsets of HTML and DIR tables start from 0, DBF at 1 - loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0; + // Offsets of HTML and DIR tables start from 0, DBF at 1 + loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0; #else // !__WIN__ - // Offsets of HTML tables start from 0, DIR and DBF at 1 - loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0; + // Offsets of HTML tables start from 0, DIR and DBF at 1 + loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0; #endif // !__WIN__ while (true) { - // Default Offset depends on table type - switch (tc) { + // Default Offset depends on table type + switch (tc) { case TAB_DOS: case TAB_FIX: case TAB_BIN: case TAB_VEC: case TAB_DBF: - poff= loff + nof; // Default next offset - nlg= MY_MAX(nlg, poff); // Default lrecl + poff= loff + nof; // Default next offset + nlg= MY_MAX(nlg, poff); // Default lrecl break; case TAB_CSV: case TAB_FMT: - nlg+= nof; + nlg+= nof; case TAB_DIR: case TAB_XML: - poff= loff + (pcf->Flags & U_VIRTUAL ? 0 : 1); + poff= loff + (pcf->Flags & U_VIRTUAL ? 0 : 1); break; case TAB_INI: case TAB_MAC: @@ -316,39 +316,39 @@ int TABDEF::GetColCatInfo(PGLOBAL g) poff = 0; // Offset represents an independant flag break; default: // VCT PLG ODBC JDBC MYSQL WMI... - poff = 0; // NA + poff = 0; // NA break; - } // endswitch tc + } // endswitch tc -// do { - field= Hc->GetColumnOption(g, field, pcf); +// do { + field= Hc->GetColumnOption(g, field, pcf); // } while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/)); - if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) { - // DBF date format defaults to 'YYYMMDD' - pcf->Datefmt= "YYYYMMDD"; - pcf->Length= 8; - } // endif tc + if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) { + // DBF date format defaults to 'YYYMMDD' + pcf->Datefmt= "YYYYMMDD"; + pcf->Length= 8; + } // endif tc - if (!field) - break; + if (!field) + break; // Allocate the column description block cdp= new(g) COLDEF; if ((nof= cdp->Define(g, NULL, pcf, poff)) < 0) - return -1; // Error, probably unhandled type - else - loff= cdp->GetOffset(); - - switch (tc) { - case TAB_VEC: - cdp->SetOffset(0); // Not to have shift - case TAB_BIN: - // BIN/VEC are packed by default + return -1; // Error, probably unhandled type + else + loff= cdp->GetOffset(); + + switch (tc) { + case TAB_VEC: + cdp->SetOffset(0); // Not to have shift + case TAB_BIN: + // BIN/VEC are packed by default if (nof) { - // Field width is the internal representation width - // that can also depend on the column format + // Field width is the internal representation width + // that can also depend on the column format fty = cdp->Decode ? 'C' : 'X'; eds = 0; n = 0; @@ -371,38 +371,38 @@ int TABDEF::GetColCatInfo(PGLOBAL g) if (n) nof = n; else switch (fty) { - case 'X': + case 'X': if (eds && IsTypeChar(cdp->Buf_Type)) nof = sizeof(longlong); else nof= cdp->Clen; break; - case 'C': break; - case 'R': - case 'F': nof = sizeof(float); break; - case 'I': nof = sizeof(int); break; - case 'D': nof = sizeof(double); break; - case 'S': nof = sizeof(short); break; - case 'T': nof = sizeof(char); break; - case 'G': nof = sizeof(longlong); break; - default: /* Wrong format */ + case 'C': break; + case 'R': + case 'F': nof = sizeof(float); break; + case 'I': nof = sizeof(int); break; + case 'D': nof = sizeof(double); break; + case 'S': nof = sizeof(short); break; + case 'T': nof = sizeof(char); break; + case 'G': nof = sizeof(longlong); break; + default: /* Wrong format */ sprintf(g->Message, "Invalid format %c", fty); return -1; - } // endswitch fty + } // endswitch fty } // endif nof default: - break; - } // endswitch tc + break; + } // endswitch tc - if (lcdp) - lcdp->SetNext(cdp); - else - tocols= cdp; + if (lcdp) + lcdp->SetNext(cdp); + else + tocols= cdp; - lcdp= cdp; + lcdp= cdp; i++; } // endwhile @@ -410,31 +410,31 @@ int TABDEF::GetColCatInfo(PGLOBAL g) if (i != GetDegree()) SetDegree(i); - if (GetDefType() == TYPE_AM_DOS) { - int ending, recln= 0; + if (GetDefType() == TYPE_AM_DOS) { + int ending, recln= 0; - // Was commented because sometimes ending is 0 even when - // not specified (for instance if quoted is specified) -// if ((ending= Hc->GetIntegerOption("Ending")) < 0) { - if ((ending= Hc->GetIntegerOption("Ending")) <= 0) { + // Was commented because sometimes ending is 0 even when + // not specified (for instance if quoted is specified) +// if ((ending= Hc->GetIntegerOption("Ending")) < 0) { + if ((ending= Hc->GetIntegerOption("Ending")) <= 0) { ending= (tc == TAB_BIN || tc == TAB_VEC) ? 0 : CRLF; - Hc->SetIntegerOption("Ending", ending); - } // endif ending + Hc->SetIntegerOption("Ending", ending); + } // endif ending - // Calculate the default record size - switch (tc) { + // Calculate the default record size + switch (tc) { case TAB_FIX: case TAB_BIN: recln= nlg + ending; // + length of line ending break; case TAB_VEC: recln= nlg; - + // if ((k= (pak < 0) ? 8 : pak) > 1) // See above for detailed comment // Round up lrecl to multiple of 8 or pak // recln= ((recln + k - 1) / k) * k; - + break; case TAB_DOS: case TAB_DBF: @@ -443,26 +443,30 @@ int TABDEF::GetColCatInfo(PGLOBAL g) case TAB_CSV: case TAB_FMT: // The number of separators (assuming an extra one can exist) -// recln= poff * ((qotd) ? 3 : 1); to be investigated - recln= nlg + poff * 3; // To be safe +// recln= poff * ((qotd) ? 3 : 1); to be investigated + recln= nlg + poff * 3; // To be safe default: break; } // endswitch tc - // lrecl must be at least recln to avoid buffer overflow - if (trace(1)) - htrc("Lrecl: Calculated=%d defined=%d\n", - recln, Hc->GetIntegerOption("Lrecl")); + // lrecl must be at least recln to avoid buffer overflow + if (trace(1)) + htrc("Lrecl: Calculated=%d defined=%d\n", + recln, Hc->GetIntegerOption("Lrecl")); - recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl")); - Hc->SetIntegerOption("Lrecl", recln); - ((PDOSDEF)this)->SetLrecl(recln); - } // endif Lrecl + recln = MY_MAX(recln, Hc->GetIntegerOption("Lrecl")); + Hc->SetIntegerOption("Lrecl", recln); + ((PDOSDEF)this)->SetLrecl(recln); - // Attach the column definition to the tabdef - SetCols(tocols); - return poff; - } // end of GetColCatInfo + if (trace(1)) + htrc("Lrecl set to %d\n", recln); + + } // endif Lrecl + + // Attach the column definition to the tabdef + SetCols(tocols); + return poff; + } // end of GetColCatInfo /***********************************************************************/ /* SetIndexInfo: retrieve index description from the table structure. */ @@ -487,16 +491,17 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) PCATLG cat = Cat; /*********************************************************************/ - /* Ensure that the .dll doesn't have a path. */ - /* This is done to ensure that only approved dll from the system */ + /* Ensure that the module name doesn't have a path. */ + /* This is done to ensure that only approved libs from the system */ /* directories are used (to make this even remotely secure). */ /*********************************************************************/ if (check_valid_path(Module, strlen(Module))) { strcpy(g->Message, "Module cannot contain a path"); return NULL; } else - PlugSetPath(soname, Module, GetPluginDir()); - +// PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora + strncat(strcpy(soname, GetPluginDir()), Module, _MAX_PATH); + #if defined(__WIN__) // Is the DLL already loaded? if (!Hdll && !(Hdll = GetModuleHandle(soname))) @@ -522,31 +527,31 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) // Get the function returning an instance of the external DEF class if (!(getdef = (XGETDEF)GetProcAddress((HINSTANCE)Hdll, getname))) { - char buf[256]; - DWORD rc = GetLastError(); - - sprintf(g->Message, MSG(PROCADD_ERROR), rc, getname); - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0, - (LPTSTR)buf, sizeof(buf), NULL); - strcat(strcat(g->Message, ": "), buf); - FreeLibrary((HMODULE)Hdll); + char buf[256]; + DWORD rc = GetLastError(); + + sprintf(g->Message, MSG(PROCADD_ERROR), rc, getname); + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0, + (LPTSTR)buf, sizeof(buf), NULL); + strcat(strcat(g->Message, ": "), buf); + FreeLibrary((HMODULE)Hdll); return NULL; } // endif getdef #else // !__WIN__ const char *error = NULL; - + #if 0 // Don't know what all this stuff does - Dl_info dl_info; + Dl_info dl_info; - // The OEM lib must retrieve exported CONNECT variables + // The OEM lib must retrieve exported CONNECT variables if (dladdr(&connect_hton, &dl_info)) { if (dlopen(dl_info.dli_fname, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL) == 0) { error = dlerror(); sprintf(g->Message, "dlopen failed: %s, OEM not supported", SVP(error)); return NULL; } // endif dlopen - + } else { error = dlerror(); sprintf(g->Message, "dladdr failed: %s, OEM not supported", SVP(error)); @@ -626,7 +631,7 @@ bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR, int) char *desc = (char*)PlugSubAlloc(g, NULL, strlen(Module) + strlen(Subtype) + 3); sprintf(desc, "%s(%s)", Module, Subtype); - Desc = desc; + Desc = desc; return false; } // end of DefineAM @@ -701,17 +706,17 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode) txfp = new(g) FIXFAM(defp); } else if (rfm == RECFM_VCT) { #if defined(VCT_SUPPORT) - assert(Pxdef->GetDefType() == TYPE_AM_VCT); + assert(Pxdef->GetDefType() == TYPE_AM_VCT); if (map) txfp = new(g) VCMFAM((PVCTDEF)defp); else txfp = new(g) VCTFAM((PVCTDEF)defp); #else // !VCT_SUPPORT - strcpy(g->Message, "VCT no more supported"); - return NULL; + strcpy(g->Message, "VCT no more supported"); + return NULL; #endif // !VCT_SUPPORT - } // endif's + } // endif's ((PTDBDOS)tdbp)->SetTxfp(txfp); } // endif Txfp diff --git a/storage/connect/restget.cpp b/storage/connect/restget.cpp index 955e5f97fbc..6b184ae6926 100644 --- a/storage/connect/restget.cpp +++ b/storage/connect/restget.cpp @@ -7,7 +7,8 @@ #if defined(MARIADB) #include #else -#include "mini_global.h" +#include "mini-global.h" +#define _OS_H_INCLUDED // Prevent os.h to be called #endif using namespace utility::conversions; // String conversions utilities @@ -18,70 +19,76 @@ using namespace concurrency::streams; // Asynchronous streams #include "global.h" - /***********************************************************************/ /* Make a local copy of the requested file. */ /***********************************************************************/ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn) { - int rc= 0; - auto fileStream= std::make_shared(); + int rc = 0; + bool xt = trace(515); + auto fileStream = std::make_shared(); - if (!http || !fn) { - strcpy(g->Message, "Missing http or filename"); - return 2; - } // endif + if (!http || !fn) { + strcpy(g->Message, "Missing http or filename"); + return 2; + } // endif - //std::string sfn(fn); - //auto wfn= to_string_t(sfn); - //rc= 0; + if (xt) + htrc("restGetFile: fn=%s\n", fn); // Open stream to output file. - pplx::task requestTask= - fstream::open_ostream(to_string_t(fn)) - .then([=](ostream outFile) { - *fileStream= outFile; - - // Create http_client to send the request. - http_client client(to_string_t(http)); - - if (uri) - { - // Build request URI and start the request. - uri_builder builder(to_string_t(uri)); - return client.request(methods::GET, builder.to_string()); - } - else - return client.request(methods::GET); - }) - - // Handle response headers arriving. - .then([=](http_response response) { -#if defined(DEVELOPMENT) - fprintf(stderr, "Received response status code:%u\n", - response.status_code()); -#endif // DEVELOPMENT - - // Write response body into the file. - return response.body().read_to_end(fileStream->streambuf()); - }) - - // Close the file stream. - .then([=](size_t) { return fileStream->close(); }); + pplx::task requestTask = fstream::open_ostream(to_string_t(fn)) + .then([=](ostream outFile) { + *fileStream= outFile; + + if (xt) + htrc("Outfile isopen=%d\n", outFile.is_open()); + + // Create http_client to send the request. + http_client client(to_string_t(http)); + + if (uri) { + // Build request URI and start the request. + uri_builder builder(to_string_t(uri)); + return client.request(methods::GET, builder.to_string()); + } else + return client.request(methods::GET); + }) + + // Handle response headers arriving. + .then([=](http_response response) { + if (xt) + htrc("Received response status code:%u\n", + response.status_code()); + + // Write response body into the file. + return response.body().read_to_end(fileStream->streambuf()); + }) + + // Close the file stream. + .then([=](size_t n) { + if (xt) + htrc("Return size=%u\n", n); + + return fileStream->close(); + }); // Wait for all the outstanding I/O to complete and handle any exceptions - try - { + try { requestTask.wait(); - } - catch (const std::exception &e) - { -#if defined(DEVELOPMENT) - fprintf(stderr, "Error exception: %s\n", e.what()); -#endif // DEVELOPMENT - sprintf(g->Message, "Error exception: %s", e.what()); + + if (xt) + htrc("In Wait\n"); + + } catch (const std::exception &e) { + if (xt) + htrc("Error exception: %s\n", e.what()); + sprintf(g->Message, "Error exception: %s", e.what()); rc= 1; } // end try/catch + if (xt) + htrc("restget done: rc=%d\n", rc); + return rc; -} // end of restGetFile \ No newline at end of file +} // end of restGetFile diff --git a/storage/connect/tabfmt.cpp b/storage/connect/tabfmt.cpp index 02720a3089a..746382178fb 100644 --- a/storage/connect/tabfmt.cpp +++ b/storage/connect/tabfmt.cpp @@ -189,9 +189,11 @@ PQRYRES CSVColumns(PGLOBAL g, PCSZ dp, PTOS topt, bool info) htrc("File %s Sep=%c Qot=%c Header=%d maxerr=%d\n", SVP(tdp->Fn), tdp->Sep, tdp->Qot, tdp->Header, tdp->Maxerr); +#if defined(ZIP_SUPPORT) if (tdp->Zipped) tcvp = new(g)TDBCSV(tdp, new(g)UNZFAM(tdp)); else +#endif // ZIP_SUPPORT tcvp = new(g) TDBCSV(tdp, new(g) DOSFAM(tdp)); tcvp->SetMode(MODE_READ); diff --git a/storage/connect/tabjdbc.cpp b/storage/connect/tabjdbc.cpp index 789daff6fcd..06b6b3a9730 100644 --- a/storage/connect/tabjdbc.cpp +++ b/storage/connect/tabjdbc.cpp @@ -641,7 +641,9 @@ bool TDBJDBC::OpenDB(PGLOBAL g) Cnp->InitValue(g); if ((n = Jcp->GetResultSize(Query->GetStr(), Cnp)) < 0) { - sprintf(g->Message, "Cannot get result size rc=%d", n); + char* msg = PlugDup(g, g->Message); + + sprintf(g->Message, "Get result size: %s (rc=%d)", msg, n); return true; } else if (n) { Jcp->m_Rows = n; diff --git a/storage/connect/tabjson.cpp b/storage/connect/tabjson.cpp index a8f76900cb4..0b282345c8a 100644 --- a/storage/connect/tabjson.cpp +++ b/storage/connect/tabjson.cpp @@ -71,15 +71,15 @@ char *GetJsonNull(void); /***********************************************************************/ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) { - static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, + static int buftyp[] = {TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; - static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, + static XFLD fldtyp[] = {FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_PREC, FLD_LENGTH, FLD_SCALE, FLD_NULL, FLD_FORMAT}; static unsigned int length[] = {0, 6, 8, 10, 10, 6, 6, 0}; - int i, n = 0; + int i, n = 0; int ncol = sizeof(buftyp) / sizeof(int); - PJCL jcp; - JSONDISC *pjdc = NULL; + PJCL jcp; + JSONDISC *pjdc = NULL; PQRYRES qrp; PCOLRES crp; @@ -89,15 +89,15 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) goto skipit; } // endif info - if (GetIntegerTableOption(g, topt, "Multiple", 0)) { - strcpy(g->Message, "Cannot find column definition for multiple table"); - return NULL; - } // endif Multiple + if (GetIntegerTableOption(g, topt, "Multiple", 0)) { + strcpy(g->Message, "Cannot find column definition for multiple table"); + return NULL; + } // endif Multiple - pjdc = new(g) JSONDISC(g, length); + pjdc = new(g) JSONDISC(g, length); - if (!(n = pjdc->GetColumns(g, db, dsn, topt))) - return NULL; + if (!(n = pjdc->GetColumns(g, db, dsn, topt))) + return NULL; skipit: if (trace(1)) @@ -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 = PlugDup(g, "Nullable"); - crp->Next->Name = PlugDup(g, "Jpath"); + crp->Name = PlugDup(g, "Nullable"); + crp->Next->Name = PlugDup(g, "Jpath"); if (info || !qrp) return qrp; @@ -122,8 +122,8 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) /* Now get the results into blocks. */ /*********************************************************************/ for (i = 0, jcp = pjdc->fjcp; jcp; i++, jcp = jcp->Next) { - if (jcp->Type == TYPE_UNKNOWN) - jcp->Type = TYPE_STRING; // Void column + if (jcp->Type == TYPE_UNKNOWN) + jcp->Type = TYPE_STRING; // Void column crp = qrp->Colresp; // Column Name crp->Kdata->SetValue(jcp->Name, i); @@ -159,380 +159,380 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info) /***********************************************************************/ JSONDISC::JSONDISC(PGLOBAL g, uint *lg) { - length = lg; - jcp = fjcp = pjcp = NULL; - tjnp = NULL; - jpp = NULL; - tjsp = NULL; - jsp = NULL; - row = NULL; - sep = NULL; - i = n = bf = ncol = lvl = 0; - all = false; -} // end of JSONDISC constructor + length = lg; + jcp = fjcp = pjcp = NULL; + tjnp = NULL; + jpp = NULL; + tjsp = NULL; + jsp = NULL; + row = NULL; + sep = NULL; + i = n = bf = ncol = lvl = 0; + all = false; +} // end of JSONDISC constructor int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt) { - char filename[_MAX_PATH]; - bool mgo = (GetTypeID(topt->type) == TAB_MONGO); - PCSZ level = GetStringTableOption(g, topt, "Level", NULL); - - if (level) { - lvl = atoi(level); - lvl = (lvl > 16) ? 16 : lvl; - } else - lvl = 0; - - sep = GetStringTableOption(g, topt, "Separator", "."); - - /*********************************************************************/ - /* Open the input file. */ - /*********************************************************************/ - tdp = new(g) JSONDEF; + char filename[_MAX_PATH]; + bool mgo = (GetTypeID(topt->type) == TAB_MONGO); + PCSZ level = GetStringTableOption(g, topt, "Level", NULL); + + if (level) { + lvl = atoi(level); + lvl = (lvl > 16) ? 16 : lvl; + } else + lvl = 0; + + sep = GetStringTableOption(g, topt, "Separator", "."); + + /*********************************************************************/ + /* Open the input file. */ + /*********************************************************************/ + tdp = new(g) JSONDEF; #if defined(ZIP_SUPPORT) - tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL); - tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false); + tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL); + tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false); #endif // ZIP_SUPPORT - tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL); - - if (!(tdp->Database = SetPath(g, db))) - return 0; - - tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); - tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; - tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2); - tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL); - tdp->Accept = GetBooleanTableOption(g, topt, "Accept", false); - tdp->Uri = (dsn && *dsn ? dsn : NULL); - - if (!tdp->Fn && !tdp->Uri) { - strcpy(g->Message, MSG(MISSING_FNAME)); - return 0; - } // endif Fn - - if (tdp->Fn) { - // We used the file name relative to recorded datapath - PlugSetPath(filename, tdp->Fn, tdp->GetPath()); - tdp->Fn = PlugDup(g, filename); - } // endif Fn - - if (trace(1)) - htrc("File %s objname=%s pretty=%d lvl=%d\n", - tdp->Fn, tdp->Objname, tdp->Pretty, lvl); - - if (tdp->Uri) { + tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL); + + if (!(tdp->Database = SetPath(g, db))) + return 0; + + tdp->Objname = GetStringTableOption(g, topt, "Object", NULL); + tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0; + tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2); + tdp->Xcol = GetStringTableOption(g, topt, "Expand", NULL); + tdp->Accept = GetBooleanTableOption(g, topt, "Accept", false); + tdp->Uri = (dsn && *dsn ? dsn : NULL); + + if (!tdp->Fn && !tdp->Uri) { + strcpy(g->Message, MSG(MISSING_FNAME)); + return 0; + } // endif Fn + + if (tdp->Fn) { + // We used the file name relative to recorded datapath + PlugSetPath(filename, tdp->Fn, tdp->GetPath()); + tdp->Fn = PlugDup(g, filename); + } // endif Fn + + if (trace(1)) + htrc("File %s objname=%s pretty=%d lvl=%d\n", + tdp->Fn, tdp->Objname, tdp->Pretty, lvl); + + if (tdp->Uri) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) - tdp->Collname = GetStringTableOption(g, topt, "Name", NULL); - tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname); - tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test"); - tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all"); - tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false); - tdp->Driver = (PSZ)GetStringTableOption(g, topt, "Driver", NULL); - tdp->Version = GetIntegerTableOption(g, topt, "Version", 3); - tdp->Wrapname = (PSZ)GetStringTableOption(g, topt, "Wrapper", - (tdp->Version == 2) ? "Mongo2Interface" : "Mongo3Interface"); - tdp->Pretty = 0; + tdp->Collname = GetStringTableOption(g, topt, "Name", NULL); + tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname); + tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test"); + tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all"); + tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false); + tdp->Driver = (PSZ)GetStringTableOption(g, topt, "Driver", NULL); + tdp->Version = GetIntegerTableOption(g, topt, "Version", 3); + tdp->Wrapname = (PSZ)GetStringTableOption(g, topt, "Wrapper", + (tdp->Version == 2) ? "Mongo2Interface" : "Mongo3Interface"); + tdp->Pretty = 0; #else // !MONGO_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return 0; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); + return 0; #endif // !MONGO_SUPPORT - } // endif Uri + } // endif Uri - if (tdp->Pretty == 2) { - if (tdp->Zipped) { + if (tdp->Pretty == 2) { + if (tdp->Zipped) { #if defined(ZIP_SUPPORT) - tjsp = new(g) TDBJSON(tdp, new(g) UNZFAM(tdp)); + tjsp = new(g) TDBJSON(tdp, new(g) UNZFAM(tdp)); #else // !ZIP_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); - return 0; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); + return 0; #endif // !ZIP_SUPPORT - } else - tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); + } else + tjsp = new(g) TDBJSON(tdp, new(g) MAPFAM(tdp)); - if (tjsp->MakeDocument(g)) - return 0; + if (tjsp->MakeDocument(g)) + return 0; - jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; - } else { - if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) - if (!mgo) { - sprintf(g->Message, "LRECL must be specified for pretty=%d", tdp->Pretty); - return 0; - } else - tdp->Lrecl = 8192; // Should be enough + jsp = (tjsp->GetDoc()) ? tjsp->GetDoc()->GetValue(0) : NULL; + } else { + if (!(tdp->Lrecl = GetIntegerTableOption(g, topt, "Lrecl", 0))) + if (!mgo) { + sprintf(g->Message, "LRECL must be specified for pretty=%d", tdp->Pretty); + return 0; + } else + tdp->Lrecl = 8192; // Should be enough - tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); + tdp->Ending = GetIntegerTableOption(g, topt, "Ending", CRLF); - if (tdp->Zipped) { + if (tdp->Zipped) { #if defined(ZIP_SUPPORT) - tjnp = new(g)TDBJSN(tdp, new(g) UNZFAM(tdp)); + tjnp = new(g)TDBJSN(tdp, new(g) UNZFAM(tdp)); #else // !ZIP_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); - return NULL; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); + return NULL; #endif // !ZIP_SUPPORT - } else if (tdp->Uri) { - if (tdp->Driver && toupper(*tdp->Driver) == 'C') { + } else if (tdp->Uri) { + if (tdp->Driver && toupper(*tdp->Driver) == 'C') { #if defined(CMGO_SUPPORT) - tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); + tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); #else - sprintf(g->Message, "Mongo %s Driver not available", "C"); - return 0; + sprintf(g->Message, "Mongo %s Driver not available", "C"); + return 0; #endif - } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { + } else if (tdp->Driver && toupper(*tdp->Driver) == 'J') { #if defined(JAVA_SUPPORT) - tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); + tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else - sprintf(g->Message, "Mongo %s Driver not available", "Java"); - return 0; + sprintf(g->Message, "Mongo %s Driver not available", "Java"); + return 0; #endif - } else { // Driver not specified + } else { // Driver not specified #if defined(CMGO_SUPPORT) - tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); + tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp)); #elif defined(JAVA_SUPPORT) - tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); + tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp)); #else - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return 0; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); + return 0; #endif - } // endif Driver - - } else - tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp)); - - tjnp->SetMode(MODE_READ); - - // Allocate the parse work memory - PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); - memset(G, 0, sizeof(GLOBAL)); - G->Sarea_Size = tdp->Lrecl * 10; - G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); - PlugSubSet(G->Sarea, G->Sarea_Size); - G->jump_level = 0; - tjnp->SetG(G); - - if (tjnp->OpenDB(g)) - return 0; - - switch (tjnp->ReadDB(g)) { - case RC_EF: - strcpy(g->Message, "Void json table"); - case RC_FX: - goto err; - default: - jsp = tjnp->GetRow(); - } // endswitch ReadDB - - } // endif pretty - - if (!(row = (jsp) ? jsp->GetObject() : NULL)) { - strcpy(g->Message, "Can only retrieve columns from object rows"); - goto err; - } // endif row - - all = GetBooleanTableOption(g, topt, "Fullarray", false); - jcol.Name = jcol.Fmt = NULL; - jcol.Next = NULL; - jcol.Found = true; - colname[0] = 0; - - if (!tdp->Uri) { - fmt[0] = '$'; - fmt[1] = '.'; - bf = 2; - } // endif Uri - - /*********************************************************************/ - /* Analyse the JSON tree and define columns. */ - /*********************************************************************/ - for (i = 1; ; i++) { - for (jpp = row->GetFirst(); jpp; jpp = jpp->GetNext()) { - strncpy(colname, jpp->GetKey(), 64); - fmt[bf] = 0; - - if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0))) - goto err; - - } // endfor jpp - - // Missing column can be null - for (jcp = fjcp; jcp; jcp = jcp->Next) { - jcp->Cbn |= !jcp->Found; - jcp->Found = false; - } // endfor jcp - - if (tdp->Pretty != 2) { - // Read next record - switch (tjnp->ReadDB(g)) { - case RC_EF: - jsp = NULL; - break; - case RC_FX: - goto err; - default: - jsp = tjnp->GetRow(); - } // endswitch ReadDB - - } else - jsp = tjsp->GetDoc()->GetValue(i); - - if (!(row = (jsp) ? jsp->GetObject() : NULL)) - break; - - } // endfor i - - if (tdp->Pretty != 2) - tjnp->CloseDB(g); - - return n; + } // endif Driver + + } else + tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp)); + + tjnp->SetMode(MODE_READ); + + // Allocate the parse work memory + PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); + memset(G, 0, sizeof(GLOBAL)); + G->Sarea_Size = tdp->Lrecl * 10; + G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); + G->jump_level = 0; + tjnp->SetG(G); + + if (tjnp->OpenDB(g)) + return 0; + + switch (tjnp->ReadDB(g)) { + case RC_EF: + strcpy(g->Message, "Void json table"); + case RC_FX: + goto err; + default: + jsp = tjnp->GetRow(); + } // endswitch ReadDB + + } // endif pretty + + if (!(row = (jsp) ? jsp->GetObject() : NULL)) { + strcpy(g->Message, "Can only retrieve columns from object rows"); + goto err; + } // endif row + + all = GetBooleanTableOption(g, topt, "Fullarray", false); + jcol.Name = jcol.Fmt = NULL; + jcol.Next = NULL; + jcol.Found = true; + colname[0] = 0; + + if (!tdp->Uri) { + fmt[0] = '$'; + fmt[1] = '.'; + bf = 2; + } // endif Uri + + /*********************************************************************/ + /* Analyse the JSON tree and define columns. */ + /*********************************************************************/ + for (i = 1; ; i++) { + for (jpp = row->GetFirst(); jpp; jpp = jpp->GetNext()) { + strncpy(colname, jpp->GetKey(), 64); + fmt[bf] = 0; + + if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0))) + goto err; + + } // endfor jpp + + // Missing column can be null + for (jcp = fjcp; jcp; jcp = jcp->Next) { + jcp->Cbn |= !jcp->Found; + jcp->Found = false; + } // endfor jcp + + if (tdp->Pretty != 2) { + // Read next record + switch (tjnp->ReadDB(g)) { + case RC_EF: + jsp = NULL; + break; + case RC_FX: + goto err; + default: + jsp = tjnp->GetRow(); + } // endswitch ReadDB + + } else + jsp = tjsp->GetDoc()->GetValue(i); + + if (!(row = (jsp) ? jsp->GetObject() : NULL)) + break; + + } // endfor i + + if (tdp->Pretty != 2) + tjnp->CloseDB(g); + + return n; err: - if (tdp->Pretty != 2) - tjnp->CloseDB(g); + if (tdp->Pretty != 2) + tjnp->CloseDB(g); - return 0; -} // end of GetColumns + return 0; +} // end of GetColumns bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j) { - char *p, *pc = colname + strlen(colname); - int ars; - PJOB job; - PJAR jar; - - if ((valp = jvp ? jvp->GetValue() : NULL)) { - jcol.Type = valp->GetType(); - jcol.Len = valp->GetValLen(); - jcol.Scale = valp->GetValPrec(); - jcol.Cbn = valp->IsNull(); - } else if (!jvp || jvp->IsNull()) { - jcol.Type = TYPE_UNKNOWN; - jcol.Len = jcol.Scale = 0; - jcol.Cbn = true; - } else if (j < lvl) { - if (!fmt[bf]) - strcat(fmt, colname); - - p = fmt + strlen(fmt); - jsp = jvp->GetJson(); - - switch (jsp->GetType()) { - case TYPE_JOB: - job = (PJOB)jsp; - - for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) { - PCSZ k = jrp->GetKey(); - - if (*k != '$') { - strncat(strncat(fmt, sep, 128), k, 128); - strncat(strncat(colname, "_", 64), k, 64); - } // endif Key - - if (Find(g, jrp->GetVal(), k, j + 1)) - return true; - - *p = *pc = 0; - } // endfor jrp - - return false; - case TYPE_JAR: - jar = (PJAR)jsp; - - if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key))) - ars = jar->GetSize(false); - else - ars = MY_MIN(jar->GetSize(false), 1); - - for (int k = 0; k < ars; k++) { - if (!tdp->Xcol || stricmp(tdp->Xcol, key)) { - sprintf(buf, "%d", k); - - if (tdp->Uri) - strncat(strncat(fmt, sep, 128), buf, 128); - else - strncat(strncat(strncat(fmt, "[", 128), buf, 128), "]", 128); - - if (all) - strncat(strncat(colname, "_", 64), buf, 64); - - } else - strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); - - if (Find(g, jar->GetValue(k), "", j)) - return true; - - *p = *pc = 0; - } // endfor k - - return false; - default: - sprintf(g->Message, "Logical error after %s", fmt); - return true; - } // endswitch Type - - } else if (lvl >= 0) { - jcol.Type = TYPE_STRING; - jcol.Len = 256; - jcol.Scale = 0; - jcol.Cbn = true; - } else - return false; - - AddColumn(g); - return false; -} // end of Find + char *p, *pc = colname + strlen(colname); + int ars; + PJOB job; + PJAR jar; + + if ((valp = jvp ? jvp->GetValue() : NULL)) { + jcol.Type = valp->GetType(); + jcol.Len = valp->GetValLen(); + jcol.Scale = valp->GetValPrec(); + jcol.Cbn = valp->IsNull(); + } else if (!jvp || jvp->IsNull()) { + jcol.Type = TYPE_UNKNOWN; + jcol.Len = jcol.Scale = 0; + jcol.Cbn = true; + } else if (j < lvl) { + if (!fmt[bf]) + strcat(fmt, colname); + + p = fmt + strlen(fmt); + jsp = jvp->GetJson(); + + switch (jsp->GetType()) { + case TYPE_JOB: + job = (PJOB)jsp; + + for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) { + PCSZ k = jrp->GetKey(); + + if (*k != '$') { + strncat(strncat(fmt, sep, 128), k, 128); + strncat(strncat(colname, "_", 64), k, 64); + } // endif Key + + if (Find(g, jrp->GetVal(), k, j + 1)) + return true; + + *p = *pc = 0; + } // endfor jrp + + return false; + case TYPE_JAR: + jar = (PJAR)jsp; + + if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key))) + ars = jar->GetSize(false); + else + ars = MY_MIN(jar->GetSize(false), 1); + + for (int k = 0; k < ars; k++) { + if (!tdp->Xcol || stricmp(tdp->Xcol, key)) { + sprintf(buf, "%d", k); + + if (tdp->Uri) + strncat(strncat(fmt, sep, 128), buf, 128); + else + strncat(strncat(strncat(fmt, "[", 128), buf, 128), "]", 128); + + if (all) + strncat(strncat(colname, "_", 64), buf, 64); + + } else + strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); + + if (Find(g, jar->GetValue(k), "", j)) + return true; + + *p = *pc = 0; + } // endfor k + + return false; + default: + sprintf(g->Message, "Logical error after %s", fmt); + return true; + } // endswitch Type + + } else if (lvl >= 0) { + jcol.Type = TYPE_STRING; + jcol.Len = 256; + jcol.Scale = 0; + jcol.Cbn = true; + } else + return false; + + AddColumn(g); + return false; +} // end of Find void JSONDISC::AddColumn(PGLOBAL g) { - bool b = fmt[bf] != 0; // True if formatted - - // Check whether this column was already found - for (jcp = fjcp; jcp; jcp = jcp->Next) - if (!strcmp(colname, jcp->Name)) - break; - - if (jcp) { - if (jcp->Type != jcol.Type) { - if (jcp->Type == TYPE_UNKNOWN) - jcp->Type = jcol.Type; - else if (jcol.Type != TYPE_UNKNOWN) - jcp->Type = TYPE_STRING; - - } // endif Type - - if (b && (!jcp->Fmt || strlen(jcp->Fmt) < strlen(fmt))) { - jcp->Fmt = PlugDup(g, fmt); - length[7] = MY_MAX(length[7], strlen(fmt)); - } // endif fmt - - jcp->Len = MY_MAX(jcp->Len, jcol.Len); - jcp->Scale = MY_MAX(jcp->Scale, jcol.Scale); - jcp->Cbn |= jcol.Cbn; - jcp->Found = true; - } else if (jcol.Type != TYPE_UNKNOWN || tdp->Accept) { - // New column - jcp = (PJCL)PlugSubAlloc(g, NULL, sizeof(JCOL)); - *jcp = jcol; - jcp->Cbn |= (i > 1); - jcp->Name = PlugDup(g, colname); - length[0] = MY_MAX(length[0], strlen(colname)); - - if (b) { - jcp->Fmt = PlugDup(g, fmt); - length[7] = MY_MAX(length[7], strlen(fmt)); - } else - jcp->Fmt = NULL; - - if (pjcp) { - jcp->Next = pjcp->Next; - pjcp->Next = jcp; - } else - fjcp = jcp; - - n++; - } // endif jcp - - if (jcp) - pjcp = jcp; + bool b = fmt[bf] != 0; // True if formatted + + // Check whether this column was already found + for (jcp = fjcp; jcp; jcp = jcp->Next) + if (!strcmp(colname, jcp->Name)) + break; + + if (jcp) { + if (jcp->Type != jcol.Type) { + if (jcp->Type == TYPE_UNKNOWN) + jcp->Type = jcol.Type; + else if (jcol.Type != TYPE_UNKNOWN) + jcp->Type = TYPE_STRING; + + } // endif Type + + if (b && (!jcp->Fmt || strlen(jcp->Fmt) < strlen(fmt))) { + jcp->Fmt = PlugDup(g, fmt); + length[7] = MY_MAX(length[7], strlen(fmt)); + } // endif fmt + + jcp->Len = MY_MAX(jcp->Len, jcol.Len); + jcp->Scale = MY_MAX(jcp->Scale, jcol.Scale); + jcp->Cbn |= jcol.Cbn; + jcp->Found = true; + } else if (jcol.Type != TYPE_UNKNOWN || tdp->Accept) { + // New column + jcp = (PJCL)PlugSubAlloc(g, NULL, sizeof(JCOL)); + *jcp = jcol; + jcp->Cbn |= (i > 1); + jcp->Name = PlugDup(g, colname); + length[0] = MY_MAX(length[0], strlen(colname)); + + if (b) { + jcp->Fmt = PlugDup(g, fmt); + length[7] = MY_MAX(length[7], strlen(fmt)); + } else + jcp->Fmt = NULL; + + if (pjcp) { + jcp->Next = pjcp->Next; + pjcp->Next = jcp; + } else + fjcp = jcp; + + n++; + } // endif jcp + + if (jcp) + pjcp = jcp; } // end of AddColumn @@ -548,13 +548,13 @@ JSONDEF::JSONDEF(void) Limit = 1; Base = 0; Strict = false; - Sep = '.'; - Uri = NULL; - Collname = Options = Filter = NULL; - Pipe = false; - Driver = NULL; - Version = 0; - Wrapname = NULL; + Sep = '.'; + Uri = NULL; + Collname = Options = Filter = NULL; + Pipe = false; + Driver = NULL; + Version = 0; + Wrapname = NULL; } // end of JSONDEF constructor /***********************************************************************/ @@ -562,41 +562,41 @@ JSONDEF::JSONDEF(void) /***********************************************************************/ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - Schema = GetStringCatInfo(g, "DBname", Schema); - Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT); + Schema = GetStringCatInfo(g, "DBname", Schema); + Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT); Objname = GetStringCatInfo(g, "Object", NULL); Xcol = GetStringCatInfo(g, "Expand", NULL); Pretty = GetIntCatInfo("Pretty", 2); Limit = GetIntCatInfo("Limit", 10); Base = GetIntCatInfo("Base", 0) ? 1 : 0; - Sep = *GetStringCatInfo(g, "Separator", "."); - Accept = GetBoolCatInfo("Accept", false); + Sep = *GetStringCatInfo(g, "Separator", "."); + Accept = GetBoolCatInfo("Accept", false); - // Don't use url as MONGO uri when called from REST - if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) { + // Don't use url as MONGO uri when called from REST + if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) { #if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) - Collname = GetStringCatInfo(g, "Name", - (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); - Collname = GetStringCatInfo(g, "Tabname", Collname); - Options = GetStringCatInfo(g, "Colist", NULL); - Filter = GetStringCatInfo(g, "Filter", NULL); - Pipe = GetBoolCatInfo("Pipeline", false); - Driver = GetStringCatInfo(g, "Driver", NULL); - Version = GetIntCatInfo("Version", 3); - Pretty = 0; + Collname = GetStringCatInfo(g, "Name", + (Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name); + Collname = GetStringCatInfo(g, "Tabname", Collname); + Options = GetStringCatInfo(g, "Colist", NULL); + Filter = GetStringCatInfo(g, "Filter", NULL); + Pipe = GetBoolCatInfo("Pipeline", false); + Driver = GetStringCatInfo(g, "Driver", NULL); + Version = GetIntCatInfo("Version", 3); + Pretty = 0; #if defined(JAVA_SUPPORT) - if (Version == 2) - Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo2Interface"); - else - Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo3Interface"); + if (Version == 2) + Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo2Interface"); + else + Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo3Interface"); #endif // JAVA_SUPPORT #else // !MONGO_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return true; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); + return true; #endif // !MONGO_SUPPORT - } // endif Uri + } // endif Uri - return DOSDEF::DefineAM(g, (Uri ? "XMGO" : "DOS"), poff); + return DOSDEF::DefineAM(g, (Uri ? "XMGO" : "DOS"), poff); } // end of DefineAM /***********************************************************************/ @@ -604,6 +604,9 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) { + if (trace(1)) + htrc("JSON GetTable Pretty=%d Uri=%s\n", Pretty, SVP(Uri)); + if (Catfunc == FNC_COL) return new(g)TDBJCL(this); @@ -618,47 +621,47 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) !(tmp == TMP_FORCE && (m == MODE_UPDATE || m == MODE_DELETE)); - if (Uri) { - if (Driver && toupper(*Driver) == 'C') { + if (Uri) { + if (Driver && toupper(*Driver) == 'C') { #if defined(CMGO_SUPPORT) - txfp = new(g) CMGFAM(this); + txfp = new(g) CMGFAM(this); #else - sprintf(g->Message, "Mongo %s Driver not available", "C"); - return NULL; + sprintf(g->Message, "Mongo %s Driver not available", "C"); + return NULL; #endif - } else if (Driver && toupper(*Driver) == 'J') { + } else if (Driver && toupper(*Driver) == 'J') { #if defined(JAVA_SUPPORT) - txfp = new(g) JMGFAM(this); + txfp = new(g) JMGFAM(this); #else - sprintf(g->Message, "Mongo %s Driver not available", "Java"); - return NULL; + sprintf(g->Message, "Mongo %s Driver not available", "Java"); + return NULL; #endif - } else { // Driver not specified + } else { // Driver not specified #if defined(CMGO_SUPPORT) - txfp = new(g) CMGFAM(this); + txfp = new(g) CMGFAM(this); #elif defined(JAVA_SUPPORT) - txfp = new(g) JMGFAM(this); -#else // !MONGO_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); - return NULL; + txfp = new(g) JMGFAM(this); +#else // !MONGO_SUPPORT + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO"); + return NULL; #endif // !MONGO_SUPPORT - } // endif Driver + } // endif Driver - } else if (Zipped) { + } else if (Zipped) { #if defined(ZIP_SUPPORT) - if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { - txfp = new(g) UNZFAM(this); - } else if (m == MODE_INSERT) { - txfp = new(g) ZIPFAM(this); - } else { - strcpy(g->Message, "UPDATE/DELETE not supported for ZIP"); - return NULL; - } // endif's m + if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { + txfp = new(g) UNZFAM(this); + } else if (m == MODE_INSERT) { + txfp = new(g) ZIPFAM(this); + } else { + strcpy(g->Message, "UPDATE/DELETE not supported for ZIP"); + return NULL; + } // endif's m #else // !ZIP_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); - return NULL; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); + return NULL; #endif // !ZIP_SUPPORT - } else if (Compressed) { + } else if (Compressed) { #if defined(GZ_SUPPORT) if (Compressed == 1) txfp = new(g) GZFAM(this); @@ -668,7 +671,7 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "GZ"); return NULL; #endif // !GZ_SUPPORT - } else if (map) + } else if (map) txfp = new(g) MAPFAM(this); else txfp = new(g) DOSFAM(this); @@ -676,41 +679,41 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m) // Txfp must be set for TDBDOS tdbp = new(g) TDBJSN(this, txfp); - if (Lrecl) { - // Allocate the parse work memory - PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); - memset(G, 0, sizeof(GLOBAL)); - G->Sarea_Size = Lrecl * 10; - G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); - PlugSubSet(G->Sarea, G->Sarea_Size); - G->jump_level = 0; - ((TDBJSN*)tdbp)->G = G; - } else { - strcpy(g->Message, "LRECL is not defined"); - return NULL; - } // endif Lrecl - - } else { - if (Zipped) { + if (Lrecl) { + // Allocate the parse work memory + PGLOBAL G = (PGLOBAL)PlugSubAlloc(g, NULL, sizeof(GLOBAL)); + memset(G, 0, sizeof(GLOBAL)); + G->Sarea_Size = Lrecl * 10; + G->Sarea = PlugSubAlloc(g, NULL, G->Sarea_Size); + PlugSubSet(G->Sarea, G->Sarea_Size); + G->jump_level = 0; + ((TDBJSN*)tdbp)->G = G; + } else { + strcpy(g->Message, "LRECL is not defined"); + return NULL; + } // endif Lrecl + + } else { + if (Zipped) { #if defined(ZIP_SUPPORT) - if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { - txfp = new(g) UNZFAM(this); - } else if (m == MODE_INSERT) { - strcpy(g->Message, "INSERT supported only for zipped JSON when pretty=0"); - return NULL; - } else { - strcpy(g->Message, "UPDATE/DELETE not supported for ZIP"); - return NULL; - } // endif's m + if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) { + txfp = new(g) UNZFAM(this); + } else if (m == MODE_INSERT) { + strcpy(g->Message, "INSERT supported only for zipped JSON when pretty=0"); + return NULL; + } else { + strcpy(g->Message, "UPDATE/DELETE not supported for ZIP"); + return NULL; + } // endif's m #else // !ZIP_SUPPORT - sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); - return NULL; + sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "ZIP"); + return NULL; #endif // !ZIP_SUPPORT - } else - txfp = new(g) MAPFAM(this); + } else + txfp = new(g) MAPFAM(this); tdbp = new(g) TDBJSON(this, txfp); - ((TDBJSON*)tdbp)->G = g; + ((TDBJSON*)tdbp)->G = g; } // endif Pretty if (Multiple) @@ -738,16 +741,16 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp) Limit = tdp->Limit; Pretty = tdp->Pretty; B = tdp->Base ? 1 : 0; - Sep = tdp->Sep; + Sep = tdp->Sep; Strict = tdp->Strict; } else { Jmode = MODE_OBJECT; Objname = NULL; - Xcol = NULL; + Xcol = NULL; Limit = 1; Pretty = 0; B = 0; - Sep = '.'; + Sep = '.'; Strict = false; } // endif tdp @@ -761,7 +764,7 @@ TDBJSN::TDBJSN(PJDEF tdp, PTXF txfp) : TDBDOS(tdp, txfp) TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp) { - G = NULL; + G = NULL; Top = tdbp->Top; Row = tdbp->Row; Val = tdbp->Val; @@ -777,7 +780,7 @@ TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp) SameRow = tdbp->SameRow; Xval = tdbp->Xval; B = tdbp->B; - Sep = tdbp->Sep; + Sep = tdbp->Sep; Pretty = tdbp->Pretty; Strict = tdbp->Strict; Comma = tdbp->Comma; @@ -786,7 +789,7 @@ TDBJSN::TDBJSN(TDBJSN *tdbp) : TDBDOS(NULL, tdbp) // Used for update PTDB TDBJSN::Clone(PTABS t) { - G = NULL; + G = NULL; PTDB tp; PJCOL cp1, cp2; PGLOBAL g = t->G; @@ -860,33 +863,33 @@ PJSON TDBJSN::FindRow(PGLOBAL g) PJSON jsp = Row; PJVAL val = NULL; - for (objpath = PlugDup(g, Objname); jsp && objpath; objpath = p) { - if ((p = strchr(objpath, Sep))) - *p++ = 0; + for (objpath = PlugDup(g, Objname); jsp && objpath; objpath = p) { + if ((p = strchr(objpath, Sep))) + *p++ = 0; - if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key - val = (jsp->GetType() == TYPE_JOB) ? - jsp->GetObject()->GetValue(objpath) : NULL; - } else { - if (*objpath == '[') { - if (objpath[strlen(objpath) - 1] == ']') - objpath++; - else - return NULL; - } // endif [ + if (*objpath != '[' && !IsNum(objpath)) { // objpass is a key + val = (jsp->GetType() == TYPE_JOB) ? + jsp->GetObject()->GetValue(objpath) : NULL; + } else { + if (*objpath == '[') { + if (objpath[strlen(objpath) - 1] == ']') + objpath++; + else + return NULL; + } // endif [ - val = (jsp->GetType() == TYPE_JAR) ? - jsp->GetArray()->GetValue(atoi(objpath) - B) : NULL; - } // endif objpath + val = (jsp->GetType() == TYPE_JAR) ? + jsp->GetArray()->GetValue(atoi(objpath) - B) : NULL; + } // endif objpath - jsp = (val) ? val->GetJson() : NULL; - } // endfor objpath + jsp = (val) ? val->GetJson() : NULL; + } // endfor objpath return jsp; } // end of FindRow /***********************************************************************/ -/* OpenDB: Data Base open routine for JSN access method. */ +/* OpenDB: Data Base open routine for JSN access method. */ /***********************************************************************/ bool TDBJSN::OpenDB(PGLOBAL g) { @@ -911,15 +914,15 @@ bool TDBJSN::OpenDB(PGLOBAL g) return true; } // endswitch Jmode - } // endif Use + } // endif Use - if (TDBDOS::OpenDB(g)) - return true; + if (TDBDOS::OpenDB(g)) + return true; - if (Xcol) - To_Filter = NULL; // Imcompatible + if (Xcol) + To_Filter = NULL; // Imcompatible - return false; + return false; } // end of OpenDB /***********************************************************************/ @@ -969,27 +972,27 @@ int TDBJSN::ReadDB(PGLOBAL g) NextSame = 0; M++; return RC_OK; - } else if ((rc = TDBDOS::ReadDB(g)) == RC_OK) { - if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) - // Deferred reading failed - return rc; - - // Recover the memory used for parsing - PlugSubSet(G->Sarea, G->Sarea_Size); - - if ((Row = ParseJson(G, To_Line, strlen(To_Line), &Pretty, &Comma))) { - Row = FindRow(g); - SameRow = 0; - Fpos++; - M = 1; - rc = RC_OK; - } else if (Pretty != 1 || strcmp(To_Line, "]")) { - strcpy(g->Message, G->Message); - rc = RC_FX; - } else - rc = RC_EF; - - } // endif ReadDB + } else if ((rc = TDBDOS::ReadDB(g)) == RC_OK) { + if (!IsRead() && ((rc = ReadBuffer(g)) != RC_OK)) + // Deferred reading failed + return rc; + + // Recover the memory used for parsing + PlugSubSet(G->Sarea, G->Sarea_Size); + + if ((Row = ParseJson(G, To_Line, strlen(To_Line), &Pretty, &Comma))) { + Row = FindRow(g); + SameRow = 0; + Fpos++; + M = 1; + rc = RC_OK; + } else if (Pretty != 1 || strcmp(To_Line, "]")) { + strcpy(g->Message, G->Message); + rc = RC_FX; + } else + rc = RC_EF; + + } // endif ReadDB return rc; } // end of ReadDB @@ -999,68 +1002,68 @@ int TDBJSN::ReadDB(PGLOBAL g) /***********************************************************************/ int TDBJSN::MakeTopTree(PGLOBAL g, PJSON jsp) { - if (Objname) { - if (!Val) { - // Parse and allocate Objname item(s) - char *p; - char *objpath = PlugDup(g, Objname); - int i; - PJOB objp; - PJAR arp; - PJVAL val = NULL; + if (Objname) { + if (!Val) { + // Parse and allocate Objname item(s) + char *p; + char *objpath = PlugDup(g, Objname); + int i; + PJOB objp; + PJAR arp; + PJVAL val = NULL; - Top = NULL; + Top = NULL; - for (; objpath; objpath = p) { - if ((p = strchr(objpath, Sep))) - *p++ = 0; + for (; objpath; objpath = p) { + if ((p = strchr(objpath, Sep))) + *p++ = 0; - if (*objpath != '[' && !IsNum(objpath)) { - objp = new(g) JOBJECT; + if (*objpath != '[' && !IsNum(objpath)) { + objp = new(g) JOBJECT; - if (!Top) - Top = objp; + if (!Top) + Top = objp; - if (val) - val->SetValue(objp); + if (val) + val->SetValue(objp); - val = new(g) JVALUE; - objp->SetValue(g, val, objpath); - } else { - if (*objpath == '[') { - // Old style - if (objpath[strlen(objpath) - 1] != ']') { - sprintf(g->Message, "Invalid Table path %s", Objname); - return RC_FX; - } else - objpath++; + val = new(g) JVALUE; + objp->SetValue(g, val, objpath); + } else { + if (*objpath == '[') { + // Old style + if (objpath[strlen(objpath) - 1] != ']') { + sprintf(g->Message, "Invalid Table path %s", Objname); + return RC_FX; + } else + objpath++; - } // endif objpath + } // endif objpath - arp = new(g) JARRAY; + arp = new(g) JARRAY; - if (!Top) - Top = arp; + if (!Top) + Top = arp; - if (val) - val->SetValue(arp); + if (val) + val->SetValue(arp); - val = new(g) JVALUE; - i = atoi(objpath) - B; - arp->SetValue(g, val, i); - arp->InitArray(g); - } // endif objpath + val = new(g) JVALUE; + i = atoi(objpath) - B; + arp->SetValue(g, val, i); + arp->InitArray(g); + } // endif objpath - } // endfor p + } // endfor p - Val = val; - } // endif Val + Val = val; + } // endif Val - Val->SetValue(jsp); - } else - Top = jsp; + Val->SetValue(jsp); + } else + Top = jsp; - return RC_OK; + return RC_OK; } // end of MakeTopTree /***********************************************************************/ @@ -1095,11 +1098,11 @@ int TDBJSN::MakeTopTree(PGLOBAL g, PJSON jsp) /***********************************************************************/ int TDBJSN::WriteDB(PGLOBAL g) { - int rc = TDBDOS::WriteDB(g); + int rc = TDBDOS::WriteDB(g); - PlugSubSet(G->Sarea, G->Sarea_Size); - Row->Clear(); - return rc; + PlugSubSet(G->Sarea, G->Sarea_Size); + Row->Clear(); + return rc; } // end of WriteDB /* ---------------------------- JSONCOL ------------------------------ */ @@ -1111,12 +1114,12 @@ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) : DOSCOL(g, cdp, tdbp, cprec, i, "DOS") { Tjp = (TDBJSN *)(tdbp->GetOrig() ? tdbp->GetOrig() : tdbp); - G = Tjp->G; + G = Tjp->G; Jpath = cdp->GetFmt(); MulVal = NULL; Nodes = NULL; Nod = 0; - Sep = Tjp->Sep; + Sep = Tjp->Sep; Xnod = -1; Xpd = false; Parsed = false; @@ -1128,14 +1131,14 @@ JSONCOL::JSONCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i) /***********************************************************************/ JSONCOL::JSONCOL(JSONCOL *col1, PTDB tdbp) : DOSCOL(col1, tdbp) { - G = col1->G; + G = col1->G; Tjp = col1->Tjp; Jpath = col1->Jpath; MulVal = col1->MulVal; Nodes = col1->Nodes; Nod = col1->Nod; - Sep = col1->Sep; - Xnod = col1->Xnod; + Sep = col1->Sep; + Xnod = col1->Xnod; Xpd = col1->Xpd; Parsed = col1->Parsed; } // end of JSONCOL copy constructor @@ -1153,7 +1156,7 @@ bool JSONCOL::SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check) return true; Tjp = (TDBJSN*)To_Tdb; - G = Tjp->G; + G = Tjp->G; return false; } // end of SetBuffer @@ -1179,130 +1182,130 @@ bool JSONCOL::CheckExpand(PGLOBAL g, int i, PSZ nm, bool b) /***********************************************************************/ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) { - int n; - bool dg = true, b = false; - PJNODE jnp = &Nodes[i]; - - //if (*p == '[') p++; // Old syntax .[ or :[ - n = (int)strlen(p); - - if (*p) { - if (p[n - 1] == ']') { - p[--n] = 0; - } else if (!IsNum(p)) { - // Wrong array specification - sprintf(g->Message, "Invalid array specification %s for %s", p, Name); - return true; - } // endif p - - } else - b = true; - - // To check whether a numeric Rank was specified - dg = IsNum(p); - - if (!n) { - // Default specifications - if (CheckExpand(g, i, nm, false)) - return true; - else if (jnp->Op != OP_EXP) { - if (b) { - // Return 1st value (B is the index base) - jnp->Rank = Tjp->B; - jnp->Op = OP_EQ; - } else if (!Value->IsTypeNum()) { - jnp->CncVal = AllocateValue(g, (void*)", ", TYPE_STRING); - jnp->Op = OP_CNC; - } else - jnp->Op = OP_ADD; - - } // endif OP - - } else if (dg) { - // Return nth value - jnp->Rank = atoi(p) - Tjp->B; - jnp->Op = OP_EQ; - } else if (n == 1) { - // Set the Op value; - if (Sep == ':') - switch (*p) { - case '*': *p = 'x'; break; - case 'x': - case 'X': *p = '*'; break; // Expand this array - default: break; - } // endswitch p - - switch (*p) { - case '+': jnp->Op = OP_ADD; break; - case 'x': jnp->Op = OP_MULT; break; - case '>': jnp->Op = OP_MAX; break; - case '<': jnp->Op = OP_MIN; break; - case '!': jnp->Op = OP_SEP; break; // Average - case '#': jnp->Op = OP_NUM; break; - case '*': // Expand this array - if (!Tjp->Xcol && nm) { - Xpd = true; - jnp->Op = OP_EXP; - Tjp->Xval = i; - Tjp->Xcol = nm; - } else if (CheckExpand(g, i, nm, true)) - return true; - - break; - default: - sprintf(g->Message, - "Invalid function specification %c for %s", *p, Name); - return true; - } // endswitch *p - - } else if (*p == '"' && p[n - 1] == '"') { - // This is a concat specification - jnp->Op = OP_CNC; - - if (n > 2) { - // Set concat intermediate string - p[n - 1] = 0; - jnp->CncVal = AllocateValue(g, p + 1, TYPE_STRING); - } // endif n - - } else { - sprintf(g->Message, "Wrong array specification for %s", Name); - return true; - } // endif's - - // For calculated arrays, a local Value must be used - switch (jnp->Op) { - case OP_NUM: - jnp->Valp = AllocateValue(g, TYPE_INT); - break; - case OP_ADD: - case OP_MULT: - case OP_SEP: - if (!IsTypeChar(Buf_Type)) - jnp->Valp = AllocateValue(g, Buf_Type, 0, GetPrecision()); - else - jnp->Valp = AllocateValue(g, TYPE_DOUBLE, 0, 2); - - break; - case OP_MIN: - case OP_MAX: - jnp->Valp = AllocateValue(g, Buf_Type, Long, GetPrecision()); - break; - case OP_CNC: - if (IsTypeChar(Buf_Type)) - jnp->Valp = AllocateValue(g, TYPE_STRING, Long, GetPrecision()); - else - jnp->Valp = AllocateValue(g, TYPE_STRING, 512); - - break; - default: - break; - } // endswitch Op - - if (jnp->Valp) - MulVal = AllocateValue(g, jnp->Valp); - - return false; + int n; + bool dg = true, b = false; + PJNODE jnp = &Nodes[i]; + + //if (*p == '[') p++; // Old syntax .[ or :[ + n = (int)strlen(p); + + if (*p) { + if (p[n - 1] == ']') { + p[--n] = 0; + } else if (!IsNum(p)) { + // Wrong array specification + sprintf(g->Message, "Invalid array specification %s for %s", p, Name); + return true; + } // endif p + + } else + b = true; + + // To check whether a numeric Rank was specified + dg = IsNum(p); + + if (!n) { + // Default specifications + if (CheckExpand(g, i, nm, false)) + return true; + else if (jnp->Op != OP_EXP) { + if (b) { + // Return 1st value (B is the index base) + jnp->Rank = Tjp->B; + jnp->Op = OP_EQ; + } else if (!Value->IsTypeNum()) { + jnp->CncVal = AllocateValue(g, (void*)", ", TYPE_STRING); + jnp->Op = OP_CNC; + } else + jnp->Op = OP_ADD; + + } // endif OP + + } else if (dg) { + // Return nth value + jnp->Rank = atoi(p) - Tjp->B; + jnp->Op = OP_EQ; + } else if (n == 1) { + // Set the Op value; + if (Sep == ':') + switch (*p) { + case '*': *p = 'x'; break; + case 'x': + case 'X': *p = '*'; break; // Expand this array + default: break; + } // endswitch p + + switch (*p) { + case '+': jnp->Op = OP_ADD; break; + case 'x': jnp->Op = OP_MULT; break; + case '>': jnp->Op = OP_MAX; break; + case '<': jnp->Op = OP_MIN; break; + case '!': jnp->Op = OP_SEP; break; // Average + case '#': jnp->Op = OP_NUM; break; + case '*': // Expand this array + if (!Tjp->Xcol && nm) { + Xpd = true; + jnp->Op = OP_EXP; + Tjp->Xval = i; + Tjp->Xcol = nm; + } else if (CheckExpand(g, i, nm, true)) + return true; + + break; + default: + sprintf(g->Message, + "Invalid function specification %c for %s", *p, Name); + return true; + } // endswitch *p + + } else if (*p == '"' && p[n - 1] == '"') { + // This is a concat specification + jnp->Op = OP_CNC; + + if (n > 2) { + // Set concat intermediate string + p[n - 1] = 0; + jnp->CncVal = AllocateValue(g, p + 1, TYPE_STRING); + } // endif n + + } else { + sprintf(g->Message, "Wrong array specification for %s", Name); + return true; + } // endif's + + // For calculated arrays, a local Value must be used + switch (jnp->Op) { + case OP_NUM: + jnp->Valp = AllocateValue(g, TYPE_INT); + break; + case OP_ADD: + case OP_MULT: + case OP_SEP: + if (!IsTypeChar(Buf_Type)) + jnp->Valp = AllocateValue(g, Buf_Type, 0, GetPrecision()); + else + jnp->Valp = AllocateValue(g, TYPE_DOUBLE, 0, 2); + + break; + case OP_MIN: + case OP_MAX: + jnp->Valp = AllocateValue(g, Buf_Type, Long, GetPrecision()); + break; + case OP_CNC: + if (IsTypeChar(Buf_Type)) + jnp->Valp = AllocateValue(g, TYPE_STRING, Long, GetPrecision()); + else + jnp->Valp = AllocateValue(g, TYPE_STRING, 512); + + break; + default: + break; + } // endswitch Op + + if (jnp->Valp) + MulVal = AllocateValue(g, jnp->Valp); + + return false; } // end of SetArrayOptions /***********************************************************************/ @@ -1313,87 +1316,87 @@ bool JSONCOL::SetArrayOptions(PGLOBAL g, char *p, int i, PSZ nm) /***********************************************************************/ bool JSONCOL::ParseJpath(PGLOBAL g) { - char *p, *p1 = NULL, *p2 = NULL, *pbuf = NULL; - int i; - bool a, mul = false; - - if (Parsed) - return false; // Already done - else if (InitValue(g)) - return true; - else if (!Jpath) - Jpath = Name; - - if (To_Tdb->GetOrig()) { - // This is an updated column, get nodes from origin - for (PJCOL colp = (PJCOL)Tjp->GetColumns(); colp; - colp = (PJCOL)colp->GetNext()) - if (!stricmp(Name, colp->GetName())) { - Nod = colp->Nod; - Nodes = colp->Nodes; - Xpd = colp->Xpd; - goto fin; - } // endif Name - - sprintf(g->Message, "Cannot parse updated column %s", Name); - return true; - } // endif To_Orig - - pbuf = PlugDup(g, Jpath); - if (*pbuf == '$') pbuf++; - if (*pbuf == Sep) pbuf++; - if (*pbuf == '[') p1 = pbuf++; - - // Estimate the required number of nodes - for (i = 0, p = pbuf; (p = NextChr(p, Sep)); i++, p++) - Nod++; // One path node found - - Nodes = (PJNODE)PlugSubAlloc(g, NULL, (++Nod) * sizeof(JNODE)); - memset(Nodes, 0, (Nod) * sizeof(JNODE)); - - // Analyze the Jpath for this column - for (i = 0, p = pbuf; p && i < Nod; i++, p = (p2 ? p2 : NULL)) { - a = (p1 != NULL); - p1 = strchr(p, '['); - p2 = strchr(p, Sep); - - if (!p2) - p2 = p1; - else if (p1) { - if (p1 < p2) - p2 = p1; - else if (p1 == p2 + 1) - *p2++ = 0; // Old syntax .[ or :[ - else - p1 = NULL; - - } // endif p1 - - if (p2) - *p2++ = 0; - - // Jpath must be explicit - if (a || *p == 0 || *p == '[' || IsNum(p)) { - // Analyse intermediate array processing - if (SetArrayOptions(g, p, i, Nodes[i - 1].Key)) - return true; - - } else if (*p == '*') { - // Return JSON - Nodes[i].Op = OP_XX; - } else { - Nodes[i].Key = p; - Nodes[i].Op = OP_EXIST; - } // endif's - - } // endfor i, p - - Nod = i; + char *p, *p1 = NULL, *p2 = NULL, *pbuf = NULL; + int i; + bool a, mul = false; + + if (Parsed) + return false; // Already done + else if (InitValue(g)) + return true; + else if (!Jpath) + Jpath = Name; + + if (To_Tdb->GetOrig()) { + // This is an updated column, get nodes from origin + for (PJCOL colp = (PJCOL)Tjp->GetColumns(); colp; + colp = (PJCOL)colp->GetNext()) + if (!stricmp(Name, colp->GetName())) { + Nod = colp->Nod; + Nodes = colp->Nodes; + Xpd = colp->Xpd; + goto fin; + } // endif Name + + sprintf(g->Message, "Cannot parse updated column %s", Name); + return true; + } // endif To_Orig + + pbuf = PlugDup(g, Jpath); + if (*pbuf == '$') pbuf++; + if (*pbuf == Sep) pbuf++; + if (*pbuf == '[') p1 = pbuf++; + + // Estimate the required number of nodes + for (i = 0, p = pbuf; (p = NextChr(p, Sep)); i++, p++) + Nod++; // One path node found + + Nodes = (PJNODE)PlugSubAlloc(g, NULL, (++Nod) * sizeof(JNODE)); + memset(Nodes, 0, (Nod) * sizeof(JNODE)); + + // Analyze the Jpath for this column + for (i = 0, p = pbuf; p && i < Nod; i++, p = (p2 ? p2 : NULL)) { + a = (p1 != NULL); + p1 = strchr(p, '['); + p2 = strchr(p, Sep); + + if (!p2) + p2 = p1; + else if (p1) { + if (p1 < p2) + p2 = p1; + else if (p1 == p2 + 1) + *p2++ = 0; // Old syntax .[ or :[ + else + p1 = NULL; + + } // endif p1 + + if (p2) + *p2++ = 0; + + // Jpath must be explicit + if (a || *p == 0 || *p == '[' || IsNum(p)) { + // Analyse intermediate array processing + if (SetArrayOptions(g, p, i, Nodes[i - 1].Key)) + return true; + + } else if (*p == '*') { + // Return JSON + Nodes[i].Op = OP_XX; + } else { + Nodes[i].Key = p; + Nodes[i].Op = OP_EXIST; + } // endif's + + } // endfor i, p + + Nod = i; fin: - MulVal = AllocateValue(g, Value); - Parsed = true; - return false; + MulVal = AllocateValue(g, Value); + Parsed = true; + return false; } // end of ParseJpath /***********************************************************************/ @@ -1401,66 +1404,66 @@ fin: /***********************************************************************/ PSZ JSONCOL::GetJpath(PGLOBAL g, bool proj) { - if (Jpath) { - char *p1, *p2, *mgopath; - int i = 0; - - if (strcmp(Jpath, "*")) { - p1 = Jpath; - if (*p1 == '$') p1++; - if (*p1 == '.') p1++; - mgopath = PlugDup(g, p1); - } else - return NULL; - - for (p1 = p2 = mgopath; *p1; p1++) - if (i) { // Inside [] - if (isdigit(*p1)) { - if (!proj) - *p2++ = *p1; - - } else if (*p1 == ']' && i == 1) { - if (proj && p1[1] == '.') - p1++; - - i = 0; - } else if (*p1 == '.' && i == 2) { - if (!proj) - *p2++ = '.'; - - i = 0; - } else if (!proj) - return NULL; - - } else switch (*p1) { - case ':': - case '.': - if (isdigit(p1[1])) - i = 2; - - *p2++ = '.'; - break; - case '[': - if (*(p2 - 1) != '.') - *p2++ = '.'; - - i = 1; - break; - case '*': - if (*(p2 - 1) == '.' && !*(p1 + 1)) { - p2--; // Suppress last :* - break; - } // endif p2 - - default: - *p2++ = *p1; - break; - } // endswitch p1; - - *p2 = 0; - return mgopath; - } else - return NULL; + if (Jpath) { + char *p1, *p2, *mgopath; + int i = 0; + + if (strcmp(Jpath, "*")) { + p1 = Jpath; + if (*p1 == '$') p1++; + if (*p1 == '.') p1++; + mgopath = PlugDup(g, p1); + } else + return NULL; + + for (p1 = p2 = mgopath; *p1; p1++) + if (i) { // Inside [] + if (isdigit(*p1)) { + if (!proj) + *p2++ = *p1; + + } else if (*p1 == ']' && i == 1) { + if (proj && p1[1] == '.') + p1++; + + i = 0; + } else if (*p1 == '.' && i == 2) { + if (!proj) + *p2++ = '.'; + + i = 0; + } else if (!proj) + return NULL; + + } else switch (*p1) { + case ':': + case '.': + if (isdigit(p1[1])) + i = 2; + + *p2++ = '.'; + break; + case '[': + if (*(p2 - 1) != '.') + *p2++ = '.'; + + i = 1; + break; + case '*': + if (*(p2 - 1) == '.' && !*(p1 + 1)) { + p2--; // Suppress last :* + break; + } // endif p2 + + default: + *p2++ = *p1; + break; + } // endswitch p1; + + *p2 = 0; + return mgopath; + } else + return NULL; } // end of GetJpath @@ -1469,7 +1472,7 @@ PSZ JSONCOL::GetJpath(PGLOBAL g, bool proj) /***********************************************************************/ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp) { - if (Value->IsTypeNum()) { + if (Value->IsTypeNum()) { strcpy(g->Message, "Cannot make Json for a numeric column"); Value->Reset(); } else @@ -1484,22 +1487,22 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp) void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) { if (val) { - vp->SetNull(false); + vp->SetNull(false); switch (val->GetValType()) { case TYPE_STRG: case TYPE_INTG: - case TYPE_BINT: - case TYPE_DBL: - case TYPE_DTM: - vp->SetValue_pval(val->GetValue()); + case TYPE_BINT: + case TYPE_DBL: + case TYPE_DTM: + vp->SetValue_pval(val->GetValue()); break; case TYPE_BOOL: if (vp->IsTypeNum()) vp->SetValue(val->GetInteger() ? 1 : 0); else vp->SetValue_psz((PSZ)(val->GetInteger() ? "true" : "false")); - + break; case TYPE_JAR: SetJsonValue(g, vp, val->GetArray()->GetValue(0), n); @@ -1509,16 +1512,16 @@ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n) vp->SetValue_psz(val->GetObject()->GetText(g, NULL)); break; // } // endif Type - + default: - vp->Reset(); - vp->SetNull(true); - } // endswitch Type + vp->Reset(); + vp->SetNull(true); + } // endswitch Type - } else { - vp->Reset(); - vp->SetNull(true); - } // endif val + } else { + vp->Reset(); + vp->SetNull(true); + } // endif val } // end of SetJsonValue @@ -1530,8 +1533,8 @@ void JSONCOL::ReadColumn(PGLOBAL g) if (!Tjp->SameRow || Xnod >= Tjp->SameRow) Value->SetValue_pval(GetColumnValue(g, Tjp->Row, 0)); - if (Xpd && Value->IsNull() && !((PJDEF)Tjp->To_Def)->Accept) - throw("Null expandable JSON value"); + if (Xpd && Value->IsNull() && !((PJDEF)Tjp->To_Def)->Accept) + throw("Null expandable JSON value"); // Set null when applicable if (!Nullable) @@ -1579,11 +1582,11 @@ PVAL JSONCOL::GetColumnValue(PGLOBAL g, PJSON row, int i) else return CalculateArray(g, arp, i); - } else { - // Unexpected array, unwrap it as [0] - val = arp->GetValue(0); - i--; - } // endif's + } else { + // Unexpected array, unwrap it as [0] + val = arp->GetValue(0); + i--; + } // endif's break; case TYPE_JVAL: @@ -1612,17 +1615,17 @@ PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n) PJVAL jvp; JVALUE jval; - if (!ars) { - Value->Reset(); - Value->SetNull(true); - Tjp->NextSame = 0; - return Value; - } // endif ars + if (!ars) { + Value->Reset(); + Value->SetNull(true); + Tjp->NextSame = 0; + return Value; + } // endif ars if (!(jvp = arp->GetValue((Nodes[n].Rx = Nodes[n].Nx)))) { strcpy(g->Message, "Logical error expanding array"); - throw 666; - } // endif jvp + throw 666; + } // endif jvp if (n < Nod - 1 && jvp->GetJson()) { jval.SetValue(GetColumnValue(g, jvp->GetJson(), n + 1)); @@ -1637,7 +1640,7 @@ PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n) Xnod = n; Tjp->NextSame = Xnod; - } // endif NextSame + } // endif NextSame SetJsonValue(g, Value, jvp, n); return Value; @@ -1648,58 +1651,58 @@ PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n) /***********************************************************************/ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) { - int i, ars, nv = 0, nextsame = Tjp->NextSame; - bool err; + int i, ars, nv = 0, nextsame = Tjp->NextSame; + bool err; OPVAL op = Nodes[n].Op; PVAL val[2], vp = Nodes[n].Valp; PJVAL jvrp, jvp; JVALUE jval; vp->Reset(); - ars = MY_MIN(Tjp->Limit, arp->size()); + ars = MY_MIN(Tjp->Limit, arp->size()); - if (trace(1)) - htrc("CalculateArray: size=%d op=%d nextsame=%d\n", - ars, op, nextsame); + if (trace(1)) + htrc("CalculateArray: size=%d op=%d nextsame=%d\n", + ars, op, nextsame); - for (i = 0; i < ars; i++) { - jvrp = arp->GetValue(i); + for (i = 0; i < ars; i++) { + jvrp = arp->GetValue(i); - if (trace(1)) - htrc("i=%d nv=%d\n", i, nv); + if (trace(1)) + htrc("i=%d nv=%d\n", i, nv); - if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do { - if (jvrp->IsNull()) { - jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING); - jvp = jvrp; - } else if (n < Nod - 1 && jvrp->GetJson()) { + if (!jvrp->IsNull() || (op == OP_CNC && GetJsonNull())) do { + if (jvrp->IsNull()) { + jvrp->Value = AllocateValue(g, GetJsonNull(), TYPE_STRING); + jvp = jvrp; + } else if (n < Nod - 1 && jvrp->GetJson()) { Tjp->NextSame = nextsame; jval.SetValue(GetColumnValue(g, jvrp->GetJson(), n + 1)); jvp = &jval; } else jvp = jvrp; - - if (trace(1)) - htrc("jvp=%s null=%d\n", - jvp->GetString(g), jvp->IsNull() ? 1 : 0); - if (!nv++) { + if (trace(1)) + htrc("jvp=%s null=%d\n", + jvp->GetString(g), jvp->IsNull() ? 1 : 0); + + if (!nv++) { SetJsonValue(g, vp, jvp, n); continue; } else SetJsonValue(g, MulVal, jvp, n); - if (!MulVal->IsNull()) { - switch (op) { + if (!MulVal->IsNull()) { + switch (op) { case OP_CNC: if (Nodes[n].CncVal) { val[0] = Nodes[n].CncVal; err = vp->Compute(g, val, 1, op); } // endif CncVal - + val[0] = MulVal; err = vp->Compute(g, val, 1, op); - break; + break; // case OP_NUM: case OP_SEP: val[0] = Nodes[n].Valp; @@ -1714,16 +1717,16 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n) if (err) vp->Reset(); - - if (trace(1)) { - char buf(32); - htrc("vp='%s' err=%d\n", - vp->GetCharString(&buf), err ? 1 : 0); + if (trace(1)) { + char buf(32); - } // endif trace + htrc("vp='%s' err=%d\n", + vp->GetCharString(&buf), err ? 1 : 0); - } // endif Null + } // endif trace + + } // endif Null } while (Tjp->NextSame > nextsame); @@ -1753,8 +1756,8 @@ PJSON JSONCOL::GetRow(PGLOBAL g) PJAR arp; PJSON nwr, row = Tjp->Row; - for (int i = 0; i < Nod && row; i++) { - if (Nodes[i+1].Op == OP_XX) + for (int i = 0; i < Nod && row; i++) { + if (Nodes[i+1].Op == OP_XX) break; else switch (row->GetType()) { case TYPE_JOB: @@ -1765,19 +1768,19 @@ PJSON JSONCOL::GetRow(PGLOBAL g) val = ((PJOB)row)->GetValue(Nodes[i].Key); break; case TYPE_JAR: - arp = (PJAR)row; + arp = (PJAR)row; - if (!Nodes[i].Key) { + if (!Nodes[i].Key) { if (Nodes[i].Op == OP_EQ) val = arp->GetValue(Nodes[i].Rank); else val = arp->GetValue(Nodes[i].Rx); } else { - // Unexpected array, unwrap it as [0] - val = arp->GetValue(0); - i--; - } // endif Nodes + // Unexpected array, unwrap it as [0] + val = arp->GetValue(0); + i--; + } // endif Nodes break; case TYPE_JVAL: @@ -1827,10 +1830,10 @@ PJSON JSONCOL::GetRow(PGLOBAL g) /***********************************************************************/ void JSONCOL::WriteColumn(PGLOBAL g) { - if (Xpd && Tjp->Pretty < 2) { - strcpy(g->Message, "Cannot write expanded column when Pretty is not 2"); - throw 666; - } // endif Xpd + if (Xpd && Tjp->Pretty < 2) { + strcpy(g->Message, "Cannot write expanded column when Pretty is not 2"); + throw 666; + } // endif Xpd /*********************************************************************/ /* Check whether this node must be written. */ @@ -1864,8 +1867,8 @@ void JSONCOL::WriteColumn(PGLOBAL g) if (!(jsp = ParseJson(G, s, (int)strlen(s)))) { strcpy(g->Message, s); - throw 666; - } // endif jsp + throw 666; + } // endif jsp if (arp) { if (Nod > 1 && Nodes[Nod-2].Op == OP_EQ) @@ -1887,10 +1890,10 @@ void JSONCOL::WriteColumn(PGLOBAL g) // fall through case TYPE_DATE: case TYPE_INT: - case TYPE_TINY: - case TYPE_SHORT: - case TYPE_BIGINT: - case TYPE_DOUBLE: + case TYPE_TINY: + case TYPE_SHORT: + case TYPE_BIGINT: + case TYPE_DOUBLE: if (arp) { if (Nodes[Nod-1].Op == OP_EQ) arp->SetValue(G, new(G) JVALUE(G, Value), Nodes[Nod-1].Rank); @@ -1981,7 +1984,7 @@ int TDBJSON::MakeDocument(PGLOBAL g) return RC_OK; /*********************************************************************/ - /* Create the mapping file object in mode read. */ + /* Create the mapping file object in mode read. */ /*********************************************************************/ Mode = MODE_READ; @@ -2010,70 +2013,70 @@ int TDBJSON::MakeDocument(PGLOBAL g) if (!jsp && g->Message[0]) return RC_FX; - if ((objpath = PlugDup(g, Objname))) { - if (*objpath == '$') objpath++; - if (*objpath == '.') objpath++; - - /*********************************************************************/ - /* Find the table in the tree structure. */ - /*********************************************************************/ - for (; jsp && objpath; objpath = p) { - if ((p = strchr(objpath, Sep))) - *p++ = 0; - - if (*objpath != '[' && !IsNum(objpath)) { - // objpass is a key - if (jsp->GetType() != TYPE_JOB) { - strcpy(g->Message, "Table path does not match the json file"); - return RC_FX; - } // endif Type - - key = objpath; - objp = jsp->GetObject(); - arp = NULL; - val = objp->GetValue(key); - - if (!val || !(jsp = val->GetJson())) { - sprintf(g->Message, "Cannot find object key %s", key); - return RC_FX; - } // endif val - - } else { - if (*objpath == '[') { - // Old style - if (objpath[strlen(objpath) - 1] != ']') { - sprintf(g->Message, "Invalid Table path %s", Objname); - return RC_FX; - } else - objpath++; - - } // endif objpath - - if (jsp->GetType() != TYPE_JAR) { - strcpy(g->Message, "Table path does not match the json file"); - return RC_FX; - } // endif Type - - arp = jsp->GetArray(); - objp = NULL; - i = atoi(objpath) - B; - val = arp->GetValue(i); - - if (!val) { - sprintf(g->Message, "Cannot find array value %d", i); - return RC_FX; - } // endif val - - } // endif - - jsp = val->GetJson(); - } // endfor objpath - - } // endif objpath + if ((objpath = PlugDup(g, Objname))) { + if (*objpath == '$') objpath++; + if (*objpath == '.') objpath++; + + /*********************************************************************/ + /* Find the table in the tree structure. */ + /*********************************************************************/ + for (; jsp && objpath; objpath = p) { + if ((p = strchr(objpath, Sep))) + *p++ = 0; + + if (*objpath != '[' && !IsNum(objpath)) { + // objpass is a key + if (jsp->GetType() != TYPE_JOB) { + strcpy(g->Message, "Table path does not match the json file"); + return RC_FX; + } // endif Type + + key = objpath; + objp = jsp->GetObject(); + arp = NULL; + val = objp->GetValue(key); + + if (!val || !(jsp = val->GetJson())) { + sprintf(g->Message, "Cannot find object key %s", key); + return RC_FX; + } // endif val + + } else { + if (*objpath == '[') { + // Old style + if (objpath[strlen(objpath) - 1] != ']') { + sprintf(g->Message, "Invalid Table path %s", Objname); + return RC_FX; + } else + objpath++; + + } // endif objpath + + if (jsp->GetType() != TYPE_JAR) { + strcpy(g->Message, "Table path does not match the json file"); + return RC_FX; + } // endif Type + + arp = jsp->GetArray(); + objp = NULL; + i = atoi(objpath) - B; + val = arp->GetValue(i); + + if (!val) { + sprintf(g->Message, "Cannot find array value %d", i); + return RC_FX; + } // endif val + + } // endif + + jsp = val->GetJson(); + } // endfor objpath + + } // endif objpath if (jsp && jsp->GetType() == TYPE_JAR) Doc = jsp->GetArray(); - else { + else { // The table is void or is just one object or one value Doc = new(g) JARRAY; @@ -2149,7 +2152,7 @@ int TDBJSON::MakeIndex(PGLOBAL g, PIXDEF pxdf, bool) } else return RC_OK; - } // end of MakeIndex + } // end of MakeIndex /***********************************************************************/ /* Return the position in the table. */ @@ -2227,11 +2230,11 @@ bool TDBJSON::OpenDB(PGLOBAL g) return true; } // endswitch Jmode - if (Xcol) - To_Filter = NULL; // Imcompatible + if (Xcol) + To_Filter = NULL; // Imcompatible - Use = USE_OPEN; - return false; + Use = USE_OPEN; + return false; } // end of OpenDB /***********************************************************************/ @@ -2241,7 +2244,7 @@ int TDBJSON::ReadDB(PGLOBAL) { int rc; - N++; + N++; if (NextSame) { SameRow = NextSame; @@ -2352,8 +2355,8 @@ void TDBJSON::CloseDB(PGLOBAL g) TDBJCL::TDBJCL(PJDEF tdp) : TDBCAT(tdp) { Topt = tdp->GetTopt(); - Db = tdp->Schema; - Dsn = tdp->Uri; + Db = tdp->Schema; + Dsn = tdp->Uri; } // end of TDBJCL constructor /***********************************************************************/ diff --git a/storage/connect/tabrest.cpp b/storage/connect/tabrest.cpp index e800411a36d..9e1a643c89f 100644 --- a/storage/connect/tabrest.cpp +++ b/storage/connect/tabrest.cpp @@ -1,13 +1,23 @@ /*************** Rest C++ Program Source Code File (.CPP) **************/ -/* PROGRAM NAME: Rest Version 1.3 */ +/* PROGRAM NAME: Rest Version 1.5 */ /* (C) Copyright to the author Olivier BERTRAND 2018 - 2019 */ -/* This program is the REST OEM (Web API support) module definition. */ +/* This program is the REST Web API support for MariaDB. */ +/* When compiled without MARIADB defined, it is the EOM module code. */ /***********************************************************************/ /***********************************************************************/ /* Definitions needed by the included files. */ /***********************************************************************/ +#if defined(MARIADB) #include // All MariaDB stuff +#else // !MARIADB OEM module +#include "mini-global.h" +#define _MAX_PATH 260 +#if !defined(__WIN__) +#define __stdcall +#endif // !__WIN__ +#define _OS_H_INCLUDED // Prevent os.h to be called +#endif // !MARIADB /***********************************************************************/ /* Include application header files: */ @@ -19,12 +29,12 @@ #include "plgdbsem.h" #include "xtable.h" #include "filamtxt.h" -#include "plgxml.h" #include "tabdos.h" -#include "tabfmt.h" +#include "plgxml.h" +#include "tabxml.h" #include "tabjson.h" +#include "tabfmt.h" #include "tabrest.h" -#include "tabxml.h" /***********************************************************************/ /* Get the file from the Web. */ @@ -32,25 +42,61 @@ int restGetFile(PGLOBAL g, PCSZ http, PCSZ uri, PCSZ fn); #if defined(__WIN__) -static PCSZ slash= "\\"; +static PCSZ slash = "\\"; #else // !__WIN__ -static PCSZ slash= "/"; +static PCSZ slash = "/"; #define stricmp strcasecmp #endif // !__WIN__ +#if !defined(MARIADB) +/***********************************************************************/ +/* DB static variables. */ +/***********************************************************************/ +int TDB::Tnum; +int DTVAL::Shift; +int CSORT::Limit = 0; +double CSORT::Lg2 = log(2.0); +size_t CSORT::Cpn[1000] = { 0 }; + +/***********************************************************************/ +/* These functions are exported from the REST library. */ +/***********************************************************************/ +extern "C" { + PTABDEF __stdcall GetREST(PGLOBAL, void*); + PQRYRES __stdcall ColREST(PGLOBAL, PTOS, char*, char*, bool); +} // extern "C" + +/***********************************************************************/ +/* This function returns a table definition class. */ +/***********************************************************************/ +PTABDEF __stdcall GetREST(PGLOBAL g, void *memp) +{ + return new(g, memp) RESTDEF; +} // end of GetREST +#endif // !MARIADB + /***********************************************************************/ /* Return the columns definition to MariaDB. */ /***********************************************************************/ +#if defined(MARIADB) PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) +#else // !MARIADB +PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) +#endif // !MARIADB { PQRYRES qrp= NULL; - char filename[_MAX_PATH]; + char filename[_MAX_PATH + 1]; // MAX PATH ??? PCSZ http, uri, fn, ftype; - http= GetStringTableOption(g, tp, "Http", NULL); - uri= GetStringTableOption(g, tp, "Uri", NULL); - fn= GetStringTableOption(g, tp, "Filename", "rest.json"); - ftype = GetStringTableOption(g, tp, "Type", "JSON"); + http = GetStringTableOption(g, tp, "Http", NULL); + uri = GetStringTableOption(g, tp, "Uri", NULL); + fn = GetStringTableOption(g, tp, "Filename", "rest.json"); +#if defined(MARIADB) + ftype = GetStringTableOption(g, tp, "Type", "JSON"); +#else // !MARIADB + // OEM tables must specify the file type + ftype = GetStringTableOption(g, tp, "Ftype", "JSON"); +#endif // !MARIADB // We used the file name relative to recorded datapath strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash); @@ -60,11 +106,11 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) if (http && restGetFile(g, http, uri, filename)) { // sprintf(g->Message, "Failed to get file at %s", http); } else if (!stricmp(ftype, "XML")) - qrp= XMLColumns(g, db, tab, tp, info); + qrp = XMLColumns(g, db, tab, tp, info); else if (!stricmp(ftype, "JSON")) - qrp= JSONColumns(g, db, NULL, tp, info); + qrp = JSONColumns(g, db, NULL, tp, info); else if (!stricmp(ftype, "CSV")) - qrp= CSVColumns(g, NULL, tp, info); + qrp = CSVColumns(g, NULL, tp, info); else sprintf(g->Message, "Usupported file type %s", ftype); @@ -78,40 +124,59 @@ PQRYRES RESTColumns(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) /***********************************************************************/ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { - char filename[_MAX_PATH]; - TABTYPE type= GetTypeID(am); - - switch (type) { - case TAB_JSON: - case TAB_XML: - case TAB_CSV: - break; - default: - sprintf(g->Message, "Unsupported REST table type %s", am); - return true; - } // endswitch type - - Http= GetStringCatInfo(g, "Http", NULL); - Uri= GetStringCatInfo(g, "Uri", NULL); - Fn= GetStringCatInfo(g, "Filename", "rest.json"); + char filename[_MAX_PATH + 1]; + int rc = 0, n; + LPCSTR ftype; + +#if defined(MARIADB) + ftype = GetStringCatInfo(g, "Type", "JSON"); +#else // !MARIADB + // OEM tables must specify the file type + ftype = GetStringCatInfo(g, "Ftype", "JSON"); +#endif // !MARIADB + + if (trace(515)) + htrc("ftype = %s am = %s\n", ftype, SVP(am)); + + n = (!stricmp(ftype, "JSON")) ? 1 + : (!stricmp(ftype, "XML")) ? 2 + : (!stricmp(ftype, "CSV")) ? 3 : 0; + + if (n == 0) { + htrc("DefineAM: Unsupported REST table type %s", am); + sprintf(g->Message, "Unsupported REST table type %s", am); + return true; + } // endif n + + Http = GetStringCatInfo(g, "Http", NULL); + Uri = GetStringCatInfo(g, "Uri", NULL); + Fn = GetStringCatInfo(g, "Filename", "rest.json"); // We used the file name relative to recorded datapath - PlugSetPath(filename, Fn, GetPath()); + //PlugSetPath(filename, Fn, GetPath()); + strncat(strcpy(filename, GetPath()), Fn, _MAX_PATH); // Retrieve the file from the web and copy it locally - if (Http && restGetFile(g, Http, Uri, filename)) {} - else if (type == TAB_JSON) - Tdp= new (g) JSONDEF; - else if (type == TAB_XML) - Tdp= new (g) XMLDEF; - else if (type == TAB_CSV) - Tdp= new (g) CSVDEF; - else - sprintf(g->Message, "Unsupported REST table type %s", am); + rc = restGetFile(g, Http, Uri, filename); + + if (trace(515)) + htrc("Return from restGetFile: rc=%d\n", rc); + + if (rc) + return true; + else switch (n) { + case 1: Tdp = new (g) JSONDEF; break; + case 2: Tdp = new (g) XMLDEF; break; + case 3: Tdp = new (g) CSVDEF; break; + default: Tdp = NULL; + } // endswitch n // Do make the table/view definition if (Tdp && Tdp->Define(g, Cat, Name, Schema, "REST")) - Tdp= NULL; // Error occured + Tdp = NULL; // Error occured + + if (trace(515)) + htrc("Tdp defined\n", rc); // Return true in case of error return (Tdp == NULL); @@ -122,10 +187,13 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ PTDB RESTDEF::GetTable(PGLOBAL g, MODE m) { - if (m != MODE_READ && m != MODE_READX) { - strcpy(g->Message, "REST tables are currently read only"); - return NULL; - } // endif m + if (trace(515)) + htrc("REST GetTable mode=%d\n", m); + + if (m != MODE_READ && m != MODE_READX) { + strcpy(g->Message, "REST tables are currently read only"); + return NULL; + } // endif m return Tdp->GetTable(g, m); // Leave file type do the job } // end of GetTable diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index b2dbdd70e06..1150824464f 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -281,7 +281,7 @@ bool TDBTBL::InitTableList(PGLOBAL g) } // endfor tp - hc->get_table()->s->connect_string.str = scs; + hc->get_table()->s->connect_string.str = (char*)scs; hc->get_table()->s->connect_string.length = sln; //NumTables = n; -- cgit v1.2.1 From 672cc34cf5a5ec695202f904058b91fed0c5b536 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 22 Aug 2019 23:24:27 +0200 Subject: Fix change in xml2 test result --- storage/connect/mysql-test/connect/r/xml2.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/connect/mysql-test/connect/r/xml2.result b/storage/connect/mysql-test/connect/r/xml2.result index f7bbc17c8a0..b8075fa1928 100644 --- a/storage/connect/mysql-test/connect/r/xml2.result +++ b/storage/connect/mysql-test/connect/r/xml2.result @@ -325,7 +325,7 @@ HEX(c) 3F3F3F3F3F3F3F Warnings: Level Warning Code 1366 -Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column `test`.`t1`.`c` at row 1 +Message Incorrect string value: '\xC3\x81\xC3\x82\xC3\x83...' for column 'c' at row 1 Level Warning Code 1105 Message Out of range value ÁÂÃÄÅÆÇ for column 'c' at row 1 -- cgit v1.2.1 From afc21ab6d8e785299e0d9e5339b8c94a90b3355c Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 23 Nov 2019 16:11:46 +0100 Subject: Commit some changes before pulling from origin CMakeLists.txt connect.cc --- storage/connect/CMakeLists.txt | 77 +++++++++++++++++++++++++----------------- storage/connect/connect.cc | 3 ++ 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index fd006e104c1..5c870be5ef6 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -40,6 +40,10 @@ user_connect.h valblk.h value.h xindex.h xobject.h xtable.h) add_definitions( -DMARIADB -DFORCE_INIT_OF_VARS -Dconnect_EXPORTS) add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT ) +macro(DISABLE_WARNING W) + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-error=${W}") + MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-${W}" DEBUG) +endmacro() # # OS specific C flags, definitions and source files. @@ -47,14 +51,15 @@ add_definitions( -DHUGE_SUPPORT -DGZ_SUPPORT ) IF(UNIX) MY_CHECK_AND_SET_COMPILER_FLAG("-Wall -Wmissing-declarations") if(NOT WITH_WARNINGS) - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-function") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-variable") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-value") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-parentheses") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-misleading-indentation") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-format-truncation") - MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-implicit-fallthrough") + DISABLE_WARNING("unused-function") + DISABLE_WARNING("unused-variable") + DISABLE_WARNING("unused-value") + DISABLE_WARNING("parentheses") + DISABLE_WARNING("strict-aliasing") + DISABLE_WARNING("misleading-indentation") + DISABLE_WARNING("format-truncation") + DISABLE_WARNING("implicit-fallthrough") + DISABLE_WARNING("type-limits") endif(NOT WITH_WARNINGS) add_definitions( -DUNIX -DLINUX -DUBUNTU ) @@ -68,10 +73,6 @@ ELSE(NOT UNIX) tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h) # Add exception handling to the CONNECT project) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") - SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") - SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD") - SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MD") SET(IPHLPAPI_LIBRARY iphlpapi.lib) IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang)) # Connect does not work with clang-cl @@ -171,7 +172,8 @@ IF(CONNECT_WITH_ODBC) # the library 'libiodbc' gets compiled with 'sql'h. # This will also need changes in the sources (e.g. #include ). - find_path(ODBC_INCLUDE_DIR sql.h + find_file(ODBC_INCLUDES sql.h + PATHS /usr/include /usr/include/odbc /usr/local/include @@ -181,7 +183,7 @@ IF(CONNECT_WITH_ODBC) #"C:/Program Files/Microsoft SDKs/Windows/v7.0A/include" #"C:/Program Files/Microsoft SDKs/Windows/v6.0a/include" #"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/include" - DOC "Specify the directory containing sql.h." + DOC "Specify the path to sql.h." ) find_library(ODBC_LIBRARY @@ -200,9 +202,10 @@ IF(CONNECT_WITH_ODBC) DOC "Specify the ODBC driver manager library here." ) - mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR) + mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDES) - IF(ODBC_INCLUDE_DIR AND ODBC_LIBRARY) + IF(ODBC_INCLUDES AND ODBC_LIBRARY) + get_filename_component(ODBC_INCLUDE_DIR "${ODBC_INCLUDES}" PATH) set(CMAKE_REQUIRED_LIBRARIES ${ODBC_LIBRARY}) set(CMAKE_REQUIRED_INCLUDES ${ODBC_INCLUDE_DIR}) CHECK_CXX_SOURCE_COMPILES( @@ -307,7 +310,6 @@ IF(CONNECT_WITH_MONGO) ENDIF(libmongoc-1.0_FOUND) ENDIF(CONNECT_WITH_MONGO) - # # REST # @@ -324,6 +326,11 @@ IF(CONNECT_WITH_REST) # If needed edit next line to set the path to libcpprest.so SET(REST_LIBRARY -lcpprest) MESSAGE (STATUS ${REST_LIBRARY}) + ELSE(NOT UNIX) +# Next line sets debug compile mode matching cpprest_2_10d.dll +# when it was binary installed (can be change later in Visual Studio) +# Comment it out if not needed depending on your cpprestsdk installation. + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") ENDIF(UNIX) SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) add_definitions(-DREST_SUPPORT) @@ -351,32 +358,41 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES} COMPONENT connect-engine RECOMPILE_FOR_EMBEDDED LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY} - ${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY} ${REST_LIBRARY}) + ${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY}) IF(NOT TARGET connect) RETURN() ENDIF() +# Don't link with bundled zlib and systel libxml2 at the same time. +# System libxml2 uses system zlib, might conflict with the bundled one. +IF (XML_LIBRARY AND BUILD_BUNDLED_ZLIB) + GET_PROPERTY(INCS TARGET connect PROPERTY INCLUDE_DIRECTORIES) + LIST(REMOVE_ITEM INCS ${ZLIB_INCLUDE_DIR}) + SET_PROPERTY(TARGET connect PROPERTY INCLUDE_DIRECTORIES ${INCS}) +ENDIF() + IF(WIN32) IF (libmongoc-1.0_FOUND) - SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS - "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") + SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS + "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") ENDIF(libmongoc-1.0_FOUND) -ENDIF(WIN32) # Install some extra files that belong to connect engine -IF(WIN32) - # install ha_connect.lib - GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION) - STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION}) - IF(CMAKE_CONFIGURATION_TYPES) - STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" - CONNECT_LIB ${CONNECT_LIB}) - ENDIF() - INSTALL(FILES ${CONNECT_LIB} + + INSTALL(FILES "$/ha_connect.lib" DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF(WIN32) +IF(MSVC) + # Temporarily disable "conversion from size_t .." + IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") + ENDIF() + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") + string(REPLACE "/permissive-" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +ENDIF() + IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND) # TODO: Find how to compile and install the java wrapper classes # Find required libraries and include directories @@ -387,4 +403,3 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF() - diff --git a/storage/connect/connect.cc b/storage/connect/connect.cc index b1078de8eaa..a8d9216983a 100644 --- a/storage/connect/connect.cc +++ b/storage/connect/connect.cc @@ -389,6 +389,9 @@ RCODE EvalColumns(PGLOBAL g, PTDB tdbp, bool reset, bool mrr) try { for (colp = tdbp->GetColumns(); rc == RC_OK && colp; colp = colp->GetNext()) { + xtrc(2, "Going to read column %s of table %s\n", + colp->GetName(), tdbp->GetName()); + if (reset) colp->Reset(); -- cgit v1.2.1 From 4ba36cfa0c677b7d094092d6aa5541c6c936a11f Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 12 Mar 2020 19:06:03 +0100 Subject: - Fix https://stackoverflow.com/questions/60625778/import-complex-xml-from-multiple-files-in-mariadb/60637429#60637429 Import complex XML from multiple files in MariaDB Some row results are missing and replaced by the last file one. Thats because Nx and Sx column members are not reset when changing file. modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h --- storage/connect/ha_connect.cc | 8 ++++---- storage/connect/tabxml.cpp | 15 ++++++++++----- storage/connect/tabxml.h | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index a7bfcd2149b..da9c41ba247 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -2962,10 +2962,10 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) case Item_func::LE_FUNC: vop= OP_LE; break; case Item_func::GE_FUNC: vop= OP_GE; break; case Item_func::GT_FUNC: vop= OP_GT; break; - case Item_func::LIKE_FUNC: - vop= OP_LIKE; - neg= ((Item_func_opt_neg *)condf)->negated; - break; + //case Item_func::LIKE_FUNC: + // vop= OP_LIKE; + // neg= ((Item_func_like *)condf)->negated; + // break; case Item_func::ISNOTNULL_FUNC: neg= true; // fall through diff --git a/storage/connect/tabxml.cpp b/storage/connect/tabxml.cpp index 19490d350e8..68941c67be8 100644 --- a/storage/connect/tabxml.cpp +++ b/storage/connect/tabxml.cpp @@ -240,7 +240,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) more: if (vp->atp) { - strncpy(colname, vp->atp->GetName(g), sizeof(colname)); + size_t z = sizeof(colname) - 1; + strncpy(colname, vp->atp->GetName(g), z); + colname[z] = 0; strncat(xcol->Name, colname, XLEN(xcol->Name)); switch (vp->atp->GetText(g, buf, sizeof(buf))) { @@ -811,12 +813,15 @@ bool TDBXML::Initialize(PGLOBAL g) if (Void) return false; - if (Columns && !Bufdone) { + if (Columns) { // Allocate the buffers that will contain node values for (colp = (PXMLCOL)Columns; colp; colp = (PXMLCOL)colp->GetNext()) - if (!colp->IsSpecial()) // Not a pseudo column - if (colp->AllocBuf(g, Mode == MODE_INSERT)) - return true; + if (!colp->IsSpecial()) { // Not a pseudo column + if (!Bufdone && colp->AllocBuf(g, Mode == MODE_INSERT)) + return true; + + colp->Nx = colp->Sx = -1; + } // endif Special Bufdone = true; } // endif Bufdone diff --git a/storage/connect/tabxml.h b/storage/connect/tabxml.h index fb3913f08ea..42dbb038b47 100644 --- a/storage/connect/tabxml.h +++ b/storage/connect/tabxml.h @@ -157,6 +157,7 @@ class DllExport TDBXML : public TDBASE { /* Class XMLCOL: XDB table access method column descriptor. */ /***********************************************************************/ class XMLCOL : public COLBLK { + friend class TDBXML; public: // Constructors XMLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PCSZ am = "XML"); -- cgit v1.2.1 From 4a8b55330c94dc9bd8c90bc5651723efe168fc39 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 12 Mar 2020 19:36:54 +0100 Subject: Resolved ha_connect.cc and CMakeLists.txt --- storage/connect/CMakeLists.txt | 63 +++++++++--------------------------------- storage/connect/ha_connect.cc | 7 ----- 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 916aa1aad3e..7eedba08bee 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -310,34 +310,6 @@ IF(CONNECT_WITH_MONGO) ENDIF(libmongoc-1.0_FOUND) ENDIF(CONNECT_WITH_MONGO) -# -# REST -# - -OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) - -IF(CONNECT_WITH_REST) - MESSAGE(STATUS "=====> REST support is ON") - FIND_PACKAGE(cpprestsdk) - IF (cpprestsdk_FOUND) - MESSAGE(STATUS "=====> cpprestsdk found") - IF(UNIX) -# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR}) -# If needed edit next line to set the path to libcpprest.so - SET(REST_LIBRARY -lcpprest) - MESSAGE (STATUS ${REST_LIBRARY}) - ELSE(NOT UNIX) -# Next line sets debug compile mode matching cpprest_2_10d.dll -# when it was binary installed (can be change later in Visual Studio) -# Comment it out if not needed depending on your cpprestsdk installation. - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") - ENDIF(UNIX) - SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp restget.cpp tabrest.h) - add_definitions(-DREST_SUPPORT) - ELSE(NOT cpprestsdk_FOUND) - MESSAGE(STATUS "=====> cpprestsdk package not found") - ENDIF (cpprestsdk_FOUND) -ENDIF(CONNECT_WITH_REST) # # REST @@ -346,7 +318,7 @@ ENDIF(CONNECT_WITH_REST) OPTION(CONNECT_WITH_REST "Compile CONNECT storage engine with REST support" ON) IF(CONNECT_WITH_REST) - MESSAGE(STATUS "=====> REST support is ON") +# MESSAGE(STATUS "=====> REST support is ON") SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp tabrest.h) add_definitions(-DREST_SUPPORT) FIND_PACKAGE(cpprestsdk QUIET) @@ -366,8 +338,8 @@ IF(CONNECT_WITH_REST) SET(CONNECT_SOURCES ${CONNECT_SOURCES} restget.cpp) add_definitions(-DREST_SOURCE) # ENDIF() - ELSE(NOT cpprestsdk_FOUND) -# MESSAGE(STATUS "=====> cpprestsdk package not found") +# ELSE(NOT cpprestsdk_FOUND) +# MESSAGE(STATUS "=====> cpprestsdk package not found") ENDIF (cpprestsdk_FOUND) ENDIF(CONNECT_WITH_REST) @@ -396,35 +368,26 @@ IF(NOT TARGET connect) RETURN() ENDIF() -# Don't link with bundled zlib and systel libxml2 at the same time. -# System libxml2 uses system zlib, might conflict with the bundled one. -IF (XML_LIBRARY AND BUILD_BUNDLED_ZLIB) - GET_PROPERTY(INCS TARGET connect PROPERTY INCLUDE_DIRECTORIES) - LIST(REMOVE_ITEM INCS ${ZLIB_INCLUDE_DIR}) - SET_PROPERTY(TARGET connect PROPERTY INCLUDE_DIRECTORIES ${INCS}) -ENDIF() - IF(WIN32) IF (libmongoc-1.0_FOUND) SET_TARGET_PROPERTIES(connect PROPERTIES LINK_FLAGS "/DELAYLOAD:libbson-1.0.dll /DELAYLOAD:libmongoc-1.0.dll") ENDIF(libmongoc-1.0_FOUND) +ENDIF(WIN32) # Install some extra files that belong to connect engine - - INSTALL(FILES "$/ha_connect.lib" +IF(WIN32) + # install ha_connect.lib + GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION) + STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION}) + IF(CMAKE_CONFIGURATION_TYPES) + STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" + CONNECT_LIB ${CONNECT_LIB}) + ENDIF() + INSTALL(FILES ${CONNECT_LIB} DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine) ENDIF(WIN32) -IF(MSVC) - # Temporarily disable "conversion from size_t .." - IF(CMAKE_SIZEOF_VOID_P EQUAL 8) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267") - ENDIF() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4996") - string(REPLACE "/permissive-" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -ENDIF() - IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND) # TODO: Find how to compile and install the java wrapper classes # Find required libraries and include directories diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index d64ed0022ed..d1b409e5143 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -2968,19 +2968,12 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) case Item_func::LE_FUNC: vop= OP_LE; break; case Item_func::GE_FUNC: vop= OP_GE; break; case Item_func::GT_FUNC: vop= OP_GT; break; -<<<<<<< HEAD - //case Item_func::LIKE_FUNC: - // vop= OP_LIKE; - // neg= ((Item_func_like *)condf)->negated; - // break; -======= #if MYSQL_VERSION_ID > 100200 case Item_func::LIKE_FUNC: vop = OP_LIKE; neg= ((Item_func_like*)condf)->negated; break; #endif // VERSION_ID > 100200 ->>>>>>> 51e9381dcc01ebd72d4f0adc057a64213f850d70 case Item_func::ISNOTNULL_FUNC: neg= true; // fall through -- cgit v1.2.1 From 45b9fa4a8a4936fb5a12079fcd88f5a15511c1c0 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Thu, 12 Mar 2020 23:25:18 +0100 Subject: Fix compile error in tabcmg.cpp --- storage/connect/ha_connect.cc | 4 ---- storage/connect/tabcmg.cpp | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index d1b409e5143..20f96d03f32 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,11 +170,7 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { -<<<<<<< HEAD - char version[]= "Version 1.06.0010 August 22, 2019"; -======= char version[]= "Version 1.07.0001 November 12, 2019"; ->>>>>>> 51e9381dcc01ebd72d4f0adc057a64213f850d70 #if defined(__WIN__) char compver[]= "Version 1.07.0001 " __DATE__ " " __TIME__; char slash= '\\'; diff --git a/storage/connect/tabcmg.cpp b/storage/connect/tabcmg.cpp index b9b7f6e4b60..f2ff721627c 100644 --- a/storage/connect/tabcmg.cpp +++ b/storage/connect/tabcmg.cpp @@ -26,6 +26,8 @@ #include "tabmul.h" #include "filter.h" +PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info); + /* -------------------------- Class CMGDISC -------------------------- */ /***********************************************************************/ -- cgit v1.2.1 From 674197e2ff3bd8c15e8784ba1f5ac3e73e7104a9 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 14 Mar 2020 18:08:15 +0100 Subject: Disable set warnings as errors for Windows --- storage/connect/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/connect/CMakeLists.txt b/storage/connect/CMakeLists.txt index 7eedba08bee..f4b139aa705 100644 --- a/storage/connect/CMakeLists.txt +++ b/storage/connect/CMakeLists.txt @@ -73,6 +73,7 @@ ELSE(NOT UNIX) tabwmi.cpp tabwmi.h tabmac.cpp tabmac.h macutil.cpp macutil.h) # Add exception handling to the CONNECT project) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX-") SET(IPHLPAPI_LIBRARY iphlpapi.lib) IF(MSVC AND (CMAKE_CXX_COMPILER_ID MATCHES Clang)) # Connect does not work with clang-cl -- cgit v1.2.1 From e3163524eab5b6d6853ece6b31c3b39dc2f7646a Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Mon, 18 May 2020 23:52:33 +0200 Subject: - Fix MDEV-22571 and MDEV-22572. Allow multiple ZIP table and enable using special column in them. modified: storage/connect/tabzip.cpp modified: storage/connect/tabzip.h --- storage/connect/tabzip.cpp | 13 +++++++++++-- storage/connect/tabzip.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/storage/connect/tabzip.cpp b/storage/connect/tabzip.cpp index c026744dba8..d9c13e2a58a 100644 --- a/storage/connect/tabzip.cpp +++ b/storage/connect/tabzip.cpp @@ -23,6 +23,7 @@ #include "filamzip.h" #include "resource.h" // for IDS_COLUMNS #include "tabdos.h" +#include "tabmul.h" #include "tabzip.h" /* -------------------------- Class ZIPDEF --------------------------- */ @@ -41,7 +42,14 @@ bool ZIPDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ PTDB ZIPDEF::GetTable(PGLOBAL g, MODE m) { - return new(g) TDBZIP(this); + PTDB tdbp = NULL; + + tdbp = new(g) TDBZIP(this); + + if (Multiple) + tdbp = new(g) TDBMUL(tdbp); + + return tdbp; } // end of GetTable /* ------------------------------------------------------------------- */ @@ -108,7 +116,7 @@ int TDBZIP::Cardinality(PGLOBAL g) Cardinal = (err == UNZ_OK) ? (int)ginfo.number_entry : 0; } else - Cardinal = 0; + Cardinal = 10; // Dummy for multiple tables } // endif Cardinal @@ -187,6 +195,7 @@ int TDBZIP::DeleteDB(PGLOBAL g, int irc) void TDBZIP::CloseDB(PGLOBAL g) { close(); + nexterr = UNZ_OK; // For multiple tables Use = USE_READY; // Just to be clean } // end of CloseDB diff --git a/storage/connect/tabzip.h b/storage/connect/tabzip.h index 32b15281f81..d36e4dc01d0 100644 --- a/storage/connect/tabzip.h +++ b/storage/connect/tabzip.h @@ -48,6 +48,8 @@ public: // Implementation virtual AMT GetAmType(void) {return TYPE_AM_ZIP;} + virtual PCSZ GetFile(PGLOBAL) {return zfn;} + virtual void SetFile(PGLOBAL, PCSZ fn) {zfn = fn;} // Methods virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); -- cgit v1.2.1 From cc6bba008d750196b8537025ab48d5f8e274bbcd Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 20 Oct 2021 10:21:00 +0200 Subject: MDEV-26647 (plugin name) Include password validation plugin information in the error message if the SQL statement is not satisfied password policy Add plugin name to the error message. --- .../plugins/r/binlog-simple_plugin_check.result | 2 +- .../suite/plugins/r/cracklib_password_check.result | 18 ++++++------- .../suite/plugins/r/simple_password_check.result | 30 +++++++++++----------- .../plugins/r/two_password_validations.result | 8 +++--- sql/share/errmsg-utf8.txt | 3 ++- sql/sql_acl.cc | 8 ++++-- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/mysql-test/suite/plugins/r/binlog-simple_plugin_check.result b/mysql-test/suite/plugins/r/binlog-simple_plugin_check.result index 6c960ee325c..1cba628db07 100644 --- a/mysql-test/suite/plugins/r/binlog-simple_plugin_check.result +++ b/mysql-test/suite/plugins/r/binlog-simple_plugin_check.result @@ -8,7 +8,7 @@ simple_password_check # CREATE USER user1@localhost IDENTIFIED BY 'BsG9#9.cem#!85'; CREATE USER user2@localhost IDENTIFIED BY 'bsg9#d.cem#!85'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) DROP USER user1@localhost; include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info diff --git a/mysql-test/suite/plugins/r/cracklib_password_check.result b/mysql-test/suite/plugins/r/cracklib_password_check.result index 6b4e30b3d81..8eb730355ca 100644 --- a/mysql-test/suite/plugins/r/cracklib_password_check.result +++ b/mysql-test/suite/plugins/r/cracklib_password_check.result @@ -14,29 +14,29 @@ LOAD_OPTION ON PLUGIN_MATURITY Stable PLUGIN_AUTH_VERSION 1.0 grant select on *.* to foocar identified by 'foocar'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) show warnings; Level Code Message Warning 1819 cracklib: it is based on your username -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (cracklib_password_check) grant select on *.* to foocar identified by 'racoof'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) show warnings; Level Code Message Warning 1819 cracklib: it is based on your username -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (cracklib_password_check) grant select on *.* to foo@barbar identified by 'barbar'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) show warnings; Level Code Message Warning 1819 cracklib: it does not contain enough DIFFERENT characters -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (cracklib_password_check) grant select on *.* to foobar identified by 'qwerty'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) show warnings; Level Code Message Warning 1819 cracklib: it is based on a dictionary word -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (cracklib_password_check) grant select on *.* to foobar identified by 'q$%^&*rty'; drop user foobar; # @@ -44,7 +44,7 @@ drop user foobar; # when using cracklib plugin # create user 'newuser'@'localhost'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) uninstall plugin cracklib_password_check; create user foo1 identified by 'pwd'; drop user foo1; diff --git a/mysql-test/suite/plugins/r/simple_password_check.result b/mysql-test/suite/plugins/r/simple_password_check.result index 672d0107492..11005020fe7 100644 --- a/mysql-test/suite/plugins/r/simple_password_check.result +++ b/mysql-test/suite/plugins/r/simple_password_check.result @@ -71,13 +71,13 @@ ENUM_VALUE_LIST NULL READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED create user foo1 identified by 'pwd'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) create user foo1; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to foo1 identified by 'pwd'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to `FooBar1!` identified by 'FooBar1!'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to `BarFoo1!` identified by 'FooBar1!'; drop user `BarFoo1!`; create user foo1 identified by 'aA.12345'; @@ -99,28 +99,28 @@ simple_password_check_other_characters 3 create user foo1 identified by '123:qwe:ASD!'; drop user foo1; create user foo1 identified by '-23:qwe:ASD!'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) create user foo1 identified by '123:4we:ASD!'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) create user foo1 identified by '123:qwe:4SD!'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) create user foo1 identified by '123:qwe:ASD4'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) create user foo1 identified by '123:qwe:ASD!'; set password for foo1 = password('qwe:-23:ASD!'); -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = old_password('4we:123:ASD!'); -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = password('qwe:123:4SD!'); -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = old_password('qwe:123:ASD4'); -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = password('qwe:123:ASD!'); select @@strict_password_validation; @@strict_password_validation 1 set password for foo1 = ''; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = '2222222222222222'; ERROR HY000: The MariaDB server is running with the --strict-password-validation option so it cannot execute this statement set password for foo1 = '11111111111111111111111111111111111111111'; @@ -134,13 +134,13 @@ ERROR HY000: The MariaDB server is running with the --strict-password-validation grant select on *.* to foo2 identified with mysql_old_password using '2222222222222222'; ERROR HY000: The MariaDB server is running with the --strict-password-validation option so it cannot execute this statement create user foo2 identified with mysql_native_password using ''; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to foo2 identified with mysql_old_password; ERROR 28000: Can't find any matching row in the user table update mysql.user set password='xxx' where user='foo1'; set global strict_password_validation=0; set password for foo1 = ''; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = '2222222222222222'; set password for foo1 = '11111111111111111111111111111111111111111'; create user foo2 identified by password '11111111111111111111111111111111111111111'; diff --git a/mysql-test/suite/plugins/r/two_password_validations.result b/mysql-test/suite/plugins/r/two_password_validations.result index dc6bab3c2d5..be0b7638aa2 100644 --- a/mysql-test/suite/plugins/r/two_password_validations.result +++ b/mysql-test/suite/plugins/r/two_password_validations.result @@ -5,16 +5,16 @@ install soname "cracklib_password_check"; grant select on *.* to foobar identified by 'q$%^&*R1234ty'; drop user foobar; grant select on *.* to Fff_fff1 identified by '1fff_ffF'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (cracklib_password_check) show warnings; Level Code Message Warning 1819 cracklib: it does not contain enough DIFFERENT characters -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (cracklib_password_check) grant select on *.* to foobar identified by 'q-%^&*rty'; -ERROR HY000: Your password does not satisfy the current policy requirements +ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) show warnings; Level Code Message -Error 1819 Your password does not satisfy the current policy requirements +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) uninstall plugin simple_password_check; grant select on *.* to foobar identified by 'q-%^&*rty'; drop user foobar; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index b05fa5e5412..97520facefe 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6925,7 +6925,8 @@ ER_INVALID_YEAR_COLUMN_LENGTH rus "Тип YEAR(%lu) более не поддерживается, вместо него будет создана колонка с типом YEAR(4)" ER_NOT_VALID_PASSWORD - eng "Your password does not satisfy the current policy requirements" + eng "Your password does not satisfy the current policy requirements (%s)" + ukr "Ваш пароль не відповідає поточним правилам (%s)" ER_MUST_CHANGE_PASSWORD eng "You must SET PASSWORD before executing this statement" diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 4c68b4505a4..07d77d28753 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1450,7 +1450,12 @@ static my_bool do_validate(THD *, plugin_ref plugin, void *arg) struct validation_data *data= (struct validation_data *)arg; struct st_mariadb_password_validation *handler= (st_mariadb_password_validation *)plugin_decl(plugin)->info; - return handler->validate_password(data->user, data->password); + if (handler->validate_password(data->user, data->password)) + { + my_error(ER_NOT_VALID_PASSWORD, MYF(0), plugin_ref_to_int(plugin)->name.str); + return true; + } + return false; } @@ -1464,7 +1469,6 @@ static bool validate_password(LEX_USER *user, THD *thd) if (plugin_foreach(NULL, do_validate, MariaDB_PASSWORD_VALIDATION_PLUGIN, &data)) { - my_error(ER_NOT_VALID_PASSWORD, MYF(0)); return true; } } -- cgit v1.2.1 From 15a2ff1231b7508fa3a2ef9ab6a63e0e3b488157 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 20 Oct 2021 11:37:14 +0200 Subject: MDEV-26647 (simple_password_check) Include password validation plugin information in the error message if the SQL statement is not satisfied password policy Make the plugin reporting cause of the error. --- .../suite/plugins/r/simple_password_check.result | 69 ++++++++++++++++++++++ .../plugins/r/two_password_validations.result | 2 + .../suite/plugins/t/simple_password_check.test | 14 +++++ .../simple_password_check/simple_password_check.c | 28 +++++++++ 4 files changed, 113 insertions(+) diff --git a/mysql-test/suite/plugins/r/simple_password_check.result b/mysql-test/suite/plugins/r/simple_password_check.result index 11005020fe7..e8f98d1a9c8 100644 --- a/mysql-test/suite/plugins/r/simple_password_check.result +++ b/mysql-test/suite/plugins/r/simple_password_check.result @@ -72,12 +72,36 @@ READ_ONLY NO COMMAND_LINE_ARGUMENT REQUIRED create user foo1 identified by 'pwd'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Too short password (< 8) +Warning 1819 simple_password_check: Not enough upper case letters (< 1) +Warning 1819 simple_password_check: Not enough digits (< 1) +Warning 1819 simple_password_check: Not enough special characters (< 1) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' create user foo1; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: The password equal to the user name +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' grant select on *.* to foo1 identified by 'pwd'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Too short password (< 8) +Warning 1819 simple_password_check: Not enough upper case letters (< 1) +Warning 1819 simple_password_check: Not enough digits (< 1) +Warning 1819 simple_password_check: Not enough special characters (< 1) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to `FooBar1!` identified by 'FooBar1!'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: The password equal to the user name +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) grant select on *.* to `BarFoo1!` identified by 'FooBar1!'; drop user `BarFoo1!`; create user foo1 identified by 'aA.12345'; @@ -100,27 +124,63 @@ create user foo1 identified by '123:qwe:ASD!'; drop user foo1; create user foo1 identified by '-23:qwe:ASD!'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough digits (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' create user foo1 identified by '123:4we:ASD!'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough lower case letters (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' create user foo1 identified by '123:qwe:4SD!'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough upper case letters (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' create user foo1 identified by '123:qwe:ASD4'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough special characters (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo1'@'%' create user foo1 identified by '123:qwe:ASD!'; set password for foo1 = password('qwe:-23:ASD!'); ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough digits (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = old_password('4we:123:ASD!'); ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = password('qwe:123:4SD!'); ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough upper case letters (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = old_password('qwe:123:ASD4'); ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: Not enough special characters (< 3) +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = password('qwe:123:ASD!'); select @@strict_password_validation; @@strict_password_validation 1 set password for foo1 = ''; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: The password equal to the user name +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = '2222222222222222'; ERROR HY000: The MariaDB server is running with the --strict-password-validation option so it cannot execute this statement set password for foo1 = '11111111111111111111111111111111111111111'; @@ -135,12 +195,21 @@ grant select on *.* to foo2 identified with mysql_old_password using '2222222222 ERROR HY000: The MariaDB server is running with the --strict-password-validation option so it cannot execute this statement create user foo2 identified with mysql_native_password using ''; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: The password equal to the user name +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) +Error 1396 Operation CREATE USER failed for 'foo2'@'%' grant select on *.* to foo2 identified with mysql_old_password; ERROR 28000: Can't find any matching row in the user table update mysql.user set password='xxx' where user='foo1'; set global strict_password_validation=0; set password for foo1 = ''; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) +show warnings; +Level Code Message +Warning 1819 simple_password_check: The password equal to the user name +Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) set password for foo1 = '2222222222222222'; set password for foo1 = '11111111111111111111111111111111111111111'; create user foo2 identified by password '11111111111111111111111111111111111111111'; diff --git a/mysql-test/suite/plugins/r/two_password_validations.result b/mysql-test/suite/plugins/r/two_password_validations.result index be0b7638aa2..4bd674baebb 100644 --- a/mysql-test/suite/plugins/r/two_password_validations.result +++ b/mysql-test/suite/plugins/r/two_password_validations.result @@ -14,6 +14,8 @@ grant select on *.* to foobar identified by 'q-%^&*rty'; ERROR HY000: Your password does not satisfy the current policy requirements (simple_password_check) show warnings; Level Code Message +Warning 1819 simple_password_check: Not enough upper case letters (< 1) +Warning 1819 simple_password_check: Not enough digits (< 1) Error 1819 Your password does not satisfy the current policy requirements (simple_password_check) uninstall plugin simple_password_check; grant select on *.* to foobar identified by 'q-%^&*rty'; diff --git a/mysql-test/suite/plugins/t/simple_password_check.test b/mysql-test/suite/plugins/t/simple_password_check.test index 4965ee492d2..d0ba7e1180b 100644 --- a/mysql-test/suite/plugins/t/simple_password_check.test +++ b/mysql-test/suite/plugins/t/simple_password_check.test @@ -15,16 +15,20 @@ select * from information_schema.system_variables where variable_name like 'simp --error ER_NOT_VALID_PASSWORD create user foo1 identified by 'pwd'; +show warnings; # Create user with no password. --error ER_NOT_VALID_PASSWORD create user foo1; +show warnings; --error ER_NOT_VALID_PASSWORD grant select on *.* to foo1 identified by 'pwd'; +show warnings; --error ER_NOT_VALID_PASSWORD grant select on *.* to `FooBar1!` identified by 'FooBar1!'; +show warnings; grant select on *.* to `BarFoo1!` identified by 'FooBar1!'; drop user `BarFoo1!`; @@ -43,25 +47,32 @@ drop user foo1; --error ER_NOT_VALID_PASSWORD create user foo1 identified by '-23:qwe:ASD!'; +show warnings; --error ER_NOT_VALID_PASSWORD create user foo1 identified by '123:4we:ASD!'; +show warnings; --error ER_NOT_VALID_PASSWORD create user foo1 identified by '123:qwe:4SD!'; +show warnings; --error ER_NOT_VALID_PASSWORD create user foo1 identified by '123:qwe:ASD4'; +show warnings; create user foo1 identified by '123:qwe:ASD!'; --error ER_NOT_VALID_PASSWORD set password for foo1 = password('qwe:-23:ASD!'); +show warnings; --error ER_NOT_VALID_PASSWORD set password for foo1 = old_password('4we:123:ASD!'); --error ER_NOT_VALID_PASSWORD set password for foo1 = password('qwe:123:4SD!'); +show warnings; --error ER_NOT_VALID_PASSWORD set password for foo1 = old_password('qwe:123:ASD4'); +show warnings; set password for foo1 = password('qwe:123:ASD!'); # now, strict_password_validation @@ -69,6 +80,7 @@ select @@strict_password_validation; --error ER_NOT_VALID_PASSWORD set password for foo1 = ''; +show warnings; --error ER_OPTION_PREVENTS_STATEMENT set password for foo1 = '2222222222222222'; --error ER_OPTION_PREVENTS_STATEMENT @@ -83,6 +95,7 @@ create user foo2 identified with mysql_native_password using '111111111111111111 grant select on *.* to foo2 identified with mysql_old_password using '2222222222222222'; --error ER_NOT_VALID_PASSWORD create user foo2 identified with mysql_native_password using ''; +show warnings; --error ER_PASSWORD_NO_MATCH grant select on *.* to foo2 identified with mysql_old_password; @@ -93,6 +106,7 @@ set global strict_password_validation=0; --error ER_NOT_VALID_PASSWORD set password for foo1 = ''; +show warnings; set password for foo1 = '2222222222222222'; set password for foo1 = '11111111111111111111111111111111111111111'; create user foo2 identified by password '11111111111111111111111111111111111111111'; diff --git a/plugin/simple_password_check/simple_password_check.c b/plugin/simple_password_check/simple_password_check.c index 36459354755..93f759b293b 100644 --- a/plugin/simple_password_check/simple_password_check.c +++ b/plugin/simple_password_check/simple_password_check.c @@ -29,7 +29,13 @@ static int validate(MYSQL_CONST_LEX_STRING *username, const char *ptr= password->str, *end= ptr + length; if (strncmp(password->str, username->str, length) == 0) + { + // warning used to do not change error code + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: The password equal to the user name", + ME_WARNING); return 1; + } /* everything non-ascii is the "other" character and is good for the password */ for(; ptr < end; ptr++) @@ -43,6 +49,28 @@ static int validate(MYSQL_CONST_LEX_STRING *username, else others++; } + + // warnings used to do not change error code + if (length < min_length) + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: Too short password (< %u)", + ME_WARNING, min_length); + if (uppers < min_letters) + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: Not enough upper case " + "letters (< %u)",ME_WARNING, min_letters); + if (lowers < min_letters) + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: Not enough lower case " + "letters (< %u)",ME_WARNING, min_letters); + if (digits < min_digits) + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: Not enough digits (< %u)", + ME_WARNING, min_digits); + if (others < min_others) + my_printf_error(ER_NOT_VALID_PASSWORD, + "simple_password_check: Not enough special " + "characters (< %u)",ME_WARNING, min_others); /* remember TRUE means the password failed the validation */ return length < min_length || uppers < min_letters || -- cgit v1.2.1 From 4329720b79bf19d6d0359ef1e6bcf3de76d7cbd3 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 25 Jul 2022 13:27:23 +0200 Subject: Fixes for WolfSSL 5.4.0 --- extra/wolfssl/CMakeLists.txt | 3 ++- extra/wolfssl/user_settings.h.in | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/extra/wolfssl/CMakeLists.txt b/extra/wolfssl/CMakeLists.txt index 3faddbf49a2..35c3b735bdd 100644 --- a/extra/wolfssl/CMakeLists.txt +++ b/extra/wolfssl/CMakeLists.txt @@ -136,7 +136,8 @@ IF(WOLFSSL_FASTMATH) PROPERTIES COMPILE_FLAGS ${TFM_COMPILE_FLAGS}) ENDIF() ELSE() - SET(WOLFCRYPT_SOURCES ${WOLFCRYPT_SOURCES} ${WOLFCRYPT_SRCDIR}/integer.c) + SET(WOLFSSL_SP_MATH_ALL 1) + SET(WOLFCRYPT_SOURCES ${WOLFCRYPT_SOURCES} ${WOLFCRYPT_SRCDIR}/sp_int.c) ENDIF() IF(WOLFSSL_X86_64_BUILD) diff --git a/extra/wolfssl/user_settings.h.in b/extra/wolfssl/user_settings.h.in index bbe8c820019..2355fd1691c 100644 --- a/extra/wolfssl/user_settings.h.in +++ b/extra/wolfssl/user_settings.h.in @@ -47,6 +47,7 @@ WolfSSL will use more stack space with it, with fastmath */ #cmakedefine FP_MAX_BITS 16384 +#define RSA_MAX_SIZE 8192 #cmakedefine WOLFSSL_AESNI #cmakedefine USE_FAST_MATH #cmakedefine TFM_TIMING_RESISTANT @@ -55,5 +56,6 @@ #cmakedefine USE_INTEL_SPEEDUP #cmakedefine USE_FAST_MATH #cmakedefine WOLFSSL_X86_64_BUILD +#cmakedefine WOLFSSL_SP_MATH_ALL #endif /* WOLFSSL_USER_SETTINGS_H */ -- cgit v1.2.1 From f0107c90a026b28a40de772c353a9d0cb2b242e3 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Wed, 27 Jul 2022 16:21:28 +0200 Subject: wolfssl v5.4.0-stable --- extra/wolfssl/wolfssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/wolfssl/wolfssl b/extra/wolfssl/wolfssl index e6c07a296d2..57aac1c50b4 160000 --- a/extra/wolfssl/wolfssl +++ b/extra/wolfssl/wolfssl @@ -1 +1 @@ -Subproject commit e6c07a296d2996e8d5c3cc615dfc50013bbcc794 +Subproject commit 57aac1c50b45275c7a99eca32ad985998b292dc8 -- cgit v1.2.1 From 4b77d38c2673feb5705ae335a54fe81c77e93b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 28 Jul 2022 08:51:19 +0300 Subject: Fix GCC -Og -Wmaybe-uninitialized --- storage/spider/spd_sys_table.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/storage/spider/spd_sys_table.cc b/storage/spider/spd_sys_table.cc index 9c97050d41c..bc0a06e3076 100644 --- a/storage/spider/spd_sys_table.cc +++ b/storage/spider/spd_sys_table.cc @@ -2639,11 +2639,11 @@ int spider_get_sys_link_mon_key( DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM); } - if ( - !(db_name = get_field(mem_root, table->field[0])) || - !(table_name = get_field(mem_root, table->field[1])) || - !(link_id = get_field(mem_root, table->field[2])) - ) + if (!(db_name = get_field(mem_root, table->field[0]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(table_name = get_field(mem_root, table->field[1]))) + DBUG_RETURN(HA_ERR_OUT_OF_MEM); + if (!(link_id = get_field(mem_root, table->field[2]))) DBUG_RETURN(HA_ERR_OUT_OF_MEM); db_name_length = strlen(db_name); -- cgit v1.2.1 From 2658410afc313a6c44ae2915074d1e15a6e0ce97 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 28 Jul 2022 15:53:56 +1000 Subject: MDEV-29187: Deadlock output in InnoDB status always shows transaction (0) At some point the incrementing of the transaction counter got dropped. Thanks Agustin for the bug report. --- storage/innobase/lock/lock0lock.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index d5905e7b523..6a24f369c22 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -6126,6 +6126,7 @@ namespace Deadlock for (trx_t *next= cycle;;) { next= next->lock.wait_trx; + l++; const undo_no_t next_weight= TRX_WEIGHT(next) | (next->mysql_thd && #ifdef WITH_WSREP -- cgit v1.2.1 From 38d0256b148281812315c9eeb479edb8755f57e1 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 28 Jul 2022 21:03:32 +0530 Subject: - Fixed the change_column_collation test case to avoid the loss of debug sync signal --- mysql-test/suite/innodb/r/change_column_collation.result | 2 +- mysql-test/suite/innodb/t/change_column_collation.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/innodb/r/change_column_collation.result b/mysql-test/suite/innodb/r/change_column_collation.result index 54eff706276..b1771b2bd00 100644 --- a/mysql-test/suite/innodb/r/change_column_collation.result +++ b/mysql-test/suite/innodb/r/change_column_collation.result @@ -40,9 +40,9 @@ INSERT INTO t1 VALUES (4, 'AAA'); UPDATE t1 set msg = "ddd" where id = 2; DELETE FROM t1 WHERE id= 3; SET DEBUG_SYNC = 'now SIGNAL go_ahead'; -SET DEBUG_SYNC = 'RESET'; connection default; ERROR 23000: Duplicate entry 'NULL' for key 'msg' +SET DEBUG_SYNC = 'RESET'; SELECT * FROM t1; id msg 4 AAA diff --git a/mysql-test/suite/innodb/t/change_column_collation.test b/mysql-test/suite/innodb/t/change_column_collation.test index 7d82aac7ec2..f63d1974c72 100644 --- a/mysql-test/suite/innodb/t/change_column_collation.test +++ b/mysql-test/suite/innodb/t/change_column_collation.test @@ -63,13 +63,13 @@ INSERT INTO t1 VALUES (4, 'AAA'); UPDATE t1 set msg = "ddd" where id = 2; DELETE FROM t1 WHERE id= 3; SET DEBUG_SYNC = 'now SIGNAL go_ahead'; -SET DEBUG_SYNC = 'RESET'; connection default; --error ER_DUP_ENTRY reap; +SET DEBUG_SYNC = 'RESET'; SELECT * FROM t1; DROP TABLE t1; -- cgit v1.2.1 From 05a407b2397a4d782467c4353e297ffd40b11099 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Wed, 20 Jul 2022 10:26:51 -0700 Subject: MDEV-28782: modify mariadb-tzinfo-to-sql to set 'wsrep*' variables appropriately in cases where Galera is not compiled in In 3b662c6ebd26b54ce534d9e7451cdc31e6c0046c, it was discovered that the values of the 'wsrep_is_on' and 'wsrep_cannot_replicate_tz' variables need to be overridden for embedded builds to pass However, there are other build configurations where these variables also have NULL values. The mariadb-tzinfo-to-sql script (implemented in sql/tztime.cc) can be slightly modified to set its 'wsrep_is_on' and 'wsrep_cannot_replicate_tz' variables more predictably in all such cases, thus allowing the mysql_tzinfo_to_sql_symlink.test test to pass without any special-casing for particular build types. See comments: - https://github.com/MariaDB/server/commit/3b662c6ebd26b54ce534d9e7451cdc31e6c0046c#r78994411 - https://jira.mariadb.org/browse/MDEV-28782?focusedCommentId=230038&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-230038 All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- mysql-test/main/mysql_tzinfo_to_sql_symlink.result | 40 +++++++++++----------- mysql-test/main/mysql_tzinfo_to_sql_symlink.test | 17 --------- sql/tztime.cc | 23 +++++++++---- 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result index a6be207434f..d5c6518a130 100644 --- a/mysql-test/main/mysql_tzinfo_to_sql_symlink.result +++ b/mysql-test/main/mysql_tzinfo_to_sql_symlink.result @@ -7,9 +7,9 @@ CREATE TABLE time_zone_leap_second LIKE mysql.time_zone_leap_second; # MDEV-5226 mysql_tzinfo_to_sql errors with tzdata 2013f and above # # Verbose run -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0'); @@ -56,9 +56,9 @@ execute immediate if(@wsrep_cannot_replicate_tz, concat('ALTER TABLE time_zone_t # MDEV-28263: mariadb-tzinfo-to-sql improve wsrep and binlog cases # # Run on zoneinfo directory -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0'); @@ -116,9 +116,9 @@ COUNT(*) # # Run on zoneinfo directory --skip-write-binlog # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0'); SET @save_sql_log_bin=@@SQL_LOG_BIN; SET SESSION SQL_LOG_BIN=0; @@ -188,9 +188,9 @@ TRUNCATE TABLE time_zone_leap_second; # # Testing with explicit timezonefile # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0'); @@ -252,9 +252,9 @@ TRUNCATE TABLE time_zone_leap_second; # # Testing with explicit timezonefile --skip-write-binlog # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0'); SET @save_sql_log_bin=@@SQL_LOG_BIN; SET SESSION SQL_LOG_BIN=0; @@ -310,9 +310,9 @@ TRUNCATE TABLE time_zone_leap_second; # # Testing --leap # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0'); @@ -373,9 +373,9 @@ TRUNCATE TABLE time_zone_leap_second; # # Testing --skip-write-binlog --leap # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0'); SET @save_sql_log_bin=@@SQL_LOG_BIN; SET SESSION SQL_LOG_BIN=0; @@ -425,9 +425,9 @@ COM_TRUNCATE 1 # # Testing --skip-write-binlog # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0'); SET @save_sql_log_bin=@@SQL_LOG_BIN; SET SESSION SQL_LOG_BIN=0; @@ -447,9 +447,9 @@ UNLOCK TABLES; COMMIT; SET SESSION SQL_LOG_BIN=@save_sql_log_bin; execute immediate if(@wsrep_is_on, 'SET SESSION WSREP_ON=@save_wsrep_on', 'do 0'); -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0'); SET @save_sql_log_bin=@@SQL_LOG_BIN; SET SESSION SQL_LOG_BIN=0; @@ -471,9 +471,9 @@ execute immediate if(@wsrep_is_on, 'SET SESSION WSREP_ON=@save_wsrep_on', 'do 0' # # MDEV-6236 - [PATCH] mysql_tzinfo_to_sql may produce invalid SQL # -set @wsrep_is_on=(select sum(SESSION_VALUE='ON') from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); +set @wsrep_is_on=(select coalesce(sum(SESSION_VALUE='ON'), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'); SELECT concat('%', GROUP_CONCAT(OPTION), '%') INTO @replicate_opt FROM (SELECT DISTINCT concat('REPLICATE_', UPPER(ENGINE)) AS OPTION FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME IN ('time_zone', 'time_zone_name', 'time_zone_transition', 'time_zone_transition_type', 'time_zone_leap_second') AND ENGINE in ('MyISAM', 'Aria')) AS o ORDER BY OPTION DESC; -set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select sum(GLOBAL_VALUE NOT LIKE @replicate_opt) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); +set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0) from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone'", 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, 'ALTER TABLE time_zone ENGINE=InnoDB', 'do 0'); execute immediate if(@wsrep_cannot_replicate_tz, "select ENGINE into @time_zone_name_engine from information_schema.TABLES where TABLE_SCHEMA=DATABASE() and TABLE_NAME='time_zone_name'", 'do 0'); diff --git a/mysql-test/main/mysql_tzinfo_to_sql_symlink.test b/mysql-test/main/mysql_tzinfo_to_sql_symlink.test index 857f24e610f..34df1281c38 100644 --- a/mysql-test/main/mysql_tzinfo_to_sql_symlink.test +++ b/mysql-test/main/mysql_tzinfo_to_sql_symlink.test @@ -3,8 +3,6 @@ --source include/not_windows.inc --source include/no_protocol.inc -let $is_embedded=`select version() like '%embedded%'`; - CREATE TABLE time_zone LIKE mysql.time_zone; CREATE TABLE time_zone_name LIKE mysql.time_zone_name; CREATE TABLE time_zone_transition LIKE mysql.time_zone_transition; @@ -63,9 +61,6 @@ SELECT COUNT(*) FROM time_zone_transition; SELECT COUNT(*) FROM time_zone_transition_type; SELECT COUNT(*) FROM time_zone_leap_second; -if ($is_embedded) { ---replace_column 1 0 2 0 -} SELECT @wsrep_is_on, @wsrep_cannot_replicate_tz, @save_wsrep_on, @save_sql_log_bin, @@SQL_LOG_BIN; SELECT g.VARIABLE_NAME, g.VARIABLE_VALUE - b.VARIABLE_VALUE AS diff FROM information_schema.global_status g @@ -100,9 +95,6 @@ SELECT COUNT(*) FROM time_zone_transition; SELECT COUNT(*) FROM time_zone_transition_type; SELECT COUNT(*) FROM time_zone_leap_second; -if ($is_embedded) { ---replace_column 1 0 2 0 -} SELECT @wsrep_is_on, @wsrep_cannot_replicate_tz, @save_wsrep_on, @save_sql_log_bin, @@SQL_LOG_BIN; SELECT g.VARIABLE_NAME, g.VARIABLE_VALUE - b.VARIABLE_VALUE AS diff FROM information_schema.global_status g @@ -135,9 +127,6 @@ SELECT COUNT(*) FROM time_zone_transition; SELECT COUNT(*) FROM time_zone_transition_type; SELECT COUNT(*) FROM time_zone_leap_second; -if ($is_embedded) { ---replace_column 1 0 2 0 -} SELECT @wsrep_is_on, @wsrep_cannot_replicate_tz, @save_wsrep_on, @save_sql_log_bin, @@SQL_LOG_BIN; SELECT g.VARIABLE_NAME, g.VARIABLE_VALUE - b.VARIABLE_VALUE AS diff FROM information_schema.global_status g @@ -170,9 +159,6 @@ SELECT COUNT(*) FROM time_zone_transition; SELECT COUNT(*) FROM time_zone_transition_type; SELECT COUNT(*) FROM time_zone_leap_second; -if ($is_embedded) { ---replace_column 1 0 2 0 -} SELECT @wsrep_is_on, @wsrep_cannot_replicate_tz, @save_wsrep_on, @save_sql_log_bin, @@SQL_LOG_BIN; SELECT g.VARIABLE_NAME, g.VARIABLE_VALUE - b.VARIABLE_VALUE AS diff FROM information_schema.global_status g @@ -205,9 +191,6 @@ SELECT COUNT(*) FROM time_zone_transition; SELECT COUNT(*) FROM time_zone_transition_type; SELECT COUNT(*) FROM time_zone_leap_second; -if ($is_embedded) { ---replace_column 1 0 2 0 -} SELECT @wsrep_is_on, @wsrep_cannot_replicate_tz, @save_wsrep_on, @save_sql_log_bin, @@SQL_LOG_BIN; SELECT g.VARIABLE_NAME, g.VARIABLE_VALUE - b.VARIABLE_VALUE AS diff FROM information_schema.global_status g diff --git a/sql/tztime.cc b/sql/tztime.cc index 4725e26a4c1..8b64aee583e 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1798,7 +1798,7 @@ end: delete thd; if (org_thd) org_thd->store_globals(); /* purecov: inspected */ - + default_tz= default_tz_name ? global_system_variables.time_zone : my_tz_SYSTEM; @@ -1873,7 +1873,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) #ifdef ABBR_ARE_USED char chars[MY_MAX(TZ_MAX_CHARS + 1, (2 * (MY_TZNAME_MAX + 1)))]; #endif - /* + /* Used as a temporary tz_info until we decide that we actually want to allocate and keep the tz info and tz name in tz_storage. */ @@ -2026,7 +2026,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables) mysql.time_zone_transition table. Here we additionally need records in ascending order by index scan also satisfies us. */ - table= tz_tables->table; + table= tz_tables->table; table->field[0]->store((longlong) tzid, TRUE); if (table->file->ha_index_init(0, 1)) goto end; @@ -2361,7 +2361,7 @@ my_tz_find(THD *thd, const String *name) /** Convert leap seconds into non-leap - This function will convert the leap seconds added by the OS to + This function will convert the leap seconds added by the OS to non-leap seconds, e.g. 23:59:59, 23:59:60 -> 23:59:59, 00:00:01 ... This check is not checking for years on purpose : although it's not a complete check this way it doesn't require looking (and having installed) @@ -2725,11 +2725,20 @@ static const char *trunc_tables_const= "TRUNCATE TABLE time_zone_name;\n" "TRUNCATE TABLE time_zone_transition;\n" "TRUNCATE TABLE time_zone_transition_type;\n"; + +/* + These queries need to return FALSE/0 when the 'wsrep*' variables do not + exist at all. + Moving the WHERE clause into the sum(...) seems like the obvious solution + here, but it does not work in bootstrap mode (see MDEV-28782 and + 0e4cf497ca11a7298e2bd896cb594bd52085a1d4). + Thus we use coalesce(..., 0) instead, +*/ static const char *wsrep_is_on= - "select sum(SESSION_VALUE='ON')" + "select coalesce(sum(SESSION_VALUE='ON'), 0)" " from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_on'"; static const char *wsrep_cannot_replicate_tz= - "select sum(GLOBAL_VALUE NOT LIKE @replicate_opt)" + "select coalesce(sum(GLOBAL_VALUE NOT LIKE @replicate_opt), 0)" " from information_schema.SYSTEM_VARIABLES WHERE VARIABLE_NAME='wsrep_mode'"; int @@ -2770,7 +2779,7 @@ main(int argc, char **argv) " ORDER BY OPTION DESC;\n"); printf("set @wsrep_cannot_replicate_tz=@wsrep_is_on AND (%s);\n", wsrep_cannot_replicate_tz); if (opt_skip_write_binlog) - /* If turn off session wsrep if we cannot replicate using galera. + /* We turn off session wsrep if we cannot replicate using galera. Disable sql_log_bin as the name implies. */ printf("execute immediate if(@wsrep_is_on, 'SET @save_wsrep_on=@@WSREP_ON, WSREP_ON=OFF', 'do 0');\n" "SET @save_sql_log_bin=@@SQL_LOG_BIN;\n" -- cgit v1.2.1 From cbcc0101ee3016b398490685d30db296b1892db7 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 28 Jul 2022 16:17:03 +0200 Subject: MDEV-29188 Crash in JSON_EXTRACT If we have null_value set then decimal/string value/result shoud be 0 pointer. --- mysql-test/main/func_json.result | 11 +++++++++++ mysql-test/main/func_json.test | 14 ++++++++++++++ sql/item_cmpfunc.cc | 4 ++++ sql/item_jsonfunc.cc | 8 +++++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index cba57b0853e..8e3b47e322a 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1005,5 +1005,16 @@ JSON_VALID('{"admin\\"": null}') {"admin\"": null} 1 {"\"admin": null} 1 {"\"": null} # +# MDEV-29188: Crash in JSON_EXTRACT +# +CREATE TABLE t1 (j JSON); +INSERT INTO t1 VALUES +('{"ID": "4", "Name": "Betty", "Age": 19}'), +('[10, 20, [30, 40]]'); +SELECT * FROM t1 WHERE JSON_EXTRACT(j, '$.Age')=19; +j +{"ID": "4", "Name": "Betty", "Age": 19} +drop table t1; +# # End of 10.3 tests # diff --git a/mysql-test/main/func_json.test b/mysql-test/main/func_json.test index aa461433dfe..16f323a9a56 100644 --- a/mysql-test/main/func_json.test +++ b/mysql-test/main/func_json.test @@ -613,6 +613,20 @@ SELECT JSON_VALID('{"admin\\"": null}'), '{"admin\\"": null}' UNION SELECT JSON_VALID('{"\\"": null}'), '{"\\"": null}'; +--echo # +--echo # MDEV-29188: Crash in JSON_EXTRACT +--echo # + +CREATE TABLE t1 (j JSON); + +INSERT INTO t1 VALUES + ('{"ID": "4", "Name": "Betty", "Age": 19}'), + ('[10, 20, [30, 40]]'); + +SELECT * FROM t1 WHERE JSON_EXTRACT(j, '$.Age')=19; + +drop table t1; + --echo # --echo # End of 10.3 tests --echo # diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index f41414f8ae9..a3c0d4d95df 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -795,7 +795,9 @@ int Arg_comparator::compare_e_string() { String *res1,*res2; res1= (*a)->val_str(&value1); + DBUG_ASSERT((res1 == NULL) == (*a)->null_value); res2= (*b)->val_str(&value2); + DBUG_ASSERT((res2 == NULL) == (*b)->null_value); if (!res1 || !res2) return MY_TEST(res1 == res2); return MY_TEST(sortcmp(res1, res2, compare_collation()) == 0); @@ -832,10 +834,12 @@ int Arg_comparator::compare_decimal() { my_decimal decimal1; my_decimal *val1= (*a)->val_decimal(&decimal1); + DBUG_ASSERT((val1 == NULL) == (*a)->null_value); if (!(*a)->null_value) { my_decimal decimal2; my_decimal *val2= (*b)->val_decimal(&decimal2); + DBUG_ASSERT((val2 == NULL) == (*b)->null_value); if (!(*b)->null_value) { if (set_null) diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index c0f063639bc..5166d9a78af 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -1109,12 +1109,14 @@ my_decimal *Item_func_json_extract::val_decimal(my_decimal *to) case JSON_VALUE_OBJECT: case JSON_VALUE_ARRAY: case JSON_VALUE_FALSE: + // TODO: fix: NULL should be NULL case JSON_VALUE_NULL: - break; + int2my_decimal(E_DEC_FATAL_ERROR, 0, false/*unsigned_flag*/, to); + return to; }; } - int2my_decimal(E_DEC_FATAL_ERROR, 0, false/*unsigned_flag*/, to); - return to; + DBUG_ASSERT(null_value); + return 0; } -- cgit v1.2.1 From a6f7c8edc9b8c394662e06df7421eb6215ced0d3 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Fri, 29 Jul 2022 15:57:51 +0530 Subject: MDEV-28762: recursive call of some json functions without stack control Fixup to MDEV-28762. Fixes warnings about unused variable "stack_used_up" during building with RelWithDebInfo --- sql/json_table.cc | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sql/json_table.cc b/sql/json_table.cc index d8502cb6dc9..73ae4974956 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -118,10 +118,12 @@ int get_disallowed_table_deps_for_list(MEM_ROOT *mem_root, NESTED_JOIN *nested_join; List_iterator li(*join_list); - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + { + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); + ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); + }); if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) return 1; @@ -1329,10 +1331,12 @@ static void add_extra_deps(List *join_list, table_map deps) TABLE_LIST *table; List_iterator li(*join_list); - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + { + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); + ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); + }); if (check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL)) return; @@ -1424,10 +1428,12 @@ table_map add_table_function_dependencies(List *join_list, table_map res= 0; List_iterator li(*join_list); - long arbitrary_var; - long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); DBUG_EXECUTE_IF("json_check_min_stack_requirement", - {ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE);}); + { + long arbitrary_var; + long stack_used_up= (available_stack_size(current_thd->thread_stack, &arbitrary_var)); + ALLOCATE_MEM_ON_STACK(my_thread_stack_size-stack_used_up-STACK_MIN_SIZE); + }); if ((res=check_stack_overrun(current_thd, STACK_MIN_SIZE , NULL))) return res; -- cgit v1.2.1 From f9315b33217c5c126995a6c1d2c286d480091776 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 29 Jul 2022 07:40:00 +0200 Subject: CC 3.1 update Test fixes: Since fix for CONC-603 (wrong error handling in TLS read/write) in case of a read/write error client doesn't return always error 2013 (server has gone away), so in addition we need to check for error 2026 (TLS/SSL error) and 5014 (write error). --- libmariadb | 2 +- mysql-test/include/wait_until_disconnected.inc | 2 +- mysql-test/main/kill.test | 12 ++++++------ mysql-test/main/openssl_1.result | 14 +++++++------- mysql-test/main/openssl_1.test | 14 +++++++------- mysql-test/main/openssl_6975,tlsv10.result | 12 ++++++------ mysql-test/main/openssl_6975,tlsv12.result | 12 ++++++------ mysql-test/main/ssl_7937,nossl.result | 4 ++-- mysql-test/main/ssl_7937.result | 2 +- mysql-test/main/ssl_7937.test | 2 +- mysql-test/main/ssl_ca.result | 2 +- mysql-test/main/ssl_ca.test | 2 +- mysql-test/main/ssl_cipher.result | 2 +- mysql-test/main/ssl_cipher.test | 2 +- mysql-test/main/ssl_crl.result | 2 +- mysql-test/main/ssl_crl.test | 2 +- mysql-test/main/ssl_crl_clients.result | 8 ++++---- mysql-test/main/ssl_crl_clients.test | 4 ++-- mysql-test/main/ssl_system_ca,bad.result | 2 +- mysql-test/main/ssl_timeout.result | 2 +- mysql-test/main/ssl_timeout.test | 2 +- mysql-test/main/wait_timeout.test | 4 ++-- mysql-test/suite/sys_vars/t/completion_type_func.test | 4 ++-- 23 files changed, 57 insertions(+), 57 deletions(-) diff --git a/libmariadb b/libmariadb index d12fd88b6c0..7fdb3eab663 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit d12fd88b6c0fafbf25f59e7fecd639cb2b38f157 +Subproject commit 7fdb3eab66384a355475704332d11cc1ab82499a diff --git a/mysql-test/include/wait_until_disconnected.inc b/mysql-test/include/wait_until_disconnected.inc index 93ada7f11ce..3854369bb60 100644 --- a/mysql-test/include/wait_until_disconnected.inc +++ b/mysql-test/include/wait_until_disconnected.inc @@ -9,7 +9,7 @@ let $counter= 600; let $mysql_errno= 0; while (!$mysql_errno) { - --error 0,ER_SERVER_SHUTDOWN,ER_CONNECTION_KILLED,2002,2006,2013 + --error 0,ER_SERVER_SHUTDOWN,ER_CONNECTION_KILLED,2002,2006,2026,2013,5014 show status; dec $counter; diff --git a/mysql-test/main/kill.test b/mysql-test/main/kill.test index 6554ab7f2c9..b2debd95a98 100644 --- a/mysql-test/main/kill.test +++ b/mysql-test/main/kill.test @@ -58,7 +58,7 @@ SET DEBUG_SYNC= 'now WAIT_FOR con1_end'; SET DEBUG_SYNC = 'RESET'; connection con1; ---error 1053,2006,2013 +--error 1053,2006,2013,5014 SELECT 1; --enable_reconnect @@ -97,7 +97,7 @@ SET DEBUG_SYNC= 'now WAIT_FOR con1_end'; SET DEBUG_SYNC = 'RESET'; connection con1; ---error 1053,2006,2013 +--error 1053,2006,2013,5014 SELECT 1; enable_reconnect; SELECT 1; @@ -144,7 +144,7 @@ KILL @id; SET DEBUG_SYNC= 'now WAIT_FOR con1_end'; connection con1; ---error 1317,1053,2006,2013 +--error 1317,1053,2006,2013,5014 reap; SELECT 1; @@ -289,7 +289,7 @@ SET DEBUG_SYNC= 'now WAIT_FOR con1_end'; connection con1; --echo # ER_SERVER_SHUTDOWN, CR_SERVER_GONE_ERROR, CR_SERVER_LOST, --echo # depending on the timing of close of the connection socket ---error 1053,2006,2013 +--error 1053,2006,2013,5014 SELECT 1; --enable_reconnect SELECT 1; @@ -522,10 +522,10 @@ drop user test@localhost; drop user test2@localhost; connection con3; ---error 2013,2006 +--error 2013,2006,5014 select 1; connection con4; ---error 2013,2006 +--error 2013,2006,5014 select 1; connection default; diff --git a/mysql-test/main/openssl_1.result b/mysql-test/main/openssl_1.result index 96b1895d57b..a9c092948be 100644 --- a/mysql-test/main/openssl_1.result +++ b/mysql-test/main/openssl_1.result @@ -47,11 +47,11 @@ disconnect con3; disconnect con4; drop user ssl_user1@localhost, ssl_user3@localhost, ssl_user4@localhost, ssl_user5@localhost; drop table t1; -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxx -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxx -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxx -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxx -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxx +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxx +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxx +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxx +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxx +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxx have_ssl 1 End of 5.0 tests @@ -179,7 +179,7 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -mysqldump: Got error: 2026: "SSL connection error: xxxx +mysqldump: Got error: 2026: "TLS/SSL error: xxxx DROP TABLE t1; GRANT SELECT ON test.* TO bug42158@localhost REQUIRE X509; FLUSH PRIVILEGES; @@ -196,4 +196,4 @@ End of 5.1 tests /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; -ERROR: Failed on connect: SSL connection error \ No newline at end of file +ERROR: Failed on connect: TLS/SSL error \ No newline at end of file diff --git a/mysql-test/main/openssl_1.test b/mysql-test/main/openssl_1.test index b70d2018c9e..54dfb3004a2 100644 --- a/mysql-test/main/openssl_1.test +++ b/mysql-test/main/openssl_1.test @@ -69,7 +69,7 @@ drop table t1; # --exec echo "this query should not execute;" > $MYSQLTEST_VARDIR/tmp/test.sql # Handle that openssl gives different error messages from YaSSL. ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca=$MYSQL_TEST_DIR/std_data/untrusted-cacert.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --echo @@ -78,7 +78,7 @@ drop table t1; # Test that we can't open connection to server if we are using # a blank ca # ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --echo @@ -87,7 +87,7 @@ drop table t1; # Test that we can't open connection to server if we are using # a nonexistent ca file # ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-ca=nonexisting_file.pem --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --echo @@ -96,7 +96,7 @@ drop table t1; # Test that we can't open connection to server if we are using # a blank client-key # ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-key= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --echo @@ -105,7 +105,7 @@ drop table t1; # Test that we can't open connection to server if we are using # a blank client-cert # ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-cert= --max-connect-retries=1 < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --echo @@ -174,7 +174,7 @@ INSERT INTO t1 VALUES (1), (2); # With wrong parameters --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR mysqldump.exe mysqldump ---replace_regex /SSL connection error.*/SSL connection error: xxxx/ +--replace_regex /TLS\/SSL error.*/TLS\/SSL error: xxxx/ --error 2 --exec $MYSQL_DUMP --default-character-set=utf8mb4 --skip-create-options --skip-comments --ssl --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test 2>&1 --echo @@ -200,7 +200,7 @@ set global sql_mode=default; # MDEV-9605 mysqlbinlog does not accept ssl-ca option as expected. # ---replace_regex /SSL connection error:.*/SSL connection error/ +--replace_regex /TLS\/SSL error:.*/TLS\/SSL error/ --error 1 --exec $MYSQL_BINLOG --read-from-remote-server --ssl-ca --user=root --host=localhost nobinlog.111111 2>&1 diff --git a/mysql-test/main/openssl_6975,tlsv10.result b/mysql-test/main/openssl_6975,tlsv10.result index b76a91bd134..f848b9a2ccc 100644 --- a/mysql-test/main/openssl_6975,tlsv10.result +++ b/mysql-test/main/openssl_6975,tlsv10.result @@ -3,14 +3,14 @@ grant select on test.* to ssl_sslv3@localhost require cipher "AES128-SHA"; create user ssl_tls12@localhost; grant select on test.* to ssl_tls12@localhost require cipher "AES128-SHA256"; TLS1.2 ciphers: user is ok with any cipher -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure TLS1.2 ciphers: user requires SSLv3 cipher AES128-SHA -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure TLS1.2 ciphers: user requires TLSv1.2 cipher AES128-SHA256 -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure SSLv3 ciphers: user is ok with any cipher Variable_name Value Ssl_cipher AES256-SHA diff --git a/mysql-test/main/openssl_6975,tlsv12.result b/mysql-test/main/openssl_6975,tlsv12.result index c16e503c339..7bc92aec74f 100644 --- a/mysql-test/main/openssl_6975,tlsv12.result +++ b/mysql-test/main/openssl_6975,tlsv12.result @@ -15,13 +15,13 @@ Variable_name Value Ssl_cipher AES128-SHA256 ERROR 1045 (28000): Access denied for user 'ssl_tls12'@'localhost' (using password: NO) SSLv3 ciphers: user is ok with any cipher -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure SSLv3 ciphers: user requires SSLv3 cipher AES128-SHA -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure SSLv3 ciphers: user requires TLSv1.2 cipher AES128-SHA256 -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure -ERROR 2026 (HY000): SSL connection error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert handshake failure drop user ssl_sslv3@localhost; drop user ssl_tls12@localhost; diff --git a/mysql-test/main/ssl_7937,nossl.result b/mysql-test/main/ssl_7937,nossl.result index 72693233bc8..7ce4a754bf8 100644 --- a/mysql-test/main/ssl_7937,nossl.result +++ b/mysql-test/main/ssl_7937,nossl.result @@ -9,7 +9,7 @@ mysql --ssl -e "call test.have_ssl()" have_ssl no mysql --ssl-ca=cacert.pem --ssl-verify-server-cert -e "call test.have_ssl()" -ERROR 2026 (HY000): SSL connection error: SSL is required, but the server does not support it +ERROR 2026 (HY000): TLS/SSL error: SSL is required, but the server does not support it mysql --ssl --ssl-verify-server-cert -e "call test.have_ssl()" -ERROR 2026 (HY000): SSL connection error: SSL is required, but the server does not support it +ERROR 2026 (HY000): TLS/SSL error: SSL is required, but the server does not support it drop procedure have_ssl; diff --git a/mysql-test/main/ssl_7937.result b/mysql-test/main/ssl_7937.result index a94ca3b3529..86180af3692 100644 --- a/mysql-test/main/ssl_7937.result +++ b/mysql-test/main/ssl_7937.result @@ -12,5 +12,5 @@ mysql --ssl-ca=cacert.pem --ssl-verify-server-cert -e "call test.have_ssl()" have_ssl yes mysql --ssl --ssl-verify-server-cert -e "call test.have_ssl()" -ERROR 2026 (HY000): SSL connection error: Failed to verify the server certificate +ERROR 2026 (HY000): TLS/SSL error: Failed to verify the server certificate drop procedure have_ssl; diff --git a/mysql-test/main/ssl_7937.test b/mysql-test/main/ssl_7937.test index 59c13107e01..58583a32ae3 100644 --- a/mysql-test/main/ssl_7937.test +++ b/mysql-test/main/ssl_7937.test @@ -21,6 +21,6 @@ create procedure have_ssl() --exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-verify-server-cert -e "call test.have_ssl()" 2>&1 --echo mysql --ssl --ssl-verify-server-cert -e "call test.have_ssl()" ---replace_regex /SSL connection error.*certificate[^\n]*/SSL connection error: Failed to verify the server certificate/ +--replace_regex /TLS\/SSL error.*certificate[^\n]*/TLS\/SSL error: Failed to verify the server certificate/ --exec $MYSQL --ssl --ssl-verify-server-cert -e "call test.have_ssl()" 2>&1 drop procedure have_ssl; diff --git a/mysql-test/main/ssl_ca.result b/mysql-test/main/ssl_ca.result index afffe4e4dff..85683a0ba90 100644 --- a/mysql-test/main/ssl_ca.result +++ b/mysql-test/main/ssl_ca.result @@ -2,7 +2,7 @@ # Bug#21920657: SSL-CA FAILS SILENTLY IF THE PATH CANNOT BE FOUND # # try to connect with wrong '--ssl-ca' path : should fail -ERROR 2026 (HY000): SSL connection error: xxxx +ERROR 2026 (HY000): TLS/SSL error: xxxx # try to connect with correct '--ssl-ca' path : should connect have_ssl 1 diff --git a/mysql-test/main/ssl_ca.test b/mysql-test/main/ssl_ca.test index 106da140130..b66afc22188 100644 --- a/mysql-test/main/ssl_ca.test +++ b/mysql-test/main/ssl_ca.test @@ -7,7 +7,7 @@ --echo # try to connect with wrong '--ssl-ca' path : should fail ---replace_regex /SSL connection error.*/SSL connection error: xxxx/ +--replace_regex /TLS\/SSL error.*/TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/wrong-cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher';" 2>&1 --echo diff --git a/mysql-test/main/ssl_cipher.result b/mysql-test/main/ssl_cipher.result index 266c9f9322a..ec7cf7bea75 100644 --- a/mysql-test/main/ssl_cipher.result +++ b/mysql-test/main/ssl_cipher.result @@ -44,7 +44,7 @@ Ssl_cipher AES128-SHA SHOW STATUS LIKE 'Ssl_cipher'; Variable_name Value Ssl_cipher AES128-SHA -mysqltest: Could not open connection 'default': 2026 SSL connection error: xxxxVariable_name Value +mysqltest: Could not open connection 'default': 2026 TLS/SSL error: xxxxVariable_name Value Ssl_cipher AES256-SHA Variable_name Value Ssl_cipher AES128-SHA diff --git a/mysql-test/main/ssl_cipher.test b/mysql-test/main/ssl_cipher.test index 27854654a9f..4aa9ce812b7 100644 --- a/mysql-test/main/ssl_cipher.test +++ b/mysql-test/main/ssl_cipher.test @@ -54,7 +54,7 @@ EOF # Test to connect using a specifi cipher --exec $MYSQL_TEST --ssl-cipher=AES128-SHA < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 # Test to connect using an unknown cipher ---replace_regex /2026 SSL connection error.*/2026 SSL connection error: xxxx/ +--replace_regex /2026 TLS\/SSL error.*/2026 TLS\/SSL error: xxxx/ --error 1 --exec $MYSQL_TEST --ssl-cipher=UNKNOWN-CIPHER < $MYSQLTEST_VARDIR/tmp/test.sql 2>&1 --remove_file $MYSQLTEST_VARDIR/tmp/test.sql diff --git a/mysql-test/main/ssl_crl.result b/mysql-test/main/ssl_crl.result index 598774bd772..d5603254ea5 100644 --- a/mysql-test/main/ssl_crl.result +++ b/mysql-test/main/ssl_crl.result @@ -2,4 +2,4 @@ Variable_name Value Ssl_version TLS_VERSION # try logging in with a certificate in the server's --ssl-crl : should fail -ERROR 2026 (HY000): SSL connection error: sslv3 alert certificate revoked +ERROR 2026 (HY000): TLS/SSL error: sslv3 alert certificate revoked diff --git a/mysql-test/main/ssl_crl.test b/mysql-test/main/ssl_crl.test index e79f8ff32c2..7ed5c210215 100644 --- a/mysql-test/main/ssl_crl.test +++ b/mysql-test/main/ssl_crl.test @@ -8,6 +8,6 @@ --echo # try logging in with a certificate in the server's --ssl-crl : should fail # OpenSSL 1.1.1a correctly rejects the certificate, but the error message is different ---replace_regex /ERROR 2013 \(HY000\): Lost connection to MySQL server at '.*', system error: [0-9]+/ERROR 2026 (HY000): SSL connection error: sslv3 alert certificate revoked/ +--replace_regex /ERROR 2013 \(HY000\): Lost connection to MySQL server at '.*', system error: [0-9]+/ERROR 2026 (HY000): TLS\/SSL error: sslv3 alert certificate revoked/ --error 1 --exec $MYSQL --ssl-ca=$MYSQL_TEST_DIR/std_data/cacert.pem --ssl-key=$MYSQL_TEST_DIR/std_data/client-key.pem --ssl-cert=$MYSQL_TEST_DIR/std_data/client-cert.pem test -e "SHOW STATUS LIKE 'Ssl_version'" 2>&1 diff --git a/mysql-test/main/ssl_crl_clients.result b/mysql-test/main/ssl_crl_clients.result index 0d8ed9a4158..44ba101c892 100644 --- a/mysql-test/main/ssl_crl_clients.result +++ b/mysql-test/main/ssl_crl_clients.result @@ -1,13 +1,13 @@ # Test clients with and without CRL lists ############ Test mysql ############## # Test mysql connecting to a server with a certificate revoked by -crl -ERROR 2026 (HY000): SSL connection error: certificate revoked +ERROR 2026 (HY000): TLS/SSL error: certificate revoked # Test mysql connecting to a server with a certificate revoked by -crlpath -ERROR 2026 (HY000): SSL connection error: certificate revoked +ERROR 2026 (HY000): TLS/SSL error: certificate revoked ############ Test mysqladmin ############## # Test mysqladmin connecting to a server with a certificate revoked by -crl mysqladmin: connect to server at 'localhost' failed -error: 'SSL connection error: certificate revoked' +error: 'TLS/SSL error: certificate revoked' # Test mysqladmin connecting to a server with a certificate revoked by -crlpath mysqladmin: connect to server at 'localhost' failed -error: 'SSL connection error: certificate revoked' +error: 'TLS/SSL error: certificate revoked' diff --git a/mysql-test/main/ssl_crl_clients.test b/mysql-test/main/ssl_crl_clients.test index f1dc4909cc6..0023dee03ac 100644 --- a/mysql-test/main/ssl_crl_clients.test +++ b/mysql-test/main/ssl_crl_clients.test @@ -34,11 +34,11 @@ copy_file $MYSQL_TEST_DIR/std_data/server-cert.crl $MYSQL_TMP_DIR/ed1f42db.r0; let $admin_suffix = --default-character-set=latin1 -S $MASTER_MYSOCK -P $MASTER_MYPORT -u root --password= ping; --echo # Test mysqladmin connecting to a server with a certificate revoked by -crl ---replace_regex /.*mysqladmin.*:/mysqladmin:/ /SSL connection error: .*CRYPT_E_REVOKED./SSL connection error: certificate revoked/ +--replace_regex /.*mysqladmin.*:/mysqladmin:/ /TLS\/SSL error: .*CRYPT_E_REVOKED./TLS\/SSL error: certificate revoked/ --error 1 --exec $MYSQLADMIN $ssl_crl $admin_suffix 2>&1 --echo # Test mysqladmin connecting to a server with a certificate revoked by -crlpath ---replace_regex /.*mysqladmin.*:/mysqladmin:/ /SSL connection error: .*CRYPT_E_REVOKED./SSL connection error: certificate revoked/ +--replace_regex /.*mysqladmin.*:/mysqladmin:/ /TLS\/SSL error: .*CRYPT_E_REVOKED./TLS\/SSL error: certificate revoked/ --error 1 --exec $MYSQLADMIN $ssl_crlpath $admin_suffix 2>&1 diff --git a/mysql-test/main/ssl_system_ca,bad.result b/mysql-test/main/ssl_system_ca,bad.result index b9c6d3e29d8..1799e9f5e32 100644 --- a/mysql-test/main/ssl_system_ca,bad.result +++ b/mysql-test/main/ssl_system_ca,bad.result @@ -1 +1 @@ -ERROR 2026 (HY000): SSL connection error: Validation of SSL server certificate failed +ERROR 2026 (HY000): TLS/SSL error: Validation of SSL server certificate failed diff --git a/mysql-test/main/ssl_timeout.result b/mysql-test/main/ssl_timeout.result index 3c94a9927da..208be527a6b 100644 --- a/mysql-test/main/ssl_timeout.result +++ b/mysql-test/main/ssl_timeout.result @@ -5,6 +5,6 @@ SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS have_ssl 1 SELECT SLEEP(600); -ERROR HY000: Lost connection to MySQL server during query +Got one of the listed errors connection default; disconnect ssl_con; diff --git a/mysql-test/main/ssl_timeout.test b/mysql-test/main/ssl_timeout.test index 430fe7130de..f5965f874ff 100644 --- a/mysql-test/main/ssl_timeout.test +++ b/mysql-test/main/ssl_timeout.test @@ -10,7 +10,7 @@ connect (ssl_con,localhost,root,,,,,SSL read_timeout=5); SELECT (VARIABLE_VALUE <> '') AS have_ssl FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_cipher'; # --error CR_SERVER_LOST ---error 2013 +--error 2013,2026 SELECT SLEEP(600); connection default; diff --git a/mysql-test/main/wait_timeout.test b/mysql-test/main/wait_timeout.test index 84841aabb8b..f7289ceed1f 100644 --- a/mysql-test/main/wait_timeout.test +++ b/mysql-test/main/wait_timeout.test @@ -61,7 +61,7 @@ connection default; # When the connection is closed in this way, the error code should # be consistent see Bug#2845 for an explanation # depending on platform/client, either errno 2006 or 2013 can occur below ---error 2006,2013 +--error 2006,2013,5014 SELECT 2; --echo --enable_reconnect; --enable_reconnect @@ -113,7 +113,7 @@ connection con1; # When the connection is closed in this way, the error code should # be consistent see Bug#2845 for an explanation # depending on platform/client, either errno 2006 or 2013 can occur below ---error 2006,2013 +--error 2006,2013,5014 SELECT 2; --echo --enable_reconnect; --enable_reconnect diff --git a/mysql-test/suite/sys_vars/t/completion_type_func.test b/mysql-test/suite/sys_vars/t/completion_type_func.test index 2411cacf8bb..5c343cee9ab 100644 --- a/mysql-test/suite/sys_vars/t/completion_type_func.test +++ b/mysql-test/suite/sys_vars/t/completion_type_func.test @@ -146,7 +146,7 @@ COMMIT; --echo ## Inserting rows should give error here because connection should ## --echo ## disconnect after using COMMIT ## ---Error 2006,2013,ER_QUERY_INTERRUPTED,ER_CONNECTION_KILLED +--Error 2006,2013,ER_QUERY_INTERRUPTED,ER_CONNECTION_KILLED,5014 INSERT INTO t1 VALUES(4,'Record_4'); connection test_con2; @@ -160,7 +160,7 @@ INSERT INTO t1 VALUES(12,'Record_12'); ROLLBACK; --echo ## Expect a failure due to COMMIT/ROLLBACK AND RELEASE behavior ## ---Error 2006,2013,ER_QUERY_INTERRUPTED,ER_CONNECTION_KILLED +--Error 2006,2013,ER_QUERY_INTERRUPTED,ER_CONNECTION_KILLED,5014 INSERT INTO t1 VALUES(4,'Record_4'); connection default; -- cgit v1.2.1 From 61d08f74275b129c5d00daaa7856aead88f034ff Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 29 Jul 2022 14:48:01 +0200 Subject: mysql-5.7.39 --- include/mysql/psi/mysql_file.h | 2 +- include/mysql/psi/mysql_idle.h | 2 +- include/mysql/psi/mysql_mdl.h | 2 +- include/mysql/psi/mysql_memory.h | 2 +- include/mysql/psi/mysql_ps.h | 2 +- include/mysql/psi/mysql_socket.h | 2 +- include/mysql/psi/mysql_sp.h | 2 +- include/mysql/psi/mysql_stage.h | 2 +- include/mysql/psi/mysql_statement.h | 2 +- include/mysql/psi/mysql_table.h | 2 +- include/mysql/psi/mysql_thread.h | 9 +- include/mysql/psi/mysql_transaction.h | 2 +- include/mysql/psi/psi.h | 13 +- include/mysql/psi/psi_abi_v0.h | 2 +- include/mysql/psi/psi_abi_v1.h | 2 +- include/mysql/psi/psi_abi_v1.h.pp | 3 + include/mysql/psi/psi_abi_v2.h | 2 +- include/mysql/psi/psi_base.h | 8 +- include/mysql/psi/psi_memory.h | 2 +- .../suite/perfschema/include/processlist_load.inc | 39 ++ .../suite/perfschema/include/processlist_set.inc | 17 + .../suite/perfschema/r/ddl_processlist.result | 20 + mysql-test/suite/perfschema/r/dml_handler.result | 69 ++-- .../suite/perfschema/r/dml_processlist.result | 24 ++ .../suite/perfschema/r/information_schema.result | 10 + .../suite/perfschema/r/max_program_zero.result | 1 + .../suite/perfschema/r/misc_global_status.result | 101 +++++ mysql-test/suite/perfschema/r/ortho_iter.result | 1 + .../suite/perfschema/r/pfs_upgrade_event.result | 1 + .../suite/perfschema/r/pfs_upgrade_func.result | 1 + .../suite/perfschema/r/pfs_upgrade_proc.result | 1 + .../suite/perfschema/r/pfs_upgrade_table.result | 1 + .../suite/perfschema/r/pfs_upgrade_view.result | 1 + .../suite/perfschema/r/privilege_table_io.result | 1 + mysql-test/suite/perfschema/r/processlist.result | 201 ++++++++++ .../suite/perfschema/r/processlist_57.result | 345 +++++++++++++++++ .../suite/perfschema/r/processlist_acl.result | 255 +++++++++++++ .../perfschema/r/processlist_anonymous.result | 66 ++++ .../suite/perfschema/r/processlist_no_pfs.result | 181 +++++++++ .../suite/perfschema/r/processlist_port.result | 145 ++++++++ .../suite/perfschema/r/processlist_reg_user.result | 89 +++++ mysql-test/suite/perfschema/r/schema.result | 1 + mysql-test/suite/perfschema/r/show_sanity.result | 2 + .../perfschema/r/start_server_disable_idle.result | 1 + .../r/start_server_disable_stages.result | 1 + .../r/start_server_disable_statements.result | 1 + .../r/start_server_disable_transactions.result | 1 + .../perfschema/r/start_server_disable_waits.result | 1 + .../suite/perfschema/r/start_server_innodb.result | 1 + .../perfschema/r/start_server_low_index.result | 1 + .../r/start_server_low_table_lock.result | 1 + .../perfschema/r/start_server_no_account.result | 1 + .../perfschema/r/start_server_no_cond_class.result | 1 + .../perfschema/r/start_server_no_cond_inst.result | 1 + .../perfschema/r/start_server_no_file_class.result | 1 + .../perfschema/r/start_server_no_file_inst.result | 1 + .../suite/perfschema/r/start_server_no_host.result | 1 + .../perfschema/r/start_server_no_index.result | 1 + .../suite/perfschema/r/start_server_no_mdl.result | 1 + .../r/start_server_no_memory_class.result | 1 + .../r/start_server_no_mutex_class.result | 1 + .../perfschema/r/start_server_no_mutex_inst.result | 1 + ...start_server_no_prepared_stmts_instances.result | 1 + .../r/start_server_no_rwlock_class.result | 1 + .../r/start_server_no_rwlock_inst.result | 1 + .../r/start_server_no_setup_actors.result | 1 + .../r/start_server_no_setup_objects.result | 1 + .../r/start_server_no_socket_class.result | 1 + .../r/start_server_no_socket_inst.result | 1 + .../r/start_server_no_stage_class.result | 1 + .../r/start_server_no_stages_history.result | 1 + .../r/start_server_no_stages_history_long.result | 1 + .../r/start_server_no_statement_class.result | 1 + .../r/start_server_no_statements_history.result | 1 + .../start_server_no_statements_history_long.result | 1 + .../perfschema/r/start_server_no_table_hdl.result | 1 + .../perfschema/r/start_server_no_table_inst.result | 1 + .../perfschema/r/start_server_no_table_lock.result | 1 + .../r/start_server_no_thread_class.result | 1 + .../r/start_server_no_thread_inst.result | 1 + .../r/start_server_no_transactions_history.result | 1 + ...tart_server_no_transactions_history_long.result | 1 + .../suite/perfschema/r/start_server_no_user.result | 1 + .../r/start_server_no_waits_history.result | 1 + .../r/start_server_no_waits_history_long.result | 1 + .../suite/perfschema/r/start_server_nothing.result | 2 + .../suite/perfschema/r/start_server_off.result | 1 + .../suite/perfschema/r/start_server_on.result | 1 + .../r/statement_program_lost_inst.result | 1 + .../r/table_aggregate_global_2u_2t.result | 1 + .../r/table_aggregate_global_2u_3t.result | 1 + .../r/table_aggregate_global_4u_2t.result | 1 + .../r/table_aggregate_global_4u_3t.result | 1 + .../perfschema/r/table_aggregate_hist_2u_2t.result | 1 + .../perfschema/r/table_aggregate_hist_2u_3t.result | 1 + .../perfschema/r/table_aggregate_hist_4u_2t.result | 1 + .../perfschema/r/table_aggregate_hist_4u_3t.result | 1 + .../suite/perfschema/r/table_aggregate_off.result | 1 + .../r/table_aggregate_thread_2u_2t.result | 1 + .../r/table_aggregate_thread_2u_3t.result | 1 + .../r/table_aggregate_thread_4u_2t.result | 1 + .../r/table_aggregate_thread_4u_3t.result | 1 + .../r/table_io_aggregate_global_2u_2t.result | 1 + .../r/table_io_aggregate_global_2u_3t.result | 1 + .../r/table_io_aggregate_global_4u_2t.result | 1 + .../r/table_io_aggregate_global_4u_3t.result | 1 + .../r/table_io_aggregate_hist_2u_2t.result | 1 + .../r/table_io_aggregate_hist_2u_3t.result | 1 + .../r/table_io_aggregate_hist_4u_2t.result | 1 + .../r/table_io_aggregate_hist_4u_3t.result | 1 + .../r/table_io_aggregate_thread_2u_2t.result | 1 + .../r/table_io_aggregate_thread_2u_3t.result | 1 + .../r/table_io_aggregate_thread_4u_2t.result | 1 + .../r/table_io_aggregate_thread_4u_3t.result | 1 + .../r/table_lock_aggregate_global_2u_2t.result | 1 + .../r/table_lock_aggregate_global_2u_3t.result | 1 + .../r/table_lock_aggregate_global_4u_2t.result | 1 + .../r/table_lock_aggregate_global_4u_3t.result | 1 + .../r/table_lock_aggregate_hist_2u_2t.result | 1 + .../r/table_lock_aggregate_hist_2u_3t.result | 1 + .../r/table_lock_aggregate_hist_4u_2t.result | 1 + .../r/table_lock_aggregate_hist_4u_3t.result | 1 + .../r/table_lock_aggregate_thread_2u_2t.result | 1 + .../r/table_lock_aggregate_thread_2u_3t.result | 1 + .../r/table_lock_aggregate_thread_4u_2t.result | 1 + .../r/table_lock_aggregate_thread_4u_3t.result | 1 + mysql-test/suite/perfschema/r/table_schema.result | 8 + mysql-test/suite/perfschema/r/threads_mysql.result | 16 +- mysql-test/suite/perfschema/t/ddl_processlist.test | 32 ++ mysql-test/suite/perfschema/t/dml_processlist.test | 39 ++ .../perfschema/t/misc_global_status-master.opt | 1 + .../suite/perfschema/t/misc_global_status.test | 134 +++++++ .../suite/perfschema/t/processlist-master.opt | 1 + mysql-test/suite/perfschema/t/processlist.test | 197 ++++++++++ mysql-test/suite/perfschema/t/processlist_57.test | 349 ++++++++++++++++++ .../suite/perfschema/t/processlist_acl-master.opt | 1 + mysql-test/suite/perfschema/t/processlist_acl.test | 196 ++++++++++ .../suite/perfschema/t/processlist_anonymous.test | 111 ++++++ .../perfschema/t/processlist_no_pfs-master.opt | 2 + .../suite/perfschema/t/processlist_no_pfs.test | 29 ++ .../suite/perfschema/t/processlist_port-master.opt | 1 + .../suite/perfschema/t/processlist_port.test | 162 ++++++++ .../suite/perfschema/t/processlist_reg_user.test | 134 +++++++ mysql-test/suite/perfschema/t/threads_mysql.test | 6 +- storage/perfschema/CMakeLists.txt | 4 +- storage/perfschema/cursor_by_account.cc | 2 +- storage/perfschema/cursor_by_account.h | 2 +- storage/perfschema/cursor_by_host.cc | 2 +- storage/perfschema/cursor_by_host.h | 2 +- storage/perfschema/cursor_by_thread.cc | 2 +- storage/perfschema/cursor_by_thread.h | 2 +- .../perfschema/cursor_by_thread_connect_attr.cc | 2 +- storage/perfschema/cursor_by_thread_connect_attr.h | 2 +- storage/perfschema/cursor_by_user.cc | 2 +- storage/perfschema/cursor_by_user.h | 2 +- storage/perfschema/ha_perfschema.cc | 49 ++- storage/perfschema/ha_perfschema.h | 2 +- storage/perfschema/pfs.cc | 15 +- storage/perfschema/pfs.h | 2 +- storage/perfschema/pfs_account.cc | 29 +- storage/perfschema/pfs_account.h | 2 +- storage/perfschema/pfs_atomic.h | 2 +- storage/perfschema/pfs_autosize.cc | 2 +- storage/perfschema/pfs_buffer_container.cc | 2 +- storage/perfschema/pfs_buffer_container.h | 2 +- storage/perfschema/pfs_builtin_memory.cc | 2 +- storage/perfschema/pfs_builtin_memory.h | 2 +- storage/perfschema/pfs_check.cc | 2 +- storage/perfschema/pfs_column_types.h | 2 +- storage/perfschema/pfs_column_values.cc | 2 +- storage/perfschema/pfs_column_values.h | 2 +- storage/perfschema/pfs_con_slice.cc | 2 +- storage/perfschema/pfs_con_slice.h | 2 +- storage/perfschema/pfs_defaults.cc | 2 +- storage/perfschema/pfs_defaults.h | 2 +- storage/perfschema/pfs_digest.cc | 2 +- storage/perfschema/pfs_digest.h | 2 +- storage/perfschema/pfs_engine_table.cc | 105 +++++- storage/perfschema/pfs_engine_table.h | 32 +- storage/perfschema/pfs_events.h | 2 +- storage/perfschema/pfs_events_stages.cc | 2 +- storage/perfschema/pfs_events_stages.h | 2 +- storage/perfschema/pfs_events_statements.cc | 2 +- storage/perfschema/pfs_events_statements.h | 2 +- storage/perfschema/pfs_events_transactions.cc | 2 +- storage/perfschema/pfs_events_transactions.h | 2 +- storage/perfschema/pfs_events_waits.cc | 2 +- storage/perfschema/pfs_events_waits.h | 2 +- storage/perfschema/pfs_global.cc | 2 +- storage/perfschema/pfs_global.h | 2 +- storage/perfschema/pfs_host.cc | 2 +- storage/perfschema/pfs_host.h | 2 +- storage/perfschema/pfs_instr.cc | 4 +- storage/perfschema/pfs_instr.h | 5 +- storage/perfschema/pfs_instr_class.cc | 2 +- storage/perfschema/pfs_instr_class.h | 5 +- storage/perfschema/pfs_lock.h | 2 +- storage/perfschema/pfs_memory.cc | 2 +- storage/perfschema/pfs_memory.h | 2 +- storage/perfschema/pfs_prepared_stmt.cc | 2 +- storage/perfschema/pfs_prepared_stmt.h | 2 +- storage/perfschema/pfs_program.cc | 2 +- storage/perfschema/pfs_program.h | 2 +- storage/perfschema/pfs_server.cc | 2 +- storage/perfschema/pfs_server.h | 2 +- storage/perfschema/pfs_setup_actor.cc | 2 +- storage/perfschema/pfs_setup_actor.h | 2 +- storage/perfschema/pfs_setup_object.cc | 2 +- storage/perfschema/pfs_setup_object.h | 2 +- storage/perfschema/pfs_stat.h | 2 +- storage/perfschema/pfs_status.cc | 2 +- storage/perfschema/pfs_status.h | 2 +- storage/perfschema/pfs_timer.cc | 2 +- storage/perfschema/pfs_timer.h | 2 +- storage/perfschema/pfs_user.cc | 2 +- storage/perfschema/pfs_user.h | 2 +- storage/perfschema/pfs_variable.cc | 2 +- storage/perfschema/pfs_variable.h | 2 +- storage/perfschema/pfs_visitor.cc | 2 +- storage/perfschema/pfs_visitor.h | 2 +- storage/perfschema/table_accounts.cc | 12 +- storage/perfschema/table_accounts.h | 3 +- storage/perfschema/table_all_instr.cc | 2 +- storage/perfschema/table_all_instr.h | 2 +- .../table_esgs_by_account_by_event_name.cc | 12 +- .../table_esgs_by_account_by_event_name.h | 3 +- .../perfschema/table_esgs_by_host_by_event_name.cc | 12 +- .../perfschema/table_esgs_by_host_by_event_name.h | 3 +- .../table_esgs_by_thread_by_event_name.cc | 12 +- .../table_esgs_by_thread_by_event_name.h | 3 +- .../perfschema/table_esgs_by_user_by_event_name.cc | 12 +- .../perfschema/table_esgs_by_user_by_event_name.h | 3 +- .../perfschema/table_esgs_global_by_event_name.cc | 12 +- .../perfschema/table_esgs_global_by_event_name.h | 3 +- .../table_esms_by_account_by_event_name.cc | 12 +- .../table_esms_by_account_by_event_name.h | 3 +- storage/perfschema/table_esms_by_digest.cc | 12 +- storage/perfschema/table_esms_by_digest.h | 3 +- .../perfschema/table_esms_by_host_by_event_name.cc | 12 +- .../perfschema/table_esms_by_host_by_event_name.h | 3 +- storage/perfschema/table_esms_by_program.cc | 12 +- storage/perfschema/table_esms_by_program.h | 3 +- .../table_esms_by_thread_by_event_name.cc | 12 +- .../table_esms_by_thread_by_event_name.h | 3 +- .../perfschema/table_esms_by_user_by_event_name.cc | 12 +- .../perfschema/table_esms_by_user_by_event_name.h | 3 +- .../perfschema/table_esms_global_by_event_name.cc | 12 +- .../perfschema/table_esms_global_by_event_name.h | 3 +- .../table_ets_by_account_by_event_name.cc | 12 +- .../table_ets_by_account_by_event_name.h | 3 +- .../perfschema/table_ets_by_host_by_event_name.cc | 12 +- .../perfschema/table_ets_by_host_by_event_name.h | 3 +- .../table_ets_by_thread_by_event_name.cc | 12 +- .../perfschema/table_ets_by_thread_by_event_name.h | 3 +- .../perfschema/table_ets_by_user_by_event_name.cc | 12 +- .../perfschema/table_ets_by_user_by_event_name.h | 3 +- .../perfschema/table_ets_global_by_event_name.cc | 12 +- .../perfschema/table_ets_global_by_event_name.h | 3 +- storage/perfschema/table_events_stages.cc | 32 +- storage/perfschema/table_events_stages.h | 5 +- storage/perfschema/table_events_statements.cc | 32 +- storage/perfschema/table_events_statements.h | 5 +- storage/perfschema/table_events_transactions.cc | 32 +- storage/perfschema/table_events_transactions.h | 5 +- storage/perfschema/table_events_waits.cc | 32 +- storage/perfschema/table_events_waits.h | 5 +- storage/perfschema/table_events_waits_summary.cc | 12 +- storage/perfschema/table_events_waits_summary.h | 3 +- .../table_ews_by_account_by_event_name.cc | 12 +- .../table_ews_by_account_by_event_name.h | 3 +- .../perfschema/table_ews_by_host_by_event_name.cc | 12 +- .../perfschema/table_ews_by_host_by_event_name.h | 3 +- .../table_ews_by_thread_by_event_name.cc | 12 +- .../perfschema/table_ews_by_thread_by_event_name.h | 3 +- .../perfschema/table_ews_by_user_by_event_name.cc | 12 +- .../perfschema/table_ews_by_user_by_event_name.h | 3 +- .../perfschema/table_ews_global_by_event_name.cc | 12 +- .../perfschema/table_ews_global_by_event_name.h | 3 +- storage/perfschema/table_file_instances.cc | 12 +- storage/perfschema/table_file_instances.h | 3 +- .../perfschema/table_file_summary_by_event_name.cc | 12 +- .../perfschema/table_file_summary_by_event_name.h | 3 +- .../perfschema/table_file_summary_by_instance.cc | 12 +- .../perfschema/table_file_summary_by_instance.h | 3 +- storage/perfschema/table_global_status.cc | 12 +- storage/perfschema/table_global_status.h | 3 +- storage/perfschema/table_global_variables.cc | 12 +- storage/perfschema/table_global_variables.h | 3 +- storage/perfschema/table_helper.cc | 2 +- storage/perfschema/table_helper.h | 2 +- storage/perfschema/table_host_cache.cc | 12 +- storage/perfschema/table_host_cache.h | 3 +- storage/perfschema/table_hosts.cc | 12 +- storage/perfschema/table_hosts.h | 3 +- storage/perfschema/table_md_locks.cc | 12 +- storage/perfschema/table_md_locks.h | 3 +- .../table_mems_by_account_by_event_name.cc | 12 +- .../table_mems_by_account_by_event_name.h | 3 +- .../perfschema/table_mems_by_host_by_event_name.cc | 12 +- .../perfschema/table_mems_by_host_by_event_name.h | 3 +- .../table_mems_by_thread_by_event_name.cc | 12 +- .../table_mems_by_thread_by_event_name.h | 3 +- .../perfschema/table_mems_by_user_by_event_name.cc | 12 +- .../perfschema/table_mems_by_user_by_event_name.h | 3 +- .../perfschema/table_mems_global_by_event_name.cc | 12 +- .../perfschema/table_mems_global_by_event_name.h | 3 +- storage/perfschema/table_os_global_by_type.cc | 12 +- storage/perfschema/table_os_global_by_type.h | 3 +- storage/perfschema/table_performance_timers.cc | 12 +- storage/perfschema/table_performance_timers.h | 3 +- .../perfschema/table_prepared_stmt_instances.cc | 12 +- storage/perfschema/table_prepared_stmt_instances.h | 3 +- storage/perfschema/table_processlist.cc | 406 +++++++++++++++++++++ storage/perfschema/table_processlist.h | 133 +++++++ .../table_replication_applier_configuration.cc | 12 +- .../table_replication_applier_configuration.h | 3 +- .../perfschema/table_replication_applier_status.cc | 12 +- .../perfschema/table_replication_applier_status.h | 3 +- ...le_replication_applier_status_by_coordinator.cc | 12 +- ...ble_replication_applier_status_by_coordinator.h | 3 +- .../table_replication_applier_status_by_worker.cc | 12 +- .../table_replication_applier_status_by_worker.h | 3 +- .../table_replication_connection_configuration.cc | 12 +- .../table_replication_connection_configuration.h | 3 +- .../table_replication_connection_status.cc | 12 +- .../table_replication_connection_status.h | 3 +- .../table_replication_group_member_stats.cc | 12 +- .../table_replication_group_member_stats.h | 3 +- .../perfschema/table_replication_group_members.cc | 12 +- .../perfschema/table_replication_group_members.h | 3 +- .../table_session_account_connect_attrs.cc | 12 +- .../table_session_account_connect_attrs.h | 3 +- storage/perfschema/table_session_connect.cc | 2 +- storage/perfschema/table_session_connect.h | 2 +- storage/perfschema/table_session_connect_attrs.cc | 12 +- storage/perfschema/table_session_connect_attrs.h | 3 +- storage/perfschema/table_session_status.cc | 12 +- storage/perfschema/table_session_status.h | 3 +- storage/perfschema/table_session_variables.cc | 12 +- storage/perfschema/table_session_variables.h | 3 +- storage/perfschema/table_setup_actors.cc | 12 +- storage/perfschema/table_setup_actors.h | 3 +- storage/perfschema/table_setup_consumers.cc | 12 +- storage/perfschema/table_setup_consumers.h | 3 +- storage/perfschema/table_setup_instruments.cc | 12 +- storage/perfschema/table_setup_instruments.h | 3 +- storage/perfschema/table_setup_objects.cc | 12 +- storage/perfschema/table_setup_objects.h | 3 +- storage/perfschema/table_setup_timers.cc | 12 +- storage/perfschema/table_setup_timers.h | 3 +- storage/perfschema/table_socket_instances.cc | 12 +- storage/perfschema/table_socket_instances.h | 3 +- .../table_socket_summary_by_event_name.cc | 12 +- .../table_socket_summary_by_event_name.h | 3 +- .../perfschema/table_socket_summary_by_instance.cc | 12 +- .../perfschema/table_socket_summary_by_instance.h | 3 +- storage/perfschema/table_status_by_account.cc | 12 +- storage/perfschema/table_status_by_account.h | 3 +- storage/perfschema/table_status_by_host.cc | 12 +- storage/perfschema/table_status_by_host.h | 3 +- storage/perfschema/table_status_by_thread.cc | 14 +- storage/perfschema/table_status_by_thread.h | 3 +- storage/perfschema/table_status_by_user.cc | 12 +- storage/perfschema/table_status_by_user.h | 3 +- storage/perfschema/table_sync_instances.cc | 32 +- storage/perfschema/table_sync_instances.h | 5 +- storage/perfschema/table_table_handles.cc | 12 +- storage/perfschema/table_table_handles.h | 3 +- storage/perfschema/table_threads.cc | 12 +- storage/perfschema/table_threads.h | 3 +- storage/perfschema/table_tiws_by_index_usage.cc | 12 +- storage/perfschema/table_tiws_by_index_usage.h | 3 +- storage/perfschema/table_tiws_by_table.cc | 12 +- storage/perfschema/table_tiws_by_table.h | 3 +- storage/perfschema/table_tlws_by_table.cc | 12 +- storage/perfschema/table_tlws_by_table.h | 3 +- storage/perfschema/table_users.cc | 12 +- storage/perfschema/table_users.h | 3 +- storage/perfschema/table_uvar_by_thread.cc | 12 +- storage/perfschema/table_uvar_by_thread.h | 3 +- storage/perfschema/table_variables_by_thread.cc | 12 +- storage/perfschema/table_variables_by_thread.h | 3 +- storage/perfschema/unittest/CMakeLists.txt | 2 +- storage/perfschema/unittest/conf.txt | 2 +- storage/perfschema/unittest/pfs-t.cc | 2 +- storage/perfschema/unittest/pfs_account-oom-t.cc | 2 +- storage/perfschema/unittest/pfs_connect_attr-t.cc | 2 +- storage/perfschema/unittest/pfs_host-oom-t.cc | 2 +- storage/perfschema/unittest/pfs_instr-oom-t.cc | 2 +- storage/perfschema/unittest/pfs_instr-t.cc | 2 +- .../perfschema/unittest/pfs_instr_class-oom-t.cc | 2 +- storage/perfschema/unittest/pfs_instr_class-t.cc | 2 +- storage/perfschema/unittest/pfs_misc-t.cc | 2 +- storage/perfschema/unittest/pfs_noop-t.cc | 4 +- storage/perfschema/unittest/pfs_server_stubs.cc | 2 +- storage/perfschema/unittest/pfs_timer-t.cc | 2 +- storage/perfschema/unittest/pfs_user-oom-t.cc | 2 +- .../perfschema/unittest/stub_global_status_var.h | 2 +- storage/perfschema/unittest/stub_pfs_defaults.h | 2 +- storage/perfschema/unittest/stub_pfs_global.h | 2 +- storage/perfschema/unittest/stub_print_error.h | 2 +- 401 files changed, 4852 insertions(+), 527 deletions(-) create mode 100644 mysql-test/suite/perfschema/include/processlist_load.inc create mode 100644 mysql-test/suite/perfschema/include/processlist_set.inc create mode 100644 mysql-test/suite/perfschema/r/ddl_processlist.result create mode 100644 mysql-test/suite/perfschema/r/dml_processlist.result create mode 100644 mysql-test/suite/perfschema/r/misc_global_status.result create mode 100644 mysql-test/suite/perfschema/r/processlist.result create mode 100644 mysql-test/suite/perfschema/r/processlist_57.result create mode 100644 mysql-test/suite/perfschema/r/processlist_acl.result create mode 100644 mysql-test/suite/perfschema/r/processlist_anonymous.result create mode 100644 mysql-test/suite/perfschema/r/processlist_no_pfs.result create mode 100644 mysql-test/suite/perfschema/r/processlist_port.result create mode 100644 mysql-test/suite/perfschema/r/processlist_reg_user.result create mode 100644 mysql-test/suite/perfschema/t/ddl_processlist.test create mode 100644 mysql-test/suite/perfschema/t/dml_processlist.test create mode 100644 mysql-test/suite/perfschema/t/misc_global_status-master.opt create mode 100644 mysql-test/suite/perfschema/t/misc_global_status.test create mode 100644 mysql-test/suite/perfschema/t/processlist-master.opt create mode 100644 mysql-test/suite/perfschema/t/processlist.test create mode 100644 mysql-test/suite/perfschema/t/processlist_57.test create mode 100644 mysql-test/suite/perfschema/t/processlist_acl-master.opt create mode 100644 mysql-test/suite/perfschema/t/processlist_acl.test create mode 100644 mysql-test/suite/perfschema/t/processlist_anonymous.test create mode 100644 mysql-test/suite/perfschema/t/processlist_no_pfs-master.opt create mode 100644 mysql-test/suite/perfschema/t/processlist_no_pfs.test create mode 100644 mysql-test/suite/perfschema/t/processlist_port-master.opt create mode 100644 mysql-test/suite/perfschema/t/processlist_port.test create mode 100644 mysql-test/suite/perfschema/t/processlist_reg_user.test create mode 100644 storage/perfschema/table_processlist.cc create mode 100644 storage/perfschema/table_processlist.h diff --git a/include/mysql/psi/mysql_file.h b/include/mysql/psi/mysql_file.h index 9f87aa3e64f..8f0fe6d9c78 100644 --- a/include/mysql/psi/mysql_file.h +++ b/include/mysql/psi/mysql_file.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_idle.h b/include/mysql/psi/mysql_idle.h index ca657b4476b..61a25f20a0e 100644 --- a/include/mysql/psi/mysql_idle.h +++ b/include/mysql/psi/mysql_idle.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2011, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_mdl.h b/include/mysql/psi/mysql_mdl.h index 4dba7ccb2c1..45723a60d3b 100644 --- a/include/mysql/psi/mysql_mdl.h +++ b/include/mysql/psi/mysql_mdl.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2012, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_memory.h b/include/mysql/psi/mysql_memory.h index 11a8f8438a7..03dc181b83d 100644 --- a/include/mysql/psi/mysql_memory.h +++ b/include/mysql/psi/mysql_memory.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2012, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_ps.h b/include/mysql/psi/mysql_ps.h index e664d07c451..a3291e3402e 100644 --- a/include/mysql/psi/mysql_ps.h +++ b/include/mysql/psi/mysql_ps.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2014, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2014, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_socket.h b/include/mysql/psi/mysql_socket.h index ea86db0049c..3bc22dddca9 100644 --- a/include/mysql/psi/mysql_socket.h +++ b/include/mysql/psi/mysql_socket.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2010, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_sp.h b/include/mysql/psi/mysql_sp.h index 68b79f1b852..1fec59cec91 100644 --- a/include/mysql/psi/mysql_sp.h +++ b/include/mysql/psi/mysql_sp.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2013, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_stage.h b/include/mysql/psi/mysql_stage.h index 2e09004d93e..473611dc66d 100644 --- a/include/mysql/psi/mysql_stage.h +++ b/include/mysql/psi/mysql_stage.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2010, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_statement.h b/include/mysql/psi/mysql_statement.h index 953400ff7e0..bee98456d2f 100644 --- a/include/mysql/psi/mysql_statement.h +++ b/include/mysql/psi/mysql_statement.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2010, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_table.h b/include/mysql/psi/mysql_table.h index 7492f41ca5b..a0755aa4c92 100644 --- a/include/mysql/psi/mysql_table.h +++ b/include/mysql/psi/mysql_table.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2010, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/mysql_thread.h b/include/mysql/psi/mysql_thread.h index 479d1511df4..c25e90f2120 100644 --- a/include/mysql/psi/mysql_thread.h +++ b/include/mysql/psi/mysql_thread.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, @@ -1320,6 +1320,13 @@ static inline void inline_mysql_thread_set_psi_THD(THD *thd) } #endif /* __cplusplus */ +static inline void mysql_thread_set_peer_port(uint port MY_ATTRIBUTE ((unused))) { +#ifdef HAVE_PSI_THREAD_INTERFACE + struct PSI_thread *psi = PSI_THREAD_CALL(get_thread)(); + PSI_THREAD_CALL(set_thread_peer_port)(psi, port); +#endif +} + #endif #endif /* DISABLE_MYSQL_THREAD_H */ diff --git a/include/mysql/psi/mysql_transaction.h b/include/mysql/psi/mysql_transaction.h index 075b8543fbd..763c3aa05dd 100644 --- a/include/mysql/psi/mysql_transaction.h +++ b/include/mysql/psi/mysql_transaction.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2013, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/psi.h b/include/mysql/psi/psi.h index e16a194db1f..98bcffd7b5c 100644 --- a/include/mysql/psi/psi.h +++ b/include/mysql/psi/psi.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, @@ -1678,6 +1678,15 @@ typedef void (*set_thread_info_v1_t)(const char* info, uint info_len); */ typedef void (*set_thread_v1_t)(struct PSI_thread *thread); +/** + Assign the remote (peer) port to the instrumented thread. + + @param thread pointer to the thread instrumentation + @param port the remote port +*/ +typedef void (*set_thread_peer_port_v1_t)(PSI_thread *thread, + unsigned int port); + /** Delete the current thread instrumentation. */ typedef void (*delete_current_thread_v1_t)(void); @@ -2724,6 +2733,8 @@ struct PSI_v1 start_metadata_wait_v1_t start_metadata_wait; end_metadata_wait_v1_t end_metadata_wait; + + set_thread_peer_port_v1_t set_thread_peer_port; }; /** @} (end of group Group_PSI_v1) */ diff --git a/include/mysql/psi/psi_abi_v0.h b/include/mysql/psi/psi_abi_v0.h index 2272c41b9d5..2fe6546ecac 100644 --- a/include/mysql/psi/psi_abi_v0.h +++ b/include/mysql/psi/psi_abi_v0.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2011, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/psi_abi_v1.h b/include/mysql/psi/psi_abi_v1.h index ba244be38b6..78c2ddb094f 100644 --- a/include/mysql/psi/psi_abi_v1.h +++ b/include/mysql/psi/psi_abi_v1.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/psi_abi_v1.h.pp b/include/mysql/psi/psi_abi_v1.h.pp index 10fcde7128e..b84be5867a9 100644 --- a/include/mysql/psi/psi_abi_v1.h.pp +++ b/include/mysql/psi/psi_abi_v1.h.pp @@ -463,6 +463,8 @@ typedef void (*set_thread_start_time_v1_t)(time_t start_time); typedef void (*set_thread_state_v1_t)(const char* state); typedef void (*set_thread_info_v1_t)(const char* info, uint info_len); typedef void (*set_thread_v1_t)(struct PSI_thread *thread); +typedef void (*set_thread_peer_port_v1_t)(PSI_thread *thread, + unsigned int port); typedef void (*delete_current_thread_v1_t)(void); typedef void (*delete_thread_v1_t)(struct PSI_thread *thread); typedef struct PSI_file_locker* (*get_thread_file_name_locker_v1_t) @@ -834,6 +836,7 @@ struct PSI_v1 destroy_metadata_lock_v1_t destroy_metadata_lock; start_metadata_wait_v1_t start_metadata_wait; end_metadata_wait_v1_t end_metadata_wait; + set_thread_peer_port_v1_t set_thread_peer_port; }; typedef struct PSI_v1 PSI; typedef struct PSI_mutex_info_v1 PSI_mutex_info; diff --git a/include/mysql/psi/psi_abi_v2.h b/include/mysql/psi/psi_abi_v2.h index c70cfc8cb93..0aeebaca779 100644 --- a/include/mysql/psi/psi_abi_v2.h +++ b/include/mysql/psi/psi_abi_v2.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/include/mysql/psi/psi_base.h b/include/mysql/psi/psi_base.h index 624a55cff32..66d709b48ef 100644 --- a/include/mysql/psi/psi_base.h +++ b/include/mysql/psi/psi_base.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2008, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2008, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, @@ -89,6 +89,12 @@ extern "C" { */ #define PSI_FLAG_VOLATILITY_SESSION (1 << 6) +/** + System thread flag. + Indicates that the instrumented object exists on a system thread. +*/ +#define PSI_FLAG_THREAD_SYSTEM (1 << 9) + #ifdef HAVE_PSI_INTERFACE /** diff --git a/include/mysql/psi/psi_memory.h b/include/mysql/psi/psi_memory.h index 4640a29b4ef..454c3dbe2a1 100644 --- a/include/mysql/psi/psi_memory.h +++ b/include/mysql/psi/psi_memory.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, 2021, Oracle and/or its affiliates. +/* Copyright (c) 2013, 2022, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2.0, diff --git a/mysql-test/suite/perfschema/include/processlist_load.inc b/mysql-test/suite/perfschema/include/processlist_load.inc new file mode 100644 index 00000000000..5a14ea17d07 --- /dev/null +++ b/mysql-test/suite/perfschema/include/processlist_load.inc @@ -0,0 +1,39 @@ +# ../include/processlist_load.inc +# +# SUMMARY +# +# Execute PROCESSLIST queries, sorted by user +# +# USAGE +# +# Example: Using processlist_set.inc to set @@global.performance_schema_show_processlist +# +# let $pfs_spl = on/off +# --source ../include/processlist_set.inc +# --source ../include/processlist_load.inc +# +# Columns +# 1 2 3 4 5 6