home *** CD-ROM | disk | FTP | other *** search
- .Na "dbaltbind"
- .Aa
- .Fu
- Bind a compute column to a program variable.
- .Ih "compute column, binding to a program variable"
- .Sy
- .Sf "RETCODE dbaltbind(dbproc, computeid, column, vartype,"
- .sp -1v
- .Sf " varlen, varaddr)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "int" "computeid"
- .Sp "int" "column"
- .Sp "int" "vartype"
- .Sp "DBINT" "varlen"
- .Sp "BYTE" "*varaddr"
- .Co
- .Bl
- This routine directs \*L
- to copy compute column data returned by \*S into a program
- variable.
- (A compute column results from the COMPUTE clause of a \*N SELECT
- statement.)
- When each new row containing compute data is read via
- .I "dbnextrow()"
- or
- .I "dbgetrow(),"
- the data from the designated \f2column\f1 in that compute row
- is copied into the program variable with the address \f2varaddr\f1. There
- must be a separate
- .I "dbaltbind()"
- call for each compute column that is to be copied.
- It is not necessary to bind every compute column to a program variable.
- .Bl
- The \*S can return two types of rows:
- regular rows containing data from columns designated by a SELECT statement's \f2select-list\f1,
- and compute rows resulting from the COMPUTE clause.
- .I "dbaltbind()"
- binds data from compute rows.
- Use
- .I "dbbind()"
- for binding data from regular rows.
- .Bl
- You must make the calls to
- .I "dbaltbind()"
- after a call to
- .I "dbresults()"
- and before the first call to
- .I "dbnextrow()."
- .Bl
- The typical sequence of calls is:
- .SD
- .ta +4n +4n +4n +4n +4n +4n
- .so dbaltbind.ex
- .ED
- .Bl
- .I "dbaltbind()"
- incurs a little overhead,
- because it causes
- the data to be copied into a program variable.
- To avoid this copying, you can use the
- \f2dbadata()\f1 routine to directly access the returned data.
- .Bl
- You can only bind a result column to a single program variable.
- If you bind a result column to multiple variables,
- only the last binding takes effect.
- .Bl
- Since \*S can return null values,
- \*L provides
- a set of default values, one for each datatype,
- that it will automatically substitute when binding null values.
- The \f2dbsetnull()\f1 function allows you to
- explicitly set your own null substitution values.
- (See the manual page for the
- .I "dbsetnull()"
- function for a list of the default substitution values.)
- .Bz
- .Pa
- .Pi dbproc
- A pointer to the DBPROCESS structure that provides the connection
- for a particular front end/\*S process. It contains all the
- information that \*L uses to manage communications and data between the
- front end and \*S.
- .Pi computeid
- The id that identifies the particular compute row of interest.
- A SELECT statement may have multiple COMPUTE clauses,
- each of which returns a separate compute row.
- The \f2computeid\f1 corresponding to the
- first COMPUTE clause in a SELECT is 1.
- .Pi column
- The column number of the row data that is to be copied to a
- program variable. The first column is column number 1.
- Note that the order in which compute columns are returned is determined by the order
- of the corresponding columns in the \f2select-list\f1, not by the order in which the
- compute columns were originally specified.
- For example, in the following query the result of ``sum(price)'' is referenced by giving
- \f2column\f1 a value of 1, not 2:
- .SD
- .in +5n
- .ne 2
- select price, advance from titles
- compute sum(advance), sum(price)
- .in -5n
- .ED
- The relative order of compute columns in the \f2select-list\f1, rather than their absolute
- position, determines the value of \f2column\f1.
- For instance, given the following variation of the previous SELECT:
- .SD
- .in +5n
- .ne 2
- select title_id, price, advance from titles
- compute sum(advance), sum(price)
- .in -5n
- .ED
- the \f2column\f1 for ``sum(price)'' still has a value of 1 and not 2,
- because the ``title_id'' column in the \f2select-list\f1
- is not a compute column and therefore is ignored when determining the compute column's number.
- .Pi vartype
- This describes the datatype of the binding.
- It must correspond to
- the datatype of the program variable that will receive
- the copy of the data from the DBPROCESS.
- The table below shows the correspondence between \f2vartypes\f1
- and program variable types.
- .sp
- \f2dbaltbind()\f1 supports a wide range of type conversions,
- so the \f2vartype\f1 can be different from the type returned
- by the SQL query.
- For instance, a SYBMONEY result may be bound to a DBFLT8
- program variable via FLT8BIND, and the appropriate data conversion
- will happen automatically.
- For a list of the data conversions provided by \*L,
- see the manual page for \f2dbwillconvert()\f1.
- .Ih "datatype conversion"
- .Ih "conversion, datatype"
- .sp
- For a list of the typedefs used by \*L, see
- the manual page for
- .I types.
- .sp
- Here is a list of the legal
- .I vartypes
- recognized by
- .I "dbaltbind(),"
- along with the \*S and program variable
- types that each one refers to:
- .Ih "dbaltbind types"
- .Ih "types, dbaltbind"
- .sp
- .nf
- .in +3n
- .ps -2
- .vs -2
- .ne 15
- .ta +24n +26n
- \f3Vartype Program variable type \*S type\f1
- .sp 0.5v
- CHARBIND DBCHAR SYBCHAR
- STRINGBIND DBCHAR SYBCHAR
- NTBSTRINGBIND DBCHAR SYBCHAR
- VARYCHARBIND DBVARYCHAR SYBCHAR
- BINARYBIND DBBINARY SYBBINARY
- VARYBINBIND DBVARYBIN SYBBINARY
- TINYBIND DBTINYINT SYBINT1
- SMALLBIND DBSMALLINT SYBINT2
- INTBIND DBINT SYBINT4
- FLT8BIND DBFLT8 SYBFLT8
- BITBIND DBBIT SYBBIT
- DATETIMEBIND DBDATETIME SYBDATETIME
- MONEYBIND DBMONEY SYBMONEY
- .fi
- .ps +2
- .vs +2
- .in -3n
- .sp
- Since SYBTEXT and SYBIMAGE data are never returned through a compute
- row, those datatypes are not listed above.
- .sp
- Note that the \*S type in the table above is listed merely for
- your information. The \f2vartype\f1 you specify does not necessarily have to
- correspond to a particular \*S type,
- because, as mentioned earlier,
- \f2dbaltbind()\f1 will convert \*S data into the specified \f2vartype\f1.
- .sp
- The above table shows that four representations for
- character data are available.
- They differ according to whether the data is blank-padded or null-terminated:
- .sp
- .nf
- .in +3n
- .ps -2
- .vs -2
- .ne 5.5
- .ta +24n +24n +15n
- \f3Vartype Program type Padding Terminator\f1
- .sp 0.5v
- CHARBIND DBCHAR blanks none
- STRINGBIND DBCHAR blanks \e0
- NTBSTRINGBIND DBCHAR none \e0
- VARYCHARBIND DBVARYCHAR none none
- .fi
- .in -3n
- .ps +2
- .vs +2
- .sp
- Note that the ``\e0'' in the table above is the null terminator character.
- .sp
- If overflow occurs when converting integer or float data to a character/text binding type,
- the first character of the resulting value will contain an asterisk (``*'') to indicate the error.
- .sp
- Binary and image data may be stored in two different ways:
- .sp
- .nf
- .in +3n
- .ps -2
- .vs -2
- .ne 3.5
- .ta +24n +24n
- \f3Vartype Program type Padding\f1
- .sp 0.5v
- BINARYBIND DBBINARY nulls
- VARYBINBIND DBVARBINARY none
- .fi
- .ps +2
- .vs +2
- .in -3n
- .sp
- When a column of integer data is summed or averaged,
- \*S always returns a 4-byte integer,
- regardless of the size of the column.
- Therefore, be sure that the variable which is to contain
- the result from such a compute is declared as DBINT
- and that the \f2vartype\f1 of the binding is INTBIND.
- .Pi varlen
- The length of the program variable in bytes.
- .sp
- For fixed-length \f2vartypes\f1, such as MONEYBIND or
- FLT8BIND, this length is ignored.
- .sp
- For character and binary types,
- \f2varlen\f1 must describe the total length of the available
- destination buffer space, including any space that may be required
- for special terminating bytes, such as a null terminator.
- If \f2varlen\f1 is 0, the total number of bytes available
- will be copied into the program variable.
- (For \f2char\f1 and \f2binary\f1 \*S data, the total number of bytes available
- is equal to the defined length of the database column, including any blank padding.
- For \f2varchar\f1 and \f2varbinary\f1 data, the total number
- of bytes available is equal to the actual data contained in the column.)
- Therefore, if you are sure that your program variable is large enough
- to handle the results, you can just set \f2varlen\f1 to 0.
- .Pi varaddr
- The address of the program variable to which the data will be
- copied.
- .in -.375i
- .Re
- .br
- SUCCEED or FAIL.
- \f2dbaltbind()\f1 returns FAIL if the
- column number isn't valid, if the
- data conversion specified by
- .I vartype
- isn't legal, or if
- .I varaddr
- is NULL.
- .Sa
- dbadata,
- dbbind,
- dbconvert,
- dbsetnull,
- dbwillconvert,
- types
-