[fdo-commits] r2610 - in trunk: Providers/GenericRdbms/Src/Fdo/FeatureCommands Providers/GenericRdbms/Src/Gdbi Providers/GenericRdbms/Src/ODBC/Fdo Providers/GenericRdbms/Src/UnitTest/Common Providers/GenericRdbms/Src/UnitTest/Odbc Utilities/Common Utilities/Common/Inc

svn_fdo at osgeo.org svn_fdo at osgeo.org
Fri Feb 23 12:39:55 EST 2007


Author: romicadascalescu
Date: 2007-02-23 12:39:54 -0500 (Fri, 23 Feb 2007)
New Revision: 2610

Added:
   trunk/Utilities/Common/Inc/FdoCommonExpressionExecutor.h
Modified:
   trunk/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp
   trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
   trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp
   trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h
   trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
   trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
   trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp
   trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp
   trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h
   trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h
   trunk/Utilities/Common/FdoCommon.vcproj
Log:
Ticket #20 Generic RDBMS: fix various SelectAggregates defects

Modified: trunk/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -29,8 +29,10 @@
 #include "FdoRdbmsFeatureSubsetReader.h"
 #include "LockUtility.h"
 #include "FdoRdbmsFilterProcessor.h"
+#include <FdoCommonFilterExecutor.h>
+#include <FdoCommonSchemaUtil.h>
+#include <FdoCommonExpressionExecutor.h>
 
-
 #define SELECT_CLEANUP \
         if ( qid != -1) {\
         try { \
@@ -92,7 +94,7 @@
         throw FdoCommandException::Create(NlsMsgGet(FDORDBMS_13, "Connection not established"));
     try
     {
-        FdoPtr<FdoRdbmsFilterProcessor>flterProcessor = FdoPtr<FdoRdbmsConnection>((FdoRdbmsConnection*)GetConnection())->GetFilterProcessor();
+        FdoPtr<FdoRdbmsFilterProcessor>flterProcessor = mFdoConnection->GetFilterProcessor();
 
         FdoRdbmsFilterUtilConstrainDef filterConstrain;
         filterConstrain.distinct = distinct;
@@ -101,6 +103,14 @@
         filterConstrain.groupByProperties = mGroupingCol;
         filterConstrain.orderByProperties = mOrderingIdentifiers;
 
+		// Validate the filter
+		if ( this->GetFilterRef() != NULL )
+		{
+			FdoPtr<FdoIFilterCapabilities> filterCaps = mFdoConnection->GetFilterCapabilities();
+	
+			FdoCommonFilterExecutor::ValidateFilter( NULL, this->GetFilterRef(), NULL, filterCaps);
+		}
+
         // Call FilterToSql just to populate the filter's list of geometric conditions;
         FdoString * sqlString = flterProcessor->FilterToSql( this->GetFilterRef(),
                                                              this->GetClassNameRef()->GetText(),
@@ -151,6 +161,14 @@
                                                              callerId );
                 }
             }
+            if (callerId == FdoCommandType_SelectAggregates)
+            {
+                FdoSchemaManagerP pschemaManager = mConnection->GetSchemaUtil()->GetSchemaManager();
+                FdoPtr<FdoFeatureSchemaCollection> schemas = pschemaManager->GetFdoSchemas(L"");
+                FdoPtr<FdoCommonExpressionExecutor> expVer = FdoCommonExpressionExecutor::Create(schemas, GetClassNameRef());
+                FdoPtr<FdoIExpressionCapabilities> expCap = mFdoConnection->GetExpressionCapabilities();
+                expVer->ValidateIdentifiers(mIdentifiers, expCap);
+            }
         }
 
         GdbiQueryResult *queryRslt = mConnection->GetGdbiConnection()->ExecuteQuery( sqlString );

Modified: trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -370,7 +370,11 @@
 					address[1] = '\0';
 			}
 			else
-				memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, size); 
+            {
+				memcpy(address, (char*)(colInfo->value) + mArrayPos*colInfo->size, size);
+                if (size < length) // ensure we don't get garbage at the end...
+                    address[size] = '\0';
+            }
 			
             if (size < colInfo->size)
             {

Modified: trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -187,6 +187,7 @@
     FdoRdbmsFilterUtilConstrainDef *inFilterConstrain,
     bool forUpdate,
     FdoInt16 callerId )
+
 {
     const wchar_t * ret = NULL;
 
@@ -229,3 +230,45 @@
     return ret;
 }
 
+void FdoRdbmsOdbcFilterProcessor::ProcessFunction(FdoFunction& expr)
+{
+    unsigned long  dbVersion = mFdoConnection->GetDbiConnection()->GetDbVersion();
+    
+    if(dbVersion == RDBI_DBVERSION_ODBC_SQLSERVER || dbVersion == RDBI_DBVERSION_ODBC_ACCESS)
+    {
+        // SQL Server doesn't have a native 'CONCAT' method; instead, use the '+' string concatenation operator:
+        if (0==FdoCommonOSUtil::wcsicmp(expr.GetName(), L"CONCAT"))
+        {
+            AppendString(OPEN_PARENTH);
+            FdoPtr<FdoExpressionCollection> exprCol = expr.GetArguments();
+            for(int i=0; i<exprCol->GetCount(); i++ )
+            {
+                if( i!= 0 )
+                    AppendString( ARITHMETIC_PLUS );
+
+                FdoPtr<FdoExpression>exp = exprCol->GetItem( i );
+                HandleExpr( exp );
+            }
+            AppendString( CLOSE_PARENTH );
+            return;
+        }
+    }
+    FdoRdbmsFilterProcessor::ProcessFunction(expr);
+}
+
+void FdoRdbmsOdbcFilterProcessor::ProcessFunctionName(FdoFunction& expr)
+{
+    unsigned long  dbVersion = mFdoConnection->GetDbiConnection()->GetDbVersion();
+    
+    if(dbVersion == RDBI_DBVERSION_ODBC_SQLSERVER)
+    {
+        // Map 'well-known FDO function names' to SQL Server-specific function names, when they differ:
+        FdoString* sFunctionName = expr.GetName();
+        if (0==FdoCommonOSUtil::wcsicmp(sFunctionName, L"CEIL"))
+        {
+            AppendString(L"CEILING");
+            return;
+        }
+    }
+    FdoRdbmsFilterProcessor::ProcessFunctionName(expr);
+}

