1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/* $Id: indextst.cpp,v 1.2 1999/03/19 10:56:32 willy Exp $
Xbase project source code
This program creates a sample database and multiple indices.
It tests the index logic.
Copyright (C) 1997 StarTech, Gary A. Kunkel
email - xbase@startech.keller.tx.us
www - http://www.startech.keller.tx.us/xbase.html
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
V 1.0 10/10/97 - Initial release of software
V 1.5 1/2/98 - Added memo field support
V 1.6a 5/1/98 - Added expression support
V 1.8 11/29/98 - Version 1.8 upgrade
*/
#include <xdb/xbase.h>
/* set the stack large for dos compiles */
#ifdef __XBDOS
#include <stdio.h>
/* FIXME? what compiler requires this and how to tell that compiler?
__XBDOS has very unclean semantics -- willy */
extern unsigned _stklen = 100000;
#endif
int main()
{
xbShort f1, f2, f3, rc, sts = 0;
char charbuf[10];
xbSchema MyRecord[] =
{
{ "CHARFLD1", XB_CHAR_FLD, 6, 0 },
{ "CHARFLD2", XB_CHAR_FLD, 6, 0 },
{ "NUMFLD1", XB_NUMERIC_FLD, 6, 0 },
{ "",0,0,0 }
};
/* define the classes */
xbXBase x; /* initialize xbase */
xbDbf MyFile( &x ); /* class for table */
#ifdef XB_INDEX_ANY
#ifdef XB_INDEX_NDX
xbNdx indx1( &MyFile ); /* class for ndx index 1 */
xbNdx indx2( &MyFile ); /* class for ndx index 2 */
xbNdx indx3( &MyFile ); /* class for ndx index 3 */
#endif // XB_INDEX_NDX
#ifdef XB_INDEX_NTX
xbNtx intx1( &MyFile ); /* class for ntx index 1 */
xbNtx intx2( &MyFile ); /* class for ntx index 2 */
xbNtx intx3( &MyFile ); /* class for ntx index 3 */
#endif // XB_INDEX_NTX
#endif // XB_INDEX_ANY
std::cout << "Creating test database and indices" << std::endl;
if(( rc = MyFile.CreateDatabase( "IXTEST.DBF", MyRecord, XB_OVERLAY ))
!= XB_NO_ERROR )
std::cout << "Error creating database = " << rc << "\n";
else
{
#ifdef XB_INDEX_ANY
#ifdef XB_INDEX_NDX
if(( rc = indx1.CreateIndex(
"IXNDX1.NDX", "CHARFLD1", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 1 = " << rc << std::endl;
exit( 1 );
}
if(( rc = indx2.CreateIndex(
"IXNDX2.NDX", "CHARFLD1+CHARFLD2", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 2 = " << rc << std::endl;
exit( 1 );
}
if(( rc = indx3.CreateIndex(
"IXNDX3.NDX", "NUMFLD1", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 3 = " << rc << std::endl;
exit( 1 );
}
#endif // XB_INDEX_NDX
#ifdef XB_INDEX_NTX
if(( rc = intx1.CreateIndex(
"IXNTX1.NTX", "CHARFLD1", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 4 = " << rc << std::endl;
exit( 1 );
}
if(( rc = intx2.CreateIndex(
"IXNTX2.NTX", "CHARFLD1+CHARFLD2", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 5 = " << rc << std::endl;
exit( 1 );
}
if(( rc = intx3.CreateIndex(
"IXNTX3.NTX", "NUMFLD1", XB_NOT_UNIQUE, XB_OVERLAY )) != XB_NO_ERROR )
{
std::cout << "Error creating index 6 = " << rc << std::endl;
exit( 1 );
}
#endif // XB_INDEX_NTX
#endif // XB_INDEX_ANY
}
f1 = MyFile.GetFieldNo( "CHARFLD1" );
f2 = MyFile.GetFieldNo( "CHARFLD2" );
f3 = MyFile.GetFieldNo( "NUMFLD1" );
std::cout << "Populating database and indices with data" << std::endl;
for( int i = 0; i < 1000; i++ ){
memset( charbuf, 0x00, 10 );
sprintf( charbuf, "%d", i );
MyFile.BlankRecord();
MyFile.PutField( f1, charbuf );
MyFile.PutField( f2, charbuf );
MyFile.PutLongField( f3, i );
MyFile.AppendRecord();
}
#ifdef XB_INDEX_ANY
#ifdef XB_INDEX_NDX
std::cout << "Testing NDX index 1" << std::endl;
if(( rc = indx1.CheckIndexIntegrity(0)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index indx1" << std::endl;
sts++;
}
std::cout << "Testing NDX index 2" << std::endl;
if(( rc = indx2.CheckIndexIntegrity(0)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index indx2" << std::endl;
sts++;
}
std::cout << "Testing NDX index 3" << std::endl;
if(( rc = indx3.CheckIndexIntegrity(0)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index indx3" << std::endl;
sts++;
}
#endif
#ifdef XB_INDEX_NTX
std::cout << "Testing NTX index 1" << std::endl;
if(( rc = intx1.CheckIndexIntegrity(1)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index intx1" << std::endl;
sts++;
}
std::cout << "Testing NTX index 2" << std::endl;
if(( rc = intx2.CheckIndexIntegrity(1)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index intx2" << std::endl;
sts++;
}
std::cout << "Testing NTX index 3" << std::endl;
if(( rc = intx3.CheckIndexIntegrity(1)) != XB_NO_ERROR ){
std::cout << "Error " << rc << " with index intx3" << std::endl;
sts++;
}
#endif // XB_INDEX_NTX
#endif // XB_INDEX_ANY
std::cout << "Index testing completed" << std::endl;
MyFile.CloseDatabase(); /* Close database and associated indexes */
return sts;
}
|