Commit 128136cb authored by Olivier Bertrand's avatar Olivier Bertrand

- Add support of partition tables

modified:
  storage/connect/ha_connect.cc
  storage/connect/ha_connect.h
  storage/connect/reldef.cpp

- Add INSERT/UPDATE support to PROXY tables
modified:
  storage/connect/tabutil.cpp
  storage/connect/tabutil.h

- Take care of SPECIAL columns
modified:
  storage/connect/filamdbf.cpp
  storage/connect/reldef.h
  storage/connect/tabfmt.cpp

-Typo and misc
modified:
  storage/connect/odbconn.cpp
  storage/connect/tabfix.cpp
  storage/connect/xindex.cpp
parents 9cb4b6c0 7bbcc3e4
......@@ -546,10 +546,11 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
PDOSDEF tdp = (PDOSDEF)Tdbp->GetDef();
// Count the number of columns
for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext()) {
reclen += cdp->GetLong();
n++;
} // endfor cdp
for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext())
if (!(cdp->Flags & U_SPECIAL)) {
reclen += cdp->GetLong();
n++;
} // endif Flags
if (Lrecl != reclen) {
sprintf(g->Message, MSG(BAD_LRECL), Lrecl, reclen);
......@@ -570,30 +571,31 @@ bool DBFFAM::AllocateBuffer(PGLOBAL g)
descp = (DESCRIPTOR*)header;
// Currently only standard Xbase types are supported
for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext()) {
descp++;
switch ((c = *GetFormatType(cdp->GetType()))) {
case 'S': // Short integer
case 'L': // Large (big) integer
case 'T': // Tiny integer
c = 'N'; // Numeric
case 'N': // Numeric (integer)
case 'F': // Float (double)
descp->Decimals = (uchar)cdp->F.Prec;
case 'C': // Char
case 'D': // Date
break;
default: // Should never happen
sprintf(g->Message, "Unsupported DBF type %c for column %s",
c, cdp->GetName());
return true;
} // endswitch c
strncpy(descp->Name, cdp->GetName(), 11);
descp->Type = c;
descp->Length = (uchar)cdp->GetLong();
} // endfor cdp
for (cdp = tdp->GetCols(); cdp; cdp = cdp->GetNext())
if (!(cdp->Flags & U_SPECIAL)) {
descp++;
switch ((c = *GetFormatType(cdp->GetType()))) {
case 'S': // Short integer
case 'L': // Large (big) integer
case 'T': // Tiny integer
c = 'N'; // Numeric
case 'N': // Numeric (integer)
case 'F': // Float (double)
descp->Decimals = (uchar)cdp->F.Prec;
case 'C': // Char
case 'D': // Date
break;
default: // Should never happen
sprintf(g->Message, "Unsupported DBF type %c for column %s",
c, cdp->GetName());
return true;
} // endswitch c
strncpy(descp->Name, cdp->GetName(), 11);
descp->Type = c;
descp->Length = (uchar)cdp->GetLong();
} // endif Flags
*(char*)(++descp) = EOH;
......
This diff is collapsed.
......@@ -201,11 +201,13 @@ public:
PIXDEF GetIndexInfo(TABLE_SHARE *s= NULL);
const char *GetDBName(const char *name);
const char *GetTableName(void);
char *GetPartName(void);
//int GetColNameLen(Field *fp);
//char *GetColName(Field *fp);
//void AddColName(char *cp, Field *fp);
TABLE *GetTable(void) {return table;}
bool IsSameIndex(PIXDEF xp1, PIXDEF xp2);
bool IsPartitioned(void);
PTDB GetTDB(PGLOBAL g);
int OpenTable(PGLOBAL g, bool del= false);
......@@ -520,7 +522,7 @@ protected:
PVAL sdvalin; // Used to convert date values
PVAL sdvalout; // Used to convert date values
bool istable; // True for table handler
//char tname[64]; // The table name
char partname[64]; // The partition name
MODE xmod; // Table mode
XINFO xinfo; // The table info structure
bool valid_info; // True if xinfo is valid
......
......@@ -2135,7 +2135,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
PSZ fnc = "Unknown";
UWORD n;
SWORD ncol, len, tp;
SQLULEN crow;
SQLULEN crow = 0;
PQRYRES qrp = cap->Qrp;
PCOLRES crp;
RETCODE rc = 0;
......
......@@ -132,19 +132,28 @@ int RELDEF::GetCharCatInfo(PSZ what, PSZ sdef, char *buf, int size)
/***********************************************************************/
char *RELDEF::GetStringCatInfo(PGLOBAL g, PSZ what, PSZ sdef)
{
char *sval= NULL, *s= Hc->GetStringOption(what, sdef);
char *name, *sval= NULL, *s= Hc->GetStringOption(what, sdef);
if (s) {
sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
strcpy(sval, s);
if (Hc->IsPartitioned() &&
(!stricmp(what, "filename") || !stricmp(what, "tabname"))) {
name= Hc->GetPartName();
sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + strlen(name));
sprintf(sval, s, name);
} else {
sval= (char*)PlugSubAlloc(g, NULL, strlen(s) + 1);
strcpy(sval, s);
} // endif partitioned
} else if (!stricmp(what, "filename")) {
// Return default file name
char *ftype= Hc->GetStringOption("Type", "*");
int i, n;
if (IsFileType(GetTypeID(ftype))) {
sval= (char*)PlugSubAlloc(g, NULL, strlen(Hc->GetTableName()) + 12);
strcat(strcpy(sval, Hc->GetTableName()), ".");
name= Hc->GetPartName();
sval= (char*)PlugSubAlloc(g, NULL, strlen(name) + 12);
strcat(strcpy(sval, name), ".");
n= strlen(sval);
// Fold ftype to lower case
......
......@@ -213,6 +213,7 @@ class DllExport COLDEF : public COLCRT { /* Column description block
void SetNbm(int nbm) {Nbm = nbm;}
int Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff);
void Define(PGLOBAL g, PCOL colp);
bool IsSpecial(void) {return (Flags & U_SPECIAL) ? true : false;}
protected:
void *To_Min; /* Point to array of block min values */
......
......@@ -132,6 +132,7 @@ int TDBFIX::ResetTableOpt(PGLOBAL g, bool dop, bool dox)
To_Filter = NULL; // Disable filtering
//To_BlkIdx = NULL; // and block filtering
To_BlkFil = NULL; // and index filtering
Cardinality(g); // If called by create
RestoreNrec(); // May have been modified
MaxSize = -1; // Size must be recalculated
Cardinal = -1; // as well as Cardinality
......
......@@ -406,7 +406,7 @@ bool CSVDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
// Double check correctness of offset values
if (Catfunc == FNC_NO)
for (PCOLDEF cdp = To_Cols; cdp; cdp = cdp->GetNext())
if (cdp->GetOffset() < 1) {
if (cdp->GetOffset() < 1 && !cdp->IsSpecial()) {
strcpy(g->Message, MSG(BAD_OFFSET_VAL));
return true;
} // endif Offset
......
......@@ -313,7 +313,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
if (!(tab = GetStringCatInfo(g, "Tabname", NULL))) {
if (!def) {
strcpy(g->Message, "Missing object table definition");
return TRUE;
return true;
} else
tab = "Noname";
......@@ -327,7 +327,7 @@ bool PRXDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Tablep = new(g) XTAB(tab, def);
Tablep->SetQualifier(db);
return FALSE;
return false;
} // end of DefineAM
/***********************************************************************/
......@@ -352,6 +352,28 @@ TDBPRX::TDBPRX(PPRXDEF tdp) : TDBASE(tdp)
Tdbp = NULL; // The object table
} // end of TDBPRX constructor
TDBPRX::TDBPRX(PGLOBAL g, PTDBPRX tdbp) : TDBASE(tdbp)
{
Tdbp = tdbp->Tdbp;
} // end of TDBPRX copy constructor
// Method
PTDB TDBPRX::CopyOne(PTABS t)
{
PTDB tp;
PPRXCOL cp1, cp2;
PGLOBAL g = t->G;
tp = new(g) TDBPRX(g, this);
for (cp1 = (PPRXCOL)Columns; cp1; cp1 = (PPRXCOL)cp1->GetNext()) {
cp2 = new(g) PRXCOL(cp1, tp); // Make a copy
NewPointer(t, cp1, cp2);
} // endfor cp1
return tp;
} // end of CopyOne
/***********************************************************************/
/* Get the PTDB of the sub-table. */
/***********************************************************************/
......@@ -423,7 +445,7 @@ PTDBASE TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b)
} else {
// Sub-table is a CONNECT table
tabp->Next = To_Table; // For loop checking
tdbp = cat->GetTable(g, tabp);
tdbp = cat->GetTable(g, tabp, Mode);
} // endif mysql
if (s) {
......@@ -456,11 +478,12 @@ bool TDBPRX::InitTable(PGLOBAL g)
if (!Tdbp) {
// Get the table description block of this table
if (!(Tdbp = GetSubTable(g, ((PPRXDEF)To_Def)->Tablep)))
return TRUE;
return true;
Tdbp->SetMode(Mode);
} // endif Tdbp
return FALSE;
return false;
} // end of InitTable
/***********************************************************************/
......@@ -507,32 +530,51 @@ bool TDBPRX::OpenDB(PGLOBAL g)
return Tdbp->OpenDB(g);
} // endif use
if (Mode != MODE_READ) {
if (Mode == MODE_DELETE) {
/*******************************************************************/
/* Currently XCOL tables cannot be modified. */
/*******************************************************************/
strcpy(g->Message, "PROXY tables are read only");
return TRUE;
strcpy(g->Message, "No DELETE for PROXY tables");
return true;
} // endif Mode
if (InitTable(g))
return TRUE;
return true;
/*********************************************************************/
/* Check and initialize the subtable columns. */
/*********************************************************************/
for (PCOL cp = Columns; cp; cp = cp->GetNext())
if (((PPRXCOL)cp)->Init(g))
return TRUE;
if (((PPRXCOL)cp)->Init(g, Tdbp))
return true;
/*********************************************************************/
/* In Update mode, the updated column blocks must be distinct from */
/* the read column blocks. So make a copy of the TDB and allocate */
/* its column blocks in mode write (required by XML tables). */
/*********************************************************************/
if (Mode == MODE_UPDATE) {
PTDBASE utp;
if (!(utp= (PTDBASE)Tdbp->Duplicate(g))) {
sprintf(g->Message, MSG(INV_UPDT_TABLE), Tdbp->GetName());
return true;
} // endif tp
for (PCOL cp = To_SetCols; cp; cp = cp->GetNext())
if (((PPRXCOL)cp)->Init(g, utp))
return true;
} // endif MODE_UPDATE
/*********************************************************************/
/* Physically open the object table. */
/*********************************************************************/
if (Tdbp->OpenDB(g))
return TRUE;
return true;
Use = USE_OPEN;
return FALSE;
return false;
} // end of OpenDB
/***********************************************************************/
......@@ -551,8 +593,9 @@ int TDBPRX::ReadDB(PGLOBAL g)
/***********************************************************************/
int TDBPRX::WriteDB(PGLOBAL g)
{
sprintf(g->Message, "%s tables are read only", To_Def->GetType());
return RC_FX;
//sprintf(g->Message, "%s tables are read only", To_Def->GetType());
//return RC_FX;
return Tdbp->WriteDB(g);
} // end of WriteDB
/***********************************************************************/
......@@ -594,7 +637,7 @@ PRXCOL::PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am)
//strcpy(F_Date, cdp->F_Date);
Colp = NULL;
To_Val = NULL;
Pseudo = FALSE;
Pseudo = false;
Colnum = cdp->GetOffset(); // If columns are retrieved by number
if (trace)
......@@ -602,30 +645,49 @@ PRXCOL::PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am)
} // end of PRXCOL constructor
/***********************************************************************/
/* PRXCOL constructor used for copying columns. */
/* tdbp is the pointer to the new table descriptor. */
/***********************************************************************/
PRXCOL::PRXCOL(PRXCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp)
{
Colp = col1->Colp;
To_Val = col1->To_Val;
Pseudo = col1->Pseudo;
Colnum = col1->Colnum;
} // end of PRXCOL copy constructor
/***********************************************************************/
/* PRXCOL initialization routine. */
/* Look for the matching column in the object table. */
/***********************************************************************/
bool PRXCOL::Init(PGLOBAL g)
bool PRXCOL::Init(PGLOBAL g, PTDBASE tp)
{
PTDBPRX tdbp = (PTDBPRX)To_Tdb;
if (!tp)
tp = ((PTDBPRX)To_Tdb)->Tdbp;
if (!(Colp = tdbp->Tdbp->ColDB(g, Name, 0)) && Colnum)
Colp = tdbp->Tdbp->ColDB(g, NULL, Colnum);
if (!(Colp = tp->ColDB(g, Name, 0)) && Colnum)
Colp = tp->ColDB(g, NULL, Colnum);
if (Colp) {
MODE mode = To_Tdb->GetMode();
// May not have been done elsewhere
Colp->InitValue(g);
To_Val = Colp->GetValue();
if (mode == MODE_INSERT || mode == MODE_UPDATE)
if (Colp->SetBuffer(g, Colp->GetValue(), true, false))
return true;
// this may be needed by some tables (which?)
Colp->SetColUse(ColUse);
} else {
sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tdbp->Tdbp->GetName());
return TRUE;
sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tp->GetName());
return true;
} // endif Colp
return FALSE;
return false;
} // end of Init
/***********************************************************************/
......@@ -659,6 +721,21 @@ void PRXCOL::ReadColumn(PGLOBAL g)
} // end of ReadColumn
/***********************************************************************/
/* WriteColumn: */
/***********************************************************************/
void PRXCOL::WriteColumn(PGLOBAL g)
{
if (trace > 1)
htrc("PRX WriteColumn: name=%s\n", Name);
if (Colp) {
To_Val->SetValue_pval(Value);
Colp->WriteColumn(g);
} // endif Colp
} // end of WriteColumn
/* ---------------------------TDBTBC class --------------------------- */
/***********************************************************************/
......
......@@ -57,13 +57,17 @@ class DllExport TDBPRX : public TDBASE {
friend class PRXDEF;
friend class PRXCOL;
public:
// Constructor
// Constructors
TDBPRX(PPRXDEF tdp);
TDBPRX(PGLOBAL g, PTDBPRX tdbp);
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_PRX;}
virtual PTDB Duplicate(PGLOBAL g)
{return (PTDB)new(g) TDBPRX(g, this);}
// Methods
virtual PTDB CopyOne(PTABS t);
virtual int GetRecpos(void) {return Tdbp->GetRecpos();}
virtual void ResetDB(void) {Tdbp->ResetDB();}
virtual int RowNumber(PGLOBAL g, bool b = FALSE);
......@@ -97,15 +101,19 @@ class DllExport PRXCOL : public COLBLK {
public:
// Constructors
PRXCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "PRX");
PRXCOL(PRXCOL *colp, PTDB tdbp); // Constructor used in copy process
// Implementation
virtual int GetAmType(void) {return TYPE_AM_PRX;}
virtual int GetAmType(void) {return TYPE_AM_PRX;}
// Methods
virtual void Reset(void);
virtual bool IsSpecial(void) {return Pseudo;}
virtual void ReadColumn(PGLOBAL g);
bool Init(PGLOBAL g);
virtual void Reset(void);
virtual bool IsSpecial(void) {return Pseudo;}
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check)
{return false;}
virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
bool Init(PGLOBAL g, PTDBASE tp = NULL);
protected:
// Default constructor not to be used
......
......@@ -2407,7 +2407,7 @@ void XFILE::Close(void)
#if defined(XMAP)
if (Mmp && CloseMemMap(Mmp->memory, Mmp->lenL))
printf("Error %d closing mapped index\n");
printf("Error closing mapped index\n");
#endif // XMAP
} // end of Close
......@@ -2574,8 +2574,8 @@ bool XHUGE::Open(PGLOBAL g, char *filename, int id, MODE mode)
} // endif Hfile
if (trace)
htrc(" rc=%d oflag=%p mode=%d handle=%d fn=%s\n",
rc, oflag, mode, Hfile, filename);
htrc(" oflag=%p mode=%d handle=%d fn=%s\n",
oflag, mode, Hfile, filename);
if (mode == MODE_INSERT) {
/*******************************************************************/
......
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