Skip to content

Commit

Permalink
- Fix Catalog JSON table crash when no Jpath
Browse files Browse the repository at this point in the history
- Added JSON OBJECT specification for pretty != 2.
- Fix NULL values not recognized for nullable JSON columns
- Issue an error message when a JSON table is created without specifying LRECL if PRETTY != 2.
- Make JSONColumns use a TDBJSON class.
- Make JSON table using MAPFAM
modified:
  filamap.h
  filamtxt.h
  ha_connect.cc
  json.result
  tabjson.cpp
  tabjson.h
  table.cpp

- Implementing Discovery for the XML table type.
modified:
  domdoc.cpp
  domdoc.h
  ha_connect.cc
  libdoc.cpp
  plgxml.cpp
  plgxml.h
  reldef.cpp
  reldef.h
  tabxml.cpp
  tabxml.h

- Providing an error message when creating an ODBC table via discovery returns
  columns of more than one table.
modified:
  ha_connect.cc

- TableOptionStruct declaration moved from ha_connect.h to mycat.h
  To make it easier to use by other classes.
modified:
  ha_connect.cc
  ha_connect.h
  mycat.cc
  mycat.h
  reldef.cpp
  tabmysql.cpp
  taboccur.cpp
  tabpivot.cpp
  tabtbl.cpp
  tabutil.cpp
  tabxcl.cpp
  • Loading branch information
Buggynours committed Apr 17, 2015
1 parent 05b30fb commit eae8318
Show file tree
Hide file tree
Showing 25 changed files with 894 additions and 393 deletions.
1 change: 0 additions & 1 deletion storage/connect/connect.cc
Expand Up @@ -42,7 +42,6 @@
#include "tabcol.h"
#include "catalog.h"
#include "ha_connect.h"
#include "mycat.h"

