summaryrefslogtreecommitdiff
path: root/storage/connect/reldef.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2014-04-19 16:41:25 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2014-04-19 16:41:25 +0200
commit50953a0e9de6ae36a62fc195f3fc97d6d319493e (patch)
tree33689c716390d4e5f3abf302937322baaae3cf04 /storage/connect/reldef.cpp
parent812520315318e358d2d9daf9ca709578af1efe40 (diff)
parent213ecbbb4f3d252ba2d653eacf756e123821c41a (diff)
downloadmariadb-git-50953a0e9de6ae36a62fc195f3fc97d6d319493e.tar.gz
- Commit merge files
modified: storage/connect/catalog.h storage/connect/filamvct.cpp storage/connect/filamzip.cpp storage/connect/ha_connect.cc storage/connect/ha_connect.h storage/connect/mycat.cc storage/connect/mycat.h storage/connect/myconn.cpp storage/connect/mysql-test/connect/r/xml.result storage/connect/plgdbutl.cpp storage/connect/reldef.cpp storage/connect/reldef.h storage/connect/tabdos.cpp storage/connect/tabfmt.cpp storage/connect/tabmul.cpp storage/connect/tabmysql.cpp storage/connect/taboccur.cpp storage/connect/tabodbc.cpp storage/connect/tabpivot.cpp storage/connect/tabpivot.h storage/connect/tabsys.cpp storage/connect/tabtbl.cpp storage/connect/tabutil.cpp storage/connect/tabvct.cpp storage/connect/tabwmi.cpp storage/connect/tabxcl.cpp storage/connect/tabxml.cpp storage/connect/xindex.cpp
Diffstat (limited to 'storage/connect/reldef.cpp')
-rw-r--r--storage/connect/reldef.cpp297
1 files changed, 287 insertions, 10 deletions
diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp
index 63cb2034e53..ae528db470f 100644
--- a/storage/connect/reldef.cpp
+++ b/storage/connect/reldef.cpp
@@ -24,6 +24,7 @@
#include "osutil.h"
//#include "sqlext.h"
#endif
+#include "handler.h"
/***********************************************************************/
/* Include application header files */
@@ -46,6 +47,7 @@
#include "tabdos.h"
#include "valblk.h"
#include "tabmul.h"
+#include "ha_connect.h"
/* --------------------------- Class RELDEF -------------------------- */
@@ -60,8 +62,106 @@ RELDEF::RELDEF(void)
Name = NULL;
Database = NULL;
Cat = NULL;
+ Hc = NULL;
} // end of RELDEF constructor
+/***********************************************************************/
+/* This function sets an integer table information. */
+/***********************************************************************/
+bool RELDEF::SetIntCatInfo(PSZ what, int n)
+ {
+ return Hc->SetIntegerOption(what, n);
+ } // end of SetIntCatInfo
+
+/***********************************************************************/
+/* This function returns integer table information. */
+/***********************************************************************/
+int RELDEF::GetIntCatInfo(PSZ what, int idef)
+ {
+ int n= Hc->GetIntegerOption(what);
+
+ return (n == NO_IVAL) ? idef : n;
+ } // end of GetIntCatInfo
+
+/***********************************************************************/
+/* This function returns Boolean table information. */
+/***********************************************************************/
+bool RELDEF::GetBoolCatInfo(PSZ what, bool bdef)
+ {
+ bool b= Hc->GetBooleanOption(what, bdef);
+
+ return b;
+ } // end of GetBoolCatInfo
+
+/***********************************************************************/
+/* This function returns size catalog information. */
+/***********************************************************************/
+int RELDEF::GetSizeCatInfo(PSZ what, PSZ sdef)
+ {
+ char * s, c;
+ int i, n= 0;
+
+ if (!(s= Hc->GetStringOption(what)))
+ s= sdef;
+
+ if ((i= sscanf(s, " %d %c ", &n, &c)) == 2)
+ switch (toupper(c)) {
+ case 'M':
+ n *= 1024;
+ case 'K':
+ n *= 1024;
+ } // endswitch c
+
+ return n;
+} // end of GetSizeCatInfo
+
+/***********************************************************************/
+/* This function sets char table information in buf. */
+/***********************************************************************/
+int RELDEF::GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size)
+ {
+ char *s= Hc->GetStringOption(what);
+
+ strncpy(buf, ((s) ? s : sdef), size);
+ return size;
+ } // end of GetCharCatInfo
+
+/***********************************************************************/
+/* This function returns string table information. */
+/* Default parameter is "*" to get the handler default. */
+/***********************************************************************/
+char *RELDEF::GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef)
+ {
+ char *sval= NULL, *s= Hc->GetStringOption(what, sdef);
+
+ if (s) {
+ sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
+ strcpy(sval, s);
+ } else if (!stricmp(what, "filename")) {
+ // Return default file name
+ char *ftype= Hc->GetStringOption("Type", "*");
+ int i, n;
+
+ if (IsFileType(GetTypeID(ftype))) {
+ sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 12);
+ strcat(strcpy(sval, Hc->GetTableName()), ".");
+ n= strlen(sval);
+
+ // Fold ftype to lower case
+ for (i= 0; i < 12; i++)
+ if (!ftype[i]) {
+ sval[n+i]= 0;
+ break;
+ } else
+ sval[n+i]= tolower(ftype[i]);
+
+ } // endif FileType
+
+ } // endif s
+
+ return sval;
+ } // end of GetStringCatInfo
+
/* --------------------------- Class TABDEF -------------------------- */
/***********************************************************************/
@@ -91,24 +191,201 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am)
Name = (PSZ)PlugSubAlloc(g, NULL, strlen(name) + 1);
strcpy(Name, name);
Cat = cat;
- Catfunc = GetFuncID(Cat->GetStringCatInfo(g, "Catfunc", NULL));
- Elemt = cat->GetIntCatInfo("Elements", 0);
- Multiple = cat->GetIntCatInfo("Multiple", 0);
- Degree = cat->GetIntCatInfo("Degree", 0);
- Read_Only = cat->GetBoolCatInfo("ReadOnly", false);
- const char *data_charset_name= cat->GetStringCatInfo(g, "Data_charset", NULL);
+ Hc = ((MYCAT*)cat)->GetHandler();
+ Catfunc = GetFuncID(GetStringCatInfo(g, "Catfunc", NULL));
+ Elemt = GetIntCatInfo("Elements", 0);
+ Multiple = GetIntCatInfo("Multiple", 0);
+ Degree = GetIntCatInfo("Degree", 0);
+ Read_Only = GetBoolCatInfo("ReadOnly", false);
+ const char *data_charset_name= GetStringCatInfo(g, "Data_charset", NULL);
m_data_charset= data_charset_name ?
get_charset_by_csname(data_charset_name, MY_CS_PRIMARY, 0):
NULL;
// Get The column definitions
- if ((poff = cat->GetColCatInfo(g, this)) < 0)
+ if ((poff = GetColCatInfo(g)) < 0)
return true;
// Do the definition of AM specific fields
return DefineAM(g, am, poff);
} // end of Define
+/***********************************************************************/
+/* This function returns column table information. */
+/***********************************************************************/
+int TABDEF::GetColCatInfo(PGLOBAL g)
+ {
+ char *type= GetStringCatInfo(g, "Type", "*");
+ int i, loff, poff, nof, nlg;
+ void *field= NULL;
+ TABTYPE tc;
+ PCOLDEF cdp, lcdp= NULL, tocols= NULL;
+ PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));
+
+ memset(pcf, 0, sizeof(COLINFO));
+
+ // Get a unique char identifier for type
+ tc= (Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX;
+
+ // Take care of the column definitions
+ i= poff= nof= nlg= 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;
+
+ while (true) {
+ // 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= max(nlg, poff); // Default lrecl
+ break;
+ case TAB_CSV:
+ case TAB_FMT:
+ nlg+= nof;
+ case TAB_DIR:
+ case TAB_XML:
+ poff= loff + 1;
+ break;
+ case TAB_INI:
+ case TAB_MAC:
+ case TAB_TBL:
+ case TAB_XCL:
+ case TAB_OCCUR:
+ case TAB_PRX:
+ case TAB_OEM:
+ poff = 0; // Offset represents an independant flag
+ break;
+ default: // VCT PLG ODBC MYSQL WMI...
+ poff = 0; // NA
+ break;
+ } // endswitch tc
+
+// 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 (!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 if (nof)
+ 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
+ switch (cdp->Fmt ? *cdp->Fmt : 'X') {
+ case 'C': break;
+ case 'R':
+ case 'F':
+ case 'L':
+ case 'I': nof= 4; break;
+ case 'D': nof= 8; break;
+ case 'S': nof= 2; break;
+ case 'T': nof= 1; break;
+ default: nof= cdp->Clen;
+ } // endswitch Fmt
+
+ default:
+ break;
+ } // endswitch tc
+
+ if (lcdp)
+ lcdp->SetNext(cdp);
+ else
+ tocols= cdp;
+
+ lcdp= cdp;
+ i++;
+ } // endwhile
+
+ // Degree is the the number of defined columns (informational)
+ if (i != GetDegree())
+ SetDegree(i);
+
+ 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) {
+#if defined(WIN32)
+ ending= 2;
+#else
+ ending= 1;
+#endif
+ Hc->SetIntegerOption("Ending", ending);
+ } // endif ending
+
+ // Calculate the default record size
+ switch (tc) {
+ case TAB_FIX:
+ recln= nlg + ending; // + length of line ending
+ break;
+ case TAB_BIN:
+ 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:
+ recln= nlg;
+ break;
+ 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
+ default:
+ break;
+ } // endswitch tc
+
+ // lrecl must be at least recln to avoid buffer overflow
+ recln= max(recln, Hc->GetIntegerOption("Lrecl"));
+ Hc->SetIntegerOption("Lrecl", recln);
+ ((PDOSDEF)this)->SetLrecl(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. */
+/***********************************************************************/
+void TABDEF::SetIndexInfo(void)
+ {
+ // Attach new index(es)
+ SetIndx(Hc->GetIndexInfo());
+ } // end of SetIndexInfo
+
/* --------------------------- Class OEMDEF -------------------------- */
/***********************************************************************/
@@ -188,7 +465,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
// Have the external class do its complete definition
if (!cat->Cbuf) {
// Suballocate a temporary buffer for the entire column section
- cat->Cblen = cat->GetSizeCatInfo("Colsize", "8K");
+ cat->Cblen = GetSizeCatInfo("Colsize", "8K");
cat->Cbuf = (char*)PlugSubAlloc(g, NULL, cat->Cblen);
} // endif Cbuf
@@ -218,8 +495,8 @@ bool OEMDEF::DeleteTableFile(PGLOBAL g)
/***********************************************************************/
bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
- Module = Cat->GetStringCatInfo(g, "Module", "");
- Subtype = Cat->GetStringCatInfo(g, "Subtype", Module);
+ Module = GetStringCatInfo(g, "Module", "");
+ Subtype = GetStringCatInfo(g, "Subtype", Module);
if (!*Module)
Module = Subtype;