| Previous | Contents | Index |
The FIELD option allows for record retrieval using a key field in a structure. SETUP's "SHOW FIELDS" menu option (see Chapter 16, Database Setup) displays the field names. The FIELD option is currently used only with the KEY or PARTIAL KEY option. The KEY option specifies the key to look for. The key is contained in str_expr.
The above example shows how to look in the CLIENT structure for an ID.
_EXTRACTED contains the number of records extracted. If the operation fails, _EXTRACTED will be 0 and an error message will be displayed.
15.9.3 SET STRUCTURE, FIELD: PARTIAL KEY
SET STRUCTURE struc_name, FIELD field_expr: PARTIAL KEY str_expr
|
| Example 15-46 SET STRUCTURE, FIELD: PARTIAL KEY |
|---|
open structure cl: name 'sheerpower:samples\client' input 'Name': name$ set structure cl, field last: partial key name$ print cl(id); ' '; cl(last) end Name? D 80561 Derringer |
This statement retrieves the first record matching the partial key in str_expr.
SET STRUCTURE struc_name: ID str_expr
|
| Example 15-47 SET STRUCTURE: ID |
|---|
declare structure str
open structure cl: name 'sheerpower:samples\client'
ask structure cl: id cl_id$
set structure str: id cl_id$
extract structure str
end extract
for each str
print str(#1); ' '; str(#2)
next str
end
20000 Smith
20001 Jones
20002 Kent
23422 Johnson
32001 Waters
43223 Errant
80542 Brock
80543 Cass
80544 Porter
80561 Derringer
80573 Farmer
|
SET STRUCTURE: ID sets a structure to a structure ID that has been stored previously into a string variable with the ASK STRUCTURE: ID statement. Once the SET STRUCTURE: ID statement has been used, the structure with the new structure name (STR in the example) can be accessed. By using these statements, generalized routines can be written when the structure that will be accessed until runtime is not known.
SET STRUCTURE struc_name: POINTER num_expr
|
| Example 15-48 SET STRUCTURE: POINTER |
|---|
open structure cl: name 'sheerpower:samples\client' extract structure cl end extract set structure cl: pointer 3 print cl(id); ' ' ; cl(last) end 23422 Johnson |
This statement sets the structure to the nth record extracted. The statement is useful after an extract has been done because it provides random access to any record extracted. There is no error message if there are no records extracted, or if the number given is out of range. If the number is valid, _EXTRACTED is set to 1; otherwise, it is set to 0.
15.9.6 SET STRUCTURE: EXTRACTED 0
SET STRUCTURE struc_name: EXTRACTED 0
|
| Example 15-49 SET STRUCTURE: EXTRACTED 0 |
|---|
open structure vend: name 'sheerpower:samples\vendor' set structure vend: extracted 0 end |
Setting the number of records extracted to zero causes a new collection to be started. The SET STRUCTURE struc_name : EXTRACTED 0 statement is used in conjunction with the EXTRACT STRUCTURE struc_name: APPEND statement.
Below is an example of opening an existing structure, extracting a record from it and updating the information in the record.
| Example 15-50 Updating a Structure |
|---|
// Simple customer query
open structure cust: name 'sheerpower:\samples\customer', access outin
do
line input 'Customer number', default '12513': cust$
if _exit or _back or cust$ = '' then exit do // get out if nothing to do
set structure cust, field custnbr: key cust$ // do the search
if _extracted = 0 then
message error: 'Cannot find '; cust$
repeat do
end if
print cust(custnbr), cust(name)
line input 'New name', default cust(name): newname$
if _exit or _back then repeat do
if newname$ = cust(name) then repeat do // nothing to do
cust(name) = newname$ // update the name
print 'Name changed to: '; cust(name)
loop
end
|
SheerPower works with data in any database engine. SETUP tells SheerPower where data files are located and what database engines are used. Structures and definitions are the description of the data layout and it’s characteristics. Once structures have been defined with SETUP, SheerPower's structure statements can be used to manipulate the data.
SETUP supports the following database engines:
ARSSee Chapter 17, SheerPower and ODBC for instruction on using ODBC with SheerPower.
ODBC
FASTFILE
| Example 16-1 Entering SETUP |
|---|
|
|
The OPEN STRUCTURE dialog box will open. If this is an existing structure, select the folder where it is stored, then select the file name.
If you are creating a new structure, choose the folder where it is to be stored and type in the file name.
Click on [Open] to open the structure.
| Example 16-2 Open Structure |
|---|
|
|
Once the structure has been opened, the STRUCTURE DEFINITION window will be displayed.
| Example 16-3 Structure Definition Window |
|---|
|
|
This section describes the SETUP structure definition fields and options for answering them. Data fields inside the structure can be defined or modified. Field definitions can also be displayed in multiple formats.
Default answers are provided for many of the structure definition fields. You may either accept the default answer, or type in different information.
The NAME of the structure will default to be the same name as the file that you opened or created. The default extension for the file is .STR. The structure file contains:
The structure name can be any Windows file specification.
Clicking on the [...]button to the left of the structure NAME field will reopen the Open Structure dialog box. This allows you to choose a different structure name.
Click on the down arrow beside the DATABASE field to select the DATABASE ENGINE used by this structure.
| Example 16-4 Selecting Database Engine |
|---|
|
|
If this is a new structure, the default database engine will be ARS.
When modifying an existing data structure, the default will be the database engine specified in the structure file when it was originally setup.
Inside the DATA SET field, type in the name of the DATA SET that will be used with this structure. If this is a new structure, the default data set name will be the same as the structure name. The default extension is .ARS.
| Example 16-5 Data Set |
|---|
|
|
The same data set can be used for a number of structures. For instance, you might use the CUSTOMER data set for both a CUSTOMER and a SALES structure:
structure files data set
CUSTOMER.STR |
\ |
\ v
\
CUSTOMER.ARS
/
/
/
SALES.STR
|
This can be useful when there are multiple uses for a set of data, but the access and definitions required should be different for each structure.
The data set name can be any Windows file specification.
| Previous | Next | Contents | Index |