/ MakeSrcdef: make the SQL statement from SRDEF option. */ /
| 326 | /* MakeSrcdef: make the SQL statement from SRDEF option. */ |
| 327 | /***********************************************************************/ |
| 328 | bool TDBEXT::MakeSrcdef(PGLOBAL g) |
| 329 | { |
| 330 | char *catp = strstr(Srcdef, "%s"); |
| 331 | |
| 332 | if (catp) { |
| 333 | char *fil1 = 0, *fil2 = 0; |
| 334 | PCSZ ph = ((EXTDEF*)To_Def)->Phpos; |
| 335 | |
| 336 | if (!ph) |
| 337 | ph = (strstr(catp + 2, "%s")) ? "WH" : "W"; |
| 338 | |
| 339 | if (stricmp(ph, "H")) { |
| 340 | fil1 = (To_CondFil && *To_CondFil->Body) |
| 341 | ? To_CondFil->Body : PlugDup(g, "1=1"); |
| 342 | } // endif ph |
| 343 | |
| 344 | if (stricmp(ph, "W")) { |
| 345 | fil2 = (To_CondFil && To_CondFil->Having && *To_CondFil->Having) |
| 346 | ? To_CondFil->Having : PlugDup(g, "1=1"); |
| 347 | } // endif ph |
| 348 | |
| 349 | int n_placeholders = count_placeholders(Srcdef); |
| 350 | if (n_placeholders < 0) |
| 351 | { |
| 352 | safe_strcpy(g->Message, sizeof(g->Message), "MakeSQL: Wrong place holders specification"); |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | if (!stricmp(ph, "W") && n_placeholders <= 1) { |
| 357 | Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1)); |
| 358 | Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil1)); |
| 359 | } |
| 360 | else if (!stricmp(ph, "WH") && n_placeholders <= 2) |
| 361 | { |
| 362 | Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1) + strlen(fil2)); |
| 363 | Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil1, fil2)); |
| 364 | } |
| 365 | else if (!stricmp(ph, "H") && n_placeholders <= 1) |
| 366 | { |
| 367 | Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil2)); |
| 368 | Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil2)); |
| 369 | } |
| 370 | else if (!stricmp(ph, "HW") && n_placeholders <= 2) |
| 371 | { |
| 372 | Query = new(g)STRING(g, strlen(Srcdef) + strlen(fil1) + strlen(fil2)); |
| 373 | Query->SetLength(snprintf(Query->GetStr(), Query->GetSize(), Srcdef, fil2, fil1)); |
| 374 | } else { |
| 375 | safe_strcpy(g->Message, sizeof(g->Message), "MakeSQL: Wrong place holders specification"); |
| 376 | return true; |
| 377 | } // endif's ph |
| 378 | |
| 379 | } else |
| 380 | Query = new(g)STRING(g, 0, Srcdef); |
| 381 | |
| 382 | return false; |
| 383 | } // end of MakeSrcdef |
| 384 | |
| 385 | /***********************************************************************/ |
nothing calls this directly
no test coverage detected