mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Changing CONNECT version number and date
modified: storage/connect/ha_connect.cc storage/connect/mysql-test/connect/r/xml.result - Testing default pivot columns for srcdef Fixing order by MariaDB bug for pivot tables modified: storage/connect/tabmysql.cpp storage/connect/tabmysql.h storage/connect/tabpivot.cpp storage/connect/tabpivot.h
This commit is contained in:
@@ -158,7 +158,7 @@ extern "C" char nmfile[];
|
|||||||
extern "C" char pdebug[];
|
extern "C" char pdebug[];
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
char version[]= "Version 1.01.0005 April 27, 2013";
|
char version[]= "Version 1.01.0006 Mai 21, 2013";
|
||||||
|
|
||||||
#if defined(XMSG)
|
#if defined(XMSG)
|
||||||
char msglang[]; // Default message language
|
char msglang[]; // Default message language
|
||||||
|
@@ -413,7 +413,7 @@ DROP TABLE t1;
|
|||||||
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
|
SET @a=LOAD_FILE('MYSQLD_DATADIR/test/t1.xml');
|
||||||
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
|
SELECT CAST(@a AS CHAR CHARACTER SET latin1);
|
||||||
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
|
CAST(@a AS CHAR CHARACTER SET latin1) <?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
<!-- Created by CONNECT Version 1.01.0005 April 27, 2013 -->
|
<!-- Created by CONNECT Version 1.01.0006 Mai 21, 2013 -->
|
||||||
<t1>
|
<t1>
|
||||||
<line>
|
<line>
|
||||||
<node>ÀÁÂÃ</node>
|
<node>ÀÁÂÃ</node>
|
||||||
|
@@ -900,6 +900,29 @@ PCOL TDBMYSQL::MakeFieldColumn(PGLOBAL g, char *name)
|
|||||||
return colp;
|
return colp;
|
||||||
} // end of MakeFieldColumn
|
} // end of MakeFieldColumn
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* Called by Pivot tables to find default column names in a View */
|
||||||
|
/* as the name of last field not equal to the passed name. */
|
||||||
|
/***********************************************************************/
|
||||||
|
char *TDBMYSQL::FindFieldColumn(char *name)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
MYSQL_FIELD *fld;
|
||||||
|
char *cp = NULL;
|
||||||
|
|
||||||
|
for (n = Myc.m_Fields - 1; n >= 0; n--) {
|
||||||
|
fld = &Myc.m_Res->fields[n];
|
||||||
|
|
||||||
|
if (!name || stricmp(name, fld->name)) {
|
||||||
|
cp = fld->name;
|
||||||
|
break;
|
||||||
|
} // endif name
|
||||||
|
|
||||||
|
} // endfor n
|
||||||
|
|
||||||
|
return cp;
|
||||||
|
} // end of FindFieldColumn
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Data Base read routine for MYSQL access method. */
|
/* Data Base read routine for MYSQL access method. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
@@ -90,6 +90,7 @@ class TDBMYSQL : public TDBASE {
|
|||||||
// Specific routines
|
// Specific routines
|
||||||
bool SetColumnRanks(PGLOBAL g);
|
bool SetColumnRanks(PGLOBAL g);
|
||||||
PCOL MakeFieldColumn(PGLOBAL g, char *name);
|
PCOL MakeFieldColumn(PGLOBAL g, char *name);
|
||||||
|
PSZ FindFieldColumn(char *name);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Internal functions
|
// Internal functions
|
||||||
|
@@ -161,6 +161,42 @@ PCOL TDBPIVOT::MakeCol(PGLOBAL g, PCOLDEF cdp, PCOL cprec, int n)
|
|||||||
return colp;
|
return colp;
|
||||||
} // end of MakeCol
|
} // end of MakeCol
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
/* Find default fonction and pivot columns. */
|
||||||
|
/***********************************************************************/
|
||||||
|
bool TDBPIVOT::FindDefaultColumns(PGLOBAL g)
|
||||||
|
{
|
||||||
|
PCOLDEF cdp;
|
||||||
|
PTABDEF defp = Tdbp->GetDef();
|
||||||
|
|
||||||
|
if (!Fncol) {
|
||||||
|
for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext())
|
||||||
|
if (!Picol || stricmp(Picol, cdp->GetName()))
|
||||||
|
Fncol = cdp->GetName();
|
||||||
|
|
||||||
|
if (!Fncol) {
|
||||||
|
strcpy(g->Message, MSG(NO_DEF_FNCCOL));
|
||||||
|
return true;
|
||||||
|
} // endif Fncol
|
||||||
|
|
||||||
|
} // endif Fncol
|
||||||
|
|
||||||
|
if (!Picol) {
|
||||||
|
// Find default Picol as the last one not equal to Fncol
|
||||||
|
for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext())
|
||||||
|
if (stricmp(Fncol, cdp->GetName()))
|
||||||
|
Picol = cdp->GetName();
|
||||||
|
|
||||||
|
if (!Picol) {
|
||||||
|
strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
|
||||||
|
return true;
|
||||||
|
} // endif Picol
|
||||||
|
|
||||||
|
} // endif Picol
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} // end of FindDefaultColumns
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
/* Prepare the source table Query. */
|
/* Prepare the source table Query. */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
@@ -174,69 +210,45 @@ bool TDBPIVOT::GetSourceTable(PGLOBAL g)
|
|||||||
if (!(Tdbp = GetSubTable(g, ((PPIVOTDEF)To_Def)->Tablep, true)))
|
if (!(Tdbp = GetSubTable(g, ((PPIVOTDEF)To_Def)->Tablep, true)))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!Tdbp->IsView()) {
|
if (!GBdone) {
|
||||||
|
char *colist;
|
||||||
PCOLDEF cdp;
|
PCOLDEF cdp;
|
||||||
PTABDEF defp = Tdbp->GetDef();
|
|
||||||
|
|
||||||
if (!Fncol) {
|
if (FindDefaultColumns(g))
|
||||||
for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext())
|
return true;
|
||||||
if (!Picol || stricmp(Picol, cdp->GetName()))
|
|
||||||
Fncol = cdp->GetName();
|
|
||||||
|
|
||||||
if (!Fncol) {
|
// Locate the suballocated colist (size is not known yet)
|
||||||
strcpy(g->Message, MSG(NO_DEF_FNCCOL));
|
*(colist = (char*)PlugSubAlloc(g, NULL, 0)) = 0;
|
||||||
return true;
|
|
||||||
} // endif Fncol
|
|
||||||
|
|
||||||
} // endif Fncol
|
// Make the column list
|
||||||
|
for (cdp = To_Def->GetCols(); cdp; cdp = cdp->GetNext())
|
||||||
|
if (!cdp->GetOffset())
|
||||||
|
strcat(strcat(colist, cdp->GetName()), ", ");
|
||||||
|
|
||||||
if (!Picol) {
|
// Add the Pivot column at the end of the list
|
||||||
// Find default Picol as the last one not equal to Fncol
|
strcat(colist, Picol);
|
||||||
for (cdp = defp->GetCols(); cdp; cdp = cdp->GetNext())
|
|
||||||
if (!Fncol || stricmp(Fncol, cdp->GetName()))
|
|
||||||
Picol = cdp->GetName();
|
|
||||||
|
|
||||||
if (!Picol) {
|
// Now we know how much was suballocated
|
||||||
strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
|
PlugSubAlloc(g, NULL, strlen(colist));
|
||||||
return true;
|
|
||||||
} // endif Picol
|
|
||||||
|
|
||||||
} // endif Picol
|
// Locate the source string (size is not known yet)
|
||||||
|
Tabsrc = (char*)PlugSubAlloc(g, NULL, 0);
|
||||||
|
|
||||||
if (!GBdone) {
|
// Start making the definition
|
||||||
char *colist;
|
strcat(strcat(strcpy(Tabsrc, "SELECT "), colist), ", ");
|
||||||
|
|
||||||
// Locate the suballocated colist (size is not known yet)
|
// Make it suitable for Pivot by doing the group by
|
||||||
*(colist = (char*)PlugSubAlloc(g, NULL, 0)) = 0;
|
strcat(strcat(Tabsrc, Function), "(");
|
||||||
|
strcat(strcat(strcat(Tabsrc, Fncol), ") "), Fncol);
|
||||||
|
strcat(strcat(Tabsrc, " FROM "), Tabname);
|
||||||
|
strcat(strcat(Tabsrc, " GROUP BY "), colist);
|
||||||
|
|
||||||
// Make the column list
|
if (Tdbp->IsView()) // Until MariaDB bug is fixed
|
||||||
for (cdp = To_Def->GetCols(); cdp; cdp = cdp->GetNext())
|
strcat(strcat(Tabsrc, " ORDER BY "), colist);
|
||||||
if (!cdp->GetOffset())
|
|
||||||
strcat(strcat(colist, cdp->GetName()), ", ");
|
|
||||||
|
|
||||||
// Add the Pivot column at the end of the list
|
// Now we know how much was suballocated
|
||||||
strcat(colist, Picol);
|
PlugSubAlloc(g, NULL, strlen(Tabsrc));
|
||||||
|
} // endif !GBdone
|
||||||
// Now we know how much was suballocated
|
|
||||||
PlugSubAlloc(g, NULL, strlen(colist));
|
|
||||||
|
|
||||||
// Locate the source string (size is not known yet)
|
|
||||||
Tabsrc = (char*)PlugSubAlloc(g, NULL, 0);
|
|
||||||
|
|
||||||
// Start making the definition
|
|
||||||
strcat(strcat(strcpy(Tabsrc, "SELECT "), colist), ", ");
|
|
||||||
|
|
||||||
// Make it suitable for Pivot by doing the group by
|
|
||||||
strcat(strcat(Tabsrc, Function), "(");
|
|
||||||
strcat(strcat(strcat(Tabsrc, Fncol), ") "), Fncol);
|
|
||||||
strcat(strcat(Tabsrc, " FROM "), Tabname);
|
|
||||||
strcat(strcat(Tabsrc, " GROUP BY "), colist);
|
|
||||||
|
|
||||||
// Now we know how much was suballocated
|
|
||||||
PlugSubAlloc(g, NULL, strlen(Tabsrc));
|
|
||||||
} // endif !GBdone
|
|
||||||
|
|
||||||
} // endif IsView
|
|
||||||
|
|
||||||
} else if (!Tabsrc) {
|
} else if (!Tabsrc) {
|
||||||
strcpy(g->Message, MSG(SRC_TABLE_UNDEF));
|
strcpy(g->Message, MSG(SRC_TABLE_UNDEF));
|
||||||
@@ -263,6 +275,10 @@ bool TDBPIVOT::GetSourceTable(PGLOBAL g)
|
|||||||
bool TDBPIVOT::MakePivotColumns(PGLOBAL g)
|
bool TDBPIVOT::MakePivotColumns(PGLOBAL g)
|
||||||
{
|
{
|
||||||
if (!Tdbp->IsView()) {
|
if (!Tdbp->IsView()) {
|
||||||
|
// This was not done yet if GBdone is true
|
||||||
|
if (FindDefaultColumns(g))
|
||||||
|
return true;
|
||||||
|
|
||||||
// Now it is time to allocate the pivot and function columns
|
// Now it is time to allocate the pivot and function columns
|
||||||
if (!(Fcolp = Tdbp->ColDB(g, Fncol, 0))) {
|
if (!(Fcolp = Tdbp->ColDB(g, Fncol, 0))) {
|
||||||
// Function column not found in table
|
// Function column not found in table
|
||||||
@@ -309,36 +325,15 @@ bool TDBPIVOT::MakeViewColumns(PGLOBAL g)
|
|||||||
} else
|
} else
|
||||||
tdbp = (PTDBMY)Tdbp;
|
tdbp = (PTDBMY)Tdbp;
|
||||||
|
|
||||||
if (!Fncol || !Picol) {
|
if (!Fncol && !(Fncol = tdbp->FindFieldColumn(Picol))) {
|
||||||
strcpy(g->Message, "Missing Function or Pivot column");
|
strcpy(g->Message, MSG(NO_DEF_FNCCOL));
|
||||||
return true;
|
return true;
|
||||||
} // endif
|
|
||||||
#if 0
|
|
||||||
if (!Fncol) {
|
|
||||||
for (crp = qryp->Colresp; crp; crp = crp->Next)
|
|
||||||
if (!Picol || stricmp(Picol, crp->Name))
|
|
||||||
Fncol = crp->Name;
|
|
||||||
|
|
||||||
if (!Fncol) {
|
|
||||||
strcpy(g->Message, MSG(NO_DEF_FNCCOL));
|
|
||||||
return true;
|
|
||||||
} // endif Fncol
|
|
||||||
|
|
||||||
} // endif Fncol
|
} // endif Fncol
|
||||||
|
|
||||||
if (!Picol) {
|
if (!Picol && !(Picol = tdbp->FindFieldColumn(Fncol))) {
|
||||||
// Find default Picol as the last one not equal to Fncol
|
strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
|
||||||
for (crp = qryp->Colresp; crp; crp = crp->Next)
|
return true;
|
||||||
if (!Fncol || stricmp(Fncol, crp->Name))
|
|
||||||
Picol = crp->Name;
|
|
||||||
|
|
||||||
if (!Picol) {
|
|
||||||
strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
|
|
||||||
return true;
|
|
||||||
} // endif Picol
|
|
||||||
|
|
||||||
} // endif Picol
|
} // endif Picol
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
// Now it is time to allocate the pivot and function columns
|
// Now it is time to allocate the pivot and function columns
|
||||||
if (!(Fcolp = tdbp->MakeFieldColumn(g, Fncol)))
|
if (!(Fcolp = tdbp->MakeFieldColumn(g, Fncol)))
|
||||||
|
@@ -78,6 +78,7 @@ class TDBPIVOT : public TDBPRX {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Internal routines
|
// Internal routines
|
||||||
|
bool FindDefaultColumns(PGLOBAL g);
|
||||||
bool GetSourceTable(PGLOBAL g);
|
bool GetSourceTable(PGLOBAL g);
|
||||||
bool MakePivotColumns(PGLOBAL g);
|
bool MakePivotColumns(PGLOBAL g);
|
||||||
bool MakeViewColumns(PGLOBAL g);
|
bool MakeViewColumns(PGLOBAL g);
|
||||||
|
Reference in New Issue
Block a user