mycat.cc 21.6 KB
Newer Older
1
/* Copyright (C) Olivier Bertrand 2004 - 2013
Alexander Barkov's avatar
Alexander Barkov committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  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
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/*************** Mycat CC Program Source Code File (.CC) ***************/
/* PROGRAM NAME: MYCAT                                                 */
/* -------------                                                       */
19
/*  Version 1.4                                                        */
Alexander Barkov's avatar
Alexander Barkov committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
/*                                                                     */
/*  Author: Olivier Bertrand                       2012 - 2013         */
/*                                                                     */
/* WHAT THIS PROGRAM DOES:                                             */
/* -----------------------                                             */
/*  This program are the DB description related routines.              */
/***********************************************************************/

/***********************************************************************/
/*  Include relevant MariaDB header file.                              */
/***********************************************************************/
#if defined(WIN32)
//#include <windows.h>
//#include <sqlext.h>
#elif defined(UNIX)
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#endif
#define DONT_DEFINE_VOID
//#include <mysql/plugin.h>
#include "handler.h"
#undef  OFFSET

/***********************************************************************/
/*  Include application header files                                   */
/*                                                                     */
/*  global.h     is header containing all global declarations.         */
/*  plgdbsem.h   is header containing DB application declarations.     */
/*  tabdos.h     is header containing TDBDOS classes declarations.     */
/*  MYCAT.h      is header containing DB description declarations.     */
/***********************************************************************/
#if defined(UNIX)
#include "osutil.h"
#endif   // UNIX
#include "global.h"
#include "plgdbsem.h"
#include "reldef.h"
#include "tabcol.h"
#include "xtable.h"
#include "filamtxt.h"
#include "tabdos.h"
#include "tabfmt.h"
#include "tabvct.h"
#include "tabsys.h"
#if defined(WIN32)
#include "tabmac.h"
#include "tabwmi.h"
#endif   // WIN32
71 72
//#include "tabtbl.h"
#include "tabxcl.h"
Alexander Barkov's avatar
Alexander Barkov committed
73
#include "tabtbl.h"
74
#include "taboccur.h"
Alexander Barkov's avatar
Alexander Barkov committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#if defined(XML_SUPPORT)
#include "tabxml.h"
#endif   // XML_SUPPORT
#include "tabmul.h"
#if defined(MYSQL_SUPPORT)
#include "tabmysql.h"
#endif   // MYSQL_SUPPORT
#if defined(ODBC_SUPPORT)
#define NODBC
#include "tabodbc.h"
#endif   // ODBC_SUPPORT
#if defined(PIVOT_SUPPORT)
#include "tabpivot.h"
#endif   // PIVOT_SUPPORT
#include "ha_connect.h"
#include "mycat.h"

92 93 94
/***********************************************************************/
/*  Extern static variables.                                           */
/***********************************************************************/
Alexander Barkov's avatar
Alexander Barkov committed
95 96 97 98 99 100 101
#if defined(WIN32)
extern "C" HINSTANCE s_hModule;           // Saved module handle
#endif  // !WIN32

extern int xtrace;

