Skip to content

Commit fb98632

Browse files
committed
JSONColumns and XMLColumns revisited. They can retrieve their parameters directly
from the PTOS argument. For this to work, finding the table options is now split in HA_CONNECT functions and exported functions available from out of ha_connect. modified: storage/connect/ha_connect.cc modified: storage/connect/libdoc.cpp modified: storage/connect/mycat.h modified: storage/connect/plgdbsem.h modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/tabxml.cpp modified: storage/connect/tabxml.h The BIN table formats have been changed to handle the case of floating point values when used with Big Endian or Little Endian machines. modified: storage/connect/ha_connect.cc modified: storage/connect/mysql-test/connect/r/bin.result modified: storage/connect/mysql-test/connect/t/bin.test modified: storage/connect/reldef.cpp modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabfix.cpp modified: storage/connect/tabfix. h
1 parent 37840d5 commit fb98632

File tree

15 files changed

+369
-292
lines changed

15 files changed

+369
-292
lines changed

storage/connect/ha_connect.cc

Lines changed: 135 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,8 @@ extern "C" {
195195
/***********************************************************************/
196196
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
197197
PQRYRES VirColumns(PGLOBAL g, bool info);
198-
PQRYRES JSONColumns(PGLOBAL g, char *dp, const char *fn, char *objn,
199-
int pretty, int lvl, int mxr, bool info);
200-
PQRYRES XMLColumns(PGLOBAL g, char *dp, char *tab, PTOS topt, bool info);
198+
PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info);
199+
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
201200
void PushWarning(PGLOBAL g, THD *thd, int level);
202201
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, const char *host,
203202
const char *db, char *tab, const char *src, int port);
@@ -1017,6 +1016,117 @@ char *GetListOption(PGLOBAL g, const char *opname,
10171016
return opval;
10181017
} // end of GetListOption
10191018

1019+
/****************************************************************************/
1020+
/* Return the value of a string option or NULL if not specified. */
1021+
/****************************************************************************/
1022+
char *GetStringTableOption(PGLOBAL g, PTOS options, char *opname, char *sdef)
1023+
{
1024+
const char *opval= NULL;
1025+
1026+
if (!options)
1027+
return sdef;
1028+
else if (!stricmp(opname, "Type"))
1029+
opval= options->type;
1030+
else if (!stricmp(opname, "Filename"))
1031+
opval= options->filename;
1032+
else if (!stricmp(opname, "Optname"))
1033+
opval= options->optname;
1034+
else if (!stricmp(opname, "Tabname"))
1035+
opval= options->tabname;
1036+
else if (!stricmp(opname, "Tablist"))
1037+
opval= options->tablist;
1038+
else if (!stricmp(opname, "Database") ||
1039+
!stricmp(opname, "DBname"))
1040+
opval= options->dbname;
1041+
else if (!stricmp(opname, "Separator"))
1042+
opval= options->separator;
1043+
else if (!stricmp(opname, "Qchar"))
1044+
opval= options->qchar;
1045+
else if (!stricmp(opname, "Module"))
1046+
opval= options->module;
1047+
else if (!stricmp(opname, "Subtype"))
1048+
opval= options->subtype;
1049+
else if (!stricmp(opname, "Catfunc"))
1050+
opval= options->catfunc;
1051+
else if (!stricmp(opname, "Srcdef"))
1052+
opval= options->srcdef;
1053+
else if (!stricmp(opname, "Colist"))
1054+
opval= options->colist;
1055+
else if (!stricmp(opname, "Data_charset"))
1056+
opval= options->data_charset;
1057+
1058+
if (!opval && options && options->oplist)
1059+
opval= GetListOption(g, opname, options->oplist);
1060+
1061+
return opval ? (char*)opval : sdef;
1062+
} // end of GetStringTableOption
1063+
1064+
/****************************************************************************/
1065+
/* Return the value of a Boolean option or bdef if not specified. */
1066+
/****************************************************************************/
1067+
bool GetBooleanTableOption(PGLOBAL g, PTOS options, char *opname, bool bdef)
1068+
{
1069+
bool opval= bdef;
1070+
char *pv;
1071+
1072+
if (!options)
1073+
return bdef;
1074+
else if (!stricmp(opname, "Mapped"))
1075+
opval= options->mapped;
1076+
else if (!stricmp(opname, "Huge"))
1077+
opval= options->huge;
1078+
else if (!stricmp(opname, "Split"))
1079+
opval= options->split;
1080+
else if (!stricmp(opname, "Readonly"))
1081+
opval= options->readonly;
1082+
else if (!stricmp(opname, "SepIndex"))
1083+
opval= options->sepindex;
1084+
else if (!stricmp(opname, "Header"))
1085+
opval= (options->header != 0); // Is Boolean for some table types
1086+
else if (options->oplist)
1087+
if ((pv= GetListOption(g, opname, options->oplist)))
1088+
opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
1089+
1090+
return opval;
1091+
} // end of GetBooleanTableOption
1092+
1093+
/****************************************************************************/
1094+
/* Return the value of an integer option or NO_IVAL if not specified. */
1095+
/****************************************************************************/
1096+
int GetIntegerTableOption(PGLOBAL g, PTOS options, char *opname, int idef)
1097+
{
1098+
ulonglong opval= NO_IVAL;
1099+
1100+
if (!options)
1101+
return idef;
1102+
else if (!stricmp(opname, "Lrecl"))
1103+
opval= options->lrecl;
1104+
else if (!stricmp(opname, "Elements"))
1105+
opval= options->elements;
1106+
else if (!stricmp(opname, "Multiple"))
1107+
opval= options->multiple;
1108+
else if (!stricmp(opname, "Header"))
1109+
opval= options->header;
1110+
else if (!stricmp(opname, "Quoted"))
1111+
opval= options->quoted;
1112+
else if (!stricmp(opname, "Ending"))
1113+
opval= options->ending;
1114+
else if (!stricmp(opname, "Compressed"))
1115+
opval= (options->compressed);
1116+
1117+
if (opval == NO_IVAL) {
1118+
char *pv;
1119+
1120+
if ((pv= GetListOption(g, opname, options->oplist)))
1121+
opval= CharToNumber(pv, strlen(pv), ULONGLONG_MAX, true);
1122+
else
1123+
return idef;
1124+
1125+
} // endif opval
1126+
1127+
return (int)opval;
1128+
} // end of GetIntegerTableOption
1129+
10201130
/****************************************************************************/
10211131
/* Return the table option structure. */
10221132
/****************************************************************************/
@@ -1035,9 +1145,6 @@ char *ha_connect::GetRealString(const char *s)
10351145
char *sv;
10361146

