CData ODBC Driver for Amazon Marketplace 2019 - Online Help
Questions / Feedback?

Executing Stored Procedures

CData ODBC Driver for Amazon Marketplace 2019 - Build 19.0.7354

Procedure for Calling Stored Procedures

Use SQLExecDirect to call a stored procedure and SQLFetch and SQLGetData to iterate through its results. The following example shows the CALL syntax; you can also use the EXECUTE syntax, detailed in EXECUTE Statements.

Example


  SQLHENV henv;
  SQLHDBC hdbc;
  SQLLEN cbObjectName = SQL_NTS;
  if (SQLAllocHandle(SQL_HANDLE_ENV, 0 ,&henv) == SQL_SUCCESS) {
    SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
    if (SQLAllocHandle(SQL_HANDLE_DBC, henv ,&hdbc) == SQL_SUCCESS) {
      if (SQLConnect(hdbc, "CData AmazonMarketplace Source", SQL_NTS, 0, 0, 0, 0) == SQL_SUCCESS) {
        SQLHSTMT hstmt;
        SQLAllocHandle(SQL_HANDLE_STMT, hdbc ,&hstmt); 
        if (SQLExecDirect(hstmt, (SQLCHAR*)"{?=call CreateJob('Account', 'Insert')}", SQL_NTS) == SQL_SUCCESS) {
        if (SQLExecDirect(hstmt, "{?=call SampleProcedure('7')}", SQL_NTS) == SQL_SUCCESS) {
          char sCreatedById[255] = {0};
          SQLLEN cbsCreatedById = 0;
          while(SQLFetch(hstmt) == SQL_SUCCESS) {
            SQLGetData(hstmt, 2, SQL_C_CHAR, (SQLPOINTER)sCreatedById, 255, &cbsCreatedById);
            printf("CreatedById: %s\n", sCreatedById);
          }
        }
        SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
        SQLDisconnect(hdbc);
      }
      SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
    }
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
  }

 
 
Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 19.0.7354.0