Commit 4fd74200 authored by Olivier Bertrand's avatar Olivier Bertrand

- Adding 3 new table types:

  PROXY table base on another table. Used by several other types.
  XCOL  proxy on a table having a colummn containing a list of values
  OCCUR proxy on a table having several columns containing the same type
        of values that can be put in a unique column and several rows.
  TBL   Not new but now internally using the PROXY table class.
- Fix 2 bugs in add_field:
        Change '=' to ' ' after the COMMENT keyword.
        Quote column names between '`' in the SQL string.
- Update xml test result to the CONNECT version

added:
  storage/connect/taboccur.cpp
  storage/connect/taboccur.h
  storage/connect/tabutil.cpp
  storage/connect/tabutil.h
  storage/connect/tabxcl.cpp
  storage/connect/tabxcl.h
modified:
  storage/connect/CMakeLists.txt
  storage/connect/ha_connect.cc
  storage/connect/ha_connect.h
  storage/connect/mycat.cc
  storage/connect/myconn.cpp
  storage/connect/mysql-test/connect/r/xml.result
  storage/connect/plgdbsem.h
  storage/connect/tabmysql.cpp
  storage/connect/tabtbl.cpp
  storage/connect/tabtbl.h
  storage/connect/valblk.cpp
  storage/connect/valblk.h
