ODBC Driver for Streak

Build 22.0.8462

Querying Data

After Connecting, you can allocate a statement handle and execute the statement.

SELECT Procedure

Use SQLExecDirect to execute the statement and SQLFetch to fetch the records. You can use SQLBindCol to bind variables to columns in the result set. The numbering of the result set columns starts at 1.

SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); 
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
SQLDriverConnect(hdbc, 0, (SQLCHAR*)"Dsn=CData Streak Source", SQL_NTS, 0, 0, 0, 0);
SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
SQLExecDirect(hstmt, (SQLCHAR*)"SELECT Email FROM Users WHERE UserKey = 'agxzfm1haWxmb29nYWVyLAsSDE9yZ2FuaXphdGlvbiIJY2RhdGEuY29tDAsSBFVzZXIYgICs35ruuwkM'", SQL_NTS);  
SQLCHAR sEmail[20] = {0};
SQLLEN cbEmail = 0;
SQLBindCol(hstmt, 1, SQL_C_CHAR, sEmail, 20, &cbEmail);
SQLRETURN retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
 ...
}

Iterating over the Results

You can use SQLGetData to get values while iterating through a cursor. To iterate over the results, use SQLFetch to fetch rows and SQLGetData to retrieve the column values.

  SQLHENV henv;
  SQLHDBC hdbc;
  SQLHSTMT hstmt;
  char sUserKey[255] = {0};
  SQLLEN cbId = 0;
  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 Streak Source", SQL_NTS, 0, 0, 0, 0) == SQL_SUCCESS) {
        if (SQLAllocHandle(SQL_HANDLE_STMT, hdbc ,&hstmt) == SQL_SUCCESS) {
          if (SQLExecDirect(hstmt, "SELECT UserKey FROM Users WHERE UserKey = 'agxzfm1haWxmb29nYWVyLAsSDE9yZ2FuaXphdGlvbiIJY2RhdGEuY29tDAsSBFVzZXIYgICs35ruuwkM'", SQL_NTS) == SQL_SUCCESS) {
            while(SQLFetch(hstmt) == SQL_SUCCESS) {
              if (SQLGetData(hstmt, 1, SQL_C_CHAR, (SQLPOINTER)sUserKey, 255, &cbId) == SQL_SUCCESS) {
                printf("UserKey: %s\n", sUserKey);
              }
            }
          }
          SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
        }
        SQLDisconnect(hdbc);
      }
      SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
    }
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
  }

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462