MCPcopy Create free account
hub / github.com/MariaDB/server / MakePivotColumns

Method MakePivotColumns

storage/connect/tabpivot.cpp:108–314  ·  view source on GitHub ↗

/ Make the Pivot table column list. */ /

Source from the content-addressed store, hash-verified

106/* Make the Pivot table column list. */
107/***********************************************************************/
108PQRYRES PIVAID::MakePivotColumns(PGLOBAL g)
109{
110 char *p, *query, *colname, *skc, buf[64];
111 int ndif, nblin, w = 0;
112 bool b = false;
113 PVAL valp;
114 PQRYRES qrp;
115 PCOLRES *pcrp, crp, fncrp = NULL;
116
117 try {
118 // Are there columns to skip?
119 if (Skcol) {
120 uint n = strlen(Skcol);
121
122 skc = (char*)PlugSubAlloc(g, NULL, n + 2);
123 snprintf(skc, n + 2, "%s", Skcol);
124 skc[n + 1] = 0;
125
126 // Replace ; by nulls in skc
127 for (p = strchr(skc, ';'); p; p = strchr(p, ';'))
128 *p++ = 0;
129
130 } else
131 skc = NULL;
132
133 if (!Tabsrc && Tabname) {
134 // Locate the query
135 query = (char*)PlugSubAlloc(g, NULL, strlen(Tabname) + 26);
136 snprintf(query, strlen(Tabname) + 26, "SELECT * FROM `%s` LIMIT 1", Tabname);
137 } else if (!Tabsrc) {
138 snprintf(g->Message, sizeof(g->Message), MSG(SRC_TABLE_UNDEF));
139 goto err;
140 } else
141 query = (char*)Tabsrc;
142
143 // Open a MySQL connection for this table
144 if (!Myc.Open(g, Host, Database, User, Pwd, Port)) {
145 b = true;
146
147 // Returned values must be in their original character set
148 if (Myc.ExecSQL(g, "SET character_set_results=NULL", &w) == RC_FX)
149 goto err;
150 else
151 Myc.FreeResult();
152
153 } else
154 goto err;
155
156 // Send the source command to MySQL
157 if (Myc.ExecSQL(g, query, &w) == RC_FX)
158 goto err;
159
160 // We must have a storage query to get pivot column values
161 if (!(Qryp = Myc.GetResult(g, true)))
162 goto err;
163
164 if (!Fncol) {
165 for (crp = Qryp->Colresp; crp; crp = crp->Next)

Callers 1

PivotColumnsFunction · 0.80

Calls 15

PlugSubAllocFunction · 0.85
PlgDBallocFunction · 0.85
AllocateValueFunction · 0.85
PlugDupFunction · 0.85
ExecSQLMethod · 0.80
FreeResultMethod · 0.80
GetPrecMethod · 0.80
SetValue_pvblkMethod · 0.80
InitValueMethod · 0.80
InitColumnMethod · 0.80
htrcFunction · 0.70
OpenMethod · 0.45

Tested by

no test coverage detected