home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.microsoft.com
/
2002-07-02_ftp.microsoft.com.zip
/
developr
/
ODBC
/
unsup-ed
/
LONGRC.C
next >
Wrap
C/C++ Source or Header
|
1993-10-10
|
3KB
|
107 lines
//
// PROGRAM: longrcv.c
// (C) 1990-1992 Microsoft Corporation. All rights reserved
//
// PURPOSE: Demonstrates the use of SQLGetData to receive long data values
//
// FUNCTIONS:
// LongRcv()
//
//
/* This function retrieves the Publisher name from the Publishers
table. The table has the following 4 columns:
pub_id char(4)
name varchar(40)
city varchar(20)
state char(2)
For purposes of illustration, we assume that the buffer available
for holding the Publisher name is just 5 characters long. Since
this name could potentially be 40 characters, we make multiple
calls to SQLGetData to retrieve all the characters. */
#define NAMEBUFLEN 5
/*
The following are the henv, hdbc and hstmt which have presumably
been initialized by SQLAllocEnv, SQLAllocConnect and SQLAllocStmt
respectively, in another module.
*/
extern HENV henv;
extern HDBC hdbc;
extern HSTMT hstmt;
void FAR PASCAL LongRcv()
{
RETCODE retcode; // Holds the return code for API calls
UCHAR szPubName[NAMEBUFLEN]; // To hold Publisher name
SDWORD cbPubName;
/*
ExecDirect a select statement which retrieves the Publisher Name
and City from the Publishers table.
*/
retcode = SQLExecDirect(hstmt, "Select pub_name from publishers",
SQL_NTS);
if (retcode == SQL_SUCCESS) {
while (TRUE) {
/* The following call to SQLFetch only moves the cursor to the
next row. If a SQLBindCol had been done, the data would have
been implicitly transferred to the bound locations. */
retcode = SQLFetch(hstmt);
if (retcode == SQL_ERROR){
/* Something has gone wrong */
handle_error();
}
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO){
/* Now, we can explicitly get the required data */
retcode = SQLGetData(hstmt, 1, SQL_C_CHAR, szPubName,
NAMEBUFLEN, &cbPubName);
/* If the pub_name was longer than 5 characters, this call to
SQLGetData returns SQL_SUCCESS_WITH_INFO. A subsequent
call to SQLError returns SQLSTATE 01004 (Data Truncated).
At this stage we enter a loop to repeatedly call SQLGetData
until all data has been obtained. */
while (retcode == SQL_SUCCESS_WITH_INFO){
retcode = SQLGetData(hstmt, 1, SQL_C_CHAR, szPubName,
NAMEBUFLEN, &cbPubName);
}
/* At this stage, if retcode is SQL_SUCCESS, we are fine.
Otherwise, something wrong has happened! */
if (retcode == SQL_SUCCESS){
return ;
}
handle_error();
} // inner if
} // while
} // outer if
}