Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Using Data Structures

computers


Using Data Structures

7.1. - Generalities



7.1.1. - Data structure loading

7.1.2. - Viewing and editing data values

7.1.3. - Data filtering and attributes selection

7.1.4. - Data indexing

7.1.5. - Parameters setting

7.1.6. - Relationships between database files

7.1.7. - Building Working Environments

7.1. - Generalities

After the LOGICAL Database Definition (the definition of data structure using data NAMES) we also must define it Physical (the definition of the instances in the database files - the records - using data VALUES).

We can further define a subset of the collection of data stored in the database by defining for each table, corresponding to a database files, a vertical projection (with associated ATTRIBUTE LISTS) and a horizontal projection (with associated FILTER EXPRESSION).

To assure the appropriate methods of identification, accessing and order the data values in the database files we can associate one or more INDEXES on each database file.

7.1.1. - Data structure loading

To load data values in the defined database files we dispose on the following methods:

7.1.1.1. - Loading data values from the keyboard

After ending the creation of a database file we can begin to load data in the new created DB file, by answering Yes to the question issued by the system: Loading data now?

After selecting a DB file we can select in the MENU working mode the option RECORD / APPEND (the system automatically execute a BROWSE command for entering a new record)

Execute an APPEND command in the COMMAND working mode

7.1.1.2. - Loading data values from another files

After selecting a DB file we can select in the MENU working mode the option RECORD / APPEND FROM (the system automatically ask for:

the location

the name

the format

of the data file in which were stored the data values)

Execute an APPEND FROM command in the COMMAND working mode

7.1.2. - Viewing and editing data values

For viewing and editing data values the most user friendly facility offered from the X-Base systems is the using of the BRO 737b13h WSE command. This command can be used in three working modes: MENU, COMMAND and PROGRAM.

In general BROWSE is one of the most useful commands available in X-Base systems. Use BROWSE to open a window and display records from a database file. You can then easily edit and append records. You can have a Browse window open for each work area if you have sufficient memory.

Main action

- Navigating in a Browse Window

You can move from record to record with the UP and DOWN arrow keys or the vertical thumb. You can move forward and backward through a group of records with PAGE UP and PAGE DOWN keys. You can move to the next or previous field by pressing TAB or SHIFT TAB or by using the horizontal thumb.

- Saving your Changes

You may save any change you make to your data and exit BROWSE by pressing CTRL+W or CTRL+END or by clicking on the close box. If you press CTRL+Q or ESCAPE you may exit BROWSE without saving changes you made to the current field.

You can edit MEMO fields in the BROWSE window. To edit a MEMO field in a BROWSE place the cursor in the memo field and press CTRL+PgDn, or double-click on the MEMO field to open it for editing. To exit the MEMO field and save your changes press CTRL+W or click on the close box. If you do not save your change press ESCAPE.

- BROWSE and Related Files

FoxPro allows you to establish relationships between databases. If a relationship is established, when the record pointer is moved in the parent database, the record pointer is automatically positioned on the corresponding record in the child database. You can open a BROWSE window for the parent window and one for each of the child databases. When you move to a record in the parent BROWSE window, the proper record or records are displayed in the child BROWSE window.

In a single BROWSE window you can include fields from both the parent database and any child databases. The FIELDS clause described in further detail below allows you to include a list of fields from the parent and child databases.

Select the work area of the parent database. Then issue BROWSE with the FIELDS clause. When you include fields from child databases in the field list of FIELDS, preface the child field names with their database alias and a period.

For additional information on creating relationships between databases, see SET RELATION in this section.

- SET SKIP Support

SET SKIP lets you to establish a one to many relationships between two databases. For each record from the parent database that appears in the BROWSE window, all related records (if any) from child database will appear. The parent record will appear once along with the first matching record from the child database. Subsequent matching records (if any) will appear in the rows following the parent and first matching child record. Shaded blocks will appear in any column containing information from the parent database beyond the first matching record.

If you are on a parent record, you can move between each of the parent records in the BROWSE window by pressing CTRL + | to move to the next parent record, or CTRL + | to move to the previous parent record.

Example

In the following command sequence a one-to-many relationship is created with SET SKIP. We consider the former defined database with the schema:

PART (code, name, color, weight) KEY code

SUPPLIER (code, name, city) KEY code

ORDER (part, supplier, quantity) KEY (part, supplier)

We want to display for each ordered PART the name the SUPPLIER name, and the ordered quantity.

CLEAR

CLOSE ALL

SELECT 0  && first available work area

USE PART  && parent relation for first relationship

SELECT 0  && first available work area

USE ORDER  && child relation for first relationship

INDEX ON part && index child relation

SELECT 0  && first available work area

USE SUPPLIER  && child relation for second relationship

INDEX ON code && index child relation

SELECT PART  && select parent relation

SET RELATION TO code INTO ORDER && index child relation

SET SKIP ON  && establish first relationship

SELECT ORDER  && select parent relation

SET RELATION TO supplier INTO SUPPLIER && establish second relationship

SELECT PART  && select parent relation

BROWSE FIELDS PART.name, SUPPLIER.name, ORDER.quantity

