/ Get the PTDB of the sub-table. */ /
| 391 | /* Get the PTDB of the sub-table. */ |
| 392 | /***********************************************************************/ |
| 393 | PTDB TDBPRX::GetSubTable(PGLOBAL g, PTABLE tabp, bool b) |
| 394 | { |
| 395 | const char *sp = NULL; |
| 396 | char *db, *name; |
| 397 | bool mysql = true; |
| 398 | PTDB tdbp = NULL; |
| 399 | TABLE_SHARE *s = NULL; |
| 400 | Field* *fp = NULL; |
| 401 | PCATLG cat = To_Def->GetCat(); |
| 402 | PHC hc = ((MYCAT*)cat)->GetHandler(); |
| 403 | LPCSTR cdb, curdb = hc->GetDBName(NULL); |
| 404 | THD *thd = (hc->GetTable())->in_use; |
| 405 | |
| 406 | db = (char*)(tabp->GetSchema() ? tabp->GetSchema() : curdb); |
| 407 | name = (char*)tabp->GetName(); |
| 408 | |
| 409 | // Check for eventual loop |
| 410 | for (PTABLE tp = To_Table; tp; tp = tp->Next) { |
| 411 | cdb = (tp->Schema) ? tp->Schema : curdb; |
| 412 | |
| 413 | if (!stricmp(name, tp->Name) && !stricmp(db, cdb)) { |
| 414 | snprintf(g->Message, sizeof(g->Message), "Table %s.%s pointing on itself", db, name); |
| 415 | return NULL; |
| 416 | } // endif |
| 417 | |
| 418 | } // endfor tp |
| 419 | |
| 420 | if (!tabp->GetSrc()) { |
| 421 | if (!(s = GetTableShare(g, thd, db, name, mysql))) |
| 422 | return NULL; |
| 423 | |
| 424 | if (s->is_view && !b) |
| 425 | s->field = hc->get_table()->s->field; |
| 426 | |
| 427 | hc->tshp = s; |
| 428 | } else if (b) { |
| 429 | // Don't use caller's columns |
| 430 | fp = hc->get_table()->field; |
| 431 | hc->get_table()->field = NULL; |
| 432 | |
| 433 | // Make caller use the source definition |
| 434 | sp = hc->get_table()->s->option_struct_table->srcdef; |
| 435 | hc->get_table()->s->option_struct_table->srcdef = tabp->GetSrc(); |
| 436 | } // endif srcdef |
| 437 | |
| 438 | if (mysql) { |
| 439 | // Access sub-table via MySQL API |
| 440 | if (!(tdbp= cat->GetTable(g, tabp, Mode, "MYPRX"))) { |
| 441 | char buf[MAX_STR]; |
| 442 | |
| 443 | strcpy(buf, g->Message); |
| 444 | snprintf(g->Message, sizeof(g->Message), "Error accessing %s.%s: %s", db, name, buf); |
| 445 | hc->tshp = NULL; |
| 446 | goto err; |
| 447 | } // endif Define |
| 448 | |
| 449 | if (db) |
| 450 | ((PTDBMY)tdbp)->SetDatabase(tabp->GetSchema()); |
nothing calls this directly
no test coverage detected