10371147
if (IsPartitioned() && s) {
1038-
// sv= (char*)PlugSubAlloc(xp->g, NULL, strlen(s) + strlen(partname));
1039-
// With wrong string pattern, the size of the constructed string
1040-
// can be more than strlen(s) + strlen(partname)
10411148
sv= (char*)PlugSubAlloc(xp->g, NULL, 0);
10421149
sprintf(sv, s, partname);
10431150
PlugSubAlloc(xp->g, NULL, strlen(sv) + 1);
@@ -1048,7 +1155,7 @@ char *ha_connect::GetRealString(const char *s)
10481155
} // end of GetRealString
10491156

10501157
/****************************************************************************/
1051-
/* Return the value of a string option or NULL if not specified. */
1158+
/* Return the value of a string option or sdef if not specified. */
10521159
/****************************************************************************/
10531160
char *ha_connect::GetStringOption(char *opname, char *sdef)
10541161
{
@@ -1066,55 +1173,20 @@ char *ha_connect::GetStringOption(char *opname, char *sdef)
10661173
opval= thd_query_string(table->in_use)->str;
10671174
else if (!stricmp(opname, "Partname"))
10681175
opval= partname;
1069-
else if (!options)
1070-
;
1071-
else if (!stricmp(opname, "Type"))
1072-
opval= (char*)options->type;
1073-
else if (!stricmp(opname, "Filename"))
1074-
opval= GetRealString(options->filename);
1075-
else if (!stricmp(opname, "Optname"))
1076-
opval= (char*)options->optname;
1077-
else if (!stricmp(opname, "Tabname"))
1078-
opval= GetRealString(options->tabname);
1079-
else if (!stricmp(opname, "Tablist"))
1080-
opval= (char*)options->tablist;
1081-
else if (!stricmp(opname, "Database") ||
1082-
!stricmp(opname, "DBname"))
1083-
opval= (char*)options->dbname;
1084-
else if (!stricmp(opname, "Separator"))
1085-
opval= (char*)options->separator;
1086-
else if (!stricmp(opname, "Qchar"))
1087-
opval= (char*)options->qchar;
1088-
else if (!stricmp(opname, "Module"))
1089-
opval= (char*)options->module;
1090-
else if (!stricmp(opname, "Subtype"))
1091-
opval= (char*)options->subtype;
1092-
else if (!stricmp(opname, "Catfunc"))
1093-
opval= (char*)options->catfunc;
1094-
else if (!stricmp(opname, "Srcdef"))
1095-
opval= (char*)options->srcdef;
1096-
else if (!stricmp(opname, "Colist"))
1097-
opval= (char*)options->colist;
1098-
else if (!stricmp(opname, "Data_charset"))
1099-
opval= (char*)options->data_charset;
11001176
else if (!stricmp(opname, "Table_charset")) {
11011177
const CHARSET_INFO *chif= (tshp) ? tshp->table_charset
11021178
: table->s->table_charset;
11031179

11041180
if (chif)
11051181
opval= (char*)chif->csname;
11061182

1107-
} // endif Table_charset
1108-
1109-
if (!opval && options && options->oplist) {
1110-
opval= GetListOption(xp->g, opname, options->oplist);
1111-
1112-
if (opval && (!stricmp(opname, "connect")
1113-
|| !stricmp(opname, "tabname")
1114-
|| !stricmp(opname, "filename")))
1115-
opval = GetRealString(opval);
1183+
} else
1184+
opval= GetStringTableOption(xp->g, options, opname, NULL);
11161185

1117-
} // endif opval
1186+
if (opval && (!stricmp(opname, "connect")
1187+
|| !stricmp(opname, "tabname")
1188+
|| !stricmp(opname, "filename")))
1189+
opval = GetRealString(opval);
11181190