/***********************************************************************/
102
/*  Get a unique enum table type ID.                                   */
Alexander Barkov's avatar
Alexander Barkov committed
103
/***********************************************************************/
104
TABTYPE GetTypeID(const char *type)
Alexander Barkov's avatar
Alexander Barkov committed
105
  {
106 107 108 109 110 111 112
  return (!type) ? TAB_UNDEF                      
                 : (!stricmp(type, "DOS"))   ? TAB_DOS
                 : (!stricmp(type, "FIX"))   ? TAB_FIX
                 : (!stricmp(type, "BIN"))   ? TAB_BIN
	               : (!stricmp(type, "CSV"))   ? TAB_CSV
                 : (!stricmp(type, "FMT"))   ? TAB_FMT
                 : (!stricmp(type, "DBF"))   ? TAB_DBF
113
#ifdef XML_SUPPORT
114
                 : (!stricmp(type, "XML"))   ? TAB_XML
115
#endif
116 117
                 : (!stricmp(type, "INI"))   ? TAB_INI
                 : (!stricmp(type, "VEC"))   ? TAB_VEC
118
#ifdef ODBC_SUPPORT
119
                 : (!stricmp(type, "ODBC"))  ? TAB_ODBC
120
#endif
121
#ifdef MYSQL_SUPPORT
122
                 : (!stricmp(type, "MYSQL")) ? TAB_MYSQL
123
                 : (!stricmp(type, "MYPRX")) ? TAB_MYSQL
124
#endif
125
                 : (!stricmp(type, "DIR"))   ? TAB_DIR
126
#ifdef WIN32
127 128
	               : (!stricmp(type, "MAC"))   ? TAB_MAC
	               : (!stricmp(type, "WMI"))   ? TAB_WMI
129
#endif
130
	               : (!stricmp(type, "TBL"))   ? TAB_TBL
131 132 133 134
	               : (!stricmp(type, "XCOL"))  ? TAB_XCL
	               : (!stricmp(type, "OCCUR")) ? TAB_OCCUR
                 : (!stricmp(type, "CATLG")) ? TAB_PRX  // Legacy
                 : (!stricmp(type, "PROXY")) ? TAB_PRX
Olivier Bertrand's avatar
Olivier Bertrand committed
135 136 137
#ifdef PIVOT_SUPPORT
                 : (!stricmp(type, "PIVOT")) ? TAB_PIVOT
#endif
138
                 : (!stricmp(type, "OEM"))   ? TAB_OEM : TAB_NIY;
Alexander Barkov's avatar
Alexander Barkov committed
139 140
  } // end of GetTypeID

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
/***********************************************************************/
/*  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:
156
    case TAB_INI:
157 158 159 160 161 162 163 164 165 166 167
    case TAB_VEC:
      isfile= true;
      break;
    default:
      isfile= false;
      break;
    } // endswitch type

  return isfile;
  } // end of IsFileType

168 169 170 171 172 173 174
/***********************************************************************/
/*  Return true for table types accepting null fields.                 */
/***********************************************************************/
bool IsTypeNullable(TABTYPE type)
  {
  bool nullable;

175
#if 0
176 177 178
  switch (type) {                      
    case TAB_ODBC:
    case TAB_MYSQL:
179
    case TAB_TBL:
180 181 182 183 184 185 186 187
    case TAB_INI:
    case TAB_XML:
      nullable= true;
      break;
    default:
      nullable= false;
      break;
    } // endswitch type
188 189 190 191 192 193 194 195 196 197 198 199
#endif // 0

  switch (type) {                      
    case TAB_MAC:
    case TAB_DIR:
      nullable= false;
      break;
    default:
      nullable= true;
      break;
    } // endswitch type

200 201 202
  return nullable;
  } // end of IsTypeNullable

203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/***********************************************************************/
/*  Return true for table types with fix length records.               */
/***********************************************************************/
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

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
/***********************************************************************/
/*  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

Alexander Barkov's avatar
Alexander Barkov committed
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
/* ------------------------- Class CATALOG --------------------------- */

/***********************************************************************/
/*  CATALOG Constructor.                                               */
/***********************************************************************/
CATALOG::CATALOG(void)
  {
#if defined(WIN32)
  DataPath= ".\\";
#else   // !WIN32
  DataPath= "./";
#endif  // !WIN32
  memset(&Ctb, 0, sizeof(CURTAB));
  Cbuf= NULL;
  Cblen= 0;
	DefHuge= false;
  } // end of CATALOG constructor

/* -------------------------- Class MYCAT ---------------------------- */

/***********************************************************************/
/*  MYCAT Constructor.                                                 */
/***********************************************************************/
MYCAT::MYCAT(PHC hc) : CATALOG()
  {
	Hc= hc;
  DefHuge= false;
  } // end of MYCAT constructor

/***********************************************************************/
282
/*  Nothing to do for CONNECT.                                         */
Alexander Barkov's avatar
Alexander Barkov committed
283 284 285 286 287 288 289 290 291 292 293 294 295
/***********************************************************************/
void MYCAT::Reset(void)
  {
  } // end of Reset

/***********************************************************************/
/*  This function sets the current database path.                      */
/***********************************************************************/
void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
	{
	if (path) {
		size_t len= strlen(path) + (*path != '.' ? 4 : 1);
		char  *buf= (char*)PlugSubAlloc(g, NULL, len);
296 297 298 299 300 301 302
		
		if (PlugIsAbsolutePath(path))
		{
		  strcpy(buf, path);
		  *datapath= buf;
		  return;
		}
Alexander Barkov's avatar
Alexander Barkov committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321

		if (*path != '.') {
#if defined(WIN32)
			char *s= "\\";
#else   // !WIN32
			char *s= "/";
#endif  // !WIN32
			strcat(strcat(strcat(strcpy(buf, "."), s), path), s);
		} else
			strcpy(buf, path);

		*datapath= buf;
		} // endif path

	} // end of SetDataPath

