/ Make the Pivot table column list. */ /
| 106 | /* Make the Pivot table column list. */ |
| 107 | /***********************************************************************/ |
| 108 | PQRYRES 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) |
no test coverage detected