2017-07-02 22:29:31 +02:00
|
|
|
/* Copyright (C) MariaDB Corporation Ab
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
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
|
2019-08-17 16:58:58 +02:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/*************** Mycat CC Program Source Code File (.CC) ***************/
|
|
|
|
/* PROGRAM NAME: MYCAT */
|
|
|
|
/* ------------- */
|
2020-12-01 19:30:56 +01:00
|
|
|
/* Version 1.8 */
|
2013-02-07 10:34:27 +01:00
|
|
|
/* */
|
2020-12-01 19:30:56 +01:00
|
|
|
/* Author: Olivier Bertrand 2012 - 2020 */
|
2013-02-07 10:34:27 +01:00
|
|
|
/* */
|
|
|
|
/* WHAT THIS PROGRAM DOES: */
|
|
|
|
/* ----------------------- */
|
|
|
|
/* This program are the DB description related routines. */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Include relevant MariaDB header file. */
|
|
|
|
/***********************************************************************/
|
2018-05-07 00:27:13 +02:00
|
|
|
#define DONT_DEFINE_VOID
|
|
|
|
#include <my_global.h>
|
2014-10-09 10:30:11 +02:00
|
|
|
|
2018-05-07 00:27:13 +02:00
|
|
|
#if defined(UNIX)
|
2013-02-07 10:34:27 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
#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"
|
2017-02-16 18:01:48 +01:00
|
|
|
//#include "reldef.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "xtable.h"
|
2017-02-16 18:01:48 +01:00
|
|
|
#include "tabext.h"
|
|
|
|
#include "tabcol.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "filamtxt.h"
|
|
|
|
#include "tabdos.h"
|
|
|
|
#include "tabfmt.h"
|
2016-11-06 14:57:27 +01:00
|
|
|
#if defined(VCT_SUPPORT)
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabvct.h"
|
2016-11-06 14:57:27 +01:00
|
|
|
#endif // VCT_SUPPORT
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabsys.h"
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32)
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabmac.h"
|
|
|
|
#include "tabwmi.h"
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // _WIN32
|
2013-04-29 13:50:20 +02:00
|
|
|
//#include "tabtbl.h"
|
|
|
|
#include "tabxcl.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabtbl.h"
|
2013-04-29 13:50:20 +02:00
|
|
|
#include "taboccur.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabmul.h"
|
|
|
|
#include "tabmysql.h"
|
|
|
|
#if defined(ODBC_SUPPORT)
|
|
|
|
#define NODBC
|
|
|
|
#include "tabodbc.h"
|
|
|
|
#endif // ODBC_SUPPORT
|
2017-10-15 16:13:23 +02:00
|
|
|
#if defined(JAVA_SUPPORT)
|
2016-05-12 23:26:40 +02:00
|
|
|
#define NJDBC
|
|
|
|
#include "tabjdbc.h"
|
2017-10-15 16:13:23 +02:00
|
|
|
#endif // JAVA_SUPPORT
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "tabpivot.h"
|
2014-10-31 12:28:07 +01:00
|
|
|
#include "tabvir.h"
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
#include "tabbson.h"
|
|
|
|
#else
|
2015-01-19 18:55:25 +01:00
|
|
|
#include "tabjson.h"
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2013-02-07 10:34:27 +01:00
|
|
|
#include "ha_connect.h"
|
2015-04-17 20:05:41 +02:00
|
|
|
#if defined(XML_SUPPORT)
|
|
|
|
#include "tabxml.h"
|
|
|
|
#endif // XML_SUPPORT
|
2018-01-30 15:43:20 +01:00
|
|
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
2017-07-02 22:29:31 +02:00
|
|
|
#include "mongo.h"
|
2018-01-30 15:43:20 +01:00
|
|
|
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
2016-12-12 10:57:19 +01:00
|
|
|
#if defined(ZIP_SUPPORT)
|
|
|
|
#include "tabzip.h"
|
|
|
|
#endif // ZIP_SUPPORT
|
2019-07-30 22:45:04 +02:00
|
|
|
#if defined(REST_SUPPORT)
|
|
|
|
#include "tabrest.h"
|
2019-11-16 14:59:54 +01:00
|
|
|
#endif // REST_SUPPORT
|
2015-12-04 22:38:16 +01:00
|
|
|
#include "mycat.h"
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2013-02-12 12:34:14 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Extern static variables. */
|
|
|
|
/***********************************************************************/
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32)
|
2013-02-07 10:34:27 +01:00
|
|
|
extern "C" HINSTANCE s_hModule; // Saved module handle
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // !_WIN32
|
2018-01-30 15:43:20 +01:00
|
|
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
|
|
|
bool MongoEnabled(void);
|
|
|
|
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
|
|
|
bool Force_Bson(void);
|
|
|
|
#endif // BSON_SUPPORT
|
2014-02-03 23:07:49 +01:00
|
|
|
|
2015-05-20 11:19:44 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the plugin directory. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char *GetPluginDir(void)
|
|
|
|
{
|
2016-09-05 13:18:04 +02:00
|
|
|
return opt_plugin_dir;
|
2015-05-20 11:19:44 +02:00
|
|
|
} // end of GetPluginDir
|
|
|
|
|
2021-05-17 19:17:31 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Get the lc_messages_dir, it is where error messages for various */
|
|
|
|
/* languages are installed, and by default the INSTALL_MYSQLSHAREDIR. */
|
|
|
|
/***********************************************************************/
|
|
|
|
char *GetMessageDir(void)
|
|
|
|
{
|
|
|
|
return lc_messages_dir;
|
|
|
|
} // end of GetMessageDir
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2013-02-12 12:34:14 +01:00
|
|
|
/* Get a unique enum table type ID. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2013-02-12 12:34:14 +01:00
|
|
|
TABTYPE GetTypeID(const char *type)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
2019-08-17 16:58:58 +02:00
|
|
|
return (!type) ? TAB_UNDEF
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "DOS")) ? TAB_DOS
|
|
|
|
: (!stricmp(type, "FIX")) ? TAB_FIX
|
|
|
|
: (!stricmp(type, "BIN")) ? TAB_BIN
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "CSV")) ? TAB_CSV
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "FMT")) ? TAB_FMT
|
|
|
|
: (!stricmp(type, "DBF")) ? TAB_DBF
|
2017-07-02 22:29:31 +02:00
|
|
|
#if defined(XML_SUPPORT)
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "XML")) ? TAB_XML
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // XML_SUPPORT
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "INI")) ? TAB_INI
|
|
|
|
: (!stricmp(type, "VEC")) ? TAB_VEC
|
2017-07-02 22:29:31 +02:00
|
|
|
#if defined(ODBC_SUPPORT)
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "ODBC")) ? TAB_ODBC
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // ODBC_SUPPORT
|
2017-10-15 16:13:23 +02:00
|
|
|
#if defined(JAVA_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "JDBC")) ? TAB_JDBC
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // JAVA_SUPPORT
|
2018-01-30 15:43:20 +01:00
|
|
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "MONGO") && MongoEnabled()) ? TAB_MONGO
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL
|
2013-04-30 16:16:32 +02:00
|
|
|
: (!stricmp(type, "MYPRX")) ? TAB_MYSQL
|
2013-02-12 12:34:14 +01:00
|
|
|
: (!stricmp(type, "DIR")) ? TAB_DIR
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32)
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "MAC")) ? TAB_MAC
|
|
|
|
: (!stricmp(type, "WMI")) ? TAB_WMI
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // _WIN32
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "TBL")) ? TAB_TBL
|
|
|
|
: (!stricmp(type, "XCOL")) ? TAB_XCL
|
|
|
|
: (!stricmp(type, "OCCUR")) ? TAB_OCCUR
|
2013-04-29 13:50:20 +02:00
|
|
|
: (!stricmp(type, "CATLG")) ? TAB_PRX // Legacy
|
|
|
|
: (!stricmp(type, "PROXY")) ? TAB_PRX
|
2013-05-10 20:22:21 +02:00
|
|
|
: (!stricmp(type, "PIVOT")) ? TAB_PIVOT
|
2014-10-31 12:28:07 +01:00
|
|
|
: (!stricmp(type, "VIR")) ? TAB_VIR
|
2015-01-19 18:55:25 +01:00
|
|
|
: (!stricmp(type, "JSON")) ? TAB_JSON
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
: (!stricmp(type, "BSON")) ? TAB_BSON
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2017-07-02 22:29:31 +02:00
|
|
|
#if defined(ZIP_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "ZIP")) ? TAB_ZIP
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // ZIP_SUPPORT
|
2019-08-17 16:58:58 +02:00
|
|
|
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of GetTypeID
|
|
|
|
|
2013-03-07 21:38:00 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return true for table types based on file. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool IsFileType(TABTYPE type)
|
|
|
|
{
|
|
|
|
bool isfile;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2013-03-07 21:38:00 +01:00
|
|
|
case TAB_DOS:
|
|
|
|
case TAB_FIX:
|
|
|
|
case TAB_BIN:
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_CSV:
|
2013-03-07 21:38:00 +01:00
|
|
|
case TAB_FMT:
|
|
|
|
case TAB_DBF:
|
|
|
|
case TAB_XML:
|
2013-03-21 12:16:56 +01:00
|
|
|
case TAB_INI:
|
2013-03-07 21:38:00 +01:00
|
|
|
case TAB_VEC:
|
2015-01-19 18:55:25 +01:00
|
|
|
case TAB_JSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_BSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_REST:
|
|
|
|
// case TAB_ZIP:
|
2013-03-07 21:38:00 +01:00
|
|
|
isfile= true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
isfile= false;
|
|
|
|
break;
|
|
|
|
} // endswitch type
|
|
|
|
|
|
|
|
return isfile;
|
|
|
|
} // end of IsFileType
|
|
|
|
|
2014-02-16 18:05:43 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return true for table types returning exact row count. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool IsExactType(TABTYPE type)
|
|
|
|
{
|
|
|
|
bool exact;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2014-02-16 18:05:43 +01:00
|
|
|
case TAB_FIX:
|
|
|
|
case TAB_BIN:
|
|
|
|
case TAB_DBF:
|
|
|
|
// case TAB_XML: depends on Multiple || Xpand || Coltype
|
2015-01-06 10:18:04 +01:00
|
|
|
// case TAB_JSON: depends on Multiple || Xpand || Coltype
|
2014-02-16 18:05:43 +01:00
|
|
|
case TAB_VEC:
|
2014-10-31 12:28:07 +01:00
|
|
|
case TAB_VIR:
|
2014-02-16 18:05:43 +01:00
|
|
|
exact= true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
exact= false;
|
|
|
|
break;
|
|
|
|
} // endswitch type
|
|
|
|
|
|
|
|
return exact;
|
|
|
|
} // end of IsExactType
|
|
|
|
|
2013-03-17 11:31:11 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return true for table types accepting null fields. */
|
|
|
|
/***********************************************************************/
|
|
|
|
bool IsTypeNullable(TABTYPE type)
|
|
|
|
{
|
|
|
|
bool nullable;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2013-04-10 23:38:27 +02:00
|
|
|
case TAB_MAC:
|
|
|
|
case TAB_DIR:
|
|
|
|
nullable= false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nullable= true;
|
|
|
|
break;
|
|
|
|
} // endswitch type
|
|
|
|
|
2013-03-17 11:31:11 +01:00
|
|
|
return nullable;
|
|
|
|
} // end of IsTypeNullable
|
|
|
|
|
2013-04-03 21:54:02 +02:00
|
|
|
/***********************************************************************/
|
2015-01-06 10:18:04 +01:00
|
|
|
/* Return true for fixed record length tables. */
|
2013-04-03 21:54:02 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
bool IsTypeFixed(TABTYPE type)
|
|
|
|
{
|
|
|
|
bool fix;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2013-04-03 21:54:02 +02:00
|
|
|
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
|
|
|
|
|
2013-12-04 23:53:30 +01:00
|
|
|
/***********************************************************************/
|
2014-04-14 14:26:48 +02:00
|
|
|
/* Return true for table indexable by XINDEX. */
|
2013-12-04 23:53:30 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
bool IsTypeIndexable(TABTYPE type)
|
|
|
|
{
|
|
|
|
bool idx;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2013-12-04 23:53:30 +01:00
|
|
|
case TAB_DOS:
|
|
|
|
case TAB_CSV:
|
|
|
|
case TAB_FMT:
|
|
|
|
case TAB_FIX:
|
|
|
|
case TAB_BIN:
|
|
|
|
case TAB_VEC:
|
|
|
|
case TAB_DBF:
|
2015-01-19 18:55:25 +01:00
|
|
|
case TAB_JSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_BSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2013-12-04 23:53:30 +01:00
|
|
|
idx= true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
idx= false;
|
|
|
|
break;
|
|
|
|
} // endswitch type
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
} // end of IsTypeIndexable
|
|
|
|
|
2014-04-14 14:26:48 +02:00
|
|
|
/***********************************************************************/
|
|
|
|
/* Return index type: 0 NO, 1 XINDEX, 2 REMOTE. */
|
|
|
|
/***********************************************************************/
|
|
|
|
int GetIndexType(TABTYPE type)
|
|
|
|
{
|
|
|
|
int xtyp;
|
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
switch (type) {
|
2014-04-14 14:26:48 +02:00
|
|
|
case TAB_DOS:
|
|
|
|
case TAB_CSV:
|
|
|
|
case TAB_FMT:
|
|
|
|
case TAB_FIX:
|
|
|
|
case TAB_BIN:
|
|
|
|
case TAB_VEC:
|
|
|
|
case TAB_DBF:
|
2015-01-19 18:55:25 +01:00
|
|
|
case TAB_JSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_BSON:
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2014-04-14 14:26:48 +02:00
|
|
|
xtyp= 1;
|
|
|
|
break;
|
|
|
|
case TAB_MYSQL:
|
2015-12-04 22:38:16 +01:00
|
|
|
case TAB_ODBC:
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_JDBC:
|
|
|
|
case TAB_MONGO:
|
|
|
|
xtyp= 2;
|
2014-04-19 17:02:53 +02:00
|
|
|
break;
|
2014-10-31 12:28:07 +01:00
|
|
|
case TAB_VIR:
|
|
|
|
xtyp= 3;
|
|
|
|
break;
|
2014-04-14 14:26:48 +02:00
|
|
|
default:
|
|
|
|
xtyp= 0;
|
|
|
|
break;
|
|
|
|
} // endswitch type
|
|
|
|
|
|
|
|
return xtyp;
|
|
|
|
} // end of GetIndexType
|
|
|
|
|
2013-02-12 12:34:14 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
/* 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
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
/* ------------------------- Class CATALOG --------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* CATALOG Constructor. */
|
|
|
|
/***********************************************************************/
|
|
|
|
CATALOG::CATALOG(void)
|
|
|
|
{
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32)
|
2014-08-23 19:17:15 +02:00
|
|
|
//DataPath= ".\\";
|
2021-06-08 17:44:43 +02:00
|
|
|
#else // !_WIN32
|
2014-08-23 19:17:15 +02:00
|
|
|
//DataPath= "./";
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // !_WIN32
|
2013-02-07 10:34:27 +01:00
|
|
|
memset(&Ctb, 0, sizeof(CURTAB));
|
|
|
|
Cbuf= NULL;
|
|
|
|
Cblen= 0;
|
2019-08-17 16:58:58 +02:00
|
|
|
DefHuge= false;
|
2013-02-07 10:34:27 +01:00
|
|
|
} // end of CATALOG constructor
|
|
|
|
|
|
|
|
/* -------------------------- Class MYCAT ---------------------------- */
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* MYCAT Constructor. */
|
|
|
|
/***********************************************************************/
|
|
|
|
MYCAT::MYCAT(PHC hc) : CATALOG()
|
|
|
|
{
|
2019-08-17 16:58:58 +02:00
|
|
|
Hc= hc;
|
2013-02-07 10:34:27 +01:00
|
|
|
DefHuge= false;
|
|
|
|
} // end of MYCAT constructor
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2013-05-13 12:20:08 +02:00
|
|
|
/* Nothing to do for CONNECT. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
|
|
|
void MYCAT::Reset(void)
|
|
|
|
{
|
|
|
|
} // end of Reset
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* GetTableDesc: retrieve a table descriptor. */
|
2013-05-05 12:45:26 +02:00
|
|
|
/* Look for a table descriptor matching the name and type. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/***********************************************************************/
|
2019-11-16 14:59:54 +01:00
|
|
|
PTABDEF MYCAT::GetTableDesc(PGLOBAL g, PTABLE tablep,
|
2015-05-10 12:14:21 +02:00
|
|
|
LPCSTR type, PRELDEF *)
|
2019-08-17 16:58:58 +02:00
|
|
|
{
|
2019-11-16 14:59:54 +01:00
|
|
|
PTABDEF tdp= NULL;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("GetTableDesc: name=%s am=%s\n", tablep->GetName(), SVP(type));
|
|
|
|
|
|
|
|
// If not specified get the type of this table
|
2019-07-30 22:45:04 +02:00
|
|
|
//if (!type)
|
|
|
|
// type= Hc->GetStringOption("Type","*");
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
tdp= MakeTableDesc(g, tablep, type);
|
|
|
|
|
|
|
|
if (trace(1))
|
|
|
|
htrc("GetTableDesc: tdp=%p\n", tdp);
|
|
|
|
|
|
|
|
return tdp;
|
|
|
|
} // end of GetTableDesc
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* MakeTableDesc: make a table/view description. */
|
|
|
|
/* Note: caller must check if name already exists before calling it. */
|
|
|
|
/***********************************************************************/
|
2019-11-16 14:59:54 +01:00
|
|
|
PTABDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
2013-02-12 12:34:14 +01:00
|
|
|
TABTYPE tc;
|
2019-08-17 16:58:58 +02:00
|
|
|
LPCSTR name= (PSZ)PlugDup(g, tablep->GetName());
|
|
|
|
LPCSTR schema= (PSZ)PlugDup(g, tablep->GetSchema());
|
2019-11-16 14:59:54 +01:00
|
|
|
PTABDEF tdp= NULL;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("MakeTableDesc: name=%s schema=%s am=%s\n",
|
|
|
|
name, SVP(schema), SVP(am));
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
/*********************************************************************/
|
2013-02-12 12:34:14 +01:00
|
|
|
/* Get a unique enum identifier for types. */
|
2013-02-07 10:34:27 +01:00
|
|
|
/*********************************************************************/
|
2019-08-17 16:58:58 +02:00
|
|
|
if (!am) {
|
|
|
|
tc= Hc->GetRealType();
|
|
|
|
am= Hc->GetStringOption("Type","*");
|
|
|
|
} else
|
|
|
|
tc= GetTypeID(am);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
switch (tc) {
|
2013-02-12 12:34:14 +01:00
|
|
|
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;
|
2013-02-07 10:34:27 +01:00
|
|
|
#if defined(XML_SUPPORT)
|
2013-02-12 12:34:14 +01:00
|
|
|
case TAB_XML: tdp= new(g) XMLDEF; break;
|
2013-02-07 10:34:27 +01:00
|
|
|
#endif // XML_SUPPORT
|
2016-11-06 14:57:27 +01:00
|
|
|
#if defined(VCT_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_VEC: tdp= new(g) VCTDEF; break;
|
2016-11-06 14:57:27 +01:00
|
|
|
#endif // VCT_SUPPORT
|
2013-02-07 10:34:27 +01:00
|
|
|
#if defined(ODBC_SUPPORT)
|
2013-02-12 12:34:14 +01:00
|
|
|
case TAB_ODBC: tdp= new(g) ODBCDEF; break;
|
2013-02-07 10:34:27 +01:00
|
|
|
#endif // ODBC_SUPPORT
|
2017-10-15 16:13:23 +02:00
|
|
|
#if defined(JAVA_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_JDBC: tdp= new(g) JDBCDEF; break;
|
2017-10-15 16:13:23 +02:00
|
|
|
#endif // JAVA_SUPPORT
|
2021-06-08 17:44:43 +02:00
|
|
|
#if defined(_WIN32)
|
2013-02-12 12:34:14 +01:00
|
|
|
case TAB_MAC: tdp= new(g) MACDEF; break;
|
|
|
|
case TAB_WMI: tdp= new(g) WMIDEF; break;
|
2021-06-08 17:44:43 +02:00
|
|
|
#endif // _WIN32
|
2013-02-12 12:34:14 +01:00
|
|
|
case TAB_OEM: tdp= new(g) OEMDEF; break;
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_TBL: tdp= new(g) TBLDEF; break;
|
|
|
|
case TAB_XCL: tdp= new(g) XCLDEF; break;
|
|
|
|
case TAB_PRX: tdp= new(g) PRXDEF; break;
|
|
|
|
case TAB_OCCUR: tdp= new(g) OCCURDEF; break;
|
|
|
|
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
|
2013-05-10 20:22:21 +02:00
|
|
|
case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
|
2014-10-31 12:28:07 +01:00
|
|
|
case TAB_VIR: tdp= new(g) VIRDEF; break;
|
2020-12-08 01:15:40 +01:00
|
|
|
case TAB_JSON:
|
|
|
|
#if defined(BSON_SUPPORT)
|
|
|
|
if (Force_Bson())
|
|
|
|
tdp= new(g) BSONDEF;
|
|
|
|
else
|
|
|
|
#endif // BSON_SUPPORT
|
|
|
|
tdp= new(g) JSONDEF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
#if defined(BSON_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_BSON: tdp= new(g) BSONDEF; break;
|
2020-12-08 01:15:40 +01:00
|
|
|
#endif // BSON_SUPPORT
|
2016-12-12 10:57:19 +01:00
|
|
|
#if defined(ZIP_SUPPORT)
|
2020-12-01 19:30:56 +01:00
|
|
|
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
|
2016-12-12 10:57:19 +01:00
|
|
|
#endif // ZIP_SUPPORT
|
2019-07-30 22:45:04 +02:00
|
|
|
#if defined(REST_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_REST: tdp= new (g) RESTDEF; break;
|
2019-07-30 22:45:04 +02:00
|
|
|
#endif // REST_SUPPORT
|
2018-01-30 15:43:20 +01:00
|
|
|
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
|
2019-08-17 16:58:58 +02:00
|
|
|
case TAB_MONGO:
|
|
|
|
if (MongoEnabled()) {
|
|
|
|
tdp = new(g) MGODEF;
|
|
|
|
break;
|
|
|
|
} // endif enabled
|
2021-03-19 21:55:40 +01:00
|
|
|
/* fall through */
|
2018-01-30 15:43:20 +01:00
|
|
|
#endif // JAVA_SUPPORT || CMGO_SUPPORT
|
2019-08-17 16:58:58 +02:00
|
|
|
default:
|
2022-07-19 21:06:55 +02:00
|
|
|
snprintf(g->Message, sizeof(g->Message), MSG(BAD_TABLE_TYPE), am, name);
|
2013-02-07 10:34:27 +01:00
|
|
|
} // endswitch
|
|
|
|
|
2013-04-29 13:50:20 +02:00
|
|
|
// Do make the table/view definition
|
2019-11-16 14:59:54 +01:00
|
|
|
if (tdp && tdp->Define(g, this, name, schema, am))
|
|
|
|
tdp = NULL;
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("Table %s made\n", am);
|
|
|
|
|
2013-02-07 10:34:27 +01:00
|
|
|
return tdp;
|
|
|
|
} // end of MakeTableDesc
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* Initialize a Table Description Block construction. */
|
|
|
|
/***********************************************************************/
|
2013-04-12 18:30:15 +02:00
|
|
|
PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
2019-11-16 14:59:54 +01:00
|
|
|
PTABDEF tdp;
|
2013-02-07 10:34:27 +01:00
|
|
|
PTDB tdbp= NULL;
|
2016-01-09 20:52:17 +01:00
|
|
|
// LPCSTR name= tablep->GetName();
|
2013-02-07 10:34:27 +01:00
|
|
|
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("GetTableDB: name=%s\n", tablep->GetName());
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
// Look for the description of the requested table
|
2016-01-09 20:52:17 +01:00
|
|
|
tdp= GetTableDesc(g, tablep, type);
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
if (tdp) {
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("tdb=%p type=%s\n", tdp, tdp->GetType());
|
|
|
|
|
|
|
|
if (tablep->GetSchema())
|
|
|
|
tdp->Database = SetPath(g, tablep->GetSchema());
|
|
|
|
|
|
|
|
if (trace(2))
|
|
|
|
htrc("Going to get table...\n");
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
tdbp= tdp->GetTable(g, mode);
|
2019-08-17 16:58:58 +02:00
|
|
|
} // endif tdp
|
2013-02-07 10:34:27 +01:00
|
|
|
|
|
|
|
if (tdbp) {
|
2019-08-17 16:58:58 +02:00
|
|
|
if (trace(1))
|
|
|
|
htrc("tdbp=%p name=%s amtype=%d\n", tdbp, tdbp->GetName(),
|
|
|
|
tdbp->GetAmType());
|
2013-02-07 10:34:27 +01:00
|
|
|
tablep->SetTo_Tdb(tdbp);
|
|
|
|
tdbp->SetTable(tablep);
|
2014-07-17 18:13:51 +02:00
|
|
|
tdbp->SetMode(mode);
|
2013-02-07 10:34:27 +01:00
|
|
|
} // endif tdbp
|
|
|
|
|
|
|
|
return (tdbp);
|
|
|
|
} // end of GetTable
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
/* ClearDB: Terminates Database usage. */
|
|
|
|
/***********************************************************************/
|
2015-05-10 12:14:21 +02:00
|
|
|
void MYCAT::ClearDB(PGLOBAL)
|
2013-02-07 10:34:27 +01:00
|
|
|
{
|
|
|
|
} // end of ClearDB
|
|
|
|
|
|
|
|
/* ------------------------ End of MYCAT --------------------------- */
|