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,24 +3256,25 @@ bool ha_connect::add_fields(THD *thd, void *alt_info, ...@@ -3256,24 +3256,25 @@ bool ha_connect::add_fields(THD *thd, void *alt_info,
*/ */
bool ha_connect::pre_create(THD *thd, void *crt_info, 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 *typn= "?";
const char *fncn= "?";
const char *user; 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) #if defined(WIN32)
char *nsp= NULL, *cls= NULL; char *nsp= NULL, *cls= NULL;
#endif // WIN32 #endif // WIN32
char *supfnc = "*C"; int port= MYSQL_PORT, hdr= 0, mxr= 0;
int port= MYSQL_PORT, hdr= 0, mxr= 0; uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
uint tm; bool b= false, ok= false, dbf= false;
bool b= false, ok= false, dbf= false; TABTYPE ttp= TAB_UNDEF;
LEX_STRING *comment, *name; LEX_STRING *comment, *name;
HA_CREATE_INFO *create_info= (HA_CREATE_INFO *)crt_info; HA_CREATE_INFO *create_info= (HA_CREATE_INFO *)crt_info;
CHARSET_INFO *cs; CHARSET_INFO *cs;
engine_option_value *pov; engine_option_value *pov;
PQRYRES qrp; PQRYRES qrp;
PCOLRES crp; PCOLRES crp;
PGLOBAL g= GetPlug(thd); PGLOBAL g= GetPlug(thd);
if (!g) if (!g)
return true; return true;
...@@ -3294,7 +3295,8 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -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")) { } else if (!stricmp(pov->name.str, "db_name")) {
db= pov->value.str; db= pov->value.str;
} else if (!stricmp(pov->name.str, "catfunc")) { } 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")) { } else if (!stricmp(pov->name.str, "sep_char")) {
sep= pov->value.str; sep= pov->value.str;
spc= (!strcmp(sep, "\\t")) ? '\t' : *sep; spc= (!strcmp(sep, "\\t")) ? '\t' : *sep;
...@@ -3319,25 +3321,25 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -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")); mxr= atoi(GetListOption("maxerr", pov->value.str, "0"));
} // endelse option_list } // endelse option_list
if (!tab && fnc != 'T') if (!tab && !(fnc & (FNC_TABLE | FNC_COL)))
tab= (char*)create_info->alias; tab= (char*)create_info->alias;
switch (ttp) { switch (ttp) {
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
case 'O': // ODBC case TAB_ODBC:
if (!(dsn= create_info->connect_string.str) if (!(dsn= create_info->connect_string.str)
&& fnc != 'S'&& fnc != 'D') && !(fnc & (FNC_DSN | FNC_DRIVER)))
sprintf(g->Message, "Missing %s connection string", typn); sprintf(g->Message, "Missing %s connection string", typn);
else else
ok= true; ok= true;
supfnc = "*CTSD"; supfnc |= (FNC_TABLE | FNC_DSN | FNC_DRIVER);
break; break;
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
case 'A': // DBF case TAB_DBF:
dbf= true; dbf= true;
// Passthru // Passthru
case 'C': // CSV case TAB_CSV:
if (!fn) if (!fn)
sprintf(g->Message, "Missing %s file name", typn); sprintf(g->Message, "Missing %s file name", typn);
else else
...@@ -3345,7 +3347,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3345,7 +3347,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
break; break;
#if defined(MYSQL_SUPPORT) #if defined(MYSQL_SUPPORT)
case 'Y': // MYSQL case TAB_MYSQL:
if (!user) if (!user)
user= "root"; // Avoid crash user= "root"; // Avoid crash
...@@ -3353,7 +3355,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3353,7 +3355,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
break; break;
#endif // MYSQL_SUPPORT #endif // MYSQL_SUPPORT
#if defined(WIN32) #if defined(WIN32)
case 'W': // WMI case TAB_WMI:
ok= true; ok= true;
break; break;
#endif // WIN32 #endif // WIN32
...@@ -3362,9 +3364,9 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3362,9 +3364,9 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
} // endif ttp } // endif ttp
// Check for supported catalog function // Check for supported catalog function
if (ok && !strchr(supfnc, fnc)) { if (ok && !(supfnc & fnc)) {
sprintf(g->Message, "Unsupported catalog function %c for table type %s", sprintf(g->Message, "Unsupported catalog function %s for table type %s",
fnc, typn); fncn, typn);
ok= false; ok= false;
} // endif supfnc } // endif supfnc
...@@ -3381,45 +3383,48 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3381,45 +3383,48 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
return true; // Should never happen return true; // Should never happen
switch (ttp) { switch (ttp) {
case 'A': case TAB_DBF:
qrp= DBFColumns(g, fn, fnc == 'C'); qrp= DBFColumns(g, fn, fnc == FNC_COL);
break; break;
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
case 'O': case TAB_ODBC:
switch (fnc) { switch (fnc) {
case 'C': case FNC_NO:
case '\0': case FNC_COL:
qrp= MyODBCCols(g, dsn, tab, fnc == 'C'); qrp= ODBCColumns(g, dsn, tab, NULL, fnc == FNC_COL);
break; break;
case 'T': case FNC_TABLE:
qrp= ODBCTables(g, dsn, tab, true); qrp= ODBCTables(g, dsn, tab, true);
break; break;
case 'S': case FNC_DSN:
qrp= ODBCDataSources(g, true); qrp= ODBCDataSources(g, true);
break; break;
case 'D': case FNC_DRIVER:
qrp= ODBCDrivers(g, true); qrp= ODBCDrivers(g, true);
break; break;
default: default:
sprintf(g->Message, "invalid catfunc %c", fnc); sprintf(g->Message, "invalid catfunc %c", fncn);
} // endswitch info } // endswitch info
break; break;
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
#if defined(MYSQL_SUPPORT) #if defined(MYSQL_SUPPORT)
case 'Y': case TAB_MYSQL:
qrp= MyColumns(g, host, db, user, pwd, tab, qrp= MyColumns(g, host, db, user, pwd, tab,
NULL, port, false, fnc == 'C'); NULL, port, false, fnc == FNC_COL);
break; break;
#endif // MYSQL_SUPPORT #endif // MYSQL_SUPPORT
case 'C': case TAB_CSV:
qrp= CSVColumns(g, fn, spc, qch, hdr, mxr, fnc == 'C'); qrp= CSVColumns(g, fn, spc, qch, hdr, mxr, fnc == FNC_COL);
break; break;
#if defined(WIN32) #if defined(WIN32)
case 'W': case TAB_WMI:
qrp= WMIColumns(g, nsp, cls, fnc == 'C'); qrp= WMIColumns(g, nsp, cls, fnc == FNC_COL);
break; break;
#endif // WIN32 #endif // WIN32
default:
strcpy(g->Message, "System error in pre_create");
break;
} // endswitch ttp } // endswitch ttp
if (!qrp) { if (!qrp) {
...@@ -3427,7 +3432,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3427,7 +3432,7 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
return true; return true;
} // endif qrp } // endif qrp
if (fnc && fnc != '*') { if (fnc != FNC_NO) {
// Catalog table // Catalog table
for (crp=qrp->Colresp; !b && crp; crp= crp->Next) { for (crp=qrp->Colresp; !b && crp; crp= crp->Next) {
cnm= encode(g, crp->Name); cnm= encode(g, crp->Name);
...@@ -3488,6 +3493,8 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info) ...@@ -3488,6 +3493,8 @@ bool ha_connect::pre_create(THD *thd, void *crt_info, void *alt_info)
// cs= get_charset_by_name(csn, 0); // cs= get_charset_by_name(csn, 0);
// break; // break;
default:
break; // Ignore
} // endswitch Fld } // endswitch Fld
comment= thd->make_lex_string(NULL, rem, strlen(rem), true); comment= thd->make_lex_string(NULL, rem, strlen(rem), true);
......
/* Copyright (C) Olivier Bertrand 2004 - 2012 /* Copyright (C) Olivier Bertrand 2004 - 2013
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/*************** Mycat CC Program Source Code File (.CC) ***************/ /*************** Mycat CC Program Source Code File (.CC) ***************/
/* PROGRAM NAME: MYCAT */ /* PROGRAM NAME: MYCAT */
/* ------------- */ /* ------------- */
/* Version 1.3 */ /* Version 1.4 */
/* */ /* */
/* Author: Olivier Bertrand 2012 - 2013 */ /* Author: Olivier Bertrand 2012 - 2013 */
/* */ /* */
...@@ -86,39 +86,66 @@ ...@@ -86,39 +86,66 @@
#include "ha_connect.h" #include "ha_connect.h"
#include "mycat.h" #include "mycat.h"
/**************************************************************************/ /***********************************************************************/
/* Extern static variables. */ /* Extern static variables. */
/**************************************************************************/ /***********************************************************************/
#if defined(WIN32) #if defined(WIN32)
extern "C" HINSTANCE s_hModule; // Saved module handle extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // !WIN32 #endif // !WIN32
extern int xtrace; extern int xtrace;
/**************************************************************************/
/* General DB routines. */
/**************************************************************************/
//bool PlugCheckPattern(PGLOBAL, LPCSTR, LPCSTR);
//#if !defined(WIN32)
//#endif // !WIN32
//void ptrc(char const *fmt, ...);
/***********************************************************************/ /***********************************************************************/
/* Get a unique char identifier for types. The letter used are: */ /* Get a unique enum table type ID. */
/* ABCDEF..I.KLM.O..R.T.VWXY.. */
/***********************************************************************/ /***********************************************************************/
char GetTypeID(const char *type) TABTYPE GetTypeID(const char *type)
{ {
return (!type) ? 'D' // DOS (default) return (!type) ? TAB_UNDEF
: (!stricmp(type, "FMT")) ? 'T' // CSV : (!stricmp(type, "DOS")) ? TAB_DOS
: (!stricmp(type, "DIR")) ? 'R' // diR : (!stricmp(type, "FIX")) ? TAB_FIX
: (!stricmp(type, "DBF")) ? 'A' // dbAse : (!stricmp(type, "BIN")) ? TAB_BIN
: (!stricmp(type, "SYS")) ? 'I' // INI : (!stricmp(type, "CSV")) ? TAB_CSV
: (!stricmp(type, "TBL")) ? 'L' // tbL : (!stricmp(type, "FMT")) ? TAB_FMT
: (!stricmp(type, "MYSQL")) ? 'Y' // mYsql : (!stricmp(type, "DBF")) ? TAB_DBF
: (!stricmp(type, "OEM")) ? 'E' : toupper(*type); : (!stricmp(type, "XML")) ? TAB_XML
: (!stricmp(type, "INI")) ? TAB_INI
: (!stricmp(type, "VEC")) ? TAB_VEC
: (!stricmp(type, "ODBC")) ? TAB_ODBC
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL
: (!stricmp(type, "DIR")) ? TAB_DIR
: (!stricmp(type, "MAC")) ? TAB_MAC
: (!stricmp(type, "WMI")) ? TAB_WMI
: (!stricmp(type, "TBL")) ? TAB_TBL
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID } // end of GetTypeID
/***********************************************************************/
/* Get a unique enum catalog function ID. */
/***********************************************************************/
uint GetFuncID(const char *func)
{
uint fnc;
if (!func)
fnc= FNC_NO;
else if (!strnicmp(func, "col", 3))
fnc= FNC_COL;
else if (!strnicmp(func, "tab", 3))
fnc= FNC_TABLE;
else if (!stricmp(func, "dsn") ||
!strnicmp(func, "datasource", 10) ||
!strnicmp(func, "source", 6) ||
!strnicmp(func, "sqldatasource", 13))
fnc= FNC_DSN;
else if (!strnicmp(func, "driver", 6) ||
!strnicmp(func, "sqldriver", 9))
fnc= FNC_DRIVER;
else
fnc= FNC_NIY;
return fnc;
} // end of GetFuncID
/* ------------------------- Class CATALOG --------------------------- */ /* ------------------------- Class CATALOG --------------------------- */
/***********************************************************************/ /***********************************************************************/
...@@ -270,43 +297,44 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef) ...@@ -270,43 +297,44 @@ char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef)
/***********************************************************************/ /***********************************************************************/
int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
{ {
char tc, *type= GetStringCatInfo(g, NULL, "Type", "DOS"); char *type= GetStringCatInfo(g, NULL, "Type", "DOS");
int i, loff, poff, nof, nlg; int i, loff, poff, nof, nlg;
void *field= NULL; void *field= NULL;
TABTYPE tc;
PCOLDEF cdp, lcdp= NULL, tocols= NULL; PCOLDEF cdp, lcdp= NULL, tocols= NULL;
PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO)); PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));
// Get a unique char identifier for type // Get a unique char identifier for type
tc= (!defp->Catfunc) ? GetTypeID(type) : 0; tc= (!defp->Catfunc) ? GetTypeID(type) : TAB_CATLG;
// Take care of the column definitions // Take care of the column definitions
i= poff= nof= nlg= 0; i= poff= nof= nlg= 0;
// Offsets of HTML and DIR tables start from 0, DBF at 1 // Offsets of HTML and DIR tables start from 0, DBF at 1
loff= (tc == 'A') ? 1 : (tc == 'X' || tc == 'R') ? -1 : 0; loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0;
while (true) { while (true) {
// Default Offset depends on table type // Default Offset depends on table type
switch (tc) { switch (tc) {
case 'D': // DOS case TAB_DOS:
case 'F': // FIX case TAB_FIX:
case 'B': // BIN case TAB_BIN:
case 'V': // VEC case TAB_VEC:
case 'A': // DBF case TAB_DBF:
poff= loff + nof; // Default next offset poff= loff + nof; // Default next offset
nlg= max(nlg, poff); // Default lrecl nlg= max(nlg, poff); // Default lrecl
break; break;
case 'C': // CSV case TAB_CSV:
case 'T': // FMT case TAB_FMT:
nlg+= nof; nlg+= nof;
case 'R': // DIR case TAB_DIR:
case 'X': // XML case TAB_XML:
poff= loff + 1; poff= loff + 1;
break; break;
case 'I': // INI case TAB_INI:
case 'M': // MAC case TAB_MAC:
case 'L': // TBL case TAB_TBL:
case 'E': // OEM case TAB_OEM:
poff = 0; // Offset represents an independant flag poff = 0; // Offset represents an independant flag
break; break;
default: // VCT PLG ODBC MYSQL WMI... default: // VCT PLG ODBC MYSQL WMI...
...@@ -318,7 +346,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -318,7 +346,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
field= Hc->GetColumnOption(field, pcf); field= Hc->GetColumnOption(field, pcf);
} while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/)); } while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/));
if (tc == 'A' && pcf->Type == TYPE_DATE && !pcf->Datefmt) { if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) {
// DBF date format defaults to 'YYYMMDD' // DBF date format defaults to 'YYYMMDD'
pcf->Datefmt= "YYYYMMDD"; pcf->Datefmt= "YYYYMMDD";
pcf->Length= 8; pcf->Length= 8;
...@@ -336,9 +364,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -336,9 +364,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
loff= cdp->GetOffset(); loff= cdp->GetOffset();
switch (tc) { switch (tc) {
case 'V': case TAB_VEC:
cdp->SetOffset(0); // Not to have shift cdp->SetOffset(0); // Not to have shift
case 'B': case TAB_BIN:
// BIN/VEC are packed by default // BIN/VEC are packed by default
if (nof) if (nof)
// Field width is the internal representation width // Field width is the internal representation width
...@@ -355,6 +383,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -355,6 +383,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
default: nof= cdp->Clen; default: nof= cdp->Clen;
} // endswitch Fmt } // endswitch Fmt
default:
break; break;
} // endswitch tc } // endswitch tc
...@@ -389,11 +418,11 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -389,11 +418,11 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
// Calculate the default record size // Calculate the default record size
switch (tc) { switch (tc) {
case 'F': case TAB_FIX:
recln= nlg + ending; // + length of line ending recln= nlg + ending; // + length of line ending
break; break;
case 'B': case TAB_BIN:
case 'V': case TAB_VEC:
recln= nlg; recln= nlg;
// if ((k= (pak < 0) ? 8 : pak) > 1) // if ((k= (pak < 0) ? 8 : pak) > 1)
...@@ -402,15 +431,16 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -402,15 +431,16 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
// recln= ((recln + k - 1) / k) * k; // recln= ((recln + k - 1) / k) * k;
break; break;
case 'D': case TAB_DOS:
case 'A': case TAB_DBF:
recln= nlg; recln= nlg;
break; break;
case 'T': case TAB_CSV:
case 'C': case TAB_FMT:
// The number of separators (assuming an extra one can exist) // The number of separators (assuming an extra one can exist)
// recln= poff * ((qotd) ? 3 : 1); to be investigated // recln= poff * ((qotd) ? 3 : 1); to be investigated
recln= nlg + poff * 3; // To be safe recln= nlg + poff * 3; // To be safe
default:
break; break;
} // endswitch tc } // endswitch tc
...@@ -484,46 +514,45 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name, ...@@ -484,46 +514,45 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name,
/***********************************************************************/ /***********************************************************************/
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
{ {
char tc; TABTYPE tc;
PRELDEF tdp= NULL; PRELDEF tdp= NULL;
if (xtrace) if (xtrace)
printf("MakeTableDesc: name=%s am=%s\n", name, SVP(am)); printf("MakeTableDesc: name=%s am=%s\n", name, SVP(am));
/*********************************************************************/ /*********************************************************************/
/* Get a unique char identifier for types. The letter used are: */ /* Get a unique enum identifier for types. */
/* ABCDEF..IJKLM.OPQRSTUVWXYZ and Allocate table definition class */
/*********************************************************************/ /*********************************************************************/
tc= GetTypeID(am); tc= GetTypeID(am);
switch (tc) { switch (tc) {
case 'F': case TAB_FIX:
case 'B': case TAB_BIN:
case 'A': case TAB_DBF:
case 'D': tdp= new(g) DOSDEF; break; case TAB_DOS: tdp= new(g) DOSDEF; break;
case 'T': case TAB_CSV:
case 'C': tdp= new(g) CSVDEF; break; case TAB_FMT: tdp= new(g) CSVDEF; break;
case 'I': tdp= new(g) INIDEF; break; case TAB_INI: tdp= new(g) INIDEF; break;
case 'R': tdp= new(g) DIRDEF; break; case TAB_DIR: tdp= new(g) DIRDEF; break;
#if defined(XML_SUPPORT) #if defined(XML_SUPPORT)
case 'X': tdp= new(g) XMLDEF; break; case TAB_XML: tdp= new(g) XMLDEF; break;
#endif // XML_SUPPORT #endif // XML_SUPPORT
case 'V': tdp= new(g) VCTDEF; break; case TAB_VEC: tdp= new(g) VCTDEF; break;
#if defined(ODBC_SUPPORT) #if defined(ODBC_SUPPORT)
case 'O': tdp= new(g) ODBCDEF; break; case TAB_ODBC: tdp= new(g) ODBCDEF; break;
#endif // ODBC_SUPPORT #endif // ODBC_SUPPORT
#if defined(WIN32) #if defined(WIN32)
case 'M': tdp= new(g) MACDEF; break; case TAB_MAC: tdp= new(g) MACDEF; break;
case 'W': tdp= new(g) WMIDEF; break; case TAB_WMI: tdp= new(g) WMIDEF; break;
#endif // WIN32 #endif // WIN32
case 'E': tdp= new(g) OEMDEF; break; case TAB_OEM: tdp= new(g) OEMDEF; break;
case 'L': tdp= new(g) TBLDEF; break; case TAB_TBL: tdp= new(g) TBLDEF; break;
#if defined(MYSQL_SUPPORT) #if defined(MYSQL_SUPPORT)
case 'Y': tdp= new(g) MYSQLDEF; break; case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
#endif // MYSQL_SUPPORT #endif // MYSQL_SUPPORT
#if defined(PIVOT_SUPPORT) //#if defined(PIVOT_SUPPORT)
case 'P': tdp= new(g) PIVOTDEF; break; // case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
#endif // PIVOT_SUPPORT //#endif // PIVOT_SUPPORT
default: default:
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name); sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch } // endswitch
......
/* Copyright (C) Olivier Bertrand 2004 - 2011 /* Copyright (C) Olivier Bertrand 2004 - 2013
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -24,7 +24,18 @@ ...@@ -24,7 +24,18 @@
#include "block.h" #include "block.h"
#include "catalog.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. */ /* MYCAT: class for managing the CONNECT plugin DB items. */
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* ODBC catalog function prototypes. */ /* ODBC catalog function prototypes. */
/***********************************************************************/ /***********************************************************************/
PQRYRES ODBCDataSources(PGLOBAL g, bool info); 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 ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info);
PQRYRES ODBCDrivers(PGLOBAL g, bool info); PQRYRES ODBCDrivers(PGLOBAL g, bool info);
...@@ -225,58 +225,67 @@ void ResetNullValues(CATPARM *cap) ...@@ -225,58 +225,67 @@ void ResetNullValues(CATPARM *cap)
/* of an ODBC table that will be retrieved by GetData commands. */ /* of an ODBC table that will be retrieved by GetData commands. */
/* Note: The first two columns (Qualifier, Owner) are ignored. */ /* Note: The first two columns (Qualifier, Owner) are ignored. */
/***********************************************************************/ /***********************************************************************/
PQRYRES ODBCColumns(PGLOBAL g, ODBConn *ocp, char *dsn, char *table, PQRYRES ODBCColumns(PGLOBAL g, char *dsn, char *table,
char *colpat) char *colpat, bool info)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR, static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR,
DB_CHAR, DB_SHORT, DB_CHAR, DB_CHAR, DB_SHORT, DB_CHAR,
DB_INT, DB_INT, DB_SHORT, DB_INT, DB_INT, DB_SHORT,
DB_SHORT, DB_SHORT, DB_CHAR}; DB_SHORT, DB_SHORT, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING, static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_SHORT, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING,
TYPE_INT, TYPE_INT, TYPE_SHORT, TYPE_INT, TYPE_INT, TYPE_SHORT,
TYPE_SHORT, TYPE_SHORT, TYPE_STRING}; TYPE_SHORT, TYPE_SHORT, TYPE_STRING};
static XFLD fldtyp[] = {FLD_NO, FLD_NO, static XFLD fldtyp[] = {FLD_NO, FLD_NO, FLD_NO,
FLD_NAME, FLD_TYPE, FLD_TYPENAME, FLD_NAME, FLD_TYPE, FLD_TYPENAME,
FLD_PREC, FLD_LENGTH, FLD_SCALE, FLD_PREC, FLD_LENGTH, FLD_SCALE,
FLD_RADIX, FLD_NULL, FLD_REM}; FLD_RADIX, FLD_NULL, FLD_REM};
static unsigned int length[] = {0, 0, 0, 6, 20, 10, 10, 6, 6, 6, 128}; static unsigned int length[] = {0, 0, 0, 0, 6, 20, 10, 10, 6, 6, 6, 128};
int n, ncol = 11; int n, ncol = 12;
int maxres; int maxres;
PQRYRES qrp; PQRYRES qrp;
CATPARM *cap; CATPARM *cap;
ODBConn *ocp;
/************************************************************************/ /************************************************************************/
/* Do an evaluation of the result size. */ /* Do an evaluation of the result size. */
/************************************************************************/ /************************************************************************/
if (ocp) { if (!info) {
ocp = new(g) ODBConn(g, NULL);
if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly
return NULL;
n = ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_TABLE); n = ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_TABLE);
maxres = (n) ? (int)n : 250; maxres = (n) ? (int)n : 250;
n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_QUALIFIER_NAME_LEN);
length[0] = (n) ? (n + 1) : 128; length[0] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN);
length[1] = (n) ? (n + 1) : 128; length[1] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN);
length[2] = (n) ? (n + 1) : 128; length[2] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN);
length[3] = (n) ? (n + 1) : 128;
} else { // Info table } else { // Info table
maxres = 0; maxres = 0;
length[0] = 128; length[0] = 128;
length[1] = 128; length[1] = 128;
length[2] = 128; length[2] = 128;
length[3] = 128;
} // endif ocp } // endif ocp
#ifdef DEBTRACE #ifdef DEBTRACE
htrc("ODBCColumns: max=%d len=%d,%d,%d\n", htrc("ODBCColumns: max=%d len=%d,%d,%d\n",
maxres, length[0], length[1], length[2]); maxres, length[0], length[1], length[2], length[3]);
#endif #endif
/************************************************************************/ /************************************************************************/
/* Allocate the structures used to refer to the result set. */ /* Allocate the structures used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_COLUMNS + 1, qrp = PlgAllocResult(g, ncol, maxres, IDS_COLUMNS,
dbtype, buftyp, NULL, length, true, true); dbtype, buftyp, fldtyp, length, true, true);
if (!ocp) // Info table if (info) // Info table
return qrp; return qrp;
#ifdef DEBTRACE #ifdef DEBTRACE
...@@ -305,6 +314,7 @@ PQRYRES ODBCColumns(PGLOBAL g, ODBConn *ocp, char *dsn, char *table, ...@@ -305,6 +314,7 @@ PQRYRES ODBCColumns(PGLOBAL g, ODBConn *ocp, char *dsn, char *table,
return qrp; return qrp;
} // end of ODBCColumns } // end of ODBCColumns
#if 0
/**************************************************************************/ /**************************************************************************/
/* MyODBCCols: returns column info as required by ha_connect::pre_create. */ /* MyODBCCols: returns column info as required by ha_connect::pre_create. */
/**************************************************************************/ /**************************************************************************/
...@@ -339,7 +349,6 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info) ...@@ -339,7 +349,6 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info)
if (ocp) if (ocp)
ocp->Close(); ocp->Close();
#if 0
if (!qrp) if (!qrp)
return NULL; // Error in ODBCColumns return NULL; // Error in ODBCColumns
...@@ -375,9 +384,9 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info) ...@@ -375,9 +384,9 @@ PQRYRES MyODBCCols(PGLOBAL g, char *dsn, char *tab, bool info)
crp->Ncol = ++i; crp->Ncol = ++i;
qrp->Nbcol = i; // Should be 7; was 11, skipped 4 qrp->Nbcol = i; // Should be 7; was 11, skipped 4
#endif // 0
return qrp; return qrp;
} // end of MyODBCCols } // end of MyODBCCols
#endif // 0
/*************************************************************************/ /*************************************************************************/
/* ODBCDataSources: constructs the result blocks containing all ODBC */ /* ODBCDataSources: constructs the result blocks containing all ODBC */
...@@ -482,16 +491,19 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info) ...@@ -482,16 +491,19 @@ PQRYRES ODBCDrivers(PGLOBAL g, bool info)
/***********************************************************************/ /***********************************************************************/
PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_CHAR}; static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_CHAR, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING, static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_STRING, TYPE_STRING}; TYPE_STRING, TYPE_STRING};
static unsigned int length[] = {0, 0, 16, 128}; static unsigned int length[] = {0, 0, 0, 16, 128};
int n, ncol = 4; int n, ncol = 5;
int maxres; int maxres;
PQRYRES qrp; PQRYRES qrp;
CATPARM *cap; CATPARM *cap;
ODBConn *ocp; ODBConn *ocp;
/************************************************************************/
/* Do an evaluation of the result size. */
/************************************************************************/
if (!info) { if (!info) {
/**********************************************************************/ /**********************************************************************/
/* Open the connection with the ODBC data source. */ /* Open the connection with the ODBC data source. */
...@@ -501,13 +513,9 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) ...@@ -501,13 +513,9 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info)
if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly
return NULL; return NULL;
} // endif info
/************************************************************************/
/* Do an evaluation of the result size. */
/************************************************************************/
if (!info) {
maxres = 512; // This is completely arbitrary maxres = 512; // This is completely arbitrary
n = ocp->GetMaxValue(SQL_MAX_QUALIFIER_NAME_LEN);
length[0] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN);
length[0] = (n) ? (n + 1) : 128; length[0] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN);
...@@ -516,6 +524,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) ...@@ -516,6 +524,7 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info)
maxres = 0; maxres = 0;
length[0] = 128; length[0] = 128;
length[1] = 128; length[1] = 128;
length[2] = 128;
} // endif info } // endif info
#ifdef DEBTRACE #ifdef DEBTRACE
...@@ -526,8 +535,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) ...@@ -526,8 +535,8 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info)
/************************************************************************/ /************************************************************************/
/* Allocate the structures used to refer to the result set. */ /* Allocate the structures used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_TABLES + 1, qrp = PlgAllocResult(g, ncol, maxres, IDS_TABLES, dbtype, buftyp,
dbtype, buftyp, NULL, length, true, true); NULL, length, true, true);
if (info) if (info)
return qrp; return qrp;
...@@ -570,10 +579,11 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info) ...@@ -570,10 +579,11 @@ PQRYRES ODBCTables(PGLOBAL g, char *dsn, char *tabpat, bool info)
/**************************************************************************/ /**************************************************************************/
PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_SHORT, DB_CHAR}; static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR,
DB_CHAR, DB_SHORT, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING, static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_STRING,
TYPE_SHORT, TYPE_STRING}; TYPE_STRING, TYPE_SHORT, TYPE_STRING};
static unsigned int length[] = {0, 0, 0, 6, 128}; static unsigned int length[] = {0, 0, 0, 0, 6, 128};
int n, ncol = 5; int n, ncol = 5;
int maxres; int maxres;
PQRYRES qrp; PQRYRES qrp;
...@@ -596,12 +606,14 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) ...@@ -596,12 +606,14 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table)
/************************************************************************/ /************************************************************************/
n = ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_TABLE); n = ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_TABLE);
maxres = (n) ? (int)n : 250; maxres = (n) ? (int)n : 250;
n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_QUALIFIER_NAME_LEN);
length[0] = (n) ? (n + 1) : 128; length[0] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN);
length[1] = (n) ? (n + 1) : 128; length[1] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN);
length[2] = (n) ? (n + 1) : 128; length[2] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN);
length[3] = (n) ? (n + 1) : 128;
#ifdef DEBTRACE #ifdef DEBTRACE
htrc("ODBCPrimaryKeys: max=%d len=%d,%d,%d\n", htrc("ODBCPrimaryKeys: max=%d len=%d,%d,%d\n",
...@@ -611,7 +623,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) ...@@ -611,7 +623,7 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table)
/************************************************************************/ /************************************************************************/
/* Allocate the structure used to refer to the result set. */ /* Allocate the structure used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_PKEY + 1, qrp = PlgAllocResult(g, ncol, maxres, IDS_PKEY,
dbtype, buftyp, NULL, length, true, true); dbtype, buftyp, NULL, length, true, true);
#ifdef DEBTRACE #ifdef DEBTRACE
...@@ -653,14 +665,15 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table) ...@@ -653,14 +665,15 @@ PQRYRES ODBCPrimaryKeys(PGLOBAL g, ODBConn *op, char *dsn, char *table)
PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat,
int un, int acc) int un, int acc)
{ {
static int dbtype[] = {DB_CHAR, DB_CHAR, DB_SHORT, DB_CHAR, static int dbtype[] = {DB_CHAR, DB_CHAR, DB_CHAR, DB_SHORT, DB_CHAR,
DB_CHAR, DB_SHORT, DB_SHORT, DB_CHAR, DB_CHAR, DB_SHORT, DB_SHORT, DB_CHAR, DB_CHAR,
DB_CHAR, DB_INT, DB_INT, DB_CHAR}; DB_INT, DB_INT, DB_CHAR};
static int buftyp[] = {TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING, static int buftyp[] = {TYPE_STRING,
TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_STRING,
TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_STRING, TYPE_STRING, TYPE_SHORT, TYPE_SHORT, TYPE_STRING,
TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_STRING}; TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_STRING};
static unsigned int length[] = {0, 0 ,6 ,0 ,0 ,6 ,6 ,0 ,2 ,10 ,10 ,128}; static unsigned int length[] = {0, 0, 0 ,6 ,0 ,0 ,6 ,6 ,0 ,2 ,10 ,10 ,128};
int n, ncol = 12; int n, ncol = 13;
int maxres; int maxres;
PQRYRES qrp; PQRYRES qrp;
CATPARM *cap; CATPARM *cap;
...@@ -683,11 +696,11 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, ...@@ -683,11 +696,11 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat,
n = 1 + ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_INDEX); n = 1 + ocp->GetMaxValue(SQL_MAX_COLUMNS_IN_INDEX);
maxres = (n) ? (int)n : 32; maxres = (n) ? (int)n : 32;
n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_USER_NAME_LEN);
length[0] = (n) ? (n + 1) : 128; length[1] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_TABLE_NAME_LEN);
length[1] = length[4] = (n) ? (n + 1) : 128; length[2] = length[5] = (n) ? (n + 1) : 128;
n = ocp->GetMaxValue(SQL_MAX_QUALIFIER_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_QUALIFIER_NAME_LEN);
length[3] = (n) ? (n + 1) : length[1]; length[0] = length[4] = (n) ? (n + 1) : length[2];
n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN); n = ocp->GetMaxValue(SQL_MAX_COLUMN_NAME_LEN);
length[7] = (n) ? (n + 1) : 128; length[7] = (n) ? (n + 1) : 128;
...@@ -698,7 +711,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, ...@@ -698,7 +711,7 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat,
/************************************************************************/ /************************************************************************/
/* Allocate the structure used to refer to the result set. */ /* Allocate the structure used to refer to the result set. */
/************************************************************************/ /************************************************************************/
qrp = PlgAllocResult(g, ncol, maxres, IDS_STAT + 1, qrp = PlgAllocResult(g, ncol, maxres, IDS_STAT,
dbtype, buftyp, NULL, length, true, true); dbtype, buftyp, NULL, length, true, true);
#ifdef DEBTRACE #ifdef DEBTRACE
...@@ -734,80 +747,6 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat, ...@@ -734,80 +747,6 @@ PQRYRES ODBCStatistics(PGLOBAL g, ODBConn *op, char *dsn, char *pat,
/************************************************************************/ /************************************************************************/
return qrp; return qrp;
} // end of Statistics } // end of Statistics
/***********************************************************************/
/* GetColumnInfo: used when defining a ODBC table. The issue is that */
/* some ODBC drivers give key information by SQLPrimaryKeys while */
/* others do not implement it but give info using SQLStatistics. */
/***********************************************************************/
PQRYRES GetColumnInfo(PGLOBAL g, char*& dsn,
char *table, int ver, PVBLK& vbp)
{
PCOLRES crp;
PQRYRES qrpc, qrp;
PVBLK vbp2;
ODBConn *ocp = new(g) ODBConn(g, NULL);
/**********************************************************************/
/* Open the connection with the ODBC data source. */
/**********************************************************************/
if (ocp->Open(dsn, 2) < 1) // 2 is openReadOnly
return NULL;
else if (ver > 0)
ocp->m_Catver = ver;
/**********************************************************************/
/* Get the information about the ODBC table columns. */
/**********************************************************************/
if ((qrpc = ODBCColumns(g, ocp, dsn, table, NULL)))
dsn = ocp->GetConnect(); // Complete connect string
else
return NULL;
if ((qrp = ODBCPrimaryKeys(g, ocp, dsn, table))) {
// Oracle, ...
if (qrp->Nblin) {
crp = qrp->Colresp->Next->Next;
vbp = crp->Kdata;
vbp->ReAlloc(vbp->GetValPointer(), qrp->Nblin);
} // endif Nblin
} else if ((qrp = ODBCStatistics(g, ocp, dsn, table, -1, -1))) {
// Case of Microsoft Jet Engine
if (qrp->Nblin) {
int i, n = 0;
PCOLRES crp2;
crp = qrp->Colresp->Next->Next->Next->Next;
crp2 = crp->Next->Next->Next;
// This test may have to be modified for other ODBC drivers
for (i = 0; i < qrp->Nblin; i++)
if (!strcmp(crp->Kdata->GetCharValue(i), "PrimaryKey"))
n++;
if (n) {
vbp2 = crp2->Kdata;
vbp = AllocValBlock(g, NULL, vbp2->GetType(), n,
vbp2->GetVlen(), 0, false, false);
for (i = 0, n = 0; i < qrp->Nblin; i++)
if (!strcmp(crp->Kdata->GetCharValue(i), "PrimaryKey"))
vbp->SetValue(vbp2, n++, i);
} // endif n
} // endif Nblin
} // endif qrp
/************************************************************************/
/* Close the local connection. */
/************************************************************************/
ocp->Close();
return qrpc;
} // end of GetColumnInfo
#endif // 0 #endif // 0
/***********************************************************************/ /***********************************************************************/
...@@ -1796,8 +1735,8 @@ int ODBConn::GetCatInfo(CATPARM *cap) ...@@ -1796,8 +1735,8 @@ int ODBConn::GetCatInfo(CATPARM *cap)
rc = SQLNumResultCols(hstmt, &ncol); rc = SQLNumResultCols(hstmt, &ncol);
// n + 1 because we ignore the first column // n because we no more ignore the first column
if ((n = (UWORD)cap->Qrp->Nbcol) + 1 > (UWORD)ncol) if ((n = (UWORD)cap->Qrp->Nbcol) > (UWORD)ncol)
ThrowDBX(MSG(COL_NUM_MISM)); ThrowDBX(MSG(COL_NUM_MISM));
if (m_RowsetSize == 1 && cap->Qrp->Maxres > 1) { if (m_RowsetSize == 1 && cap->Qrp->Maxres > 1) {
...@@ -1825,9 +1764,8 @@ int ODBConn::GetCatInfo(CATPARM *cap) ...@@ -1825,9 +1764,8 @@ int ODBConn::GetCatInfo(CATPARM *cap)
ThrowDBX(m_G->Message); ThrowDBX(m_G->Message);
} // endif tp } // endif tp
// n + 2 because column numbers begin with 1 and because // n + 1 because column numbers begin with 1
// we ignore the first column rc = SQLBindCol(hstmt, n + 1, tp, buffer, len, vl);
rc = SQLBindCol(hstmt, n + 2, tp, buffer, len, vl);
if (!Check(rc)) if (!Check(rc))
ThrowDBX(rc, hstmt); ThrowDBX(rc, hstmt);
......
...@@ -52,6 +52,30 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Correl Block */ ...@@ -52,6 +52,30 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Correl Block */
TYPE_FB_XML = 21, /* DOM XML file block */ TYPE_FB_XML = 21, /* DOM XML file block */
TYPE_FB_XML2 = 27}; /* libxml2 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 */ enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */ TYPE_AM_ROWID = 1, /* ROWID type (special column) */
TYPE_AM_FILID = 2, /* FILEID type (special column) */ TYPE_AM_FILID = 2, /* FILEID type (special column) */
......
...@@ -129,10 +129,10 @@ char *GetMsgid(int id) ...@@ -129,10 +129,10 @@ char *GetMsgid(int id)
case IDS_13: p = "%s: invalid connection key value %d"; break; case IDS_13: p = "%s: invalid connection key value %d"; break;
case IDS_14: p = "SafeDB: %s rc=%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_15: p = "Wrong communication Dll called for engine %s"; break;
case IDS_TAB_01: p = "Qualifier"; break; case IDS_TAB_01: p = "Table_Qualifier"; break;
case IDS_TAB_02: p = "Owner"; break; case IDS_TAB_02: p = "Table_Owner"; break;
case IDS_TAB_03: p = "Name"; break; case IDS_TAB_03: p = "Table_Name"; break;
case IDS_TAB_04: p = "Type"; break; case IDS_TAB_04: p = "Table_Type"; break;
case IDS_TAB_05: p = "Remark"; break; case IDS_TAB_05: p = "Remark"; break;
case IDS_COL_01: p = "Table_Qualif"; break; case IDS_COL_01: p = "Table_Qualif"; break;
case IDS_COL_02: p = "Table_Owner"; break; case IDS_COL_02: p = "Table_Owner"; break;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
/***********************************************************************/ /***********************************************************************/
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
#include "mycat.h"
#include "reldef.h" #include "reldef.h"
#include "colblk.h" #include "colblk.h"
#include "filamap.h" #include "filamap.h"
...@@ -74,7 +75,7 @@ TABDEF::TABDEF(void) ...@@ -74,7 +75,7 @@ TABDEF::TABDEF(void)
{ {
Owner = NULL; Owner = NULL;
Desc = NULL; Desc = NULL;
Catfunc = 0; Catfunc = FNC_NO;
Card = 0; Card = 0;
Elemt = 0; Elemt = 0;
Sort = 0; Sort = 0;
...@@ -96,7 +97,7 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) ...@@ -96,7 +97,7 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am)
Name = (PSZ)PlugSubAlloc(g, memp, strlen(name) + 1); Name = (PSZ)PlugSubAlloc(g, memp, strlen(name) + 1);
strcpy(Name, name); strcpy(Name, name);
Cat = cat; Cat = cat;
Catfunc = toupper(*Cat->GetStringCatInfo(g, Name, "Catfunc", "")); Catfunc = GetFuncID(Cat->GetStringCatInfo(g, Name, "Catfunc", NULL));
Elemt = cat->GetIntCatInfo(name, "Elements", 0); Elemt = cat->GetIntCatInfo(name, "Elements", 0);
Multiple = cat->GetIntCatInfo(name, "Multiple", 0); Multiple = cat->GetIntCatInfo(name, "Multiple", 0);
Degree = cat->GetIntCatInfo(name, "Degree", 0); Degree = cat->GetIntCatInfo(name, "Degree", 0);
......
...@@ -85,7 +85,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */ ...@@ -85,7 +85,7 @@ class DllExport TABDEF : public RELDEF { /* Logical table descriptor */
// Members // Members
PSZ Owner; /* Table owner (for ODBC) */ PSZ Owner; /* Table owner (for ODBC) */
PSZ Desc; /* Table description */ PSZ Desc; /* Table description */
char Catfunc; /* Catalog function */ uint Catfunc; /* Catalog function ID */
int Card; /* (max) number of rows in table */ int Card; /* (max) number of rows in table */
int Elemt; /* Number of rows in blocks or rowset */ int Elemt; /* Number of rows in blocks or rowset */
int Sort; /* Table already sorted ??? */ int Sort; /* Table already sorted ??? */
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include "osutil.h" #include "osutil.h"
#include "plgdbsem.h" #include "plgdbsem.h"
#include "catalog.h" #include "catalog.h"
//#include "reldef.h" #include "mycat.h"
#include "xindex.h" #include "xindex.h"
#include "filamap.h" #include "filamap.h"
#include "filamfix.h" #include "filamfix.h"
...@@ -297,7 +297,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -297,7 +297,7 @@ PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
/* Column blocks will be allocated only when needed. */ /* Column blocks will be allocated only when needed. */
/*********************************************************************/ /*********************************************************************/
if (Recfm == RECFM_DBF) { if (Recfm == RECFM_DBF) {
if (!Catfunc) { if (Catfunc == FNC_NO) {
if (map) if (map)
txfp = new(g) DBMFAM(this); txfp = new(g) DBMFAM(this);
else else
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/***********************************************************************/ /***********************************************************************/
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
#include "mycat.h"
#include "filamap.h" #include "filamap.h"
#if defined(ZIP_SUPPORT) #if defined(ZIP_SUPPORT)
#include "filamzip.h" #include "filamzip.h"
...@@ -405,7 +406,7 @@ bool CSVDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -405,7 +406,7 @@ bool CSVDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
char buf[8]; char buf[8];
// Double check correctness of offset values // Double check correctness of offset values
if (!Catfunc) if (Catfunc == FNC_NO)
for (PCOLDEF cdp = To_Cols; cdp; cdp = cdp->GetNext()) for (PCOLDEF cdp = To_Cols; cdp; cdp = cdp->GetNext())
if (cdp->GetOffset() < 1) { if (cdp->GetOffset() < 1) {
strcpy(g->Message, MSG(BAD_OFFSET_VAL)); strcpy(g->Message, MSG(BAD_OFFSET_VAL));
...@@ -441,7 +442,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode) ...@@ -441,7 +442,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
{ {
PTDBASE tdbp; PTDBASE tdbp;
if (Catfunc != 'C') { if (Catfunc != FNC_COL) {
USETEMP tmp = PlgGetUser(g)->UseTemp; USETEMP tmp = PlgGetUser(g)->UseTemp;
bool map = Mapped && mode != MODE_INSERT && bool map = Mapped && mode != MODE_INSERT &&
!(tmp != TMP_NO && mode == MODE_UPDATE) && !(tmp != TMP_NO && mode == MODE_UPDATE) &&
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#include "xtable.h" #include "xtable.h"
#include "tabcol.h" #include "tabcol.h"
#include "colblk.h" #include "colblk.h"
//#include "xindex.h" #include "mycat.h"
#include "reldef.h" #include "reldef.h"
#include "tabmysql.h" #include "tabmysql.h"
#include "valblk.h" #include "valblk.h"
...@@ -105,7 +105,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -105,7 +105,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/ /***********************************************************************/
PTDB MYSQLDEF::GetTable(PGLOBAL g, MODE m) PTDB MYSQLDEF::GetTable(PGLOBAL g, MODE m)
{ {
if (Catfunc == 'C') if (Catfunc == FNC_COL)
return new(g) TDBMCL(this); return new(g) TDBMCL(this);
else else
return new(g) TDBMYSQL(this); return new(g) TDBMYSQL(this);
......
...@@ -64,6 +64,7 @@ ...@@ -64,6 +64,7 @@
/***********************************************************************/ /***********************************************************************/
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
#include "mycat.h"
#include "xtable.h" #include "xtable.h"
#include "tabodbc.h" #include "tabodbc.h"
#include "odbccat.h" #include "odbccat.h"
...@@ -102,7 +103,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -102,7 +103,7 @@ bool ODBCDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Desc = Connect = Cat->GetStringCatInfo(g, Name, "Connect", ""); Desc = Connect = Cat->GetStringCatInfo(g, Name, "Connect", "");
Tabname = Cat->GetStringCatInfo(g, Name, "Name", Tabname = Cat->GetStringCatInfo(g, Name, "Name",
Catfunc == 'T' ? NULL : Name); (Catfunc & (FNC_TABLE || FNC_COL)) ? NULL : Name);
Tabname = Cat->GetStringCatInfo(g, Name, "Tabname", Tabname); Tabname = Cat->GetStringCatInfo(g, Name, "Tabname", Tabname);
Tabowner = Cat->GetStringCatInfo(g, Name, "Owner", ""); Tabowner = Cat->GetStringCatInfo(g, Name, "Owner", "");
Tabqual = Cat->GetStringCatInfo(g, Name, "Qualifier", ""); Tabqual = Cat->GetStringCatInfo(g, Name, "Qualifier", "");
...@@ -125,16 +126,16 @@ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m) ...@@ -125,16 +126,16 @@ PTDB ODBCDEF::GetTable(PGLOBAL g, MODE m)
/* Column blocks will be allocated only when needed. */ /* Column blocks will be allocated only when needed. */
/*********************************************************************/ /*********************************************************************/
switch (Catfunc) { switch (Catfunc) {
case 'C': case FNC_COL:
tdbp = new(g) TDBOCL(this); tdbp = new(g) TDBOCL(this);
break; break;
case 'T': case FNC_TABLE:
tdbp = new(g) TDBOTB(this); tdbp = new(g) TDBOTB(this);
break; break;
case 'S': case FNC_DSN:
tdbp = new(g) TDBSRC(this); tdbp = new(g) TDBSRC(this);
break; break;
case 'D': case FNC_DRIVER:
tdbp = new(g) TDBDRV(this); tdbp = new(g) TDBDRV(this);
break; break;
default: default:
...@@ -950,7 +951,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g) ...@@ -950,7 +951,7 @@ PQRYRES TDBOTB::GetResult(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
PQRYRES TDBOCL::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 GetResult
/* ------------------------ End of Tabodbc --------------------------- */ /* ------------------------ End of Tabodbc --------------------------- */
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "global.h" #include "global.h"
#include "plgdbsem.h" #include "plgdbsem.h"
//#include "catalog.h" #include "mycat.h"
#include "reldef.h" #include "reldef.h"
#include "xtable.h" #include "xtable.h"
#include "colblk.h" #include "colblk.h"
...@@ -344,7 +344,7 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -344,7 +344,7 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Wclass = strcat(strcpy(p, "Win32_"), Wclass); Wclass = strcat(strcpy(p, "Win32_"), Wclass);
} // endif Wclass } // endif Wclass
if (!Catfunc) if (Catfunc == FNC_NO)
Ems = Cat->GetIntCatInfo(Name, "Estimate", 100); Ems = Cat->GetIntCatInfo(Name, "Estimate", 100);
return false; return false;
...@@ -355,12 +355,12 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -355,12 +355,12 @@ bool WMIDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
/***********************************************************************/ /***********************************************************************/
PTDB WMIDEF::GetTable(PGLOBAL g, MODE m) PTDB WMIDEF::GetTable(PGLOBAL g, MODE m)
{ {
if (!Catfunc) if (Catfunc == FNC_NO)
return new(g) TDBWMI(this); return new(g) TDBWMI(this);
else if (Catfunc == 'C') else if (Catfunc == FNC_COL)
return new(g) TDBWCL(this); 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; return NULL;
} // end of GetTable } // 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