11191191
if (!opval) {
11201192
if (sdef && !strcmp(sdef, "*")) {
@@ -1145,31 +1217,13 @@ char *ha_connect::GetStringOption(char *opname, char *sdef)
11451217
/****************************************************************************/
11461218
bool ha_connect::GetBooleanOption(char *opname, bool bdef)
11471219
{
1148-
bool opval= bdef;
1149-
char *pv;
1220+
bool opval;
11501221
PTOS options= GetTableOptionStruct();
11511222

11521223
if (!stricmp(opname, "View"))
11531224
opval= (tshp) ? tshp->is_view : table_share->is_view;
1154-
else if (!options)
1155-
;
1156-
else if (!stricmp(opname, "Mapped"))
1157-
opval= options->mapped;
1158-
else if (!stricmp(opname, "Huge"))
1159-
opval= options->huge;
1160-
//else if (!stricmp(opname, "Compressed"))
1161-
// opval= options->compressed;
1162-
else if (!stricmp(opname, "Split"))
1163-
opval= options->split;
1164-
else if (!stricmp(opname, "Readonly"))
1165-
opval= options->readonly;
1166-
else if (!stricmp(opname, "SepIndex"))
1167-
opval= options->sepindex;
1168-
else if (!stricmp(opname, "Header"))
1169-
opval= (options->header != 0); // Is Boolean for some table types
1170-
else if (options->oplist)
1171-
if ((pv= GetListOption(xp->g, opname, options->oplist)))
1172-
opval= (!*pv || *pv == 'y' || *pv == 'Y' || atoi(pv) != 0);
1225+
else
1226+
opval= GetBooleanTableOption(xp->g, options, opname, bdef);
11731227

11741228
return opval;
11751229
} // end of GetBooleanOption
@@ -1198,37 +1252,18 @@ bool ha_connect::SetBooleanOption(char *opname, bool b)
11981252
/****************************************************************************/
11991253
int ha_connect::GetIntegerOption(char *opname)
12001254
{
1201-
ulonglong opval= NO_IVAL;
1202-
char *pv;
1255+
int opval;
12031256
PTOS options= GetTableOptionStruct();
12041257
TABLE_SHARE *tsp= (tshp) ? tshp : table_share;
12051258

12061259
if (!stricmp(opname, "Avglen"))
1207-
opval= (ulonglong)tsp->avg_row_length;
1260+
opval= (int)tsp->avg_row_length;
12081261
else if (!stricmp(opname, "Estimate"))
1209-
opval= (ulonglong)tsp->max_rows;
1210-
else if (!options)
1211-
;
1212-
else if (!stricmp(opname, "Lrecl"))
1213-
opval= options->lrecl;
1214-
else if (!stricmp(opname, "Elements"))
1215-
opval= options->elements;
1216-
else if (!stricmp(opname, "Multiple"))
1217-
opval= options->multiple;
1218-
else if (!stricmp(opname, "Header"))
1219-
opval= options->header;
1220-
else if (!stricmp(opname, "Quoted"))
1221-
opval= options->quoted;
1222-
else if (!stricmp(opname, "Ending"))
1223-
opval= options->ending;
1224-
else if (!stricmp(opname, "Compressed"))
1225-
opval= (options->compressed);
1226-
1227-
if (opval == (ulonglong)NO_IVAL && options && options->oplist)
1228-
if ((pv= GetListOption(xp->g, opname, options->oplist)))
1229-
opval= CharToNumber(pv, strlen(pv), ULONGLONG_MAX, true);
1262+
opval= (int)tsp->max_rows;
1263+
else
1264+
opval= GetIntegerTableOption(xp->g, options, opname, NO_IVAL);
12301265

1231-
return (int)opval;
1266+
return opval;
12321267
} // end of GetIntegerOption
12331268

12341269
/****************************************************************************/
@@ -4965,12 +5000,12 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
49655000
const char *fncn= "?";
49665001
const char *user, *fn, *db, *host, *pwd, *sep, *tbl, *src;
49675002
const char *col, *ocl, *rnk, *pic, *fcl, *skc;
4968-
char *tab, *dsn, *shm, *dpath, *objn;
5003+
char *tab, *dsn, *shm, *dpath;
49695004
#if defined(WIN32)
49705005
char *nsp= NULL, *cls= NULL;
49715006
#endif // WIN32
4972-
int port= 0, hdr= 0, mxr= 0, mxe= 0, rc= 0, lvl= 0;
4973-
int cop __attribute__((unused))= 0, pty= 2, lrecl= 0;
5007+
int port= 0, hdr= 0, mxr= 0, mxe= 0, rc= 0;
5008+
int cop __attribute__((unused))= 0, lrecl= 0;
49745009
#if defined(ODBC_SUPPORT)
49755010
POPARM sop = NULL;
49765011
char *ucnc = NULL;
@@ -5000,7 +5035,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
50005035
if (!g)
50015036
return HA_ERR_INTERNAL_ERROR;
50025037

5003-
user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= dsn= objn= NULL;
5038+
user= host= pwd= tbl= src= col= ocl= pic= fcl= skc= rnk= dsn= NULL;
50045039

50055040
// Get the useful create options
50065041
ttp= GetTypeID(topt->type);
@@ -5031,7 +5066,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
50315066
skc= GetListOption(g, "skipcol", topt->oplist, NULL);
50325067
rnk= GetListOption(g, "rankcol", topt->oplist, NULL);
50335068
pwd= GetListOption(g, "password", topt->oplist);
5034-
objn= GetListOption(g, "Object", topt->oplist, NULL);
50355069
#if defined(WIN32)
50365070
nsp= GetListOption(g, "namespace", topt->oplist);
50375071
cls= GetListOption(g, "class", topt->oplist);
@@ -5049,8 +5083,6 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
50495083
#if defined(PROMPT_OK)
50505084
cop= atoi(GetListOption(g, "checkdsn", topt->oplist, "0"));
50515085
#endif // PROMPT_OK
5052-
pty= atoi(GetListOption(g,"Pretty", topt->oplist, "2"));
5053-
lvl= atoi(GetListOption(g,"Level", topt->oplist, "0"));
50545086
} else {
50555087
host= "localhost";
50565088
user= (ttp == TAB_ODBC ? NULL : "root");
@@ -5342,7 +5374,7 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
53425374
qrp= VirColumns(g, fnc == FNC_COL);
53435375
break;
53445376
case TAB_JSON:
5345-
qrp= JSONColumns(g, (char*)db, fn, objn, pty, lrecl, lvl, fnc == FNC_COL);
5377+
qrp= JSONColumns(g, (char*)db, topt, fnc == FNC_COL);
53465378
break;
53475379
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
53485380
case TAB_XML:
@@ -6608,7 +6640,7 @@ maria_declare_plugin(connect)
66086640
0x0103, /* version number (1.03) */
66096641
NULL, /* status variables */
66106642
connect_system_variables, /* system variables */
6611-
"1.03.0006", /* string version */
6643+
"1.03.0007", /* string version */
66126644
MariaDB_PLUGIN_MATURITY_BETA /* maturity */
66136645
}
66146646
maria_declare_plugin_end;

storage/connect/libdoc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn)
533533
// This function does not crash (
534534
if (xmlSaveFormatFileEnc((const char *)ofn, Docp, Encoding, 0) < 0) {
535535
xmlErrorPtr err = xmlGetLastError();
536-
537536
strcpy(g->Message, (err) ? err->message : "Error saving XML doc");
537+
xmlResetError(Xerr);
538538
rc = -1;
539539
} // endif Save
540540
// rc = xmlDocDump(of, Docp);
@@ -569,6 +569,7 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
569569
htrc("CloseDoc: xp=%p count=%d\n", xp, (xp) ? xp->Count : 0);
570570

571571
//if (xp && xp->Count == 1) {
572+
if (xp) {
572573
if (Nlist) {
573574
xmlXPathFreeNodeSet(Nlist);
574575

@@ -605,7 +606,7 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
605606
Ctxp = NULL;
606607
} // endif Ctxp
607608

608-
// } // endif Count
609+
} // endif xp
609610

610611
CloseXML2File(g, xp, false);
611612
} // end of Close

storage/connect/mycat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "block.h"
2525
#include "catalog.h"
2626

27-
typedef struct ha_table_option_struct TOS, *PTOS;
27+
//typedef struct ha_table_option_struct TOS, *PTOS;
2828

2929
/**
3030
structure for CREATE TABLE options (table options)

0 commit comments

Comments
 (0)