Commit d7143a41 authored by Alexander Barkov's avatar Alexander Barkov

Adding the CONNECT storage engine sources.

parent 055b62f4
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if( WITH_WARNINGS )
add_definitions(-Wall -Wfatal-errors -Wextra)
message(STATUS "GCC: All warnings enabled")
else()
add_definitions(--no-warnings)
message(STATUS "GCC: All warnings disabled")
endif()
add_definitions( -DUNIX -DLINUX -DUBUNTU -DMARIADB -DFORCE_INIT_OF_VARS -DMYSQL_DYNAMIC_PLUGIN )
add_definitions( -DHUGE_SUPPORT -DXML_SUPPORT -DMYSQL_SUPPORT -DZIP_SUPPORT -DODBC_SUPPORT )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -fexceptions -fPIC ")
INCLUDE_DIRECTORIES(/usr/include/libxml2)
INCLUDE_DIRECTORIES(/usr/include/i386-linux-gnu)
INCLUDE_DIRECTORIES()
get_property(inc_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
message("inc_dirs = ${inc_dirs}")
SET(CONNECT_PLUGIN_STATIC "connect")
SET(CONNECT_PLUGIN_DYNAMIC "connect")
SET(CONNECT_SOURCES
ha_connect.cc connect.cc user_connect.cc mycat.cc
fmdlex.c inihandl.c osutil.c plugutil.c rcmsg.c
csort.cpp maputil.cpp plgdbutl.cpp
colblk.cpp reldef.cpp tabcol.cpp table.cpp
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
tabodbc.cpp odbconn.cpp
filamzip.cpp tabtbl.cpp myconn.cpp myutil.cpp tabmysql.cpp
tabxml.cpp plgxml.cpp libdoc.cpp)
SET(XML_LIBRARY "-L/usr/lib/i386-linux-gnu -lxml2")
#SET(MYSQL_LIBRARY "-L/usr/local/mysql/lib -lmysqlclient")
#SET(MYSQL_LIBRARY "-L/ ../../libmysql/libmysqlclient.a")
# For static linking
SET(MYSQL_LIBRARY mysqlclient)
# For dynaric linking
#SET(MYSQL_LIBRARY libmysql)
SET(ODBC_LIBRARY "-L/usr/lib -lodbc")
MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
STORAGE_ENGINE MODULE_ONLY
MODULE_OUTPUT_NAME "ha_connect"
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${MYSQL_LIBRARY} ${ODBC_LIBRARY})
/**************** Block H Declares Source Code File (.H) ***************/
/* Name: BLOCK.H Version 2.0 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998 */
/* */
/* This file contains the BLOCK pure virtual class definition. */
/*---------------------------------------------------------------------*/
/* Note: one of the main purpose of this base class is to take care */
/* of the very specific way Plug handles memory allocation. */
/* Instead of allocating small chunks of storage via new or malloc */
/* Plug works in its private memory pool in which it does the sub- */
/* allocation using the function PlugSubAlloc. These are never freed */
/* separately but when a transaction is terminated, the entire pool */
/* is set to empty, resulting in a very fast and efficient allocate */
/* process, no garbage collection problem, and an automatic recovery */
/* procedure (via LongJump) when the memory is exhausted. */
/* For this to work new must be given two parameters, first the */
/* global pointer of the Plug application, and an optional pointer to */
/* the memory pool to use, defaulting to NULL meaning using the Plug */
/* standard default memory pool, example: */
/* tabp = new(g) XTAB("EMPLOYEE"); */
/* allocates a XTAB class object in the standard Plug memory pool. */
/***********************************************************************/
#if !defined(BLOCK_DEFINED)
#define BLOCK_DEFINED
#if defined(WIN32) && !defined(NOEX)
#define DllExport __declspec( dllexport )
#else // !WIN32
#define DllExport
#endif // !WIN32
/***********************************************************************/
/* Definition of class BLOCK with its method function new. */
/***********************************************************************/
typedef class BLOCK *PBLOCK;
class DllExport BLOCK {
public:
void * operator new(size_t size, PGLOBAL g, void *p = NULL) {
#ifdef DEBTRACE
if (debug != NULL)
htrc("New BLOCK: size=%d g=%p p=%p\n", size, g, p);
#endif
return (PlugSubAlloc(g, p, size));
} // end of new
virtual void Print(PGLOBAL, FILE *, uint) {} // Produce file desc
virtual void Print(PGLOBAL, char *, uint) {} // Produce string desc
#if !defined(__BORLANDC__)
// Avoid warning C4291 by defining a matching dummy delete operator
void operator delete(void *, PGLOBAL, void *) {}
#endif
}; // end of class BLOCK
#endif // !BLOCK_DEFINED
/*************** Catalog H Declares Source Code File (.H) **************/
/* Name: CATALOG.H Version 3.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2000-2012 */
/* */
/* This file contains the CATALOG PlugDB classes definitions. */
/***********************************************************************/
#ifndef __CATALOG__H
#define __CATALOG__H
#include "block.h"
/***********************************************************************/
/* Defines the length of a buffer to contain entire table section. */
/***********************************************************************/
#define PLG_MAX_PATH 144 /* Must be the same across systems */
#define PLG_BUFF_LEN 100 /* Number of lines in binary file buffer */
#if !defined(WIN32)
/**************************************************************************/
/* Defines specific to Windows and ODBC. */
/**************************************************************************/
#define SQL_CHAR 1
#define SQL_NUMERIC 2
#define SQL_DECIMAL 3
#define SQL_INTEGER 4
#define SQL_SMALLINT 5
#define SQL_FLOAT 6
#define SQL_REAL 7
#define SQL_DOUBLE 8
#define SQL_TIMESTAMP 11
#define SQL_VARCHAR 12
#define SQL_NULLABLE_UNKNOWN 2
#define SQL_ALL_EXCEPT_LIKE 2
#define SQL_SEARCHABLE 3
#define SQL_ALL_TYPES 0
#define SQL_TABLE_STAT 0
#define SQL_BEST_ROWID 1
#define SQL_PC_NOT_PSEUDO 1
#define SQL_PC_PSEUDO 2
#define SQL_SCOPE_CURROW 0
#endif // !WIN32
//typedef class INDEXDEF *PIXDEF;
/***********************************************************************/
/* Defines the structure used to enumerate tables or views. */
/***********************************************************************/
typedef struct _curtab {
PRELDEF CurTdb;
char *Curp;
char *Tabpat;
bool Ispat;
bool NoView;
int Nt;
char *Type[16];
} CURTAB, *PCURTAB;
/***********************************************************************/
/* Defines the structure used to get column catalog info. */
/***********************************************************************/
typedef struct _colinfo {
char *Name;
int Type;
int Offset;
int Length;
int Key;
int Prec;
int Opt;
char *Remark;
char *Datefmt;
char *Fieldfmt;
ushort Flags; // Used by MariaDB CONNECT handlers
} COLINFO, *PCOLINFO;
/***********************************************************************/
/* CATALOG: base class for catalog classes. */
/***********************************************************************/
class DllExport CATALOG {
friend class RELDEF;
friend class TABDEF;
friend class DIRDEF;
friend class OEMDEF;
public:
CATALOG(void); // Constructor
// Implementation
void *GetDescp(void) {return Descp;}
PRELDEF GetTo_Desc(void) {return To_Desc;}
//PSZ GetDescFile(void) {return DescFile;}
int GetCblen(void) {return Cblen;}
bool GetDefHuge(void) {return DefHuge;}
void SetDefHuge(bool b) {DefHuge = b;}
bool GetSepIndex(void) {return SepIndex;}
void SetSepIndex(bool b) {SepIndex = b;}
char *GetCbuf(void) {return Cbuf;}
char *GetDataPath(void) {return (char*)DataPath;}
// Methods
virtual void Reset(void) {}
virtual void SetDataPath(PGLOBAL g, const char *path) {}
virtual bool GetBoolCatInfo(LPCSTR name, PSZ what, bool bdef) {return bdef;}
virtual bool SetIntCatInfo(LPCSTR name, PSZ what, int ival) {return false;}
virtual int GetIntCatInfo(LPCSTR name, PSZ what, int idef) {return idef;}
virtual int GetSizeCatInfo(LPCSTR name, PSZ what, PSZ sdef) {return 0;}
virtual int GetCharCatInfo(LPCSTR name, PSZ what, PSZ sdef, char *buf, int size)
{strncpy(buf, sdef, size); return size;}
virtual char *GetStringCatInfo(PGLOBAL g, PSZ name, PSZ what, PSZ sdef)
{return sdef;}
virtual int GetColCatInfo(PGLOBAL g, PTABDEF defp) {return -1;}
virtual bool GetIndexInfo(PGLOBAL g, PTABDEF defp) {return true;}
virtual bool CheckName(PGLOBAL g, char *name) {return true;}
virtual bool ClearName(PGLOBAL g, PSZ name) {return true;}
virtual PRELDEF MakeOneTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) {return NULL;}
virtual PRELDEF GetTableDescEx(PGLOBAL g, PTABLE tablep) {return NULL;}
virtual PRELDEF GetTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am,
PRELDEF *prp = NULL) {return NULL;}
virtual PRELDEF GetFirstTable(PGLOBAL g) {return NULL;}
virtual PRELDEF GetNextTable(PGLOBAL g) {return NULL;}
virtual bool TestCond(PGLOBAL g, const char *name, const char *type) {return true;}
virtual bool DropTable(PGLOBAL g, PSZ name, bool erase) {return true;}
virtual PTDB GetTable(PGLOBAL g, PTABLE tablep, MODE mode = MODE_READ) {return NULL;}
virtual void TableNames(PGLOBAL g, char *buffer, int maxbuf, int info[]) {}
virtual void ColumnNames(PGLOBAL g, char *tabname, char *buffer,
int maxbuf, int info[]) {}
virtual void ColumnDefs(PGLOBAL g, char *tabname, char *buffer,
int maxbuf, int info[]) {}
virtual void *DecodeValues(PGLOBAL g, char *tabname, char *colname,
char *buffer, int maxbuf, int info[]) {return NULL;}
virtual int ColumnType(PGLOBAL g, char *tabname, char *colname) {return 0;}
virtual void ClearDB(PGLOBAL g) {}
protected:
virtual bool ClearSection(PGLOBAL g, const char *key, const char *section) {return true;}
virtual PRELDEF MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am) {return NULL;}
// Members
PRELDEF To_Desc; /* To chain of relation desc. */
void *Descp; /* To DB description area */
//AREADEF DescArea; /* Table desc. area size */
char *Cbuf; /* Buffer used for col section */
int Cblen; /* Length of suballoc. buffer */
CURTAB Ctb; /* Used to enumerate tables */
bool DefHuge; /* true: tables default to huge */
bool SepIndex; /* true: separate index files */
//char DescFile[_MAX_PATH]; /* DB description filename */
LPCSTR DataPath; /* Is the Path of DB data dir */
}; // end of class CATALOG
#endif // __CATALOG__H
/************** PlgDBSem H Declares Source Code File (.H) **************/
/* Name: CHKLVL.H Version 1.1 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2009 */
/* */
/* This file contains the definition of the checking level constants. */
/***********************************************************************/
#if !defined(_CHKLVL_DEFINED_)
#define _CHKLVL_DEFINED_
/***********************************************************************/
/* Following definitions are used to indicate the level of checking. */
/***********************************************************************/
enum CHKLVL {CHK_NO = 0x00, /* No checking */
CHK_TYPE = 0x01, /* Check types for Insert/Update */
CHK_UPDATE = 0x02, /* Two pass checking of Update */
CHK_DELETE = 0x04, /* Indexed checking of Delete */
CHK_JOIN = 0x08, /* Check types joining tables */
CHK_OPT = 0x10, /* Automatic optimize on changes */
CHK_MANY = 0x20, /* Check many-to-many joins */
CHK_ALL = 0x3F, /* All of the above */
CHK_STD = 0x1E, /* Standard level of checking */
CHK_MAXRES = 0x40, /* Prevent Maxres recalculation */
CHK_ONLY = 0x100}; /* Just check, no action (NIY) */
/***********************************************************************/
/* Following definitions are used to indicate the execution mode. */
/***********************************************************************/
enum XMOD {XMOD_EXECUTE = 0, /* DOS execution mode */
XMOD_PREPARE = 1, /* Prepare mode */
XMOD_TEST = 2, /* Test mode */
XMOD_CONVERT = 3}; /* HQL conversion mode */
/***********************************************************************/
/* Following definitions indicate the use of a temporay file. */
/***********************************************************************/
enum USETEMP {TMP_AUTO = 0, /* Best choice */
TMP_NO = 1, /* Never */
TMP_YES = 2, /* Always */
TMP_FORCE = 3}; /* Forced for MAP tables */
#endif // _CHKLVL_DEFINED_
This diff is collapsed.
/*************** Colblk H Declares Source Code File (.H) ***************/
/* Name: COLBLK.H Version 1.5 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */
/* */
/* This file contains the COLBLK and derived classes declares. */
/***********************************************************************/
#ifndef __COLBLK__H
#define __COLBLK__H
/***********************************************************************/
/* Include required application header files */
/***********************************************************************/
#include "xobject.h"
#include "reldef.h"
/***********************************************************************/
/* Class COLBLK: Base class for table column descriptors. */
/***********************************************************************/
class DllExport COLBLK : public XOBJECT {
friend class TDBPIVOT;
protected:
// Default constructors used by derived classes
COLBLK(PCOLDEF cdp = NULL, PTDB tdbp = NULL, int i = 0);
COLBLK(PCOL colp, PTDB tdbp = NULL); // Used in copy process
COLBLK(int n) {} // Used when changing a column class in TDBXML
public:
// Implementation
virtual int GetType(void) {return TYPE_COLBLK;}
virtual int GetResultType(void) {return Buf_Type;}
virtual int GetPrecision(void) {return Format.Prec;}
virtual int GetLength(void) {return Long;}
virtual int GetLengthEx(void);
virtual int GetAmType() {return TYPE_AM_ERROR;}
virtual void SetOk(void) {Status |= BUF_EMPTY;}
virtual PTDB GetTo_Tdb(void) {return To_Tdb;}
PCOL GetNext(void) {return Next;}
PSZ GetName(void) {return Name;}
int GetIndex(void) {return Index;}
int GetOpt(void) {return Opt;}
ushort GetColUse(void) {return ColUse;}
ushort GetColUse(ushort u) {return (ColUse & u);}
ushort GetStatus(void) {return Status;}
ushort GetStatus(ushort u) {return (Status & u);}
void SetColUse(ushort u) {ColUse = u;}
void SetStatus(ushort u) {Status = u;}
void AddColUse(ushort u) {ColUse |= u;}
void AddStatus(ushort u) {Status |= u;}
void SetNext(PCOL cp) {Next = cp;}
void SetKcol(PXCOL kcp) {To_Kcol = kcp;}
PCOLDEF GetCdp(void) {return Cdp;}
PSZ GetDomain(void) {return (Cdp) ? Cdp->Decode : NULL;}
PSZ GetDesc(void) {return (Cdp) ? Cdp->Desc : NULL;}
PSZ GetFmt(void) {return (Cdp) ? Cdp->Fmt : NULL;}
// Methods
virtual void Reset(void);
virtual bool Compare(PXOB xp);
virtual bool SetFormat(PGLOBAL, FORMAT&);
virtual int CheckColumn(PGLOBAL g, PSQL sqlp, PXOB &xp, int &ag);
virtual bool IsSpecial(void) {return false;}
virtual int CheckSpcCol(PTDB tdbp, int n) {return 2;}
virtual bool CheckSort(PTDB tdbp);
virtual void MarkCol(ushort bits);
virtual bool Eval(PGLOBAL g);
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
virtual void SetTo_Val(PVAL valp) {}
virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *, uint);
virtual bool VarSize(void) {return false;}
virtual bool IsColInside(PCOL colp) {return this == colp;}
bool InitValue(PGLOBAL g);
protected:
// Members
PCOL Next; // Next column in table
PSZ Name; // Column name
PCOLDEF Cdp; // To column definition block
PTDB To_Tdb; // Points to Table Descriptor Block
PXCOL To_Kcol; // Points to Xindex matching column
int Index; // Column number in table
int Opt; // Cluster/sort information
int Buf_Type; // Data type
int Long; // Internal length in table
FORMAT Format; // Output format
ushort ColUse; // Column usage
ushort Status; // Column read status
}; // end of class COLBLK
/***********************************************************************/
/* Class SPCBLK: Base class for special column descriptors. */
/***********************************************************************/
class SPCBLK : public COLBLK {
public:
// Constructor
SPCBLK(PCOLUMN cp);
// Implementation
virtual int GetAmType(void) = 0;
virtual bool GetRnm(void) {return false;}
// Methods
virtual bool IsSpecial(void) {return true;}
virtual void ReadColumn(PGLOBAL g) = 0;
virtual void WriteColumn(PGLOBAL g);
protected:
// Default constructor not to be used
SPCBLK(void) : COLBLK(1) {}
}; // end of class SPCBLK
/***********************************************************************/
/* Class RIDBLK: ROWID special column descriptor. */
/***********************************************************************/
class RIDBLK : public SPCBLK {
public:
// Constructor
RIDBLK(PCOLUMN cp, bool rnm);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_ROWID;}
virtual bool GetRnm(void) {return Rnm;}
// Methods
virtual void ReadColumn(PGLOBAL g);
protected:
bool Rnm; // False for RowID, True for RowNum
}; // end of class RIDBLK
/***********************************************************************/
/* Class FIDBLK: FILEID special column descriptor. */
/***********************************************************************/
class FIDBLK : public SPCBLK {
public:
// Constructor
FIDBLK(PCOLUMN cp);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_FILID;}
// Methods
virtual void Reset(void) {} // This is a pseudo constant column
virtual int CheckSpcCol(PTDB tdbp, int n)
{return (n == 2 && tdbp == To_Tdb) ? 1 : 2;}
virtual void ReadColumn(PGLOBAL g);
protected:
PSZ Fn; // The current To_File of the table
}; // end of class FIDBLK
/***********************************************************************/
/* Class TIDBLK: TABID special column descriptor. */
/***********************************************************************/
class TIDBLK : public SPCBLK {
public:
// Constructor
TIDBLK(PCOLUMN cp);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_TABID;}
// Methods
virtual void Reset(void) {} // This is a pseudo constant column
virtual int CheckSpcCol(PTDB tdbp, int n)
{return (n == 3 && tdbp == To_Tdb) ? 1 : 2;}
virtual void ReadColumn(PGLOBAL g);
protected:
// Default constructor not to be used
TIDBLK(void) {}
// Members
PSZ Tname; // The current table name
}; // end of class TIDBLK
#endif // __COLBLK__H
This diff is collapsed.
/* Copyright (C) Olivier Bertrand 2004 - 2011
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 */
/**************** Cnt H Declares Source Code File (.H) *****************/
/* Name: CONNECT.H Version 2.4 */
/* This file contains the some based classes declares. */
/***********************************************************************/
//#include "xtable.h" // Base class declares
#include "filamtxt.h"
#include "tabdos.h"
//typedef struct _tabdesc *PTABD; // For friend setting
typedef struct _xinfo *PXF;
typedef struct _create_xinfo *PCXF;
typedef class TDBDOX *PTDBDOX;
/***********************************************************************/
/* Definition of classes XCOLCRT, XIXDEF, XKPDEF, DOXDEF, TDBDOX */
/* These classes purpose is chiefly to access protected items! */
/***********************************************************************/
class XCOLCRT: public COLCRT {
friend class ha_connect;
friend bool CntCreateTable(PGLOBAL, char *, PCXF);
public:
XCOLCRT(PSZ name) : COLCRT(name) {Nulls= -1;} // Constructor
bool HasNulls(void) {return (Nulls != 0);}
private:
int Nulls;
}; // end of class XCOLCRT
class DOXDEF: public DOSDEF {
//friend class TDBDOX;
//friend int MakeIndex(PGLOBAL, PTDB, PIXDEF);
friend int CntIndexInit(PGLOBAL, PTDB, int);
}; // end of class DOXDEF
/***********************************************************************/
/* This is the DOS/UNIX Access Method base class declaration. */
/***********************************************************************/
class TDBDOX: public TDBDOS {
friend int MakeIndex(PGLOBAL, PTDB, PIXDEF);
friend int CntCloseTable(PGLOBAL, PTDB);
friend int CntIndexInit(PGLOBAL, PTDB, int);
friend RCODE CntIndexRead(PGLOBAL, PTDB, OPVAL, const void*, int);
friend RCODE CntDeleteRow(PGLOBAL, PTDB, bool);
friend int CntIndexRange(PGLOBAL, PTDB, const uchar**, uint*,
bool*, key_part_map*);
friend class ha_connect;
}; // end of class TDBDOX
class XKPDEF: public KPARTDEF {
friend class TDBDOX;
friend class ha_connect;
//friend int CntMakeIndex(PGLOBAL, const char *, PIXDEF);
friend int CntIndexInit(PGLOBAL, PTDB, int);
public:
XKPDEF(const char *name, int n) : KPARTDEF((PSZ)name, n) {HasNulls= false;}
void SetNulls(bool b) {HasNulls= b;}
protected:
bool HasNulls; /* Can have null values */
}; // end of class XKPDEF
RCODE CheckRecord(PGLOBAL g, PTDB tdbp, char *oldbuf, char *newbuf);
This diff is collapsed.
/*************** Csort H Declares Source Code File (.H) ****************/
/* Name: CSORT.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2000-2012 */
/* */
/* This file contains the CSORT class declares (not 64-bits ready) */
/* */
/* Note on use of this class: This class is meant to be used as a */
/* base class by the calling class. This is because the comparison */
/* routine must belong to both CSORT and the calling class. */
/* This avoids to pass explicitly to it the calling "this" pointer. */
/***********************************************************************/
#if !defined(CSORT_DEFINED)
#define CSORT_DEFINED
#include <math.h> /* Required for log function */
#undef DOMAIN // Was defined in math.h
/***********************************************************************/
/* Constant and external definitions. */
/***********************************************************************/
#define THRESH 4 /* Threshold for insertion (was 4) */
#define MTHRESH 6 /* Threshold for median */
#ifdef DEBTRACE
extern FILE *debug; /* Debug file */
#endif
typedef int* const CPINT;
/***********************************************************************/
/* This is the CSORT base class declaration. */
/***********************************************************************/
class DllExport CSORT {
public:
// Constructor
CSORT(bool cns, int th = THRESH, int mth = MTHRESH);
protected:
// Implementation
/*********************************************************************/
/* qsortx/qstx are NOT conservative but use less storage space. */
/* qsortc/qstc ARE conservative but use more storage space. */
/*********************************************************************/
int Qsortx(void); /* Index quick/insert sort */
void Qstx(int *base, int *max); /* Preliminary quick sort */
int Qsortc(void); /* Conservative q/ins sort */
void Qstc(int *base, int *max); /* Preliminary quick sort */
void Istc(int *base, int *hi, int *max); /* Insertion sort routine */
public:
// Methods
int Qsort(PGLOBAL g, int n); /* Sort calling routine */
//virtual void Print(PGLOBAL g, FILE *f, uint n);
//virtual void Print(PGLOBAL g, char *ps, uint z);
#ifdef DEBTRACE
int GetNcmp(void) {return num_comp;}
#endif
protected:
// Overridable
virtual int Qcompare(int *, int *) = 0; /* Item compare routine */
#ifdef DEBTRACE
virtual void DebugSort(int ph, int n, int *base, int *mid, int *tmp);
#endif
public:
// Utility
static void SetCmpNum(void)
{for (int i = 1; i < 1000; i++) Cpn[i] = Cmpnum(i); Limit = 1000;}
protected:
static size_t Cmpnum(int n)
#if defined(AIX)
{return (n < Limit) ? Cpn[n]
: (size_t)round(1.0 + (double)n * (log2((double)n) - 1.0));}
#else // !AIX
{return (n < Limit) ? Cpn[n]
: (size_t)(1.5 + (double)n * (log((double)n)/Lg2 - 1.0));}
#endif // !AIX
// Members
static int Limit; /* Size of precalculated array */
static size_t Cpn[1000]; /* Precalculated cmpnum values */
static double Lg2; /* Precalculated log(2) value */
PGLOBAL G;
PDBUSER Dup; /* Used for progress info */
bool Cons; /* true for conservative sort */
int Thresh; /* Threshold for using qsort */
int Mthresh; /* Threshold for median find */
int Nitem; /* Number of items to sort */
MBLOCK Index; /* Index allocation block */
MBLOCK Offset; /* Offset allocation block */
CPINT &Pex; /* Reference to sort index */
CPINT &Pof; /* Reference to offset array */
int *Swix; /* Pointer on EQ/GT work area */
int Savmax; /* Saved ProgMax value */
int Savcur; /* Saved ProgCur value */
LPCSTR Savstep; /* Saved progress step */
#ifdef DEBTRACE
int num_comp; /* Number of quick sort calls */
#endif
}; // end of class CSORT
#endif // CSORT_DEFINED
This diff is collapsed.
/******************************************************************/
/* Declaration of XML document processing using MS DOM */
/* Author: Olivier Bertrand 2007 - 2012 */
/******************************************************************/
#include "plgxml.h"
typedef class DOMDOC *PDOMDOC;
typedef class DOMNODE *PDOMNODE;
typedef class DOMATTR *PDOMATTR;
typedef class DOMNODELIST *PDOMLIST;
/******************************************************************/
/* XML block. Must have the same layout than FBLOCK up to Type. */
/******************************************************************/
typedef struct _xblock { /* Loaded XML file block */
struct _xblock *Next;
LPCSTR Fname; /* Point on file name */
size_t Length; /* Used to tell if read mode */
short Count; /* Nb of times file is used */
short Type; /* TYPE_FB_XML */
int Retcode; /* Return code from Load */
MSXML2::IXMLDOMDocumentPtr Docp;/* Document interface pointer */
//IXMLDOMNodeListPtr Nlist;
} XBLOCK, *PXBLOCK;
/******************************************************************/
/* Declaration of DOM document. */
/******************************************************************/
class DOMDOC : public XMLDOCUMENT {
friend class DOMNODE;
public:
// Constructor
DOMDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp);
// Properties
virtual short GetDocType(void) {return TYPE_FB_XML;}
virtual void *GetDocPtr(void) {return Docp;}
// Methods
virtual bool Initialize(PGLOBAL g);
virtual bool ParseFile(char *fn);
virtual bool NewDoc(PGLOBAL g, char *ver);
virtual void AddComment(PGLOBAL g, char *com);
virtual PXNODE GetRoot(PGLOBAL g);
virtual PXNODE NewRoot(PGLOBAL g, char *name);
virtual PXNODE NewPnode(PGLOBAL g, char *name);
virtual PXATTR NewPattr(PGLOBAL g);
virtual PXLIST NewPlist(PGLOBAL g);
virtual int DumpDoc(PGLOBAL g, char *ofn);
virtual void CloseDoc(PGLOBAL g, PFBLOCK xp);
virtual PFBLOCK LinkXblock(PGLOBAL g, MODE m, int rc, char *fn);
protected:
// Members
MSXML2::IXMLDOMDocumentPtr Docp;
MSXML2::IXMLDOMNodeListPtr Nlist;
HRESULT Hr;
}; // end of class DOMDOC
/******************************************************************/
/* Declaration of DOM XML node. */
/******************************************************************/
class DOMNODE : public XMLNODE {
friend class DOMDOC;
friend class DOMNODELIST;
public:
// Properties
virtual char *GetName(PGLOBAL g);
virtual int GetType(void) {return Nodep->nodeType;}
virtual PXNODE GetNext(PGLOBAL g);
virtual PXNODE GetChild(PGLOBAL g);
// Methods
virtual char *GetText(char *buf, int len);
virtual bool SetContent(PGLOBAL g, char *txtp, int len);
virtual PXNODE Clone(PGLOBAL g, PXNODE np);
virtual PXLIST GetChildElements(PGLOBAL g, char *xp, PXLIST lp);
virtual PXLIST SelectNodes(PGLOBAL g, char *xp, PXLIST lp);
virtual PXNODE SelectSingleNode(PGLOBAL g, char *xp, PXNODE np);
virtual PXATTR GetAttribute(PGLOBAL g, char *name, PXATTR ap);
virtual PXNODE AddChildNode(PGLOBAL g, char *name, PXNODE np);
virtual PXATTR AddProperty(PGLOBAL g, char *name, PXATTR ap);
virtual void AddText(PGLOBAL g, char *txtp);
virtual void DeleteChild(PGLOBAL g, PXNODE dnp);
protected:
// Constructor
DOMNODE(PXDOC dp, MSXML2::IXMLDOMNodePtr np);
// Members
MSXML2::IXMLDOMDocumentPtr Docp;
MSXML2::IXMLDOMNodePtr Nodep;
char Name[64];
WCHAR *Ws;
int Len;
}; // end of class DOMNODE
/******************************************************************/
/* Declaration of DOM XML node list. */
/******************************************************************/
class DOMNODELIST : public XMLNODELIST {
friend class DOMDOC;
friend class DOMNODE;
public:
// Methods
virtual int GetLength(void) {return Listp->length;}
virtual PXNODE GetItem(PGLOBAL g, int n, PXNODE np);
protected:
// Constructor
DOMNODELIST(PXDOC dp, MSXML2::IXMLDOMNodeListPtr lp);
// Members
MSXML2::IXMLDOMNodeListPtr Listp;
}; // end of class DOMNODELIST
/******************************************************************/
/* Declaration of DOM XML attribute. */
/******************************************************************/
class DOMATTR : public XMLATTRIBUTE {
friend class DOMDOC;
friend class DOMNODE;
public:
// Properties
//virtual char *GetText(void);
// Methods
virtual bool SetText(PGLOBAL g, char *txtp, int len);
protected:
// Constructor
DOMATTR(PXDOC dp, MSXML2::IXMLDOMAttributePtr ap);
// Members
MSXML2::IXMLDOMAttributePtr Atrp;
WCHAR *Ws;
int Len;
}; // end of class DOMATTR
This diff is collapsed.
This diff is collapsed.
/*************** FilAMap H Declares Source Code File (.H) **************/
/* Name: FILAMAP.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */
/* */
/* This file contains the MAP file access method classes declares. */
/***********************************************************************/
#ifndef __FILAMAP_H
#define __FILAMAP_H
#include "block.h"
#include "filamtxt.h"
typedef class MAPFAM *PMAPFAM;
/***********************************************************************/
/* This is the variable file access method using file mapping. */
/***********************************************************************/
class DllExport MAPFAM : public TXTFAM {
public:
// Constructor
MAPFAM(PDOSDEF tdp);
MAPFAM(PMAPFAM tmfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_MAP;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) MAPFAM(this);}
// Methods
virtual void Reset(void);
virtual int GetFileLength(PGLOBAL g);
virtual int Cardinality(PGLOBAL g) {return (g) ? -1 : 0;}
virtual int MaxBlkSize(PGLOBAL g, int s) {return s;}
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos);
virtual int SkipRecord(PGLOBAL g, bool header);
virtual bool OpenTableFile(PGLOBAL g);
virtual bool DeferReading(void) {return false;}
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g);
virtual void Rewind(void);
protected:
// Members
char *Memory; // Pointer on file mapping view.
char *Mempos; // Position of next data to read
char *Fpos; // Position of last read record
char *Tpos; // Target Position for delete move
char *Spos; // Start position for delete move
char *Top; // Mark end of file mapping view
}; // end of class MAPFAM
/***********************************************************************/
/* This is the blocked file access method using file mapping. */
/***********************************************************************/
class DllExport MBKFAM : public MAPFAM {
public:
// Constructor
MBKFAM(PDOSDEF tdp);
MBKFAM(PMAPFAM tmfp) : MAPFAM(tmfp) {}
// Implementation
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) MBKFAM(this);}
// Methods
virtual void Reset(void);
virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s)
{return TXTFAM::MaxBlkSize(g, s);}
virtual int GetRowID(void);
virtual int SkipRecord(PGLOBAL g, bool header);
virtual int ReadBuffer(PGLOBAL g);
virtual void Rewind(void);
protected:
// No additional members
}; // end of class MBKFAM
/***********************************************************************/
/* This is the fixed file access method using file mapping. */
/***********************************************************************/
class DllExport MPXFAM : public MBKFAM {
public:
// Constructor
MPXFAM(PDOSDEF tdp);
MPXFAM(PMAPFAM tmfp) : MBKFAM(tmfp) {}
// Implementation
virtual int GetPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) MPXFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g) {return TXTFAM::Cardinality(g);}
virtual int MaxBlkSize(PGLOBAL g, int s)
{return TXTFAM::MaxBlkSize(g, s);}
//virtual int GetRowID(void);
virtual bool SetPos(PGLOBAL g, int recpos);
virtual bool DeferReading(void) {return false;}
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
protected:
// No additional members
}; // end of class MPXFAM
#endif // __FILAMAP_H
This diff is collapsed.
/***************** FilAmDbf H Declares Source Code File (.H) ****************/
/* Name: filamdbf.h Version 1.3 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2012 */
/* */
/* This file contains the DBF file access method classes declares. */
/****************************************************************************/
#ifndef __FILAMDBF_H
#define __FILAMDBF_H
#include "filamfix.h"
#include "filamap.h"
typedef class DBFBASE *PDBF;
typedef class DBFFAM *PDBFFAM;
typedef class DBMFAM *PDBMFAM;
/****************************************************************************/
/* This is the base class for dBASE file access methods. */
/****************************************************************************/
class DllExport DBFBASE {
public:
// Constructors
DBFBASE(PDOSDEF tdp);
DBFBASE(PDBF txfp);
// Implementation
int ScanHeader(PGLOBAL g, PSZ fname, int lrecl, char *defpath);
protected:
// Default constructor, not to be used
DBFBASE(void) {}
// Members
int Records; /* records in the file */
bool Accept; /* true if bad lines are accepted */
int Nerr; /* Number of bad records */
int Maxerr; /* Maximum number of bad records */
int ReadMode; /* 1: ALL 2: DEL 0: NOT DEL */
//PSZ Defpath; /* Default data path */
}; // end of class DBFBASE
/****************************************************************************/
/* This is the DOS/UNIX Access Method class declaration for DBase files. */
/****************************************************************************/
class DllExport DBFFAM : public FIXFAM, public DBFBASE {
public:
// Constructors
DBFFAM(PDOSDEF tdp) : FIXFAM(tdp), DBFBASE(tdp) {}
DBFFAM(PDBFFAM txfp) : FIXFAM(txfp), DBFBASE((PDBF)txfp) {}
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_DBF;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) DBFFAM(this);}
// Methods
virtual int GetNerr(void) {return Nerr;}
virtual int Cardinality(PGLOBAL g);
//virtual int GetRowID(void); // Temporarily suppressed
virtual bool OpenTableFile(PGLOBAL g);
virtual bool AllocateBuffer(PGLOBAL g);
virtual void ResetBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
//virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g);
virtual void Rewind(void);
protected:
// Members
virtual bool CopyHeader(PGLOBAL g);
//int Records; in TXTFAM
//int Headlen; in TXTFAM
}; // end of class DBFFAM
/****************************************************************************/
/* This is the DOS/UNIX Access Method class declaration for DBase files */
/* using file mapping to access the file. */
/****************************************************************************/
class DllExport DBMFAM : public MPXFAM, public DBFBASE {
public:
// Constructors
DBMFAM(PDOSDEF tdp) : MPXFAM(tdp), DBFBASE(tdp) {}
DBMFAM(PDBMFAM txfp) : MPXFAM(txfp), DBFBASE((PDBF)txfp) {}
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_DBF;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) DBMFAM(this);}
virtual int GetDelRows(void);
// Methods
virtual int GetNerr(void) {return Nerr;}
virtual int Cardinality(PGLOBAL g);
//virtual int GetRowID(void); // Temporarily suppressed
virtual bool AllocateBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
//virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void Rewind(void);
protected:
// Members
//int Records; in TXTFAM
//int Headlen; in TXTFAM
}; // end of class DBFFAM
#endif // __FILAMDBF_H
This diff is collapsed.
/************** FilAMFix H Declares Source Code File (.H) **************/
/* Name: FILAMFIX.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005 - 2012 */
/* */
/* This file contains the FIX file access method classes declares. */
/***********************************************************************/
#ifndef __FILAMFIX_H
#define __FILAMFIX_H
#include "filamtxt.h"
typedef class FIXFAM *PFIXFAM;
typedef class BGXFAM *PBGXFAM;
/***********************************************************************/
/* This is the DOS/UNIX Access Method class declaration for standard */
/* files with fixed record format (FIX, BIN) */
/***********************************************************************/
class DllExport FIXFAM : public BLKFAM {
public:
// Constructor
FIXFAM(PDOSDEF tdp);
FIXFAM(PFIXFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_FIX;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) FIXFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g) {return TXTFAM::Cardinality(g);}
virtual int MaxBlkSize(PGLOBAL g, int s)
{return TXTFAM::MaxBlkSize(g, s);}
virtual bool AllocateBuffer(PGLOBAL g);
virtual void ResetBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g);
protected:
virtual bool CopyHeader(PGLOBAL g) {return false;}
virtual bool MoveIntermediateLines(PGLOBAL g, bool *b);
// No additional members
}; // end of class FIXFAM
#if defined(WIN32)
typedef __int64 BIGINT;
#else // !WIN32
typedef off64_t BIGINT;
#define FILE_BEGIN SEEK_SET
#define FILE_CURRENT SEEK_CUR
#define FILE_END SEEK_END
#endif // !WIN32
/***********************************************************************/
/* This is the DOS/UNIX Access Method class declaration for files */
/* that are standard files with columns starting at fixed offset */
/* This class is for fixed formatted files of more than 2 gigabytes. */
/***********************************************************************/
class BGXFAM : public FIXFAM {
public:
// Constructor
BGXFAM(PDOSDEF tdp);
BGXFAM(PBGXFAM txfp);
// Implementation
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) BGXFAM(this);}
// Methods
//virtual void Reset(void);
virtual int Cardinality(PGLOBAL g);
virtual bool OpenTableFile(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g);
virtual void Rewind(void);
protected:
bool BigSeek(PGLOBAL g, HANDLE h, BIGINT pos
, int org = FILE_BEGIN);
int BigRead(PGLOBAL g, HANDLE h, void *inbuf, int req);
bool BigWrite(PGLOBAL g, HANDLE h, void *inbuf, int req);
virtual bool OpenTempFile(PGLOBAL g);
virtual bool MoveIntermediateLines(PGLOBAL g, bool *b = NULL);
// Members
HANDLE Hfile; // Handle(descriptor) to big file
HANDLE Tfile; // Handle(descriptor) to big temp file
//BIGINT Xpos; // Current file position
}; // end of class BGXFAM
#endif // __FILAMFIX_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// MACUTIL.H Olivier Bertrand 2008-2012
// Get Mac Addresses via GetAdaptersInfo
#if defined(WIN32)
#include <iphlpapi.h>
#else // !WIN32
#error This is WIN32 only
#endif // !WIN32
#include "block.h"
typedef class MACINFO *MACIP;
/***********************************************************************/
/* This is the class declaration for MACINFO. */
/***********************************************************************/
class DllExport MACINFO : public BLOCK {
public:
// Constructor
MACINFO(bool adap, bool fix);
// Implementation
int GetNadap(PGLOBAL g);
bool GetMacInfo(PGLOBAL g);
bool GetFixedInfo(PGLOBAL g);
void MakeErrorMsg(PGLOBAL g, DWORD drc);
bool NextMac(void);
bool GetOneInfo(PGLOBAL g, int flag, void *v, int lv);
// Members
FIXED_INFO *Fip; // Points to fixed info structure
PIP_ADAPTER_INFO Piaf; // Points on Adapter info array
PIP_ADAPTER_INFO Curp; // Points on current Adapt info
ULONG Buflen; // Buffer length
bool Fix; // true if FixedInfo is needed
bool Adap; // true if Piaf is needed
int N; // Number of adapters
}; // end of class MACINFO
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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