void DisplayResults(HSTMT lpStmt, SQLSMALLINT cCols) { BINDING *pFirstBinding, *pThisBinding; SQLSMALLINT siDisplaySize; RETCODE RetCode; int iCount = 0; // Allocate memory for each column AllocateBindings(lpStmt, cCols, &pFirstBinding, &siDisplaySize); // Set the display mode and write the titles DisplayTitles(lpStmt, siDisplaySize, pFirstBinding); // Fetch and display the data do { // Fetch a row if (iCount++ >= gHeight - 2) { char szInput[100]; printf(" "); SetConsole(siDisplaySize + 2, TRUE); printf(" Press ENTER to continue, Q to quit"); printf("%d", gHeight); SetConsole(siDisplaySize + 2, FALSE); gets(szInput); if ((*szInput == 'Q') || (*szInput == 'q')) goto Exit; iCount = 1; DisplayTitles(lpStmt, siDisplaySize, pFirstBinding); } TRYODBC(lpStmt, SQL_HANDLE_STMT, RetCode = SQLFetch(lpStmt)); if (RetCode == SQL_NO_DATA_FOUND) break; if (RetCode == SQL_NO_DATA) break; // Display the data. Ignore truncations for (pThisBinding = pFirstBinding; pThisBinding; pThisBinding = pThisBinding->sNext) { if (pThisBinding->indPtr != SQL_NULL_DATA) { _tprintf(pThisBinding->fChar ? TEXT(DISPLAY_FORMAT_C) : TEXT(DISPLAY_FORMAT), PIPE, pThisBinding->siDisplaySize, pThisBinding->siDisplaySize, pThisBinding->szBuffer); } else { _tprintf(TEXT(DISPLAY_FORMAT_C), PIPE, pThisBinding->siDisplaySize, pThisBinding->siDisplaySize, "<NULL>"); } } _tprintf(TEXT(" %c\n"), PIPE); } while ( 1); SetConsole(siDisplaySize + 2, TRUE); printf("%*.*s", siDisplaySize + 2, siDisplaySize + 2, " "); SetConsole(siDisplaySize + 2, FALSE); printf("\n"); Exit: // Clean up the allocated buffers while (pFirstBinding) { pThisBinding = pFirstBinding->sNext; free(pFirstBinding->szBuffer); free(pFirstBinding); pFirstBinding = pThisBinding; } }
void DisplayResults(HSTMT hStmt, SQLSMALLINT cCols) { BINDING *pFirstBinding, *pThisBinding; SQLSMALLINT cDisplaySize; RETCODE RetCode = SQL_SUCCESS; int iCount = 0; // Allocate memory for each column AllocateBindings(hStmt, cCols, &pFirstBinding, &cDisplaySize); // Set the display mode and write the titles DisplayTitles(hStmt, cDisplaySize+1, pFirstBinding); // Fetch and display the data bool fNoData = false; do { // Fetch a row if (iCount++ >= gHeight - 2) { int nInputChar; bool fEnterReceived = false; while(!fEnterReceived) { wprintf(L" "); SetConsole(cDisplaySize+2, TRUE); wprintf(L" Press ENTER to continue, Q to quit (height:%hd)", gHeight); SetConsole(cDisplaySize+2, FALSE); nInputChar = _getch(); wprintf(L"\n"); if ((nInputChar == 'Q') || (nInputChar == 'q')) { goto Exit; } else if ('\r' == nInputChar) { fEnterReceived = true; } // else loop back to display prompt again } iCount = 1; DisplayTitles(hStmt, cDisplaySize+1, pFirstBinding); } TRYODBC(hStmt, SQL_HANDLE_STMT, RetCode = SQLFetch(hStmt)); if (RetCode == SQL_NO_DATA_FOUND) { fNoData = true; } else { // Display the data. Ignore truncations for (pThisBinding = pFirstBinding; pThisBinding; pThisBinding = pThisBinding->sNext) { if (pThisBinding->indPtr != SQL_NULL_DATA) { wprintf(pThisBinding->fChar ? DISPLAY_FORMAT_C:DISPLAY_FORMAT, PIPE, pThisBinding->cDisplaySize, pThisBinding->cDisplaySize, pThisBinding->wszBuffer); } else { wprintf(DISPLAY_FORMAT_C, PIPE, pThisBinding->cDisplaySize, pThisBinding->cDisplaySize, L"<NULL>"); } } wprintf(L" %c\n",PIPE); } } while (!fNoData); SetConsole(cDisplaySize+2, TRUE); wprintf(L"%*.*s", cDisplaySize+2, cDisplaySize+2, L" "); SetConsole(cDisplaySize+2, FALSE); wprintf(L"\n"); Exit: // Clean up the allocated buffers while (pFirstBinding) { pThisBinding = pFirstBinding->sNext; free(pFirstBinding->wszBuffer); free(pFirstBinding); pFirstBinding = pThisBinding; } }