diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index b2303b07de8..7422815223f 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -3392,21 +3392,6 @@ static int connect_assisted_discovery(handlerton *hton, THD* thd, } // endif tab - // Check whether a table is defined on itself - switch (ttp) { - case TAB_PRX: - case TAB_XCL: - case TAB_TBL: - case TAB_OCCUR: - if (!stricmp(tab, create_info->alias) && - !stricmp(db, thd->db)) { - sprintf(g->Message, "A %s table cannot refer to itself", topt->type); - my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); - return HA_ERR_INTERNAL_ERROR; - } // endif tab - - } // endswitch ttp - switch (ttp) { #if defined(ODBC_SUPPORT) case TAB_ODBC: @@ -3758,7 +3743,8 @@ int ha_connect::create(const char *name, TABLE *table_arg, Field *fp; TABTYPE type; TABLE *st= table; // Probably unuseful - xp= GetUser(ha_thd(), xp); + THD *thd= ha_thd(); + xp= GetUser(thd, xp); PGLOBAL g= xp->g; DBUG_ENTER("ha_connect::create"); @@ -3768,7 +3754,27 @@ int ha_connect::create(const char *name, TABLE *table_arg, DBUG_ASSERT(options); type= GetTypeID(options->type); - if (check_privileges(ha_thd(), options)) + // Check table type + if (type == TAB_UNDEF) { + if (!options->tabname) { + strcpy(g->Message, "No table_type. Will be set to DOS"); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + type= TAB_DOS; + options->type= "DOS"; + } else { + strcpy(g->Message, "No table_type. Will be set to PROXY"); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + type= TAB_PRX; + options->type= "PROXY"; + } // endif fnc + + } else if (type == TAB_NIY) { + sprintf(g->Message, "Unsupported table type %s", options->type); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + DBUG_RETURN(HA_ERR_INTERNAL_ERROR); + } // endif ttp + + if (check_privileges(thd, options)) DBUG_RETURN(HA_ERR_INTERNAL_ERROR); if (options->data_charset) { @@ -3795,6 +3801,21 @@ int ha_connect::create(const char *name, TABLE *table_arg, } else dbf= (GetTypeID(options->type) == TAB_DBF && !options->catfunc); + // Check whether a table is defined on itself + switch (type) { + case TAB_PRX: + case TAB_XCL: + case TAB_OCCUR: + if (!stricmp(options->tabname, create_info->alias) && + (!options->dbname || !stricmp(options->dbname, thd->db))) { + sprintf(g->Message, "A %s table cannot refer to itself", + options->type); + my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0)); + return HA_ERR_INTERNAL_ERROR; + } // endif tab + + } // endswitch ttp + if (type == TAB_XML) { bool dom; // True: MS-DOM, False libxml2 char *xsup= GetListOption(g, "Xmlsup", options->oplist, "*"); @@ -3964,8 +3985,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, strcat(strcat(buf, "."), lwt); sprintf(g->Message, "No file name. Table will use %s", buf); - push_warning(table->in_use, - MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, g->Message); strcat(strcat(strcpy(dbpath, "./"), table->s->db.str), "/"); PlugSetPath(fn, buf, dbpath); @@ -3994,7 +4014,7 @@ int ha_connect::create(const char *name, TABLE *table_arg, // We should be in CREATE TABLE if (table->in_use->lex->sql_command != SQLCOM_CREATE_TABLE) - push_warning(table->in_use, MYSQL_ERROR::WARN_LEVEL_WARN, 0, + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0, "Wrong command in create, please contact CONNECT team"); // Get the index definitions diff --git a/storage/connect/mysql-test/connect/r/tbl.result b/storage/connect/mysql-test/connect/r/tbl.result index 01a6afcebe8..bc77516c22d 100644 --- a/storage/connect/mysql-test/connect/r/tbl.result +++ b/storage/connect/mysql-test/connect/r/tbl.result @@ -4,6 +4,9 @@ CREATE TABLE t1 ( a INT NOT NULL, message CHAR(10)) ENGINE=connect; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos INSERT INTO t1 VALUES (1,'Testing'),(2,'dos table'),(3,'t1'); SELECT * FROM t1; a message diff --git a/storage/connect/mysql-test/connect/r/upd.result b/storage/connect/mysql-test/connect/r/upd.result index 24cfdafaa9a..fa519c4b688 100644 --- a/storage/connect/mysql-test/connect/r/upd.result +++ b/storage/connect/mysql-test/connect/r/upd.result @@ -59,6 +59,9 @@ END// # Testing DOS table changes # CREATE TABLE t1 ENGINE=connect AS SELECT * FROM employee; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos CALL test.tst_up(); serialno name sex title manager department secretary salary 74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00 @@ -154,6 +157,9 @@ serialno name sex title manager department secretary salary # Testing DOS table changes # CREATE TABLE t1 ENGINE=connect mapped=yes AS SELECT * FROM employee; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos CALL test.tst_up(); serialno name sex title manager department secretary salary 74200 BANCROFT 2 SALESMAN 70012 0318 24888 9600.00 diff --git a/storage/connect/tabcol.h b/storage/connect/tabcol.h index 5cc2050f872..8c21fe6d1b2 100644 --- a/storage/connect/tabcol.h +++ b/storage/connect/tabcol.h @@ -15,7 +15,8 @@ /***********************************************************************/ /* Definition of class XTAB with all its method functions. */ /***********************************************************************/ - class DllExport XTAB: public BLOCK { // Table Name-Owner-Correl block. +class DllExport XTAB: public BLOCK { // Table Name-Owner-Correl block. + friend class TDBPRX; public: // Constructors XTAB(LPCSTR name, LPCSTR correl = NULL); diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 2af1055e8e1..b3401530c1b 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -283,25 +283,36 @@ bool MYSQLDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) Desc = "MySQL Table"; - if (!stricmp(am, "MYPRX")) - // MYSQL access from a PROXY table, - // we must get parms from the calling table - Remove_tshp(Cat); + if (!stricmp(am, "MYPRX")) { + // Normal case of specific MYSQL table + if (!url || !*url) { + // Not using the connection URL + Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); + Database = Cat->GetStringCatInfo(g, "Database", "*"); + Tabname = Cat->GetStringCatInfo(g, "Name", Name); // Deprecated + Tabname = Cat->GetStringCatInfo(g, "Tabname", Tabname); + Username = Cat->GetStringCatInfo(g, "User", "*"); + Password = Cat->GetStringCatInfo(g, "Password", NULL); + Portnumber = Cat->GetIntCatInfo("Port", mysqld_port); + } else if (ParseURL(g, url)) + return TRUE; - if (!url || !*url) { - // Not using the connection URL - Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); + Bind = !!Cat->GetIntCatInfo("Bind", 0); + Delayed = !!Cat->GetIntCatInfo("Delayed", 0); + } else { + // MYSQL access from a PROXY table, not using URL Database = Cat->GetStringCatInfo(g, "Database", "*"); Tabname = Cat->GetStringCatInfo(g, "Name", Name); // Deprecated Tabname = Cat->GetStringCatInfo(g, "Tabname", Tabname); + + // We must get connection parms from the calling table + Remove_tshp(Cat); + Hostname = Cat->GetStringCatInfo(g, "Host", "localhost"); Username = Cat->GetStringCatInfo(g, "User", "*"); Password = Cat->GetStringCatInfo(g, "Password", NULL); Portnumber = Cat->GetIntCatInfo("Port", mysqld_port); - } else if (ParseURL(g, url)) - return TRUE; + } // endif am - Bind = !!Cat->GetIntCatInfo("Bind", 0); - Delayed = !!Cat->GetIntCatInfo("Delayed", 0); return FALSE; } // end of DefineAM diff --git a/storage/connect/taboccur.cpp b/storage/connect/taboccur.cpp index e1b83c06422..8b7e10f2e34 100644 --- a/storage/connect/taboccur.cpp +++ b/storage/connect/taboccur.cpp @@ -60,7 +60,6 @@ extern "C" int trace; /***********************************************************************/ bool OCCURDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) { -//Tabname = Cat->GetStringCatInfo(g, "SrcTable", ""); Xcol = Cat->GetStringCatInfo(g, "OccurCol", ""); Rcol = Cat->GetStringCatInfo(g, "RankCol", ""); Colist = Cat->GetStringCatInfo(g, "Colist", ""); @@ -72,22 +71,9 @@ bool OCCURDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) /***********************************************************************/ PTDB OCCURDEF::GetTable(PGLOBAL g, MODE m) { - if (Catfunc != FNC_COL) { - PTDB tdbp; - PTDBOCCUR tocp = new(g) TDBOCCUR(this); - - // Check that the source table is available - if (!tocp || !(tdbp = tocp->GetSubTable(g, Tablep))) - return NULL; - - // Set Tdbp now - tocp->SetTdbp((PTDBASE)tdbp); - - if (tocp->MakeColumnList(g) < 0) - return NULL; - - return tocp; - } else + if (Catfunc != FNC_COL) + return new(g) TDBOCCUR(this); + else return new(g) TDBTBC(this); } // end of GetTable @@ -145,6 +131,24 @@ PCOL TDBOCCUR::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n) return colp; } // end of MakeCol +/***********************************************************************/ +/* Initializes the table. */ +/***********************************************************************/ +bool TDBOCCUR::InitTable(PGLOBAL g) + { + if (!Tdbp) { + // Get the table description block of this table + if (!(Tdbp = (PTDBASE)GetSubTable(g, ((POCCURDEF)To_Def)->Tablep))) + return TRUE; + + if (MakeColumnList(g) < 0) + return TRUE; + + } // endif Tdbp + + return FALSE; + } // end of InitTable + /***********************************************************************/ /* Allocate OCCUR column description block. */ /***********************************************************************/ @@ -199,7 +203,9 @@ int TDBOCCUR::MakeColumnList(PGLOBAL g) int TDBOCCUR::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { -// Mult = MakeColumnList(g); + if (InitTable(g)) + return NULL; + MaxSize = Mult * Tdbp->GetMaxSize(g); } // endif MaxSize @@ -233,12 +239,7 @@ bool TDBOCCUR::OpenDB(PGLOBAL g) return Tdbp->OpenDB(g); } // endif use - /*********************************************************************/ - /* Do it here if not done yet. */ - /*********************************************************************/ -// if (MakeColumnList(g) < 0) -// return TRUE; - + if (Mode != MODE_READ) { /*******************************************************************/ /* Currently OCCUR tables cannot be modified. */ @@ -247,21 +248,11 @@ bool TDBOCCUR::OpenDB(PGLOBAL g) return TRUE; } // endif Mode -#if 0 /*********************************************************************/ - /* Be sure OCCUR column exist. */ + /* Do it here if not done yet. */ /*********************************************************************/ - if (!Xcolp) { - if (!(Xcolp = (POCCURCOL)ColDB(g, Xcolumn, 0))) { - sprintf(g->Message, "OCCUR column %s definition error", Xcolumn); - return TRUE; - } else if (Xcolp->InitValue(g)) { - strcpy(g->Message, "OCCUR InitValue failed"); - return TRUE; - } // endif's Xcolp - - } // endif Xcolp -#endif // 0 + if (InitTable(g)) + return NULL; if (Xcolp) // Lock this column so it is evaluated by its table only diff --git a/storage/connect/taboccur.h b/storage/connect/taboccur.h index 0cfabf87793..c0077a0b33e 100644 --- a/storage/connect/taboccur.h +++ b/storage/connect/taboccur.h @@ -37,7 +37,6 @@ class OCCURDEF : public PRXDEF { /* Logical table description */ protected: // Members -//char *Tabname; /* The source table name */ char *Colist; /* The source column list */ char *Xcol; /* The multiple occurence column */ char *Rcol; /* The rank column */ @@ -59,15 +58,14 @@ class TDBOCCUR : public TDBPRX { void SetTdbp(PTDBASE tdbp) {Tdbp = tdbp;} // Methods -//virtual int GetRecpos(void) {return N;} virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} virtual int RowNumber(PGLOBAL g, bool b = FALSE); PTDB GetSourceTable(PGLOBAL g); int MakeColumnList(PGLOBAL g); // Database routines -//virtual PCOL ColDB(PGLOBAL g, PSZ colname, int num); virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); + virtual bool InitTable(PGLOBAL g); virtual int GetMaxSize(PGLOBAL g); virtual bool OpenDB(PGLOBAL g); virtual int ReadDB(PGLOBAL g); @@ -94,7 +92,6 @@ class OCCURCOL : public COLBLK { public: // Constructors OCCURCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n); -//OCCURCOL(OCCURCOL *colp, PTDB tdbp); // Constructor used in copy process // Implementation virtual int GetAmType(void) {return TYPE_AM_OCCUR;} @@ -120,7 +117,6 @@ class RANKCOL : public COLBLK { public: // Constructors RANKCOL(PCOLDEF cdp, PTDBOCCUR tdbp, int n) : COLBLK(cdp, tdbp, n) {} -//RANKCOL(RANKCOL *colp, PTDB tdbp); // Constructor used in copy process // Implementation virtual int GetAmType(void) {return TYPE_AM_OCCUR;} diff --git a/storage/connect/tabtbl.cpp b/storage/connect/tabtbl.cpp index c1286785d73..5a2089d04d6 100644 --- a/storage/connect/tabtbl.cpp +++ b/storage/connect/tabtbl.cpp @@ -209,65 +209,6 @@ PCOL TDBTBL::InsertSpecialColumn(PGLOBAL g, PCOL scp) return colp; } // end of InsertSpecialColumn -#if 0 -/***********************************************************************/ -/* Get the PTDB of a table of the list. */ -/***********************************************************************/ -PTDB TDBTBL::GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp) - { -//char *db; - bool mysql; - PTDB tdbp = NULL; - TABLE_SHARE *s; - PCATLG cat = To_Def->GetCat(); - PHC hc = ((MYCAT*)cat)->GetHandler(); - THD *thd = (hc->GetTable())->in_use; - - if (!thd) - return NULL; // Should not happen anymore - -//if (tblp->DB) -// db = tblp->DB; -//else -// db = (char*)hc->GetDBName(NULL); - -//if (!(s = GetTableShare(g, thd, db, tblp->Name, mysql))) - if (!(s = GetTableShare(g, thd, tblp->DB, tblp->Name, mysql))) - return NULL; - - if (mysql) { -#if defined(MYSQL_SUPPORT) - // Access sub-table via MySQL API - if (!(tdbp= cat->GetTable(g, tabp, MODE_READ, "MYSQL"))) { - sprintf(g->Message, "Cannot access %s.%s", tblp->DB, tblp->Name); - goto err; - } // endif Define - - if (tabp->GetQualifier()) - ((PTDBMY)tdbp)->SetDatabase(tabp->GetQualifier()); - -#else // !MYSQL_SUPPORT - sprintf(g->Message, "%s.%s is not a CONNECT table", - db, tblp->Name); - goto err; -#endif // MYSQL_SUPPORT - } else { - // Sub-table is a CONNECT table - hc->tshp = s; - tdbp = cat->GetTable(g, tabp); - hc->tshp = NULL; - } // endif plugin - - if (trace && tdbp) - htrc("Subtable %s in %s\n", - tblp->Name, SVP(((PTDBASE)tdbp)->GetDef()->GetDB())); - - err: - free_table_share(s); - return tdbp; - } // end of GetSubTable -#endif // 0 - /***********************************************************************/ /* Initializes the table table list. */ /***********************************************************************/ @@ -293,7 +234,8 @@ bool TDBTBL::InitTableList(PGLOBAL g) else continue; // Skip this table - } // endif tdbp + } else + RemoveNext(tabp); // To avoid looping // We must allocate subtable columns before GetMaxSize is called // because some (PLG, ODBC?) need to have their columns attached. @@ -393,80 +335,18 @@ bool TDBTBL::TestFil(PGLOBAL g, PFIL filp, PTABLE tabp) return TRUE; // invalid operator } // end of TestFil -#if 0 -/***********************************************************************/ -/* TBL GetProgMax: get the max value for progress information. */ -/***********************************************************************/ -int TDBTBL::GetProgMax(PGLOBAL g) - { - int n, pmx = 0; - - if (!Tablist && InitTableList(g)) - return -1; - - for (PTABLE tabp = Tablist; tabp; tblp = tabp->GetNext()) - if ((n = tabp->GetTo_Tdb()->GetProgMax(g)) > 0) - pmx += n; - - return pmx; - } // end of GetProgMax - -/***********************************************************************/ -/* TBL GetProgCur: get the current value for progress information. */ -/***********************************************************************/ -int TDBTBL::GetProgCur(void) - { - return Crp + Tdbp->GetProgCur(); - } // end of GetProgCur - -/***********************************************************************/ -/* TBL Cardinality: returns table cardinality in number of rows. */ -/* This function can be called with a null argument to test the */ -/* availability of Cardinality implementation (1 yes, 0 no). */ -/* Can be used on Multiple FIX table only. */ -/***********************************************************************/ -int TDBTBL::Cardinality(PGLOBAL g) - { - if (!g) - return Tdbp->Cardinality(g); - - if (!Tablist && InitTableList(g)) - return -1; - - int n, card = 0; - - for (int i = 0; i < NumFiles; i++) { - Tdbp->SetFile(g, Filenames[i]); - Tdbp->ResetSize(); - - if ((n = Tdbp->Cardinality(g)) < 0) { -// strcpy(g->Message, MSG(BAD_CARDINALITY)); - return -1; - } // endif n - - card += n; - } // endfor i - - return card; - } // end of Cardinality -#endif // 0 - /***********************************************************************/ /* Sum up the sizes of all sub-tables. */ /***********************************************************************/ int TDBTBL::GetMaxSize(PGLOBAL g) { if (MaxSize < 0) { - int mxsz; + int mxsz; if (!Tablist && InitTableList(g)) return 0; // Cannot be calculated at this stage -// if (Use == USE_OPEN) { -// strcpy(g->Message, MSG(MAXSIZE_ERROR)); -// return -1; -// } else - MaxSize = 0; + MaxSize = 0; for (PTABLE tabp = Tablist; tabp; tabp = tabp->GetNext()) { if ((mxsz = tabp->GetTo_Tdb()->GetMaxSize(g)) < 0) { @@ -524,17 +404,6 @@ bool TDBTBL::OpenDB(PGLOBAL g) return Tdbp->OpenDB(g); // Re-open fist table } // endif use -#if 0 - /*********************************************************************/ - /* Direct access needed for join or sorting. */ - /*********************************************************************/ - if (NeedIndexing(g)) { - // Direct access of TBL tables is not implemented yet - strcpy(g->Message, MSG(NO_MUL_DIR_ACC)); - return TRUE; - } // endif NeedIndexing -#endif // 0 - /*********************************************************************/ /* When GetMaxsize was called, To_Filter was not set yet. */ /*********************************************************************/ @@ -634,144 +503,6 @@ int TDBTBL::ReadDB(PGLOBAL g) return rc; } // end of ReadDB -#if 0 -/***********************************************************************/ -/* Data Base write routine for MUL access method. */ -/***********************************************************************/ -int TDBTBL::WriteDB(PGLOBAL g) - { - strcpy(g->Message, MSG(TABMUL_READONLY)); - return RC_FX; // NIY - } // end of WriteDB - -/***********************************************************************/ -/* Data Base delete line routine for MUL access method. */ -/***********************************************************************/ -int TDBTBL::DeleteDB(PGLOBAL g, int irc) - { - strcpy(g->Message, MSG(TABMUL_READONLY)); - return RC_FX; // NIY - } // end of DeleteDB - -/***********************************************************************/ -/* Data Base close routine for MUL access method. */ -/***********************************************************************/ -void TDBTBL::CloseDB(PGLOBAL g) - { - if (Tdbp) - Tdbp->CloseDB(g); - - } // end of CloseDB -#endif // 0 - -/* ---------------------------- TBLCOL ------------------------------- */ - -#if 0 -/***********************************************************************/ -/* TBLCOL public constructor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am) - : COLBLK(cdp, tdbp, i) - { - if (cprec) { - Next = cprec->GetNext(); - cprec->SetNext(this); - } else { - Next = tdbp->GetColumns(); - tdbp->SetColumns(this); - } // endif cprec - - // Set additional Dos access method information for column. - Long = cdp->GetLong(); // ??? -//strcpy(F_Date, cdp->F_Date); - Colp = NULL; - To_Val = NULL; - Pseudo = FALSE; - Colnum = cdp->GetOffset(); // If columns are retrieved by number - - if (trace) - htrc(" making new %sCOL C%d %s at %p\n", am, Index, Name, this); - - } // end of TBLCOL constructor - -/***********************************************************************/ -/* TBLCOL public constructor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(SPCBLK *scp, PTDB tdbp) : COLBLK(scp->GetName(), tdbp, 0) - { - // Set additional TBL access method information for pseudo column. - Is_Key = Was_Key = scp->IsKey(); - Long = scp->GetLength(); - Buf_Type = scp->GetResultType(); - *Format.Type = (Buf_Type == TYPE_INT) ? 'N' : 'C'; - Format.Length = Long; - Colp = NULL; - To_Val = NULL; - Pseudo = TRUE; - } // end of TBLCOL constructor - -/***********************************************************************/ -/* TBLCOL constructor used for copying columns. */ -/* tdbp is the pointer to the new table descriptor. */ -/***********************************************************************/ -TBLCOL::TBLCOL(TBLCOL *col1, PTDB tdbp) : COLBLK(col1, tdbp) - { - Long = col1->Long; - Colp = col1->Colp; - To_Val = col1->To_Val; - Pseudo = col1->Pseudo; - } // end of TBLCOL copy constructor - -/***********************************************************************/ -/* TBLCOL initialization routine. */ -/* Look for the matching column in the current table. */ -/***********************************************************************/ -bool TBLCOL::Init(PGLOBAL g) - { - PTDBTBL tdbp = (PTDBTBL)To_Tdb; - - To_Val = NULL; - - if (!(Colp = tdbp->Tdbp->ColDB(g, Name, 0)) && Colnum) - Colp = tdbp->Tdbp->ColDB(g, NULL, Colnum); - - if (Colp) { - Colp->InitValue(g); // May not have been done elsewhere - To_Val = Colp->GetValue(); - } else if (!tdbp->Accept) { - sprintf(g->Message, MSG(NO_MATCHING_COL), Name, tdbp->Tdbp->GetName()); - return TRUE; - } else { - if (Nullable) - Value->SetNull(true); - - Value->Reset(); - } // endif's - - return FALSE; - } // end of Init - -/***********************************************************************/ -/* ReadColumn: */ -/***********************************************************************/ -void TBLCOL::ReadColumn(PGLOBAL g) - { - if (trace) - htrc("TBL ReadColumn: name=%s\n", Name); - - if (Colp) { - Colp->ReadColumn(g); - Value->SetValue_pval(To_Val); - - // Set null when applicable - if (Nullable) - Value->SetNull(Value->IsNull()); - - } // endif Colp - - } // end of ReadColumn -#endif // 0 - /* ---------------------------- TBTBLK ------------------------------- */ /***********************************************************************/ diff --git a/storage/connect/tabtbl.h b/storage/connect/tabtbl.h index d241b00743e..69b862ebe4e 100644 --- a/storage/connect/tabtbl.h +++ b/storage/connect/tabtbl.h @@ -24,8 +24,6 @@ class DllExport TBLDEF : public PRXDEF { /* Logical table description */ // Implementation virtual const char *GetType(void) {return "TBL";} -//PTABLE GetTables(void) {return Tablep;} -//int GetNtables(void) {return Ntables;} // Methods virtual bool DefineAM(PGLOBAL g, LPCSTR am, int poff); @@ -33,7 +31,6 @@ class DllExport TBLDEF : public PRXDEF { /* Logical table description */ protected: // Members -//PTABLE To_Tables; /* To the list of tables */ bool Accept; /* TRUE if bad tables are accepted */ int Maxerr; /* Maximum number of bad tables */ int Ntables; /* Number of tables */ @@ -43,7 +40,6 @@ class DllExport TBLDEF : public PRXDEF { /* Logical table description */ /* This is the TBL Access Method class declaration. */ /***********************************************************************/ class DllExport TDBTBL : public TDBPRX { -//friend class TBLCOL; friend class TBTBLK; friend class TDBPLG; public: @@ -55,33 +51,25 @@ class DllExport TDBTBL : public TDBPRX { // Methods virtual void ResetDB(void); -//virtual PTABLE GetTablist(void) {return (PSZ)Tablist;} virtual int GetRecpos(void) {return Rows;} virtual int GetBadLines(void) {return (int)Nbf;} // Database routines virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); virtual int GetMaxSize(PGLOBAL g); -//virtual int GetProgMax(PGLOBAL g); -//virtual int GetProgCur(void); virtual int RowNumber(PGLOBAL g, bool b = FALSE); virtual PCOL InsertSpecialColumn(PGLOBAL g, PCOL scp); virtual bool OpenDB(PGLOBAL g); virtual int ReadDB(PGLOBAL g); -//virtual int WriteDB(PGLOBAL g); -//virtual int DeleteDB(PGLOBAL g, int irc); -//virtual void CloseDB(PGLOBAL g); protected: // Internal functions -//PTDB GetSubTable(PGLOBAL g, PTBL tblp, PTABLE tabp); bool InitTableList(PGLOBAL g); bool TestFil(PGLOBAL g, PFIL filp, PTABLE tabp); // Members PTABLE Tablist; // Points to the table list PTABLE CurTable; // Points to the current table -//PTDBASE Tdbp; // Current table PTDB bool Accept; // TRUE if bad tables are accepted int Maxerr; // Maximum number of bad tables int Nbf; // Number of bad connections @@ -89,41 +77,6 @@ class DllExport TDBTBL : public TDBPRX { int Crp; // Used for CurPos }; // end of class TDBTBL -#if 0 -/***********************************************************************/ -/* Class TBLCOL: TBL access method column descriptor. */ -/* This A.M. is used for TBL tables. */ -/***********************************************************************/ -class DllExport TBLCOL : public COLBLK { - friend class TDBTBL; - public: - // Constructors - TBLCOL(PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i, PSZ am = "TBL"); - TBLCOL(TBLCOL *colp, PTDB tdbp); // Constructor used in copy process -//TBLCOL(SPCBLK *colp, PTDB tdbp); // Constructor used for pseudo columns - - // Implementation - virtual int GetAmType(void) {return TYPE_AM_TBL;} - - // Methods - virtual bool IsSpecial(void) {return Pseudo;} - virtual void ReadColumn(PGLOBAL g); -//virtual void WriteColumn(PGLOBAL g); -// void Print(PGLOBAL g, FILE *, UINT); - bool Init(PGLOBAL g); - - protected: - // Default constructor not to be used - TBLCOL(void) {} - - // Members - PCOL Colp; // Points to matching table column - PVAL To_Val; // To the matching column value - bool Pseudo; // TRUE for special columns - int Colnum; // Used when retrieving columns by number - }; // end of class TBLCOL -#endif // 0 - /***********************************************************************/ /* Class TBTBLK: TDBPLG TABID special column descriptor. */ /***********************************************************************/ diff --git a/storage/connect/tabutil.cpp b/storage/connect/tabutil.cpp index 76885aeedce..3829e16b00b 100644 --- a/storage/connect/tabutil.cpp +++ b/storage/connect/tabutil.cpp @@ -245,7 +245,7 @@ PQRYRES TabColumns(PGLOBAL g, THD *thd, const char *db, return qrp; } // end of TabColumns -/* -------------- Implementation of the XCOL classes ---------------- */ +/* -------------- Implementation of the PROXY classes ---------------- */ /***********************************************************************/ /* PRXDEF constructor. */ @@ -311,11 +311,23 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp) TABLE_SHARE *s; PCATLG cat = To_Def->GetCat(); PHC hc = ((MYCAT*)cat)->GetHandler(); + LPCSTR cdb, curdb = hc->GetDBName(NULL); THD *thd = (hc->GetTable())->in_use; db = (char*)tabp->GetQualifier(); name = (char*)tabp->GetName(); + // Check for eventual loop + for (PTABLE tp = To_Table; tp; tp = tp->Next) { + cdb = (tp->Qualifier) ? tp->Qualifier : curdb; + + if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) { + sprintf(g->Message, "Table %s.%s pointing on itself", db, name); + return NULL; + } // endif + + } // endfor tp + if (!(s = GetTableShare(g, thd, db, name, mysql))) return NULL; @@ -337,9 +349,11 @@ PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp) db, tblp->Name); goto err; #endif // MYSQL_SUPPORT - } else + } else { // Sub-table is a CONNECT table + tabp->Next = To_Table; // For loop checking tdbp = cat->GetTable(g, tabp); + } // endif mysql hc->tshp = NULL; @@ -420,7 +434,7 @@ bool TDBPRX::OpenDB(PGLOBAL g) } // endif Mode if (InitTable(g)) - return NULL; + return TRUE; /*********************************************************************/ /* Check and initialize the subtable columns. */ @@ -468,6 +482,14 @@ int TDBPRX::DeleteDB(PGLOBAL g, int irc) return RC_FX; } // end of DeleteDB +/***********************************************************************/ +/* Used by the TBL tables. */ +/***********************************************************************/ +void TDBPRX::RemoveNext(PTABLE tp) + { + tp->Next = NULL; + } // end of RemoveNext + /* ---------------------------- PRXCOL ------------------------------- */ /***********************************************************************/ diff --git a/storage/connect/tabutil.h b/storage/connect/tabutil.h index 48e97bd49ec..3a5946bae8f 100644 --- a/storage/connect/tabutil.h +++ b/storage/connect/tabutil.h @@ -95,6 +95,7 @@ class DllExport TDBPRX : public TDBASE { virtual int DeleteDB(PGLOBAL g, int irc); virtual void CloseDB(PGLOBAL g) {if (Tdbp) Tdbp->CloseDB(g);} PTDB GetSubTable(PGLOBAL g, PTABLE tabp); + void RemoveNext(PTABLE tp); protected: // Members diff --git a/storage/connect/tabxcl.cpp b/storage/connect/tabxcl.cpp index 337a6cefd1d..78998435aa6 100644 --- a/storage/connect/tabxcl.cpp +++ b/storage/connect/tabxcl.cpp @@ -105,7 +105,6 @@ PTDB XCLDEF::GetTable(PGLOBAL g, MODE mode) /***********************************************************************/ TDBXCL::TDBXCL(PXCLDEF tdp) : TDBPRX(tdp) { -//Tdbp = NULL; // The physical table Xcolumn = tdp->Xcol; // CSV column name Xcolp = NULL; // To the XCVCOL column Mult = tdp->Mult; // Multiplication factor @@ -222,28 +221,6 @@ bool TDBXCL::OpenDB(PGLOBAL g) if (Tdbp->OpenDB(g)) return TRUE; -#if 0 - /*********************************************************************/ - /* Check for direct access. */ - /*********************************************************************/ - if (To_Key_Col) - if (!Tdbp->GetDef()->Indexable()) { - strcpy(g->Message, "Object table is not indexable"); - return TRUE; - } else { - ((PTDBX)Tdbp)->To_Key_Col = To_Key_Col; - ((PTDBX)Tdbp)->To_Link = To_Link; - ((PTDBX)Tdbp)->Knum = Knum; - To_Kindex = (PKXBASE)new(g) KINDEX(Tdbp); - - if (To_Kindex->Init(g)) - return TRUE; - - ((PKINDEX)To_Kindex)->SetMult(Mult); - Tdbp->SetKindex(To_Kindex); - } // endif Indexable -#endif // 0 - return FALSE; } // end of OpenDB @@ -332,45 +309,3 @@ void XCLCOL::ReadColumn(PGLOBAL g) ((PTDBXCL)To_Tdb)->RowFlag = 1; } // end of ReadColumn - -#if 0 -/* -------------- Implementation of the MULINDX class ---------------- */ - -/***********************************************************************/ -/* Returns FALSE if Ok, TRUE if there are no more equal values. */ -/***********************************************************************/ -bool MULINDX::HaveSame(void) - { - return (Op == OP_SAME || Txlp->RowFlag == 1); - } // end of HaveSame - -/***********************************************************************/ -/* Returns FALSE if Ok, TRUE if there are no more equal values. */ -/***********************************************************************/ -bool MULINDX::NextVal(bool eq) - { - return (Pof) ? KINDEX::NextVal(eq) : TRUE; - } // end of NextVal - -/***********************************************************************/ -/* Returns TRUE if there are more same values. */ -/***********************************************************************/ -bool MULINDX::MoreVal(void) - { - Op = OP_SAME; // There may be more equal values - return (Pof) ? Pof[Val_K] : Val_K; - } // end of MoreVal - -/***********************************************************************/ -/* Change the index multiple status. */ -/***********************************************************************/ -bool MULINDX::Init(PGLOBAL g) - { - if (KINDEX::Init(g)) - return TRUE; - - Mul = TRUE; - MaxSame *= Txlp->Mult; - return FALSE; - } // end of Init -#endif // 0 diff --git a/storage/connect/tabxcl.h b/storage/connect/tabxcl.h index 6db653d5709..79b890c9f55 100644 --- a/storage/connect/tabxcl.h +++ b/storage/connect/tabxcl.h @@ -8,7 +8,6 @@ typedef class XCLDEF *PXCLDEF; typedef class TDBXCL *PTDBXCL; typedef class XCLCOL *PXCLCOL; -//pedef class MULINDX *PMINDX; /* -------------------------- XCOL classes --------------------------- */ @@ -49,7 +48,6 @@ class XCLDEF : public PRXDEF { /* Logical table description */ /* This is the class declaration for the XCSV table. */ /***********************************************************************/ class TDBXCL : public TDBPRX { -//friend class MULINDX; friend class XCLDEF; friend class PRXCOL; friend class XCLCOL; @@ -63,7 +61,6 @@ class TDBXCL : public TDBPRX { // Methods virtual void ResetDB(void) {N = 0; Tdbp->ResetDB();} virtual int RowNumber(PGLOBAL g, bool b = FALSE); -//virtual bool HaveSame(void) {return RowFlag == 1;} // Database routines virtual PCOL MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n); @@ -106,28 +103,3 @@ class XCLCOL : public PRXCOL { char *Cp; // Pointer to current position char Sep; // The separator }; // end of class XCLCOL - -#if 0 -/* ------------------------- MULINDX classes ------------------------- */ - -/***********************************************************************/ -/* This represents a KINDEX class for an XCOL table. */ -/***********************************************************************/ -class MULINDX : public KINDEX { - public: - // Constructor - MULINDX(PTDBXCL txlp) : KINDEX(txlp->Tdbp) {Txlp = txlp;} - - // Implementation - virtual BOOL HaveSame(void); - - // Methods - virtual BOOL Init(PGLOBAL g); - virtual BOOL NextVal(BOOL eq); - virtual int MoreVal(void); - - protected: - //Member - PTDBXCL Txlp; -}; // end of class MULINDX -#endif // 0