Modified: trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h	2007-02-23 17:39:54 UTC (rev 2610)
@@ -47,4 +47,8 @@
     virtual bool IsAggregateFunctionName(FdoString* wFunctionName) const;
 
     virtual void ProcessDateTimeValue(FdoDateTimeValue& expr);
+    
+    virtual void ProcessFunction(FdoFunction& expr);
+
+    virtual void ProcessFunctionName(FdoFunction& expr);
 };

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -893,7 +893,7 @@
     {
         selCmdAggreg = (FdoISelectAggregates*)mConnection->CreateCommand( FdoCommandType_SelectAggregates );
         selCmdAggreg->SetFeatureClassName(L"Acad:AcDb3dPolyline");
-        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(L"(ceil(segcount)) AS TestFunc");
+        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(L"(ceil(segcount/1.0)) AS TestFunc");
         FdoPtr<FdoIdentifierCollection>idCol = selCmdAggreg->GetPropertyNames();
         idCol->Add( cmpId );
         myDataReader = selCmdAggreg->Execute();
@@ -1005,7 +1005,7 @@
         printf(">>> ... Executing the select aggregate command \n");
 
         selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
-        selAggr->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+        selAggr->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
         FdoFilter *aFilter = FdoComparisonCondition::Create(
                                 FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
                                 FdoComparisonOperations_EqualTo, 
@@ -1054,11 +1054,9 @@
 
     catch( FdoException *ex )
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
         printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
     }
 }
 
@@ -1090,7 +1088,7 @@
         printf(">>> ... Executing the select aggregate command \n");
 
         selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
-        selAggr->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+        selAggr->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
         FdoFilter *aFilter = FdoComparisonCondition::Create(
                                 FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
                                 FdoComparisonOperations_EqualTo, 
@@ -1102,7 +1100,7 @@
             FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
                                       L"MyConcatString",
                                       FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Concat(layer, color)")))));
+                                            FdoExpression::Parse(L"CONCAT(layer, color)")))));
 
         rdr = selAggr->Execute();
         count = 0;
@@ -1139,11 +1137,9 @@
 
     catch( FdoException *ex )
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
         printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
     }
 }
 
@@ -1172,7 +1168,7 @@
         printf(">>> ... Executing the select aggregate command \n");
 
         selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
-        selCmd->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+        selCmd->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
         ids = selCmd->GetPropertyNames();
         ids->Clear();
         ids->Add(
@@ -1223,11 +1219,9 @@
 
     catch( FdoException *ex )
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
         printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
     }
 }
 
@@ -1259,7 +1253,7 @@
         printf(">>> ... Executing the select command \n");
 
         selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
-        selCmd->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+        selCmd->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
         FdoFilter *aFilter = FdoComparisonCondition::Create(
                                 FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
                                 FdoComparisonOperations_EqualTo, 
@@ -1271,7 +1265,7 @@
             FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
                                       L"MyConcatString",
                                       FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Concat(layer, color)")))));
+                                            FdoExpression::Parse(L"CONCAT(layer, color)")))));
 
         rdr = selCmd->Execute();
         count = 0;
@@ -1307,10 +1301,127 @@
 
     catch( FdoException *ex )
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
         printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
     }
 }
+
+void FdoAdvancedSelectTest::TestMaxBoolProperty()
+{
+	FdoPtr<FdoIDataReader>myDataReader;
+	FdoPtr<FdoISelectAggregates>selCmdAggreg;
+     try
+    {
+        selCmdAggreg = (FdoISelectAggregates*)mConnection->CreateCommand( FdoCommandType_SelectAggregates );
+        selCmdAggreg->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
+        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(L"(Max(boolean)) AS testFld");
+        FdoPtr<FdoIdentifierCollection>idCol = selCmdAggreg->GetPropertyNames();
+        idCol->Add( cmpId );
+        try
+        {
+            myDataReader = selCmdAggreg->Execute();
+            TestCommonFail(FdoException::Create(L"TestUpperDateProperty should fail!"));
+        }
+        catch( FdoException *ex )
+        {
+            printf("Expected error: %ls\n", ex->GetExceptionMessage());
+            ex->Release();
+        }
+    }
+    catch( FdoException *ex )
+    {
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
+    }
+}
+
+void FdoAdvancedSelectTest::TestUpperDateProperty()
+{
+	FdoPtr<FdoIDataReader>myDataReader;
+	FdoPtr<FdoISelectAggregates>selCmdAggreg;
+    try
+    {
+        selCmdAggreg = (FdoISelectAggregates*)mConnection->CreateCommand( FdoCommandType_SelectAggregates );
+        selCmdAggreg->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
+        FdoStringP exec = L"(Upper(";
+        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(exec + GetDateTimePropName()+ L")) AS testFld");
+        FdoPtr<FdoIdentifierCollection>idCol = selCmdAggreg->GetPropertyNames();
+        idCol->Add( cmpId );
+        try
+        {
+            myDataReader = selCmdAggreg->Execute();
+            TestCommonFail(FdoException::Create(L"TestUpperDateProperty should fail!"));
+        }
+        catch( FdoException *ex )
+        {
+            printf("Expected error: %ls\n", ex->GetExceptionMessage());
+            ex->Release();
+        }
+    }
+    catch( FdoException *ex )
+    {
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
+    }
+}
+
+void FdoAdvancedSelectTest::TestCeillInt64Property()
+{
+	FdoPtr<FdoIDataReader>myDataReader;
+	FdoPtr<FdoISelectAggregates>selCmdAggreg;
+    try
+    {
+        selCmdAggreg = (FdoISelectAggregates*)mConnection->CreateCommand( FdoCommandType_SelectAggregates );
+        selCmdAggreg->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
+        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(L"(Ceil(int64)) AS testFld");
+        FdoPtr<FdoIdentifierCollection>idCol = selCmdAggreg->GetPropertyNames();
+        idCol->Add( cmpId );
+        try
+        {
+            myDataReader = selCmdAggreg->Execute();
+            TestCommonFail(FdoException::Create(L"TestUpperDateProperty should fail!"));
+        }
+        catch( FdoException *ex )
+        {
+            printf("Expected error: %ls\n", ex->GetExceptionMessage());
+            ex->Release();
+        }
+    }
+    catch( FdoException *ex )
+    {
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
+    }
+}
+
+void FdoAdvancedSelectTest::TestLowerOnStringProperty()
+{
+	FdoPtr<FdoIDataReader>myDataReader;
+	FdoPtr<FdoISelectAggregates>selCmdAggreg;
+    try
+    {
+        selCmdAggreg = (FdoISelectAggregates*)mConnection->CreateCommand( FdoCommandType_SelectAggregates );
+        selCmdAggreg->SetFeatureClassName(GetSchemaName() + L":" + AcDb3dPolylineName());
+        FdoPtr<FdoComputedIdentifier>cmpId = (FdoComputedIdentifier*)FdoExpression::Parse(L"(Lower(layer)) AS testFld");
+        FdoPtr<FdoIdentifierCollection>idCol = selCmdAggreg->GetPropertyNames();
+        idCol->Add( cmpId );
+        myDataReader = selCmdAggreg->Execute();
+        printf(">>> ... Checking the returned reader \n");
+        while (myDataReader->ReadNext())
+        {
+            if (!myDataReader->IsNull(L"testFld"))
+            {
+                FdoStringP myString = myDataReader->GetString(L"testFld");
+                printf ("String value = %ls\n", (FdoString*)myString);
+            }
+        }
+        myDataReader->Close();
+    }
+    catch( FdoException *ex )
+    {
+        printf("FDO exception: %ls \n", ex->GetExceptionMessage() );
+        TestCommonFail(ex);
+    }
+}
+

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h	2007-02-23 17:39:54 UTC (rev 2610)
@@ -38,6 +38,10 @@
   CPPUNIT_TEST( checkDataReaderContentOnSelAggRequestWithNumCharFunction );
   CPPUNIT_TEST( checkFeatureReaderContentOnSelRequestWithAggrFunction );
   CPPUNIT_TEST( checkFeatureReaderContentOnSelRequestWithNumCharFunction );
