1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

1) Handling string memory allocation with a new STRING class. This is only

the beginning. Defining the STRING class and begining to use it (MYSQL)

2) Change the xtrace, use_tempfile and exact_info connect variables from
   GLOBAL to SESSION. Remaining GLOBAL variables have been made readonly.

3) Take care of LEX_STRING variables. The .str should not be regarded as
   allways being 0 terminated. This is handled by the Strz functions that
   make sure to return 0 terminated strings.

Bug fix:
- When inserting in MYSQL table with special column(s) a query such as:
insert into t2 values(0,4,'new04'),(0,5,'new05');
failed saying: column id (the special column) not found in t2.
It is now accepted but must be counted in values (these 0 are ignored)
- ROWID was returning row numbers based 0. Now it is from base 1.

modified:
  storage/connect/array.cpp
  storage/connect/blkfil.cpp
  storage/connect/colblk.cpp
  storage/connect/connect.cc
  storage/connect/filamap.cpp
  storage/connect/filamdbf.cpp
  storage/connect/filamfix.cpp
  storage/connect/filamtxt.cpp
  storage/connect/filamvct.cpp
  storage/connect/filamzip.cpp
  storage/connect/filamzip.h
  storage/connect/filter.cpp
  storage/connect/global.h
  storage/connect/ha_connect.cc
  storage/connect/ha_connect.h
  storage/connect/libdoc.cpp
  storage/connect/mycat.cc
  storage/connect/myconn.cpp
  storage/connect/odbconn.cpp
  storage/connect/plgdbutl.cpp
  storage/connect/plugutil.c
  storage/connect/reldef.cpp
  storage/connect/tabcol.cpp
  storage/connect/tabdos.cpp
  storage/connect/tabfix.cpp
  storage/connect/tabfmt.cpp
  storage/connect/table.cpp
  storage/connect/tabmul.cpp
  storage/connect/tabmysql.cpp
  storage/connect/tabmysql.h
  storage/connect/taboccur.cpp
  storage/connect/tabodbc.cpp
  storage/connect/tabpivot.cpp
  storage/connect/tabsys.cpp
  storage/connect/tabtbl.cpp
  storage/connect/tabutil.cpp
  storage/connect/tabvct.cpp
  storage/connect/tabwmi.cpp
  storage/connect/tabwmi.h
  storage/connect/tabxcl.cpp
  storage/connect/tabxml.cpp
  storage/connect/user_connect.cc
  storage/connect/valblk.cpp
  storage/connect/value.cpp
  storage/connect/value.h
  storage/connect/xindex.cpp
  storage/connect/xobject.cpp
  storage/connect/xobject.h
  storage/connect/xtable.h
This commit is contained in:
Olivier Bertrand
2014-10-21 17:29:51 +02:00
parent c65a9fb4c6
commit 56e2771321
49 changed files with 1354 additions and 1235 deletions

View File

@@ -51,11 +51,6 @@
#define ASSERT(B)
#endif
/***********************************************************************/
/* Static variables. */
/***********************************************************************/
extern "C" int trace;
/***********************************************************************/
/* DB static external variables. */
/***********************************************************************/

View File

@@ -39,11 +39,6 @@
#include "array.h" // ARRAY classes dcls
#include "blkfil.h" // Block Filter classes dcls
/***********************************************************************/
/* Static variables. */
/***********************************************************************/
extern "C" int trace;
/* ------------------------ Class BLOCKFILTER ------------------------ */
/***********************************************************************/

View File

@@ -23,8 +23,6 @@
#include "xindex.h"
#include "xtable.h"
extern "C" int trace;
/***********************************************************************/
/* COLBLK protected constructor. */
/***********************************************************************/

View File

@@ -48,11 +48,6 @@
#define my_strlwr(p) my_casedn_str(default_charset_info, (p));
#define my_stricmp(a, b) my_strcasecmp(default_charset_info, (a), (b))
/***********************************************************************/
/* DB static variables. */
/***********************************************************************/
extern "C" int trace;
/***********************************************************************/
/* Routines called internally by semantic routines. */
/***********************************************************************/
@@ -289,7 +284,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
// } else
colp= tdbp->ColDB(g, p, 0);
if (!colp) {
if (!colp && !(mode == MODE_INSERT && tdbp->IsSpecial(p))) {
sprintf(g->Message, "Column %s not found in %s", p, tdbp->GetName());
goto err;
} // endif colp

View File

@@ -46,8 +46,6 @@
#include "filamap.h"
#include "tabdos.h"
extern "C" int trace;
/* --------------------------- Class MAPFAM -------------------------- */
/***********************************************************************/

View File

@@ -63,8 +63,6 @@
#define DBFTYPE 3 /* value of bits 0 and 1 if .dbf */
#define EOH 0x0D /* end-of-header marker in .dbf file */
extern "C" int trace; // The general trace value
/****************************************************************************/
/* First 32 bytes of a .dbf file. */
/* Note: some reserved fields are used here to store info (Fields) */

View File

@@ -52,7 +52,6 @@
#define INVALID_SET_FILE_POINTER 0xFFFFFFFF
#endif
extern "C" int trace;
extern int num_read, num_there, num_eq[2]; // Statistics
/* --------------------------- Class FIXFAM -------------------------- */

View File

@@ -56,7 +56,6 @@
#endif
extern int num_read, num_there, num_eq[2]; // Statistics
extern "C" int trace;
/***********************************************************************/
/* Routine called externally by TXTFAM SortedRows functions. */

View File

@@ -64,7 +64,6 @@
extern int num_read, num_there; // Statistics
static int num_write;
extern "C" int trace;
#if defined(UNIX)
// Add dummy strerror (NGC)

View File

@@ -62,7 +62,6 @@
/* DB static variables. */
/***********************************************************************/
extern int num_read, num_there, num_eq[]; // Statistics
extern "C" int trace;
/* ------------------------------------------------------------------- */

View File

@@ -1,170 +1,170 @@
/************** FilAmZip H Declares Source Code File (.H) **************/
/* Name: FILAMZIP.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
/* */
/* This file contains the GZIP access method classes declares. */
/***********************************************************************/
#ifndef __FILAMZIP_H
#define __FILAMZIP_H
#include "zlib.h"
typedef class ZIPFAM *PZIPFAM;
typedef class ZBKFAM *PZBKFAM;
typedef class ZIXFAM *PZIXFAM;
typedef class ZLBFAM *PZLBFAM;
/***********************************************************************/
/* This is the access method class declaration for not optimized */
/* variable record length files compressed using the gzip library */
/* functions. File is accessed record by record (row). */
/***********************************************************************/
class DllExport ZIPFAM : public TXTFAM {
// friend class DOSCOL;
public:
// Constructor
ZIPFAM(PDOSDEF tdp) : TXTFAM(tdp) {Zfile = NULL; Zpos = 0;}
ZIPFAM(PZIPFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZIP;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZIPFAM(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 bool AllocateBuffer(PGLOBAL g);
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 int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
int Zerror(PGLOBAL g); // GZ error function
// Members
gzFile Zfile; // Points to GZ file structure
z_off_t Zpos; // Uncompressed file position
}; // end of class ZIPFAM
/***********************************************************************/
/* This is the access method class declaration for optimized variable */
/* record length files compressed using the gzip library functions. */
/* The File is accessed by block (requires an opt file). */
/***********************************************************************/
class DllExport ZBKFAM : public ZIPFAM {
public:
// Constructor
ZBKFAM(PDOSDEF tdp);
ZBKFAM(PZBKFAM txfp);
// Implementation
virtual int GetPos(void);
virtual int GetNextPos(void) {return 0;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZBKFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual int SkipRecord(PGLOBAL g, bool header);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
// Members
char *CurLine; // Position of current line in buffer
char *NxtLine; // Position of Next line in buffer
bool Closing; // True when closing on Insert
}; // end of class ZBKFAM
/***********************************************************************/
/* This is the access method class declaration for fixed record */
/* length files compressed using the gzip library functions. */
/* The file is always accessed by block. */
/***********************************************************************/
class DllExport ZIXFAM : public ZBKFAM {
public:
// Constructor
ZIXFAM(PDOSDEF tdp);
ZIXFAM(PZIXFAM txfp) : ZBKFAM(txfp) {}
// Implementation
virtual int GetNextPos(void) {return 0;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZIXFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
protected:
// No additional Members
}; // end of class ZIXFAM
/***********************************************************************/
/* This is the DOS/UNIX Access Method class declaration for PlugDB */
/* fixed/variable files compressed using the zlib library functions. */
/* Physically these are written and read using the same technique */
/* than blocked variable files, only the contain of each block is */
/* compressed using the deflate zlib function. The purpose of this */
/* specific format is to have a fast mechanism for direct access of */
/* records so blocked optimization is fast and direct access (joins) */
/* is allowed. Note that the block length is written ahead of each */
/* block to enable reading when optimization file is not available. */
/***********************************************************************/
class DllExport ZLBFAM : public BLKFAM {
public:
// Constructor
ZLBFAM(PDOSDEF tdp);
ZLBFAM(PZLBFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZLIB;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZLBFAM(this);}
inline void SetOptimized(bool b) {Optimized = b;}
// Methods
virtual int GetFileLength(PGLOBAL g);
/************** FilAmZip H Declares Source Code File (.H) **************/
/* Name: FILAMZIP.H Version 1.2 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 2005-2014 */
/* */
/* This file contains the GZIP access method classes declares. */
/***********************************************************************/
#ifndef __FILAMZIP_H
#define __FILAMZIP_H
#include "zlib.h"
typedef class ZIPFAM *PZIPFAM;
typedef class ZBKFAM *PZBKFAM;
typedef class ZIXFAM *PZIXFAM;
typedef class ZLBFAM *PZLBFAM;
/***********************************************************************/
/* This is the access method class declaration for not optimized */
/* variable record length files compressed using the gzip library */
/* functions. File is accessed record by record (row). */
/***********************************************************************/
class DllExport ZIPFAM : public TXTFAM {
// friend class DOSCOL;
public:
// Constructor
ZIPFAM(PDOSDEF tdp) : TXTFAM(tdp) {Zfile = NULL; Zpos = 0;}
ZIPFAM(PZIPFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZIP;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZIPFAM(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 bool AllocateBuffer(PGLOBAL g);
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
bool WriteCompressedBuffer(PGLOBAL g);
int ReadCompressedBuffer(PGLOBAL g, void *rdbuf);
// Members
z_streamp Zstream; // Compression/decompression stream
Byte *Zbuffer; // Compressed block buffer
int *Zlenp; // Pointer to block length
bool Optimized; // true when opt file is available
}; // end of class ZLBFAM
#endif // __FILAMZIP_H
virtual int SkipRecord(PGLOBAL g, bool header);
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, bool abort);
virtual void Rewind(void);
protected:
int Zerror(PGLOBAL g); // GZ error function
// Members
gzFile Zfile; // Points to GZ file structure
z_off_t Zpos; // Uncompressed file position
}; // end of class ZIPFAM
/***********************************************************************/
/* This is the access method class declaration for optimized variable */
/* record length files compressed using the gzip library functions. */
/* The File is accessed by block (requires an opt file). */
/***********************************************************************/
class DllExport ZBKFAM : public ZIPFAM {
public:
// Constructor
ZBKFAM(PDOSDEF tdp);
ZBKFAM(PZBKFAM txfp);
// Implementation
virtual int GetPos(void);
virtual int GetNextPos(void) {return 0;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZBKFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual int SkipRecord(PGLOBAL g, bool header);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
// Members
char *CurLine; // Position of current line in buffer
char *NxtLine; // Position of Next line in buffer
bool Closing; // True when closing on Insert
}; // end of class ZBKFAM
/***********************************************************************/
/* This is the access method class declaration for fixed record */
/* length files compressed using the gzip library functions. */
/* The file is always accessed by block. */
/***********************************************************************/
class DllExport ZIXFAM : public ZBKFAM {
public:
// Constructor
ZIXFAM(PDOSDEF tdp);
ZIXFAM(PZIXFAM txfp) : ZBKFAM(txfp) {}
// Implementation
virtual int GetNextPos(void) {return 0;}
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZIXFAM(this);}
// Methods
virtual int Cardinality(PGLOBAL g);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
protected:
// No additional Members
}; // end of class ZIXFAM
/***********************************************************************/
/* This is the DOS/UNIX Access Method class declaration for PlugDB */
/* fixed/variable files compressed using the zlib library functions. */
/* Physically these are written and read using the same technique */
/* than blocked variable files, only the contain of each block is */
/* compressed using the deflate zlib function. The purpose of this */
/* specific format is to have a fast mechanism for direct access of */
/* records so blocked optimization is fast and direct access (joins) */
/* is allowed. Note that the block length is written ahead of each */
/* block to enable reading when optimization file is not available. */
/***********************************************************************/
class DllExport ZLBFAM : public BLKFAM {
public:
// Constructor
ZLBFAM(PDOSDEF tdp);
ZLBFAM(PZLBFAM txfp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_ZLIB;}
virtual int GetPos(void);
virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g)
{return (PTXF)new(g) ZLBFAM(this);}
inline void SetOptimized(bool b) {Optimized = b;}
// Methods
virtual int GetFileLength(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos);
virtual bool AllocateBuffer(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g);
virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void);
protected:
bool WriteCompressedBuffer(PGLOBAL g);
int ReadCompressedBuffer(PGLOBAL g, void *rdbuf);
// Members
z_streamp Zstream; // Compression/decompression stream
Byte *Zbuffer; // Compressed block buffer
int *Zlenp; // Pointer to block length
bool Optimized; // true when opt file is available
}; // end of class ZLBFAM
#endif // __FILAMZIP_H

View File

@@ -39,11 +39,6 @@
//#include "select.h"
#include "xindex.h"
/***********************************************************************/
/* Static variables. */
/***********************************************************************/
extern "C" int trace;
/***********************************************************************/
/* Utility routines. */
/***********************************************************************/

View File

@@ -46,6 +46,11 @@
#define CRLF 1
#endif // !WIN32
/***********************************************************************/
/* Define access to the thread based trace value. */
/***********************************************************************/
#define trace GetTraceValue()
/***********************************************************************/
/* Miscellaneous Constants */
/***********************************************************************/
@@ -255,6 +260,7 @@ DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
DllExport char *PlugDup(PGLOBAL g, const char *str);
DllExport void *MakePtr(void *, OFFSET);
DllExport void htrc(char const *fmt, ...);
DllExport int GetTraceValue(void);
#if defined(__cplusplus)
} // extern "C"

File diff suppressed because it is too large Load Diff

View File

@@ -26,6 +26,8 @@
#pragma interface /* gcc class implementation */
#endif
static char *strz(PGLOBAL g, LEX_STRING &ls);
/****************************************************************************/
/* Structures used to pass info between CONNECT and ha_connect. */
/****************************************************************************/
@@ -177,13 +179,16 @@ class ha_connect: public handler
protected:
char *PlugSubAllocStr(PGLOBAL g, void *memp, const char *str, size_t length)
{
char *ptr;
if (!(ptr= (char*) PlugSubAlloc(g, memp, length + 1)))
return NULL;
memcpy(ptr, str, length);
ptr[length]= '\0';
char *ptr= (char*)PlgDBSubAlloc(g, memp, length + 1);
if (ptr) {
memcpy(ptr, str, length);
ptr[length]= '\0';
} // endif ptr
return ptr;
}
} // end of PlugSubAllocStr
public:
ha_connect(handlerton *hton, TABLE_SHARE *table_arg);
~ha_connect();
@@ -235,6 +240,8 @@ public:
uint key_len= 0);
bool MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q,
const void *key, int klen);
inline char *Strz(LEX_STRING &ls);
/** @brief
The name that will be used for display purposes.

View File

@@ -180,7 +180,6 @@ class XML2ATTR : public XMLATTRIBUTE {
extern "C" {
extern char version[];
extern int trace;
} // "C"
#if defined(MEMORY_TRACE)

View File

@@ -98,8 +98,6 @@
extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // !WIN32
extern "C" int trace;
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
/***********************************************************************/

