6. Embedded SQL for BASIC : BASIC Variables and Data Types : Variable Declarations : Data Types
 
Share this page                  
Data Types
The Embedded SQL preprocessor accepts the following elementary BASIC data types. The table below maps these types to their corresponding Ingres type categories. For a description of exact type mapping, see Data Type Conversion in this chapter.
BASIC Type
Ingres Type
string
character
integer
integer
long
integer
word
integer
byte
integer
real
float
single
float
double
float
double
decimal
Because BASIC supports the packed decimal datatype, the Ingres decimal type is mapped to it.  For example, the BASIC packed decmial declarations:
declare decimal pack1
declare decimal (p,s) pack2
correspond to the Ingres decimal types:
decimal (15, 2)
decimal (p,s)
In addition, the preprocessor accepts the BASIC record type in variable declarations, providing the record has been predefined in an Embedded SQL declaration section.
The data types gfloat and hfloat are illegal and will cause declaration errors.
Neither the preprocessor nor the runtime support routines support gfloat or hfloat floating-point arithmetic. Consequently, the precision of floating-point data is less than that which is available in VMS BASIC programs. You should not compile the BASIC source code with the command line qualifiers gfloat or hfloat if you intend to pass those floating-point values to or from Ingres objects.
The following sections discuss the variable declarations and the use of variables in Embedded SQL statements.
String Data Type
The Embedded SQL preprocessor accepts both fixed-length and dynamic string declarations. Strings can be declared using any of the declarations listed later. Note that you can indicate string length only for non-dynamic strings, that is, for string declarations appearing in common, map, or record declarations. For example,
common (globals) string ename = 30
is acceptable, but
declare string bad_str_var = 30 ! length is illegal
will generate an error.
The reference to an uninitialized BASIC dynamic string variable in an embedded statement that assigns the value of that string to Ingres will result in a runtime error because that restriction does not apply to the retrieval of data into an uninitialized dynamic string variable.
Integer Data Type
Embedded SQL/BASIC accepts all BASIC integer data type sizes. It is important that the preprocessor know about integer size because it generates code to load data in and out of program variables. The preprocessor assumes that integer size is four bytes by default. However, you can inform the preprocessor of a non-default integer size by using the -i flag on the preprocessor command line. For detailed information on this flag, see Advanced Processing in this chapter.
You can explicitly override the default size or the preprocessor -i command-line flag by using the BASIC subtype words byte, word, or long in the variable declaration, as these examples illustrate:
declare byte one_byte_int
common (globals) word two_byte_int
external long four_byte_int
These declarations instruct the preprocessor to create integer variables of one, two, and four bytes respectively, regardless of the default setting.
You can use an integer variable with any numeric-valued object to assign or receive numeric data. For example, you can use such a variable to set a field in a form or to select a column from a database table. It can also specify simple numeric objects, such as table field row numbers.
Real Data Type
As with the integer data type, the preprocessor must know the size of real data variables so that these variables can interact with Ingres correctly at runtime. The preprocessor accepts two sizes of real data: 4-byte variables (the default) and 8-byte variables. Again, you can change the default size with a flag on the preprocessor command line--in this case, the -r flag. For detailed information on this flag, see Advanced Processing in this chapter.
You can explicitly override the default size by using the BASIC subtype words single or double in a variable declaration. For example, the following two declarations:
declare single four_byte_real
map (myarea) double eight_byte_real
create real variables of four and eight bytes, respectively, regardless of the default setting.
A real variable can be used in Embedded SQL statements to assign or receive numeric data (both real and integer) to and from database columns, form fields, and table field columns. It cannot be used to specify numeric objects, such as table field row numbers.
Decimal Data Type
The preprocessor accepts variable declarations of the decimal data type. Note that because the current implementation of Ingres does not store data in packed decimal format, Ingres converts the contents of a decimal variable to and from a double at runtime. Therefore, although decimal variables can interact with Ingres, the movement of data at runtime, both before and after database manipulation, can lead to some loss of precision.
Decimal variables can be used in Embedded SQL statements to transmit numeric values to and from database columns, form fields, and table field columns. You cannot, however, use decimal variables with Ingres integer objects, such as table field row numbers.
The default scale and precision for both decimal variables and decimal symbolic constants in EQUEL/BASIC is the BASIC default of (15,2). The preprocessor does not support the BASIC compile flag /decimal_size. Compiling with the flag will not change the default precision and scale of decimal variables as far as the preprocessor is concerned. You should always specify the precision and scale when declaring a decimal variable or constant. For example:
declare decimal (10.4) constant = 1.2345 – Preferred declaration
declare decimal constant = 1.234         – Will use default (15,2) thus
                                           scale is truncated to two places.
Record Data Type
The Embedded SQL preprocessor supports the declaration and use of user-defined record variables. You can declare a variable of type record if you have already defined the record in an Embedded SQL declaration section. Later sections discuss the syntax of record declarations and their use in Embedded SQL statements.