Useful Functions

Several functions return useful information from a Browse window:

- VARREAD ( ) - can be used to determine the current field name in a Browse window

- RECNO ( ) - returns the record number of the currently selected record

- ROW ( ) and COL ( ) - return the position of the cursor in the Browse window

7.1.3. - Data filtering and attributes selection

You can work with a subset of a table by using PARTITION VIEWS. A PARTITION VIEW is a selection of attributes from the defining list attributes of the table and also a selection of the tuples that satisfy a certain condition. Attaching to a table can create such PARTITION VIEW:

- a list of desired attributes

- a condition expression

Using two commands can make this operation:

- SET FIELDS ON | OFF

- SET FIELDS TO [ [ < field1 > [ , < field2 > . ] ] | ALL ]

This command designates which fields can be accessed within a database file currently in USE. The specified fields are activated, when SET FIELDS is ON, although using SET FIELDS TO with a field listing automatically SET-s FIELDS ON.

If SET FIELDS is OFF then all the fields within the currently selected database file are accessible. The default value is OFF.

If SET FIELDS is SET ON then only those fields that have been specified in SET FIELDS TO can be accessed.

< field1 > , < field2 > . build the field listing that can be accessed.

Using consecutive SET FIELDS TO commands with a field listing adds fields to those that are currently accessible, while using SET FIELDS TO ALL makes all the fields within the currently selected database file accessible.

Using SET FIELDS TO without including a field list or the ALL option removes all fields from a field listing for the currently selected DBF.

- SET FILTER TO [ < EXPl > ]

This command provides access to records that meet a condition indicated by < expL >. Once this SET command is executed, only those records which meet the condition will appear to be present in the database. All commands, which access the database, respect the SET FILTER condition. Issuing SET FILTER TO without the optional < expL > turns off the conditional restrictions on the currently selected database. A separate FILTER may be SET for each database file in USE. The filter remains attached to the database file until a new SET FILTER TO command is issued.

7.1.4. - Data indexing

You can attach to each DBF many INDEX files. To attach an IF to a DBF you must simple open the IF when the DBF is active (selected). A database that has attached an index file is displayed and accessed in the order specified by the index expression, as long as order is set to the index. An index file doesn't change the physical order of the records in the DBF.

FoxPro lets you create two types of index files:

SIMPLE ( INDIVIDUAL ) (files with the extension .IDX) the index file contains one index entry


COMPOUND (files with the extension .CDX) the index file contains multiple index entities called tags


A STRUCTURAL COMPOUND IF is a compound IF that always have the same base name as the DBF and is automatically opened with the database file. A COMPACT IF is an index created in the faster access index technology. All IF in FoxPro can be built with such option. Only if you are sharing files between FoxPro and another X-BASE products you must use non-compact .IDX index files.

