`

dbbind

阅读更多

dbbind

Binds a regular result column (a column of results from a SELECT statement's select list) to a program variable.

Syntax

RETCODE dbbind ( 
PDBPROCESS 
dbproc
INT 
column
INT 
vartype
DBINT 
varlen
LPBYTE 
varaddr );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.

column

Is the column number of the row data to be copied to a program variable. The first column is number 1.

vartype

Is a description of the binding's data type. It corresponds to the data type of the program variable that receives the copy of the data from the DBPROCESS. The dbbind function supports a wide range of type conversions, so vartype can be different from the type returned by the SQL query. For instance, a SQLMONEY result can be bound to a DBFLT8 program variable, using FLT8BIND, and the appropriate data conversion happens automatically. For more information about a list of the data conversions provided by DB-Library, see dbwillconvert. For more information about a list of the type definitions used by DB-Library, see DB-Library for C Data Types.

The following table lists legal vartypes recognized by dbbind and the program variable and SQL Server type tokens that each refers to.


vartype

varaddr
SQL Server data type 
of column
CHARBIND DBCHAR SQLCHAR, SQLVARCHAR, or SQLTEXT
STRINGBIND DBCHAR SQLCHAR, SQLVARCHAR, or SQLTEXT
NTBSTRINGBIND DBCHAR SQLCHAR, SQLVARCHAR, or SQLTEXT
VARYCHARBIND DBVARYCHAR SQLCHAR, SQLVARCHAR, or SQLTEXT
BINARYBIND DBBINARY SQLBINARY, SQLVARBINARY, or SQLIMAGE
VARYBINBIND DBVARYBIN SQLBINARY, SQLVARBINARY, or SQLIMAGE
TINYBIND DBTINYINT SQLINT1 or SQLINTN
SMALLBIND DBSMALLINT SQLINT2 or SQLINTN
INTBIND DBINT SQLINT4 or SQLINTN
FLT4BIND DBFLT4 SQLFLT4 or SQLFLTN
FLT8BIND DBFLT8 SQLFLT8 or SQLFLTN
BITBIND DBBIT SQLBIT
SMALLMONEYBIND DBMONEY4 SQLMONEY4 or SQLMONEYN
MONEYBIND DBMONEY SQLMONEY or SQLMONEYN
DECIMALBIND DBDECIMAL SQLDECIMAL
NUMERICBIND DBNUMERIC SQLNUMERIC
SRCDECIMALBIND DBDECIMAL SQLDECIMAL
SRCNUMERICBIND DBNUMERIC SQLNUMERIC
SMALLDATETIBIND DBDATETIM4 SQLDATETIM4 or SQLDATETIMN
DATETIMEBIND DBDATETIME SQLDATETIME or SQLDATETIMN

Note that the SQL Server type in the preceding table is listed merely for your information. The vartype you specify does not necessarily have to correspond to a particular SQL Server data type because dbbind converts SQL Server data into the specified vartype.

The following table lists the four representations for character and text data. They differ according to whether the data is blank-padded or null-terminated.

vartypevaraddr Padding Terminator
CHARBIND DBCHAR blanks none
STRINGBIND DBCHAR blanks \0
NTBSTRINGBIND DBCHAR none \0
VARYCHARBIND DBVARYCHAR none none

Note that "\0" is the null terminator character. Similarly, binary and image data can be stored in two different ways.

vartypevaraddr Padding
BINARYBIND DBBINARY nulls
VARYBINBIND DBVARBINARY none

When the source column specified by the column parameter has a type of SQLDECIMAL or SQLNUMERIC, you can keep the same precision and scale in your bound C variable by using SRCDECIMALBIND or SRCNUMERICBIND.

varlen

Is the length of the varaddr program variable in bytes. For fixed-length vartypes, such as MONEYBIND or FLT8BIND, this length is ignored. For character, text, binary, and image types, varlen must describe the total length of the available destination buffer space, including any space that can be required for special terminating bytes, such as a null terminator. If varlen is 0, the number of bytes available is copied into the program variable. (For char and binary SQL Server data, the number of bytes available is equal to the defined length of the database column, including any blank padding. For varcharvarbinarytext, and image data, the 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 set varlen to 0.

In some cases, DB-Library issues a message indicating that data conversion resulted in an overflow. This is usually caused by a varlen specification being too small for the data being received from SQL Server. For example, if varlen is set to 5, vartype is set to VARYCHARBIND, and the SQL Server column being bound is of type VARCHAR with a length of 20. When the bind occurs (using dbnextrow), the overflow message is issued. Note however that five bytes of data will be bound. Other types of binds also can cause the overflow message to be issued. For information about data type conversions, see dbconvert.

varaddr

Is the address of the program variable to which the data is copied. Calling dbbind with a NULL varaddr parameter breaks a previously set binding.

When binding using DECIMALBIND or NUMERICBIND, the varaddr parameter must be a pointer to a DBNUMERIC or DBDECIMAL C variable, respectively, with the precision and scale fields of the structure already set to the desired values. You can use DEFAULTPRECISION to specify a default precision and DEFAULTSCALE to specify a default scale.

Returns

SUCCEED or FAIL. The dbbind function returns FAIL if the column number given isn't valid, if the vartype isn't compatible with the SQL Server data type being returned, or if varaddr is NULL.

Remarks

Data comes back from SQL Server one row at a time. This function directs DB-Library to copy the data for a regular column (designated in a SELECT statement's select list) into a program variable. When each new row containing regular (not compute) data is read using dbnextrow or dbgetrow, the data from the designated column in that row is copied into the program variable with the address varaddr. There must be a separate dbbind call for each regular column to be copied. It is not necessary to bind every column to a program variable. A result column can be bound to only one program variable.

SQL Server can return two types of rows: regular rows and compute rows resulting from the COMPUTE clause of a SELECT statement. The dbbind function binds data from regular rows. Use dbaltbind for binding data from compute rows.

Calls to dbbind must be made after a call to dbresults and before the first call to dbnextrow.

Using dbbind causes some overhead because it copies the row data into the designated program variable. To avoid this copying, the returned data can be accessed more directly with dbdatlen and dbdata.

Because null values can be returned from SQL Server, there is a set of default values, one for each data type that will be substituted when binding null values. You can explicitly set your own values to be substituted for the default null value with the dbsetnull function. (For more information about a list of the default substitution values, see dbsetnull.)

For the Microsoft Windows® operating system, DB-Library retrieves information about date, time, numeric, and currency formatting from the Sqlcommn.loc file. The location of Sqlcommn.loc is pointed to by the SQLLocalizationFilekey in the Windows initialization file (Win.ini) under the [SQLSERVER] application heading. For example:

[SQLSERVER]
SQLLocalizationFile=C:\SQL60\BIN\SQLCOMMN.LOC

For the Microsoft Windows NT® 4.0 operating system, you set the date, time, numeric, and currency formatting using the International application in Control Panel. Use the SQL Server Client Network Utility Use International Settingsoption to activate this for DB-Library.

Examples

This example shows the typical sequence of calls:

DBINT   xvariable;
DBCHAR   yvariable[10];

// Read the query into the command buffer. 
dbcmd(dbproc, "SELECT x = 100, y = 'hello'");
// Send the query to SQL Server. 
dbsqlexec(dbproc);
// Get ready to process the results of the query. 
dbresults(dbproc);
// Bind column data to program variables. 
dbbind(dbproc, 1, INTBIND, (DBINT) 0, (BYTE *) &xvariable);
dbbind(dbproc, 2, STRINGBIND, (DBINT) 0, yvariable);

// Now process each row. 
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
   // C-code to print or process row data
}

 

See Also

DB-Library for C Data Types

dbgetrow

dbaltbind

dbnextrow

dbanullbind

dbresults

dbconvert

dbsetnull

dbdata

dbwillconvert

dbdatlen

分享到:
评论

相关推荐

    麦肯锡 组织 概述与基本框架gl.ppt

    麦肯锡 组织 概述与基本框架gl.ppt

    node-v10.11.0-linux-s390x.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    大型强子对撞机电源转换器设计与运行挑战

    大型强子对撞机电源转换器设计与运行挑战

    (优作)低功耗STM32F411开发板(原理图+PCB源文件+官方例程+驱动等)

    本文档提供了一套完整的STM32F411低功耗开发板资源,包含详细的原理图、PCB设计源文件、官方提供的示例程序以及必要的驱动程序。这些资料对于嵌入式系统开发者来说是宝贵的学习资源,特别适合那些希望深入了解STM32F411微控制器及其应用的学生、工程师和电子爱好者。文档旨在帮助用户快速上手STM32F411的开发工作,无论是进行学术研究、产品原型设计还是个人项目实践,都能从中获益。 关键词标签: STM32F411 低功耗 开发板 资料下载

    基于机器学习的发债主体违约风险预测python源码+项目说明+设计报告+答辩PPT.zip

    该项目以发债企业作为研究对象,利用财务逻辑和技术手段对178个原始特征指标进行有效筛选,构建了基于多种机器学习算法的模型,对比后挑选LightGBM模型作为最终模型进行更精细化训练,最终模型关键预测指标均有比较好的效果。 使用说明 BondDefault文件为项目代码 基于机器学习的发债主体违约风险预测.pdf为pdf形式的项目文稿 基于机器学习的发债主体违约风险预测.pptx为ppt形式的项目展示 由于数据集太大,此处没有上传

    Rain Birdt Simple To Set Timer (SST) 使用说明书.pdf

    Rain Birdt Simple To Set Timer (SST) 使用说明书

    SITRANS LVL 200S, LVL 200E 振动式安全手册.pdf

    SITRANS LVL 200S, LVL 200E 振动式安全手册

    麦肯锡-xx电信市场分析报告gl.ppt

    麦肯锡-xx电信市场分析报告gl.ppt

    基于matlab实现的三次样条插值法 求信号的包络线 源代码.rar

    基于matlab实现的三次样条插值法 求信号的包络线 源代码.rar

    麦肯锡_xx大客户培训战略报告gl.ppt

    麦肯锡_xx大客户培训战略报告gl.ppt

    node-v9.0.0-linux-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    node-v8.6.0-linux-s390x.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    嗨森无人机管理平台.zip

    无人机最强算法源码,易于部署和学习交流使用

    node-v8.16.2-linux-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

Global site tag (gtag.js) - Google Analytics