YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/*************** Mycat CC Program Source Code File (.CC) ***************/ /* PROGRAM NAME: MYCAT */ /* ------------- */ /* Version 1.8 */ /* */ /* Author: Olivier Bertrand 2012 - 2020 */ /* */ /* WHAT THIS PROGRAM DOES: */ /* ----------------------- */ /* This program are the DB description related routines. */ /***********************************************************************/
/***********************************************************************/ /* Get the plugin directory. */ /***********************************************************************/ char *GetPluginDir(void)
{ return opt_plugin_dir;
} // end of GetPluginDir
/***********************************************************************/ /* Get the lc_messages_dir, it is where error messages for various */ /* languages are installed, and by default the INSTALL_MYSQLSHAREDIR. */ /***********************************************************************/ char *GetMessageDir(void)
{ return lc_messages_dir;
} // end of GetMessageDir
/***********************************************************************/ /* Return true for table types based on file. */ /***********************************************************************/ bool IsFileType(TABTYPE type)
{ bool isfile;
switch (type) { case TAB_DOS: case TAB_FIX: case TAB_BIN: case TAB_CSV: case TAB_FMT: case TAB_DBF: case TAB_XML: case TAB_INI: case TAB_VEC: case TAB_JSON: #ifdefined(BSON_SUPPORT) case TAB_BSON: #endif// BSON_SUPPORT case TAB_REST: // case TAB_ZIP:
isfile= true; break; default:
isfile= false; break;
} // endswitch type
switch (type) { case TAB_FIX: case TAB_BIN: case TAB_DBF: // case TAB_XML: depends on Multiple || Xpand || Coltype // case TAB_JSON: depends on Multiple || Xpand || Coltype case TAB_VEC: case TAB_VIR:
exact= true; break; default:
exact= false; break;
} // endswitch type
switch (type) { case TAB_MAC: case TAB_DIR:
nullable= false; break; default:
nullable= true; break;
} // endswitch type
return nullable;
} // end of IsTypeNullable
/***********************************************************************/ /* Return true for fixed record length tables. */ /***********************************************************************/ bool IsTypeFixed(TABTYPE type)
{ bool fix;
switch (type) { case TAB_FIX: case TAB_BIN: case TAB_VEC: // case TAB_DBF: ???
fix= true; break; default:
fix= false; break;
} // endswitch type
return fix;
} // end of IsTypeFixed
/***********************************************************************/ /* Return true for table indexable by XINDEX. */ /***********************************************************************/ bool IsTypeIndexable(TABTYPE type)
{ bool idx;
switch (type) { case TAB_DOS: case TAB_CSV: case TAB_FMT: case TAB_FIX: case TAB_BIN: case TAB_VEC: case TAB_DBF: case TAB_JSON: #ifdefined(BSON_SUPPORT) case TAB_BSON: #endif// BSON_SUPPORT
idx= true; break; default:
idx= false; break;
} // endswitch type
return idx;
} // end of IsTypeIndexable
/***********************************************************************/ /* Return index type: 0 NO, 1 XINDEX, 2 REMOTE. */ /***********************************************************************/ int GetIndexType(TABTYPE type)
{ int xtyp;
switch (type) { case TAB_DOS: case TAB_CSV: case TAB_FMT: case TAB_FIX: case TAB_BIN: case TAB_VEC: case TAB_DBF: case TAB_JSON: #ifdefined(BSON_SUPPORT) case TAB_BSON: #endif// BSON_SUPPORT
xtyp= 1; break; case TAB_MYSQL: case TAB_ODBC: case TAB_JDBC: case TAB_MONGO:
xtyp= 2; break; case TAB_VIR:
xtyp= 3; break; default:
xtyp= 0; break;
} // endswitch type
return xtyp;
} // end of GetIndexType
/***********************************************************************/ /* Get a unique enum catalog function ID. */ /***********************************************************************/
uint GetFuncID(constchar *func)
{
uint fnc;
/***********************************************************************/ /* Nothing to do for CONNECT. */ /***********************************************************************/ void MYCAT::Reset(void)
{
} // end of Reset
/***********************************************************************/ /* GetTableDesc: retrieve a table descriptor. */ /* Look for a table descriptor matching the name and type. */ /***********************************************************************/
PTABDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
LPCSTR type, PRELDEF *)
{
PTABDEF tdp= NULL;
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","*");
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. */ /* Note: caller must check if name already exists before calling it. */ /***********************************************************************/
PTABDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
{
TABTYPE tc;
LPCSTR name= (PSZ)PlugDup(g, tablep->GetName());
LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema());
PTABDEF tdp= NULL;
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);
switch (tc) { case TAB_FIX: case TAB_BIN: case TAB_DBF: case TAB_DOS: tdp= new(g) DOSDEF; break; case TAB_CSV: case TAB_FMT: tdp= new(g) CSVDEF; break; case TAB_INI: tdp= new(g) INIDEF; break; case TAB_DIR: tdp= new(g) DIRDEF; break; #ifdefined(XML_SUPPORT) case TAB_XML: tdp= new(g) XMLDEF; break; #endif// XML_SUPPORT #ifdefined(VCT_SUPPORT) case TAB_VEC: tdp= new(g) VCTDEF; break; #endif// VCT_SUPPORT #ifdefined(ODBC_SUPPORT) case TAB_ODBC: tdp= new(g) ODBCDEF; break; #endif// ODBC_SUPPORT #ifdefined(JAVA_SUPPORT) case TAB_JDBC: tdp= new(g) JDBCDEF; break; #endif// JAVA_SUPPORT #ifdefined(_WIN32) case TAB_MAC: tdp= new(g) MACDEF; break; case TAB_WMI: tdp= new(g) WMIDEF; break; #endif// _WIN32 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_PIVOT: tdp= new(g) PIVOTDEF; break; case TAB_VIR: tdp= new(g) VIRDEF; break; case TAB_JSON: #ifdefined(BSON_SUPPORT) if (Force_Bson())
tdp= new(g) BSONDEF; else #endif// BSON_SUPPORT
tdp= new(g) JSONDEF;
break; #ifdefined(BSON_SUPPORT) case TAB_BSON: tdp= new(g) BSONDEF; break; #endif// BSON_SUPPORT #ifdefined(ZIP_SUPPORT) case TAB_ZIP: tdp= new(g) ZIPDEF; break; #endif// ZIP_SUPPORT #ifdefined(REST_SUPPORT) case TAB_REST: tdp= new (g) RESTDEF; break; #endif// REST_SUPPORT #ifdefined(JAVA_SUPPORT) || defined(CMGO_SUPPORT) case TAB_MONGO: if (MongoEnabled()) {
tdp = new(g) MGODEF; break;
} // endif enabled /* fall through */ #endif// JAVA_SUPPORT || CMGO_SUPPORT default:
snprintf(g->Message, sizeof(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;