![]() |
![]() |
![]() |
![]() |
2 Using the Database Kit Macro Interfaces
This chapter documents the user interfaces for the Connect, Query, and Manipulate macros, the secondary windows associated with these macros, and the Tools interface.
These macros allow you to connect to your database, ask for information from, and send information to your database. These macros contain and use the modules discussed in the previous chapter.
- Using the Connect Interface
- Using the Query Interface
- Using the Manipulate Interface
- Using the Secondary Windows
- Using the Tools Interface
The Connect macro connects the user to or disconnects the user from a specified database. It provides a user interface to the DBconnect module (see the on-line reference page for DBconnect), which performs the connect or disconnect.
This section contains the basic information required for connecting to a database. For a detailed description, see Connecting and Disconnecting on page 1-12.
A connect establishes a connection between the user and the database and initiates a session with the database. A disconnect terminates the session and breaks the connection. Both connect and disconnect are performed by the server that manages the database. The option selected from the Connection menu determines whether the server performs a connect or a disconnect.
When connecting, the user must supply, at minimum, the following:
- A server type. The server type indicates the type of database to which the user will connect; for example, ORACLE.
- Either a connect string or the elements from which to construct a connect string. Connect constructs a connect string only if the user does not supply one.
- The Connect choice on the Connection menu. This corresponds to a value of 0 for DBconnect's connect_disconnect parameter.
A user name is always required for a connect string. Depending on the database type, as indicated by the server type, one or more of the following may also be required:
Which elements are required and how they are assembled into a connect string are specific to the database type.
Typically, you should see your database information to obtain the correct connect string. For more information, see Connect Strings on page 1-14 or refer to your database documentation.
When disconnecting, the user needs to supply only the Disconnect choice on the Connect macro's Connection menu, to indicate that a disconnect is desired. (This corresponds to the value 1 for DBconnect's connect_disconnect parameter.)
The Connect interface appears whenever you instance a Connect macro in an application or start an application that contains a Connect macro:
This interface contains the following components:
- a menu bar whose menus provide a number of connection commands or choices
- input fields into which you enter connection information
- output fields into which AVS/Express returns information about the connect or disconnect.
The menubar, located at the top of the Connect interface, contains a set of pull-down menus that provide commands or options specific to the Connect macro:
The Connect menus provide the following groups of commands or options:
- File: load connection settings from a file or save them to a file
- Server Type: specify a server type
- Connection: specify whether to connect or disconnect
You use these pull-down menus in the same way that you use the pull-down menus found in many other software products.
The File menu provides the commands that load or save the current connection settings. The following commands are available:
- Load New Settings: opens a file window in which you select a file that contains connection settings that are to be used for the current connect. The settings are inserted into the appropriate fields. You should select a file that you created with the Save New Settings command.
- Save New Settings: opens a file window in which you specify a file in which to save the current connection settings. Each line in the resulting file contains a string that represents the name of a field in the Connect interface and the value of the field; for example:
The Server Type menu provides a list of the possible server types; for example, ORACLE. Selecting a server type inserts it into the Server Type field (see Input Fields on page 2-5). The default is the current value in the Server Type field.
This field maps to DBconnect.database_driver.
A specification of whether to connect or disconnect. The allowed values are Connect (which corresponds to 0) and Disconnect (which corresponds to 1). The default is Connect.
This field maps to DBconnect.connect_disconnect.
The Connect interface contains a number of input fields into which you enter connect values. If you plan to use a connect string, you should use the Connect String input field; otherwise, you must supply the elements from which to construct a connect string in the other fields.
The server type, which indicates the type of database to which to connect; for example, ORACLE. The default is the value of the environment variable XP_DB_DRIVER, if it is set, otherwise there is no default.
This field maps to DBconnect.database_driver.
The host name of the machine on which the server that manages the database resides. The default is the value of the environment variable XP_SERVER_HOST, if it is set. If it is not set then it is the default host for the specified database driver.
This value is required only if the user does not supply a value for Connect String and the specified server type requires a host name in the connect string. If a value is specified for Connect String, this field is ignored.
This field maps to DBconnect.server_host.
The name of the server that manages the database. The default is the value of the environment variable XP_SERVER_NAME, if it is set, otherwise it is the default server for the specified database driver.
This value is required only if the user does not supply a value for Connect String and the specified server type requires a server name in the connect string. If a value is specified for Connect String, this field is ignored.
This field maps to DBconnect.server_name.
The database to which to connect. The default is the value of the environment variable XP_DATABASE_NAME, if it is set, otherwise it is the default database for the specified database driver.
This value is required only if the user does not supply a value for Connect String and the specified server type requires a database name in the connect string. If a value is specified for Connect String, this field is ignored.
This field maps to DBconnect.database_name.
The connect string that the database server will use when connecting the user to the specified database. The default is the value of the environment variable XP_CONNECT_STRING, if it is set, otherwise there is no default.
The format of a connect string is specific to the type of database (as specified with Server Type).
If a value for Connect String is not supplied, the user must supply the elements from which to construct a connect string. The values required for constructing a connect string are also database specific.
For a discussion of connect string format and the values required for constructing a connect string, see either Connect Strings on page 1-14 or your database documentation.
This field maps to DBconnect.connect_string.
The user's ID on the host system. The default is the value of the environment variable XP_USER_ID, if it is set, otherwise there is no default.
This value is required only if the user does not supply a value for Connect String. If a value is specified for Connect String, this field is ignored.
This field maps to DBconnect.user_id.
The user's password on the host system. The default is the value of the environment variable XP_USER_PASSWORD, if it is set, otherwise there is no default.
This value is required only if the user does not supply a value for Connect String and the specified server type requires a user password in the connect string. If a value is specified for Connect String, this field is ignored.
This field maps to DBconnect.user_password.
The Connect interface contains a number of output fields into which connection information is returned.
An message that describes the status of the connect or disconnect. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to DBconnect.message.
The status code associated with the message returned in the message parameter. A value of 0 indicates success; a nonzero value indicates failure. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to DBconnect.return_code.
The Query interface queries a database, that is, it selects data from a table or view in the current database based on user specifications in a SQL SELECT statement and returns the data as an array of columns, one for each column specified by the SELECT statement. It provides a user interface to the DBquery module that performs the query and some additional modules that perform support tasks.
Note: You must be connected to a database before querying it; see Connecting to a Database on page 2-2. If you are not connected to a database and you try to query a database, the query is not processed and the "Not connected" message remains in the Message field.
You use the Query macro to query a database as follows:
2. Specify values for the parameters that control query processing (optional- you can use the defaults).
During this process, you can view various types of additional information as necessary.
Note: Query requires a SELECT statement. If you attempt to process an invalid statement, the message "DBerror: Invalid statement" is returned to the Message field and an error window containing additional information opens. For details on constructing SQL statements, see Constructing SQL Statements on page 1-10.
The next section briefly describes how the Database Kit stores and processes output query. Subsequent sections explain the query process and some related topics.
Before querying a database via the Query interface, it is useful to understand how the Database Kit stores and processes data.
The Database Kit stores the data returned by a query in columns. The columns of data are made available to the application in an array of type DBcolumn. DBcolumn is a Database Kit group that consists of the following:
- an array containing a column of returned data
- an integer value that indicates whether null data values are present
- the value that is used to represent a null data value
- the name of the column
Although the Database Kit stores data as columns, it is frequently spoken of as occurring in rows, where a row consists of the same-indexed entries in a set of column arrays. For example, the third row of a set of data stored as a set of column arrays would consist of the following:
Keep this definition of "row" in mind when using this manual.
For a more on this same topic, see Querying a Database on page 1-16.
The Query interface provides a number of parameters that you can set to control how your SELECT statement is processed. Before you can set these parameters effectively, you must understand how a query operates.
A query is executed as a select operation followed by one or more fetch operations. The select operation involves sending the SELECT statement to the database server, which returns the data. The fetch operation moves the data into an array of columns, where it is accessible to an application.
A fetch operation is executed as follows:
1. DBquery fetches rows of data into the fetch buffers until either it reaches the number of rows specified by the rows per fetch parameter (described later in this section) or it has returned all the rows.
IMPORTANT: Some database servers stop fetching rows prior to reaching the limit if they encounter a row with an error, but resume fetching rows during the next fetch operation. See your database documentation for a description of how your database handles fetch operations.
2. The contents of the fetch buffers are copied into a set of user buffers that are available to the application. There is one user buffer per column returned.
If there are more rows to be returned and auto-fetch mode is on (see The Auto Fetch Parameter on page 2-33), Query repeats the fetch operation until either it reaches the number of rows specified by the User buf row limit parameter (described later in this section) or it has returned all the rows. When the user buffers are full, DBquery either flushes the buffers and begins a new fetch operation or ends the query, as determined by the status of the Flush when full parameter (described later in this section).
The data in the user buffers is returned to the application as an array of columns.
By design, Query does not execute a fetch operation as soon as an SQL SELECT statement has been entered. This ensures that you have time to set query-processing parameter values before the query begins. When you finish entering your SELECT statement and setting query-processing parameters, you must process the query; that is, trigger its execution.
Two related operations also affect the state of a query's execution:
- If allowed by your database, you can cancel the currently executing query. See your database documentation to determine if your database allows you to cancel queries.
The cancellation operation attempts to cancel any select or fetch operation currently running on the server and prohibits further fetches for the current query. (Additional fetches occur when there is more data to be fetched and auto-fetch is on.) In addition, it releases all memory allocated for the query by the Database Kit or the database software.
- If the current query is not executing in auto-fetch mode, you can reset it; that is, restart it from the beginning.
You process, cancel, or reset queries using either commands on the Statement menu or the Process, Cancel, or Reset options; see The Statement Menu on page 2-13 or Tools on page 2-15, respectively.
You can view your query output in either of two ways:
- The Query interface provides an Output window in which you can view the columns of data returned by your query. The description of the user interface, later in this chapter, explains how to open the Output window.
- Depending on how your application is set up, you may be able to use your query output as input to an AVS/Express viewer module such as Viewer3D. The Query macro provides five ports called Graph1 through Graph5. If one of these output ports is connected to a viewer module, selecting the corresponding Graph tool on the toolbar, as described later in this chapter, opens the viewer and enters your query output as input.
The Query interface appears whenever you instance a Query macro in an application or start an application that contains a Query macro:
This interface contains the following components:
- a statement window and a related Clear button
- a menu bar whose menus provide a number of query commands or choices
- two toolbars that contain a number of query tools
- output fields into which information about the query is returned
A number of the Query commands and tools open additional windows. These windows, called secondary windows in this manual, provide access to query-processing parameters, display query output and other information, and, in certain circumstances, provide special error information.
The remainder of this section describes the interface components and provides a quick reference to their use. The secondary windows are described in Using the Secondary Windows on page 2-30.
The statement window, located in the middle of the Query interface, is where you construct a SQL SELECT statement. The following figure illustrates the statement window with the construction of a SELECT statement in process:
You can enter text into the statement window in three ways:
- Type in the information as you would into any window.
- Open a Table List, View List, Column List, or User-defined List window and select items from the window (see The List Modes Menu on page 2-15).
- Load the contents of a file containing a complete or partial SQL statement (see The File Menu on page 2-13).
When you finish entering a statement, you initiate its execution with one of the following:
- the Statement->Process command (see The Statement Menu on page 2-13)
- the Process icon (see Tools on page 2-15)
Be sure that you have entered the complete statement and, optionally, set any query-processing parameters before processing the select statement.
Note: If you attempt to process an invalid SQL statement, the Query interface will display an Error window containing information that marks the location of the error. For more information, see The Error Window on page 2-42.
To clear the current statement from the window and buffer and start again, press the Clear button just above the upper left corner of the statement window.
The menubar, located at the top of the Query interface, contains a set of pull-down menus that provide commands specific to the Query macro:
The File menu provides commands for loading or saving SELECT statements. The following commands are available:
- Save Statement: saves the current SELECT statement in the statement window to the specified file
- Load Statement: inserts the contents of the specified file into the statement window
Each command provides a file selection window in which you make your selection.
The statement being saved or loaded does not need to be a complete SELECT statement. It can be a partial statement that you want to use in constructing a complete statement.
The Save Statement command uses the DBsave module. The Load Statement command uses the DBload module.
The Statement menu provides commands that allow you to start or stop the query specified by the current SELECT statement. The following commands are available:
- Process: starts the current query.
- Cancel: cancels the currently executing query, if your database allows you to cancel queries. See your database documentation to determine if your database allows you to cancel queries.
- Reset: restarts the currently executing query from the beginning. You can reset (restart) a query only if the query is not executing in auto-fetch mode.
You can also use the Process, Cancel, or Reset icons on the toolbar. (see Tools on page 2-15).
The Process command maps to DBquery.process_statement. The Cancel statement maps to DBcancel. The Reset statement maps to DBquery.new_statement.
The Parameters menu contains commands that allow you to view and change the values of query-processing parameters. The following commands are available:
- Control: opens the Query Control window, which allows you to view and set the values of the following types of query-processing parameters:
For details and an illustration, see The Query Control Window on page 2-30.
- Output Types: opens the Query Output Types window, which allows you to specify how numerical values are returned from a query
For details and an illustration, see The Query Output Types Window on page 2-34.
You can also open these windows with the Query Control and Query Output Types tools (see Tools on page 2-15).
The Display menu contains commands that allow you to control which windows are visible and whether the upper toolbar is visible. The following commands are available:
- Statistics: opens the Query Statistics window, which contains statistics about the current query For a description of the Query Statistics window, see The Query Statistics Window on page 2-36.
- Output Window: opens the Output window, which contains output from the current query. For a description of the output window, see The Output Window on page 2-38.
- Connection Information: opens the Connection Information window, which contains information about the current connection. For more information about the Connection Information window see The Connection Information Window on page 2-40
- Toolbar: opens and closes the upper toolbar (the lower toolbar is always open)
You can also open these windows with the Query Statistics, Output Window, and Connection Information icons (see Tools on page 2-15).
The List Modes menu contains commands that provide table, view, and column information about the current database and additional user-defined information for use in constructing SELECT statements. The following commands are available:
- User Tables: opens the Table List window, which contains a list of the tables in the current database
- User Views: opens the View List window, which contains a list of the views in the current database
- User-defined: opens a User-defined List window, which contains the contents of a user-specified file
The file should contain a list of SQL elements to be used in constructing a SQL statement. There must be only one entry per line in the file, and each line can have a maximum of 80 characters.
- Column Names: prompts for a table name and then opens a Column List window, which contains a list of the columns in that table
Selecting an entry in any of these windows inserts the entry into the statement window at the most recent cursor position. Depending on how your platform handles buffer input, you may need to signify completion of the current line in the statement window (as noted in the message under the window) before selecting the entry; check your user documentation for specifics.
You can also open these windows with the Table List, Column List, View List, and User-defined List icons (see Tools on page 2-15).
For descriptions of the above windows, see The List Windows on page 2-41.
The toolbars contain a set of query tools. The upper toolbar, located beneath the menubar, is open by default. You can close and open it with the Display->Toolbar command. The lower toolbar, located beneath the statement window, is always open.
The upper toolbar contains the following icons:
The lower toolbar contains the following icons:
Each of the Graph tools is linked to a Graph output port in the Query macro. The Graph ports are typically connected to other UIwindows; for example, Viewer3D. Selecting a Graph tool opens the corresponding UIwindow. (For information on the Graph ports, see the on-line reference for Query.) Each of the other tools performs the same action as a Query command on the menubar.
The following table describes each tool briefly and notes the corresponding Query command. See the description of that command for a detailed description of the operation performed.
The Query interface contains three output fields into which connection and status information are returned.
An message that describes the status of the current connection, either Connected or Disconnected.
This field maps to DBquery.connect_information.connected.
A message that describes the status of the query. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to DBquery.message.
The status code associated with the message returned in the message parameter. A value of 0 indicates success; a nonzero value indicates failure. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to DBquery.return_code.
The following table provides a quick reference to the tasks you can perform with the Query interface. For descriptions of these components, see the previous sections.
Table B-2
The Manipulate macro performs SQL operations other than queries on a database. It provides a user interface to the DBdelete, DBinsert, DBupdate, DBmiscStatement, DBcommit, and DBrollback modules that perform the operation and some additional modules that perform support tasks.
Note: You must be connected to a database before performing a SQL operation on it. If you are not connected to a database, the SQL operation is not processed and the value in the Message field is "Not connected." If you are using the Manipulate macro to perform the operation, you will typically use the Connect macro to connect to the database. See Connecting to a Database on page 2-2.
You use the Manipulate macro to perform a non-query SQL operation other than a commit or rollback by constructing the appropriate SQL statement and submitting it for execution.
You use Manipulate to perform a commit or roll back by selecting a Manipulate command or tool from its interface.
At any time, you can view connection and other status information.
Note: Manipulate will process any SQL statement except CONNECT, SELECT, COMMIT, or ROLLBACK. If you attempt to process an invalid statement, the message "DBerror: Invalid statement" is returned to the Message field and an error window containing additional information opens. For details on constructing SQL statements, see Constructing SQL Statements on page 1-10.
The following subsections describe important aspects of these tasks.
By design, Manipulate does not execute a SQL statement as soon as it has been entered. When you finish entering the statement, you must process the statement; that is, trigger its execution.
You process an operation using either commands on the Statement menu or the Process tool; see The Statement Menu on page 2-25 or Tools on page 2-26, respectively.
Unlike other SQL operations in the Database Kit, you do not perform a commit or rollback by entering a COMMIT or ROLLBACK statement in the statement window and processing it. Instead, you use the appropriate menu command or tool, described later in this section, as follows:
- Commit: The Com/Roll->Commit command or the Commit tool
- Rollback: The Com/Roll->Rollback command or the Rollback tool
These commands and tools are described in The Com/Roll menu on page 2-26 and Tools on page 2-26, respectively.
The Manipulate interface appears whenever you instance a Manipulate macro in an application or start up an application that contains a Manipulate macro. Note that it is extremely similar- but NOT identical- to the Query interface.
This interface contains the following components:
- a statement window and a related Clear button
- a menu bar whose menus provide a number of manipulate-related commands or choices
- two toolbars that contain a number of manipulate-related tools
- output fields into which information about the SQL operation is returned
A number of the Manipulate commands and tools open additional windows. These windows, called secondary windows in this manual, provide access to additional information, including, in certain circumstances, special error information.
![]()
The remainder of this section describes the interface components and provides a quick reference to their use. The secondary windows are described in Using the Secondary Windows on page 2-30.
The statement window, located in the middle of the Manipulate interface, is where you construct a SQL statement. The following figure illustrates the statement window with the construction of a DELETE statement in process:
You can enter text into the statement window in three ways:
- Type in the information as you would into any window.
- Open a Table List, View List, Column List, or User-defined List window and select items from the window (see The List Modes Menu on page 2-25).
- Load the contents of a file containing a complete or partial SQL statement (see The File Menu on page 2-13).
When you finish entering a statement, you initiate its execution with one of the following:
- the Statement->Process command (see The Statement Menu on page 2-25)
- the Process tool (see Tools on page 2-26)
Be sure before you process the SQL statement that you have entered the complete statement.
Note: If you attempt to process an invalid SQL statement, the Manipulate interface will display an Error window containing information that marks the location of the error. For more information, see The Error Window on page 2-42.
To clear the current statement from the window and buffer and start again, press the Clear button just above the upper left corner of the statement window.
The menubar, located at the top of the Manipulate interface, contains a set of pull-down menus that provide commands specific to the Manipulate macro:
The Manipulate menus provide the following groups of commands:
- File: save the current SQL statement to a file or load it from a file
- Statement: start the current SQL statement
- Display: display connection information; open or close the upper toolbar
- List Modes: display table, view, column, and user-defined information for use in constructing a SQL statement
- Com/Roll: end (commit or roll back) the current transaction
You use these pull-down menus in the same way that you use the pull-down menus found in many other software products.
The File menu operates exactly as the Query interface File statement does. See The File Menu on page 2-13.
The Statement menu provides the Process command, which allows you to start the SQL operation specified by the current SELECT statement. You can also process statements with the Process tool (see Tools on page 2-26).
The Process command maps to DBdelete.process_statement, DBinsert.process_statement or DBupdate.process_statement.
The Display menu operates exactly as the Display Menu for the Query Interface. For info see The Display Menu on page 2-14
The List Modes menu operates exactly as the List Modes menu for the Query Interface. For info see The List Modes Menu on page 2-15.
You can also open these windows with the Table List, Column List, View List, and User-defined List tools (see Tools on page 2-26).
For descriptions of these windows, see The List Windows on page 2-41.
The Com/Roll menu contains commands that end (commit or roll back) the current transaction. (The current transaction includes all commands executed on the current connection, not just those executed through the current Manipulate interface.) The following commands are available:
- Commit: commits the current transaction, making any changes in the current transaction permanent in the database
- Rollback: rolls back the current transaction, aborting any changes in the current transaction
You can also commit or roll back a transaction with the Commit and Rollback tools (see Tools on page 2-26).
The toolbars contain a set of manipulate-related tools. The upper toolbar, located beneath the menubar, is open by default. You can close and open it with the Display->Toolbar command. The lower toolbar, located beneath the statement window, is always open.
The upper toolbar contains the following tools:
The lower toolbar contains the following tool:
Each of the tools performs the same action as its associated Manipulate command on the menus. The following table describes each tool briefly and notes the corresponding Manipulate command. See the description of that command for a detailed description of the operation performed.
The Manipulate interface contains three output fields into which connection and status information are returned.
A message that describes the status of the current connection, either Connected or Disconnected.
This field maps to the connect_information.connected field of DBdelete, DBinsert, DBupdate, or DBmiscStatement.
A message that describes the status of the SQL operation. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to the message field of DBdelete, DBinsert, DBupdate, or DBmiscStatement.
The status code associated with the message returned in the message parameter. A value of 0 indicates success; a nonzero value indicates failure. For a list of possible values, see Chapter 4, Database Kit Messages and Codes.
This field maps to the return_code field of DBdelete, DBinsert, DBupdate, or DBmiscStatement.
The following table provides a quick reference to the tasks you can perform with the Manipulate interface. For descriptions of these components, see the previous sections.
Table B-2
Using various Query and Manipulate commands and tools opens additional UIwindows that either provide access to parameters or display output or other information. Not all secondary windows are used by both Query and Manipulate interfaces. The following table lists the secondary windows (in one case, a group of related windows) and notes which of the interfaces use them:
The Query Control window is used only by the Query interface. It displays the current values of parameters that control query processing and allows you to reset those values. The following figure illustrates this window with the default values displayed:
The parameters whose values are displayed in this window can be grouped as follows:
- Null numeric field indicators. The top six values, Null value short, Null value int, and so forth, specify how a null numeric field is represented.
- Fetch-processing parameters. The User buf row limit, User buf realloc interval, and Rows per fetch values control fetch processing.
- Auto fetch. The Auto fetch loop button turns auto-fetch mode off or on.
- Flush when full. The Flush when full button determines how to proceed when the user buffer is full.
- Query timeout. The Query timeout value specifies how long the Query macro will wait for a response from the database server after the SQL command is submitted for processing.
When you display query output, you must be able to represent null-value fields in a recognizable way. This is not an issue for string fields, which use a zero-length null-terminated string. It is an issue for numeric fields (byte, signed short integer, signed integer, unsigned integer, float, or double float), because all possible entries in a numeric field have value, including 0.
The Query interface provides a set of null field indicator parameters that specify how a null numeric or string field is represented:
Null value short
Null value int
Null value float
Null value uint
Null value double
Null value byteFor each parameter, you provide an integer value that will be inserted into null fields of that datatype. The defaults are -127 for Null value byte and -999 for the others.
The Query interface provides three parameters that you can use to control the size of the fetch and user buffers used during fetch processing: Rows per fetch, User buf realloc interval, and User buf row limit.
- Rows per fetch The size of the fetch buffers and, by extension, the number of rows returned by each database fetch operation
- User buf realloc interval The initial size of the user buffers and the number of rows to be allocated whenever more rows are required
- User buf row limit The maximum size of the user buffers and, by extension, the total number of rows returned
These values interact as follows:
- The value of User buf realloc interval must be greater than or equal to Rows per fetch and less than or equal to User buf row limit.
- The value of User buf row limit must be greater than or equal to, and an integral multiple of Rows per fetch.
You should select values for these parameters carefully because your choices will affect how memory is used during the fetch processing used to return the results of a query. You should be especially careful when setting these values if your system has limited memory available.
One way to use less memory is to set a small value for Rows per fetch. Decreasing the size of the fetch buffer will result in more frequent fetch operations but smaller memory usage. In particular, do not set the value of Rows per fetch near or equal to the value of User buf row limit unless you have specified that the user buffers will be flushed when full (see Flushing the User Buffers on page 1-20) and are deliberately working with small user buffers.
Also, you should not initially allocate the entire number of rows required for the user buffers; that is, you should not set the value of User buf realloc interval near or equal to the value of User buf row limit. Instead, set User buf realloc interval to a low number to ensure that memory is used in small quantities as it is needed.
A number of memory usage status fields that allow you to gauge memory usage for a query are available to you in the Query Statistics window (see The Query Statistics Window on page 2-36). You should be aware that these fields include only the memory allocated explicitly by the Database Kit; they do not include the memory allocated by the database-native routines.
By default, fetch processing operates in a mode called auto-fetch; that is, it loops continuously until it returns the number of rows specified by User buf row limit to the application or there are no more rows to return. The Query interface provides a parameter called Auto fetch that turns auto-fetch on or off. When you turn auto-fetch off, fetch processing pauses between fetch operations. This is useful for viewing partial results. With auto-fetch turned off, you must reprocess the SQL statement after every pause to continue fetch processing. See Processing, Canceling, or Resetting a Query on page 2-10.)
Note: If auto-fetch is turned off and you reset any query parameters other than Flush when full between loops, the select resumes execution from the start rather than resuming with next rows of returned data.
Note: If auto-fetch is turned on, you should not turn on the Flush when full parameter. If you turn on Flush when full while in auto-fetch mode, the user buffers will be flushed automatically every time they fill until the end of fetch processing, and only the last user-buffer's worth of data will be available for processing. (Flush when full is described in the next section.)
As noted previously, Query executes fetch operations until either the number of rows specified by User buf row limit is reached or there are no more rows to be returned. The Query interface provides a parameter called Flush when full that determines how to proceed when the user buffers are full.
- If Flush when full is selected, Query flushes the buffers and begins a new fetch operation.
- If Flush when full is deselected, Query ends the query processing.
Note: You should select Flush when full only if fetch processing is not being performed in auto-fetch mode (see the previous section).
Note: Some database servers stop fetching rows prior to reaching the limit set by Rows per fetch if they encounter a row with an error, but resume fetching rows during the next fetch operation. As a result, the user buffer may not be completely full when it is flushed. See your database documentation for a description of how your database handles fetch operations.
Note: Space is not automatically reallocated for the user buffer when a flush occurs. The memory allocation stays at the maximum for subsequent fetch operations until the current query is canceled or released or a new query is issued.
The Query timeout parameter specifies, in seconds, how long the Query macro will wait for a response from the database server once a SQL command is submitted for processing.
The Query Output Types window is used only by the Query interface. It is provided by the OutputUI macro, which is available for use in other applications; see the on-line help.
The buttons in this window allow you to specify how numerical values are returned from a query. The following figure illustrates this window with the default settings displayed:
A database typically supports different datatypes than does the Database Kit. Therefore, the Database Kit maps the data returned by a query into its own datatypes. (See Mapping Data to Supported Database Kit Datatypes on page 1-22, for details.) This default mapping is typically the one used; however, you can force the mapping of numeric fields to other types.
In general, the database-independent layer maps numeric types as follows:
- Floating-point types are fields for which SCALE is not equal to 0 and fields that have been set explicitly to database-specific FLOAT datatypes. They are mapped to a C-language double float datatype. (SCALE is an SQL expression representing the number of digits to the right of the decimal point.)
- All other numeric datatypes are considered fixed types and are mapped to the C-language integer datatype.
For information on your database's supported datatypes and for supported limits for scale, precision and number of digits in the result, see your database documentation.
You can use the numeric datatype parameters provided by this window- Force output, Float Type, and Fixed Type- to override the database-independent layer's default mapping of numeric fields. You must exercise care when using these parameters to override the database-independent layer's mapping. If the mapping you select causes an overflow condition, cancellation of the current query will occur due to fetch errors.
The three override parameters are used as follows:
- Force output. This parameter specifies how numeric data returned from the database is treated. The following table lists the allowed values and their meanings:
In the context of this parameter, "fixed" means non-floating-point types with a SCALE of 0. By default, the database-independent layer maps these values to signed byte, signed short integer, or signed integer, depending on the maximum value of the column as defined by the database engine.
This parameter is useful in circumstances such as the following: some databases return a SCALE of 0 for all columns that result from the use of operators such as UNION, UNION ALL, and INTERSECT. Therefore, all of the columns, including floating-point types, are classified as fixed types and may result in an overflow error. (To determine whether your database does this, see Chapter 3, Database-Specific Usage,or your database documentation.)
Selecting Float Type allows such a query to return all numeric values, both floating-point and fixed, into double or float fields, avoiding the overflow error.
- Float Type. This parameter specifies how floating-point types are mapped. The following table lists the allowed values and their meanings:
This parameter allows you to reduce float types from double to float. Do not do this unless you are certain that the maximum values returned by the query (including the returned values of functions such as AVG) can be contained in the float datatype without resulting in an overflow condition. (An overflow condition will result in the display of the Database Kit error DB ERROR: Recoverable database error.)
Note: Regardless of how a database represents floating-point types internally, the data values actually present may be restricted by factors such as application-level editing rules or host-variable datatypes. For example, the data values for a column could always be generated from a C-language float variable. For more information, see your database documentation.
- Fixed Type. This parameter specifies how fixed types are mapped. The following table lists the allowed values and their meanings:
Note: Regardless of how a database represents fixed types internally, the data values actually present may be restricted by factors such as application-level editing rules or host-variable datatypes. For more information, see your database documentation.
The Query Statistics window is used only by the Query interface. It contains statistics about the most recent fetch operation of the current query:
- the number of fetches performed
- the number of rows processed in the last fetch
- the number of columns in the returned data rows
- the number of rows allocated for the user buffer
- the number of rows used in the user buffer
- the number of bytes allocated for the user buffer
The values in this window depend on parameter settings specified in the query-processing windows (see The Parameters Menu on page 2-14) and the amount of processing completed. They are obtained from the various fields of the DBquery.output_statistics structure.
You can open this window with either the Display->Statistics command or the corresponding tool. See The Display Menu on page 2-14 and Tools on page 2-15 for details.
The Query Statistics window is provided by the StatisticsUI macro. This macro is available for use in other applications; see the on-line reference for StatisticsUI.
The Output window is used only by the Query interface. The following figure illustrates an Output window containing some data returned by a simple query (the contents of a given Output window will vary depending on the query specifications).
The Output window, unlike other secondary windows, has its own menubar, containing menus and commands that save the output or specify how it is displayed. Five Output window menus are available:
- File: contains the Save Output command. This command converts query output to an array of strings and saves it in a specified file. It provides a file window in which to specify the file.
For more information on the conversion, see Viewing and Processing Output on page 2-10.
- Rows: specifies the number of rows to be displayed at one time. You can select from the following:
- Columns: specifies header information. You can select from the following:
- Column Mode: specifies header information. You can select from the following:
- Spaces: specifies the number of spaces between columns. You can select from the following:
- Clear: contains the Clear Output Window command, which empties the Output window.
The Output window is provided by the OutputWindowUI macro. This macro is available for use in other applications; see the on-line reference for OutputWindowUI.
The Connection Information window is used by both the Query and Manipulate interfaces. It contains the following information about the current connection:
- the database driver
- the server host
- the server name
- the database name
- the user ID
- the connect string
The values in this window are obtained from the various fields of the connect_information parameter of the relevant underlying Database Kit module.
You can open this window with either the Display->Connection Information command or the corresponding tool. See The Display Menu on page 2-14 and Tools on page 2-15 for details.
The Connection Information window is provided by the ConnectionUI macro. This macro is available for use in other applications; see the on-line reference for ConnectionUI.
The List windows display information about tables, views, and columns in the current database. You can use them to construct SELECT statements, as described in The Statement Window and the Clear Button on page 2-12. The following windows are available:
You can open these windows with either the List Modes menu or the corresponding tools. See The List Modes Menu on page 2-15 and Tools on page 2-15 for details.
The Table List window contains a list of the tables in the current database; for example:
The View List and Column List windows, which display lists of views in the current database and columns in a specified table, have a similar appearance.
The User-Defined List window contains the contents of a user-specified file; for example:
The file should contain a list of SQL elements to be used in constructing a SQL statement. There must be only one entry per line in the file, and each line can have a maximum of 80 characters.
A certain amount of error information is available in fields in the Connect, Query, and Manipulate interfaces. In addition, an error resulting from an invalid SQL statement displays a special Error window that identifies the location of the error.
Suppose, for example, that you construct the following simple DELETE statement in the statement window of the Manipulate interface:
In this DELETE statement, the table name MINUTES is misspelled as MNIUTES. Because the table MNIUTES does not exist, the database server returns an SQL error message when you process this statement, and the following Error window is displayed:
The System error and Error code fields show the SQL error message and return code, respectively. The Statement error location consists of the invalid statement with the marker ----->> inserted at the point of error.
For error handling information, including a description of how this error message is constructed, see Handling Errors on page 1-52.
The Error window is provided by the ErrorUI macro. This macro is available for use in other applications; see the on-line reference for ErrorUI.
The Tools macro provides access to the user interfaces of the Connect, Query, and Manipulate macros. The Tools interface appears whenever you instance a Tools macro:
This interface contains three tools.
- The Connect tool opens the Connect user interface. This interface is used to connect to or disconnect from a database. For more information, see Using the Connect Interface on page 2-2.
- The Query tool opens the Query user interface. This interface is used to query a database. For more information, see Using the Query Interface on page 2-8.
- The Manipulate tool opens the Manipulate user interface. This interface is used to perform non-query SQL operation on a database. For more information, see Using the Manipulate Interface on page 2-21.
The Tools macro is intended only as a convenience for launching these three interfaces when you are using the Database Kit in the AVS/Express development environment. It is not intended for use in an application that you develop from AVS/Express.
Note: You must be connected to a database before performing a query or other SQL operation on it. If you are using the Query or Manipulate macro to perform the SQL operation, you will typically use the Connect macro to connect to the database. See Connecting to a Database on page 2-2.
![]() |
![]() |
![]() |
![]() |
![]() |
Copyright © 2001 Advanced Visual Systems
Inc.
All rights reserved.