summaryrefslogtreecommitdiff
path: root/src/examples/xb_ex_v4_create_dbf.cpp
blob: a2aff748dfb576681456ce2500d5212a796597d7 (plain)
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
/*  xb_ex_v4_create_dbf.cpp

XBase64 Software Library

Copyright (c) 1997,2003,2014,2022 Gary A Kunkel

The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.

Email Contact:

    XDB-devel@lists.sourceforge.net
    XDB-users@lists.sourceforge.net

    This example demonstrates the creation of a Version IV file and and indices 

*/

#include <xbase.h>

using namespace xb;

int main()
{

#ifdef XB_DBF4_SUPPORT

  xbSchema MyRecord[] =
  {
    { "FIRSTNAME", XB_CHAR_FLD,     15, 0 },
    { "LASTNAME",  XB_CHAR_FLD,     20, 0 },
    { "BIRTHDATE", XB_DATE_FLD,      8, 0 },
    { "AMOUNT",    XB_NUMERIC_FLD,   9, 2 },
    { "RETIRED?",  XB_LOGICAL_FLD,   1, 0 },
    { "ZIPCODE",   XB_NUMERIC_FLD,   5, 0 },
    { "NUMFLD1",   XB_FLOAT_FLD,    12, 2 },
    { "NUMFLD2",   XB_FLOAT_FLD,    14, 2 },
    #ifdef XB_MEMO_SUPPORT
    { "MEMO1",     XB_MEMO_FLD,     10, 0 },
    #endif
    { "",0,0,0 }
  };

  /* define the classes */
  xbXBase x;                                /* initialize xbase             */
  x.SetDataDirectory( PROJECT_DATA_DIR );   /* where all the tables/files live    */

  xbInt16 iRc;
  xbDbf * MyDbfFile;
  xbIx *pIx;
  void *pTag;
  MyDbfFile = new xbDbf4( &x );

  if(( iRc = MyDbfFile->CreateTable( "MyV4Table1", "MyV4TableAlias", MyRecord, XB_OVERLAY, XB_MULTI_USER )) != XB_NO_ERROR )
    x.DisplayError( iRc );
  else
  {

    #ifdef XB_MDX_SUPPORT

    /*
     Create a few index tags
     CreateTag( const xbString &sIxType, const xbString &sName, const xbString &sKey, const xbString &sFilter, 
               xbInt16 iDescending, xbInt16 iUnique, xbInt16 iOverLay, xbIx **xbIxOut, void **vpTagOut );
    */

    // std::cout << "Creating three index tags\n";
    if(( iRc = MyDbfFile->CreateTag( "MDX", "NAME_TAG",   "LASTNAME+FIRSTNAME", ".NOT. DELETED()", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
      x.DisplayError( iRc );
    if(( iRc = MyDbfFile->CreateTag( "MDX", "BDDATE_TAG",  "BIRTHDATE", "", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
      x.DisplayError( iRc );
    if(( iRc = MyDbfFile->CreateTag( "MDX", "ZIP_TAG",   "ZIPCODE", "", 0, 0, XB_OVERLAY, &pIx, &pTag )) != XB_NO_ERROR )
      x.DisplayError( iRc );

    #endif  // XB_MDX_SUPPORT
  }

  MyDbfFile->Close();   /* Close database and associated indexes */

#endif // XB_DBF4_SUPPORT
  return 0;
}