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 >
C/C++ Source or Header  |  1993-10-10  |  4KB  |  122 lines

  1. //
  2. //  PROGRAM: longsend.c
  3. //           (C) 1990-1992 Microsoft Corporation. All rights reserved
  4. //
  5. //  PURPOSE: Demonstrates the use of SQLPutData to send long data values
  6. //
  7. //  FUNCTIONS:
  8. //          LongSend() - custom test
  9. //
  10. //
  11.  
  12.  
  13. /*
  14.     The following are the henv, hdbc and hstmt which have presumably
  15.     been initialized by SQLAllocEnv, SQLAllocConnect and SQLAllocStmt
  16.     respectively, in another module.
  17. */
  18.  
  19. extern HENV  henv;
  20. extern HDBC  hdbc;
  21. extern HSTMT hstmt;
  22.  
  23. void FAR PASCAL LongSend()
  24.  
  25. {
  26.  
  27. RETCODE retcode;                // Holds the return code for API calls
  28. PTR     pToken;                 
  29. SDWORD  cbValue;                // Set to SQL_DATA_AT_EXEC
  30. int     cParam = 0;
  31.  
  32.  
  33.    cbValue = SQL_DATA_AT_EXEC;
  34.  
  35. /*      
  36.     Prepare an insert statement. The table is called publishers and
  37.     has the following 4 columns:
  38.     pub_id  char(4)
  39.     name    varchar(40)
  40.     city    varchar(20)
  41.     state   char(2)
  42. */
  43.  
  44.    retcode = SQLPrepare(hstmt, "Insert into publishers values (?,?,?,?)",
  45.             SQL_NTS);
  46.  
  47.  
  48.    if (retcode == SQL_SUCCESS) {
  49.  
  50.       /* The first 3 fields will use SQLPutData for insertion. Accordingly,
  51.        the *pcbValue is set to SQL_DATA_AT_EXEC. The rgbValue has been
  52.        set to NULL - but it might just as easily been set to a value
  53.        which would give some more information during a later call to
  54.        SQLParamData. */
  55.  
  56.       /* For parameter #1, the C data type is SQL_C_CHAR, SQL data type
  57.        is SQL_CHAR, cbColDef (the precision) is 4 - because the column
  58.        is char(4), ibScale is 0 because char columns don't have a scale */
  59.  
  60.     SQLSetParam(hstmt, 1, SQL_C_CHAR, SQL_CHAR, 4, 0, NULL, &cbValue);
  61.  
  62.       /* Note that for the next two parameters, fSqlType is SQL_VARCHAR */
  63.  
  64.     SQLSetParam(hstmt, 2, SQL_C_CHAR, SQL_VARCHAR, 40, 0, NULL, &cbValue);
  65.     SQLSetParam(hstmt, 3, SQL_C_CHAR, SQL_VARCHAR, 20, 0, NULL, &cbValue);
  66.  
  67.       /* This is not a SQL_DATA_AT_EXEC parameter - ie, SQLPutData is not
  68.      used. pcbValue is NULL, saying that rgbValue is a NULL teminated
  69.      string. */
  70.  
  71.     SQLSetParam(hstmt, 4, SQL_C_CHAR, SQL_CHAR, 2, 0, "WA", NULL);
  72.  
  73.     retcode = SQLExecute(hstmt);
  74.  
  75.       /* SQLExecute returns SQL_NEED_DATA because parameters 1, 2, 3
  76.      are SQL_DATA_AT_EXEC. */
  77.  
  78.     if (retcode == SQL_NEED_DATA){
  79.  
  80.       /* Call SQLParamData to begin SQL_AT_EXEC parameter processing.
  81.          pToken contains the application dependent *rgbValue - which
  82.          is NULL in this case. */
  83.  
  84.         retcode = SQLParamData(hstmt, &pToken);
  85.  
  86.         while (retcode == SQL_NEED_DATA) {
  87.          cParam++;
  88.          switch (cParam) {
  89.  
  90.             /* Parameters 1 and 3 are sent in one shot. Parameter 2
  91.                is sent in two calls to SQLPutData. This is how a
  92.                long value would be sent. In this example, none of the
  93.                are long values and SQLPutData is used purely for
  94.                illustration purposes. */
  95.  
  96.                case 1: retcode = SQLPutData(hstmt, "1622", SQL_NTS);
  97.                     break;
  98.  
  99.                case 2: retcode = SQLPutData(hstmt, "Mc Graw ", SQL_NTS);
  100.                    retcode = SQLPutData(hstmt, "Hill", SQL_NTS);
  101.                    break;
  102.                case 3: retcode = SQLPutData(hstmt, "Seattle", SQL_NTS);
  103.                    break;
  104.  
  105.  
  106.          }     // switch
  107.  
  108.           /* Call SQLParamData to indicate that the processing of this
  109.          SQL_AT_EXEC parameter is over and to signal the beginning
  110.          of the next SQL_AT_EXEC parameter, if any. If all the
  111.          SQL_AT_EXEC parameters have been processed, SQLParamData
  112.          returns  SQL_SUCCESS. */
  113.  
  114.          retcode = SQLParamData(hstmt, &pToken);
  115.  
  116.         }    //  while
  117.     }   // inner if
  118.  
  119.    }   // outer if
  120.  
  121. }
  122.