#define my_strupr(p) my_caseup_str(default_charset_info, (p));
#define my_strlwr(p) my_casedn_str(default_charset_info, (p));
Expand Down
95 changes: 89 additions & 6 deletions storage/connect/domdoc.cpp
Expand Up @@ -275,7 +275,7 @@ PXNODE DOMNODE::GetNext(PGLOBAL g)
{
if (Nodep->nextSibling == NULL)
Next = NULL;
else if (!Next)
else // if (!Next)
Next = new(g) DOMNODE(Doc, Nodep->nextSibling);

return Next;
Expand All @@ -288,7 +288,7 @@ PXNODE DOMNODE::GetChild(PGLOBAL g)
{
if (Nodep->firstChild == NULL)
Children = NULL;
else if (!Children)
else // if (!Children)
Children = new(g) DOMNODE(Doc, Nodep->firstChild);

return Children;
Expand Down Expand Up @@ -441,15 +441,27 @@ PXNODE DOMNODE::SelectSingleNode(PGLOBAL g, char *xp, PXNODE np)
/******************************************************************/
PXATTR DOMNODE::GetAttribute(PGLOBAL g, char *name, PXATTR ap)
{
MSXML2::IXMLDOMElementPtr ep = Nodep;
MSXML2::IXMLDOMAttributePtr atp = ep->getAttributeNode(name);
MSXML2::IXMLDOMElementPtr ep;
MSXML2::IXMLDOMNamedNodeMapPtr nmp;
MSXML2::IXMLDOMAttributePtr atp;

if (name) {
ep = Nodep;
atp = ep->getAttributeNode(name);
nmp = NULL;
} else {
nmp = Nodep->Getattributes();
atp = nmp->Getitem(0);
} // endif name

if (atp) {
if (ap) {
((PDOMATTR)ap)->Atrp = atp;
((PDOMATTR)ap)->Nmp = nmp;
((PDOMATTR)ap)->K = 0;
return ap;
} else
return new(g) DOMATTR(Doc, atp);
return new(g) DOMATTR(Doc, atp, nmp);

} else
return NULL;
Expand Down Expand Up @@ -617,14 +629,85 @@ bool DOMNODELIST::DropItem(PGLOBAL g, int n)
/******************************************************************/
/* DOMATTR constructor. */
/******************************************************************/
DOMATTR::DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap)
DOMATTR::DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap,
MSXML2::IXMLDOMNamedNodeMapPtr nmp)
: XMLATTRIBUTE(dp)
{
Atrp = ap;
Nmp = nmp;
Ws = NULL;
Len = 0;
K = 0;
} // end of DOMATTR constructor

/******************************************************************/
/* Return the attribute name. */
/******************************************************************/
char *DOMATTR::GetName(PGLOBAL g)
{
if (!WideCharToMultiByte(CP_ACP, 0, Atrp->nodeName, -1,
Name, sizeof(Name), NULL, NULL)) {
strcpy(g->Message, MSG(NAME_CONV_ERR));
return NULL;
} // endif

return Name;
} // end of GetName

/******************************************************************/
/* Return the next attribute node. */
/* This funtion is implemented as needed by XMLColumns. */
/******************************************************************/
PXATTR DOMATTR::GetNext(PGLOBAL g)
{
if (!Nmp)
return NULL;

if (++K >= Nmp->Getlength()) {
Nmp->reset();
Nmp = NULL;
K = 0;
return NULL;
} // endif K

Atrp = Nmp->Getitem(K);
return this;
} // end of GetNext

/******************************************************************/
/* Return the content of a node and subnodes. */
/******************************************************************/
RCODE DOMATTR::GetText(PGLOBAL g, char *buf, int len)
{
RCODE rc = RC_OK;

if (!WideCharToMultiByte(CP_UTF8, 0, Atrp->text, -1,
buf, len, NULL, NULL)) {
DWORD lsr = GetLastError();

switch (lsr) {
case 0:
case ERROR_INSUFFICIENT_BUFFER: // 122L
sprintf(g->Message, "Truncated %s content", GetName(g));
rc = RC_INFO;
break;
case ERROR_NO_UNICODE_TRANSLATION: // 1113L
sprintf(g->Message, "Invalid character(s) in %s content",
GetName(g));
rc = RC_INFO;
break;
default:
sprintf(g->Message, "System error getting %s content",
GetName(g));
rc = RC_FX;
break;
} // endswitch

} // endif

return rc;
} // end of GetText

/******************************************************************/
/* Set the text content of an attribute. */
/******************************************************************/
Expand Down
19 changes: 14 additions & 5 deletions storage/connect/domdoc.h
Expand Up @@ -122,15 +122,24 @@ class DOMATTR : public XMLATTRIBUTE {
friend class DOMDOC;
friend class DOMNODE;
public:
// Properties
virtual char *GetName(PGLOBAL g);
virtual PXATTR GetNext(PGLOBAL);

// Methods
virtual bool SetText(PGLOBAL g, char *txtp, int len);
virtual RCODE GetText(PGLOBAL g, char *bufp, int len);
virtual bool SetText(PGLOBAL g, char *txtp, int len);

protected:
// Constructor
DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap);
DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap,
MSXML2::IXMLDOMNamedNodeMapPtr nmp = NULL);

// Members
MSXML2::IXMLDOMAttributePtr Atrp;
WCHAR *Ws;
int Len;
MSXML2::IXMLDOMAttributePtr Atrp;
MSXML2::IXMLDOMNamedNodeMapPtr Nmp;
char Name[64];
WCHAR *Ws;
int Len;
long K;
}; // end of class DOMATTR
1 change: 1 addition & 0 deletions storage/connect/filamap.h
Expand Up @@ -17,6 +17,7 @@ typedef class MAPFAM *PMAPFAM;
/* This is the variable file access method using file mapping. */
/***********************************************************************/
class DllExport MAPFAM : public TXTFAM {
friend class TDBJSON;
public:
// Constructor
MAPFAM(PDOSDEF tdp);
Expand Down
1 change: 1 addition & 0 deletions storage/connect/filamtxt.h
Expand Up @@ -42,6 +42,7 @@ class DllExport TXTFAM : public BLOCK {
virtual PTXF Duplicate(PGLOBAL g) = 0;
virtual bool GetUseTemp(void) {return false;}
virtual int GetDelRows(void) {return DelRows;}
PFBLOCK GetTo_Fb(void) {return To_Fb;}
int GetCurBlk(void) {return CurBlk;}
void SetTdbp(PTDBDOS tdbp) {Tdbp = tdbp;}
int GetBlock(void) {return Block;}
Expand Down
41 changes: 38 additions & 3 deletions storage/connect/ha_connect.cc
Expand Up @@ -145,7 +145,6 @@
#include "connect.h"
#include "user_connect.h"
#include "ha_connect.h"
#include "mycat.h"
#include "myutil.h"
#include "preparse.h"
#include "inihandl.h"
Expand All @@ -169,7 +168,7 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.03.0006 March 16, 2015";
char version[]= "Version 1.03.0006 April 12, 2015";

#if defined(WIN32)
char compver[]= "Version 1.03.0006 " __DATE__ " " __TIME__;
Expand Down Expand Up @@ -211,6 +210,7 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, char *tab, char *db, bool info);
PQRYRES JSONColumns(PGLOBAL g, char *dp, const char *fn, char *objn,
int pretty, int lvl, int mxr, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *dp, char *tab, PTOS topt, bool info);
void PushWarning(PGLOBAL g, THD *thd, int level);
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, const char *host,
const char *db, char *tab, const char *src, int port);
Expand Down Expand Up @@ -5228,6 +5228,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
strcpy(g->Message, "Missing OEM module or subtype");