/***********************************************************************/
/*  This function sets an integer MYCAT information.                   */
/***********************************************************************/
322
bool MYCAT::SetIntCatInfo(PSZ what, int n)
Alexander Barkov's avatar
Alexander Barkov committed
323 324 325 326 327 328 329
	{
	return Hc->SetIntegerOption(what, n);
	} // end of SetIntCatInfo

/***********************************************************************/
/*  This function returns integer MYCAT information.                   */
/***********************************************************************/
330
int MYCAT::GetIntCatInfo(PSZ what, int idef)
Alexander Barkov's avatar
Alexander Barkov committed
331 332 333 334 335 336 337 338 339
	{
	int n= Hc->GetIntegerOption(what);

	return (n == NO_IVAL) ? idef : n;
	} // end of GetIntCatInfo

/***********************************************************************/
/*  This function returns Boolean MYCAT information.                   */
/***********************************************************************/
340
bool MYCAT::GetBoolCatInfo(PSZ what, bool bdef)
Alexander Barkov's avatar
Alexander Barkov committed
341 342 343 344 345 346 347 348 349
	{
	bool b= Hc->GetBooleanOption(what, bdef);

	return b;
	} // end of GetBoolCatInfo

/***********************************************************************/
/*  This function returns size catalog information.                    */
/***********************************************************************/
350
int MYCAT::GetSizeCatInfo(PSZ what, PSZ sdef)
Alexander Barkov's avatar
Alexander Barkov committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
	{
	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 MYCAT information in buf.                  */
/***********************************************************************/
372
int MYCAT::GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size)
Alexander Barkov's avatar
Alexander Barkov committed
373 374 375 376 377 378 379 380 381 382 383
	{
	char *s= Hc->GetStringOption(what);

	strncpy(buf, ((s) ? s : sdef), size);
	return size;
	} // end of GetCharCatInfo

/***********************************************************************/
/*  This function returns string MYCAT information.                    */
/*  Default parameter is "*" to get the handler default.               */
/***********************************************************************/
384
char *MYCAT::GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef)
Alexander Barkov's avatar
Alexander Barkov committed
385 386 387 388 389 390
	{
	char *sval, *s= Hc->GetStringOption(what, sdef);
	
	if (s) {
		sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
		strcpy(sval, s);
391 392
  } else if (!stricmp(what, "filename")) {
    // Return default file name
393 394 395 396
    char *ftype= Hc->GetStringOption("Type", "dos");
    int   i, n;

    sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 12);
397
    strcat(strcpy(sval, Hc->GetTableName()), ".");
398 399 400 401 402 403 404 405 406 407
    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]);

408
  } else
Alexander Barkov's avatar
Alexander Barkov committed
409 410 411 412 413 414 415 416 417 418
		sval = NULL;

	return sval;
	}	// end of GetStringCatInfo

/***********************************************************************/
/*  This function returns column MYCAT information.                    */
/***********************************************************************/
int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
	{
419
	char		*type= GetStringCatInfo(g, "Type", "DOS");
Alexander Barkov's avatar
Alexander Barkov committed
420 421
	int      i, loff, poff, nof, nlg;
	void    *field= NULL;
422
  TABTYPE  tc;
Alexander Barkov's avatar
Alexander Barkov committed
423 424 425 426
  PCOLDEF  cdp, lcdp= NULL, tocols= NULL;
	PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));

  // Get a unique char identifier for type
427
  tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX;
Alexander Barkov's avatar
Alexander Barkov committed
428 429 430 431 432

  // Take care of the column definitions
	i= poff= nof= nlg= 0;

	// Offsets of HTML and DIR tables start from 0, DBF at 1
433
	loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0; 
