ODBC Driver for Azure DevOps

Build 24.0.9060

Batch Processing

The CData ODBC Driver for Azure DevOps offers bulk load support in Azure DevOps through the ODBC Batch API. The driver can execute related SQL data manipulation statements simultaneously by translating them into a single bulk API request. In your application's code, the driver executes statements based on an array of inputs and a parameterized query.

Batch Update Procedure

Complete the following steps to execute a batch update:

  1. Define arrays of column values for each parameter in the statement.
  2. Set the SQL_ATTR_PARAMSET_SIZE statement attribute.
  3. Bind each array to each parameter.
  4. Execute the parameterized statement.

Bulk Insert

The following code shows how to execute a bulk insert with SQLSetStmtAttr, SQLBindParameter, and SQLExecDirect:

SQLHSTMT pHstmt = NULL;
const int MAX_INSERT_COUNT = 2;
const int MAX_BUFFER_SIZE = 100;
char BuildNumberArray[MAX_INSERT_COUNT][MAX_BUFFER_SIZE] = { 0 };
SQLLEN cbBuildNumberArray[MAX_INSERT_COUNT] = { 0 };
...
retcode = SQLSetStmtAttr(pHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)MAX_INSERT_COUNT, 0);
char *BuildNumber1 = "Jon Doe", *BuildNumber2 = "John";
cbBuildNumberArray[0] = strlen(BuildNumber1);
cbBuildNumberArray[1] = strlen(BuildNumber2);
memcpy(BuildNumberArray[0], BuildNumber1, strlen(BuildNumber1));
memcpy(BuildNumberArray[1], BuildNumber2, strlen(BuildNumber2));
retcode = SQLBindParameter(pHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, BuildNumberArray, MAX_BUFFER_SIZE, cbBuildNumberArray);

retcode = SQLExecDirect(pHstmt, (SQLCHAR*) "INSERT INTO WorkItems (BuildNumber) VALUES (?)", SQL_NTS); 

Bulk Update

An array of the primary keys of the records to update must be specified. The following code shows how to execute a bulk update with SQLSetStmtAttr, SQLBindParameter, and SQLExecDirect:

SQLHSTMT pHstmt = NULL;
const int MAX_UPDATE_COUNT = 2;
const int MAX_BUFFER_SIZE = 100;
char IdArray[MAX_UPDATE_COUNT][MAX_BUFFER_SIZE] = { 0 };
char IdArray[MAX_UPDATE_COUNT][MAX_BUFFER_SIZE] = { 0 };
SQLLEN cbIdArray[MAX_UPDATE_COUNT] = { 0 };
SQLLEN cbIdArray[MAX_UPDATE_COUNT] = { 0 };
...
retcode = SQLSetStmtAttr(pHstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)MAX_UPDATE_COUNT, 0);
char *BuildNumber1 = "Jon Doe", *BuildNumber2 = "John";
char *Id1 = "Id1", *Id2 = "Id2";
cbBuildNumberArray[0] = strlen(BuildNumber1);
cbBuildNumberArray[1] = strlen(BuildNumber2);
cbIdArray[0] = strlen(Id1);
cbIdArray[1] = strlen(Id2);
memcpy(BuildNumberArray[0], BuildNumber1, strlen(BuildNumber1));
memcpy(BuildNumberArray[1], BuildNumber2, strlen(BuildNumber2));
memcpy(IdArray[0], Id1, strlen(Id1));
memcpy(IdArray[1], Id2, strlen(Id2));
retcode = SQLBindParameter(pHstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, BuildNumberArray, MAX_BUFFER_SIZE, cbBuildNumberArray);
retcode = SQLBindParameter(pHstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 0, 0, IdArray, MAX_BUFFER_SIZE, cbIdArray);

retcode = SQLExecDirect(pHstmt, (SQLCHAR*) "UPDATE WorkItems SET BuildNumber = ? WHERE Id = ?", SQL_NTS); 

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060