+  CPPUNIT_TEST( TestMaxBoolProperty );
+  CPPUNIT_TEST( TestUpperDateProperty );
+  CPPUNIT_TEST( TestCeillInt64Property );
+  CPPUNIT_TEST( TestLowerOnStringProperty );
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -61,7 +65,14 @@
     virtual void checkDataReaderContentOnSelAggRequestWithNumCharFunction();
     virtual void checkFeatureReaderContentOnSelRequestWithAggrFunction();
     virtual void checkFeatureReaderContentOnSelRequestWithNumCharFunction();
+    virtual void TestMaxBoolProperty();
+    virtual void TestUpperDateProperty();
+    virtual void TestCeillInt64Property();
+    virtual void TestLowerOnStringProperty();
 
+    virtual FdoStringP GetSchemaName(){return L"Acad";};
+    virtual FdoStringP AcDb3dPolylineName(){return L"AcDb3dPolyline";};
+    virtual FdoStringP GetDateTimePropName(){return L"datetime";};
 protected:
 	virtual void connect ();
     

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -169,7 +169,7 @@
 	L"",
     L"insert into ACDB3DPOLYLINE (LAYER, COLOR, SEGCOUNT, CLASSID, REVISIONNUMBER, FEATID, DELSTATUS ) values (200, 256, 7, 11, 0, 2, 10);",
 	L"",
-    L"insert into ACDB3DPOLYLINE (LAYER, COLOR, SEGCOUNT, CLASSID, REVISIONNUMBER, FEATID, DELSTATUS ) values (200, 256, 5, 11, 0, 8, 10);",
+    L"insert into ACDB3DPOLYLINE (LAYER, COLOR, SEGCOUNT, CLASSID, REVISIONNUMBER, FEATID, DELSTATUS ) values (200, 256, 10, 11, 0, 8, 10);",
 	L"",
 	NULL
 };
@@ -195,9 +195,9 @@
 	L"PRIMARY KEY (featid)",
 	L") ENGINE=MyISAM;",
     L"",
-    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber, featid ) values (200, 256, 1, 2, 7, 11, 0, 2);",
+    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber, featid ) values ('TestLayer1', '256', 1, 2, 7, 11, 0, 2);",
 	L"",
-    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber, featid ) values (200, 256, 3, 4, 5, 11, 0, 8);",
+    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber, featid ) values ('TestLayer2', '156', 3, 4, 10, 11, 0, 8);",
 	L"",
 	L"create table testClass (",
 	L"age int NOT NULL,",
@@ -214,7 +214,7 @@
 	L"layer varchar(10) NULL,",
 	L"color varchar(32) NULL,",
 	L"segcount int NULL,",
-	L"boolean tinyint NULL,",
+	L"boolean bit NULL,",
 	L"byte tinyint NULL,",
 	L"datetime1 datetime NULL,",
 	L"decimal1 decimal NULL,",
@@ -231,6 +231,10 @@
 	L"featid bigint IDENTITY NOT NULL",
 	L");",
     L"",
+    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber ) values ('TestLayer1', '256', 1, 2, 7, 11, 0);",
+    L"",
+    L"insert into acdb3dpolyline (layer, color, double1, single1, segcount, classid, revisionnumber ) values ('TestLayer2', '156', 3, 4, 10, 12, 1);",
+    L"",
     NULL
 };
 

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp	2007-02-23 17:39:54 UTC (rev 2610)
@@ -31,6 +31,11 @@
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OdbcMySqlFdoAdvancedSelectTest, "OdbcMySqlFdoAdvancedSelectTest");
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OdbcMySqlFdoAdvancedSelectTest, "OdbcMySqlTests");
 
+CPPUNIT_TEST_SUITE_REGISTRATION( OdbcSqlServerFdoAdvancedSelectTest );
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OdbcSqlServerFdoAdvancedSelectTest, "FdoAdvancedSelectTest");
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OdbcSqlServerFdoAdvancedSelectTest, "OdbcSqlServerFdoAdvancedSelectTest");
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OdbcSqlServerFdoAdvancedSelectTest, "OdbcSqlServerTests");
+
 void OdbcAccessFdoAdvancedSelectTest::set_provider()
 {
 	UnitTestUtil::SetProvider( "OdbcAccess" );
@@ -71,6 +76,27 @@
     }
 }
 
+void OdbcSqlServerFdoAdvancedSelectTest::set_provider()
+{
+	UnitTestUtil::SetProvider( "OdbcSqlServer" );
+}
+
+void OdbcSqlServerFdoAdvancedSelectTest::connect ()
+{
+    try
+    {
+        mConnection = UnitTestUtil::GetProviderConnectionObject();
+        mConnection->SetConnectionString(UnitTestUtil::GetConnectionString());
+        mConnection->Open();
+    }
+    catch (FdoException *ex)
+    {
+        mConnection= NULL;
+        TestCommonFail (ex);
+    }
+}
+
+
 void OdbcAccessFdoAdvancedSelectTest::TestDefect785616()
 {
     try
@@ -662,6 +688,8 @@
     }
 #endif
 }
