List:Commits« Previous MessageNext Message »
From:pharvey Date:October 23 2006 9:05am
Subject:Connector/ODBC 5 commit: r626 - trunk/Driver/examples/c
View as plain text  
Modified:
   trunk/Driver/examples/c/tutorial_07.c
   trunk/Driver/examples/c/tutorial_08.c
Log:
ENH: Added some doc


Modified: trunk/Driver/examples/c/tutorial_07.c
===================================================================
--- trunk/Driver/examples/c/tutorial_07.c	2006-10-23 04:47:27 UTC (rev 625)
+++ trunk/Driver/examples/c/tutorial_07.c	2006-10-23 07:05:51 UTC (rev 626)
@@ -18,7 +18,6 @@
     SQLCHAR *   pszCommand = "INSERT INTO Tutorial ( nID, vcData ) " /
                              "VALUES ( 1, \"data 1\" )             ";
     SQLSMALLINT nColumns        = 0;
-    SQLINTEGER  nRowsAffected   = 0;
 
     /* init */
     nReturn = SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0 );
@@ -32,19 +31,16 @@
     /* we have some form of result */
 
     /* 
-        Get number of columns. A result may have a result-set (have data and there fore
have columns) or may be just row count/affected rows.
-        This makes checking for 0 columns a good way to see if there is a result-set to
process.
+        Get number of columns. 
+        A result may have a result-set (have columns) or may be just number of affected
rows.
+        Checking for 0 columns a good way to see if there is a result-set to process.
+        Most applications will know what type of result to expect based upon the command
they send to the data source.
     */
     nReturn = SQLNumResultCols( hStm, &nColumns );
     if ( nColumns > 0 )
-    {
-        /* we have a result-set */
-    }
+        ; /* We have a result-set (may or may not have data). */
     else
-    {
-        /* no result-set - we can check for affect rows (should be 1 in this case) */
-        nReturn = SQLRowCount( hStm, nRowsAffected );
-    }
+        ; /* Result is just number of affected rows (should be 1 in this case). */
 
 exit1:
     /* fini */

Modified: trunk/Driver/examples/c/tutorial_08.c
===================================================================
--- trunk/Driver/examples/c/tutorial_08.c	2006-10-23 04:47:27 UTC (rev 625)
+++ trunk/Driver/examples/c/tutorial_08.c	2006-10-23 07:05:51 UTC (rev 626)
@@ -17,7 +17,9 @@
     SQLCHAR *   pszPWD     = argv[3];
     SQLCHAR *   pszCommand = "SELECT * " /
                              "FROM   Tutorial";
-    SQLSMALLINT nColumns   = 0;
+    SQLSMALLINT nColumns        = 0;
+    SQLINTEGER  nAffectedRows   = -1;
+    SQLINTEGER  nResultSetRows  = -1;
 
     /* init */
     nReturn = SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION, SQL_OV_ODBC3, 0 );
@@ -28,21 +30,23 @@
     if ( !SQL_SUCCEEDED( nReturn ) )
         goto exit1;
 
-    /* we have some form of result */
+    nReturn = SQLGetDiagField( SQL_HANDLE_STMT, hStmt, 0, SQL_DIAG_CURSOR_ROW_COUNT,
&nResultSetRows, 0, 0 );
+    nReturn = SQLRowCount( hStm, &nAffectedRows );
 
-    /* 
-        Get number of columns. A result may have a result-set (have data and there fore
have columns) or may be just row count/affected rows.
-        This makes checking for 0 columns a good way to see if there is a result-set to
process.
-    */
     nReturn = SQLNumResultCols( hStm, &nColumns );
     if ( nColumns > 0 )
     {
-        /* we have a result-set */
+        /* We have a result-set (may or may not have data).             */
+        /* Driver returns -1 if it can not determine row count.         */
+        /* Some drivers allow SQLRowCount to be use here - but not all. */
+        if ( nAffectedRows >= 0 )
+            printf( "%ld result-set rows\n", nAffectedRows );
+        else
+            printf( "%ld result-set rows\n", nResultSetRows );
     }
     else
-    {
-        /* no result-set - we can check for affect rows (should be 1 in this case) */
-    }
+        /* Result is just number of affected rows. */
+        printf( "%ld rows affected\n", nAffectedRows );
 
 exit1:
     /* fini */

Thread
Connector/ODBC 5 commit: r626 - trunk/Driver/examples/cpharvey23 Oct