From all opened IF you can select a MASTER index file (MIF) that controls the current order in which the records of the DBF are displayed or accessed. The other opened IF (an IF attached to a DBF) are used only for updating as changes are made to the DBF (a non-opened IF (an IF non attached to a DBF) is not updated together with the DBF. You may designate the MIF or tag in the .CDX as follows:

- in the INDEX clause of USE

- SET INDEX for .IDX or SET ORDER for .CDX

DISPLAY STATUS gives extensive information about open index files like:

names

types

index expression

name of the master index

An IF can be created with the command:

- INDEX ON <expr> TO <.idx file > | TAG <tag name > [ OF < .cdx file > ]

FOR [ < expL > ]

[ COMPACT ]

[ ASCENDING | DESCENDING ]

[ UNIQUE ]

[ ADDITIVE ]

- expr - the index expression

- .idx file - the name of the single IF

- tag name - the name of a component index in a compound IF

- .cdx file - the name of the compound file in which must be created the tag

- expL - the filter condition for the selected records from DBF to be indexed

- ASCENDING | DESCENDING - the sense of order

- UNIQUE - only the first record encountered with a particular index key value will be included in the IF

- ADDITIVE - previously opened IF remain open

An existing IF can be activated (as MIF) with the command:

- SET INDEX TO [ <.idx file list> | ? ]

ORDER < expn > | < idx file >

TAG <tag name > [ OF < .cdx file > ]

[ ASCENDING | DESCENDING ]

[ ADDITIVE ]

The following commands permits you to perform operations on and return information about index files:

- CDX ( ) - returns the name of open .CDX compound files

- CLOSE INDEX - closes all open IF in the selected work area ( except a structural index file )

- COPY INDEXES - copies single entry IF to a compound IF

- COPY TAG - creates a single entry IF from a tag in a compound IF

- DELETE TAG - removes a tag or tags from a .CDX IF

- INDEX - create an IF to display a DBF in logical order

- KEY ( ) - returns the key index expression of the master ( controlling ) IF

- MDX ( ) - returns the names of open .CDX IF

- NDX ( ) - returns the names of open .IDX IF

- ORDER ( ) - returns the name of the master IF

- REINDEX ( ) - rebuilds an IF

- SET INDEX - selects one or more IF for use with the current DBF

- SET ORDER - specifies the IF that will be used as MASTER in a IF list

- SET UNIQUE - enables or disables the maintenance of duplicate keys in an IF

- SYS ( 14 ) - returns the index expression of an IF

- SYS ( 21 ) - returns the MASTER controlling index in the currently selected DBF

- SYS ( 2021 ) - returns the index filter expression

- TAG ( ) - returns tag names from .CDX compound IF or the name of .IDX IF

7.1.5. - Parameters setting

A set of system running parameters is related to the programming environment current session and may be defined and changed using the TABS in the TOOLS / OPTION window, or the interpretative commands in the COMMAND window. The main parameters settings commands are:

SET CARRY - enables or disables the ability to carry data forward from one record to the next

SET DELETED - enables or disables access to records marked for deletion

SET EXACT - specifies whether an exact match in the length of two strings is necessary during a string comparison

SET CLEAR - enables or disables screen clear

SET CONFIRM - enables or disables the necessity of pressing terminating key to exit a field during editing

SET EXCLUSIVE - specifies if database files will be opened for exclusive or shared use on a network

SET LOCK - enables or disables automatic record or file locking in certain commands

SET MULTI LOCK - enables or disables multiple record locking

SET NEAR - determines where the record pointer will be positioned after an unsuccessfull search for a record ( at end of file, or near the neighbor record )

SET PRINTER - enables or disables output to the printer and routes printer output to a file or to a port

SET HEADING - enables or disables display of column titles for each field in the DISPLAY , LIST , SUM and AVERAGE commands

SET TALK - enables or disables the display of command results to the screen or a window

SET BELL - turns the bell on or off

SET CLOCK - turns the system clock on or off. You can also specify its location on the screen

SET LOGERRORS - saves compilation errors messages to a text file

SET DEVELOPMENT - compares the creation date and time of a program file and its compiled object file

SET ECHO - activates the TRACE window for program debugging

SET ESCAPE - enables or disables trapping of a press of the ESCAPE key during program execution

SET NOTIFY - enables or disables the display of certain system messages

SET STATUS - enables or disables the display of a status bar showing the name of the currently executing , the active database file, the current record pointer position, the number of records in the active database file and the state of the INSERT , NUMLOCK , and CAPSLOCK keys

SET SAFETY - enables or disables file overwrite protection

7.1.6. - Relationships between database files

Between two or more DBF can be established a relationships using the command SET RELATION. Before you establish a relationship, one DBF (the parent DBF) must be opened in the currently selected WA and the other (the child DBF) opened in another WA. Then you can issue SET RELATION to create the relationship.

After the relationship is created, moving the record pointer to the corresponding record in the parent DBF, moves the record pointer to the corresponding record in the child DBF. If a matching record cannot be found in the child DBF, the RP in the CDBF is positioned at the end of the DBF.

Related DBF typically have a common field. To set the relation, the CDBF must be indexed on the common field. The relational expression is usually the index expression of the MASTER controlling index of the CDBF, although it can be a numeric expression.

To remove all relationships in the currently selected WA , issue the command SET RELATION TO.

- SET RELATION TO [ < expr1 > INTO < exprN1 > | < expC1 >

[ < expr2 > INTO < expN2 > | < expC2 >. ] [ADDITIVE]

expr1 - the relational expression

expN1 - the WA number of the CDBF

expC1 - the DBF alias of the CDBF

ADDITIVE - preserves all existing relationship in the currently selected WA

7.1.7. - Building Working Environments

A Working Environment can be built with the VIEW Window. It represents the Data Structure that is used for a set of procedure modules. It contains the following information:

- all opened TABLES (the DBF) from the Data Base

- the FILTERING CONDITIONS attached to each DBF

- the LIST OF ATTRIBUTES SELECTION for each DBF

- the associated INDEX FILES (the CDX and / or IDX files)

- all established RELATIONS between open DBF

- the actually set PARAMETER values

- the DEFAULT and PATH settings

- the PROCEDURE FILE setting

- the current HELP FILE

- the current RESOURCE FILE

All this information builds a VIEW and can be saved in a file with the extension VUE, for later using. This action can be done in two ways:

- In MENU working mode with the option selection:

FILE / SAVE | SAVE AS / < file >

the file type must be selected as VIEW

- In the COMMAND or PROGRAM working mode with the command :

CREATE VIEW < file >

To reuse a defined VIEW you must restore the information from the appropriate VUE file. This action can be done in two ways:

- In MENU working mode with the option selection:

FILE / OPEN / < file >

the file type must be selected as VIEW

- In the COMMAND or PROGRAM working mode with the command:

SET VIEW TO < file > | ?

This command restores the FoxPro environment to the state it was in when the VIEW file was created.

VIEW files are useful in many situations:

- In programs - only one command SET VIEW needs to be executed to establish the entire environment needed to complete a task. This can save lots of typing

- While debugging - the environment settings can be saved in a VIEW file, testing can be performed, and the environment can be restored to continue program execution

- In application generation - a saved environment can be easy attached to many application modules like REPORTS and SCREENS


Document Info


Accesari: 811
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )