home *** CD-ROM | disk | FTP | other *** search
- .Na "dbbind"
- .Aa
- .Fu
- Bind a regular result column to a program variable.
- .Ih "regular column, binding to a program variable"
- .Sy
- .Sf "RETCODE dbbind(dbproc, column, vartype, varlen, varaddr)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "int" "column"
- .Sp "int" "vartype"
- .Sp "DBINT" "varlen"
- .Sp "BYTE" "*varaddr"
- .Co
- .Bl
- Data comes back from \*S one row at a time.
- This routine directs \*L
- to copy the data for a regular column (designated in
- a SELECT statement's \f2select-list\f1) into a program
- variable.
- When each new row containing regular (\f2not\f1 compute) data is read via
- .I "dbnextrow()"
- or
- .I "dbgetrow(),"
- the data from the designated \f2column\f1 in that row is
- copied into the program variable with the address \f2varaddr\f1. There
- must be a separate
- .I "dbbind()"
- call for each regular column that is to be copied.
- It is not necessary to bind every column to a program variable.
- .Bl
- The \*S can return two types of rows:
- regular rows
- and compute rows resulting from the COMPUTE clause of a SELECT statement.
- .I "dbbind()"
- binds data from regular rows.
- Use
- .I "dbaltbind()"
- for binding data from compute rows.
- .Bl
- You must make the calls to
- .I "dbbind()"
- after a call to
- .I "dbresults()"
- and before the first call to
- .I "dbnextrow()."
- .Bl
- The typical sequence of calls is:
- .ta +4n +4n +4n +4n +4n +4n
- .SD
- .so dbbind.ex
- .ED
- .Bl
- .I "dbbind()"
- incurs a little overhead,
- because it causes
- the data to be copied into a program variable.
- To avoid this copying, you can use the
- \f2dbdata()\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 column
- The column number of the row data that is to be copied to a
- program variable. The first column is column number 1.
- .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
- \f2dbbind()\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 "dbbind(),"
- along with the \*S and program variable
- types that each one refers to:
- .Ih "dbbind types"
- .Ih "types, dbbind"
- .sp
- .nf
- .in +3n
- .ps -2
- .vs -2
- .ne 15
- .ta +24n +26n
- \f3Vartype Program variable type \*S type\f1
- .sp 0.5v
- .mc |
- CHARBIND DBCHAR SYBCHAR or SYBTEXT
- STRINGBIND DBCHAR SYBCHAR or SYBTEXT
- NTBSTRINGBIND DBCHAR SYBCHAR or SYBTEXT
- VARYCHARBIND DBVARYCHAR SYBCHAR or SYBTEXT
- BINARYBIND DBBINARY SYBBINARY or SYBIMAGE
- VARYBINBIND DBVARYBIN SYBBINARY or SYBIMAGE
- .mc
- 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
- 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,
- \f2dbbind()\f1 will convert \*S data into the specified \f2vartype\f1.
- .sp
- The table shows that four representations for
- character and text 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
- .ps +2
- .vs +2
- .in -3n
- .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
- .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, text, binary, and image 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, \f2varbinary\f1, \f2text\f1, and \f2image\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.
- \f2dbbind()\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
- dbaltbind,
- dbconvert,
- dbdata,
- dbsetnull,
- dbwillconvert,
- types
-