View File

@@ -46,11 +46,11 @@
#include "plgcnx.h" // For DB types
#include "resource.h"
//#include "value.h"
#include "valblk.h"
//#include "valblk.h"
#include "xobject.h"
#define DLL_EXPORT // Items are exported from this DLL
#include "myconn.h"
extern "C" int trace;
extern "C" int zconv;
extern MYSQL_PLUGIN_IMPORT uint mysqld_port;
extern MYSQL_PLUGIN_IMPORT char *mysqld_unix_port;
@@ -135,7 +135,7 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
FLD_REM, FLD_NO, FLD_DEFAULT, FLD_EXTRA,
FLD_CHARSET};
unsigned int length[] = {0, 4, 16, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0};
char *fld, *colname, *chset, *fmt, v, cmd[128], uns[16], zero[16];
char *fld, *colname, *chset, *fmt, v, buf[128], uns[16], zero[16];
int i, n, nf, ncol = sizeof(buftyp) / sizeof(int);
int len, type, prec, rc, k = 0;
PQRYRES qrp;
@@ -155,16 +155,26 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
/********************************************************************/
/* Do an evaluation of the result size. */
/********************************************************************/
sprintf(cmd, "SHOW FULL COLUMNS FROM %s", table);
strcat(strcat(cmd, " FROM "), (db) ? db : PlgGetUser(g)->DBName);
STRING cmd(g, 64, "SHOW FULL COLUMNS FROM ");
bool b = cmd.Append((PSZ)table);
if (colpat)
strcat(strcat(cmd, " LIKE "), colpat);
b |= cmd.Append(" FROM ");
b |= cmd.Append((PSZ)(db ? db : PlgGetUser(g)->DBName));
if (colpat) {
b |= cmd.Append(" LIKE ");
b |= cmd.Append((PSZ)colpat);
} // endif colpat
if (b) {
strcpy(g->Message, "Out of memory");
return NULL;
} // endif b
if (trace)
htrc("MyColumns: cmd='%s'\n", cmd);
if ((n = myc.GetResultSize(g, cmd)) < 0) {
if ((n = myc.GetResultSize(g, cmd.GetStr())) < 0) {
myc.Close();
return NULL;
} // endif n
@@ -225,15 +235,15 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
*uns = 0;
*zero = 0;
switch ((nf = sscanf(fld, "%[^(](%d,%d", cmd, &len, &prec))) {
switch ((nf = sscanf(fld, "%[^(](%d,%d", buf, &len, &prec))) {
case 3:
nf = sscanf(fld, "%[^(](%d,%d) %s %s", cmd, &len, &prec, uns, zero);
nf = sscanf(fld, "%[^(](%d,%d) %s %s", buf, &len, &prec, uns, zero);
break;
case 2:
nf = sscanf(fld, "%[^(](%d) %s %s", cmd, &len, uns, zero) + 1;
nf = sscanf(fld, "%[^(](%d) %s %s", buf, &len, uns, zero) + 1;
break;
case 1:
nf = sscanf(fld, "%s %s %s", cmd, uns, zero) + 2;
nf = sscanf(fld, "%s %s %s", buf, uns, zero) + 2;
break;
default:
sprintf(g->Message, MSG(BAD_FIELD_TYPE), fld);
@@ -241,16 +251,16 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
return NULL;
} // endswitch nf
if ((type = MYSQLtoPLG(cmd, &v)) == TYPE_ERROR) {
if ((type = MYSQLtoPLG(buf, &v)) == TYPE_ERROR) {
if (v == 'K') {
// Skip this column
sprintf(g->Message, "Column %s skipped (unsupported type %s)",
colname, cmd);
colname, buf);
PushWarning(g, thd);
continue;
} // endif v
sprintf(g->Message, "Column %s unsupported type %s", colname, cmd);
sprintf(g->Message, "Column %s unsupported type %s", colname, buf);
myc.Close();
return NULL;
} else if (type == TYPE_STRING) {
@@ -276,11 +286,11 @@ PQRYRES MyColumns(PGLOBAL g, THD *thd, const char *host, const char *db,
} // endswitch nf
crp = crp->Next; // Type_Name
crp->Kdata->SetValue(cmd, i);
crp->Kdata->SetValue(buf, i);
if (type == TYPE_DATE) {
// When creating tables we do need info about date columns
fmt = MyDateFmt(cmd);
fmt = MyDateFmt(buf);
len = strlen(fmt);
} else
fmt = NULL;

View File

@@ -64,8 +64,6 @@ extern "C" HINSTANCE s_hModule; // Saved module handle
#define DEBUG_ONLY(f) ((void)0)
#endif // !_DEBUG
extern "C" int trace;
/***********************************************************************/
/* GetSQLType: returns the SQL_TYPE corresponding to a PLG type. */
/***********************************************************************/

View File

@@ -90,7 +90,6 @@ extern "C" {
#if defined(XMSG)
char msglang[16] = "ENGLISH"; // Default language
#endif
extern int trace;
extern char version[];
} // extern "C"

View File

@@ -81,8 +81,6 @@
extern HINSTANCE s_hModule; /* Saved module handle */
#endif // WIN32
extern int trace;
#if defined(XMSG)
extern char msglang[];
#endif // XMSG

View File

@@ -49,13 +49,15 @@
#include "tabmul.h"
#include "ha_connect.h"
extern "C" int trace;
extern "C" USETEMP Use_Temp;
#if !defined(WIN32)
extern handlerton *connect_hton;
#endif // !WIN32
/***********************************************************************/
/* External function. */
/***********************************************************************/
USETEMP UseTemp(void);
/* --------------------------- Class RELDEF -------------------------- */
/***********************************************************************/
@@ -591,7 +593,7 @@ PTDB OEMDEF::GetTable(PGLOBAL g, MODE mode)
PTXF txfp = NULL;
PDOSDEF defp = (PDOSDEF)Pxdef;
bool map = defp->Mapped && mode != MODE_INSERT &&
!(Use_Temp == TMP_FORCE &&
!(UseTemp() == TMP_FORCE &&
(mode == MODE_UPDATE || mode == MODE_DELETE));
int cmpr = defp->Compressed;

View File

@@ -22,8 +22,6 @@
#include "xtable.h"
#include "tabcol.h"
extern "C" int trace;
/***********************************************************************/
/* XTAB public constructor. */
/***********************************************************************/

View File

@@ -65,15 +65,17 @@
/***********************************************************************/
int num_read, num_there, num_eq[2]; // Statistics
extern "C" int trace;
extern "C" USETEMP Use_Temp;
extern bool xinfo;
/***********************************************************************/
/* Size of optimize file header. */
/***********************************************************************/
#define NZ 4
/***********************************************************************/
/* External function. */
/***********************************************************************/
bool ExactInfo(void);
USETEMP UseTemp(void);
/***********************************************************************/
/* Min and Max blocks contains zero ended fields (blank = false). */
/* No conversion of block values (check = true). */
@@ -316,7 +318,7 @@ bool DOSDEF::InvalidateIndex(PGLOBAL g)
PTDB DOSDEF::GetTable(PGLOBAL g, MODE mode)
{
// Mapping not used for insert
USETEMP tmp = Use_Temp;
USETEMP tmp = UseTemp();
bool map = Mapped && mode != MODE_INSERT &&
!(tmp != TMP_NO && Recfm == RECFM_VAR
&& mode == MODE_UPDATE) &&
@@ -1905,7 +1907,7 @@ int TDBDOS::Cardinality(PGLOBAL g)
} // endif Mode
if (Mode == MODE_ANY && xinfo) {
if (Mode == MODE_ANY && ExactInfo()) {
// Using index impossible or failed, do it the hard way
Mode = MODE_READ;
To_Line = (char*)PlugSubAlloc(g, NULL, Lrecl + 1);
@@ -2018,8 +2020,10 @@ int TDBDOS::EstimatedLength(PGLOBAL g)
/***********************************************************************/
bool TDBDOS::IsUsingTemp(PGLOBAL g)
{
return (Use_Temp == TMP_YES || Use_Temp == TMP_FORCE ||
(Use_Temp == TMP_AUTO && Mode == MODE_UPDATE));
USETEMP utp = UseTemp();
return (utp == TMP_YES || utp == TMP_FORCE ||
(utp == TMP_AUTO && Mode == MODE_UPDATE));
} // end of IsUsingTemp
/***********************************************************************/
@@ -2059,7 +2063,7 @@ bool TDBDOS::OpenDB(PGLOBAL g)
Txfp = new(g) DOSFAM((PDOSDEF)To_Def);
Txfp->SetTdbp(this);
} else if (Txfp->Blocked && (Mode == MODE_DELETE ||
(Mode == MODE_UPDATE && Use_Temp != TMP_NO))) {
(Mode == MODE_UPDATE && UseTemp() != TMP_NO))) {
/*******************************************************************/
/* Delete is not currently handled in block mode neither Update */
/* when using a temporary file. */

View File

@@ -51,13 +51,15 @@
/***********************************************************************/
/* DB static variables. */
/***********************************************************************/
extern "C" int trace;
extern "C" USETEMP Use_Temp;
extern int num_read, num_there, num_eq[2]; // Statistics
static const longlong M2G = 0x80000000;
static const longlong M4G = (longlong)2 * M2G;
/***********************************************************************/
/* External function. */
/***********************************************************************/
USETEMP UseTemp(void);
/* ------------------------------------------------------------------- */
/***********************************************************************/
@@ -273,9 +275,9 @@ bool TDBFIX::IsUsingTemp(PGLOBAL g)
{
// Not ready yet to handle using a temporary file with mapping
// or while deleting from DBF files.
return ((Use_Temp == TMP_YES && Txfp->GetAmType() != TYPE_AM_MAP &&
return ((UseTemp() == TMP_YES && Txfp->GetAmType() != TYPE_AM_MAP &&
!(Mode == MODE_DELETE && Txfp->GetAmType() == TYPE_AM_DBF)) ||
Use_Temp == TMP_FORCE || Use_Temp == TMP_TEST);
UseTemp() == TMP_FORCE || UseTemp() == TMP_TEST);
} // end of IsUsingTemp
/***********************************************************************/
@@ -307,7 +309,7 @@ bool TDBFIX::OpenDB(PGLOBAL g)
} // endif use
if (Mode == MODE_DELETE && Txfp->GetAmType() == TYPE_AM_MAP &&
(!Next || Use_Temp == TMP_FORCE)) {
(!Next || UseTemp() == TMP_FORCE)) {
// Delete all lines or using temp. Not handled in MAP mode
Txfp = new(g) FIXFAM((PDOSDEF)To_Def);
Txfp->SetTdbp(this);

View File

@@ -66,8 +66,10 @@
#define MAXCOL 200 /* Default max column nb in result */
#define TYPE_UNKNOWN 10 /* Must be greater than other types */
extern "C" int trace;
extern "C" USETEMP Use_Temp;
/***********************************************************************/
/* External function. */
/***********************************************************************/
USETEMP UseTemp(void);
/***********************************************************************/
/* CSVColumns: constructs the result blocks containing the description */
@@ -446,7 +448,7 @@ PTDB CSVDEF::GetTable(PGLOBAL g, MODE mode)
PTDBASE tdbp;
if (Catfunc != FNC_COL) {
USETEMP tmp = Use_Temp;
USETEMP tmp = UseTemp();
bool map = Mapped && mode != MODE_INSERT &&
!(tmp != TMP_NO && mode == MODE_UPDATE) &&
!(tmp == TMP_FORCE &&

View File

@@ -28,8 +28,6 @@
int TDB::Tnum = 0;
extern "C" int trace; // The general trace value
/***********************************************************************/
/* Utility routines. */
/***********************************************************************/
@@ -192,6 +190,18 @@ PSZ TDBASE::GetPath(void)
return To_Def->GetPath();
} // end of GetPath
/***********************************************************************/
/* Return true if name is a special column of this table. */
/***********************************************************************/
bool TDBASE::IsSpecial(PSZ name)
{
for (PCOLDEF cdp = To_Def->GetCols(); cdp; cdp = cdp->GetNext())
if (!stricmp(cdp->GetName(), name) && (cdp->Flags & U_SPECIAL))
return true; // Special column to ignore while inserting
return false; // Not found or not special or not inserting
} // end of IsSpecial
/***********************************************************************/
/* Initialize TDBASE based column description block construction. */
/* name is used to call columns by name. */

View File

@@ -68,8 +68,6 @@
#include "tabdos.h" // TDBDOS and DOSCOL class dcls
#include "tabmul.h" // TDBMUL and MULCOL classes dcls
extern "C" int trace;
/* ------------------------- Class TDBMUL ---------------------------- */
/***********************************************************************/

View File

@@ -67,13 +67,15 @@
void PrintResult(PGLOBAL, PSEM, PQRYRES);
#endif // _CONSOLE
extern "C" int trace;
extern bool xinfo;
// Used to check whether a MYSQL table is created on itself
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, const char *host,
const char *db, char *tab, const char *src, int port);
/***********************************************************************/
/* External function. */
/***********************************************************************/
bool ExactInfo(void);
/* -------------- Implementation of the MYSQLDEF class --------------- */
/***********************************************************************/
@@ -430,7 +432,6 @@ TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp)
Bind = NULL;
Query = NULL;
Qbuf = NULL;
Fetched = false;
m_Rc = RC_FX;
AftRows = 0;
@@ -454,7 +455,6 @@ TDBMYSQL::TDBMYSQL(PGLOBAL g, PTDBMY tdbp) : TDBASE(tdbp)
Delayed = tdbp->Delayed;
Bind = NULL;
Query = tdbp->Query;
Qbuf = NULL;
Fetched = tdbp->Fetched;
m_Rc = tdbp->m_Rc;
AftRows = tdbp->AftRows;
@@ -495,9 +495,10 @@ PCOL TDBMYSQL::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
/***********************************************************************/
bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
{
char *tk = "`";
//char *tk = "`";
char tk = '`';
int len = 0, rank = 0;
bool b = false;
bool b = false, oom = false;
PCOL colp;
//PDBUSER dup = PlgGetUser(g);
@@ -505,27 +506,24 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
return false; // already done
if (Srcdef) {
Query = Srcdef;
Query = new(g)STRING(g, 0, Srcdef);
return false;
} // endif Srcdef
//Find the address of the suballocated query
Query = (char*)PlugSubAlloc(g, NULL, 0);
strcpy(Query, "SELECT ");
// Allocate the string used to contain Query
Query = new(g) STRING(g, 1023, "SELECT ");
if (Columns) {
for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) {
// if (colp->IsSpecial()) {
// strcpy(g->Message, MSG(NO_SPEC_COL));
// return true;
// } else {
if (b)
strcat(Query, ", ");
oom |= Query->Append(", ");
else
b = true;
strcat(strcat(strcat(Query, tk), colp->GetName()), tk);
oom |= Query->Append(tk);
oom |= Query->Append(colp->GetName());
oom |= Query->Append(tk);
((PMYCOL)colp)->Rank = rank++;
} // endif colp
@@ -534,27 +532,38 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
// Query count(*) from... for which we will count the rows from
// Query '*' from...
// (the use of a char constant minimize the result storage)
strcat(Query, (Isview) ? "*" : "'*'");
if (Isview)
oom |= Query->Append('*');
else
oom |= Query->Append("'*'");
} // endif ncol
strcat(strcat(strcat(strcat(Query, " FROM "), tk), Tabname), tk);
len = strlen(Query);
oom |= Query->Append(" FROM ");
oom |= Query->Append(tk);
oom |= Query->Append(Tabname);
oom |= Query->Append(tk);
len = Query->GetLength();
if (To_CondFil) {
if (!mx) {
strcat(strcat(Query, " WHERE "), To_CondFil->Body);
len = strlen(Query) + 1;
oom |= Query->Append(" WHERE ");
oom |= Query->Append(To_CondFil->Body);
len = Query->GetLength() + 1;
} else
len += (strlen(To_CondFil->Body) + 256);
} else
len += (mx ? 256 : 1);
if (trace)
htrc("Query=%s\n", Query);
if (oom || Query->Resize(len)) {
strcpy(g->Message, "MakeSelect: Out of memory");
return true;
} // endif oom
if (trace)
htrc("Query=%s\n", Query->GetStr());
// Now we know how much to suballocate
PlugSubAlloc(g, NULL, len);
return false;
} // end of MakeSelect
@@ -563,81 +572,82 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g, bool mx)
/***********************************************************************/
bool TDBMYSQL::MakeInsert(PGLOBAL g)
{
char *colist, *valist = NULL;
char *tk = "`";
int len = 0, qlen = 0;
bool b = false;
uint len = 0;
bool b = false, oom;
PCOL colp;
if (Query)
return false; // already done
for (colp = Columns; colp; colp = colp->GetNext())
if (!colp->IsSpecial()) {
// if (colp->IsSpecial()) {
// strcpy(g->Message, MSG(NO_SPEC_COL));
// return true;
// } else {
len += (strlen(colp->GetName()) + 4);
((PMYCOL)colp)->Rank = Nparm++;
} // endif colp
colist = (char*)PlugSubAlloc(g, NULL, len);
*colist = '\0';
if (Prep) {
#if defined(MYSQL_PREPARED_STATEMENTS)
valist = (char*)PlugSubAlloc(g, NULL, 2 * Nparm);
*valist = '\0';
#else // !MYSQL_PREPARED_STATEMENTS
#if !defined(MYSQL_PREPARED_STATEMENTS)
strcpy(g->Message, "Prepared statements not used (not supported)");
PushWarning(g, this);
Prep = false;
#endif // !MYSQL_PREPARED_STATEMENTS
} // endif Prep
for (colp = Columns; colp; colp = colp->GetNext()) {
if (b) {
strcat(colist, ", ");
if (Prep) strcat(valist, ",");
} else
b = true;
for (colp = Columns; colp; colp = colp->GetNext())
if (colp->IsSpecial()) {
strcpy(g->Message, MSG(NO_SPEC_COL));
return true;
} else {
len += (strlen(colp->GetName()) + 4);
strcat(strcat(strcat(colist, tk), colp->GetName()), tk);
// Parameter marker
if (!Prep) {
if (colp->GetResultType() == TYPE_DATE)
len += 20;
else
len += colp->GetLength();
} else
len += 2;
// Parameter marker
if (!Prep) {
if (colp->GetResultType() == TYPE_DATE)
qlen += 20;
else
qlen += colp->GetLength();
} else // Prep
strcat(valist, "?");
} // endfor colp
((PMYCOL)colp)->Rank = Nparm++;
} // endif colp
// Below 40 is enough to contain the fixed part of the query
len = (strlen(Tabname) + strlen(colist)
+ ((Prep) ? strlen(valist) : 0) + 40);
Query = (char*)PlugSubAlloc(g, NULL, len);
len += (strlen(Tabname) + 40);
Query = new(g) STRING(g, len);
if (Delayed)
strcpy(Query, "INSERT DELAYED INTO ");
oom = Query->Set("INSERT DELAYED INTO ");
else
strcpy(Query, "INSERT INTO ");
oom = Query->Set("INSERT INTO ");
strcat(strcat(strcat(Query, tk), Tabname), tk);
strcat(strcat(strcat(Query, " ("), colist), ") VALUES (");
oom |= Query->Append(tk);
oom |= Query->Append(Tabname);
oom |= Query->Append("` (");
if (Prep)
strcat(strcat(Query, valist), ")");
else {
qlen += (strlen(Query) + Nparm);
Qbuf = (char *)PlugSubAlloc(g, NULL, qlen);
} // endelse Prep
for (colp = Columns; colp; colp = colp->GetNext()) {
if (b)
oom |= Query->Append(", ");
else
b = true;
oom |= Query->Append(tk);
oom |= Query->Append(colp->GetName());
oom |= Query->Append(tk);
} // endfor colp
return false;
oom |= Query->Append(") VALUES (");
#if defined(MYSQL_PREPARED_STATEMENTS)
if (Prep) {
for (int i = 0; i < Nparm; i++)
oom |= Query->Append("?,");
Query->RepLast(')');
Query->Trim();
} // endif Prep
#endif // MYSQL_PREPARED_STATEMENTS
if (oom)
strcpy(g->Message, "MakeInsert: Out of memory");
return oom;
} // end of MakeInsert
/***********************************************************************/
@@ -646,7 +656,7 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
/***********************************************************************/
int TDBMYSQL::MakeCommand(PGLOBAL g)
{
Query = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 64);
Query = new(g) STRING(g, strlen(Qrystr) + 64);
if (Quoted > 0 || stricmp(Name, Tabname)) {
char *p, *qrystr, name[68];
@@ -665,16 +675,23 @@ int TDBMYSQL::MakeCommand(PGLOBAL g)
strlwr(strcpy(name, Name)); // Not a keyword
if ((p = strstr(qrystr, name))) {
memcpy(Query, Qrystr, p - qrystr);
Query[p - qrystr] = 0;
bool oom = Query->Set(Qrystr, p - qrystr);
if (qtd && *(p-1) == ' ')
strcat(strcat(strcat(Query, "`"), Tabname), "`");
else
strcat(Query, Tabname);
if (qtd && *(p-1) == ' ') {
oom |= Query->Append('`');
oom |= Query->Append(Tabname);
oom |= Query->Append('`');
} else
oom |= Query->Append(Tabname);
oom |= Query->Append(Qrystr + (p - qrystr) + strlen(name));
if (oom) {
strcpy(g->Message, "MakeCommand: Out of memory");
return RC_FX;
} else
strlwr(strcpy(qrystr, Query->GetStr()));
strcat(Query, Qrystr + (p - qrystr) + strlen(name));
strlwr(strcpy(qrystr, Query));
} else {
sprintf(g->Message, "Cannot use this %s command",
(Mode == MODE_UPDATE) ? "UPDATE" : "DELETE");
@@ -682,7 +699,7 @@ int TDBMYSQL::MakeCommand(PGLOBAL g)
} // endif p
} else
strcpy(Query, Qrystr);
(void)Query->Set(Qrystr);
return RC_OK;
} // end of MakeCommand
@@ -755,7 +772,7 @@ int TDBMYSQL::Cardinality(PGLOBAL g)
if (!g)
return (Mode == MODE_ANY && !Srcdef) ? 1 : 0;
if (Cardinal < 0 && Mode == MODE_ANY && !Srcdef && xinfo) {
if (Cardinal < 0 && Mode == MODE_ANY && !Srcdef && ExactInfo()) {
// Info command, we must return the exact table row number
char query[96];
MYSQLC myc;
@@ -802,7 +819,7 @@ int TDBMYSQL::GetMaxSize(PGLOBAL g)
/***********************************************************************/
int TDBMYSQL::RowNumber(PGLOBAL g, bool b)
{
return N;
return N + 1;
} // end of RowNumber
/***********************************************************************/
@@ -871,7 +888,8 @@ bool TDBMYSQL::OpenDB(PGLOBAL g)
/*********************************************************************/
if (Mode == MODE_READ || Mode == MODE_READX) {
MakeSelect(g, Mode == MODE_READX);
m_Rc = (Mode == MODE_READ) ? Myc.ExecSQL(g, Query) : RC_OK;
m_Rc = (Mode == MODE_READ)
? Myc.ExecSQL(g, Query->GetStr()) : RC_OK;
#if 0
if (!Myc.m_Res || !Myc.m_Fields) {
@@ -894,7 +912,8 @@ bool TDBMYSQL::OpenDB(PGLOBAL g)
if (!MakeInsert(g)) {
#if defined(MYSQL_PREPARED_STATEMENTS)
int n = (Prep) ? Myc.PrepareSQL(g, Query) : Nparm;
int n = (Prep)
? Myc.PrepareSQL(g, Query->GetCharValue()) : Nparm;
if (Nparm != n) {
if (n >= 0) // Other errors return negative values
@@ -1007,7 +1026,7 @@ int TDBMYSQL::SendCommand(PGLOBAL g)
{
int w;
if (Myc.ExecSQLcmd(g, Query, &w) == RC_NF) {
if (Myc.ExecSQLcmd(g, Query->GetStr(), &w) == RC_NF) {
AftRows = Myc.m_Afrw;
sprintf(g->Message, "%s: %d affected rows", Tabname, AftRows);
PushWarning(g, this, 0); // 0 means a Note
@@ -1037,28 +1056,45 @@ int TDBMYSQL::SendCommand(PGLOBAL g)
/***********************************************************************/
bool TDBMYSQL::ReadKey(PGLOBAL g, OPVAL op, const void *key, int len)
{
int oldlen = strlen(Query);
bool oom;
int oldlen = Query->GetLength();
if (!key || op == OP_NEXT ||
Mode == MODE_UPDATE || Mode == MODE_DELETE)
return false;
else if (op == OP_FIRST) {
if (To_CondFil)
strcat(strcat(Query, " WHERE "), To_CondFil->Body);
if (To_CondFil) {
oom = Query->Append(" WHERE ");
if ((oom |= Query->Append(To_CondFil->Body))) {
strcpy(g->Message, "Readkey: Out of memory");
return true;
} // endif oom
} // endif To_Condfil
} else {
if (Myc.m_Res)
Myc.FreeResult();
To_Def->GetHandler()->MakeKeyWhere(g, Query, op, "`", key, len);
To_Def->GetHandler()->MakeKeyWhere(g, Query->GetStr(),
op, "`", key, len);
if (To_CondFil)
strcat(strcat(strcat(Query, " AND ("), To_CondFil->Body), ")");
if (To_CondFil) {
oom = Query->Append(" AND (");
oom |= Query->Append(To_CondFil->Body);
if ((oom |= Query->Append(')'))) {
strcpy(g->Message, "Readkey: Out of memory");
return true;
} // endif oom
} // endif To_Condfil
} // endif's op
m_Rc = Myc.ExecSQL(g, Query);
Query[oldlen] = 0;
m_Rc = Myc.ExecSQL(g, Query->GetStr());
Query->Truncate(oldlen);
return (m_Rc == RC_FX) ? true : false;
} // end of ReadKey
@@ -1102,31 +1138,38 @@ int TDBMYSQL::WriteDB(PGLOBAL g)
// Statement was not prepared, we must construct and execute
// an insert query for each line to insert
int rc;
uint len = Query->GetLength();
char buf[64];
strcpy(Qbuf, Query);
bool b, oom = false;
// Make the Insert command value list
for (PCOL colp = Columns; colp; colp = colp->GetNext()) {
if (!colp->GetValue()->IsNull()) {
if (colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE)
strcat(Qbuf, "'");
strcat(Qbuf, colp->GetValue()->GetCharString(buf));
if (colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE)
strcat(Qbuf, "'");
if ((b = colp->GetResultType() == TYPE_STRING ||
colp->GetResultType() == TYPE_DATE))
oom |= Query->Append('\'');
oom |= Query->Append(colp->GetValue()->GetCharString(buf));
if (b)
oom |= Query->Append('\'');
} else
strcat(Qbuf, "NULL");
strcat(Qbuf, (colp->GetNext()) ? "," : ")");
oom |= Query->Append("NULL");
oom |= Query->Append(',');
} // endfor colp
Myc.m_Rows = -1; // To execute the query
rc = Myc.ExecSQL(g, Qbuf);
if (unlikely(oom)) {
strcpy(g->Message, "WriteDB: Out of memory");
rc = RC_FX;
} else {
Query->RepLast(')');
Myc.m_Rows = -1; // To execute the query
rc = Myc.ExecSQL(g, Query->GetStr());
Query->Truncate(len); // Restore query
} // endif oom
return (rc == RC_NF) ? RC_OK : rc; // RC_NF is Ok
} // end of WriteDB
@@ -1531,7 +1574,7 @@ bool TDBMYEXC::OpenDB(PGLOBAL g)
if (!(Cmdlist = MakeCMD(g))) {
Myc.Close();
return true;
} // endif Query
} // endif Cmdlist
return false;
} // end of OpenDB
@@ -1559,9 +1602,12 @@ int TDBMYEXC::ReadDB(PGLOBAL g)
int rc;
do {
Query = Cmdlist->Cmd;
if (Query)
Query->Set(Cmdlist->Cmd);
else
Query = new(g) STRING(g, 0, Cmdlist->Cmd);
switch (rc = Myc.ExecSQLcmd(g, Query, &Warnings)) {
switch (rc = Myc.ExecSQLcmd(g, Query->GetStr(), &Warnings)) {
case RC_NF:
AftRows = Myc.m_Afrw;
strcpy(g->Message, "Affected rows");
@@ -1650,11 +1696,11 @@ void MYXCOL::ReadColumn(PGLOBAL g)
} else
switch (Flag) {
case 0: Value->SetValue_psz(tdbp->Query); break;
case 1: Value->SetValue(tdbp->AftRows); break;
case 2: Value->SetValue_psz(g->Message); break;
case 3: Value->SetValue(tdbp->Warnings); break;
default: Value->SetValue_psz("Invalid Flag"); break;
case 0: Value->SetValue_psz(tdbp->Query->GetStr()); break;
case 1: Value->SetValue(tdbp->AftRows); break;
case 2: Value->SetValue_psz(g->Message); break;
case 3: Value->SetValue(tdbp->Warnings); break;
default: Value->SetValue_psz("Invalid Flag"); break;
} // endswitch Flag
} // end of ReadColumn

View File

@@ -119,6 +119,7 @@ class TDBMYSQL : public TDBASE {
// Members
MYSQLC Myc; // MySQL connection class
MYSQL_BIND *Bind; // To the MySQL bind structure array
PSTRG Query; // Constructed SQL query
char *Host; // Host machine to use
char *User; // User logon info
char *Pwd; // Password logon info
@@ -126,8 +127,6 @@ class TDBMYSQL : public TDBASE {
char *Tabname; // External table name
char *Srcdef; // The source table SQL definition
char *Server; // The server ID
char *Query; // Points to SQL query
char *Qbuf; // Used for not prepared insert
char *Qrystr; // The original query
bool Fetched; // True when fetch was done
bool Isview; // True if this table is a MySQL view

View File

@@ -51,8 +51,6 @@
#include "ha_connect.h"
#include "mycat.h"
extern "C" int trace;
/***********************************************************************/
/* Prepare and count columns in the column list. */
/***********************************************************************/

View File

@@ -75,15 +75,17 @@
#include "sql_string.h"
extern "C" int trace;
extern bool xinfo;
/***********************************************************************/
/* DB static variables. */
/***********************************************************************/
// int num_read, num_there, num_eq[2], num_nf; // Statistics
extern int num_read, num_there, num_eq[2]; // Statistics
/***********************************************************************/
/* External function. */
/***********************************************************************/
bool ExactInfo(void);
/* -------------------------- Class ODBCDEF -------------------------- */
/***********************************************************************/
@@ -672,7 +674,7 @@ int TDBODBC::Cardinality(PGLOBAL g)
if (!g)
return (Mode == MODE_ANY && !Srcdef) ? 1 : 0;
if (Cardinal < 0 && Mode == MODE_ANY && !Srcdef && xinfo) {
if (Cardinal < 0 && Mode == MODE_ANY && !Srcdef && ExactInfo()) {
// Info command, we must return the exact table row number
char qry[96], tbn[64];
ODBConn *ocp = new(g) ODBConn(g, this);

View File

@@ -51,8 +51,6 @@
#include "ha_connect.h"
#include "mycat.h" // For GetHandler
extern "C" int trace;
/***********************************************************************/
/* Make the Pivot table column list. */
/***********************************************************************/

View File

@@ -53,8 +53,6 @@
GetPrivateProfileString(NULL,NULL,"",S,L,I)
#endif // !WIN32
extern "C" int trace;
/* -------------- Implementation of the INI classes ------------------ */
/***********************************************************************/

View File

@@ -86,8 +86,6 @@
#define SYSEXIT void *
#endif // !WIN32
extern "C" int trace;
/* ---------------------------- Class TBLDEF ---------------------------- */
/**************************************************************************/

View File

@@ -54,7 +54,6 @@
#include "tabutil.h"
#include "ha_connect.h"
extern "C" int trace;
extern "C" int zconv;
/************************************************************************/

View File

@@ -76,8 +76,10 @@
char *strerror(int num);
#endif // UNIX
extern "C" int trace;
extern "C" USETEMP Use_Temp;
/***********************************************************************/
/* External function. */
/***********************************************************************/
USETEMP UseTemp(void);
/***********************************************************************/
/* Char VCT column blocks are right filled with blanks (blank = true) */
@@ -209,7 +211,7 @@ PTDB VCTDEF::GetTable(PGLOBAL g, MODE mode)
// Mapping not used for insert (except for true VEC not split tables)
// or when UseTemp is forced
bool map = Mapped && (Estimate || mode != MODE_INSERT) &&
!(Use_Temp == TMP_FORCE &&
!(UseTemp() == TMP_FORCE &&
(mode == MODE_UPDATE || mode == MODE_DELETE));
PTXF txfp;
PTDB tdbp;
@@ -291,7 +293,7 @@ PCOL TDBVCT::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
bool TDBVCT::IsUsingTemp(PGLOBAL g)
{
// For developpers
return (Use_Temp == TMP_TEST);
return (UseTemp() == TMP_TEST);
} // end of IsUsingTemp
/***********************************************************************/

View File

@@ -21,8 +21,6 @@
#include "plgcnx.h" // For DB types
#include "resource.h"
extern "C" int trace;
/* ------------------- Functions WMI Column info --------------------- */
/***********************************************************************/

View File

@@ -1,151 +1,151 @@
// TABWMI.H Olivier Bertrand 2012
// WMI: Virtual table to Get WMI information
#define _WIN32_DCOM
#include <wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
#include <iostream>
using namespace std;
#include <comdef.h>
/***********************************************************************/
/* Definitions. */
/***********************************************************************/
typedef class WMIDEF *PWMIDEF;
typedef class TDBWMI *PTDBWMI;
typedef class WMICOL *PWMICOL;
typedef class TDBWCL *PTDBWCL;
typedef class WCLCOL *PWCLCOL;
/***********************************************************************/
/* Structure used by WMI column info functions. */
/***********************************************************************/
typedef struct _WMIutil {
IWbemServices *Svc;
IWbemClassObject *Cobj;
} WMIUTIL, *PWMIUT;
/***********************************************************************/
/* Functions used externally. */
/***********************************************************************/
PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info);
/* -------------------------- WMI classes ---------------------------- */
/***********************************************************************/
/* WMI: Virtual table to get the WMI information. */
/***********************************************************************/
class WMIDEF : public TABDEF { /* Logical table description */
friend class TDBWMI;
friend class TDBWCL;
friend class TDBWCX;
public:
// Constructor
WMIDEF(void) {Pseudo = 3; Nspace = NULL; Wclass = NULL; Ems = 0;}
// Implementation
virtual const char *GetType(void) {return "WMI";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
char *Nspace;
char *Wclass;
int Ems;
}; // end of WMIDEF
/***********************************************************************/
/* This is the class declaration for the WMI table. */
/***********************************************************************/
class TDBWMI : public TDBASE {
friend class WMICOL;
public:
// Constructor
TDBWMI(PWMIDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_WMI;}
// Methods
virtual int GetRecpos(void);
virtual int GetProgCur(void) {return N;}
virtual int RowNumber(PGLOBAL g, bool b = false) {return N + 1;}
// Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
// TABWMI.H Olivier Bertrand 2012
// WMI: Virtual table to Get WMI information
#define _WIN32_DCOM
#include <wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
#include <iostream>
using namespace std;
#include <comdef.h>
/***********************************************************************/
/* Definitions. */
/***********************************************************************/
typedef class WMIDEF *PWMIDEF;
typedef class TDBWMI *PTDBWMI;
typedef class WMICOL *PWMICOL;
typedef class TDBWCL *PTDBWCL;
typedef class WCLCOL *PWCLCOL;
/***********************************************************************/
/* Structure used by WMI column info functions. */
/***********************************************************************/
typedef struct _WMIutil {
IWbemServices *Svc;
IWbemClassObject *Cobj;
} WMIUTIL, *PWMIUT;
/***********************************************************************/
/* Functions used externally. */
/***********************************************************************/
PQRYRES WMIColumns(PGLOBAL g, char *nsp, char *cls, bool info);
/* -------------------------- WMI classes ---------------------------- */
/***********************************************************************/
/* WMI: Virtual table to get the WMI information. */
/***********************************************************************/
class WMIDEF : public TABDEF { /* Logical table description */
friend class TDBWMI;
friend class TDBWCL;
friend class TDBWCX;
public:
// Constructor
WMIDEF(void) {Pseudo = 3; Nspace = NULL; Wclass = NULL; Ems = 0;}
// Implementation
virtual const char *GetType(void) {return "WMI";}
// Methods
virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff);
virtual PTDB GetTable(PGLOBAL g, MODE m);
protected:
// Members
char *Nspace;
char *Wclass;
int Ems;
}; // end of WMIDEF
/***********************************************************************/
/* This is the class declaration for the WMI table. */
/***********************************************************************/
class TDBWMI : public TDBASE {
friend class WMICOL;
public:
// Constructor
TDBWMI(PWMIDEF tdp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_WMI;}
// Methods
virtual int GetRecpos(void);
virtual int GetProgCur(void) {return N;}
virtual int RowNumber(PGLOBAL g, bool b = false) {return N + 1;}
// Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
virtual int Cardinality(PGLOBAL g) {return GetMaxSize(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);
protected:
// Specific routines
bool Initialize(PGLOBAL g);
char *MakeWQL(PGLOBAL g);
void DoubleSlash(PGLOBAL g);
bool GetWMIInfo(PGLOBAL g);
// Members
IWbemServices *Svc; // IWbemServices pointer
IEnumWbemClassObject *Enumerator;
IWbemClassObject *ClsObj;
char *Nspace; // Namespace
char *Wclass; // Class name
char *ObjPath; // Used for direct access
char *Kvp; // Itou
int Ems; // Estimated max size
PCOL Kcol; // Key column
HRESULT Res;
PVBLK Vbp;
bool Init;
bool Done;
ULONG Rc;
int N; // Row number
}; // end of class TDBWMI
/***********************************************************************/
/* Class WMICOL: WMI Address column. */
/***********************************************************************/
class WMICOL : public COLBLK {
friend class TDBWMI;
public:
// Constructors
WMICOL(PCOLDEF cdp, PTDB tdbp, int n);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_WMI;}
// Methods
virtual void ReadColumn(PGLOBAL g);
protected:
WMICOL(void) {} // Default constructor not to be used
// Members
PTDBWMI Tdbp; // Points to WMI table block
VARIANT Prop; // Property value
CIMTYPE Ctype; // CIM Type
HRESULT Res;
}; // end of class WMICOL
/***********************************************************************/
/* This is the class declaration for the WMI catalog table. */
/***********************************************************************/
class TDBWCL : public TDBCAT {
public:
// Constructor
TDBWCL(PWMIDEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// Members
char *Nsp; // Name space
char *Cls; // Class
}; // end of class TDBWCL
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);
protected:
// Specific routines
bool Initialize(PGLOBAL g);
char *MakeWQL(PGLOBAL g);
void DoubleSlash(PGLOBAL g);
bool GetWMIInfo(PGLOBAL g);
// Members
IWbemServices *Svc; // IWbemServices pointer
IEnumWbemClassObject *Enumerator;
IWbemClassObject *ClsObj;
char *Nspace; // Namespace
char *Wclass; // Class name
char *ObjPath; // Used for direct access
char *Kvp; // Itou
int Ems; // Estimated max size
PCOL Kcol; // Key column
HRESULT Res;
PVBLK Vbp;
bool Init;
bool Done;
ULONG Rc;
int N; // Row number
}; // end of class TDBWMI
/***********************************************************************/
/* Class WMICOL: WMI Address column. */
/***********************************************************************/
class WMICOL : public COLBLK {
friend class TDBWMI;
public:
// Constructors
WMICOL(PCOLDEF cdp, PTDB tdbp, int n);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_WMI;}
// Methods
virtual void ReadColumn(PGLOBAL g);
protected:
WMICOL(void) {} // Default constructor not to be used
// Members
PTDBWMI Tdbp; // Points to WMI table block
VARIANT Prop; // Property value
CIMTYPE Ctype; // CIM Type
HRESULT Res;
}; // end of class WMICOL
/***********************************************************************/
/* This is the class declaration for the WMI catalog table. */
/***********************************************************************/
class TDBWCL : public TDBCAT {
public:
// Constructor
TDBWCL(PWMIDEF tdp);
protected:
// Specific routines
virtual PQRYRES GetResult(PGLOBAL g);
// Members
char *Nsp; // Name space
char *Cls; // Class
}; // end of class TDBWCL

View File

@@ -57,8 +57,6 @@
#include "ha_connect.h"
#include "mycat.h"
extern "C" int trace;
/* -------------- Implementation of the XCOL classes ---------------- */
/***********************************************************************/

View File

@@ -49,10 +49,7 @@
#include "tabxml.h"
#include "tabmul.h"
extern "C" {
extern char version[];
extern int trace;
} // "C"
extern "C" char version[];
#if defined(WIN32) && defined(DOMDOC_SUPPORT)
#define XMLSUP "MS-DOM"

View File

@@ -47,7 +47,6 @@
#include "user_connect.h"
#include "mycat.h"
extern "C" int trace;
extern uint worksize;
/****************************************************************************/

View File

@@ -43,7 +43,6 @@
#define CheckBlanks assert(!Blanks);
#define CheckParms(V, N) ChkIndx(N); ChkTyp(V);
extern "C" int trace;
extern MBLOCK Nmblk; /* Used to initialize MBLOCK's */
/***********************************************************************/

View File

@@ -48,7 +48,6 @@
#include "global.h"
#include "plgdbsem.h"
#include "preparse.h" // For DATPAR
//#include "value.h"
#include "valblk.h"
#define NO_FUNC // Already defined in ODBConn
#include "plgcnx.h" // For DB types
@@ -68,12 +67,6 @@
#define FOURYEARS 126230400 // Four years in seconds (1 leap)
/***********************************************************************/
/* Static variables. */
/***********************************************************************/
extern "C" int trace;
/***********************************************************************/
/* Initialize the DTVAL static member. */
/***********************************************************************/
@@ -1019,8 +1012,11 @@ TYPVAL<PSZ>::TYPVAL(PGLOBAL g, PSZ s, int n, int c)
if (!s) {
if (g) {
Strp = (char *)PlugSubAlloc(g, NULL, Len + 1);
Strp[Len] = '\0';
if ((Strp = (char *)PlgDBSubAlloc(g, NULL, Len + 1)))
Strp[Len] = '\0';
else
Len = 0;
} else
assert(false);

View File

@@ -256,6 +256,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
protected:
// Members
PSZ Strp;
bool Ci; // true if case insensitive
@@ -283,6 +284,7 @@ class DllExport DECVAL: public TYPVAL<PSZ> {
virtual bool IsEqual(PVAL vp, bool chktype);
virtual int CompareValue(PVAL vp);
protected:
// Members
}; // end of class DECVAL
@@ -337,6 +339,7 @@ class DllExport BINVAL: public VALUE {
virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
protected:
// Members
void *Binp;
char *Chrp;

View File

@@ -58,10 +58,9 @@
#endif
/***********************************************************************/
/* DB static external variables. */
/* DB external variables. */
/***********************************************************************/
extern MBLOCK Nmblk; /* Used to initialize MBLOCK's */
extern "C" int trace;
#if defined(XMAP)
extern bool xmap;
#endif // XMAP

View File

@@ -1,186 +1,371 @@
/************ Xobject C++ Functions Source Code File (.CPP) ************/
/* Name: XOBJECT.CPP Version 2.3 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
/* */
/* This file contains base XOBJECT class functions. */
/* Also here is the implementation of the CONSTANT class. */
/***********************************************************************/
/***********************************************************************/
/* Include mariaDB header file. */
/***********************************************************************/
#include "my_global.h"
/***********************************************************************/
/* Include required application header files */
/* global.h is header containing all global Plug declarations. */
/* plgdbsem.h is header containing the DB applic. declarations. */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "xobject.h"
/***********************************************************************/
/* Macro definitions. */
/***********************************************************************/
#if defined(_DEBUG) || defined(DEBTRACE)
#define ASSERT(B) assert(B);
#else
#define ASSERT(B)
#endif
/***********************************************************************/
/* The one and only needed void object. */
/***********************************************************************/
XVOID Xvoid;
PXOB const pXVOID = &Xvoid; // Pointer used by other classes
/* ------------------------- Class XOBJECT --------------------------- */
/***********************************************************************/
/* GetCharValue: returns the Result value as a char string. */
/* Using GetCharValue provides no conversion from numeric types. */
/***********************************************************************/
PSZ XOBJECT::GetCharValue(void)
{
ASSERT(Value)
return Value->GetCharValue();
} // end of GetCharValue()
/***********************************************************************/
/* GetShortValue: returns the Result value as a short integer. */
/***********************************************************************/
short XOBJECT::GetShortValue(void)
{
ASSERT(Value)
return Value->GetShortValue();
} // end of GetShortValue
/***********************************************************************/
/* GetIntValue: returns the Result value as a int integer. */
/***********************************************************************/
int XOBJECT::GetIntValue(void)
{
ASSERT(Value)
return Value->GetIntValue();
} // end of GetIntValue
/***********************************************************************/
/* GetFloatValue: returns the Result value as a double float. */
/***********************************************************************/
double XOBJECT::GetFloatValue(void)
{
ASSERT(Value)
return Value->GetFloatValue();
} // end of GetFloatValue
/* ------------------------- Class CONSTANT -------------------------- */
/***********************************************************************/
/* CONSTANT public constructor. */
/***********************************************************************/
CONSTANT::CONSTANT(PGLOBAL g, void *value, short type)
{
if (!(Value = AllocateValue(g, value, (int)type)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
Constant = true;
} // end of CONSTANT constructor
/***********************************************************************/
/* CONSTANT public constructor. */
/***********************************************************************/
CONSTANT::CONSTANT(PGLOBAL g, int n)
{
if (!(Value = AllocateValue(g, &n, TYPE_INT)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
Constant = true;
} // end of CONSTANT constructor
/***********************************************************************/
/* GetLengthEx: returns an evaluation of the constant string length. */
/* Note: When converting from token to string, length has to be */
/* specified but we need the domain length, not the value length. */
/***********************************************************************/
int CONSTANT::GetLengthEx(void)
{
return Value->GetValLen();
} // end of GetLengthEx
/***********************************************************************/
/* Convert a constant to the given type. */
/***********************************************************************/
void CONSTANT::Convert(PGLOBAL g, int newtype)
{
if (Value->GetType() != newtype)
if (!(Value = AllocateValue(g, Value, newtype)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
} // end of Convert
/***********************************************************************/
/* Compare: returns true if this object is equivalent to xp. */
/***********************************************************************/
bool CONSTANT::Compare(PXOB xp)
{
if (this == xp)
return true;
else if (xp->GetType() != TYPE_CONST)
return false;
else
return Value->IsEqual(xp->GetValue(), true);
} // end of Compare
#if 0
/***********************************************************************/
/* Rephrase: temporary implementation used by PlugRephraseSQL. */
/***********************************************************************/
bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
{
switch (Value->GetType()) {
case TYPE_STRING:
sprintf(work + strlen(work), "'%s'", Value->GetCharValue());
break;
case TYPE_SHORT:
sprintf(work + strlen(work), "%hd", Value->GetShortValue());
break;
case TYPE_INT:
case TYPE_DATE:
sprintf(work + strlen(work), "%d", Value->GetIntValue());
break;
case TYPE_DOUBLE:
sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
break;
case TYPE_BIGINT:
sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
break;
case TYPE_TINY:
sprintf(work + strlen(work), "%d", Value->GetTinyValue());
break;
default:
sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType());
return false;
} // endswitch
return false;
} // end of Rephrase
#endif // 0
/***********************************************************************/
/* Make file output of a constant object. */
/***********************************************************************/
void CONSTANT::Print(PGLOBAL g, FILE *f, uint n)
{
Value->Print(g, f, n);
} /* end of Print */
/***********************************************************************/
/* Make string output of a constant object. */
/***********************************************************************/
void CONSTANT::Print(PGLOBAL g, char *ps, uint z)
{
Value->Print(g, ps, z);
} /* end of Print */
/************ Xobject C++ Functions Source Code File (.CPP) ************/
/* Name: XOBJECT.CPP Version 2.4 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
/* */
/* This file contains base XOBJECT class functions. */
/* Also here is the implementation of the CONSTANT class. */
/***********************************************************************/
/***********************************************************************/
/* Include mariaDB header file. */
/***********************************************************************/
#include "my_global.h"
/***********************************************************************/
/* Include required application header files */
/* global.h is header containing all global Plug declarations. */
/* plgdbsem.h is header containing the DB applic. declarations. */
/***********************************************************************/
#include "global.h"
#include "plgdbsem.h"
#include "xobject.h"
/***********************************************************************/
/* Macro definitions. */
/***********************************************************************/
#if defined(_DEBUG) || defined(DEBTRACE)
#define ASSERT(B) assert(B);
#else
#define ASSERT(B)
#endif
/***********************************************************************/
/* The one and only needed void object. */
/***********************************************************************/
XVOID Xvoid;
PXOB const pXVOID = &Xvoid; // Pointer used by other classes
/* ------------------------- Class XOBJECT --------------------------- */
/***********************************************************************/
/* GetCharValue: returns the Result value as a char string. */
/* Using GetCharValue provides no conversion from numeric types. */
/***********************************************************************/
PSZ XOBJECT::GetCharValue(void)
{
ASSERT(Value)
return Value->GetCharValue();
} // end of GetCharValue()
/***********************************************************************/
/* GetShortValue: returns the Result value as a short integer. */
/***********************************************************************/
short XOBJECT::GetShortValue(void)
{
ASSERT(Value)
return Value->GetShortValue();
} // end of GetShortValue
/***********************************************************************/
/* GetIntValue: returns the Result value as a int integer. */
/***********************************************************************/
int XOBJECT::GetIntValue(void)
{
ASSERT(Value)
return Value->GetIntValue();
} // end of GetIntValue
/***********************************************************************/
/* GetFloatValue: returns the Result value as a double float. */
/***********************************************************************/
double XOBJECT::GetFloatValue(void)
{
ASSERT(Value)
return Value->GetFloatValue();
} // end of GetFloatValue
/* ------------------------- Class CONSTANT -------------------------- */
/***********************************************************************/
/* CONSTANT public constructor. */
/***********************************************************************/
CONSTANT::CONSTANT(PGLOBAL g, void *value, short type)
{
if (!(Value = AllocateValue(g, value, (int)type)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
Constant = true;
} // end of CONSTANT constructor
/***********************************************************************/
/* CONSTANT public constructor. */
/***********************************************************************/
CONSTANT::CONSTANT(PGLOBAL g, int n)
{
if (!(Value = AllocateValue(g, &n, TYPE_INT)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
Constant = true;
} // end of CONSTANT constructor
/***********************************************************************/
/* GetLengthEx: returns an evaluation of the constant string length. */
/* Note: When converting from token to string, length has to be */
/* specified but we need the domain length, not the value length. */
/***********************************************************************/
int CONSTANT::GetLengthEx(void)
{
return Value->GetValLen();
} // end of GetLengthEx
/***********************************************************************/
/* Convert a constant to the given type. */
/***********************************************************************/
void CONSTANT::Convert(PGLOBAL g, int newtype)
{
if (Value->GetType() != newtype)
if (!(Value = AllocateValue(g, Value, newtype)))
longjmp(g->jumper[g->jump_level], TYPE_CONST);
} // end of Convert
/***********************************************************************/
/* Compare: returns true if this object is equivalent to xp. */
/***********************************************************************/
bool CONSTANT::Compare(PXOB xp)
{
if (this == xp)
return true;
else if (xp->GetType() != TYPE_CONST)
return false;
else
return Value->IsEqual(xp->GetValue(), true);
} // end of Compare
#if 0
/***********************************************************************/
/* Rephrase: temporary implementation used by PlugRephraseSQL. */
/***********************************************************************/
bool CONSTANT::Rephrase(PGLOBAL g, PSZ work)
{
switch (Value->GetType()) {
case TYPE_STRING:
sprintf(work + strlen(work), "'%s'", Value->GetCharValue());
break;
case TYPE_SHORT:
sprintf(work + strlen(work), "%hd", Value->GetShortValue());
break;
case TYPE_INT:
case TYPE_DATE:
sprintf(work + strlen(work), "%d", Value->GetIntValue());
break;
case TYPE_DOUBLE:
sprintf(work + strlen(work), "%lf", Value->GetFloatValue());
break;
case TYPE_BIGINT:
sprintf(work + strlen(work), "%lld", Value->GetBigintValue());
break;
case TYPE_TINY:
sprintf(work + strlen(work), "%d", Value->GetTinyValue());
break;
default:
sprintf(g->Message, MSG(BAD_CONST_TYPE), Value->GetType());
return false;
} // endswitch
return false;
} // end of Rephrase
#endif // 0
/***********************************************************************/
/* Make file output of a constant object. */
/***********************************************************************/
void CONSTANT::Print(PGLOBAL g, FILE *f, uint n)
{
Value->Print(g, f, n);
} /* end of Print */
/***********************************************************************/
/* Make string output of a constant object. */
/***********************************************************************/
void CONSTANT::Print(PGLOBAL g, char *ps, uint z)
{
Value->Print(g, ps, z);
} /* end of Print */
/* -------------------------- Class STRING --------------------------- */
/***********************************************************************/
/* STRING public constructor for new char values. Alloc Size must be */
/* calculated because PlugSubAlloc rounds up size to multiple of 8. */
/***********************************************************************/
STRING::STRING(PGLOBAL g, uint n, char *str)
{
G = g;
Length = (str) ? strlen(str) : 0;
if ((Strp = (PSZ)PlgDBSubAlloc(g, NULL, MY_MAX(n, Length) + 1))) {
if (str)
strcpy(Strp, str);
else
*Strp = 0;
Next = GetNext();
Size = Next - Strp;
} else {
// This should normally never happen
Next = NULL;
Size = 0;
} // endif Strp
} // end of STRING constructor
/***********************************************************************/
/* Reallocate the string memory and return the (new) position. */
/* If Next is equal to GetNext() this means that no new suballocation */
/* has been done. Then we can just increase the size of the current */
/* allocation and the Strp will remain pointing to the same memory. */
/***********************************************************************/
char *STRING::Realloc(uint len)
{
char *p;
bool b = (Next == GetNext());
p = (char*)PlgDBSubAlloc(G, NULL, b ? len - Size : len);
if (!p) {
// No more room in Sarea; this is very unlikely
strcpy(G->Message, "No more room in work area");
return NULL;
} // endif p
if (b)
p = Strp;
Next = GetNext();
Size = Next - p;
return p;
} // end of Realloc
/***********************************************************************/
/* Set a STRING new PSZ value. */
/***********************************************************************/
bool STRING::Set(PSZ s)
{
if (!s)
return false;
uint len = strlen(s) + 1;
if (len > Size) {
char *p = Realloc(len);
if (!p)
return true;
else
Strp = p;
} // endif n
strcpy(Strp, s);
Length = len - 1;
return false;
} // end of Set
/***********************************************************************/
/* Set a STRING new PSZ value. */
/***********************************************************************/
bool STRING::Set(char *s, uint n)
{
if (!s)
return false;
uint len = MY_MIN(strlen(s), n) + 1;
if (len > Size) {
char *p = Realloc(len);
if (!p)
return true;
else
Strp = p;
} // endif n
strncpy(Strp, s, n);
Length = len - 1;
return false;
} // end of Set
/***********************************************************************/
/* Append a PSZ to a STRING. */
/***********************************************************************/
bool STRING::Append(PSZ s)
{
if (!s)
return false;
uint len = Length + strlen(s) + 1;
if (len > Size) {
char *p = Realloc(len);
if (!p)
return true;
else if (p != Strp) {
strcpy(p, Strp);
Strp = p;
} // endif p
} // endif n
strcpy(Strp + Length, s);
Length = len - 1;
return false;
} // end of Append
/***********************************************************************/
/* Append a STRING to a STRING. */
/***********************************************************************/
bool STRING::Append(STRING &str)
{
return Append(str.GetStr());
} // end of Append
/***********************************************************************/
/* Append a char to a STRING. */
/***********************************************************************/
bool STRING::Append(char c)
{
if (Length + 2 > Size) {
char *p = Realloc(Length + 2);
if (!p)
return true;
else if (p != Strp) {
strcpy(p, Strp);
Strp = p;
} // endif p
} // endif n
Strp[Length++] = c;
Strp[Length] = 0;
return false;
} // end of Append
/***********************************************************************/
/* Resize to given length but only when last suballocated. */
/* New size should be greater than string length. */
/***********************************************************************/
bool STRING::Resize(uint newsize)
{
if (Next == GetNext() && newsize > Length) {
uint nsz = (((signed)newsize + 7) / 8) * 8;
int diff = (signed)Size - (signed)nsz;
PPOOLHEADER pp = (PPOOLHEADER)G->Sarea;
if ((signed)pp->FreeBlk + diff < 0)
return true; // Out of memory
pp->To_Free -= diff;
pp->FreeBlk += diff;
Size = nsz;
return false;
} else
return newsize > Size;
} // end of Resize

View File

@@ -1,119 +1,160 @@
/*************** Xobject H Declares Source Code File (.H) **************/
/* Name: XOBJECT.H Version 2.4 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
/* */
/* This file contains the XOBJECT and derived classes declares. */
/***********************************************************************/
#ifndef __XOBJECT__H
#define __XOBJECT__H
/***********************************************************************/
/* Include required application header files */
/* block.h is header containing Block global declarations. */
/***********************************************************************/
#include "block.h"
#include "valblk.h" // includes value.h
/***********************************************************************/
/* Types used in some class definitions. */
/***********************************************************************/
//typedef struct _tabdesc *PTABD; // For friend setting
/***********************************************************************/
/* The pointer to the one and only needed void object. */
/***********************************************************************/
extern PXOB const pXVOID;
/***********************************************************************/
/* Class XOBJECT is the base class for all classes that can be used */
/* in evaluation operations: FILTER, EXPRESSION, SCALF, FNC, COLBLK, */
/* SELECT, FILTER as well as all the constant object types. */
/***********************************************************************/
class DllExport XOBJECT : public BLOCK {
public:
XOBJECT(void) {Value = NULL; Constant = false;}
// Implementation
PVAL GetValue(void) {return Value;}
bool IsConstant(void) {return Constant;}
virtual int GetType(void) {return TYPE_XOBJECT;}
virtual int GetResultType(void) {return TYPE_VOID;}
virtual int GetKey(void) {return 0;}
#if defined(_DEBUG)
virtual void SetKey(int k) {assert(false);}
#else // !_DEBUG
virtual void SetKey(int k) {} // Only defined for COLBLK
#endif // !_DEBUG
virtual int GetLength(void) = 0;
virtual int GetLengthEx(void) = 0;
virtual PSZ GetCharValue(void);
virtual short GetShortValue(void);
virtual int GetIntValue(void);
virtual double GetFloatValue(void);
virtual int GetScale(void) = 0;
// Methods
virtual void Reset(void) {}
virtual bool Compare(PXOB) = 0;
virtual bool Init(PGLOBAL) {return false;}
virtual bool Eval(PGLOBAL) {return false;}
virtual bool SetFormat(PGLOBAL, FORMAT&) = 0;
protected:
PVAL Value; // The current value of the object.
bool Constant; // true for an object having a constant value.
}; // end of class XOBJECT
/***********************************************************************/
/* Class XVOID: represent a void (null) object. */
/* Used to represent a void parameter for count(*) or for a filter. */
/***********************************************************************/
class DllExport XVOID : public XOBJECT {
public:
XVOID(void) {Constant = true;}
// Implementation
virtual int GetType(void) {return TYPE_VOID;}
virtual int GetLength(void) {return 0;}
virtual int GetLengthEx(void) {return 0;}
virtual PSZ GetCharValue(void) {return NULL;}
virtual int GetIntValue(void) {return 0;}
virtual double GetFloatValue(void) {return 0.0;}
virtual int GetScale() {return 0;}
// Methods
virtual bool Compare(PXOB xp) {return xp->GetType() == TYPE_VOID;}
virtual bool SetFormat(PGLOBAL, FORMAT&) {return true;}
}; // end of class XVOID
/***********************************************************************/
/* Class CONSTANT: represents a constant XOBJECT of any value type. */
/* Note that the CONSTANT class is a friend of the VALUE class; */
/***********************************************************************/
class DllExport CONSTANT : public XOBJECT {
public:
CONSTANT(PGLOBAL g, void *value, short type);
CONSTANT(PGLOBAL g, int n);
CONSTANT(PVAL valp) {Value = valp; Constant = true;}
// Implementation
virtual int GetType(void) {return TYPE_CONST;}
virtual int GetResultType(void) {return Value->Type;}
virtual int GetLength(void) {return Value->GetValLen();}
virtual int GetScale() {return Value->GetValPrec();}
virtual int GetLengthEx(void);
// Methods
virtual bool Compare(PXOB xp);
virtual bool SetFormat(PGLOBAL g, FORMAT& fmt)
{return Value->SetConstFormat(g, fmt);}
void Convert(PGLOBAL g, int newtype);
void SetValue(PVAL vp) {Value = vp;}
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *, uint);
}; // end of class CONSTANT
#endif
/*************** Xobject H Declares Source Code File (.H) **************/
/* Name: XOBJECT.H Version 2.4 */
/* */
/* (C) Copyright to the author Olivier BERTRAND 1998-2014 */
/* */
/* This file contains the XOBJECT and derived classes declares. */
/***********************************************************************/
#ifndef __XOBJECT__H
#define __XOBJECT__H
/***********************************************************************/
/* Include required application header files */
/* block.h is header containing Block global declarations. */
/***********************************************************************/
#include "block.h"
#include "valblk.h" // includes value.h
/***********************************************************************/
/* Types used in some class definitions. */
/***********************************************************************/
typedef class STRING *PSTRG;
/***********************************************************************/
/* The pointer to the one and only needed void object. */
/***********************************************************************/
extern PXOB const pXVOID;
/***********************************************************************/
/* Class XOBJECT is the base class for all classes that can be used */
/* in evaluation operations: FILTER, EXPRESSION, SCALF, FNC, COLBLK, */
/* SELECT, FILTER as well as all the constant object types. */
/***********************************************************************/
class DllExport XOBJECT : public BLOCK {
public:
XOBJECT(void) {Value = NULL; Constant = false;}
// Implementation
PVAL GetValue(void) {return Value;}
bool IsConstant(void) {return Constant;}
virtual int GetType(void) {return TYPE_XOBJECT;}
virtual int GetResultType(void) {return TYPE_VOID;}
virtual int GetKey(void) {return 0;}
#if defined(_DEBUG)
virtual void SetKey(int k) {assert(false);}
#else // !_DEBUG
virtual void SetKey(int k) {} // Only defined for COLBLK
#endif // !_DEBUG
virtual int GetLength(void) = 0;
virtual int GetLengthEx(void) = 0;
virtual PSZ GetCharValue(void);
virtual short GetShortValue(void);
virtual int GetIntValue(void);
virtual double GetFloatValue(void);
virtual int GetScale(void) = 0;
// Methods
virtual void Reset(void) {}
virtual bool Compare(PXOB) = 0;
virtual bool Init(PGLOBAL) {return false;}
virtual bool Eval(PGLOBAL) {return false;}
virtual bool SetFormat(PGLOBAL, FORMAT&) = 0;
protected:
PVAL Value; // The current value of the object.
bool Constant; // true for an object having a constant value.
}; // end of class XOBJECT
/***********************************************************************/
/* Class XVOID: represent a void (null) object. */
/* Used to represent a void parameter for count(*) or for a filter. */
/***********************************************************************/
class DllExport XVOID : public XOBJECT {
public:
XVOID(void) {Constant = true;}
// Implementation
virtual int GetType(void) {return TYPE_VOID;}
virtual int GetLength(void) {return 0;}
virtual int GetLengthEx(void) {return 0;}
virtual PSZ GetCharValue(void) {return NULL;}
virtual int GetIntValue(void) {return 0;}
virtual double GetFloatValue(void) {return 0.0;}
virtual int GetScale() {return 0;}
// Methods
virtual bool Compare(PXOB xp) {return xp->GetType() == TYPE_VOID;}
virtual bool SetFormat(PGLOBAL, FORMAT&) {return true;}
}; // end of class XVOID
/***********************************************************************/
/* Class CONSTANT: represents a constant XOBJECT of any value type. */
/* Note that the CONSTANT class is a friend of the VALUE class; */
/***********************************************************************/
class DllExport CONSTANT : public XOBJECT {
public:
CONSTANT(PGLOBAL g, void *value, short type);
CONSTANT(PGLOBAL g, int n);
CONSTANT(PVAL valp) {Value = valp; Constant = true;}
// Implementation
virtual int GetType(void) {return TYPE_CONST;}
virtual int GetResultType(void) {return Value->Type;}
virtual int GetLength(void) {return Value->GetValLen();}
virtual int GetScale() {return Value->GetValPrec();}
virtual int GetLengthEx(void);
// Methods
virtual bool Compare(PXOB xp);
virtual bool SetFormat(PGLOBAL g, FORMAT& fmt)
{return Value->SetConstFormat(g, fmt);}
void Convert(PGLOBAL g, int newtype);
void SetValue(PVAL vp) {Value = vp;}
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *, uint);
}; // end of class CONSTANT
/***********************************************************************/
/* Class STRING handles variable length char strings. */
/* It is mainly used to avoid buffer overrun. */
/***********************************************************************/
class DllExport STRING : public BLOCK {
public:
// Constructor
STRING(PGLOBAL g, uint n, PSZ str = NULL);
// Implementation
inline int GetLength(void) {return (int)Length;}
inline PSZ GetStr(void) {return Strp;}
inline uint32 GetSize(void) {return Size;}
// Methods
inline void Reset(void) {*Strp = 0;}
bool Set(PSZ s);
bool Set(char *s, uint n);
bool Append(PSZ s);
bool Append(STRING &str);
bool Append(char c);
bool Resize(uint n);
inline void Trim(void) {(void)Resize(Length + 1);}
inline void Chop(void) {if (Length) Strp[--Length] = 0;}
inline void RepLast(char c) {if (Length) Strp[Length-1] = c;}
inline void Truncate(uint n) {if (n >= 0 && n < Length)
{Strp[n] = 0; Length = n;}}
protected:
char *Realloc(uint len);
inline char *GetNext(void)
{return ((char*)G->Sarea)+((PPOOLHEADER)G->Sarea)->To_Free;}
// Members
PGLOBAL G; // To avoid parameter
PSZ Strp; // The char string
uint Length; // String length
uint Size; // Allocated size
char *Next; // Next alloc position
}; // end of class STRING
#endif

View File

@@ -83,6 +83,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
// Methods
virtual bool IsSame(PTDB tp) {return tp == this;}
virtual bool IsSpecial(PSZ name) = 0;
virtual bool GetBlockValues(PGLOBAL g) {return false;}
virtual int Cardinality(PGLOBAL g) {return 0;}
virtual int GetMaxSize(PGLOBAL) = 0;
@@ -158,6 +159,7 @@ class DllExport TDBASE : public TDB {
// Methods
virtual bool IsUsingTemp(PGLOBAL g) {return false;}
virtual bool IsIndexed(void) {return false;}
virtual bool IsSpecial(PSZ name);
virtual PCATLG GetCat(void);
virtual PSZ GetPath(void);
virtual void PrintAM(FILE *f, char *m);