Commit 5d75457f authored by Olivier Bertrand's avatar Olivier Bertrand

- Implement the SERVID special columns. This imply modifying the way

  special columns are processed. This will be documented.
  Also some code cleanup and some changes to prepare the indexing of
  nullable columns (not achieve yet)

modified:
  storage/connect/colblk.cpp
  storage/connect/colblk.h
  storage/connect/connect.cc
  storage/connect/connect.h
  storage/connect/ha_connect.cc
  storage/connect/ha_connect.h
  storage/connect/macutil.cpp
  storage/connect/mycat.cc
  storage/connect/plgdbsem.h
  storage/connect/reldef.cpp
  storage/connect/reldef.h
  storage/connect/table.cpp
  storage/connect/tabmysql.cpp
  storage/connect/tabmysql.h
  storage/connect/tabodbc.h
  storage/connect/tabtbl.cpp
  storage/connect/tabutil.h
  storage/connect/value.h
  storage/connect/xindex.cpp
  storage/connect/xindex.h
  storage/connect/xtable.h
parent 98f3fd64
...@@ -350,8 +350,7 @@ TIDBLK::TIDBLK(PCOLUMN cp) : SPCBLK(cp) ...@@ -350,8 +350,7 @@ TIDBLK::TIDBLK(PCOLUMN cp) : SPCBLK(cp)
*Format.Type = 'C'; *Format.Type = 'C';
Format.Length = Long; Format.Length = Long;
Format.Prec = 1; // Case insensitive Format.Prec = 1; // Case insensitive
Constant = (To_Tdb->GetAmType() != TYPE_AM_PLG && Constant = (To_Tdb->GetAmType() != TYPE_AM_TBL);
To_Tdb->GetAmType() != TYPE_AM_PLM);
Tname = NULL; Tname = NULL;
} // end of TIDBLK constructor } // end of TIDBLK constructor
...@@ -367,3 +366,30 @@ void TIDBLK::ReadColumn(PGLOBAL g) ...@@ -367,3 +366,30 @@ void TIDBLK::ReadColumn(PGLOBAL g)
} // end of ReadColumn } // end of ReadColumn
/***********************************************************************/
/* SIDBLK constructor for the SERVID special column. */
/***********************************************************************/
SIDBLK::SIDBLK(PCOLUMN cp) : SPCBLK(cp)
{
//Is_Key = 2; for when the MUL table indexed reading will be implemented.
Long = 64;
Buf_Type = TYPE_STRING;
*Format.Type = 'C';
Format.Length = Long;
Format.Prec = 1; // Case insensitive
Constant = (To_Tdb->GetAmType() != TYPE_AM_TBL);
Sname = NULL;
} // end of TIDBLK constructor
/***********************************************************************/
/* ReadColumn: what this routine does is to return the server ID. */
/***********************************************************************/
void SIDBLK::ReadColumn(PGLOBAL g)
{
//if (Sname == NULL) {
Sname = (char*)To_Tdb->GetServer();
Value->SetValue_psz(Sname);
// } // endif Sname
} // end of ReadColumn
...@@ -62,7 +62,7 @@ class DllExport COLBLK : public XOBJECT { ...@@ -62,7 +62,7 @@ class DllExport COLBLK : public XOBJECT {
virtual bool SetFormat(PGLOBAL, FORMAT&); virtual bool SetFormat(PGLOBAL, FORMAT&);
virtual int CheckColumn(PGLOBAL g, PSQL sqlp, PXOB &xp, int &ag); virtual int CheckColumn(PGLOBAL g, PSQL sqlp, PXOB &xp, int &ag);
virtual bool IsSpecial(void) {return false;} virtual bool IsSpecial(void) {return false;}
virtual int CheckSpcCol(PTDB tdbp, int n) {return 2;} virtual int CheckSpcCol(PTDB tdbp, int n) {return 2;}
virtual bool CheckSort(PTDB tdbp); virtual bool CheckSort(PTDB tdbp);
virtual bool Eval(PGLOBAL g); virtual bool Eval(PGLOBAL g);
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check); virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
...@@ -168,7 +168,7 @@ class TIDBLK : public SPCBLK { ...@@ -168,7 +168,7 @@ class TIDBLK : public SPCBLK {
// Methods // Methods
virtual void Reset(void) {} // This is a pseudo constant column virtual void Reset(void) {} // This is a pseudo constant column
virtual int CheckSpcCol(PTDB tdbp, int n) virtual int CheckSpcCol(PTDB tdbp, int n)
{return (n == 3 && tdbp == To_Tdb) ? 1 : 2;} {return (n == 3 && tdbp == To_Tdb) ? 1 : 2;}
virtual void ReadColumn(PGLOBAL g); virtual void ReadColumn(PGLOBAL g);
protected: protected:
...@@ -179,4 +179,29 @@ class TIDBLK : public SPCBLK { ...@@ -179,4 +179,29 @@ class TIDBLK : public SPCBLK {
PSZ Tname; // The current table name PSZ Tname; // The current table name
}; // end of class TIDBLK }; // end of class TIDBLK
/***********************************************************************/
/* Class SIDBLK: SERVID special column descriptor. */
/***********************************************************************/
class SIDBLK : public SPCBLK {
public:
// Constructor
SIDBLK(PCOLUMN cp);
// Implementation
virtual int GetAmType(void) {return TYPE_AM_SRVID;}
// Methods
virtual void Reset(void) {} // This is a pseudo constant column
virtual int CheckSpcCol(PTDB tdbp, int n)
{return (n == 3 && tdbp == To_Tdb) ? 1 : 2;}
virtual void ReadColumn(PGLOBAL g);
protected:
// Default constructor not to be used
SIDBLK(void) {}
// Members
PSZ Sname; // The current server name
}; // end of class SIDBLK
#endif // __COLBLK__H #endif // __COLBLK__H
...@@ -239,7 +239,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -239,7 +239,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
char *p; char *p;
int i, n; int i, n;
PCOL colp; PCOL colp;
PCOLUMN cp; //PCOLUMN cp;
PDBUSER dup= PlgGetUser(g); PDBUSER dup= PlgGetUser(g);
if (xtrace) if (xtrace)
...@@ -251,6 +251,8 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -251,6 +251,8 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
return true; return true;
} // endif tdbp } // endif tdbp
tdbp->SetMode(mode);
if (!c1) { if (!c1) {
if (mode == MODE_INSERT) if (mode == MODE_INSERT)
// Allocate all column blocks for that table // Allocate all column blocks for that table
...@@ -261,12 +263,12 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -261,12 +263,12 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
if (xtrace) if (xtrace)
printf("Allocating column %s\n", p); printf("Allocating column %s\n", p);
if (*p == '*') { // if (*p == '*') {
// This is a special column // // This is a special column
cp= new(g) COLUMN(p + 1); // cp= new(g) COLUMN(p + 1);
cp->SetTo_Table(tdbp->GetTable()); // cp->SetTo_Table(tdbp->GetTable());
colp= ((PTDBASE)tdbp)->InsertSpcBlk(g, cp); // colp= ((PTDBASE)tdbp)->InsertSpcBlk(g, cp);
} else // } else
colp= tdbp->ColDB(g, p, 0); colp= tdbp->ColDB(g, p, 0);
if (!colp) { if (!colp) {
...@@ -330,7 +332,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2, ...@@ -330,7 +332,7 @@ bool CntOpenTable(PGLOBAL g, PTDB tdbp, MODE mode, char *c1, char *c2,
printf("Opening table %s in mode %d tdbp=%p\n", printf("Opening table %s in mode %d tdbp=%p\n",
tdbp->GetName(), mode, tdbp); tdbp->GetName(), mode, tdbp);
tdbp->SetMode(mode); //tdbp->SetMode(mode);
if (del && ((PTDBASE)tdbp)->GetFtype() != RECFM_NAF) { if (del && ((PTDBASE)tdbp)->GetFtype() != RECFM_NAF) {
// To avoid erasing the table when doing a partial delete // To avoid erasing the table when doing a partial delete
......
...@@ -47,20 +47,9 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len, ...@@ -47,20 +47,9 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
PGLOBAL CntExit(PGLOBAL g); PGLOBAL CntExit(PGLOBAL g);
/***********************************************************************/ /***********************************************************************/
/* Definition of classes XCOLCRT, XIXDEF, XKPDEF, DOXDEF, TDBDOX */ /* Definition of classes XKPDEF, DOXDEF, TDBDOX */
/* These classes purpose is chiefly to access protected items! */ /* These classes purpose is chiefly to access protected items! */
/***********************************************************************/ /***********************************************************************/
class XCOLCRT: public COLCRT {
friend class ha_connect;
friend bool CntCreateTable(PGLOBAL, char *, PCXF);
public:
XCOLCRT(PSZ name) : COLCRT(name) {Nulls= -1;} // Constructor
bool HasNulls(void) {return (Nulls != 0);}
private:
int Nulls;
}; // end of class XCOLCRT
class DOXDEF: public DOSDEF { class DOXDEF: public DOSDEF {
//friend class TDBDOX; //friend class TDBDOX;
//friend int MakeIndex(PGLOBAL, PTDB, PIXDEF); //friend int MakeIndex(PGLOBAL, PTDB, PIXDEF);
...@@ -87,11 +76,7 @@ class XKPDEF: public KPARTDEF { ...@@ -87,11 +76,7 @@ class XKPDEF: public KPARTDEF {
//friend int CntMakeIndex(PGLOBAL, const char *, PIXDEF); //friend int CntMakeIndex(PGLOBAL, const char *, PIXDEF);
friend int CntIndexInit(PGLOBAL, PTDB, int); friend int CntIndexInit(PGLOBAL, PTDB, int);
public: public:
XKPDEF(const char *name, int n) : KPARTDEF((PSZ)name, n) {HasNulls= false;} XKPDEF(const char *name, int n) : KPARTDEF((PSZ)name, n) {}
void SetNulls(bool b) {HasNulls= b;}
protected:
bool HasNulls; /* Can have null values */
}; // end of class XKPDEF }; // end of class XKPDEF
//RCODE CheckRecord(PGLOBAL g, PTDB tdbp, char *oldbuf, char *newbuf); //RCODE CheckRecord(PGLOBAL g, PTDB tdbp, char *oldbuf, char *newbuf);
...@@ -873,11 +873,13 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) ...@@ -873,11 +873,13 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
pcf->Flags= 0; pcf->Flags= 0;
// Now get column information // Now get column information
pcf->Name= (char*)fp->field_name;
if (fop && fop->special) { if (fop && fop->special) {
pcf->Name= "*"; pcf->Fieldfmt= (char*)fop->special;
pcf->Flags= U_SPECIAL;
return fldp; return fldp;
} else } // endif special
pcf->Name= (char*)fp->field_name;
pcf->Prec= 0; pcf->Prec= 0;
pcf->Opt= (fop) ? (int)fop->opt : 0; pcf->Opt= (fop) ? (int)fop->opt : 0;
...@@ -983,7 +985,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf) ...@@ -983,7 +985,7 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
if (fp->comment.str && fp->comment.length) { if (fp->comment.str && fp->comment.length) {
pcf->Remark= (char*)PlugSubAlloc(g, NULL, fp->comment.length + 1); pcf->Remark= (char*)PlugSubAlloc(g, NULL, fp->comment.length + 1);
memcpy(pcf->Remark, fp->comment.str, fp->comment.length); memcpy(pcf->Remark, fp->comment.str, fp->comment.length);
pcf->Remark[fp->comment.length] = 0; pcf->Remark[fp->comment.length]= 0;
} else } else
pcf->Remark= NULL; pcf->Remark= NULL;
...@@ -1071,6 +1073,7 @@ const char *ha_connect::GetTableName(void) ...@@ -1071,6 +1073,7 @@ const char *ha_connect::GetTableName(void)
return (tshp) ? tshp->table_name.str : table->s->table_name.str; return (tshp) ? tshp->table_name.str : table->s->table_name.str;
} // end of GetTableName } // end of GetTableName
#if 0
/****************************************************************************/ /****************************************************************************/
/* Returns the column real or special name length of a field. */ /* Returns the column real or special name length of a field. */
/****************************************************************************/ /****************************************************************************/
...@@ -1083,7 +1086,7 @@ int ha_connect::GetColNameLen(Field *fp) ...@@ -1083,7 +1086,7 @@ int ha_connect::GetColNameLen(Field *fp)
if (fop && fop->special) if (fop && fop->special)
n= strlen(fop->special) + 1; n= strlen(fop->special) + 1;
else else
n= strlen(fp->field_name) + 1; n= strlen(fp->field_name);
return n; return n;
} // end of GetColNameLen } // end of GetColNameLen
...@@ -1113,6 +1116,7 @@ void ha_connect::AddColName(char *cp, Field *fp) ...@@ -1113,6 +1116,7 @@ void ha_connect::AddColName(char *cp, Field *fp)
strcpy(cp, (char*)fp->field_name); strcpy(cp, (char*)fp->field_name);
} // end of AddColName } // end of AddColName
#endif // 0
/****************************************************************************/ /****************************************************************************/
/* Get the table description block of a CONNECT table. */ /* Get the table description block of a CONNECT table. */
...@@ -1174,20 +1178,21 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del) ...@@ -1174,20 +1178,21 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del)
char *p; char *p;
unsigned int k1, k2, n1, n2; unsigned int k1, k2, n1, n2;
Field* *field; Field* *field;
Field* fp;
MY_BITMAP *map= table->read_set; MY_BITMAP *map= table->read_set;
MY_BITMAP *ump= (xmod == MODE_UPDATE) ? table->write_set : NULL; MY_BITMAP *ump= (xmod == MODE_UPDATE) ? table->write_set : NULL;
k1= k2= 0; k1= k2= 0;
n1= n2= 1; // 1 is space for final null character n1= n2= 1; // 1 is space for final null character
for (field= table->field; *field; field++) { for (field= table->field; fp= *field; field++) {
if (bitmap_is_set(map, (*field)->field_index)) { if (bitmap_is_set(map, fp->field_index)) {
n1+= (GetColNameLen(*field) + 1); n1+= (strlen(fp->field_name) + 1);
k1++; k1++;
} // endif } // endif
if (ump && bitmap_is_set(ump, (*field)->field_index)) { if (ump && bitmap_is_set(ump, fp->field_index)) {
n2+= GetColNameLen(*field); n2+= (strlen(fp->field_name) + 1);
k2++; k2++;
} // endif } // endif
...@@ -1196,9 +1201,9 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del) ...@@ -1196,9 +1201,9 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del)
if (k1) { if (k1) {
p= c1= (char*)PlugSubAlloc(g, NULL, n1); p= c1= (char*)PlugSubAlloc(g, NULL, n1);
for (field= table->field; *field; field++) for (field= table->field; fp= *field; field++)
if (bitmap_is_set(map, (*field)->field_index)) { if (bitmap_is_set(map, fp->field_index)) {
AddColName(p, *field); strcpy(p, (char*)fp->field_name);
p+= (strlen(p) + 1); p+= (strlen(p) + 1);
} // endif used field } // endif used field
...@@ -1208,9 +1213,9 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del) ...@@ -1208,9 +1213,9 @@ bool ha_connect::OpenTable(PGLOBAL g, bool del)
if (k2) { if (k2) {
p= c2= (char*)PlugSubAlloc(g, NULL, n2); p= c2= (char*)PlugSubAlloc(g, NULL, n2);
for (field= table->field; *field; field++) for (field= table->field; fp= *field; field++)
if (bitmap_is_set(ump, (*field)->field_index)) { if (bitmap_is_set(ump, fp->field_index)) {
AddColName(p, *field); strcpy(p, (char*)fp->field_name);
p+= (strlen(p) + 1); p+= (strlen(p) + 1);
} // endif used field } // endif used field
...@@ -1309,7 +1314,7 @@ int ha_connect::MakeRecord(char *buf) ...@@ -1309,7 +1314,7 @@ int ha_connect::MakeRecord(char *buf)
if (bitmap_is_set(map, fp->field_index)) { if (bitmap_is_set(map, fp->field_index)) {
// This is a used field, fill the buffer with value // This is a used field, fill the buffer with value
for (colp= tdbp->GetColumns(); colp; colp= colp->GetNext()) for (colp= tdbp->GetColumns(); colp; colp= colp->GetNext())
if (!stricmp(colp->GetName(), GetColName(fp))) if (!stricmp(colp->GetName(), (char*)fp->field_name))
break; break;
if (!colp) { if (!colp) {
...@@ -1920,7 +1925,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1920,7 +1925,7 @@ int ha_connect::optimize(THD* thd, HA_CHECK_OPT* check_opt)
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message);
rc= 0; rc= 0;
} else } else
rc = HA_ERR_INTERNAL_ERROR; rc= HA_ERR_INTERNAL_ERROR;
} // endif's } // endif's
...@@ -3235,7 +3240,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) ...@@ -3235,7 +3240,7 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to)
/* We have to retrieve the information about this table options. */ /* We have to retrieve the information about this table options. */
ha_table_option_struct *pos; ha_table_option_struct *pos;
char key[MAX_DBKEY_LENGTH], db[128], tabname[128]; char key[MAX_DBKEY_LENGTH], db[128], tabname[128];
int rc = 0; int rc= 0;
uint key_length; uint key_length;
TABLE_SHARE *share; TABLE_SHARE *share;
THD *thd= current_thd; THD *thd= current_thd;
...@@ -3851,7 +3856,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -3851,7 +3856,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
dsn= (char*)PlugSubAlloc(g, NULL, strlen(dsn) + 1); dsn= (char*)PlugSubAlloc(g, NULL, strlen(dsn) + 1);
strncpy(dsn, create_info->connect_string.str, strncpy(dsn, create_info->connect_string.str,
create_info->connect_string.length); create_info->connect_string.length);
dsn[create_info->connect_string.length] = 0; dsn[create_info->connect_string.length]= 0;
mydef->SetName(create_info->alias); mydef->SetName(create_info->alias);
mydef->SetCat(cat); mydef->SetCat(cat);
...@@ -3876,7 +3881,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, ...@@ -3876,7 +3881,7 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd,
break; break;
#endif // WIN32 #endif // WIN32
case TAB_PIVOT: case TAB_PIVOT:
supfnc = FNC_NO; supfnc= FNC_NO;
case TAB_PRX: case TAB_PRX:
case TAB_TBL: case TAB_TBL:
case TAB_XCL: case TAB_XCL:
......
...@@ -158,9 +158,9 @@ class ha_connect: public handler ...@@ -158,9 +158,9 @@ class ha_connect: public handler
PIXDEF GetIndexInfo(void); PIXDEF GetIndexInfo(void);
const char *GetDBName(const char *name); const char *GetDBName(const char *name);
const char *GetTableName(void); const char *GetTableName(void);
int GetColNameLen(Field *fp); //int GetColNameLen(Field *fp);
char *GetColName(Field *fp); //char *GetColName(Field *fp);
void AddColName(char *cp, Field *fp); //void AddColName(char *cp, Field *fp);
TABLE *GetTable(void) {return table;} TABLE *GetTable(void) {return table;}
bool IsSameIndex(PIXDEF xp1, PIXDEF xp2); bool IsSameIndex(PIXDEF xp1, PIXDEF xp2);
......
...@@ -315,4 +315,4 @@ bool MACINFO::GetOneInfo(PGLOBAL g, int flag, void *v, int lv) ...@@ -315,4 +315,4 @@ bool MACINFO::GetOneInfo(PGLOBAL g, int flag, void *v, int lv)
*((int*)v) = n; *((int*)v) = n;
return false; return false;
} // end of ReadColumn } // end of GetOneInfo
...@@ -468,9 +468,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp) ...@@ -468,9 +468,9 @@ int MYCAT::GetColCatInfo(PGLOBAL g, PTABDEF defp)
break; break;
} // endswitch tc } // endswitch tc
do { // do {
field= Hc->GetColumnOption(g, field, pcf); field= Hc->GetColumnOption(g, field, pcf);
} while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/)); // } while (field && (*pcf->Name =='*' /*|| pcf->Flags & U_VIRTUAL*/));
if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) { if (tc == TAB_DBF && pcf->Type == TYPE_DATE && !pcf->Datefmt) {
// DBF date format defaults to 'YYYMMDD' // DBF date format defaults to 'YYYMMDD'
......
...@@ -319,7 +319,8 @@ enum COLUSE {U_P = 0x01, /* the projection list. */ ...@@ -319,7 +319,8 @@ enum COLUSE {U_P = 0x01, /* the projection list. */
U_VAR = 0x10, /* a VARCHAR column */ U_VAR = 0x10, /* a VARCHAR column */
U_VIRTUAL = 0x20, /* a VIRTUAL column */ U_VIRTUAL = 0x20, /* a VIRTUAL column */
U_NULLS = 0x40, /* The column may have nulls */ U_NULLS = 0x40, /* The column may have nulls */
U_IS_NULL = 0x80}; /* The column has a null value */ U_IS_NULL = 0x80, /* The column has a null value */
U_SPECIAL = 0x100}; /* The column is special */
/***********************************************************************/ /***********************************************************************/
/* DB description class and block pointer definitions. */ /* DB description class and block pointer definitions. */
......
...@@ -383,32 +383,35 @@ int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff) ...@@ -383,32 +383,35 @@ int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff)
Name = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Name) + 1); Name = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Name) + 1);
strcpy(Name, cfp->Name); strcpy(Name, cfp->Name);
Poff = poff; if (!(cfp->Flags & U_SPECIAL)) {
Buf_Type = cfp->Type; Poff = poff;
Buf_Type = cfp->Type;
if ((Clen = GetTypeSize(Buf_Type, cfp->Length)) <= 0) {
sprintf(g->Message, MSG(BAD_COL_TYPE), GetTypeName(Buf_Type), Name); if ((Clen = GetTypeSize(Buf_Type, cfp->Length)) <= 0) {
return -1; sprintf(g->Message, MSG(BAD_COL_TYPE), GetTypeName(Buf_Type), Name);
} // endswitch return -1;
} // endswitch
strcpy(F.Type, GetFormatType(Buf_Type));
F.Length = cfp->Length; strcpy(F.Type, GetFormatType(Buf_Type));
F.Prec = cfp->Prec; F.Length = cfp->Length;
Offset = (cfp->Offset < 0) ? poff : cfp->Offset; F.Prec = cfp->Prec;
Long = cfp->Length; Offset = (cfp->Offset < 0) ? poff : cfp->Offset;
Opt = cfp->Opt; Long = cfp->Length;
Key = cfp->Key; Opt = cfp->Opt;
//Freq = cfp->Freq; Key = cfp->Key;
// Freq = cfp->Freq;
if (cfp->Remark && *cfp->Remark) {
Desc = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Remark) + 1); if (cfp->Remark && *cfp->Remark) {
strcpy(Desc, cfp->Remark); Desc = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Remark) + 1);
} // endif Remark strcpy(Desc, cfp->Remark);
} // endif Remark
if (cfp->Datefmt) {
Decode = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Datefmt) + 1); if (cfp->Datefmt) {
strcpy(Decode, cfp->Datefmt); Decode = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Datefmt) + 1);
} // endif Datefmt strcpy(Decode, cfp->Datefmt);
} // endif Datefmt
} // endif special
if (cfp->Fieldfmt) { if (cfp->Fieldfmt) {
Fmt = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Fieldfmt) + 1); Fmt = (PSZ)PlugSubAlloc(g, memp, strlen(cfp->Fieldfmt) + 1);
...@@ -416,7 +419,7 @@ int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff) ...@@ -416,7 +419,7 @@ int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff)
} // endif Fieldfmt } // endif Fieldfmt
Flags = cfp->Flags; Flags = cfp->Flags;
return (Flags & U_VIRTUAL) ? 0 : Long; return (Flags & (U_VIRTUAL|U_SPECIAL)) ? 0 : Long;
} // end of Define } // end of Define
/* ------------------------- End of RelDef --------------------------- */ /* ------------------------- End of RelDef --------------------------- */
...@@ -175,6 +175,7 @@ class DllExport COLDEF : public COLCRT { /* Column description block ...@@ -175,6 +175,7 @@ class DllExport COLDEF : public COLCRT { /* Column description block
friend class MYCAT; friend class MYCAT;
friend class COLBLK; friend class COLBLK;
friend class DBFFAM; friend class DBFFAM;
friend class TDBASE;
public: public:
COLDEF(void); // Constructor COLDEF(void); // Constructor
......
...@@ -307,15 +307,17 @@ PCOL TDBASE::ColDB(PGLOBAL g, PSZ name, int num) ...@@ -307,15 +307,17 @@ PCOL TDBASE::ColDB(PGLOBAL g, PSZ name, int num)
/*****************************************************************/ /*****************************************************************/
if (cp) if (cp)
colp = cp; colp = cp;
else else if (!(cdp->Flags & U_SPECIAL))
colp = MakeCol(g, cdp, cprec, i); colp = MakeCol(g, cdp, cprec, i);
else if (Mode == MODE_READ)
colp = InsertSpcBlk(g, cdp);
if (trace) if (trace)
htrc("colp=%p\n", colp); htrc("colp=%p\n", colp);
if (name || num) if (name || num)
break; break;
else if (colp) else if (colp && !colp->IsSpecial())
cprec = colp; cprec = colp;
} // endif Name } // endif Name
...@@ -339,30 +341,35 @@ PCOL TDBASE::InsertSpecialColumn(PGLOBAL g, PCOL colp) ...@@ -339,30 +341,35 @@ PCOL TDBASE::InsertSpecialColumn(PGLOBAL g, PCOL colp)
/***********************************************************************/ /***********************************************************************/
/* Make a special COLBLK to insert in a table. */ /* Make a special COLBLK to insert in a table. */
/***********************************************************************/ /***********************************************************************/
PCOL TDBASE::InsertSpcBlk(PGLOBAL g, PCOLUMN cp) PCOL TDBASE::InsertSpcBlk(PGLOBAL g, PCOLDEF cdp)
{ {
char *name = (char*)cp->GetName(); //char *name = cdp->GetName();
PCOL colp; char *name = cdp->GetFmt();
PCOLUMN cp;
PCOL colp;
if (!strcmp(name, "FILEID")) { cp= new(g) COLUMN(cdp->GetName());
// !strcmp(name, "SERVID")) { cp->SetTo_Table(To_Table);
if (!stricmp(name, "FILEID") ||
!stricmp(name, "SERVID")) {
if (!To_Def || !(To_Def->GetPseudo() & 2)) { if (!To_Def || !(To_Def->GetPseudo() & 2)) {
sprintf(g->Message, MSG(BAD_SPEC_COLUMN)); sprintf(g->Message, MSG(BAD_SPEC_COLUMN));
return NULL; return NULL;
} // endif Pseudo } // endif Pseudo
// if (!strcmp(name, "FILEID")) if (!stricmp(name, "FILEID"))
colp = new(g) FIDBLK(cp); colp = new(g) FIDBLK(cp);
// else else
// colp = new(g) SIDBLK(cp); colp = new(g) SIDBLK(cp);
} else if (!strcmp(name, "TABID")) { } else if (!stricmp(name, "TABID")) {
colp = new(g) TIDBLK(cp); colp = new(g) TIDBLK(cp);
//} else if (!strcmp(name, "CONID")) { //} else if (!stricmp(name, "CONID")) {
// colp = new(g) CIDBLK(cp); // colp = new(g) CIDBLK(cp);
} else if (!strcmp(name, "ROWID")) { } else if (!stricmp(name, "ROWID")) {
colp = new(g) RIDBLK(cp, false); colp = new(g) RIDBLK(cp, false);
} else if (!strcmp(name, "ROWNUM")) { } else if (!stricmp(name, "ROWNUM")) {
colp = new(g) RIDBLK(cp, true); colp = new(g) RIDBLK(cp, true);
} else { } else {
sprintf(g->Message, MSG(BAD_SPECIAL_COL), name); sprintf(g->Message, MSG(BAD_SPECIAL_COL), name);
......
...@@ -194,6 +194,7 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url) ...@@ -194,6 +194,7 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url)
if (trace) if (trace)
htrc("server: %s Tabname: %s", url, Tabname); htrc("server: %s Tabname: %s", url, Tabname);
Server = url;
return GetServerInfo(g, url); return GetServerInfo(g, url);
} else { } else {
// URL, parse it // URL, parse it
...@@ -216,8 +217,10 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url) ...@@ -216,8 +217,10 @@ bool MYSQLDEF::ParseURL(PGLOBAL g, char *url)
if (!(Hostname = strchr(Username, '@'))) { if (!(Hostname = strchr(Username, '@'))) {
strcpy(g->Message, "No host specified in URL"); strcpy(g->Message, "No host specified in URL");
return true; return true;
} else } else {
*Hostname++ = 0; // End Username *Hostname++ = 0; // End Username
Server = Hostname;
} // endif Hostname
if ((Password = strchr(Username, ':'))) { if ((Password = strchr(Username, ':'))) {
*Password++ = 0; // End username *Password++ = 0; // End username
...@@ -308,6 +311,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -308,6 +311,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Username = Cat->GetStringCatInfo(g, "User", "*"); Username = Cat->GetStringCatInfo(g, "User", "*");
Password = Cat->GetStringCatInfo(g, "Password", NULL); Password = Cat->GetStringCatInfo(g, "Password", NULL);
Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort()); Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort());
Server = Hostname;
} else if (ParseURL(g, url)) } else if (ParseURL(g, url))
return TRUE; return TRUE;
...@@ -327,6 +331,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -327,6 +331,7 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
Username = Cat->GetStringCatInfo(g, "User", "*"); Username = Cat->GetStringCatInfo(g, "User", "*");
Password = Cat->GetStringCatInfo(g, "Password", NULL); Password = Cat->GetStringCatInfo(g, "Password", NULL);
Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort()); Portnumber = Cat->GetIntCatInfo("Port", GetDefaultPort());
Server = Hostname;
} else { } else {
char *locdb = Database; char *locdb = Database;
...@@ -365,13 +370,14 @@ PTDB MYSQLDEF::GetTable(PGLOBAL g, MODE m) ...@@ -365,13 +370,14 @@ PTDB MYSQLDEF::GetTable(PGLOBAL g, MODE m)
TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp) TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp)
{ {
if (tdp) { if (tdp) {
Host = tdp->GetHostname(); Host = tdp->Hostname;
Database = tdp->GetDatabase(); Database = tdp->Database;
Tabname = tdp->GetTabname(); Tabname = tdp->Tabname;
Srcdef = tdp->GetSrcdef(); Srcdef = tdp->Srcdef;
User = tdp->GetUsername(); User = tdp->Username;
Pwd = tdp->GetPassword(); Pwd = tdp->Password;
Port = tdp->GetPortnumber(); Server = tdp->Server;
Port = tdp->Portnumber;
Isview = tdp->Isview; Isview = tdp->Isview;
Prep = tdp->Bind; Prep = tdp->Bind;
Delayed = tdp->Delayed; Delayed = tdp->Delayed;
...@@ -382,6 +388,7 @@ TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp) ...@@ -382,6 +388,7 @@ TDBMYSQL::TDBMYSQL(PMYDEF tdp) : TDBASE(tdp)
Srcdef = NULL; Srcdef = NULL;
User = NULL; User = NULL;
Pwd = NULL; Pwd = NULL;
Server = NULL;
Port = 0; Port = 0;
Isview = FALSE; Isview = FALSE;
Prep = FALSE; Prep = FALSE;
...@@ -473,10 +480,11 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g) ...@@ -473,10 +480,11 @@ bool TDBMYSQL::MakeSelect(PGLOBAL g)
if (Columns) { if (Columns) {
for (colp = Columns; colp; colp = colp->GetNext()) for (colp = Columns; colp; colp = colp->GetNext())
if (colp->IsSpecial()) { if (!colp->IsSpecial()) {
strcpy(g->Message, MSG(NO_SPEC_COL)); // if (colp->IsSpecial()) {
return TRUE; // strcpy(g->Message, MSG(NO_SPEC_COL));
} else { // return TRUE;
// } else {
if (b) if (b)
strcat(Query, ", "); strcat(Query, ", ");
else else
...@@ -519,10 +527,11 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g) ...@@ -519,10 +527,11 @@ bool TDBMYSQL::MakeInsert(PGLOBAL g)
return FALSE; // already done return FALSE; // already done
for (colp = Columns; colp; colp = colp->GetNext()) for (colp = Columns; colp; colp = colp->GetNext())
if (colp->IsSpecial()) { if (!colp->IsSpecial()) {
strcpy(g->Message, MSG(NO_SPEC_COL)); // if (colp->IsSpecial()) {
return TRUE; // strcpy(g->Message, MSG(NO_SPEC_COL));
} else { // return TRUE;
// } else {
len += (strlen(colp->GetName()) + 4); len += (strlen(colp->GetName()) + 4);
((PMYCOL)colp)->Rank = Nparm++; ((PMYCOL)colp)->Rank = Nparm++;
} // endif colp } // endif colp
......
...@@ -49,6 +49,7 @@ class MYSQLDEF : public TABDEF {/* Logical table description */ ...@@ -49,6 +49,7 @@ class MYSQLDEF : public TABDEF {/* Logical table description */
PSZ Srcdef; /* The source table SQL definition */ PSZ Srcdef; /* The source table SQL definition */
PSZ Username; /* User logon name */ PSZ Username; /* User logon name */
PSZ Password; /* Password logon info */ PSZ Password; /* Password logon info */
PSZ Server; /* PServerID */
int Portnumber; /* MySQL port number (0 = default) */ int Portnumber; /* MySQL port number (0 = default) */
bool Isview; /* TRUE if this table is a MySQL view */ bool Isview; /* TRUE if this table is a MySQL view */
bool Bind; /* Use prepared statement on insert */ bool Bind; /* Use prepared statement on insert */
...@@ -77,6 +78,7 @@ class TDBMYSQL : public TDBASE { ...@@ -77,6 +78,7 @@ class TDBMYSQL : public TDBASE {
virtual void ResetDB(void) {N = 0;} virtual void ResetDB(void) {N = 0;}
virtual int RowNumber(PGLOBAL g, bool b = FALSE); virtual int RowNumber(PGLOBAL g, bool b = FALSE);
virtual bool IsView(void) {return Isview;} virtual bool IsView(void) {return Isview;}
virtual PSZ GetServer(void) {return Server;}
void SetDatabase(LPCSTR db) {Database = (char*)db;} void SetDatabase(LPCSTR db) {Database = (char*)db;}
// Database routines // Database routines
...@@ -110,6 +112,7 @@ class TDBMYSQL : public TDBASE { ...@@ -110,6 +112,7 @@ class TDBMYSQL : public TDBASE {
char *Database; // Database to be used by server char *Database; // Database to be used by server
char *Tabname; // External table name char *Tabname; // External table name
char *Srcdef; // The source table SQL definition char *Srcdef; // The source table SQL definition
char *Server; // The server ID
char *Query; // Points to SQL query char *Query; // Points to SQL query
char *Qbuf; // Used for not prepared insert char *Qbuf; // Used for not prepared insert
bool Fetched; // True when fetch was done bool Fetched; // True when fetch was done
......
...@@ -71,10 +71,11 @@ class TDBODBC : public TDBASE { ...@@ -71,10 +71,11 @@ class TDBODBC : public TDBASE {
// Methods // Methods
virtual PTDB CopyOne(PTABS t); virtual PTDB CopyOne(PTABS t);
virtual int GetRecpos(void); virtual int GetRecpos(void);
virtual PSZ GetFile(PGLOBAL g); virtual PSZ GetFile(PGLOBAL g);
virtual void SetFile(PGLOBAL g, PSZ fn); virtual void SetFile(PGLOBAL g, PSZ fn);
virtual void ResetSize(void); virtual void ResetSize(void);
virtual int GetAffectedRows(void) {return AftRows;} virtual int GetAffectedRows(void) {return AftRows;}
virtual PSZ GetServer(void) {return "ODBC";}
// Database routines // Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
......
...@@ -380,7 +380,8 @@ int TDBTBL::GetMaxSize(PGLOBAL g) ...@@ -380,7 +380,8 @@ int TDBTBL::GetMaxSize(PGLOBAL g)
void TDBTBL::ResetDB(void) void TDBTBL::ResetDB(void)
{ {
for (PCOL colp = Columns; colp; colp = colp->GetNext()) for (PCOL colp = Columns; colp; colp = colp->GetNext())
if (colp->GetAmType() == TYPE_AM_TABID) if (colp->GetAmType() == TYPE_AM_TABID ||
colp->GetAmType() == TYPE_AM_SRVID)
colp->COLBLK::Reset(); colp->COLBLK::Reset();
for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext()) for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext())
...@@ -492,7 +493,8 @@ int TDBTBL::ReadDB(PGLOBAL g) ...@@ -492,7 +493,8 @@ int TDBTBL::ReadDB(PGLOBAL g)
// Check and initialize the subtable columns // Check and initialize the subtable columns
for (PCOL cp = Columns; cp; cp = cp->GetNext()) for (PCOL cp = Columns; cp; cp = cp->GetNext())
if (cp->GetAmType() == TYPE_AM_TABID) if (cp->GetAmType() == TYPE_AM_TABID ||
cp->GetAmType() == TYPE_AM_SRVID)
cp->COLBLK::Reset(); cp->COLBLK::Reset();
else if (((PPRXCOL)cp)->Init(g) && !Accept) else if (((PPRXCOL)cp)->Init(g) && !Accept)
return RC_FX; return RC_FX;
......
...@@ -70,6 +70,7 @@ class DllExport TDBPRX : public TDBASE { ...@@ -70,6 +70,7 @@ class DllExport TDBPRX : public TDBASE {
virtual int GetRecpos(void) {return Tdbp->GetRecpos();} virtual int GetRecpos(void) {return Tdbp->GetRecpos();}
virtual void ResetDB(void) {Tdbp->ResetDB();} virtual void ResetDB(void) {Tdbp->ResetDB();}
virtual int RowNumber(PGLOBAL g, bool b = FALSE); virtual int RowNumber(PGLOBAL g, bool b = FALSE);
virtual PSZ GetServer(void) {return (Tdbp) ? Tdbp->GetServer() : "?";}
// Database routines // Database routines
virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n);
......
...@@ -83,6 +83,7 @@ class DllExport VALUE : public BLOCK { ...@@ -83,6 +83,7 @@ class DllExport VALUE : public BLOCK {
virtual void SetPrec(int prec) {Prec = prec;} virtual void SetPrec(int prec) {Prec = prec;}
bool IsNull(void) {return Null;} bool IsNull(void) {return Null;}
void SetNull(bool b) {Null = b;} void SetNull(bool b) {Null = b;}
bool GetNullable(void) {return Nullable;}
void SetNullable(bool b) {Nullable = b;} void SetNullable(bool b) {Nullable = b;}
int GetType(void) {return Type;} int GetType(void) {return Type;}
int GetClen(void) {return Clen;} int GetClen(void) {return Clen;}
......
...@@ -2797,7 +2797,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln) ...@@ -2797,7 +2797,7 @@ bool KXYCOL::Init(PGLOBAL g, PCOL colp, int n, bool sm, int kln)
if (Asc) if (Asc)
IsSorted = colp->GetOpt() < 0; IsSorted = colp->GetOpt() < 0;
//MayHaveNulls = colp->HasNulls(); //SetNulls(colp->IsNullable()); for when null columns will be indexable
return false; return false;
} // end of Init } // end of Init
...@@ -2956,6 +2956,11 @@ void KXYCOL::InitBinFind(void *vp) ...@@ -2956,6 +2956,11 @@ void KXYCOL::InitBinFind(void *vp)
void KXYCOL::FillValue(PVAL valp) void KXYCOL::FillValue(PVAL valp)
{ {
valp->SetValue_pvblk(Kblp, Val_K); valp->SetValue_pvblk(Kblp, Val_K);
// Set null when applicable (NIY)
//if (valp->GetNullable())
// valp->SetNull(valp->IsZero());
} // end of FillValue } // end of FillValue
/***********************************************************************/ /***********************************************************************/
......
...@@ -473,10 +473,10 @@ class KXYCOL: public BLOCK { ...@@ -473,10 +473,10 @@ class KXYCOL: public BLOCK {
protected: protected:
// Members // Members
PXCOL Next; // To next in the key part list PXCOL Next; // To next in the key part list
PXCOL Previous; // To previous in the key part list PXCOL Previous; // To previous in the key part list
PKXBASE Kxp; // To the INDEX class block PKXBASE Kxp; // To the INDEX class block
PCOL Colp; // To matching object if a column PCOL Colp; // To matching object if a column
bool IsSorted; // true if column is already sorted bool IsSorted; // true if column is already sorted
bool Asc; // true for ascending sort, false for Desc bool Asc; // true for ascending sort, false for Desc
MBLOCK Keys; // Data array allocation block MBLOCK Keys; // Data array allocation block
......
...@@ -113,6 +113,7 @@ class DllExport TDB: public TBX { // Table Descriptor Block. ...@@ -113,6 +113,7 @@ class DllExport TDB: public TBX { // Table Descriptor Block.
{fprintf(f, "%s AM(%d)\n", m, GetAmType());} {fprintf(f, "%s AM(%d)\n", m, GetAmType());}
virtual void Print(PGLOBAL g, FILE *f, uint n); virtual void Print(PGLOBAL g, FILE *f, uint n);
virtual void Print(PGLOBAL g, char *ps, uint z); virtual void Print(PGLOBAL g, char *ps, uint z);
virtual PSZ GetServer(void) = 0;
// Database pure virtual routines // Database pure virtual routines
virtual PCOL ColDB(PGLOBAL g, PSZ name, int num) = 0; virtual PCOL ColDB(PGLOBAL g, PSZ name, int num) = 0;
...@@ -192,13 +193,14 @@ class DllExport TDBASE : public TDB { ...@@ -192,13 +193,14 @@ class DllExport TDBASE : public TDB {
virtual void ResetSize(void) {MaxSize = -1;} virtual void ResetSize(void) {MaxSize = -1;}
virtual void RestoreNrec(void) {} virtual void RestoreNrec(void) {}
virtual int ResetTableOpt(PGLOBAL g, bool dox); virtual int ResetTableOpt(PGLOBAL g, bool dox);
virtual PSZ GetServer(void) {return "Current";}
// Database routines // Database routines
virtual PCOL ColDB(PGLOBAL g, PSZ name, int num); virtual PCOL ColDB(PGLOBAL g, PSZ name, int num);
virtual PCOL MakeCol(PGLOBAL, PCOLDEF, PCOL, int) virtual PCOL MakeCol(PGLOBAL, PCOLDEF, PCOL, int)
{assert(false); return NULL;} {assert(false); return NULL;}
virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL colp); virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL colp);
virtual PCOL InsertSpcBlk(PGLOBAL g, PCOLUMN cp); virtual PCOL InsertSpcBlk(PGLOBAL g, PCOLDEF cdp);
virtual void MarkDB(PGLOBAL g, PTDB tdb2); virtual void MarkDB(PGLOBAL g, PTDB tdb2);
protected: protected:
......
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