home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.microsoft.com
/
2002-07-02_ftp.microsoft.com.zip
/
developr
/
ODBC
/
unsup-ed
/
LONGSE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-10
|
4KB
|
122 lines
//
// PROGRAM: longsend.c
// (C) 1990-1992 Microsoft Corporation. All rights reserved
//
// PURPOSE: Demonstrates the use of SQLPutData to send long data values
//
// FUNCTIONS:
// LongSend() - custom test
//
//
/*
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 LongSend()
{
RETCODE retcode; // Holds the return code for API calls
PTR pToken;
SDWORD cbValue; // Set to SQL_DATA_AT_EXEC
int cParam = 0;
cbValue = SQL_DATA_AT_EXEC;
/*
Prepare an insert statement. The table is called publishers and
has the following 4 columns:
pub_id char(4)
name varchar(40)
city varchar(20)
state char(2)
*/
retcode = SQLPrepare(hstmt, "Insert into publishers values (?,?,?,?)",
SQL_NTS);
if (retcode == SQL_SUCCESS) {
/* The first 3 fields will use SQLPutData for insertion. Accordingly,
the *pcbValue is set to SQL_DATA_AT_EXEC. The rgbValue has been
set to NULL - but it might just as easily been set to a value
which would give some more information during a later call to
SQLParamData. */
/* For parameter #1, the C data type is SQL_C_CHAR, SQL data type
is SQL_CHAR, cbColDef (the precision) is 4 - because the column
is char(4), ibScale is 0 because char columns don't have a scale */
SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR, 4, 0, NULL, &cbValue);
/* Note that for the next two parameters, fSqlType is SQL_VARCHAR */
SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_VARCHAR, 40, 0, NULL, &cbValue);
SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_VARCHAR, 20, 0, NULL, &cbValue);
/* This is not a SQL_DATA_AT_EXEC parameter - ie, SQLPutData is not
used. pcbValue is NULL, saying that rgbValue is a NULL teminated
string. */
SQLSetParam(hstmt, 4, SQL_C_CHAR, SQL_CHAR, 2, 0, "WA", NULL);
retcode = SQLExecute(hstmt);
/* SQLExecute returns SQL_NEED_DATA because parameters 1, 2, 3
are SQL_DATA_AT_EXEC. */
if (retcode == SQL_NEED_DATA){
/* Call SQLParamData to begin SQL_AT_EXEC parameter processing.
pToken contains the application dependent *rgbValue - which
is NULL in this case. */
retcode = SQLParamData(hstmt, &pToken);
while (retcode == SQL_NEED_DATA) {
cParam++;
switch (cParam) {
/* Parameters 1 and 3 are sent in one shot. Parameter 2
is sent in two calls to SQLPutData. This is how a
long value would be sent. In this example, none of the
are long values and SQLPutData is used purely for
illustration purposes. */
case 1: retcode = SQLPutData(hstmt, "1622", SQL_NTS);
break;
case 2: retcode = SQLPutData(hstmt, "Mc Graw ", SQL_NTS);
retcode = SQLPutData(hstmt, "Hill", SQL_NTS);
break;
case 3: retcode = SQLPutData(hstmt, "Seattle", SQL_NTS);
break;
} // switch
/* Call SQLParamData to indicate that the processing of this
SQL_AT_EXEC parameter is over and to signal the beginning
of the next SQL_AT_EXEC parameter, if any. If all the
SQL_AT_EXEC parameters have been processed, SQLParamData
returns SQL_SUCCESS. */
retcode = SQLParamData(hstmt, &pToken);
} // while
} // inner if
} // outer if
}