summaryrefslogtreecommitdiff
path: root/storage/connect/tabpivot.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2017-05-23 19:35:50 +0200
committerOlivier Bertrand <bertrandop@gmail.com>2017-05-23 19:35:50 +0200
commit3e36eb230b65d53acc8e02b00a024e72ed249425 (patch)
treebe89d99353fc70488a5b43707fac12b960f2f29b /storage/connect/tabpivot.cpp
parente8333389c89c946d3794ec9ea708d308318301a3 (diff)
downloadmariadb-git-3e36eb230b65d53acc8e02b00a024e72ed249425.tar.gz
Fix gcc compiler warnings reported by Sergei
modified: storage/connect/array.cpp modified: storage/connect/array.h modified: storage/connect/blkfil.cpp modified: storage/connect/blkfil.h modified: storage/connect/block.h modified: storage/connect/colblk.cpp modified: storage/connect/colblk.h modified: storage/connect/csort.h modified: storage/connect/filamvct.cpp modified: storage/connect/filter.cpp modified: storage/connect/filter.h modified: storage/connect/global.h modified: storage/connect/json.h modified: storage/connect/plgdbsem.h modified: storage/connect/plgdbutl.cpp modified: storage/connect/tabcol.cpp modified: storage/connect/tabcol.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h modified: storage/connect/tabjson.cpp modified: storage/connect/table.cpp modified: storage/connect/tabodbc.cpp modified: storage/connect/tabodbc.h modified: storage/connect/tabsys.h modified: storage/connect/tabxml.h modified: storage/connect/value.cpp modified: storage/connect/value.h modified: storage/connect/xindex.cpp modified: storage/connect/xindex.h modified: storage/connect/xobject.cpp modified: storage/connect/xobject.h modified: storage/connect/xtable.h Set values as nullable when retrieving catalog info modified: storage/connect/jdbconn.cpp modified: storage/connect/mysql-test/connect/r/odbc_oracle.result modified: storage/connect/odbconn.cpp Change format of Jpath modified: storage/connect/json.cpp modified: storage/connect/jsonudf.cpp modified: storage/connect/mysql-test/connect/r/json.result modified: storage/connect/mysql-test/connect/r/json_udf.result modified: storage/connect/mysql-test/connect/r/json_udf_bin.result modified: storage/connect/mysql-test/connect/r/zip.result modified: storage/connect/mysql-test/connect/t/json.test modified: storage/connect/mysql-test/connect/t/json_udf.test modified: storage/connect/mysql-test/connect/t/json_udf_bin.test modified: storage/connect/mysql-test/connect/t/zip.test modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h modified: storage/connect/tabmgo.cpp Change null representation from ??? to <null> modified: storage/connect/json.cpp Change the name of UDF that are equal to a native JSON function name modified: storage/connect/jsonudf.cpp modified: storage/connect/jsonudf.h modified: storage/connect/mysql-test/connect/t/json_udf.inc modified: storage/connect/mysql-test/connect/t/json_udf2.inc Fix bug in making JSON project info modified: storage/connect/mongofam.cpp Fix COMPUTE when one argument is null modified: storage/connect/value.cpp Value is null only when nullable modified: storage/connect/value.h
Diffstat (limited to 'storage/connect/tabpivot.cpp')
-rw-r--r--storage/connect/tabpivot.cpp389
1 files changed, 193 insertions, 196 deletions
diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp
index c6d32884417..76a46e6899b 100644
--- a/storage/connect/tabpivot.cpp
+++ b/storage/connect/tabpivot.cpp
@@ -106,214 +106,211 @@ bool PIVAID::SkipColumn(PCOLRES crp, char *skc)
/* Make the Pivot table column list. */
/***********************************************************************/
PQRYRES PIVAID::MakePivotColumns(PGLOBAL g)
- {
+{
char *p, *query, *colname, *skc, buf[64];
- int rc, ndif, nblin, w = 0;
+ int ndif, nblin, w = 0;
bool b = false;
PVAL valp;
PQRYRES qrp;
PCOLRES *pcrp, crp, fncrp = NULL;
- // Save stack and allocation environment and prepare error return
- if (g->jump_level == MAX_JUMP) {
- strcpy(g->Message, MSG(TOO_MANY_JUMPS));
- return NULL;
- } // endif jump_level
-
- if ((rc= setjmp(g->jumper[++g->jump_level])) != 0) {
- goto err;
- } // endif rc
-
- // Are there columns to skip?
- if (Skcol) {
- uint n = strlen(Skcol);
-
- skc = (char*)PlugSubAlloc(g, NULL, n + 2);
- strcpy(skc, Skcol);
- skc[n + 1] = 0;
-
- // Replace ; by nulls in skc
- for (p = strchr(skc, ';'); p; p = strchr(p, ';'))
- *p++ = 0;
-
- } else
- skc = NULL;
-
- if (!Tabsrc && Tabname) {
- // Locate the query
- query = (char*)PlugSubAlloc(g, NULL, strlen(Tabname) + 26);
- sprintf(query, "SELECT * FROM `%s` LIMIT 1", Tabname);
- } else if (!Tabsrc) {
- strcpy(g->Message, MSG(SRC_TABLE_UNDEF));
- return NULL;
- } else
- query = Tabsrc;
-
- // Open a MySQL connection for this table
- if (!Myc.Open(g, Host, Database, User, Pwd, Port)) {
- b = true;
-
- // Returned values must be in their original character set
- if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
- goto err;
- else
- Myc.FreeResult();
-
- } else
- return NULL;
-
- // Send the source command to MySQL
- if (Myc.ExecSQL(g, query, &w) == RC_FX)
- goto err;
-
- // We must have a storage query to get pivot column values
- if (!(Qryp = Myc.GetResult(g, true)))
- goto err;
-
- if (!Fncol) {
- for (crp = Qryp->Colresp; crp; crp = crp->Next)
- if ((!Picol || stricmp(Picol, crp->Name)) && !SkipColumn(crp, skc))
- Fncol = crp->Name;
-
- if (!Fncol) {
- strcpy(g->Message, MSG(NO_DEF_FNCCOL));
- goto err;
- } // endif Fncol
-
- } // endif Fncol
-
- if (!Picol) {
- // Find default Picol as the last one not equal to Fncol
- for (crp = Qryp->Colresp; crp; crp = crp->Next)
- if (stricmp(Fncol, crp->Name) && !SkipColumn(crp, skc))
- Picol = crp->Name;
-
- if (!Picol) {
- strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
- goto err;
- } // endif Picol
-
- } // endif picol
-
- // Prepare the column list
- for (pcrp = &Qryp->Colresp; crp = *pcrp; )
- if (SkipColumn(crp, skc)) {
- // Ignore this column
- *pcrp = crp->Next;
- } else if (!stricmp(Picol, crp->Name)) {
- if (crp->Nulls) {
- sprintf(g->Message, "Pivot column %s cannot be nullable", Picol);
- goto err;
- } // endif Nulls
-
- Rblkp = crp->Kdata;
- *pcrp = crp->Next;
- } else if (!stricmp(Fncol, crp->Name)) {
- fncrp = crp;
- *pcrp = crp->Next;
- } else
- pcrp = &crp->Next;
-
- if (!Rblkp) {
- strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
- goto err;
- } else if (!fncrp) {
- strcpy(g->Message, MSG(NO_DEF_FNCCOL));
- goto err;
- } // endif
-
- if (Tabsrc) {
- Myc.Close();
- b = false;
-
- // Before calling sort, initialize all
- nblin = Qryp->Nblin;
-
- Index.Size = nblin * sizeof(int);
- Index.Sub = TRUE; // Should be small enough
-
- if (!PlgDBalloc(g, NULL, Index))
- return NULL;
-
- Offset.Size = (nblin + 1) * sizeof(int);
- Offset.Sub = TRUE; // Should be small enough
-
- if (!PlgDBalloc(g, NULL, Offset))
- return NULL;
-
- ndif = Qsort(g, nblin);
-
- if (ndif < 0) // error
- return NULL;
-
- } else {
- // The query was limited, we must get pivot column values
- // Returned values must be in their original character set
-// if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
-// goto err;
-
- query = (char*)PlugSubAlloc(g, NULL, 0);
- sprintf(query, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname);
- PlugSubAlloc(g, NULL, strlen(query) + 1);
- Myc.FreeResult();
-
- // Send the source command to MySQL
- if (Myc.ExecSQL(g, query, &w) == RC_FX)
- goto err;
-
- // We must have a storage query to get pivot column values
- if (!(qrp = Myc.GetResult(g, true)))
- goto err;
-
- Myc.Close();
- b = false;
-
- // Get the column list
- crp = qrp->Colresp;
- Rblkp = crp->Kdata;
- ndif = qrp->Nblin;
- } // endif Tabsrc
-
- // Allocate the Value used to retieve column names
- if (!(valp = AllocateValue(g, Rblkp->GetType(),
- Rblkp->GetVlen(),
- Rblkp->GetPrec())))
- return NULL;
-
- // Now make the functional columns
- for (int i = 0; i < ndif; i++) {
- if (i) {
- crp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES));
- memcpy(crp, fncrp, sizeof(COLRES));
- } else
- crp = fncrp;
-
- // Get the value that will be the generated column name
- if (Tabsrc)
- valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]);
- else
- valp->SetValue_pvblk(Rblkp, i);
-
- colname = valp->GetCharString(buf);
- crp->Name = PlugDup(g, colname);
- crp->Flag = 1;
-
- // Add this column
- *pcrp = crp;
- crp->Next = NULL;
- pcrp = &crp->Next;
- } // endfor i
-
- // We added ndif columns and removed 2 (picol and fncol)
- Qryp->Nbcol += (ndif - 2);
- return Qryp;
+ try {
+ // Are there columns to skip?
+ if (Skcol) {
+ uint n = strlen(Skcol);
+
+ skc = (char*)PlugSubAlloc(g, NULL, n + 2);
+ strcpy(skc, Skcol);
+ skc[n + 1] = 0;
+
+ // Replace ; by nulls in skc
+ for (p = strchr(skc, ';'); p; p = strchr(p, ';'))
+ *p++ = 0;
+
+ } else
+ skc = NULL;
+
+ if (!Tabsrc && Tabname) {
+ // Locate the query
+ query = (char*)PlugSubAlloc(g, NULL, strlen(Tabname) + 26);
+ sprintf(query, "SELECT * FROM `%s` LIMIT 1", Tabname);
+ } else if (!Tabsrc) {
+ strcpy(g->Message, MSG(SRC_TABLE_UNDEF));
+ goto err;
+ } else
+ query = (char*)Tabsrc;
+
+ // Open a MySQL connection for this table
+ if (!Myc.Open(g, Host, Database, User, Pwd, Port)) {
+ b = true;
+
+ // Returned values must be in their original character set
+ if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
+ goto err;
+ else
+ Myc.FreeResult();
+
+ } else
+ goto err;
+
+ // Send the source command to MySQL
+ if (Myc.ExecSQL(g, query, &w) == RC_FX)
+ goto err;
+
+ // We must have a storage query to get pivot column values
+ if (!(Qryp = Myc.GetResult(g, true)))
+ goto err;
+
+ if (!Fncol) {
+ for (crp = Qryp->Colresp; crp; crp = crp->Next)
+ if ((!Picol || stricmp(Picol, crp->Name)) && !SkipColumn(crp, skc))
+ Fncol = crp->Name;
+
+ if (!Fncol) {
+ strcpy(g->Message, MSG(NO_DEF_FNCCOL));
+ goto err;
+ } // endif Fncol
+
+ } // endif Fncol
+
+ if (!Picol) {
+ // Find default Picol as the last one not equal to Fncol
+ for (crp = Qryp->Colresp; crp; crp = crp->Next)
+ if (stricmp(Fncol, crp->Name) && !SkipColumn(crp, skc))
+ Picol = crp->Name;
+
+ if (!Picol) {
+ strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
+ goto err;
+ } // endif Picol
+
+ } // endif picol
+
+ // Prepare the column list
+ for (pcrp = &Qryp->Colresp; crp = *pcrp; )
+ if (SkipColumn(crp, skc)) {
+ // Ignore this column
+ *pcrp = crp->Next;
+ } else if (!stricmp(Picol, crp->Name)) {
+ if (crp->Nulls) {
+ sprintf(g->Message, "Pivot column %s cannot be nullable", Picol);
+ goto err;
+ } // endif Nulls
+
+ Rblkp = crp->Kdata;
+ *pcrp = crp->Next;
+ } else if (!stricmp(Fncol, crp->Name)) {
+ fncrp = crp;
+ *pcrp = crp->Next;
+ } else
+ pcrp = &crp->Next;
+
+ if (!Rblkp) {
+ strcpy(g->Message, MSG(NO_DEF_PIVOTCOL));
+ goto err;
+ } else if (!fncrp) {
+ strcpy(g->Message, MSG(NO_DEF_FNCCOL));
+ goto err;
+ } // endif
+
+ if (Tabsrc) {
+ Myc.Close();
+ b = false;
+
+ // Before calling sort, initialize all
+ nblin = Qryp->Nblin;
+
+ Index.Size = nblin * sizeof(int);
+ Index.Sub = TRUE; // Should be small enough
+
+ if (!PlgDBalloc(g, NULL, Index))
+ goto err;
+
+ Offset.Size = (nblin + 1) * sizeof(int);
+ Offset.Sub = TRUE; // Should be small enough
+
+ if (!PlgDBalloc(g, NULL, Offset))
+ goto err;
+
+ ndif = Qsort(g, nblin);
+
+ if (ndif < 0) // error
+ goto err;
+
+ } else {
+ // The query was limited, we must get pivot column values
+ // Returned values must be in their original character set
+ // if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
+ // goto err;
+
+ query = (char*)PlugSubAlloc(g, NULL, 0);
+ sprintf(query, "SELECT DISTINCT `%s` FROM `%s`", Picol, Tabname);
+ PlugSubAlloc(g, NULL, strlen(query) + 1);
+ Myc.FreeResult();
+
+ // Send the source command to MySQL
+ if (Myc.ExecSQL(g, query, &w) == RC_FX)
+ goto err;
+
+ // We must have a storage query to get pivot column values
+ if (!(qrp = Myc.GetResult(g, true)))
+ goto err;
+
+ Myc.Close();
+ b = false;
+
+ // Get the column list
+ crp = qrp->Colresp;
+ Rblkp = crp->Kdata;
+ ndif = qrp->Nblin;
+ } // endif Tabsrc
+
+ // Allocate the Value used to retieve column names
+ if (!(valp = AllocateValue(g, Rblkp->GetType(),
+ Rblkp->GetVlen(),
+ Rblkp->GetPrec())))
+ goto err;
+
+ // Now make the functional columns
+ for (int i = 0; i < ndif; i++) {
+ if (i) {
+ crp = (PCOLRES)PlugSubAlloc(g, NULL, sizeof(COLRES));
+ memcpy(crp, fncrp, sizeof(COLRES));
+ } else
+ crp = fncrp;
+
+ // Get the value that will be the generated column name
+ if (Tabsrc)
+ valp->SetValue_pvblk(Rblkp, Pex[Pof[i]]);
+ else
+ valp->SetValue_pvblk(Rblkp, i);
+
+ colname = valp->GetCharString(buf);
+ crp->Name = PlugDup(g, colname);
+ crp->Flag = 1;
+
+ // Add this column
+ *pcrp = crp;
+ crp->Next = NULL;
+ pcrp = &crp->Next;
+ } // endfor i
+
+ // We added ndif columns and removed 2 (picol and fncol)
+ Qryp->Nbcol += (ndif - 2);
+ return Qryp;
+ } catch (int n) {
+ if (trace)
+ htrc("Exception %d: %s\n", n, g->Message);
+ } catch (const char *msg) {
+ strcpy(g->Message, msg);
+ } // end catch
err:
if (b)
Myc.Close();
return NULL;
- } // end of MakePivotColumns
+} // end of MakePivotColumns
/***********************************************************************/
/* PIVAID: Compare routine for sorting pivot column values. */