Alexander Barkov's avatar
Alexander Barkov committed
434 435 436 437

  while (true) {
		// Default Offset depends on table type
		switch (tc) {
438 439 440 441 442
      case TAB_DOS:
      case TAB_FIX:
      case TAB_BIN:
      case TAB_VEC:
      case TAB_DBF:
Alexander Barkov's avatar
Alexander Barkov committed
443 444 445
        poff= loff + nof;				 // Default next offset
				nlg= max(nlg, poff);		 // Default lrecl
        break;
446 447
      case TAB_CSV:
      case TAB_FMT:
Alexander Barkov's avatar
Alexander Barkov committed
448
				nlg+= nof;
449 450
      case TAB_DIR:
      case TAB_XML:
Alexander Barkov's avatar
Alexander Barkov committed
451 452
        poff= loff + 1;
        break;
453 454 455
      case TAB_INI:
      case TAB_MAC:
      case TAB_TBL:
456 457 458
      case TAB_XCL:
      case TAB_OCCUR:
      case TAB_PRX:
459
      case TAB_OEM:
Alexander Barkov's avatar
Alexander Barkov committed
460 461 462 463 464 465 466 467 468 469 470
        poff = 0;      // Offset represents an independant flag
        break;
      default:         // VCT PLG ODBC MYSQL WMI...
        poff = 0;			 // NA
        break;
			} // endswitch tc

		do {
			field= Hc->GetColumnOption(field, pcf);
			} while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/));

471
		if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) {
Alexander Barkov's avatar
Alexander Barkov committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
			// 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) {
489
			case TAB_VEC:
Alexander Barkov's avatar
Alexander Barkov committed
490
				cdp->SetOffset(0);		 // Not to have shift
491
			case TAB_BIN:
Alexander Barkov's avatar
Alexander Barkov committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
				// 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

508
      default:
Alexander Barkov's avatar
Alexander Barkov committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
				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 != defp->GetDegree())
    defp->SetDegree(i);

	if (defp->GetDefType() == TYPE_AM_DOS) {
		int			ending, recln= 0;
		PDOSDEF ddp= (PDOSDEF)defp;

		// 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) {
543
      case TAB_FIX:
Alexander Barkov's avatar
Alexander Barkov committed
544 545
        recln= nlg + ending;     // + length of line ending
        break;
546 547
      case TAB_BIN:
      case TAB_VEC:
Alexander Barkov's avatar
Alexander Barkov committed
548 549 550 551 552 553 554 555
        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;
556 557
      case TAB_DOS:
      case TAB_DBF:
Alexander Barkov's avatar
Alexander Barkov committed
558 559
        recln= nlg;
        break;
560 561
      case TAB_CSV:
      case TAB_FMT:
Alexander Barkov's avatar
Alexander Barkov committed
562 563 564
        // 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
565
      default:
Alexander Barkov's avatar
Alexander Barkov committed
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
        break;
      } // endswitch tc

		// lrecl must be at least recln to avoid buffer overflow
		recln= max(recln, Hc->GetIntegerOption("Lrecl"));
		Hc->SetIntegerOption("Lrecl", recln);
		ddp->SetLrecl(recln);
		} // endif Lrecl

	// Attach the column definition to the tabdef
	defp->SetCols(tocols);
	return poff;
	} // end of GetColCatInfo

/***********************************************************************/
/*  GetIndexInfo: retrieve index description from the table structure. */
/***********************************************************************/
bool MYCAT::GetIndexInfo(PGLOBAL g, PTABDEF defp)
  {
585 586
  // Attach new index(es)
  defp->SetIndx(Hc->GetIndexInfo());
Alexander Barkov's avatar
Alexander Barkov committed
587 588 589 590 591
	return false;
  } // end of GetIndexInfo

/***********************************************************************/
/*  GetTableDesc: retrieve a table descriptor.                         */
592
/*  Look for a table descriptor matching the name and type.            */
Alexander Barkov's avatar
Alexander Barkov committed
593 594
/***********************************************************************/
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name,
595
                                       LPCSTR type, PRELDEF *prp)
Alexander Barkov's avatar
Alexander Barkov committed
596 597
  {
	if (xtrace)
598
		printf("GetTableDesc: name=%s am=%s\n", name, SVP(type));
Alexander Barkov's avatar
Alexander Barkov committed
599

600 601
 	// If not specified get the type of this table
  if (!type && !(type= Hc->GetStringOption("Type")))
602
    type= (Hc->GetStringOption("Tabname")) ? "PROXY" : "DOS";
Alexander Barkov's avatar
Alexander Barkov committed
603 604 605 606 607 608 609 610 611 612

  return MakeTableDesc(g, name, type);
  } // end of GetTableDesc

