List:Commits« Previous MessageNext Message »
From:pharvey Date:July 18 2006 10:42pm
Subject:Connector/ODBC 5 commit: r449 - trunk/examples/CPP/7/ADO
View as plain text  
Modified:
   trunk/examples/CPP/7/ADO/main.cpp
Log:


Modified: trunk/examples/CPP/7/ADO/main.cpp
===================================================================
--- trunk/examples/CPP/7/ADO/main.cpp	2006-07-18 16:13:32 UTC (rev 448)
+++ trunk/examples/CPP/7/ADO/main.cpp	2006-07-18 22:42:12 UTC (rev 449)
@@ -57,6 +57,103 @@
     printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
 }
 
+bool doPrintRecordset( _RecordsetPtr pRecordset )
+{
+    /* field names */
+    for ( long nField = 0; nField < pRecordset->Fields->Count; nField++ )
+    {
+        if ( !nField )
+            printf( "|" );
+        printf( "%s %d |", (LPCSTR)(pRecordset->Fields->GetItem( nField
)->Name), pRecordset->Fields->Item[nField]->Type );
+    }
+    printf( "\n" );
+
+    /* rows */
+    while ( !(pRecordset->EndOfFile) )
+    {
+        for ( long nField = 0; nField < pRecordset->Fields->Count; nField++ )
+        {
+            if ( !nField )
+                printf( "|" );
+            switch ( pRecordset->Fields->Item[nField]->Value.vt )
+            {
+                case VT_EMPTY:
+                case VT_NULL:
+                case VT_I2:
+                    printf( "! %d |", pRecordset->Fields->Item[nField]->Value.vt
);
+                    break;
+                case VT_I4:
+                    printf( "%ld |",
pRecordset->Fields->Item[nField]->Value.lVal );
+                    break;
+                case VT_R4:
+                case VT_R8:
+                case VT_CY:
+                    printf( "! %d |", pRecordset->Fields->Item[nField]->Value.vt
);
+                    break;
+                case VT_DATE:
+                    printf( "%f |", pRecordset->Fields->Item[nField]->Value.date
);
+                    break;
+                case VT_BSTR:
+                case VT_DISPATCH:
+                case VT_ERROR:
+                case VT_BOOL:
+                case VT_VARIANT:
+                case VT_UNKNOWN:
+                case VT_DECIMAL:
+                case VT_I1:
+                case VT_UI1:
+                case VT_UI2:
+                case VT_UI4:
+                case VT_I8:
+                case VT_UI8:
+                case VT_INT:
+                case VT_UINT:
+                case VT_VOID:
+                case VT_HRESULT:
+                case VT_PTR:
+                case VT_SAFEARRAY:
+                case VT_CARRAY:
+                case VT_USERDEFINED:
+                case VT_LPSTR:
+                case VT_LPWSTR:
+                case VT_RECORD:
+                case VT_INT_PTR:
+                case VT_UINT_PTR:
+                case VT_FILETIME:
+                case VT_BLOB:
+                case VT_STREAM:
+                case VT_STORAGE:
+                case VT_STREAMED_OBJECT:
+                case VT_STORED_OBJECT:
+                case VT_BLOB_OBJECT:
+                case VT_CF:
+                case VT_CLSID:
+                case VT_VERSIONED_STREAM:
+                    printf( "! %d |", pRecordset->Fields->Item[nField]->Value.vt
);
+                    break;
+/*
+                case VT_BSTR_BLOB:
+                case VT_VECTOR:
+                case VT_ARRAY:
+                case VT_BYREF:
+                case VT_RESERVED:
+                case VT_ILLEGAL:
+                case VT_ILLEGALMASKED:
+                case VT_TYPEMASK:
+*/
+                default:
+                    printf( "! %d |", pRecordset->Fields->Item[nField]->Value.vt
);
+                    break;
+            }
+        }
+        printf( "\n" );
+
+        pRecordset->MoveNext(); 
+    }
+
+    return true;
+}
+
 bool doConnect()
 {
     try
@@ -77,13 +174,27 @@
 
 bool doSelect()
 {
-    _CommandPtr pCommand = NULL;
+    _CommandPtr     pCommand            = NULL;
+    _ParameterPtr   pParameter          = NULL;
+    _RecordsetPtr   pRecordset          = NULL;  
+    VARIANT         variantEmployeeID;
 
     try
     {
         TESTHR( pCommand.CreateInstance( __uuidof( Command ) ) );
-        pCommand->CommandText = "SELECT * FROM orders WHERE EmployeeID = ?";
-        pCommand->CommandType = adCmdTable;
+        pCommand->CommandText = "SELECT EmployeeID, OrderID, OrderDate FROM orders
WHERE EmployeeID = ? ORDER BY OrderDate";
+        pCommand->CommandType = adCmdText;
+
+        variantEmployeeID.vt    = VT_I2;
+        variantEmployeeID.iVal  = 4;
+        pParameter = pCommand->CreateParameter( "EmployeeID", adInteger, adParamInput,
sizeof(int), variantEmployeeID );
+        pCommand->Parameters->Append( pParameter );
+        pParameter->Value  = variantEmployeeID;
+
+        pCommand->ActiveConnection = pConnection;
+        pRecordset = pCommand->Execute( NULL, NULL, adCmdText ); 
+
+        doPrintRecordset( pRecordset );
     }
     catch ( _com_error &e )
     {

Thread
Connector/ODBC 5 commit: r449 - trunk/examples/CPP/7/ADOpharvey19 Jul