parent bc80fb07
......@@ -25,12 +25,14 @@ filamap.cpp filamdbf.cpp filamfix.cpp filamtxt.cpp filamvct.cpp
tabdos.cpp tabfix.cpp tabfmt.cpp tabmul.cpp tabsys.cpp tabvct.cpp
valblk.cpp value.cpp xindex.cpp xobject.cpp
filamzip.cpp tabtbl.cpp myutil.cpp
tabutil.cpp tabxcl.cpp taboccur.cpp
block.h catalog.h checklvl.h colblk.h connect.h csort.h engmsg.h
filamap.h filamdbf.h filamfix.h filamtxt.h filamvct.h filamzip.h
global.h ha_connect.h maputil.h msgid.h mycat.h myutil.h os.h
osutil.h plgcnx.h plgdbsem.h preparse.h reldef.h resource.h tabcol.h
tabdos.h tabfix.h tabfmt.h tabmul.h tabsys.h tabtbl.h tabvct.h
user_connect.h valblk.h value.h xindex.h xobject.h xtable.h)
user_connect.h valblk.h value.h xindex.h xobject.h xtable.h
tabutil.h tabxcl.h taboccur.h)
#
# Definitions that are shared for all OSes
......
This diff is collapsed.
/* Copyright (C) Olivier Bertrand 2004 - 2011
/* Copyright (C) Olivier Bertrand 2004 - 2013
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -64,6 +64,59 @@ typedef struct ha_field_option_struct FOS, *PFOS;
extern handlerton *connect_hton;
/**
structure for CREATE TABLE options (table options)
These can be specified in the CREATE TABLE:
CREATE TABLE ( ... ) {...here...}
*/
struct ha_table_option_struct {
const char *type;
const char *filename;
const char *optname;
const char *tabname;
const char *tablist;
const char *dbname;
const char *separator;
//const char *connect;
const char *qchar;
const char *module;
const char *subtype;
const char *catfunc;
const char *oplist;
const char *data_charset;
ulonglong lrecl;
ulonglong elements;
//ulonglong estimate;
ulonglong multiple;
ulonglong header;
ulonglong quoted;
ulonglong ending;
ulonglong compressed;
bool mapped;
bool huge;
bool split;
bool readonly;
bool sepindex;
};
/**
structure for CREATE TABLE options (field options)
These can be specified in the CREATE TABLE per field:
CREATE TABLE ( field ... {...here...}, ... )
*/
struct ha_field_option_struct
{
ulonglong offset;
ulonglong freq; // Not used by this version
ulonglong opt; // Not used by this version
ulonglong fldlen;
const char *dateformat;
const char *fieldformat;
char *special;
};
/** @brief
CONNECT_SHARE is a structure that will be shared among all open handlers.
This example implements the minimum of what you will probably need.
......@@ -143,8 +196,7 @@ public:
{
return (HA_NO_TRANSACTIONS | HA_REC_NOT_IN_SEQ | HA_HAS_RECORDS |
HA_NO_AUTO_INCREMENT | HA_NO_PREFIX_CHAR_KEYS |
HA_NO_COPY_ON_ALTER |
HA_CAN_VIRTUAL_COLUMNS |
HA_NO_COPY_ON_ALTER | HA_CAN_VIRTUAL_COLUMNS |
HA_NULL_IN_KEY | HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE);
}
......
......@@ -68,7 +68,10 @@
#include "tabmac.h"
#include "tabwmi.h"
#endif // WIN32
//#include "tabtbl.h"
#include "tabxcl.h"
#include "tabtbl.h"
#include "taboccur.h"
#if defined(XML_SUPPORT)
#include "tabxml.h"
#endif // XML_SUPPORT
......@@ -124,6 +127,10 @@ TABTYPE GetTypeID(const char *type)
: (!stricmp(type, "WMI")) ? TAB_WMI
#endif
: (!stricmp(type, "TBL")) ? TAB_TBL
: (!stricmp(type, "XCOL")) ? TAB_XCL
: (!stricmp(type, "OCCUR")) ? TAB_OCCUR
: (!stricmp(type, "CATLG")) ? TAB_PRX // Legacy
: (!stricmp(type, "PROXY")) ? TAB_PRX
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
} // end of GetTypeID
......@@ -186,7 +193,6 @@ bool IsTypeNullable(TABTYPE type)
break;
} // endswitch type
return nullable;
} // end of IsTypeNullable
......@@ -414,7 +420,7 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
PCOLINFO pcf= (PCOLINFO)PlugSubAlloc(g, NULL, sizeof(COLINFO));
// Get a unique char identifier for type
tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_CATLG;
tc= (defp->Catfunc == FNC_NO) ? GetTypeID(type) : TAB_PRX;
// Take care of the column definitions
i= poff= nof= nlg= 0;
......@@ -443,6 +449,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
case TAB_INI:
case TAB_MAC:
case TAB_TBL:
case TAB_XCL:
case TAB_OCCUR:
case TAB_PRX:
case TAB_OEM:
poff = 0; // Offset represents an independant flag
break;
......@@ -592,7 +601,7 @@ PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name,
// If not specified get the type of this table
if (!type && !(type= Hc->GetStringOption("Type")))
type= "DOS";
type= (Hc->GetStringOption("Tabname")) ? "PROXY" : "DOS";
return MakeTableDesc(g, name, type);
} // end of GetTableDesc
......@@ -636,6 +645,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
#endif // WIN32
case TAB_OEM: tdp= new(g) OEMDEF; break;
case TAB_TBL: tdp= new(g) TBLDEF; break;
case TAB_XCL: tdp= new(g) XCLDEF; break;
case TAB_PRX: tdp= new(g) PRXDEF; break;
case TAB_OCCUR: tdp= new(g) OCCURDEF; break;
#if defined(MYSQL_SUPPORT)
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
#endif // MYSQL_SUPPORT
......@@ -646,7 +658,7 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
sprintf(g->Message, MSG(BAD_TABLE_TYPE), am, name);
} // endswitch
// Do make the table/view definition from XDB file information
// Do make the table/view definition
if (tdp && tdp->Define(g, this, name, am))
tdp= NULL;
......
......@@ -62,6 +62,7 @@ static char *server_groups[] = {
#endif // EMBEDDED
extern "C" int trace;
extern MYSQL_PLUGIN_IMPORT uint mysqld_port;
/************************************************************************/
/* MyColumns: constructs the result blocks containing all columns */
......@@ -90,6 +91,9 @@ PQRYRES MyColumns(PGLOBAL g, const char *host, const char *db,
PCOLRES crp;
MYSQLC myc;
if (!port)
port = mysqld_port;
if (!info) {
/********************************************************************/
/* Open the connection with the MySQL server. */
......
......@@ -507,7 +507,7 @@ DROP TABLE t1;
SET @a=LOAD_FILE('test/t1.xml');
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
<!-- Created by CONNECT Version 1.01.0004 April 10, 2013 -->
<!-- Created by CONNECT Version 1.01.0005 April 27, 2013 -->
<t1>
<line>
<node>ÀÁÂÃ</node>
......
......@@ -69,12 +69,14 @@ enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_WMI = 14, /* WMI tables (Windows only) */
TAB_TBL = 15, /* Collection of CONNECT tables */
TAB_OEM = 16, /* OEM implemented table */
TAB_CATLG = 17, /* Catalog table */
TAB_PLG = 18, /* PLG NIY */
TAB_PIVOT = 19, /* PIVOT NIY */
TAB_JCT = 20, /* Junction tables NIY */
TAB_DMY = 21, /* DMY Dummy tables NIY */
TAB_NIY = 22}; /* Table not implemented yet */
TAB_XCL = 17, /* XCL table */
TAB_OCCUR = 18, /* OCCUR table */
TAB_PRX = 19, /* Proxy (catalog) table */
TAB_PLG = 20, /* PLG NIY */
TAB_PIVOT = 21, /* PIVOT NIY */
TAB_JCT = 22, /* Junction tables NIY */
TAB_DMY = 23, /* DMY Dummy tables NIY */
TAB_NIY = 24}; /* Table not implemented yet */
enum AMT {TYPE_AM_ERROR = 0, /* Type not defined */
TYPE_AM_ROWID = 1, /* ROWID type (special column) */
......
......@@ -63,6 +63,7 @@ void PrintResult(PGLOBAL, PSEM, PQRYRES);
#endif // _CONSOLE
extern "C" int trace;
extern MYSQL_PLUGIN_IMPORT uint mysqld_port;
/* -------------- Implementation of the MYSQLDEF class --------------- */
......@@ -243,10 +244,13 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url)
if ((sport = strchr(Hostname, ':')))
*sport++ = 0;
Portnumber = (sport && sport[0]) ? atoi(sport) : MYSQL_PORT;
Portnumber = (sport && sport[0]) ? atoi(sport) : mysqld_port;
if (Username[0] == 0)
Username = Cat->GetStringCatInfo(g, "User", "*");
if (Hostname[0] == 0)
Hostname = "localhost";
Hostname = Cat->GetStringCatInfo(g, "Host", "localhost");
if (!Database || !*Database)
Database = Cat->GetStringCatInfo(g, "Database", "*");
......@@ -282,9 +286,9 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Database = Cat->GetStringCatInfo(g, "Database", "*");
Tabname = Cat->GetStringCatInfo(g, "Name", Name); // Deprecated
Tabname = Cat->GetStringCatInfo(g, "Tabname", Tabname);
Username = Cat->GetStringCatInfo(g, "User", "root");
Username = Cat->GetStringCatInfo(g, "User", "*");
Password = Cat->GetStringCatInfo(g, "Password", NULL);
Portnumber = Cat->GetIntCatInfo("Port", MYSQL_PORT);
Portnumber = Cat->GetIntCatInfo("Port", mysqld_port);
} else if (ParseURL(g, url))
return TRUE;
......
This diff is collapsed.
// TABOCCUR.H Olivier Bertrand 2013
// Defines the OCCUR tables
#include "tabutil.h"
#define TYPE_AM_OCCUR (AMT)128
typedef class OCCURDEF *POCCURDEF;
typedef class TDBOCCUR *PTDBOCCUR;
typedef class OCCURCOL *POCCURCOL;
typedef class RANKCOL *PRANKCOL;
typedef class SRTCOL *PSRTCOL;
/* -------------------------- OCCUR classes -------------------------- */
/***********************************************************************/
/* OCCUR: OEM table that provides a view of a source table where the */
/* contain of several columns of the source table is placed in only */
/* one column, the OCCUR column, this resulting into several rows. */
/***********************************************************************/
/***********************************************************************/
/* OCCUR table. */
/***********************************************************************/
class OCCURDEF : public PRXDEF { /* Logical table description */
friend class TDBOCCUR;
public:
// Constructor
OCCURDEF(void) {Pseudo = 3; Colist = Xcol = NULL;}
// Implementation
virtual const char *GetType(void) {return "OCCUR";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
//char *Tabname; /* The source table name */
char *Colist; /* The source column list */
char *Xcol; /* The multiple occurence column */
char *Rcol; /* The rank column */
}; // end of OCCURDEF
/***********************************************************************/
/* This is the class declaration for the OCCUR table. */
/***********************************************************************/
class TDBOCCUR : public TDBPRX {
friend class OCCURCOL;
friend class RANKCOL;
friend class SRTCOL;
public:
// Constructor
TDBOCCUR(POCCURDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_OCCUR;}
void SetTdbp(PTDBASE tdbp) {Tdbp = tdbp;}
// Methods
//virtual int GetRecpos(void) {return N;}
virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();}
virtual int RowNumber(PGLOBAL g, bool b = FALSE);
PTDB GetSourceTable(PGLOBAL g);
int MakeColumnList(PGLOBAL g);
// Database routines
//virtual PCOL ColDB(PGLOBAL g, PSZ colname, int num);
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
protected:
// Members
//PTDBASE Tdbp; // To the source table or view
LPCSTR Tabname; // Name of source table
char *Colist; // Source column list
char *Xcolumn; // Occurence column name
char *Rcolumn; // Rank column name
POCCURCOL Xcolp; // To the OCCURCOL column
PCOL *Col; // To source multiple columns
int Mult; // Multiplication factor
int N; // The current table index
int M; // The occurence rank
BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip
}; // end of class TDBOCCUR
/***********************************************************************/
/* Class OCCURCOL: for the multiple occurence column. */
/***********************************************************************/
class OCCURCOL : public COLBLK {
public:
// Constructors
OCCURCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n);
//OCCURCOL(OCCURCOL *colp, PTDB tdbp); // Constructor used in copy process
// Implementation
virtual int GetAmType(void) {return TYPE_AM_OCCUR;}
int GetI(void) {return I;}
// Methods
virtual void Reset(void) {} // Evaluated only by TDBOCCUR
virtual void ReadColumn(PGLOBAL g);
void Xreset(void) {I = 0;};
protected:
// Default constructor not to be used
OCCURCOL(void) {}
// Members
int I;
}; // end of class OCCURCOL
/***********************************************************************/
/* Class RANKCOL: for the multiple occurence column ranking. */
/***********************************************************************/
class RANKCOL : public COLBLK {
public:
// Constructors
RANKCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n) : COLBLK(cdp, tdbp, n) {}
//RANKCOL(RANKCOL *colp, PTDB tdbp); // Constructor used in copy process
// Implementation
virtual int GetAmType(void) {return TYPE_AM_OCCUR;}
// Methods
virtual void ReadColumn(PGLOBAL g);
protected:
// Default constructor not to be used
RANKCOL(void) {}
// Members
}; // end of class RANKCOL
/***********************************************************************/
/* Definition of class XCOLDEF. */
/* This class purpose is just to access COLDEF protected items! */
/***********************************************************************/
class XCOLDEF: public COLDEF {
friend class TDBOCCUR;
}; // end of class XCOLDEF
This diff is collapsed.
/*************** TabTbl H Declares Source Code File (.H) ***************/
/* Name: TABTBL.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2008-2012 */
/* (C) Copyright to the author Olivier BERTRAND 2008-2013 */
/* */
/* This file contains the TDBTBL classes declares. */
/***********************************************************************/
//#include "osutil.h"
#include "block.h"
#include "colblk.h"
#include "tabutil.h"
typedef class TBLDEF *PTBLDEF;
typedef class TDBTBL *PTDBTBL;
typedef class TBLCOL *PTBLCOL;
/***********************************************************************/
/* Defines the structure used for multiple tables. */
/***********************************************************************/
typedef struct _tablist *PTBL;
typedef struct _tablist {
PTBL Next;
char *Name;
char *DB;
} TBLIST;
/***********************************************************************/
/* TBL table. */
/***********************************************************************/
class DllExport TBLDEF : public TABDEF { /* Logical table description */
class DllExport TBLDEF : public PRXDEF { /* Logical table description */
friend class TDBTBL;
friend class TDBTBC;
public:
// Constructor
TBLDEF(void);
// Implementation
virtual const char *GetType(void) {return "TBL";}
PTBL GetTables(void) {return To_Tables;}
//PTABLE GetTables(void) {return Tablep;}
//int GetNtables(void) {return Ntables;}
// Methods
......@@ -44,7 +33,7 @@ class DllExport TBLDEF : public TABDEF { /* Logical table description */
protected:
// Members
PTBL To_Tables; /* To the list of tables */
//PTABLE To_Tables; /* To the list of tables */
bool Accept; /* TRUE if bad tables are accepted */
int Maxerr; /* Maximum number of bad tables */
int Ntables; /* Number of tables */
......@@ -53,50 +42,46 @@ class DllExport TBLDEF : public TABDEF { /* Logical table description */
/***********************************************************************/
/* This is the TBL Access Method class declaration. */
/***********************************************************************/
class DllExport TDBTBL : public TDBASE {
friend class TBLCOL;
class DllExport TDBTBL : public TDBPRX {
//friend class TBLCOL;
friend class TBTBLK;
friend class TDBPLG;
public:
// Constructor
TDBTBL(PTBLDEF tdp = NULL);
//TDBTBL(PTDBTBL tdbp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_TBL;}
//virtual PTDB Duplicate(PGLOBAL g)
// {return (PTDB)new(g) TDBTBL(this);}
// Methods
virtual void ResetDB(void);
//virtual PTABLE GetTablist(void) {return (PSZ)Tablist;}
//virtual PTDB CopyOne(PTABS t);
virtual int GetRecpos(void) {return Rows;}
virtual int GetBadLines(void) {return (int)Nbf;}
// Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual int GetMaxSize(PGLOBAL g);
virtual int GetProgMax(PGLOBAL g);
virtual int GetProgCur(void);
//virtual int GetProgMax(PGLOBAL g);
//virtual int GetProgCur(void);
virtual int RowNumber(PGLOBAL g, bool b = FALSE);
virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL scp);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g);
//virtual int WriteDB(PGLOBAL g);
//virtual int DeleteDB(PGLOBAL g, int irc);
//virtual void CloseDB(PGLOBAL g);
protected:
// Internal functions
PTDB GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp);
//PTDB GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp);
bool InitTableList(PGLOBAL g);
bool TestFil(PGLOBAL g, PFIL filp, PTBL tblp);
bool TestFil(PGLOBAL g, PFIL filp, PTABLE tabp);
// Members
PTABLE Tablist; // Points to the table list
PTABLE CurTable; // Points to the current table
PTDBASE Tdbp; // Current table PTDB
//PTDBASE Tdbp; // Current table PTDB
bool Accept; // TRUE if bad tables are accepted
int Maxerr; // Maximum number of bad tables
int Nbf; // Number of bad connections
......@@ -104,6 +89,7 @@ class DllExport TDBTBL : public TDBASE {
int Crp; // Used for CurPos
}; // end of class TDBTBL
#if 0
/***********************************************************************/
/* Class TBLCOL: TBL access method column descriptor. */
/* This A.M. is used for TBL tables. */
......@@ -136,6 +122,7 @@ class DllExport TBLCOL : public COLBLK {
bool Pseudo; // TRUE for special columns
int Colnum; // Used when retrieving columns by number
}; // end of class TBLCOL
#endif // 0
/***********************************************************************/
/* Class TBTBLK: TDBPLG TABID special column descriptor. */
......
This diff is collapsed.
// TABUTIL.H Olivier Bertrand 2013
// Defines the TAB catalog tables
#ifndef TABUTIL
#define TABUTIL 1
//#include "tabtbl.h"
#define TYPE_AM_PRX (AMT)129
typedef class PRXDEF *PPRXDEF;
typedef class TDBPRX *PTDBPRX;
typedef class XXLCOL *PXXLCOL;
typedef class PRXCOL *PPRXCOL;
typedef class TBCDEF *PTBCDEF;
typedef class TDBTBC *PTDBTBC;
typedef class XTDBASE *PTDBX;
typedef class XCOLBLK *PCOLX;
TABLE_SHARE *GetTableShare(PGLOBAL g, THD *thd, const char *db,
const char *name, bool& mysql);
PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db,
const char *name, bool info);
/***********************************************************************/
/* This class is used to access protected members of TDBASE. */
/***********************************************************************/
class XTDBASE : public TDBASE {
friend class TDBXCL;
}; // end of class XCOLBLK
/***********************************************************************/
/* This class is used to access protected members of COLBLK. */
/***********************************************************************/
class XCOLBLK : public COLBLK {
friend class TDBXCL;
}; // end of class XCOLBLK
/* -------------------------- PROXY classes -------------------------- */
/***********************************************************************/
/* PROXY: table based on another table. Can be used to have a */
/* different view on an existing table. */
/* However, its real use is to be the base of TBL and PRX tables. */
/***********************************************************************/
/***********************************************************************/
/* PRX table. */
/***********************************************************************/
class DllExport PRXDEF : public TABDEF { /* Logical table description */
friend class TDBPRX;
friend class TDBTBC;
public:
// Constructor
PRXDEF(void);
// Implementation
virtual const char *GetType(void) {return "PRX";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE mode);
protected:
// Members
PTABLE Tablep; /* The object table */
}; // end of PRXDEF
/***********************************************************************/
/* This is the class declaration for the XCSV table. */
/***********************************************************************/
class DllExport TDBPRX : public TDBASE {
//friend class MULINDX;
friend class PRXDEF;
friend class PRXCOL;
public:
// Constructor
TDBPRX(PPRXDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_PRX;}
// Methods
virtual int GetRecpos(void) {return Tdbp->GetRecpos();}
virtual void ResetDB(void) {Tdbp->ResetDB();}
virtual int RowNumber(PGLOBAL g, bool b = FALSE);
// Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual bool InitTable(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
virtual int WriteDB(PGLOBAL g);
virtual int DeleteDB(PGLOBAL g, int irc);
virtual void CloseDB(PGLOBAL g) {if (Tdbp) Tdbp->CloseDB(g);}
PTDB GetSubTable(PGLOBAL g, PTABLE tabp);
protected:
// Members
PTDBASE Tdbp; // The object table
}; // end of class TDBPRX
/***********************************************************************/
/* Class PRXCOL: PRX access method column descriptor. */
/* This A.M. is used for PRX tables. */
/***********************************************************************/
class DllExport PRXCOL : public COLBLK {
friend class TDBPRX;
friend class TDBTBL;
public:
// Constructors
PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "PRX");
// Implementation
virtual int GetAmType(void) {return TYPE_AM_PRX;}
// Methods
virtual bool IsSpecial(void) {return Pseudo;}
virtual void ReadColumn(PGLOBAL g);
bool Init(PGLOBAL g);
protected:
// Default constructor not to be used
PRXCOL(void) {}
// Members
PCOL Colp; // Points to matching table column
PVAL To_Val; // To the matching column value
bool Pseudo; // TRUE for special columns
int Colnum; // Used when retrieving columns by number
}; // end of class PRXCOL
#if 0
/***********************************************************************/
/* TBC table. */
/***********************************************************************/
class TBCDEF : public TABDEF {/* Logical table description */
friend class TDBTBC;
friend class ha_connect;
public:
// Constructor
TBCDEF(void) {Database = NULL; Tabname = NULL;}
// Implementation
virtual const char *GetType(void) {return "TBC";}
inline PSZ GetDatabase(void) {return Database;};
inline PSZ GetTabname(void) {return Tabname;}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
PSZ Database; /* Database to be used by server */
PSZ Tabname; /* External table name */
}; // end of TBCDEF
#endif // 0
/***********************************************************************/
/* This is the class declaration for the TBC column catalog table. */
/***********************************************************************/
class TDBTBC : public TDBCAT {
public:
// Constructors
TDBTBC(PPRXDEF tdp);
//TDBTBC(PTBLDEF tdp);
//TDBTBC(PXCLDEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// Members
PSZ Db; // Database of the table
PSZ Tab; // Table name
}; // end of class TDBMCL
#endif // TABUTIL
This diff is collapsed.
// TABXCL.H Olivier Bertrand 2013
// Defines the XCOL tables
#include "tabutil.h"
#define TYPE_AM_XCOL (AMT)124
typedef class XCLDEF *PXCLDEF;
typedef class TDBXCL *PTDBXCL;
typedef class XCLCOL *PXCLCOL;
//pedef class MULINDX *PMINDX;
/* -------------------------- XCOL classes --------------------------- */
/***********************************************************************/
/* XCOL: table having one column containing several values comma */
/* (or any other character) separated. When creating the table, the */
/* name of the X column is given by the NAME option. */
/* This sample has a limitation: */
/* - The X column has the same length than in the physical file. */
/* This tables produces as many rows for a physical row than the */
/* number of items in the X column (eventually 0). */
/***********************************************************************/
/***********************************************************************/
/* XCL table. */
/***********************************************************************/
class XCLDEF : public PRXDEF { /* Logical table description */
friend class TDBXCL;
public:
// Constructor
XCLDEF(void);
// Implementation
virtual const char *GetType(void) {return "XCL";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE mode);
protected:
// Members
char *Xcol; /* The column containing separated fields */
char Sep; /* The field separator, defaults to comma */
int Mult; /* Multiplication factor */
}; // end of XCLDEF
/***********************************************************************/
/* This is the class declaration for the XCSV table. */
/***********************************************************************/
class TDBXCL : public TDBPRX {
//friend class MULINDX;
friend class XCLDEF;
friend class PRXCOL;
friend class XCLCOL;
public:
// Constructor
TDBXCL(PXCLDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_XCOL;}
// Methods
virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();}
virtual int RowNumber(PGLOBAL g, bool b = FALSE);
//virtual bool HaveSame(void) {return RowFlag == 1;}
// Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual bool InitTable(PGLOBAL g);
virtual int GetMaxSize(PGLOBAL g);
virtual bool OpenDB(PGLOBAL g);
virtual int ReadDB(PGLOBAL g);
protected:
// Members
char *Xcolumn; // Multiple column name
PXCLCOL Xcolp; // To the XCVCOL column
int Mult; // Multiplication factor
int N; // The current table index
int M; // The occurence rank
BYTE RowFlag; // 0: Ok, 1: Same, 2: Skip
BOOL New; // TRUE for new line
char Sep; // The Xcol separator
}; // end of class TDBXCL
/***********************************************************************/
/* Class XCLCOL: for the multiple CSV column. */
/***********************************************************************/
class XCLCOL : public PRXCOL {
friend class TDBXCL;
public:
// Constructors
XCLCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
// Methods
virtual void Reset(void) {} // Evaluated only by TDBXCL
virtual void ReadColumn(PGLOBAL g);
protected:
// Default constructor not to be used
XCLCOL(void) {}
// Members
char *Cbuf; // The column buffer
char *Cp; // Pointer to current position
char Sep; // The separator
}; // end of class XCLCOL
#if 0
/* ------------------------- MULINDX classes ------------------------- */
/***********************************************************************/
/* This represents a KINDEX class for an XCOL table. */
/***********************************************************************/
class MULINDX : public KINDEX {
public:
// Constructor
MULINDX(PTDBXCL txlp) : KINDEX(txlp->Tdbp) {Txlp = txlp;}
// Implementation
virtual BOOL HaveSame(void);
// Methods
virtual BOOL Init(PGLOBAL g);
virtual BOOL NextVal(BOOL eq);
virtual int MoreVal(void);
protected:
//Member
PTDBXCL Txlp;
}; // end of class MULINDX
#endif // 0
......@@ -266,7 +266,7 @@ char TYPBLK<char>::GetTypedValue(PVAL valp)
{return valp->GetTinyValue();}
/***********************************************************************/
/* Set one value in a block. */
/* Set one value in a block from a zero terminated string. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValue(PSZ p, int n)
......@@ -294,6 +294,22 @@ double TYPBLK<double>::GetTypedValue(PSZ p) {return atof(p);}
template <>
char TYPBLK<char>::GetTypedValue(PSZ p) {return (char)atoi(p);}
/***********************************************************************/
/* Set one value in a block from an array of characters. */
/***********************************************************************/
template <class TYPE>
void TYPBLK<TYPE>::SetValue(char *sp, uint len, int n)
{
PGLOBAL& g = Global;
PSZ spz = (PSZ)PlugSubAlloc(g, NULL, 0); // Temporary
if (sp)
memcpy(spz, sp, len);
spz[len] = 0;
SetValue(spz, n);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block from a value in another block. */
/***********************************************************************/
......@@ -552,11 +568,19 @@ void CHRBLK::SetValue(PVAL valp, int n)
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/* Set one value in a block from a zero terminated string. */
/***********************************************************************/
void CHRBLK::SetValue(PSZ sp, int n)
{
size_t len = (sp) ? strlen(sp) : 0;
uint len = (sp) ? strlen(sp) : 0;
SetValue(sp, len, n);
} // end of SetValue
/***********************************************************************/
/* Set one value in a block from an array of characters. */
/***********************************************************************/
void CHRBLK::SetValue(char *sp, uint len, int n)
{
char *p = Chrp + n * Long;
#if defined(_DEBUG) || defined(DEBTRACE)
......@@ -568,15 +592,16 @@ void CHRBLK::SetValue(PSZ sp, int n)
#endif
if (sp)
strncpy(p, sp, Long);
else
*p = '\0';
memcpy(p, sp, len);
if (Blanks)
if (Blanks) {
// Suppress eventual ending zero and right fill with blanks
for (register int i = len; i < Long; i++)
p[i] = ' ';
} else if ((signed)len < Long)
p[len] = 0;
SetNull(n, false);
} // end of SetValue
......@@ -801,12 +826,33 @@ void STRBLK::SetValue(PVAL valp, int n)
} // end of SetValue
/***********************************************************************/
/* Set one value in a block. */
/* Set one value in a block from a zero terminated string. */
/***********************************************************************/
void STRBLK::SetValue(PSZ p, int n)
{
Strp[n] = (PSZ)PlugSubAlloc(Global, NULL, strlen(p) + 1);
strcpy(Strp[n], p);
if (p) {
Strp[n] = (PSZ)PlugSubAlloc(Global, NULL, strlen(p) + 1);
strcpy(Strp[n], p);
} else
Strp[n] = NULL;
} // end of SetValue
/***********************************************************************/
/* Set one value in a block from an array of characters. */
/***********************************************************************/
void STRBLK::SetValue(char *sp, uint len, int n)
{
PSZ p;
if (sp) {
p = (PSZ)PlugSubAlloc(Global, NULL, len + 1);
memcpy(p, sp, len);
p[len] = 0;
} else
p = NULL;
Strp[n] = p;
} // end of SetValue
/***********************************************************************/
......
......@@ -64,6 +64,7 @@ class VALBLK : public BLOCK {
virtual void SetValue(double fval, int n) {assert(false);}
virtual void SetValue(char cval, int n) {assert(false);}
virtual void SetValue(PSZ sp, int n) {assert(false);}
virtual void SetValue(char *sp, uint len, int n) {assert(false);}
virtual void SetValue(PVAL valp, int n) = 0;
virtual void SetValue(PVBLK pv, int n1, int n2) = 0;
#if 0
......@@ -120,6 +121,7 @@ class TYPBLK : public VALBLK {
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(char *sp, uint len, int n);
virtual void SetValue(short sval, int n)
{Typp[n] = (TYPE)sval; SetNull(n, false);}
virtual void SetValue(int lval, int n)
......@@ -175,6 +177,7 @@ class CHRBLK : public VALBLK {
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(char *sp, uint len, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
......@@ -221,6 +224,7 @@ class STRBLK : public VALBLK {
// Methods
virtual void SetValue(PSZ sp, int n);
virtual void SetValue(char *sp, uint len, int n);
virtual void SetValue(PVAL valp, int n);
virtual void SetValue(PVBLK pv, int n1, int n2);
//virtual void SetValues(PVBLK pv, int k, int n);
......
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