diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-10-30 13:02:59 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-10-30 15:10:01 +0100 |
commit | 44f6f445933e12cbc4cce63e2b7d983b9938d3b9 (patch) | |
tree | f5230fb24510bb201eb33122a62939ce74588b83 /storage/connect/tabpivot.cpp | |
parent | 8772824ce72a811ea92dd5cfb73602eb93237891 (diff) | |
parent | f4b8b6b9a3ad4ce5e5218e2ec2dfe6dd34112e45 (diff) | |
download | mariadb-git-44f6f445933e12cbc4cce63e2b7d983b9938d3b9.tar.gz |
Merge branch '10.0' into 10.1
Diffstat (limited to 'storage/connect/tabpivot.cpp')
-rw-r--r-- | storage/connect/tabpivot.cpp | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/storage/connect/tabpivot.cpp b/storage/connect/tabpivot.cpp index da5d134f347..9121a0453e5 100644 --- a/storage/connect/tabpivot.cpp +++ b/storage/connect/tabpivot.cpp @@ -107,12 +107,12 @@ bool PIVAID::SkipColumn(PCOLRES crp, char *skc) /***********************************************************************/ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) { - char *p, *query, *colname, *skc, buf[64]; - int ndif, nblin, w = 0; - bool b = false; - PVAL valp; - PQRYRES qrp; - PCOLRES *pcrp, crp, fncrp = NULL; + char *p, *query, *colname, *skc, buf[64]; + int ndif, nblin, w = 0; + bool b = false; + PVAL valp; + PQRYRES qrp; + PCOLRES *pcrp, crp, fncrp = NULL; try { // Are there columns to skip? @@ -186,7 +186,7 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } // endif picol - // Prepare the column list + // Prepare the column list for (pcrp = &Qryp->Colresp; crp = *pcrp; ) if (SkipColumn(crp, skc)) { // Ignore this column @@ -205,95 +205,95 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } 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 (!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; + if (Tabsrc) { + Myc.Close(); + b = false; - // Before calling sort, initialize all - nblin = Qryp->Nblin; + // Before calling sort, initialize all + nblin = Qryp->Nblin; - Index.Size = nblin * sizeof(int); - Index.Sub = TRUE; // Should be small enough + Index.Size = nblin * sizeof(int); + Index.Sub = TRUE; // Should be small enough - if (!PlgDBalloc(g, NULL, Index)) - goto err; + if (!PlgDBalloc(g, NULL, Index)) + goto err; - Offset.Size = (nblin + 1) * sizeof(int); - Offset.Sub = TRUE; // Should be small enough + Offset.Size = (nblin + 1) * sizeof(int); + Offset.Sub = TRUE; // Should be small enough - if (!PlgDBalloc(g, NULL, Offset)) - goto err; + if (!PlgDBalloc(g, NULL, Offset)) + goto err; - ndif = Qsort(g, nblin); + ndif = Qsort(g, nblin); - if (ndif < 0) // error - goto err; + 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; + } 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(); + 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; + // 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; + // We must have a storage query to get pivot column values + if (!(qrp = Myc.GetResult(g, true))) + goto err; - Myc.Close(); - b = false; + Myc.Close(); + b = false; - // Get the column list - crp = qrp->Colresp; - Rblkp = crp->Kdata; - ndif = qrp->Nblin; - } // endif Tabsrc + // 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; + // 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 + // 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); @@ -306,10 +306,10 @@ PQRYRES PIVAID::MakePivotColumns(PGLOBAL g) } // end catch err: - if (b) - Myc.Close(); + if (b) + Myc.Close(); - return NULL; + return NULL; } // end of MakePivotColumns /***********************************************************************/ |