120 likes | 293 Views
Chapter 4. Accessing Database Tables. Create a table. Fields in Visual FoxPro Character (254 bytes) Numeric/Float (20 bytes) Date/DateTime (8 bytes/8 bytes) Integer (4 bytes) Logical (1 byte) Currency (8 bytes) Memo (4 bytes + unlimited). USE and CLOSE.
E N D
Chapter 4 Accessing Database Tables Foxpro Chapter 4
Create a table • Fields in Visual FoxPro • Character (254 bytes) • Numeric/Float (20 bytes) • Date/DateTime (8 bytes/8 bytes) • Integer (4 bytes) • Logical (1 byte) • Currency (8 bytes) • Memo (4 bytes + unlimited) Foxpro Chapter 4
USE and CLOSE • USE file1 && file1 is used • USE file2 && file2 is used, file1 closed • USE && file2 is closed • CLOSE DATABASES && close all files note: you may open 2 or more files at the same time see chapter 7 Foxpro Chapter 4
MODIFY STRUCTURE • Fields in a table can be modified using the MODIFY STRUCTURE Command • Adding new fields • Deleting existing fields • Changing name, type or length of fields • Data in the table may be lost if you • delete a column • change the type of a column • What about change name or length? Foxpro Chapter 4
How to Recover the Original File? • Save File1 for the first time File1.dbf • When File1 is revised and saved File1.bak (original) and File1.dbf (revised) • When File1 is revised and saved again File1.bak (original) and File1.dbf (revised) • COPY FILE File1.bak TO File1.dbf Foxpro Chapter 4
SET DEFAULT TO • SET DEFAULT TO c:\aFox • Files will be searched under this directory (c:\aFox) • Newly created files will be placed here (c:\aFox) • SET PATH TO a:\ • Files not found in c:\aFox will be searched under the directory specified by the path (a:\) • SET PATH TO u:\student\olc06145 • Where will newly created files be saved? • What about original file? Foxpro Chapter 4
LIST, BROWSE, EDIT... • LIST && all records and fields • SET FIELDS TO • restrict columns to be displayed • SET FILTER TO • restrict rows to be displayed • LIST/BROWSE/EDIT FIELDS … FOR … • FIELDS - restrict columns to be displayed • FOR - restrict rows to be displayed Foxpro Chapter 4
Accessing a Specific Record Suppose a file has 3 records BOF -- 1 -- 2 -- 3 -- EOF Let Rptr = record pointer • GO TOP Rptr --> 1 recno()=1 • GO BOTTOM Rptr --> 3 recno()=3 • SKIP -3 Rptr --> BOF recno()=1 not 0 • SKIP Rptr --> 1 recno()=1 • SKIP 3 Rptr --> EOF recno()=4 not 3 Foxpro Chapter 4
Useful FunctionsRECCOUNT() EOF() BOF() Suppose a file has 3 records BOF -- 1 -- 2 -- 3 -- EOF • RECCOUNT()=3 total number of records • GO TOP BOF()=.F. EOF()=.F. • GO BOTTOM BOF()=.F. EOF()=.F. • SKIP -3 BOF()=.T. EOF()=.F. • SKIP BOF()=.F. EOF()=.F. • SKIP 3 BOF()=.F. EOF()=.T. Foxpro Chapter 4
Accessing the Memo Field • Double click the “memo” field of a record • A text editing window will appear • Press Control-W to close the window Foxpro Chapter 4
Displaying Contents of a Record Class Name 7A Chan 7S Wong GO BOTTOM ?Name && Wong ?Name=‘Cheung’ && a variable ?Name && Wong ?m->Name && Cheung Foxpro Chapter 4
Exercise • P.121 • Q.1, Q.2, Q.3, Q.4 • P.122 • Q.11 • P.123 • Q.13 • P.124 • Q.15 Foxpro Chapter 4