6. Embedded SQL for BASIC : Dynamic Programming for BASIC : How to Set SQLNAME for Dynamic FRS
 
Share this page                  
How to Set SQLNAME for Dynamic FRS
Using the sqlvar with Dynamic FRS statements requires a few extra steps that relate to differences between Dynamic FRS and Dynamic SQL. These differences are described in the SQL Reference Guide.
When using the SQLDA in a forms input or output using clause, the value of sqlname must be set to a valid field or column name. If this name was set by a previous describe statement, it must be retained or reset by the program. If the name refers to a hidden column or table field, then your program must set it directly. If your program sets sqlname directly, it must also set sqlnamel and sqlnamec.
The name portion need not be padded with blanks. For example, a dynamically named table field has been described, and the application always initializes any table field with a hidden 6-byte character column called "rowid". The code used to retrieve a row from the table field including the hidden column and _state variable would have to construct the two named columns:
declare string rowid = 6
declare long rowstate
...
exec frs describe table :formname :tablename INTO :sqlda
...

! BASIC is zero-based so save before incrementing
col_num = sqlda::sqld
sqlda::sqld = sqlda::sqld + 1
! Set up to retrieve rowid
sqlda::sqlvar(col_num)::sqltype = IISQ_CHA_TYPE
sqlda::sqlvar(col_num)::sqllen = 6
sqlda::sqlvar(col_num)::sqldata = loc(rowid)
sqlda::sqlvar(col_num)::sqlind = 0
sqlda::sqlvar(col_num)::sqlname::sqlnamel = 5
sqlda::sqlvar(col_num)::sqlname::sqlnamec = 'rowid'

col_num = sqlda::sqld
sqlda::sqld = sqlda::sqld + 1
! Set up to retrieve _STATE
sqlda::sqlvar(col_num)::sqltype = IISQ_INT_TYPE
sqlda::sqlvar(col_num)::sqllen = 4
sqlda::sqlvar(col_num)::sqldata = loc(rowstate)
sqlda::sqlvar(col_num)::sqlind = 0
sqlda::sqlvar(col_num)::sqlname::sqlnamel = 6
sqlda::sqlvar(col_num)::sqlname::sqlnamec = '_state'
...
exec frs getrow :formname :tablename using descriptor :sqlda