[fdo-commits] r771 - in branches/3.2.x/Providers/GenericRdbms/Src:
Fdo/FeatureCommands Gdbi ODBC/Fdo UnitTest/Common UnitTest/Odbc
svn_fdo at osgeo.org
svn_fdo at osgeo.org
Fri Feb 23 12:05:16 EST 2007
Author: romicadascalescu
Date: 2007-02-23 12:05:16 -0500 (Fri, 23 Feb 2007)
New Revision: 771
Modified:
branches/3.2.x/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp
branches/3.2.x/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp
branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h
branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h
Log:
Ticket #20 Generic RDBMS: fix various SelectAggregates defects
Modified: branches/3.2.x/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Fdo/FeatureCommands/FdoRdbmsSelectCommand.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -31,6 +31,7 @@
#include "FdoRdbmsFilterProcessor.h"
#include <FdoCommonFilterExecutor.h>
#include <FdoCommonSchemaUtil.h>
+#include <FdoCommonExpressionExecutor.h>
#define SELECT_CLEANUP \
if ( qid != -1) {\
@@ -93,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;
@@ -105,8 +106,7 @@
// Validate the filter
if ( this->GetFilterRef() != NULL )
{
- FdoPtr<FdoIConnection> conn = GetConnection();
- FdoPtr<FdoIFilterCapabilities> filterCaps = conn->GetFilterCapabilities();
+ FdoPtr<FdoIFilterCapabilities> filterCaps = mFdoConnection->GetFilterCapabilities();
FdoCommonFilterExecutor::ValidateFilter( NULL, this->GetFilterRef(), NULL, filterCaps);
}
@@ -161,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: branches/3.2.x/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/Gdbi/GdbiQueryResult.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -230,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: branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/ODBC/Fdo/FdoRdbmsOdbcFilterProcessor.h 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcBaseSetup.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.cpp 2007-02-23 17:05:16 UTC (rev 771)
@@ -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
@@ -866,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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoAdvancedSelectTest.h 2007-02-23 17:05:16 UTC (rev 771)
@@ -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: branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h
===================================================================
--- branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h 2007-02-22 23:13:19 UTC (rev 770)
+++ branches/3.2.x/Providers/GenericRdbms/Src/UnitTest/Odbc/OdbcFdoSelectTest.h 2007-02-23 17:05:16 UTC (rev 771)
@@ -133,6 +133,7 @@
virtual void _secondComputedIdTest() {
TestCommonFeatureCommands::secondComputedIdTest(mConnection, L"acdb3dpolyline", L"featid");
}
+ virtual int numPropertiesInPolylineClass() { return 17; };
};
class OdbcAccessFdoSelectTest : public OdbcFdoSelectTest
More information about the fdo-commits
mailing list