Commit 88c76f3b authored by Olivier Bertrand's avatar Olivier Bertrand

All use of a character to represent table types or

catalog functions have been changed:

Table_types are now internally represented be enum TABTYPE.
Catalog function names are internally translated to a uint.

The function GetTypeID was modified accordingly and a new
function GetFuncID was implemented in mycat.cc.

Modified:
ha_connect.cc
odbccat.h
odbconn.cpp
tabodbc.cpp
tabfmt.cpp
tabmysql.h
tabmysql.cpp
tabwmi.cpp
mycat.h
mycat.cc
plgdbsem.h
reldef.h
tabdos.cpp
rcmsg.h
parent b91386c2
......@@ -3256,17 +3256,18 @@ bool ha_connect::add_fields(THD *thd, void *alt_info,
*/
bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
{
char ttp= '?', spc= ',', qch= 0, fnc= '*';
char spc= ',', qch= 0;
const char *typn= "?";
const char *fncn= "?";
const char *user;
char *fn, *dsn, *tab, *db, *host, *pwd, *prt, *sep, *csn;
char *fn, *dsn, *tab, *db, *host, *pwd, *prt, *sep; // *csn;
#if defined(WIN32)
char *nsp= NULL, *cls= NULL;
#endif // WIN32
char *supfnc = "*C";
int port= MYSQL_PORT, hdr= 0, mxr= 0;
uint tm;
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool b= false, ok= false, dbf= false;
TABTYPE ttp= TAB_UNDEF;
LEX_STRING *comment, *name;
HA_CREATE_INFO *create_info= (HA_CREATE_INFO *)crt_info;
CHARSET_INFO *cs;
......@@ -3294,7 +3295,8 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
} else if (!stricmp(pov->name.str, "db_name")) {
db= pov->value.str;
} else if (!stricmp(pov->name.str, "catfunc")) {
fnc= toupper(*pov->value.str);
fncn= pov->value.str;
fnc= GetFuncID(fncn);
} else if (!stricmp(pov->name.str, "sep_char")) {
sep= pov->value.str;
spc= (!strcmp(sep, "\\t")) ? '\t' : *sep;
......@@ -3319,25 +3321,25 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
mxr= atoi(GetListOption("maxerr", pov->value.str, "0"));
} // endelse option_list
if (!tab && fnc != 'T')
if (!tab && !(fnc & (FNC_TABLE | FNC_COL)))
tab= (char*)create_info->alias;
switch (ttp) {
#if defined(ODBC_SUPPORT)
case 'O': // ODBC
case TAB_ODBC:
if (!(dsn= create_info->connect_string.str)
&& fnc != 'S'&& fnc != 'D')
&& !(fnc & (FNC_DSN | FNC_DRIVER)))
sprintf(g->Message, "Missing %s connection string", typn);
else
ok= true;
supfnc = "*CTSD";
supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER);
break;
#endif // ODBC_SUPPORT
case 'A': // DBF
case TAB_DBF:
dbf= true;
// Passthru
case 'C': // CSV
case TAB_CSV:
if (!fn)
sprintf(g->Message, "Missing %s file name", typn);
else
......@@ -3345,7 +3347,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
break;
#if defined(MYSQL_SUPPORT)
case 'Y': // MYSQL
case TAB_MYSQL:
if (!user)
user= "root"; // Avoid crash
......@@ -3353,7 +3355,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
break;
#endif // MYSQL_SUPPORT
#if defined(WIN32)
case 'W': // WMI
case TAB_WMI:
ok= true;
break;
#endif // WIN32
......@@ -3362,9 +3364,9 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
} // endif ttp
// Check for supported catalog function
if (ok && !strchr(supfnc, fnc)) {
sprintf(g->Message, "Unsupported catalog function %c for table type %s",
fnc, typn);
if (ok && !(supfnc & fnc)) {
sprintf(g->Message, "Unsupported catalog function %s for table type %s",
fncn, typn);
ok= false;
} // endif supfnc
......@@ -3381,45 +3383,48 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
return true; // Should never happen
switch (ttp) {
case 'A':
qrp= DBFColumns(g, fn, fnc == 'C');
case TAB_DBF:
qrp= DBFColumns(g, fn, fnc == FNC_COL);
break;
#if defined(ODBC_SUPPORT)
case 'O':
case TAB_ODBC:
switch (fnc) {
case 'C':
case '\0':
qrp= MyODBCCols(g, dsn, tab, fnc == 'C');
case FNC_NO:
case FNC_COL:
qrp= ODBCColumns(g, dsn, tab, NULL, fnc == FNC_COL);
break;
case 'T':
case FNC_TABLE:
qrp= ODBCTables(g, dsn, tab, true);
break;
case 'S':
case FNC_DSN:
qrp= ODBCDataSources(g, true);
break;
case 'D':
case FNC_DRIVER:
qrp= ODBCDrivers(g, true);
break;
default:
sprintf(g->Message, "invalid catfunc %c", fnc);
sprintf(g->Message, "invalid catfunc %c", fncn);
} // endswitch info
break;
#endif // ODBC_SUPPORT
#if defined(MYSQL_SUPPORT)
case 'Y':
case TAB_MYSQL:
qrp= MyColumns(g, host, db, user, pwd, tab,
NULL, port, false, fnc == 'C');
NULL, port, false, fnc == FNC_COL);
break;
#endif // MYSQL_SUPPORT
case 'C':
qrp= CSVColumns(g, fn, spc, qch, hdr, mxr, fnc == 'C');
case TAB_CSV:
qrp= CSVColumns(g, fn, spc, qch, hdr, mxr, fnc == FNC_COL);
break;
#if defined(WIN32)
case 'W':
qrp= WMIColumns(g, nsp, cls, fnc == 'C');
case TAB_WMI:
qrp= WMIColumns(g, nsp, cls, fnc == FNC_COL);
break;
#endif // WIN32
default:
strcpy(g->Message, "System error in pre_create");
break;
} // endswitch ttp
if (!qrp) {
......@@ -3427,7 +3432,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
return true;
} // endif qrp
if (fnc && fnc != '*') {
if (fnc != FNC_NO) {
// Catalog table
for (crp=qrp->Colresp; !b && crp; crp= crp->Next) {
cnm= encode(g, crp->Name);
......@@ -3488,6 +3493,8 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
// cs= get_charset_by_name(csn, 0);
// break;
default:
break; // Ignore
} // endswitch Fld
comment= thd->make_lex_string(NULL, rem, strlen(rem), true);
......
This diff is collapsed.
/* Copyright (C) Olivier Bertrand 2004 - 2011
/* Copyright (C) Olivier Bertrand 2004 - 2013
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -24,7 +24,18 @@
#include "block.h"
#include "catalog.h"
char GetTypeID(const char *type);
// Possible value for catalog functions
#define FNC_NO (1 << 0) // Not a catalog table
#define FNC_COL (1 << 1) // Column catalog function
#define FNC_TABLE (1 << 2) // Table catalog function
#define FNC_DSN (1 << 3) // Data Source catalog function
#define FNC_DRIVER (1 << 4) // Column catalog function
#define FNC_NIY (1 << 5) // Catalog function NIY
typedef class ha_connect *PHC;
TABTYPE GetTypeID(const char *type);
uint GetFuncID(const char *func);
/***********************************************************************/
/* MYCAT: class for managing the CONNECT plugin DB items. */
......
......@@ -2,6 +2,7 @@
/* ODBC catalog function prototypes. */
/***********************************************************************/
PQRYRES ODBCDataSources(PGLOBAL g, bool info);
PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info);
PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table,
char *colpat, bool info);
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info);
PQRYRES ODBCDrivers(PGLOBAL g, bool info);
This diff is collapsed.
......@@ -52,6 +52,30 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Correl Block */
TYPE_FB_XML = 21, /* DOM XML file block */
TYPE_FB_XML2 = 27}; /* libxml2 XML file block */
enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_DOS = 1, /* Fixed column offset, variable LRECL */
TAB_FIX = 2, /* Fixed column offset, fixed LRECL */
TAB_BIN = 3, /* Like FIX but can have binary fields */
TAB_CSV = 4, /* DOS files with CSV records */
TAB_FMT = 5, /* DOS files with formatted recordss */
TAB_DBF = 6, /* DBF Dbase or Foxpro files */
TAB_XML = 7, /* XML or HTML files */
TAB_INI = 8, /* INI or CFG files */
TAB_VEC = 9, /* Vector column arrangement */
TAB_ODBC = 10, /* Table accessed via (unix)ODBC */
TAB_MYSQL = 11, /* MySQL table accessed via MySQL API */
TAB_DIR = 12, /* Returns a list of files */
TAB_MAC = 13, /* MAC address (Windows only) */
TAB_WMI = 14, /* WMI tables (Windows only) */
TAB_TBL = 15, /* Collection of CONNECT tables */
TAB_OEM = 16, /* OEM implemented table */
TAB_CATLG = 16, /* Catalog table */
TAB_PLG = 17, /* PLG NIY */
TAB_PIVOT = 18, /* PIVOT NIY */
TAB_JCT = 19, /* Junction tables NIY */
TAB_DMY = 20, /* DMY Dummy tables NIY */
TAB_NIY = 21}; /* Table not implemented yet */
enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */
TYPE_AM_FILID = 2, /* FILEID type (special column) */
......
......@@ -129,10 +129,10 @@ char *GetMsgid(int id)
case IDS_13: p = "%s: invalid connection key value %d"; break;
case IDS_14: p = "SafeDB: %s rc=%d"; break;
case IDS_15: p = "Wrong communication Dll called for engine %s"; break;
case IDS_TAB_01: p = "Qualifier"; break;
case IDS_TAB_02: p = "Owner"; break;
case IDS_TAB_03: p = "Name"; break;
case IDS_TAB_04: p = "Type"; break;
case IDS_TAB_01: p = "Table_Qualifier"; break;
case IDS_TAB_02: p = "Table_Owner"; break;
case IDS_TAB_03: p = "Table_Name"; break;
case IDS_TAB_04: p = "Table_Type"; break;
case IDS_TAB_05: p = "Remark"; break;
case IDS_COL_01: p = "Table_Qualif"; break;
case IDS_COL_02: p = "Table_Owner"; break;
......
......@@ -34,6 +34,7 @@
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "mycat.h"
#include "reldef.h"
#include "colblk.h"
#include "filamap.h"
......@@ -74,7 +75,7 @@ TABDEF::TABDEF(void)
{
Owner = NULL;
Desc = NULL;
Catfunc = 0;
Catfunc = FNC_NO;
Card = 0;
Elemt = 0;
Sort = 0;
......@@ -96,7 +97,7 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am)
Name = (PSZ)PlugSubAlloc(g, memp, strlen(name) + 1);
strcpy(Name, name);
Cat = cat;
Catfunc = toupper(*Cat->GetStringCatInfo(g, Name, "Catfunc", ""));
Catfunc = GetFuncID(Cat->GetStringCatInfo(g, Name, "Catfunc", NULL));
Elemt = cat->GetIntCatInfo(name, "Elements", 0);
Multiple = cat->GetIntCatInfo(name, "Multiple", 0);
Degree = cat->GetIntCatInfo(name, "Degree", 0);
......
......@@ -85,7 +85,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
// Members
PSZ Owner; /* Table owner (for ODBC) */
PSZ Desc; /* Table description */
char Catfunc; /* Catalog function */
uint Catfunc; /* Catalog function ID */
int Card; /* (max) number of rows in table */
int Elemt; /* Number of rows in blocks or rowset */
int Sort; /* Table already sorted ??? */
......
......@@ -46,7 +46,7 @@
#include "osutil.h"
#include "plgdbsem.h"
#include "catalog.h"
//#include "reldef.h"
#include "mycat.h"
#include "xindex.h"
#include "filamap.h"
#include "filamfix.h"
......@@ -297,7 +297,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
/* Column blocks will be allocated only when needed. */
/*********************************************************************/
if (Recfm == RECFM_DBF) {
if (!Catfunc) {
if (Catfunc == FNC_NO) {
if (map)
txfp = new(g) DBMFAM(this);
else
......
......@@ -49,6 +49,7 @@
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "mycat.h"
#include "filamap.h"
#if defined(ZIP_SUPPORT)
#include "filamzip.h"
......@@ -405,7 +406,7 @@ bool CSVDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
char buf[8];
// Double check correctness of offset values
if (!Catfunc)
if (Catfunc == FNC_NO)
for (PCOLDEF cdp = To_Cols; cdp; cdp = cdp->GetNext())
if (cdp->GetOffset() < 1) {
strcpy(g->Message, MSG(BAD_OFFSET_VAL));
......@@ -441,7 +442,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
{
PTDBASE tdbp;
if (Catfunc != 'C') {
if (Catfunc != FNC_COL) {
USETEMP tmp = PlgGetUser(g)->UseTemp;
bool map = Mapped && mode != MODE_INSERT &&
!(tmp != TMP_NO && mode == MODE_UPDATE) &&
......
......@@ -53,7 +53,7 @@
#include "xtable.h"
#include "tabcol.h"
#include "colblk.h"
//#include "xindex.h"
#include "mycat.h"
#include "reldef.h"
#include "tabmysql.h"
#include "valblk.h"
......@@ -105,7 +105,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
PTDB MYSQLDEF::GetTable(PGLOBAL g, MODE m)
{
if (Catfunc == 'C')
if (Catfunc == FNC_COL)
return new(g) TDBMCL(this);
else
return new(g) TDBMYSQL(this);
......
......@@ -64,6 +64,7 @@
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "mycat.h"
#include "xtable.h"
#include "tabodbc.h"
#include "odbccat.h"
......@@ -102,7 +103,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Desc = Connect = Cat->GetStringCatInfo(g, Name, "Connect", "");
Tabname = Cat->GetStringCatInfo(g, Name, "Name",
Catfunc == 'T' ? NULL : Name);
(Catfunc & (FNC_TABLE || FNC_COL)) ? NULL : Name);
Tabname = Cat->GetStringCatInfo(g, Name, "Tabname", Tabname);
Tabowner = Cat->GetStringCatInfo(g, Name, "Owner", "");
Tabqual = Cat->GetStringCatInfo(g, Name, "Qualifier", "");
......@@ -125,16 +126,16 @@ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m)
/* Column blocks will be allocated only when needed. */
/*********************************************************************/
switch (Catfunc) {
case 'C':
case FNC_COL:
tdbp = new(g) TDBOCL(this);
break;
case 'T':
case FNC_TABLE:
tdbp = new(g) TDBOTB(this);
break;
case 'S':
case FNC_DSN:
tdbp = new(g) TDBSRC(this);
break;
case 'D':
case FNC_DRIVER:
tdbp = new(g) TDBDRV(this);
break;
default:
......@@ -950,7 +951,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g)
/***********************************************************************/
PQRYRES TDBOCL::GetResult(PGLOBAL g)
{
return MyODBCCols(g, Dsn, Tab, false);
return ODBCColumns(g, Dsn, Tab, NULL, false);
} // end of GetResult
/* ------------------------ End of Tabodbc --------------------------- */
......@@ -10,7 +10,7 @@
#include "global.h"
#include "plgdbsem.h"
//#include "catalog.h"
#include "mycat.h"
#include "reldef.h"
#include "xtable.h"
#include "colblk.h"
......@@ -344,7 +344,7 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Wclass = strcat(strcpy(p, "Win32_"), Wclass);
} // endif Wclass
if (!Catfunc)
if (Catfunc == FNC_NO)
Ems = Cat->GetIntCatInfo(Name, "Estimate", 100);
return false;
......@@ -355,12 +355,12 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/
PTDB WMIDEF::GetTable(PGLOBAL g, MODE m)
{
if (!Catfunc)
if (Catfunc == FNC_NO)
return new(g) TDBWMI(this);
else if (Catfunc == 'C')
else if (Catfunc == FNC_COL)
return new(g) TDBWCL(this);
sprintf(g->Message, "Bad catfunc %c for WMI", Catfunc);
sprintf(g->Message, "Bad catfunc %ud for WMI", Catfunc);
return NULL;
} // end of GetTable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment