File: sample2.cpp

package info (click to toggle)
xdb 1.2.0-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,676 kB
  • ctags: 1,055
  • sloc: cpp: 14,001; sh: 6,343; makefile: 150
file content (177 lines) | stat: -rw-r--r-- 6,615 bytes parent folder | download | duplicates (3)
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
/*  $Id: sample2.cpp,v 1.6 1999/03/19 10:56:32 willy Exp $

    Xbase project source code

    This sample program updates the database created by the sample1 
    program

    This program demonstrates the use of the following functions/methods
      OpenDatabase, GetFieldNo, BlankRecord, AppendRecord, 
      PutField and CloseDatabase 

    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>
extern unsigned _stklen = 100000;
#endif

int main()
{
  xbShort lname, fname, birthdate, amount, sw, f1, f2, f3, f4, m1, rc, z;
  xbFloat f;

  xbXBase x;
  xbDbf MyFile( &x );
#ifdef XB_INDEX_NDX
  xbNdx MyIndex1( &MyFile );
  xbNdx MyIndex2( &MyFile );
  xbNdx MyIndex3( &MyFile );
  xbNdx MyIndex4( &MyFile );
#endif // XB_INDEX_NDX

  MyFile.OpenDatabase( "MYFILE.DBF" );
#ifdef XB_INDEX_NDX
  if(( rc = MyIndex1.OpenIndex( "MYINDEX1.NDX" )) != XB_NO_ERROR )
     cout << "\nError opening index1 rc=" << rc;
  if(( rc = MyIndex2.OpenIndex( "MYINDEX2.NDX" )) != XB_NO_ERROR )
     cout << "\nError opening index2 rc=" << rc;
  if(( rc = MyIndex3.OpenIndex( "MYINDEX3.NDX" )) != XB_NO_ERROR )
     cout << "\nError opening index3 rc=" << rc;
  if(( rc = MyIndex4.OpenIndex( "MYINDEX4.NDX" )) != XB_NO_ERROR )
     cout << "\nError opening index4 rc=" << rc;
#endif // XB_INDEX_NDX

  lname     = MyFile.GetFieldNo( "LASTNAME" );
  fname     = MyFile.GetFieldNo( "FIRSTNAME" ); 
  birthdate = MyFile.GetFieldNo( "BIRTHDATE" ); 
  amount    = MyFile.GetFieldNo( "AMOUNT" );
  sw        = MyFile.GetFieldNo( "SWITCH" );
  f1        = MyFile.GetFieldNo( "FLOAT1" );
  f2        = MyFile.GetFieldNo( "FLOAT2" );
  f3        = MyFile.GetFieldNo( "FLOAT3" );
  f4        = MyFile.GetFieldNo( "FLOAT4" );
  m1        = MyFile.GetFieldNo( "MEMO1" );
  z         = MyFile.GetFieldNo( "ZIPCODE" );

  cout << "\nLast Name Id  = " << lname;
  cout << "\nFirst Name Id = " << fname;
  cout << "\nBirthdate Id  = " << birthdate;
  cout << "\nAmount Id     = " << amount;
  cout << "\nSwitch Id     = " << sw;
  cout << "\nFloat 1 Id    = " << f1;  
  cout << "\nFloat 2 Id    = " << f2;
  cout << "\nFloat 3 Id    = " << f3;
  cout << "\nFloat 4 Id    = " << f4;
#ifdef XB_MEMO_FIELDS
  cout << "\nMemo1 Id      = " << m1;
#endif
  cout << "\nZipcode Id    = " << z << "\n";

  /* build record one */
  MyFile.BlankRecord();			/* blank out the record buffer */
  MyFile.PutField( lname, "Queue" );			/* a name */
  MyFile.PutField( fname, "Suzy" );			/* a name */
  MyFile.PutField( birthdate, x.Sysdate());		/* a date */
  MyFile.PutField( amount, "99.99" );			/* an amount */
  MyFile.PutField( sw, "Y" );				/* a switch */
  f = 1.466f;
  MyFile.PutFloatField( f1, f );
  MyFile.PutFloatField( "FLOAT2", f );
  MyFile.PutField( f3, "1" );
  MyFile.PutField( f4, "1" );
  MyFile.PutField( z, "76262" );
  if(( rc = MyFile.AppendRecord()) != XB_NO_ERROR )       /* write it */
     cout << "\nError " << rc << " appending data record.";

  /* build record two */
  MyFile.BlankRecord();			/* blank out the record buffer */
  MyFile.PutField( lname, "Bob" );			/* a name */
  MyFile.PutField( fname, "Billy" );			/* a name */
  MyFile.PutField( birthdate, "19970304" );		/* a date */
  MyFile.PutField( amount, "88.88" );			/* an amount */
  MyFile.PutField( sw, "N" );				/* a switch */
  f = -2.1f; 
  MyFile.PutFloatField( f1, f );
  MyFile.PutFloatField( "FLOAT2", -2.1f );
  MyFile.PutField( f1, "-2.1" );
  MyFile.PutField( f2, "-2.1" );
  MyFile.PutField( f3, "-2.1" );
  MyFile.PutField( f4, "-2.1" );
  MyFile.PutField( z, "76261" );
#ifdef XB_MEMO_FIELDS
  MyFile.UpdateMemoData( m1, 20, "Sample memo field 2", F_SETLKW );
#endif
  if(( rc = MyFile.AppendRecord()) != XB_NO_ERROR )       /* write it */
     cout << "\nError " << rc << " appending data record.";

  /* build record three */
  MyFile.BlankRecord();			/* blank out the record buffer */
  MyFile.PutField( lname, "Slippery" );			/* a name */
  MyFile.PutField( fname, "Sam" );			/* a name */
  MyFile.PutField( birthdate, "19970406" );		/* a date */
  MyFile.PutField( amount, "77.77" );			/* an amount */
  MyFile.PutField( sw, "T" );				/* a switch */
  f = 3.21f; 
  MyFile.PutFloatField( f1, f );
  MyFile.PutFloatField( "FLOAT2", 3.21f );
  MyFile.PutField( f1, "3.21" );
  MyFile.PutField( f2, "3.21" );
  MyFile.PutField( f3, "3.21" );
  MyFile.PutField( f4, "3.21" );
  MyFile.PutField( z, "76263" );
#ifdef XB_MEMO_FIELDS
  MyFile.UpdateMemoData( m1, 20, "Sample memo field 3", F_SETLKW );
#endif
  if(( rc = MyFile.AppendRecord()) != XB_NO_ERROR )       /* write it */
     cout << "\nError " << rc << " appending data record.";

  /* build record four */
  MyFile.BlankRecord();			/* blank out the record buffer */
  MyFile.PutField( lname, "Lucas" );			/* a name */
  MyFile.PutField( fname, "George" );			/* a name */
  MyFile.PutField( birthdate, "19470406" );		/* a date */
  MyFile.PutField( amount, "77.77" );			/* an amount */
  MyFile.PutField( sw, "T" );				/* a switch */
  f = 4.321f; 
  MyFile.PutFloatField( f1, f );
  MyFile.PutFloatField( "FLOAT2", 4.321f );
  MyFile.PutField( f1, "4.321" );
  MyFile.PutField( f2, "4.321" );
  MyFile.PutField( f3, "4.321" );
  MyFile.PutField( f4, "4.321" );
  MyFile.PutField( z, "76260" );
#ifdef XB_MEMO_FIELDS
  MyFile.UpdateMemoData( m1, 20, "Sample memo field 4", F_SETLKW );
#endif
  if(( rc = MyFile.AppendRecord()) != XB_NO_ERROR )       /* write it */
     cout << "\nError " << rc << " appending data record.";

  MyFile.CloseDatabase();				/* close database */
  return 0;
}