break;
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
case TAB_XML:
#endif // LIBXML2_SUPPORT || DOMDOC_SUPPORT
case TAB_JSON:
if (!fn)
sprintf(g->Message, "Missing %s file name", topt->type);
Expand Down Expand Up @@ -5348,6 +5351,11 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
case TAB_JSON:
qrp= JSONColumns(g, (char*)db, fn, objn, pty, lrecl, lvl, fnc == FNC_COL);
break;
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
case TAB_XML:
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);
break;
Expand Down Expand Up @@ -5385,7 +5393,9 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
#endif // !NEW_WAY
} // endfor crp

} else {
} else {
char *schem= NULL;

// Not a catalog table
if (!qrp->Nblin) {
if (tab)
Expand Down Expand Up @@ -5469,6 +5479,19 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
key= crp->Kdata->GetCharValue(i);

break;
case FLD_SCHEM:
#if defined(ODBC_SUPPORT)
if (ttp == TAB_ODBC && crp->Kdata) {
if (schem && stricmp(schem, crp->Kdata->GetCharValue(i))) {
sprintf(g->Message,
"Several %s tables found, specify DBNAME", tab);
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
goto err;
} else if (!schem)
schem= crp->Kdata->GetCharValue(i);

} // endif ttp
#endif // ODBC_SUPPORT
default:
break; // Ignore
} // endswitch Fld
Expand Down Expand Up @@ -5790,6 +5813,18 @@ int ha_connect::create(const char *name, TABLE *table_arg,

} // endif type

if (type == TAB_JSON) {
int pretty= atoi(GetListOption(g, "Pretty", options->oplist, "2"));

if (!options->lrecl && pretty != 2) {
sprintf(g->Message, "LRECL must be specified for pretty=%d", pretty);
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
rc= HA_ERR_INTERNAL_ERROR;
DBUG_RETURN(rc);
} // endif lrecl

} // endif type

// Check column types
for (field= table_arg->field; *field; field++) {
fp= *field;
Expand Down
10 changes: 9 additions & 1 deletion storage/connect/ha_connect.h
Expand Up @@ -26,6 +26,11 @@
#pragma interface /* gcc class implementation */
#endif

/****************************************************************************/
/* mycat.h contains the TOS, PTOS, ha_table_option_struct declarations. */
/****************************************************************************/
#include "mycat.h"

static char *strz(PGLOBAL g, LEX_STRING &ls);

/****************************************************************************/
Expand Down Expand Up @@ -68,7 +73,6 @@ class XCHK : public BLOCK {

typedef class XCHK *PCHK;
typedef class user_connect *PCONNECT;
typedef struct ha_table_option_struct TOS, *PTOS;
typedef struct ha_field_option_struct FOS, *PFOS;
typedef struct ha_index_option_struct XOS, *PXOS;

Expand All @@ -80,6 +84,9 @@ extern handlerton *connect_hton;
These can be specified in the CREATE TABLE:
CREATE TABLE ( ... ) {...here...}
*/
#if 0 // moved to mycat.h
typedef struct ha_table_option_struct TOS, *PTOS;

struct ha_table_option_struct {
const char *type;
const char *filename;
Expand Down Expand Up @@ -111,6 +118,7 @@ struct ha_table_option_struct {
bool readonly;
bool sepindex;
};
#endif // 0

/**
structure for CREATE TABLE options (field options)
Expand Down

0 comments on commit eae8318

Please sign in to comment.