vcg03.htm
来自「Visual C++与数据库的连接经典实例」· HTM 代码 · 共 3,468 行 · 第 1/5 页
HTM
3,468 行
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
HDBC <I>hdbc</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A handle to an HDBC as returned by the call to the SQLAllocConnect() function.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
HSTMT FAR * <I>hstmt</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to a statement handle that will be filled in by this function.</FONT>
</TABLE></CENTER><P><B>Return Value:</B>
<BR>
<P>This function will return one of the following values:
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS_WITH_INFO
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful and more information is available.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_ERROR
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. Call SQLError() to get more information about the specific failure.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SLQ_INVALID_HANDLE
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle.</FONT>
</TABLE></CENTER><P>If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
<BR>
<P><B>Usage:</B>
<BR>
<P>The SQLAllocStmt() function is used to allocate a statement handle. This statement handle is associated with the datasource to which the HDBC handle was connected.
<BR>
<P><B>Notes:</B>
<BR>
<P>If this function fails, the returned HSTMT handle will be set to SQL_NULL_HSTMT.
<BR>
<BR>
<A NAME="E69E49"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B><I>SQLBindCol()</I></B></FONT></CENTER></H4>
<BR>
<P><B>Prototype:</B>
<BR>
<PRE>
<FONT COLOR="#000080">RETCODE SQLBindCol(HSTMT <I>hstmt</I>, UWORD <I>icol</I>, SWORD <I>fCType</I>,
PTR <I>rbgValue</I>, SDWORD <I>cbValueMax</I>, SDWORD FAR * <I>pcbValue</I>)</FONT></PRE>
<P><B>Parameters:</B>
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
HSTMT <I>hstmt</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A statement handle returned by the call to SQLAllocStmt().
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
UWORD <I>icol</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The index to the column in the table to which the variable is being bound.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>fCType</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The data type of the data variable that is being bound to column <I>icol</I>.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
PTR <I>rgbValue</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to the location in the application where the column's data is to be stored. The data type of <I>rgbValue</I> should be defined by fCType.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SDWORD <I>cbValueMax</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The number of bytes in the storage location pointed to by <I>rgbValue</I>. Usually, the C sizeof() operator can be used for this parameter.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SDWORD FAR * <I>pcbValue</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to an SDWORD variable that will receive the count of how many bytes in <I>rgbValue</I> were used.</FONT>
</TABLE></CENTER><P><B>Return Value:</B>
<BR>
<P>This function will return one of the following values:
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS_WITH_INFO
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful, and more information is available.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_ERROR
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. Call SQLError() to get more information about the specific failure.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SLQ_INVALID_HANDLE
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle.</FONT>
</TABLE></CENTER><P>If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
<BR>
<P><B>Usage:</B>
<BR>
<P>Call the SQLBindCol() function only for the columns in a table that you need. You don't have to bind to every column in a table. Columns that don't have a variable bound to them will be discarded without error.
<BR>
<P>You make a call—usually in a loop—to SQLFetch() or SQLExtendedFetch() to actually get the data from a record.
<BR>
<P>Always check the return code from this function for errors.
<BR>
<P><B>Notes:</B>
<BR>
<P>If this function fails, use the SQLError() function to find out why. When a column hasn't been bound and later must be accessed, use SQLGetData().
<BR>
<BR>
<A NAME="E69E50"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B><I>SQLBindParameter()</I></B></FONT></CENTER></H4>
<BR>
<P><B>Prototype:</B>
<BR>
<PRE>
<FONT COLOR="#000080">RETCODE SQLBindParameter(HSTMT <I>hstmt</I>, UWORD <I>ipar</I>, SWORD <I>fParamType</I>,
SWORD <I>fCType</I>, SWORD <I>fSqlType</I>, UDWORD <I>cbColDef</I>,
SWORD <I>ibScale</I>, PTR <I>rgbValue</I>, SDWORD <I>cbValueMax</I>, SDWORD <I>pcbValue</I>)</FONT></PRE>
<P><B>Parameters:</B>
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
HSTMT <I>hstmt</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A statement handle returned by the call to SQLAllocStmt().
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
UWORD <I>ipar</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The parameter number, which is one-based (not zero-based) from left to right.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>fParamType</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Parameter <I>ipar</I>'s type.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>fCType</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The C data type of the parameter.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>fSqlType</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The SQL data type of the parameter.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
UDWORD <I>cbColDef</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The column's precision.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>ibScale</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The column's scale.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
PTR <I>rgbValue</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to the location in the application where the column's data is to be stored. The data type of <I>rgbValue</I> should be defined by <I>fCType</I>.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SDWORD <I>cbValueMax</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The number of bytes in the storage location pointed to by <I>rgbValue</I>. Usually the C sizeof() operator can be used for this parameter.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SDWORD FAR * <I>pcbValue</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A pointer to an SDWORD variable that will receive the count of how many bytes in <I>rgbValue</I> were used.</FONT>
</TABLE></CENTER><P><B>Return Value:</B>
<BR>
<P>This function will return one of the following values:
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_SUCCESS_WITH_INFO
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function was successful, and more information is available.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SQL_ERROR
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. Call SQLError() to get more information about the specific failure.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SLQ_INVALID_HANDLE
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The function failed. The handle that was passed wasn't a valid handle. Possibly, the function that created the handle had failed and didn't return a valid handle.</FONT>
</TABLE></CENTER><P>If this function fails, your SQL function should end or the error should be corrected; the function should then be re-executed.
<BR>
<P><B>Usage:</B>
<BR>
<P>Call the SQLBindParameter() function to bind a buffer to a parameter marker in an SQL statement. Always check the return code from this function for errors.
<BR>
<P><B>Notes:</B>
<BR>
<P>If this function fails, use the SQLError() function to find out why. This function replaces the SQLSetParam() function found in ODBC version 1.x.
<BR>
<BR>
<A NAME="E69E51"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B><I>SQLBrowseConnect()</I></B></FONT></CENTER></H4>
<BR>
<P><B>Prototype:</B>
<BR>
<PRE>
<FONT COLOR="#000080">RETCODE SQLBrowseConnect(HDBC <I>hdbc</I>, UCHAR FAR * <I>szConnStrIn</I>, SWORD <I>cbConnStrIn</I>,
UCHAR FAR * <I>szConnStrOut</I>, SWORD <I>cbConnStrOutMax</I>, SWORD FAR * <I>pcbConnStrOut</I>)</FONT></PRE>
<P><B>Parameters:</B>
<BR>
<BR><CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
HDBC <I>hdbc</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
A handle to an HDBC as returned by the call to the SQLAllocConnect() function.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
UCHAR FAR * <I>szConnStrIn</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The input connection string.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>cbConnStrIn</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The number of bytes in <I>szConnStrIn</I>.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
UCHAR FAR * <I>szConnStrOut</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The output connection string.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD <I>cbConnStrOutMax</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The number of bytes available in <I>szConnStrOut</I>.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
SWORD FAR * <I>pcbConnStrOut</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The count of the number of bytes actually used in <I>szConnStrOut</I>.</FONT>
</TABLE></CENTER><P><B>Return Value:</B>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?