Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The application tools provide the user interface to build and run applications.
The database server handles all data management, including the storage and retrieval of
data.
Connectivity software provides the ability to access data in both Informix and nonInformix databases across a broad range of hardware platforms.
Application
Development
Tools
Connectivity
Database
Servers
Informix tools can access non-Informix databases through emerging industry standards,
such as ODBC and DRDA, while allowing third-party tools to access our database servers.
Industry-standard SQL is used to communicate requests for data from the application to
the database server. All products are based on ANSI-standard Structured Query Language
(SQL) and run on a variety of operating systems including UNIX, Windows, Windows NT,
OS/2, and Machintosh.
APPLICATION DEVELOPMENT TOOLS
The application tools allow you to:
? Design and build data entry and query screens
? Create reports
? Build robust applications
Wide choice of tools including:
? INFORMIX-NewEra
? INFORMIX-4GL
? INFORMIX-SQL
? INFORMIX-ESQL
? Third-party tools
INFORMIX
INFORMIX
USER REFERENCE
CONNTECTING WINDOWS 98 CLIENT TO SCO UNIX SERVER:
Boot the Windows 98 machine and no need to Login into NT Network. Now, follow the
step below:
Start ? Run ? Type telnet 192.177.166.20 ? OK
user1
123
Description
To start dbaccess tool
To start INFORMIX-SQL tool
To start INFORMIX-4GL tool
INFORMIX
in the UNIX
Function
Input Mode
Inserts text to left of cursor
Inserts text at beginning of line
Appends text to right of cursor
Appends text at end of line
Opens line below
Opens line above
Replaces single character under cursor with ch
Replaces text from cursor to right
ex Mode
Saves file and remains in editing mode
Saves file and quits editing mode
Quits editing mode when no changes are made to file
Escape to the UNIX shell
Command mode
Deletes a single character under the cursor
Deletes the current line
Moves cursor left one position
Moves cursor right one position
Moves cursor up one position
Moves cursor down one position
INFORMIX
DBACCESS
INTRODUCTION
DBaccess is a tool designed to enable you to access and manipulate the structure of the
database as well as the data within the database. It provides menu-driven access to basic
database functionality. DBaccess supports a query option to allow you to issue SQL commands
against the data in the database tables. It also supports altering tables through a menu-driven
environment. DBaccess supports most actions that can be performed against a database table,
including create, drop, alter, and fragment. DBaccess can also be used to gather information
about a table including the current table size, active constraints, current triggers, indexes, and
existing security privileges.
The specific functions supported depend on the release of the engine you are operating.
The options also vary depending on the type of engine running. The INFORMIX-SE engine and
the OnLine engine have different capabilities and, therefore, different options within the
DBaccess tool.
WHEN IS DBACCESS THE RIGHT TOOL SET ?
DBaccess is the right tool set for many database administrator (DBA) activities, including
database maintenance and table maintenance. By using the menu options, you can easily
perform these tasks. DBaccess automatically formats complicated SQL statements such as alter
table. In general, the purpose of the DBaccess tool is to make the syntax of table and database
maintenance less complicated.
DBaccess also allows you to create tables and databases rapidly. It provides a screen
interface so that you can enter the information for a new table. You also can use DBaccess to
test SQL statements rapidly.
DBaccess is not the appropriate tool if your goal is to create a report output from a query
or a data entry screen. It does not have formatting or screen-painting capabilities.
To start DBACCESS, type dbaccess in the unix command prompt.
MAIN MENU
INFORMIX
Options
Query-language
Connection
Database
Table
Session
Exit
Description
allows you to use SQL query language.
allows you to connect or disconnect from a database
environment.
allows you to select, create, info, drop or close a database.
allows you to create, alter or drop a database table.
allows you to retrieve information about the current DBACCESS session.
allows you to exit from DBACCESS.
QUERY LANGUAGE
The first option on the DBaccess main menu is Query language. You can find this same
Query language tool in the ISQL tools. The following options are on this menu:
Options
New
Run
Modify
Use-editor
Output
Choose
Save
Info
Drop
Exit
Description
allows you to enter a new query by using a rudimentary text
editor (SQL editor).
submits the query currently visible on the screen to the engine
for execution.
allows you to modify the query currently visible on the screen by
using the SQL editor.
allows you to specify a text editor to be used in creating and
editing SQL statements.
allows you to send the results of the query to an output device, a
printer, a file, or pipe.
allows you to choose a command file as the current SQL
statements.
allows you to save the query currently visible on the screen to an
operating system file.
allows you to select a table and display information about that
table.
allows you to delete an operating system file storing a query
previously saved using the Save option.
returns you to the main DBaccess menu.
INFORMIX
CONNECTION
The connection option of the main DBaccess menu is useful in connecting to alternative
database engines or servers. This option allows to connect or disconnect from a database
environment. When you choose Connect, a list of valid connections or servers is displayed.
Simply select the connection you want. You are allowed to enter a user ID and pass- word for
verification purposes. After successful validation of user ID and password, you are connected.
You can then access the databases valid to that connection as if they were on the same machine
and database server as when you initially entered DBaccess. This capability allows DBAs to do
remote database administration.
DATABASE
The Database option of DBaccess is primarily used by DBAs. This option allows to
select, create, info, drop or close a database. The following options are on this menu.
Options
Select
Create
Info
Drop
Close
Exit
Descriptions
allows you to select a database to work with.
allows you to create a new database.
allows you to retrieve information about the database.
allows you to delete a database.
allows you to close the current database.
allows you to return to the DBACCESS menu.
It prevents DBAs from needing to remember the details of the create database command.
It displays rudimentary statistics about a database.
It allows DBAs to view stored procedures.
Creating a database by using DBaccess has two advantages. You don't need to remember
the exact syntax of the create database statement., and the system prompts you for the dbspace.
The ability to view stored procedures is valuable. You can analyze the stored procedure
without having to remember the exact SQL syntax to retrieve the procedure from the database.
INFORMIX
If a copy of the procedure is required, you can use cut and paste or command-line options of
DBaccess to place the stored procedure code in an operating system file.
TABLE
Both DBAs and programmers will find constant use for this option. Whether it is to look
up a table and column name or perform complex database maintenance, this option has
capabilities to perform the needed work. The various options of the Table selection under
Informix are given below:
Options
Create
Alter
Info
Drop
Exit
Descriptions
allows you to create a new table.
allows you to alter the structure of the existing table.
allows you to display information about the tables in the
current database.
allows you to drop a table.
allows you to return to the DBACCESS menu.
The Info option of DBaccess is read-only, and creating a new table using DBaccess
usually doesn't affect others on the system. DBaccess makes the job of creating and altering
tables significantly easier than directly typing standard SQL statements, you must use DBaccess
with the same caution and care required of all system utilities.
SESSION
The Session command displays information about the Informix session you're currently
connected to. This information helps you keep straight what the settings are in the current
environment.
CREATING A TABLE
In your database, you can proceed to create and populate tables. From the main menu,
choose "Table" option.
INFORMIX
This is the place you do all kinds of operation on tables, such as creating a new table,
altering the schema of a table, dropping a table, and checking the information of a table.
?
To create a table:
? Choose "Create" option.
? Enter the name of the table after the prompt "CREATE TABLE >> ".
? Choose "Add" option to add a new column. Enter the column name, and
column type.
About Index, you can choose "No" not to add index for the column. After you
learn the knowledge of index, you can modify it later.
About Nulls, choose "Yes" to allow the column has null values, or "No" to
forbid.
Repeat the above for adding remaining columns.
Press Esc key to go back to parent menu.
? Choose "Modify" option to modify the definitions of existing columns.
? Choose "Drop" option to remove existing columns.
? Choose Exit option and choose Build-new-table to save changes made to
the table.
10
INFORMIX
Operation
Done editing
Delete character
Typeover / Insert
Delete rest of line
Redraw the screen
INFORMIX
11
INFORMIX-SQL
INTRODUCTION
INFORMIX-SQL, commonly known as ISQL, is a set of tools provided by Informix
Software to support developers. ISQL has a long history with Informix. These tools were
provided with Informix software products before the corporation was named Informix. Prior to
the advent of INFORMIX-4GL, they were the only fourth-generation tools available through
Informix.
WHEN IS ISQL THE RIGHT TOOL SET ?
ISQL is a set of tools, and each tool has its unique purpose. In general, ISQL is the right
set of tools when you need a quick prototype or a simple application.
The Report option invokes the ACE report generator. ACE is excellent for generating
quick reports. It supports SQL select statements, including the creation of temporary tables.
Some very complex SQL select logic is supported with ACE. It also contains good report
formatting capabilities with built-in control break logic for totals and subtotals. It does have
some limited logic capabilities, including temporary variables.
The Form option creates Perform screens. Perform is a screen-generation utility. The
entry screens created by Perform can facilitate data validation, enable intelligent cursor
movement, and process multiple table relationships. They are excellent for quick data
maintenance screens for data entry tables such as state abbreviations. They are also effective if
the application requires no major logic supporting the data entry process.
The User-menu option creates quick, hierarchically based menu structures. They are
reasonably flexible and often sufficient for the menuing needs of a system. However, the
presentation of the menus is not customizable.
To start INFORMIX SQL, type isql in the unix command prompt.
INFORMIX-SQL MENU
12
INFORMIX
Options
Form
Report
Query-language
User-menu
Database
Table
Exit
Description
Run, Modify, Create or Drop a form
Run, Modify, Create or Drop a report
Use Informix Structured Query Language
Run or modify a custom-built menu
Select, Create or Drop a database
Create, Alter or Drop a database table
Exit Informix-SQL
Options
Select
Create
Drop
Exit
Description
Select a database to work with
Create a new database
Drop a database
Return to the INFORMIX-SQL main menu
DATABASE
Select
Exit
INFORMIX
TABLE
Options
Create
Alter
Info
Drop
Exit
Description
Create a new table
Alter the structure of an existing table
Retrieve information about the tables in the current database
Drop a table from the database
Return to the INFORMIX-SQL main menu
Options
Add
Modify
Drop
Screen
Exit
i)
ii)
iii)
iv)
v)
Description
Adds columns to the table above the line with the highlight
Modify column definitions
Drop the highlighted column from the table
Displays the next screen of the table
Leaves the CREATE TABLE menu
13
14
vi)
INFORMIX
Description
Permits any combination of letters, numbers and symbols
Displays the NUMBER menu
Permits sequential serial numbers starting with any positive value
Permits dates
Permits dollars and cents
Permits datetime values
Permits interval values
Displays the VARIABLE-LENGTH menu for the variable length columns
INFORMIX
15
The options available in the alter table menu and its functions are same as create table
menu options.
INFORMATION ABOUT TABLE
To retrieve information about the tables in the current database
Table
Info
Select the table (say san1) followed by Enter key
16
INFORMIX
Options
Columns
Indexes
Privileges
Status
Table
Exit
Description
Display column names and data types for a table
Display information about indexes for the columns in a table
Display user access privileges for a table
Display status information for a table
Select a table from the current database
Return to the SQL menu
COLUMNS:
INDEXES:
PRIVILEGES:
INFORMIX
STATUS:
DROP TABLE
To drop a table from the database
Table
Drop
Options
Run
Modify
Generate
New
Compile
Drop
Exit
Description
Use a form to enter data or query a database
Modify a form specification
Generate a default form
Create a new form specification
Compile a form
Drop a form from the database
Return to the INFORMIX-SQL main menu
17
18
INFORMIX
Generate
Choose Table >> Choose the table to be used (say san1) followed by Enter key
Options
Table-selection-complete
Select-more-tables
Exit
Description
Continue creating a default form with the selected tables
Select another table to include in the default form
Returns to the FORM menu
Run
Options
Query
Next
Previous
View
Add
Update
Remove
Table
Screen
Current
Description
Searches the active database table
Shows the next row in the current list
Shows the previous row in the current list
Runs editor commands to display BLOB contents
Adds a row to the active database table
Changes a row in the active database table
Deletes a row from the active database table
Selects the current table
Shows the next page of the form
Displays the current row of the current table
INFORMIX
Master
Detail
Output
Exit
19
20
INFORMIX
Enter output file name say sample.out and press enter key.
INFORMIX
Options
Append
Create
21
Description
Adds new data to an existing output file
Creates a new output file
Options
Current-list
One-page
Options
Unload-format
Screen-format
Description
Writes the current list to the file
Writes the displayed screen to the file
Description
Writes the selected output in ascii format
Writes the selected output in screen format
Select Unload-format option and Exit to exit from the Run menu.
In the UNIX command prompt, type vi sample.out (or) cat sample.out to see the
contents of output file sample.out.
22
INFORMIX
REPORT
The Report menu takes you into a submenu that allows you to generate, edit, compile,
and run ACE reports. The ACE report writer quickly formats simple reports. You can enter a
sequence of SQL statements that generate a final sorted output. This single output thread is used
as the input to the report formatting section of the report. Complex selection logic can be
supported if it can be accommodated using multiple select statements and temporary tables to
generate a final single output stream.
ACE does not support table updating. If the application requires the ability to update
tables, ACE is not the appropriate tool. ACE can do the selection and create an output file that
can be used as input to an update procedure, but updating within an ACE report is not supported.
ACE does not support extensive logic. Although ACE does support if -then - else
constructs, its ability to do extensive logic handling is limited. ACE has a built-in limit of SQL
variables. It also has a tendency to fail on deeply nested if statements.
ACE has a built-in totaling mechanism for control breaks. These control breaks must be
specified in the order by clause of the final SQL statement. Complex totaling can be
cumbersome in ACE. If totaling must be done on fields outside the control breaks, you must use
defined variables. The built-in limit can restrict the flexibility and quantity of such totals.
Options
Run
Modify
Generate
New
Compile
Drop
Exit
Description
Runs a report
Modify a report specification
Generate a default report
Create a new report specification
Compile a report
Drop a report from the database
Return to the INFORMIX-SQL Main menu
Generate
INFORMIX
23
Choose Table >> Choose the table to be used (say san1) followed by Enter key
The report specification was successfully compiled message appears at the bottom row.
This report continues to print on the screen until it is complete. If you have more data
than will appear onscreen, the generated report allows the data to scroll off the screen.
24
INFORMIX
After modification is over, press Esc x (:x) to save and exit from vi editor.
Options
Compile
Save-and-exit
Discard-and-exit
Description
Select Yes to drop the selected report, otherwise No to cancel the drop operation.
INFORMIX
25
USER-MENU
By using the User-menu, you can quickly create a hierarchically based menu system. To
utilize the tool, your menuing design must be entirely based on a master menu/detail menu
relationship. Each entry on the main menu can be one of the following types:
?
?
?
?
?
?
F: Run a form
M: Call another menu
P: Execute another program or operating system command
Q. Execute an ISQL query or other command file
R: Run a report
S: Execute a script menu
The menus are stored in the database. You should have the menu structure designed
before entering the menu items. To begin entering the information, select the lowest level menu
and give it a name. This menu does not call any other subordinate menus.
Press M for Master, and then press A for Add. Type the name of the menu and the title
you want the user to see on the screen. The title can be long and descriptive; the name is limited
in length. The name is used only within by the menuing system to track relationships between
menus. Next, press the Esc key.
You have added your first menu. Next, add the individual items for the menu. It is best
if they already exist or if you at least know the exact names the called programs, reports,
procedures, and so on will have. You can always modify the menus, but planning ahead is best.
To begin entering the menu selections, press D for Detail. The cursor then moves to the bottom
half of the screen on Selection Number. Press A for Add. Then type the selection number and
selection type. Next, enter the selection text as you want it to appear to the user. The final entry
is the exact command string as it should be executed from the operating system.
Continue to enter your menu one item at a time. To test the current Structure at any time,
exit from the entry modification screen and choose Run. Your menu is then displayed on screen.
You can test your work immediately.
The User-menu option is a great tool for creating menus quickly. Its flexibility in calling
any type of operating system program enhances its ability to support any type of application
developed in the UNIX environment.
INFORMIX
26
CREATING A TABLE
To create a simplest table, it is very easy:
Syntax: CREATE TABLE <tableName> (
< list of column definitions including column name and data type >
);
INFORMIX
?
?
?
?
?
27
If you have all the above definitions, the order to write it is DEFAULT clause the first,
then NOT NULL, and other constraints at last.
Example: CREATE TABLE accounts (
acc_num integer PRIMARY KEY,
acc_code integer UNIQUE,
open_date date DEFAULT TODAY
);
You can also specify any of the following table-level constraints:
?
?
?
?
?
UNIQUE(<column name>)
DISTINCT (<column name>)
PRIMARY KEY(<column name>)
FOREIGN KEY(<column names>) REFERENCES <referenced table
names>(<column name>)
CHECK(<condition>) -- check the constraints be met before data be assigned
Example:
You can also use CHECK (<conditions>) to check constraints to designate conditions
that must be met before data can be assigned to a column during an INSERT or UPDATE
statement.
Example:
28
INFORMIX
sex
char CHECK (sex='M' OR sex='F'),
birthday date,
working boolean,
salary
money,
descript text,
CHECK ( (working AND (salary IS NOT NULL)) OR
(NOT working AND salary IS NULL) )
);
GETTING RID OF A TABLE
To remove a table from your database, execute
Syntax:
Example:
CREATING A VIEW
You can use CREATE VIEW statement to create a new view based on existing tables and
views in the database.
Syntax:
Example:
CREATING AN INDEX
An important technique for improving the performance of queries is to create indexes. An
index on an attribute of a relation allows the database to quickly find the data in the relation with
a given value for the indexed attribute.
Syntax:
Example:
It may be useful if the queries involved in the student id such as the following query:
SELECT *
FROM student
WHERE id = 10;
INFORMIX
29
There are five SELECT statement clauses, even though only two clauses--SELECT and
FROM--are required. You must use the clauses in the following order:
?
?
?
?
?
SELECT
FROM
WHERE
ORDER BY
INTO TEMP
30
INFORMIX
You can run a query on a single table of a database to retrieve all or specific columns or
rows and order the data in different ways. If you specify an asterisk (*) in your select statement,
all the columns are returned in their defined order. You can specify which columns you want by
including the list of column names immediately after the SELECT keyword in the statement.
The order in which the columns are selected is the order in which they are returned by default.
eg.
You can eliminate duplicate rows from being returned by using the DISTINCT or
UNIQUE keyword in your SELECT statement.
WHERE Clause of the SELECT statement
It is useful for two specific purposes:
? Specify the criteria for searching specific rows.
? Create join conditions with multiple tables.
You can use many keywords and operators to define your search criteria:
Keywords
Results in
BETWEEN
IN
LIKE
MATCHES
IS NULL
IS NOT NULL
AND / OR / NOT
Range of values
Subset of values
Variable text search
Variable text search
Search for NULL strings
Search for non-NULL Strings
Logical operators used to connect two or more conditions
Relational Operators
=
!= or <>
>
>=
<
<=
Description
Equals
Does not equal
Greater than
Greater than or equal to
Less than
Less than or equal to
Arithmetic Operators
+
*
/
Description
Addition
Subtraction
Multiplication
Division
INFORMIX
31
In addition to using the LIKE and MATCHES keywords, you can use a wildcard for
variable text search strings.
Use
with
MATCHES
*
?
[ ]
\
Description
Evaluates to 0 or,more characters
Evaluates to a single character
Specifies valid values for a single character or a range of values
Specifies a literal for the next character
Description
Counts the number of rows that are a result of
the SELECT statement
Sums the value of a given numeric column
Arithmetic means of a given numeric column
Maximum value of a given column
Minimum value of a given column
Description
Integer that represents the day
Integer that represents the month
Integer that represents the day of the week (values
0 through 6 (Sun-Sat))
Four digit integer that represents the year
Returns the date in mm/dd/yyyy format
Returns a date value
Returns a date/time value that represents the current
date and time
32
INFORMIX
In addition to the aggregate and time functions, you can also use the following functions:
Function
LENGTH
USER
TODAY
SITENAME
HEX
ROUND
TRUNC
Description
Returns the length of a character column
Returns the login account name of the current user
Returns the system data
Returns the server name for the INFORMIX-OnLine
system (defined in the onconfig file where the current
database resides)
Returns the hexadecimal encoding of an expression
Returns the rounded value of an expression
Returns the truncated value of an expression
INFORMIX
33
INSERTING DATA
The SQL INSERT statement allows a user to enter a row or rows of values into a table.
The INSERT statement has two functions: The first is creating one single new row by supplying
the column values and the second is creating a group of new rows with values derived from
another table.
SINGLE ROW INSERTS
Adding a single row is the simplest form of the INSERT statement. The statement
creates one new row in a table from a list of defined column values. You use a VALUES clause
in the statement, and the values to be inserted must have a one-to-one equivalence with the
columns of the table.
The following code shows an example of the syntax:
INSERT INTO tablel
VALUES (123, ABC")
If you do not want to specify every column of the table where you insert a row, you can
list the column names after the table name and then supply the values for the columns you list.
The VALUES clause accepts only constant values. You can use the following values:
?
?
?
?
?
?
When inserting a value into a column, you might find that restrictions were placed on the
column. For example, some columns might not allow null values or duplicate values. Also, a
column restriction can specify the exact values that are allowed to be inserted.
One column in a table can be defined as a SERIAL data type. The database server
generates values for a serial column. When you specify 0 as the value, the database server
generates the next value in the sequence. Serial columns do not allow you to insert NULL
values.
When performing inserts, the database server makes conversions if necessary. For
example. when you insert a number or date into a character column, the server converts the
values to character strings. The database server can also convert between numeric and character
data types.
INFORMIX
34
When inserting multiple rows, you have a risk of including invalid data. so the database
server terminates the statement if it reaches an invalid value.
INSERT STATEMENT WITHIN A PROGRAM
You can embed an INSERT statement in a program just as if you were performing any
simple SQL statement. An additional feature allows you to use host variables in expressions for
both the VALUES and WHERE clauses.
UPDATING DATA
You use the SQL UPDATE statement to change the values of one or more rows of a
table. The two forms of the UPDATE statement are uniform value updates and select value
updates.
To update data in a table, you must be the owner of the table or have the UPDATE
privilege for that table. If you update rows in a database without transactions and the update
fails, your database can be in a state with a half-processed update, and it is not rolled back. If
your database has transactions, you do the update with the ROLLBACK WORK statement,
which automatically rolls back any modifications if the statement fails or does not completely
finish processing.
The UPDATE statement can end in a WHERE clause, which determines what rows are
affected. If you do not include a WHERE clause, then all rows of the table are modified. The
WHERE clause consists of standard search criteria.
UNIFORM VALUE UPDATES
Updating with uniform values happens when you use the SET keyword to add a value for
a column. The value is uniformly added to every row unless you state a WHERE clause to be
more specific on your UPDATE statement:
INFORMIX
35
UPDATE tablel
SET fieldl = ABC
The SET clause identifies each column to be changed and specifies the value that is used
in making the change. You can have any amount of single-column-to-single-expression
functions in an UPDATE statement.
You can use the NULL keyword as a column value with the UPDATE Statement.
SELECTED VALUE UPDATES
Updating with selected values happens when you take a list of columns and set them to a
list of values. This method is basically the same as the first form of updates, but it assigns bulk
values to existing columns:
UPDATE tablel
SET (fieldl, field2, field3) = ('ABC, DEF, GHI)
DELETING DATA
The SQL DELETE statement removes one or more rows from a table. If you use
transaction processing, you cannot recover the deleted rows after the statement is committed.
Also, when you delete a row, the row is locked for the duration of the transaction. If a large
number of rows are deleted, keep in mind that all rows are locked. You can lock the entire table
prior to deleting if you know you are processing a lot of rows.
The advantage of using transaction processing is that, regardless of what happens during
your process, the database is left in the original state if the statement cannot be completely
processed correctly.
If the WHERE clause is not on the statement, all rows are automatically deleted from the
table. If you are using INFORMIX-SQL or Informix DBaccess when you use the DELETE
statement without a WHERE clause, you are asked to confirm that Do you want to delete all
rows in the existing table? Please note that if you use the DELETE clause in a program, you are
not asked for confirmation, and the DELETE processes automatically.
eg.
DELETE FROM tablel
The general Syntax for a DELETE statement is simple, but you must be careful that you
accurately delete the rows that you want. The DELETE keyword identifies the operation you are
to perform. The FROM clause is next followed by the table name. The WHERE clause
identifies the rows to be deleted. The search conditions are the same as those in the SELECT
and UPDATE statements; they can be used to identify many rows, and therefore an accurate
deletion process takes place.
eg.
36
INFORMIX
INFORMIX-4GL
INFORMIX 4-GL AND CLIENT/SERVER ARCHITECTURE
Informix-4GL allows you to both provide a far friendlier mode of interaction, and protect
valuable data from end user errors.
Server
Client
Informix
Server
SQL
4 GL
Because of its role in the client/server architecture, the 4GL code you write is actually a
4GL/SQL hybrid. It contains:
? 4GL logic for screen handling and the user interface
? SQL statements which are sent to the Informix Server to be processed
TYPES OF INFORMIX-4GL
There are actually two kinds of INFORMIX-4GL.
? INFORMIX-4GL Rapid Development System (RDS) and
? INFORMIX-4GL C Compiler Version.
RAPID DEVELOPMENT SYSTEM
RDS compiles the source program into pseudo-code (p-code). The time line for
compiling into p-code is very small. The p-code is later executed through a p-code runner. The
runner takes the statements that you have written in INFORMIX-4GL and translates them at runtime into something the computer can understand. Thus it takes longer time to execute. How
much longer depends on the type of hardware you are using and what the actual INFORMIX4GL code is doing.
Informix 4GL-GX
An important advantage to RDS is ready to access to a graphical presentation of your
RDS application by means of INFORMIX-4GL/GX. Some of the features are as follows:
? 3-D shading enhances the appearance of your 4GL forms
? Text fields and their delimiters are replaced by visually distinct form fields offset by
color or highlighting
? Help text is displayed in a separate window, allowing the user to simultaneously view
and use Help and the RDS application.
INFORMIX
37
Options
Module
Form
Programs
Query-language
Exit
Description
Create, modify, or run individual 4GL program modules
Create or modify 4GL screen forms
Create, compile or run 4GL application programs
Use Informix Structured Query Language
Exit INFORMIX-4GL
38
INFORMIX
Options
Modify
New
Compile
Programcompile
Run
Options
Modify
Generate
New
Compile
Exit
Options
Modify
New
Compile
Planned_Compile
Run
Drop
Exit
Description
Change an existing 4GL Program module
Create a new 4GL Program module
Compile an existing 4GL Program module
Compile an existing 4GL application program
Execute an existing 4GL program module or application
program
Description
Change an existing form specification
Generate & compile a default form specification
Create a new form specification
Compile an existing form specification
Returns to the INFORMIX-4GL menu
Description
Change the compilation definition of a 4GL application
program
Add the compilation definition of a 4GL application program
Compile a 4GL application program
Show the planned compile actions of a 4GL application
program
Execute a 4GL application program
Drop the compilation definition of a 4GL application program
Returns to the INFORMIX-4GL menu
INFORMIX
Options
New
Run
Modify
Use-editor
Output
Choose
Save
Info
Drop
Exit
39
Description
Enter new SQL statements using the SQL editor
Run the current SQL statements
Modify the current SQL statements using the SQL editor
Modify the current SQL statements using a user-specified editor
Run & send query results to a printer, file or a pipe
Choose a command file as the current SQL statements
Save the current SQL statements in a command file
Retrieve information about tables in the current database
Drop an SQL command file
Returns to the INFORMIX-SQL main menu
PROGRAM
MODULE
FUNCTION
FORM
PROGRAM
A logical sequence of operations to be performed by a computer in solving a problem or
in processing data.
MODULE
A module is a computer file with a specific purpose or function consists of INFORMIX4GL instructions. It is one piece of the entire program. Program contains at least one module.
A module contains a collection of one or more functions.
FUNCTION
A routine that performs a specific duty or job which may be required in a program. The
function is the basic unit of INFORMIX-4GL code. It is used to set off a series of INFORMIX4GL statements which should be executed when called upon.
INFORMIX
40
TYPES OF FUNCTIONS:
GLOBALS
The GLOBALS function tells INFORMIX-4GL that the only statement it should find in
this function is a variable declaration statement. Every program is only allowed one GLOBALS
function.
MAIN
The MAIN function gives INFORMIX-4GL a place to start. INFORMIX-4GL will
always read the module with the MAIN function in it first. Every program requires exactly one
MAIN function (otherwise INFORMIX-4GL would not know where to start).
FUNCTION
A FUNCTION is the basic unit for INFORMIX-4GL code. Programmer has to define
what each functions purpose is going to be.
REPORT
The REPORT function tells INFORMIX-4GL that additional report formatting
statements may be encountered. Other functions, MAIN, GLOBALS and FUNCTION, will not
understand these report statement.
FORM
The form is a separate file that is used to specify what the appearance of the visual screen
display will look like during data entry and manipulation. Forms are a separate entity from the
rest of your program. Forms are compiled separately and are used by your program. Forms can
be used to display information from a database as well as to update, delete and insert
information.
Program
Modules
Cust_main.4gl
Cust_add.4gl
Cust_edit.4gl
GLOBALS
4GL CODE
END GLOBALS
FUNCTION add_cust()
4GL code
END FUNCTION
FUNCTION delete_cust()
4GL code
4GL code
END FUNCTION
MAIN
4GL CODE
END MAIN
REPORT cust_list()
4GL code
END REPORT
FUNCTION update_cust()
4GL code
END FUNCTION
INFORMIX
41
SCOPE OF ELEMENTS
The scope of an element deals with where that particular element is known, or can be
used, in an INFORMIX-4GL program. There are three basic types of SCOPE. These can be
broken down like this:
Global
Module
Local
Category
CHAR
NUMERIC
Data types
CHAR
INTEGER
SMALLINT
FLOAT
SMALLFLOAT
DECIMAL
MONEY
SERIAL
MONEY
SERIAL
DATE
DATETIME
DATE
DATETIME
42
INFORMIX
INTERVAL
VARIABLELENGTH
INTERVAL
VARCHAR
BLOB
DEFINE
variable-list
data-type
Example:
DEFINE
fname
Start_date
x, y, z
CHAR(15),
DATE,
INTEGER
Variable Name
? May be a maximum of 18 characters in length
? First eight characters must be unique (this may be system dependent)
? Must begin with a letter, then can contain letters, numbers and underscores (_)
? May be upper or lowercase
INFORMIX
43
DEFINE
Example:
DATABASE stores
DEFINE
fname
start_date
x,y,z
LIKE customer.fname,
LIKE orders.order_date,
LIKE orders.order_num
INITIALIZING VARIABLES
There are two statements that can be used to initialize your variables, LET and
INITIALIZE.
The LET Statement
It is a standard programming statement. It means to take what is on the right side of the
equal sign and assign it to the variable on the left side. In most cases, you will want to assign a
NULL as the initial value for a variable.
The INITIALIZE Statement
The INITIALIZE statement is used specifically for initializing variables and records to
NULL.
Example:
LET X = 5
LET fname
LET lname
INITIALIZE
INITIALIZE
= John
= Smith
lname TO NULL
nr_customer.* TO NULL
44
INFORMIX
Example:
MESSAGE Press the first letter of an option. ATTRIBUTE (REVERSE)
Use the MESSAGE statement to display a character string on the Message line. The
default Message line is line two of the active window. You can change this through the use of
the OPTIONS window.
The message will remain on the screen until another MESSAGE statement is used. This
means the only way to clear a message is to display another message of zero or more characters.
Attributes:
UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM
THE ERROR STATEMENT:
Syntax:
ERROR display_list [ ATTRIBUTE (attribute list) ]
Example:
ERROR No Rows Found
INFORMIX
45
Use the ERROR statement to display a character string on the Error line. The default
Error line is the last line of the screen. You can change this through the use of the OPTIONS
statement. The Error line is always relative to the screen, regardless of the number of windows
you have open. The ERROR statement always displays text in reverse video and sounds the
terminal bell.
An error message remains on the screen until another key is pressed by the user
Attributes:
UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM
THE DISPLAY STATEMENT:
Syntax:
DISPLAY message AT row, column
[ ATTRIBUTE (attribute list) ]
Example:
DISPLAY Row Added. AT 22, 3 ATTRIBUTE (reverse)
Use the DISPLAY statement to display a character string to a specific location on the
screen. With DISPLAY, you specify exactly where you want your message to be displayed by
giving a row and column location. If no row and column location is specified, DISPLAY will
display your message where the cursor is currently pointing.
Attributes:
UNDERLINE
BLINK
REVERSE
NORMAL
INVISIBLE
DIM
BOLD
INFORMIX
46
Attributes:
UNDERLINE
BLINK
INFORMIX
47
You may want to specify the menu name in uppercase so that it is easily
differentiated from the menu commands.
INFORMIX-4GL adds a colon (:) after the menu name and two spaces between each
command option. If the menu exceeds 80 characters, an ellipse ( ) indicates that
additional command options exist.
The menu name (MAIN MENU) will be displayed to the left of the command options
when your menu is displayed.
END MENU is a required syntax when you use the MENU statement
The EXIT MENU statement terminates the menu statement.
48
INFORMIX
INFORMIX
49
If the user presses CONTROL-B, the function dummy will be called. The user has to
know that this command option exists; it does not show up on the menu the way the other
options do.
MULTIPLE MENUS
It is quite common in INFORMIX-4GL to have one menu call another.
eg.
FUNCTION main_menu()
MENU MAIN MENU
COMMAND Customer Go to the CUSTOMER menu
CALL cust_menu()
NEXT OPTION Orders
COMMAND Orders Add a new order
CALL dummy ()
. . .
END MENU
END FUNCTION
FUNCTION cust_menu()
MENU CUSTOMER
COMMAND Query Search for a customer
CALL dummy()
COMMAND Next Go to the Next customer
CALL dummy()
COMMAND Exit Return to the Main menu
EXIT MENU
END MENU
END FUNCTION
50
INFORMIX
PROCEDURAL LOGIC
INFORMIX-4GL procedural logic statements are similar to those found in other
programming languages. They are used to guide the path of a program during its execution.
IF STATEMENT:
Syntax:
IF expression THEN
Statement(s)
END IF
Example:
IF prompt_answer MATCHES [Yy] THEN
ERROR Customer will be deleted
ELSE
ERROR Delete cancelled
END IF
An IF statement is an instruction to execute a statement conditionally. It involves a twoway logical choice. During program execution, when the test expression evaluates to TRUE,
INFORMIX-4GL executes the statements following the keyword THEN and terminating with
the keyword END IF or ELSE. With an ELSE clause, whenever the test expression evaluates to
FALSE (or NULL), INFORMIX-4GL executes the ELSE clause statements. The ELSE clause is
optional.
IF WITHIN OTHER STATEMENTS
Syntax:
IF .... THEN
IF ... THEN
...
END IF
END IF
Example:
IF state = CA THEN
IF zipcode MATCHES 940* THEN
MESSAGE City is Redwood City.
END IF
END IF
IF statements can be nested within other IF statements. A frequent mistake (generic
syntax error) is to forget the END IF keywords or, in the case of nested IF statements, to fail to
match each IF with an END IF.
INFORMIX
51
CASE STATEMENT:
Syntax:
CASE
WHEN { expr / Boolean expr }
....
[ EXIT CASE ]
[ OTHERWISE ]
statement(s)
[ EXIT CASE ]
END CASE
Example:
CASE
WHEN answervar = Y
MESSAGE Answered Yes
WHEN answervar = N
MESSAGE Answered No
OTHERWISE
MESSAGE BAD Answer
END CASE
The CASE statement can be reduced to multiple IF statements. However, it is often more
coherent to express a series of related choices in one statement.
The CASE statement repeats the variable or expression once for each WHEN clause as
illustrated above. This can be eliminated by using the variable or expression in the CASE
statement only once. The WHEN statement then checks the possible values for the given
expression.
The OTHERWISE clause is optional. It is triggered when all the preceding WHEN
clause conditions test FALSE. Statements made in the OTHERWISE clause execute if all the
listed conditions fail.
There is an implied EXIT CASE statement at the end of each sequence of statements
following a WHEN clause. Thus, when conditions are met and statements associated with a
WHEN clause execute, program control passes to the sequence of statements following the END
CASE statement. You do not need an explicit EXIT CASE.
52
INFORMIX
WHILE LOOP
Syntax:
WHILE Boolean expression
Statement(s)
[ EXIT WHILE ]
[ CONTINUE WHILE ]
END WHILE
Example:
WHILE boss_in_office = TRUE
CALL act_busy() RETURNING boss_in_office
END WHILE
CALL sneak_out()
Use a WHILE loop to execute a statement or group of statements for as many times as
the stated Boolean condition tests TRUE.
The optional statement EXIT WHILE moves program control to the first statement
following END WHILE.
The optional statement CONTINUE WHILE interrupts the sequence and causes program
control to return to the top of the sequence and to test the Boolean expression.
If the Boolean expression is FALSE, then the program control skips to the first statement
after the END WHILE.
FOR LOOP:
Syntax:
FOR integer_variable = integer_expression to integer_expression
STEP integer_expression
Statement(s)
[ CONTINUE FOR ] ....
[ EXIT FOR ] ...
END FOR
Use the FOR loop to specify a number of times an iteration should occur. If you use the
keyword STEP with an integer expression, the loop is incremented in steps of the value you
state.
Since integer expression can be a variable, you can set the count dynamically.
INFORMIX
53
FORMS
CREATING A DEFAULT FORM
To create a default form, select Form from the INFORMIX-4GL menu. The Generate
option of the FORM menu will take you through the following steps to create a default form.
CHOOSE DATABASE >>
NEW FORM >>
CHOOSE TABLE >>
Table-selection-complete / select-more-tables
INFORMIX-4GL will then compile the form into a usable state.
MODIFYING A DEFAULT FORM
When you select the Modify option from the FORM menu, you are presented with a list
of forms that can be modified. Highlight the form you want to work with and press RETURN.
Save-and-exit
Saves the changes you have made, but will not compile the form.
Discard-and-exit -
Discards any changes you have made during your editing session.
eg.
The OPEN FORM statement is used to associate an INFORMIX-4GL form name with a
previously compiled form.
54
INFORMIX
Form-name is the name you want to assign to the form for use in your program. It is an
identifier for the form. It is quite common to have form-name and form-file be the same name,
but it is not required.
Form-file is the name of the previously compiled form that was created from the FORM
menu.
DISPLAY FORM STATEMENT
Syntax:
eg.
The DISPLAY FORM statement is used to display a form on the screen. Before a form
can be displayed, it must first be opened using the OPEN FORM statement.
CLOSE FORM STATEMENT
Syntax:
eg.
The CLOSE FORM statement is used to release the memory associated with a form. It
does not clear the form from the screen.
Sample Program:
MAIN
CALL prog_init()
CALL main_menu()
CALL prog_wrapup()
CLEAR SCREEN
END MAIN
FUNCTION prog_init()
OPEN FORM custform FROM custform
END FUNCTION
INFORMIX
FUNCTION main_menu()
MENU MAIN MENU
COMMAND Customer Go to the CUSTOMER menu
CALL cust_menu()
NEXT OPTION Orders
COMMAND Orders Add a new order
CALL dummy()
COMMAND Exit Return to the operating system
EXIT MENU
END MENU
END FUNCTION
FUNCTION cust_menu()
DISPLAY FORM custform
MENU CUSTOMER
COMMAND Query Search for a customer
CALL dummy()
COMMAND Next Go to the next customer
CALL dummy()
COMMAND Exit Exit to MAIN MENU
EXIT MENU
END MENU
CLEAR SCREEN
END FUNCTION
FUNCTION dummy()
ERROR Function not yet implemented
END FUNCTION
FUNCTION prog_wrapup()
CLOSE FORM custform
END FUNCTION
55
INFORMIX
56
Since there are two basic steps, keywords that handle this transfer of information: the
INPUT statement and the INSERT statement.
The INPUT statement is used to retrieve information from the user via the screen, and
transfer it to the program variables. The INPUT statement:
?
?
?
?
?
?
Before using the INPUT statement, you must have satisfied a few requirements:
? There must be a form open and displayed
? There must be a program variable assigned to each field in which you are going to
allow data entry
INPUT PROGRAM VARIABLE
Syntax:
Example:
INPUT
gr_customer.fname,
gr_customer.lname,
gr_customer.company,
gr_customer.address1,
gr_customer.address2,
gr_customer.city,
gr_customer.state,
gr_customer.zipcode,
gr_customer.phone
INFORMIX
FROM
57
fname,
lname,
company,
address1,
address2,
city,
state,
zipcode,
phone
The program variables listed have been defined in an INFORMIX-4GL module, and field
list comes from the ATTRIBUTES section of a form specification file. For every program
variable listed in the INPUT statement, there must be a corresponding field in the FORM, and
they must be in the same sequence. The cursor will move in field-list order.
The INPUT statement takes the information from the form and puts it into a
corresponding program variable as the user goes from field to field.
EXITING FROM THE INPUT STATEMENT
The Default Condition
The ACCEPT Key
The INTERRUPT Key
Pressing the RETURN key after entering data in the last field of
the form automatically causes the program to continue.
If the user presses the ACCEPT key (ESC by default), the
program will continue to the next line of code.
When the INTERRUPT key is pressed, the program proceeds to
the statement immediately following the END INPUT
statement. Any clauses within the INPUT statement will be
skipped. This effectively aborts the INPUT statement.
Example:
58
INFORMIX
Example:
Program variables:
THRU
program-variable
gr_customer.phone
DATABASE stores
GLOBALS
DEFINE gr_customer
RECORD LIKE customer.*
END GLOBALS
This method of using INPUT allows you to enter specific fields while still using the BY
NAME syntax.
INPUT STATEMENT CLAUSES
ATTRIBUTE (attribute-list)
HELP help-number
BEFORE INPUT
AFTER INPUT
ON KEY (key-list)
INFORMIX
59
INSERT STATEMENT
Syntax:
Example:
i)
ii)
The INSERT statement is used to place the values stored in program variables into the
columns of a database table. If the column list is omitted, it is implied that one value will be
supplied for every column in the specified table. If a column list is specified but not all columns
in the table are listed, then a NULL value will be inserted into the omitted columns.
Note: If a table contains a column of SERIAL data type, the program variables for that column
must be set to zero for the proper number to be assigned.
Example:
GLOBALS
cust_globs.4gl
FUNCTION input_cust()
INPUT BY NAME gr_customer.*
LET gr_customer.customer_num = 0
INSERT INTO customer
VALUES (gr_customer.*)
END FUNCTION
AN OVERVIEW OF CURSORS
CURSOR
You can think of a cursor as a marker that points to a row retrieved by a SELECT
statement. In its simplest form, a cursor is a pointer. It points to a row, called the current row; in
a set of rows, called the active set.
A cursor must be declared to retrieve rows that satisfy the criteria of a multi-row
SELECT statement. Selecting multiple rows without a cursor results in a run-time error. The
scope of cursors is Module
INFORMIX
60
TYPES OF CURSORS
There are three types of cursors available in INFORMIX-4GL. Each cursor has its own
unique set of characteristics. The three cursors are:
?
?
?
SCROLL cursors
Non-scrolling cursors
FOR UPDATE cursors
SCROLL CURSOR
The SCROLL cursor can be used to access a set of rows. A SCROLL cursor points at
one row at a time.
Using a SCROLL cursor, you can move through a set of rows in either a backward or
forward direction. It does this by creating a temporary table consisting of a snapshot of the
appropriate rows. Once this snapshot is created, it will not include any changes to the rows by
other users as long as you are looking at them.
NON-SCROLLING CURSOR
A Non-scrolling cursor will only go down (next) in the list of active rows. This type of
cursor is used when you do not need to move back and forth within the active set. A nonscrolling cursor is most commonly associated with a report.
FOR UPDATE CURSOR
A FOR UPDATE cursor (also called a locking cursor) is similar to a non-scrolling cursor
in that it can only retrieve the rows in a forward direction. However, a FOR UPDATE cursor
will place a lock on the row that the cursor is pointing to and hold that lock until the next row
becomes the current row.
A FOR UPDATE cursor is used for UPDATE or DELETE statements. You do not want
other users deleting or changing the row you are using. It can be used in conjunction with the
other types of cursors. For example, you might use a SCROLL cursor to browse the rows, and
when you find the row that you want to change, use a FOR UPDATE cursor to lock the row
during your change.
INFORMIX
61
SCROLL CURSOR
CURSOR STATEMENTS
DECLARE
OPEN
FETCH
CLOSE
FREE
Example:
The DECLARE statement is used to associate a cursor name with a SELECT statement.
The keyword SCROLL is used so that you can move the cursor in any direction.
The WITH HOLD is optional syntax to prevent the cursor from being closed when a
transaction completes. Unless you include the WITH HOLD keywords, INFORMIX-4GL closes
the cursor when the transaction is terminated with either a ROLLBACK or COMMIT WORK
statement. You must explicitly CLOSE a cursor WITH HOLD.
THE OPEN STATEMENT
Syntax:
OPEN cursor-name
Example:
?
?
?
Example:
62
INFORMIX
The FETCH statement retrieves a row and puts its values into the program variables
specified in the INTO clause.
A SCROLL cursor uses a temporary table when fetching rows from the database. This
allows a user to fetch in both a forward and backward direction when using a SCROLL cursor.
The SCROLL cursor gives you the ability to move around in the active set of the cursor.
Using one of the keywords with the FETCH statement will move you to the appropriate location
in the active set.
FIRST
PRIOR / PREVIOUS
NEXT
LAST
CURRENT
FETCH FIRST moves the cursor to the top of the active set. The
FIRST row is determined by your SELECT statement (ORDER BY
clause)
FETCH PRIOR or PREVIOUS will move the cursor from the
current row to the row just before the current row. The keywords
PRIOR and PREVIOUS are interchangeable
FETCH NEXT moves the cursor from the current row, down one, to
the next row in the active set
FETCH LAST moves the cursor to the bottom row in the active set
FETCH CURRENT indicates the current row of the active set
FETCH RELATIVE
You can use negative numbers with a FETCH RELATIVE but not with a FETCH
ABSOLUTE.
THE CLOSE STATEMENT
The CLOSE statement deactivates the active set. After you CLOSE a SELECT cursor,
you cannot execute a FETCH statement until you reopen the cursor. The CLOSE statement must
be physically located after the DECLARE, OPEN and FETCH statements.
Syntax:
CLOSE cursor-name
INFORMIX
II.
III.
Column Name
Data type
stock_num
manu_code
description
unit_price
unit
unit_descr
smallint
character
character
money
character
character
Size
3
15
4
15
Data type
Size
manu_code
manu_name
character
character
3
15
File: stock.per
DATABASE stores
SCREEN SIZE 24 by 80
{
================ STOCK MAIN ENTRY SCREEN ================
Stock #
[f000 ]
MF Code
[a0
]
Description
[f001
]
Unit Price
[f002
]
Unit Type
[f003 ]
Unit Description
[f004
]
===========================================================
}
END
TABLES
stock
63
64
INFORMIX
ATTRIBUTES
f000 = stock.stock_num, REQUIRED;
a0 = stock.manu_code, REQUIRED, UPSHIFT;
f001 = stock.description, DOWNSHIFT;
f002 = stock.unit_price;
f003 = stock.unit;
f004 = stock.unit_descr;
END
IV.
1.
2.
3.
4.
5.
6.
7.
8.
9.
V.
File: stock_glob.4gl
stock_glob.4gl
DATABASE stores
GLOBALS
DEFINE gr_stock RECORD LIKE stock.*
DEFINE nr_stock RECORD LIKE stock.*
END GLOBALS
File: stock_main.4gl
1. stock_main.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. MAIN
7.
8.
CALL set_options( )
9.
CALL main_init( )
10.
CALL main_menu( )
11.
CLEAR SCREEN
12.
13. END MAIN
INFORMIX
65
66
VI.
INFORMIX
File: stock_one.4gl
1. stock_one.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. FUNCTION one_menu( )
7.
8.
CLEAR SCREEN
9.
OPEN WINDOW w_stock AT 2,2 WITH 15 ROWS, 70 COLUMNS
10.
ATTRIBUTE(BORDER)
11. DISPLAY FORM f_stock
12.
13. LET gr_stock.* = nr_stock.*
14.
15. MENU STOCK ONE
16.
17.
BEFORE MENU
18.
HIDE OPTION ALL
19.
SHOW OPTION Query, Add, Exit
20.
21.
COMMAND Query Query for a row in the stock table.
22.
MESSAGE
23.
24.
IF query_stock( ) THEN
25.
SHOW OPTION Next, Previous, Update, Delete
26.
ELSE
27.
HIDE OPTION ALL
28.
SHOW OPTION Query, Add, Exit
29.
END IF
30.
31.
COMMAND Next Find the NEXT stock item from the list.
32.
CALL fetch_rel_stock(1)
33.
34.
COMMAND Previous Find the PREVIOUS stock item from the list.
35.
CALL fetch_rel_stock(-1)
36.
37.
COMMAND Update Change an existing stock item.
38.
CALL dummy( )
INFORMIX
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.
67
68
VII.
INFORMIX
File: stock_brws.4gl
1. stock_brws.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. FUNCTION query_stock( )
7.
8.
DEFINE fetch_ok SMALLINT
9.
10. DECLARE stock_ptr SCROLL CURSOR FOR
11.
SELECT * FROM stock
12. OPEN stock_ptr
13.
14. CALL fetch_stock(1) RETURNING fetch_ok
15.
16. IF fetch_ok THEN
17.
CALL display_stock( )
18. ELSE
19.
ERROR No rows found.
20.
CLOSE stock_ptr
21.
FREE stock_ptr
22.
END IF
23.
24.
RETURN fetch_ok
25.
26. END FUNCTION
27.
28. FUNCTION fetch_stock (fetch_flag)
29.
30.
DEFINE fetch_flag SMALLINT, fetch_ok SMALLINT
31.
LET fetch_ok = TRUE
32.
FETCH RELATIVE fetch_flag stock_ptr INTO gr_stock.*
33.
34.
IF SQLCA.SQLCODE = NOTFOUND THEN
35.
LET fetch_ok = FALSE
36.
END IF
37.
38.
RETURN fetch_ok
39.
40. END FUNCTION
41.
INFORMIX
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.
FUNCTION fetch_rel_stock(fetch_flag)
DEFINE fetch_flag SMALLINT, fetch_ok SMALLINT
CALL fetch_stock(fetch_flag) RETURNING fetch_ok
IF fetch_ok THEN
CALL display_stock( )
ELSE
IF fetch_flag = 1 THEN
ERROR You are at the end of the list.
ELSE
ERROR You are at the beginning of the list.
END IF
END IF
END FUNCTION
FUNCTION display_stock( )
DISPLAY BY NAME gr_stock.*
END FUNCTION
FUNCTION clean_up( )
CLOSE stock_ptr
FREE stock_ptr
END FUNCTION
***********
69