/ DOS Cardinality: returns table cardinality in number of rows. */ This function can be called with a null argument to test the */ availability of Cardinality implementation (1 yes, 0 no). */ /
| 1972 | /* availability of Cardinality implementation (1 yes, 0 no). */ |
| 1973 | /***********************************************************************/ |
| 1974 | int TDBDOS::Cardinality(PGLOBAL g) |
| 1975 | { |
| 1976 | int n = Txfp->Cardinality(NULL); |
| 1977 | |
| 1978 | if (!g) |
| 1979 | return (Mode == MODE_ANY) ? 1 : n; |
| 1980 | |
| 1981 | if (Cardinal < 0) { |
| 1982 | if (!Txfp->Blocked && n == 0) { |
| 1983 | // Info command, we try to return exact row number |
| 1984 | PDOSDEF dfp = (PDOSDEF)To_Def; |
| 1985 | PIXDEF xdp = dfp->To_Indx; |
| 1986 | |
| 1987 | if (xdp && xdp->IsValid()) { |
| 1988 | // Cardinality can be retreived from one index |
| 1989 | PXLOAD pxp; |
| 1990 | |
| 1991 | if (dfp->Huge) |
| 1992 | pxp = new(g) XHUGE; |
| 1993 | else |
| 1994 | pxp = new(g) XFILE; |
| 1995 | |
| 1996 | PXINDEX kxp = new(g) XINDEX(this, xdp, pxp, NULL, NULL); |
| 1997 | |
| 1998 | if (!(kxp->GetAllSizes(g, Cardinal))) |
| 1999 | return Cardinal; |
| 2000 | |
| 2001 | } // endif Mode |
| 2002 | |
| 2003 | if (Mode == MODE_ANY && ExactInfo()) { |
| 2004 | // Using index impossible or failed, do it the hard way |
| 2005 | Mode = MODE_READ; |
| 2006 | To_Line = (char*)PlugSubAlloc(g, NULL, (size_t)Lrecl + 1); |
| 2007 | |
| 2008 | if (Txfp->OpenTableFile(g)) |
| 2009 | return (Cardinal = Txfp->Cardinality(g)); |
| 2010 | |
| 2011 | for (Cardinal = 0; n != RC_EF;) |
| 2012 | if (!(n = Txfp->ReadBuffer(g))) |
| 2013 | Cardinal++; |
| 2014 | |
| 2015 | Txfp->CloseTableFile(g, false); |
| 2016 | Mode = MODE_ANY; |
| 2017 | } else { |
| 2018 | // Return the best estimate |
| 2019 | int len = GetFileLength(g); |
| 2020 | |
| 2021 | if (len >= 0) { |
| 2022 | int rec; |
| 2023 | |
| 2024 | if (trace(1)) |
| 2025 | htrc("Estimating lines len=%d ending=%d/n", |
| 2026 | len, ((PDOSDEF)To_Def)->Ending); |
| 2027 | |
| 2028 | /*************************************************************/ |
| 2029 | /* Estimate the number of lines in the table (if not known) */ |
| 2030 | /* by dividing the file length by the average record length. */ |
| 2031 | /*************************************************************/ |
nothing calls this directly
no test coverage detected