/ Make: Make and index on key column(s). */ /
| 309 | /* Make: Make and index on key column(s). */ |
| 310 | /***********************************************************************/ |
| 311 | bool XINDEX::Make(PGLOBAL g, PIXDEF sxp) |
| 312 | { |
| 313 | /*********************************************************************/ |
| 314 | /* Table can be accessed through an index. */ |
| 315 | /*********************************************************************/ |
| 316 | int k, nk = Nk, rc = RC_OK; |
| 317 | int *bof, i, j, n, ndf, nkey; |
| 318 | PKPDEF kdfp = Xdp->GetToKeyParts(); |
| 319 | bool brc = false; |
| 320 | PCOL colp; |
| 321 | PFIL filp = Tdbp->GetFilter(); |
| 322 | PXCOL kp, addcolp, prev = NULL, kcp = NULL; |
| 323 | //PDBUSER dup = (PDBUSER)g->Activityp->Aptr; |
| 324 | |
| 325 | #if defined(_DEBUG) |
| 326 | assert(X || Nk == 1); |
| 327 | #endif // _DEBUG |
| 328 | |
| 329 | /*********************************************************************/ |
| 330 | /* Allocate the storage that will contain the keys and the file */ |
| 331 | /* positions corresponding to them. */ |
| 332 | /*********************************************************************/ |
| 333 | if ((n = Tdbp->GetMaxSize(g)) < 0) |
| 334 | return true; |
| 335 | else if (!n) { |
| 336 | Num_K = Ndif = 0; |
| 337 | MaxSame = 1; |
| 338 | |
| 339 | // The if condition was suppressed because this may be an existing |
| 340 | // index that is now void because all table lines were deleted. |
| 341 | // if (sxp) |
| 342 | goto nox; // Truncate eventually existing index file |
| 343 | // else |
| 344 | // return false; |
| 345 | |
| 346 | } // endif n |
| 347 | |
| 348 | if (trace(1)) |
| 349 | htrc("XINDEX Make: n=%d\n", n); |
| 350 | |
| 351 | // File position must be stored |
| 352 | Record.Size = n * sizeof(int); |
| 353 | |
| 354 | if (!PlgDBalloc(g, NULL, Record)) { |
| 355 | snprintf(g->Message, sizeof(g->Message), MSG(MEM_ALLOC_ERR), "index", n); |
| 356 | goto err; // Error |
| 357 | } // endif |
| 358 | |
| 359 | /*********************************************************************/ |
| 360 | /* Allocate the KXYCOL blocks used to store column values. */ |
| 361 | /*********************************************************************/ |
| 362 | for (k = 0; k < Nk; k++) { |
| 363 | colp = To_Cols[k]; |
| 364 | |
| 365 | if (!kdfp) { |
| 366 | snprintf(g->Message, sizeof(g->Message), MSG(INT_COL_ERROR), |
| 367 | (colp) ? colp->GetName() : "???"); |
| 368 | goto err; // Error |
no test coverage detected