+
+
 // A test that is hard-coded for a known table.
 void OdbcAccessFdoAdvancedSelectTest::TestSelectExpressions()
 {
@@ -864,342 +892,108 @@
 {
 }
 
-// The following test is to check whether or not an identity property is
-// automatically added to the reader returned by a SelectAggregate request
-// when aa aggregate function is used. In this case, no such property should
-// be returned by the reader.
-void OdbcMySqlFdoAdvancedSelectTest::checkDataReaderContentOnSelAggRequestWithAggrFunction()
+void OdbcSqlServerFdoAdvancedSelectTest::compIdentPropertyTest()
 {
-    FdoPtr<FdoISelectAggregates>    selAggr;
-    FdoPtr<FdoIDataReader>          rdr;
-    FdoPtr<FdoIdentifierCollection> ids;
-    int                             count;
-    bool                            idPropertyFound = false;
+    try
+    {
+        FdoPtr<FdoISelectAggregates> selectAggrCmd = (FdoISelectAggregates*)mConnection->CreateCommand(FdoCommandType_SelectAggregates);
+        selectAggrCmd->SetFeatureClassName(GetCitiesClassname());
 
-	try 
-	{
-        printf(" \n \n");
-        printf(">>> Executing SelectAggregate Function Reader Content Test   \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf("       The test checks whether or not an identity property   \n");
-        printf("       is automatically added to the reader returned by a    \n");
-        printf("       SelectAggregate request when an aggregate function is \n");
-        printf("       used. If the reader contains an identity property the \n");
-        printf("       test issues an exception.                             \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf(">>> ... Executing the select aggregate command \n");
-
-        selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
-        selAggr->SetFeatureClassName(L"Fdo:acdb3dpolyline");
-        FdoFilter *aFilter = FdoComparisonCondition::Create(
-                                FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
-                                FdoComparisonOperations_EqualTo, 
-                                FdoPtr<FdoDataValue>(FdoDataValue::Create(7)));
-        selAggr->SetFilter(aFilter);
-        ids = selAggr->GetPropertyNames();
+        // Control ID's to select:
+        FdoPtr<FdoIdentifierCollection> ids = selectAggrCmd->GetPropertyNames();
         ids->Clear();
-        ids->Add(
-            FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
-                                      L"MyMaxSegcount",
-                                      FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Max(segcount)")))));
 
-        rdr = selAggr->Execute();
-        count = 0;
+        // Add computed property
+        FdoPtr<FdoIdentifierCollection> groupingIds = selectAggrCmd->GetGrouping();
+        groupingIds->Clear();
+        FdoPtr<FdoExpressionCollection> arguments1 = FdoExpressionCollection::Create();
+        FdoPtr<FdoExpression> argument1 = FdoIdentifier::Create(L"cityid");
+        arguments1->Add(argument1);
+        FdoPtr<FdoExpression> expr1 = FdoFunction::Create(L"COUNT", arguments1);
+        FdoPtr<FdoIdentifier> id1 = FdoComputedIdentifier::Create(L"COUNT_CITYID", expr1);
+        ids->Add(id1);
 
-        // The following navigates through the reader and checks the requested data.
-        // It is an error if there is an additional identity property (or any other
-        // property) other than the requested one returned by the reader.
-        printf(">>> ... Checking the returned reader \n");
-        while (rdr->ReadNext())
-        {
-            FdoInt64 myMaxSegcount = rdr->GetInt64(L"MyMaxSegcount");
+        // Execute the command:
+        FdoPtr<FdoIDataReader> dataReader = selectAggrCmd->Execute();
 
-            try
-            {
-                FdoInt64 myid = rdr->GetInt64(L"featid");
-                idPropertyFound = true;
-            }
-            catch ( ... )
-            {
-            }
-
-            count++;
+        // Iterate results:
+        long lRowCount=0;
+        while (dataReader->ReadNext())
+        {
+            //FdoString *jobTitle = dataReader->GetString(L"name");
+            FdoInt64 foo = dataReader->GetInt64(L"COUNT_CITYID");
+            lRowCount++;
         }
-        rdr->Close();
 
-        printf(">>> ... Checking for error cases \n");
-        if (idPropertyFound)
-            throw FdoException::Create(L"Id property returned with reader");
-        else
-            printf(">>> ...... Reader content as expected \n");
-
-        printf(">>> Test executed successfully \n");
+        // Validate the results:
+        CPPUNIT_ASSERT_MESSAGE("Expected 1 row, got differently", lRowCount==1);
     }
-
-    catch( FdoException *ex )
+    catch (FdoException *e)
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
-        printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        TestCommonFail (e);
     }
 }
 
-// The following test is to check whether or not an identity property is
-// automatically added to the reader returned by a SelectAggregate request
-// when a function is used that is not an aggregate function but one of CEIL,
-// CONCAT, FLOOR, LOWER and UPPER. In this case, no such property should be
-// returned by the reader.
-void OdbcMySqlFdoAdvancedSelectTest::checkDataReaderContentOnSelAggRequestWithNumCharFunction()
+void OdbcSqlServerFdoAdvancedSelectTest::groupByorderByTest()
 {
-    FdoPtr<FdoISelectAggregates>    selAggr;
-    FdoPtr<FdoIDataReader>          rdr;
-    FdoPtr<FdoIdentifierCollection> ids;
-    int                             count;
-    bool                            idPropertyFound = false;
-
-	try 
-	{
-        printf(" \n \n");
-        printf(">>> Executing SelectAggregate Function Reader Content Test   \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf("       The test checks whether or not an identity property   \n");
-        printf("       is automatically added to the reader returned by a    \n");
-        printf("       SelectAggregate request when a function is used that  \n");
-        printf("       is not an aggregate function but one of CEIL, CONCAT, \n");
-        printf("       FLOOR, LOWER and UPPER. If the reader contains an     \n");
-        printf("       identity property the test issues an exception.       \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf(">>> ... Executing the select aggregate command \n");
-
-        selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
-        selAggr->SetFeatureClassName(L"Fdo:acdb3dpolyline");
-        FdoFilter *aFilter = FdoComparisonCondition::Create(
-                                FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
-                                FdoComparisonOperations_EqualTo, 
-                                FdoPtr<FdoDataValue>(FdoDataValue::Create(10)));
-        selAggr->SetFilter(aFilter);
-        ids = selAggr->GetPropertyNames();
-        ids->Clear();
-        ids->Add(
-            FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
-                                      L"MyConcatString",
-                                      FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Concat(layer, color)")))));
-
-        rdr = selAggr->Execute();
-        count = 0;
-
-        // The following navigates through the reader and checks the requested data.
-        // It is an error if there is an additional identity property (or any other
-        // property) other than the requested one returned by the reader.
-        printf(">>> ... Checking the returned reader \n");
-        while (rdr->ReadNext())
-        {
-            FdoStringP myString = rdr->GetString(L"MyConcatString");
-
-            try
-            {
-                FdoInt64 myid = rdr->GetInt64(L"featid");
-                idPropertyFound = true;
-            }
-            catch ( ... )
-            {
-            }
-
-            count++;
-        }
-        rdr->Close();
-
-        printf(">>> ... Checking for error cases \n");
-        if (idPropertyFound)
-            throw FdoException::Create(L"Id property returned with reader");
-        else
-            printf(">>> ...... Reader content as expected \n");
-
-        printf(">>> Test executed successfully \n");
-    }
-
-    catch( FdoException *ex )
+#if 0 
+    try
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
-        printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
-    }
-}
+        FdoPtr<FdoISelectAggregates> selectAggrCmd = (FdoISelectAggregates*)mConnection->CreateCommand(FdoCommandType_SelectAggregates);
+        selectAggrCmd->SetFeatureClassName(GetEmployeesClassname());
 
-// The following test is to check whether or not the select command issues
-// an exception if the select statement uses an aggregate function. If this
-// is not the case the test issues an exception.
-void OdbcMySqlFdoAdvancedSelectTest::checkFeatureReaderContentOnSelRequestWithAggrFunction()
-{
-    FdoPtr<FdoISelect>              selCmd;
-    FdoPtr<FdoIFeatureReader>       rdr;
-    FdoPtr<FdoIdentifierCollection> ids;
-    int                             count;
-    bool                            idPropertyFound = false;
-    bool                            expectedExceptionIssued = true;
-
-	try 
-	{
-        printf(" \n \n");
-        printf(">>> Executing Select Function Aggregate Exception Test       \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf("       The test checks whether or not an exception is issued \n");
-        printf("       if the select command is invoked with an aggregate    \n");
-        printf("       function. If the expected exception is not issued the \n");
-        printf("       test issues an exception.                             \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf(">>> ... Executing the select aggregate command \n");
-
-        selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
-        selCmd->SetFeatureClassName(L"Fdo:acdb3dpolyline");
-        ids = selCmd->GetPropertyNames();
+        // Add ids to select:
+        FdoPtr<FdoIdentifierCollection> ids = selectAggrCmd->GetPropertyNames();
         ids->Clear();
-        ids->Add(
-            FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
-                                      L"MyMaxSegcount",
-                                      FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Max(segcount)")))));
+        FdoPtr<FdoIdentifier> id = FdoIdentifier::Create(L"JOBTITLE");
+        ids->Add(id);
 
-        rdr = selCmd->Execute();
+        // Add groupby info:
+        FdoPtr<FdoIdentifierCollection> groupingIds = selectAggrCmd->GetGrouping();
+        groupingIds->Clear();
+        FdoPtr<FdoIdentifier> groupingId = FdoIdentifier::Create(L"JOBTITLE");
+        groupingIds->Add(groupingId);
 
-        // If this point is reached the expected exception was not issued and hence
-        // an exception needs to be issued to indicate so.
-        expectedExceptionIssued = false;
+        // Add grouping filter:
+        FdoPtr<FdoFilter> groupingFilter = FdoFilter::Parse(L"AVG(SALARY) >= 40000.00");
+        selectAggrCmd->SetGroupingFilter(groupingFilter);
 
-        // Check the content of the reader.
+		FdoPtr<FdoIdentifierCollection>orderCol = selectAggrCmd->GetOrdering();
+		FdoPtr<FdoIdentifier>oId = FdoIdentifier::Create(L"JOBTITLE");
+        orderCol->Add( oId );
 
-        count = 0;
-        printf(">>> ... Checking the returned reader \n");
+        // Execute the command:
+        FdoPtr<FdoIDataReader> dataReader = selectAggrCmd->Execute();
 
-        while (rdr->ReadNext())
+        // Iterate results:
+        long lRowCount=0;
+        bool bFoundBoxAssembler = false;
+        bool bFoundBoxFlattener = false;
+        bool bFoundBoxArtist = false;
+        while (dataReader->ReadNext())
         {
-            FdoInt64 myMaxSegcount = rdr->GetInt64(L"MyMaxSegcount");
-            FdoStringP className = rdr->GetClassDefinition()->GetName();
+            FdoString *jobTitle = dataReader->GetString(L"JOBTITLE");
 
-            try
-            {
-                FdoInt64 myid = rdr->GetInt64(L"featid");
-                idPropertyFound = true;
-            }
-            catch ( ... )
-            {
-            }
+            if (0==wcscmp(jobTitle, L"Box Flattener"))
+                bFoundBoxFlattener = true;
+            else if (0==wcscmp(jobTitle, L"Box Assembler"))
+                bFoundBoxAssembler = true;
+            else if (0==wcscmp(jobTitle, L"Box Artist"))
+                bFoundBoxArtist = true;
 
-            count++;
+            lRowCount++;
         }
-        rdr->Close();
 
-        printf(">>> ... Checking for error cases \n");
-
-        //if (idPropertyFound)
-        //    throw FdoException::Create(L"Identity property found in reader when not expected");
-
-        //if (!expectedExceptionIssued)
-        //    throw FdoException::Create(L"Expected exception not issued");
-
-        printf(">>> Test executed succeeded \n");
+        // Validate the results:
+        CPPUNIT_ASSERT_MESSAGE("Expected 3 rows, got differently", lRowCount==3);
+        CPPUNIT_ASSERT_MESSAGE("Expected to find 'Box Flattener' but didn't", bFoundBoxFlattener);
+        CPPUNIT_ASSERT_MESSAGE("Expected to find 'Box Assembler' but didn't", bFoundBoxAssembler);
+        CPPUNIT_ASSERT_MESSAGE("Expected to find 'Box Artist' but didn't", bFoundBoxArtist);
     }
-
-    catch( FdoException *ex )
+    catch (FdoException *e)
     {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
-        printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+        TestCommonFail (e);
     }
+#endif
 }
-
-// The following test is to check whether or not an identity property is
-// automatically added to the reader returned by a Select request when a
-// function is used that is not an aggregate function but one of CEIL,
-// CONCAT, FLOOR, LOWER and UPPER. In this case, the reader is expected to
-// return such a property.
-void OdbcMySqlFdoAdvancedSelectTest::checkFeatureReaderContentOnSelRequestWithNumCharFunction()
-{
-    FdoPtr<FdoISelect>              selCmd;
-    FdoPtr<FdoIFeatureReader>       rdr;
-    FdoPtr<FdoIdentifierCollection> ids;
-    int                             count;
-    bool                            idPropertyFound = false;
-
-	try 
-	{
-        printf(" \n \n");
-        printf(">>> Executing Select Function Reader Content Test            \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf(">>>    The test checks whether or not an identity property   \n");
-        printf(">>>    is automatically added to the reader returned by a    \n");
-        printf(">>>    Select request when a function is used that is not an \n");
-        printf(">>>    aggregate function but one of CEIL, CONCAT, FLOOR,    \n");
-        printf(">>>    LOWER and UPPER. In this case, the reader is expected \n");
-        printf(">>>    to return such a property.                            \n");
-        printf(" ----------------------------------------------------------- \n");
-        printf(">>> ... Executing the select command \n");
-
-        selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
-        selCmd->SetFeatureClassName(L"Fdo:acdb3dpolyline");
-        FdoFilter *aFilter = FdoComparisonCondition::Create(
-                                FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
-                                FdoComparisonOperations_EqualTo, 
-                                FdoPtr<FdoDataValue>(FdoDataValue::Create(7)));
-        selCmd->SetFilter(aFilter);
-        ids = selCmd->GetPropertyNames();
-        ids->Clear();
-        ids->Add(
-            FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
-                                      L"MyConcatString",
-                                      FdoPtr<FdoExpression>(
-                                            FdoExpression::Parse(L"Concat(layer, color)")))));
-
-        rdr = selCmd->Execute();
-        count = 0;
-
-        // The following navigates through the reader and checks the requested data.
-        // It is an error if the reader does not return identity properties.
-        printf(">>> ... Checking the returned reader \n");
-        while (rdr->ReadNext())
-        {
-            FdoStringP myString = rdr->GetString(L"MyConcatString");
-
-            try
-            {
-                FdoInt64 myid = rdr->GetInt64(L"featid");
-                idPropertyFound = true;
-            }
-            catch ( ... )
-            {
-            }
-
-            count++;
-        }
-        rdr->Close();
-
-        printf(">>> ... Checking for error cases \n");
-        if (!idPropertyFound)
-            throw FdoException::Create(L"Id property not returned with reader");
-        else
-            printf(">>> ...... Reader content as expected \n");
-
-        printf(">>> Test executed successfully \n");
-    }
-
-    catch( FdoException *ex )
-    {
-        printf(" \n");
-        printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
-        printf(" \n");
-        printf(">>> Test failed \n");
-        CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
-    }
-}
-
-
-
 #endif

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h	2007-02-23 17:39:54 UTC (rev 2610)
@@ -50,6 +50,10 @@
     virtual void TestDefect779194() {};
     virtual void TestDefect785616();
 	virtual void getDataTypeTest();
+    virtual void TestMaxBoolProperty(){}
+    virtual void TestUpperDateProperty(){}
+    virtual void TestCeillInt64Property(){}
+    virtual void TestLowerOnStringProperty(){}
 	virtual void groupByorderByTest();
     virtual void checkDataReaderContentOnSelAggRequestWithAggrFunction();
     virtual void checkDataReaderContentOnSelAggRequestWithNumCharFunction();
@@ -67,7 +71,7 @@
     void TestConcat();
 
 protected:
-    FdoString * GetSchemaName() {return L"Fdo";}
+    FdoStringP GetSchemaName() {return L"Fdo";}
     FdoStringP GetTable1Classname()
     {
         FdoStringP className = GetSchemaName();
@@ -101,17 +105,16 @@
     virtual void groupByTest() {};
     virtual void functionTest() {};
     virtual void getDataTypeTest() {};
+    virtual void TestMaxBoolProperty(){}
     virtual void selectDistinctTest() {};
     virtual void TestDefect779194() {};
     virtual void TestDefect785616() {};
 	virtual void groupByorderByTest();
-    virtual void checkDataReaderContentOnSelAggRequestWithAggrFunction();
-    virtual void checkDataReaderContentOnSelAggRequestWithNumCharFunction();
-    virtual void checkFeatureReaderContentOnSelRequestWithAggrFunction();
-    virtual void checkFeatureReaderContentOnSelRequestWithNumCharFunction();
 
 protected:
-    FdoString * GetSchemaName() {return L"Fdo";}
+    FdoStringP GetSchemaName() {return L"Fdo";}
+    FdoStringP AcDb3dPolylineName(){return L"acdb3dpolyline";};
+    FdoStringP GetDateTimePropName(){return L"datetime1";};
     FdoStringP GetCitiesClassname()
     {
         FdoStringP className = GetSchemaName();
@@ -121,6 +124,41 @@
     }
 };
 
+class OdbcSqlServerFdoAdvancedSelectTest : public FdoAdvancedSelectTest
+{
+    CPPUNIT_TEST_SUB_SUITE (OdbcSqlServerFdoAdvancedSelectTest, FdoAdvancedSelectTest);
+    CPPUNIT_TEST (TestLowerOnStringProperty);
+    CPPUNIT_TEST_SUITE_END ();
+
+    void  set_provider();
+
+    // Overridden tests.
+    virtual void connect ();
+    virtual void compIdentFilterTest() {};
+    virtual void compIdentPropertyTest();
+    virtual void orderByTest() {};
+    virtual void groupByTest() {};
+    virtual void functionTest() {};
+    virtual void getDataTypeTest() {};
+    virtual void selectDistinctTest() {};
+    virtual void TestDefect779194() {};
+    virtual void TestDefect785616() {};
+	virtual void groupByorderByTest();
+    //virtual void TestMaxBoolProperty(){}
+
+protected:
+    FdoStringP GetSchemaName() {return L"dbo";}
+    FdoStringP AcDb3dPolylineName(){return L"acdb3dpolyline";};
+    FdoStringP GetDateTimePropName(){return L"datetime1";};
+    FdoStringP GetCitiesClassname()
+    {
+        FdoStringP className = GetSchemaName();
+        className += L":";
+        className += L"cities";
+        return className;
+    }
+};
+
 #endif
 
 #endif // ODBC_ADVANCEDSELECTTEST_H

Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h	2007-02-23 17:39:54 UTC (rev 2610)
@@ -133,6 +133,7 @@
     virtual void _secondComputedIdTest() {
         TestCommonFeatureCommands::secondComputedIdTest(mConnection, L"acdb3dpolyline", L"featid");
     }
+    virtual int numPropertiesInPolylineClass() { return 17; };
 };
 
 class OdbcAccessFdoSelectTest : public OdbcFdoSelectTest

Modified: trunk/Utilities/Common/FdoCommon.vcproj
===================================================================
--- trunk/Utilities/Common/FdoCommon.vcproj	2007-02-23 16:55:13 UTC (rev 2609)
+++ trunk/Utilities/Common/FdoCommon.vcproj	2007-02-23 17:39:54 UTC (rev 2610)
@@ -351,6 +351,10 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Inc\FdoCommonExpressionExecutor.h"
+				>
+			</File>
+			<File
 				RelativePath="Inc\FdoCommonFeatureCommand.h"
 				>
 			</File>

Added: trunk/Utilities/Common/Inc/FdoCommonExpressionExecutor.h
===================================================================
--- trunk/Utilities/Common/Inc/FdoCommonExpressionExecutor.h	                        (rev 0)
+++ trunk/Utilities/Common/Inc/FdoCommonExpressionExecutor.h	2007-02-23 17:39:54 UTC (rev 2610)
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2004-2006  Autodesk, Inc.
+* 
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+* 
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+* 
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _FDOCOMMONEXPRESSIONEXECUTOR_H_
+#define _FDOCOMMONEXPRESSIONEXECUTOR_H_
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "FdoCommonOSUtil.h"
+
+/// \brief
+/// validate extended usage of functions
+class FdoCommonExpressionExecutor : public FdoDisposable
+{
+protected:
+	FdoCommonExpressionExecutor() {};
+    FdoCommonExpressionExecutor(FdoFeatureSchemaCollection* schColl, FdoIdentifier* className)
+    {
+        m_UnknownTypeFound = false;
+        FdoInt32 cnt = 0;
+        FdoStringP Name;
+        FdoString** ptrNames = className->GetScope(cnt);
+        if (cnt == 0)
+            Name = className->GetName();
+        else
+            Name = *ptrNames;
+
+        FdoStringP schName = className->GetSchemaName();
+        if (schName.GetLength())
+        {
+            FdoPtr<FdoFeatureSchema> schema = schColl->GetItem(schName);
+            m_classes = schema->GetClasses();
+            m_actClass = m_classes->FindItem(Name);
+        }
+        else
+        {
+            for(int i = 0; i < schColl->GetCount(); i++)
+            {
+                FdoPtr<FdoFeatureSchema> schema = schColl->GetItem(i);
+                m_classes = schema->GetClasses();
+                m_actClass = m_classes->FindItem(Name);
+                if (m_actClass == NULL)
+                    m_classes = NULL;
+                else
+                    break;
+            }
+        }
+    }
+
+    FdoDataType GetObjectType(FdoStringP objectName, FdoClassDefinition* classDef)
+    {
+        if (classDef != NULL)
+        {
+            FdoPtr<FdoPropertyDefinitionCollection> defColl = classDef->GetProperties();
+            if(!objectName.Contains(L"."))
+            {
+                FdoPtr<FdoPropertyDefinition> propDef = defColl->FindItem(objectName);
+                if (propDef == NULL)
+                {
+                    FdoPtr<FdoClassDefinition> baseClassDef = classDef->GetBaseClass();
+                    while(baseClassDef != NULL)
+                    {
+                        defColl = baseClassDef->GetProperties();
+                        propDef = defColl->FindItem(objectName);
+                        if (propDef != NULL)
+                            break;
+                        baseClassDef = baseClassDef->GetBaseClass();
+                    }
+                }
+                if (propDef != NULL && propDef->GetPropertyType() == FdoPropertyType_DataProperty)
+                    return ((FdoDataPropertyDefinition*)propDef.p)->GetDataType();
+            }
+            else
+            {
+                FdoStringP propName = objectName.Left(L".");
+                objectName = objectName.Right(L".");
+                FdoPtr<FdoPropertyDefinition> propDef = defColl->FindItem(propName);
+                if (propDef == NULL)
+                {
+                    FdoPtr<FdoClassDefinition> baseClassDef = classDef->GetBaseClass();
+                    while(baseClassDef != NULL)
+                    {
+                        defColl = baseClassDef->GetProperties();
+                        propDef = defColl->FindItem(propName);
+                        if (propDef != NULL)
+                            break;
+                        baseClassDef = baseClassDef->GetBaseClass();
+                    }
+                }
+                if (propDef != NULL)
+                {
+                    if(propDef->GetPropertyType() == FdoPropertyType_ObjectProperty)
+                    {
+                        FdoPtr<FdoClassDefinition> classObjDef = ((FdoObjectPropertyDefinition*)propDef.p)->GetClass();
+                        return GetObjectType(objectName, classObjDef);
+                    }
+                    else if(propDef->GetPropertyType() == FdoPropertyType_AssociationProperty)
+                    {
+                        FdoPtr<FdoClassDefinition> classObjDef = ((FdoAssociationPropertyDefinition*)propDef.p)->GetAssociatedClass();
+                        return GetObjectType(objectName, classObjDef);
+                    }
+                }
+            }
+        }
+        m_UnknownTypeFound = true;
+        return (FdoDataType)(FdoDataType_Boolean-1);
+    }
+public:
+    static FdoCommonExpressionExecutor* Create(FdoFeatureSchemaCollection* schColl, FdoIdentifier* className)
+    {
+        return new FdoCommonExpressionExecutor(schColl, className);
+    }
+
+    void ValidateIdentifiers(FdoIdentifierCollection* idCol, FdoIExpressionCapabilities* expCap)
+    {
+        try
+        {
+            FdoPtr<FdoFunctionDefinitionCollection> functions = expCap->GetFunctions();
+            for (int i = 0; i < idCol->GetCount(); i++)
+            {
+                FdoPtr<FdoIdentifier> idf = idCol->GetItem(i);
+                if (dynamic_cast<FdoComputedIdentifier*>(idf.p) != NULL)
+                {
+                    FdoPtr<FdoExpression> expr = ((FdoComputedIdentifier*)idf.p)->GetExpression();
+                    ValidateExpresion(expr, functions);
+                }
+            }
+        }
+        catch(FdoException* e)
+        {
+            if(m_UnknownTypeFound)
+                e->Release();
+            else
+                throw e;
+        }
+    }
+private:
+    FdoDataType ValidateExpresion(FdoExpression* expr, FdoFunctionDefinitionCollection* functions)
+    {
+        if (dynamic_cast<FdoIdentifier*>(expr) != NULL){
+            return GetObjectType(((FdoIdentifier*)expr)->GetName(), m_actClass);
+        }
+        else if (dynamic_cast<FdoFunction*>(expr) != NULL)
+        {
+            FdoFunction* fct = (FdoFunction*)expr;
+            FdoString* fctName = fct->GetName();
+            FdoPtr<FdoExpressionCollection> argsExp = fct->GetArguments();
+            FdoPtr<FdoFunctionDefinition> function;
+
+            for(int i = 0; i < functions->GetCount(); i++)
+            {
+                function = functions->GetItem(i);
+                if (FdoCommonOSUtil::wcsicmp(function->GetName(), fctName) != 0)
+                    function = NULL;
+                else
+                    break;
+            }
+            if (function == NULL) // unknown function do the best...
+            {
+                m_UnknownTypeFound = true;
+                return (FdoDataType)(FdoDataType_Boolean-1);
+            }
+            // No argument provided, return the type
+            if (argsExp == NULL || !argsExp->GetCount())
+                return function->GetReturnType();
+
+            FdoPtr<FdoReadOnlySignatureDefinitionCollection> pSigs = function->GetSignatures();
+
+            for(int i = 0; i < pSigs->GetCount(); i++)
+            {
+                FdoPtr<FdoSignatureDefinition> pSig = pSigs->GetItem(i);
+                FdoPtr<FdoReadOnlyArgumentDefinitionCollection> args = pSig->GetArguments();
+                if (argsExp->GetCount() != args->GetCount())
+                    continue;
+                bool argsFound = true;
+                for(int y = 0; y < args->GetCount(); y++)
+                {
+                    FdoDataType dataTypeArg;
+                    FdoPtr<FdoArgumentDefinition> arg = args->GetItem(y);
+                    FdoPtr<FdoExpression> exp = argsExp->GetItem(y);
+                    dataTypeArg = ValidateExpresion(exp, functions);
+                    if (dataTypeArg == (FdoDataType)(FdoDataType_Boolean-1))
+                        dataTypeArg = arg->GetDataType();
+                    if (dataTypeArg != arg->GetDataType())
+                    {
+                        argsFound = false;
+                        break;
+                    }
+                }
+                if (argsFound)
+                    return pSig->GetReturnType();
+            }
+            throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_80_INVALID_EXPRESSION)));
+        }
+        else if (dynamic_cast<FdoUnaryExpression*>(expr) != NULL)
+        {
+            // just validate the expression from inside
+            FdoPtr<FdoExpression> exp1 = ((FdoUnaryExpression*)expr)->GetExpression();
+            ValidateExpresion(exp1, functions);
+            return FdoDataType_Boolean;
+        }
+        else if (dynamic_cast<FdoBinaryExpression*>(expr) != NULL)
+        {
+            // just validate the expression from inside
+            FdoPtr<FdoExpression> exp1 = ((FdoBinaryExpression*)expr)->GetLeftExpression();
+            FdoDataType left = ValidateExpresion(exp1, functions);
+            FdoPtr<FdoExpression> exp2 = ((FdoBinaryExpression*)expr)->GetRightExpression();
+            FdoDataType right = ValidateExpresion(exp2, functions);
+            if (left == FdoDataType_String || right == FdoDataType_String)
+                return FdoDataType_String;
+            if (left == FdoDataType_DateTime || right == FdoDataType_DateTime)
+                return FdoDataType_DateTime;
+            if (left == FdoDataType_Double || right == FdoDataType_Double)
+                return FdoDataType_Double;
+            if (left == FdoDataType_Decimal || right == FdoDataType_Decimal)
+                return FdoDataType_Decimal;
+            if (left == FdoDataType_Single || right == FdoDataType_Single)
+                return FdoDataType_Double;
+            if (left == FdoDataType_Int64 || right == FdoDataType_Int64)
+                return FdoDataType_Int64;
+            if (left == FdoDataType_Int32 || right == FdoDataType_Int32)
+                return FdoDataType_Int32;
+            if (left == FdoDataType_Int16 || right == FdoDataType_Int16)
+                return FdoDataType_Int16;
+            if (left == FdoDataType_Byte || right == FdoDataType_Byte)
+                return FdoDataType_Byte;
+            if (left == FdoDataType_Boolean || right == FdoDataType_Boolean)
+                return FdoDataType_Boolean;
+            // unknown type
+            m_UnknownTypeFound = true;
+            return (FdoDataType)(FdoDataType_Boolean-1);
+        }
+        else if (dynamic_cast<FdoStringValue*>(expr) != NULL)
+            return FdoDataType_String;
+        else if (dynamic_cast<FdoDateTime*>(expr) != NULL)
+            return FdoDataType_DateTime;
+        else if (dynamic_cast<FdoInt16Value*>(expr) != NULL)
+            return FdoDataType_Int16;
+        else if (dynamic_cast<FdoInt32Value*>(expr) != NULL)
+            return FdoDataType_Int32;
+        else if (dynamic_cast<FdoInt64Value*>(expr) != NULL)
+            return FdoDataType_Int64;
+        else if (dynamic_cast<FdoDoubleValue*>(expr) != NULL)
+            return FdoDataType_Double;
+        else if (dynamic_cast<FdoDecimalValue*>(expr) != NULL)
+            return FdoDataType_Decimal;
+        else if (dynamic_cast<FdoSingleValue*>(expr) != NULL)
+            return FdoDataType_Single;
+        else if (dynamic_cast<FdoByteValue*>(expr) != NULL)
+            return FdoDataType_Byte;
+        else if (dynamic_cast<FdoBooleanValue*>(expr) != NULL)
+            return FdoDataType_Boolean;
+        else // unknown type
+        {
+            m_UnknownTypeFound = true;
+            return (FdoDataType)(FdoDataType_Boolean-1);
+        }
+    }
+private:
+    FdoPtr<FdoClassCollection> m_classes;
+    FdoPtr<FdoClassDefinition> m_actClass;
+    FdoBoolean m_UnknownTypeFound;
+};
+
+#endif //_FDOCOMMONEXPRESSIONEXECUTOR_H_



More information about the fdo-commits mailing list