/ Init: Open and Initialize a Key Index. */ /
| 1201 | /* Init: Open and Initialize a Key Index. */ |
| 1202 | /***********************************************************************/ |
| 1203 | bool XINDEX::MapInit(PGLOBAL g) |
| 1204 | { |
| 1205 | /*********************************************************************/ |
| 1206 | /* Table will be accessed through an index table. */ |
| 1207 | /* If sorting is required, this will be done later. */ |
| 1208 | /*********************************************************************/ |
| 1209 | const char *ftype; |
| 1210 | BYTE *mbase; |
| 1211 | char fn[_MAX_PATH]; |
| 1212 | int *nv, nv0, k, n, id = -1; |
| 1213 | bool estim; |
| 1214 | PCOL colp; |
| 1215 | PXCOL prev = NULL, kcp = NULL; |
| 1216 | PDOSDEF defp = (PDOSDEF)Tdbp->To_Def; |
| 1217 | |
| 1218 | /*********************************************************************/ |
| 1219 | /* Get the estimated table size. */ |
| 1220 | /* Note: for fixed tables we must use cardinality to avoid the call */ |
| 1221 | /* to MaxBlkSize that could reduce the cardinality value. */ |
| 1222 | /*********************************************************************/ |
| 1223 | if (Tdbp->Cardinality(NULL)) { |
| 1224 | // For DBF tables, Cardinality includes bad or soft deleted lines |
| 1225 | // that are not included in the index, and can be larger then the |
| 1226 | // index size. |
| 1227 | estim = (Tdbp->Ftype == RECFM_DBF); |
| 1228 | n = Tdbp->Cardinality(g); // n is exact table size |
| 1229 | } else { |
| 1230 | // Variable table not optimized |
| 1231 | estim = true; // n is an estimate of the size |
| 1232 | n = Tdbp->GetMaxSize(g); |
| 1233 | } // endif Cardinality |
| 1234 | |
| 1235 | if (n <= 0) |
| 1236 | return !(n == 0); // n < 0 error, n = 0 void table |
| 1237 | |
| 1238 | /*********************************************************************/ |
| 1239 | /* Get the first key column. */ |
| 1240 | /*********************************************************************/ |
| 1241 | if (!Nk || !To_Cols || (!To_Vals && Op != OP_FIRST && Op != OP_FSTDIF)) { |
| 1242 | strcpy(g->Message, MSG(NO_KEY_COL)); |
| 1243 | return true; // Error |
| 1244 | } else |
| 1245 | colp = To_Cols[0]; |
| 1246 | |
| 1247 | switch (Tdbp->Ftype) { |
| 1248 | case RECFM_VAR: ftype = ".dnx"; break; |
| 1249 | case RECFM_FIX: ftype = ".fnx"; break; |
| 1250 | case RECFM_BIN: ftype = ".bnx"; break; |
| 1251 | case RECFM_VCT: ftype = ".vnx"; break; |
| 1252 | case RECFM_CSV: ftype = ".cnx"; break; |
| 1253 | case RECFM_DBF: ftype = ".dbx"; break; |
| 1254 | default: |
| 1255 | snprintf(g->Message, sizeof(g->Message), MSG(INVALID_FTYPE), Tdbp->Ftype); |
| 1256 | return true; |
| 1257 | } // endswitch Ftype |
| 1258 | |
| 1259 | if (defp->SepIndex()) { |
| 1260 | // Index was save in a separate file |
nothing calls this directly
no test coverage detected