ODBC – SQLBindCol Function – Using Microsoft’s sample code

Background

Reading more on ODBC via C.

Microsoft Sample

Web Site

Tried out Microsoft’s sample; available here.

Docs / SQL ODBC / ODBC Advanced / Microsoft Open Database Connectivity (ODBC)/  ODBC Programmer’s Reference / API Reference / ODBC API Reference / SQLBindCol Function

SQLBindCol Function
Link

Compile

Tried compiling the code.

Output

Image

compile.original.01.2020101.1024PM.PNG

 

Text

(55): error C2065: 'i': undeclared identifier
(60): error C2065: 'i': undeclared identifier
(60): warning C4477: 'wprintf' : format string '%S' requires an argument of type 'char *', but variadic argument 2 has type 'SQLWCHAR *'
(60): note: consider using '%lS' in the format string
(60): note: consider using '%llS' in the format string
(60): note: consider using '%LS' in the format string
(60): note: consider using '%wS' in the format string
(60): warning C4477: 'wprintf' : format string '%S' requires an argument of type 'char *', but variadic argument 3 has type 'SQLWCHAR *'
(60): note: consider using '%lS' in the format string
(60): note: consider using '%llS' in the format string
(60): note: consider using '%LS' in the format string
(60): note: consider using '%wS' in the format string
(60): warning C4477: 'wprintf' : format string '%S' requires an argument of type 'char *', but variadic argument 4 has type 'SQLWCHAR *'
(60): note: consider using '%lS' in the format string
(60): note: consider using '%llS' in the format string
(60): note: consider using '%LS' in the format string
(60): note: consider using '%wS' in the format string<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>

 

Revision

Outline

  1. error C2065: undeclared identifier
    • Changes
      • The counter variable (i) is undefined
    • Sample
      • Original
        • // Fetch and print each row of data. On an error, display a message and exit.
          for (i ; ; i++) {
      • Revision
        • for (int i=0; ; i++)
  2. warning C4477: ‘wprintf’ : format string ‘%S’ requires an argument of type ‘char *’, but variadic argument 2 has type ‘SQLWCHAR *’
    • Changes
      • Replace wprintf with printf
      • Replace %S with %ls
    •  Sample
      • Original
        • wprintf(L”%d: %S %S %S\n”, i + 1, sCustID, szName, szPhone);
      • Revised
        • printf(L”%d: %ls %ls %ls\n”, i + 1, sCustID, szName, szPhone);

 

Source Code

GitHub

  1. Repository
    • DanielAdeniji/ODBCCodeSample
      Link
    • Files
      • Vendor
        • northwind.SQLBindCol_ref.vendor.c
          Link
      • Revisions
        • northwind.SQLBindCol_ref.vendor.revised.c
          Slight Revision
          Link
        • northwind.SQLBindCol_ref.c
          Multiple Revision
          Link

Dedicating

Dedicating to Microsoft and the ODBC Standard.

Later came JDBC and all that other jazz.

 

One thought on “ODBC – SQLBindCol Function – Using Microsoft’s sample code

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s