/***********************************************************************/
/*  MakeTableDesc: make a table/view description.                      */
/*  Note: caller must check if name already exists before calling it.  */
/***********************************************************************/
PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
  {
613
  TABTYPE tc;
Alexander Barkov's avatar
Alexander Barkov committed
614 615 616 617 618 619
  PRELDEF tdp= NULL;

	if (xtrace)
		printf("MakeTableDesc: name=%s am=%s\n", name, SVP(am));

  /*********************************************************************/
620
  /*  Get a unique enum identifier for types.                          */
Alexander Barkov's avatar
Alexander Barkov committed
621
  /*********************************************************************/
622
  tc= GetTypeID(am);
Alexander Barkov's avatar
Alexander Barkov committed
623 624

  switch (tc) {
625 626 627 628 629 630 631 632
    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;
Alexander Barkov's avatar
Alexander Barkov committed
633
#if defined(XML_SUPPORT)
634
    case TAB_XML: tdp= new(g) XMLDEF;   break;
Alexander Barkov's avatar
Alexander Barkov committed
635
#endif   // XML_SUPPORT
636
    case TAB_VEC: tdp= new(g) VCTDEF;   break;
Alexander Barkov's avatar
Alexander Barkov committed
637
#if defined(ODBC_SUPPORT)
638
    case TAB_ODBC: tdp= new(g) ODBCDEF; break;
Alexander Barkov's avatar
Alexander Barkov committed
639 640
#endif   // ODBC_SUPPORT
#if defined(WIN32)
641 642
    case TAB_MAC: tdp= new(g) MACDEF;   break;
    case TAB_WMI: tdp= new(g) WMIDEF;   break;
Alexander Barkov's avatar
Alexander Barkov committed
643
#endif   // WIN32
644 645
    case TAB_OEM: tdp= new(g) OEMDEF;   break;
	  case TAB_TBL: tdp= new(g) TBLDEF;   break;
646 647 648
	  case TAB_XCL: tdp= new(g) XCLDEF;   break;
	  case TAB_PRX: tdp= new(g) PRXDEF;   break;
		case TAB_OCCUR: tdp= new(g) OCCURDEF;	break;
Alexander Barkov's avatar
Alexander Barkov committed
649
#if defined(MYSQL_SUPPORT)
650
		case TAB_MYSQL: tdp= new(g) MYSQLDEF;	break;
Alexander Barkov's avatar
Alexander Barkov committed
651
#endif   // MYSQL_SUPPORT
Olivier Bertrand's avatar
Olivier Bertrand committed
652 653 654
#if defined(PIVOT_SUPPORT)
    case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
#endif   // PIVOT_SUPPORT
Alexander Barkov's avatar
Alexander Barkov committed
655 656 657 658
    default:
      sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
    } // endswitch

659
  // Do make the table/view definition
Alexander Barkov's avatar
Alexander Barkov committed
660 661 662 663 664 665 666 667 668
  if (tdp && tdp->Define(g, this, name, am))
    tdp= NULL;

  return tdp;
  } // end of MakeTableDesc

/***********************************************************************/
/*  Initialize a Table Description Block construction.                 */
/***********************************************************************/
669
PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
Alexander Barkov's avatar
Alexander Barkov committed
670 671 672 673 674 675 676 677 678
  {
  PRELDEF tdp;
  PTDB    tdbp= NULL;
  LPCSTR  name= tablep->GetName();

	if (xtrace)
		printf("GetTableDB: name=%s\n", name);

  // Look for the description of the requested table
679
  tdp= GetTableDesc(g, name, type);
Alexander Barkov's avatar
Alexander Barkov committed
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709

  if (tdp) {
		if (xtrace)
			printf("tdb=%p type=%s\n", tdp, tdp->GetType());

		if (tablep->GetQualifier())
			SetPath(g, &tdp->Database, tablep->GetQualifier());
		
    tdbp= tdp->GetTable(g, mode);
		} // endif tdp

  if (tdbp) {
		if (xtrace)
			printf("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
																						tdbp->GetAmType());
    tablep->SetTo_Tdb(tdbp);
    tdbp->SetTable(tablep);
    } // endif tdbp

  return (tdbp);
  } // end of GetTable

/***********************************************************************/
/*  ClearDB: Terminates Database usage.                                */
/***********************************************************************/
void MYCAT::ClearDB(PGLOBAL g)
  {
  } // end of ClearDB

/* ------------------------ End of MYCAT --------------------------- */