[fdo-commits] r231 - in branches/3.2.x/Providers/SDF/Src: .
Provider UnitTest Utils
svn_fdo at osgeo.org
svn_fdo at osgeo.org
Thu Mar 8 15:28:05 EST 2007
Author: badreddinekaroui
Date: 2007-03-08 15:28:04 -0500 (Thu, 08 Mar 2007)
New Revision: 231
Modified:
branches/3.2.x/Providers/SDF/Src/Makefile.am
branches/3.2.x/Providers/SDF/Src/Provider/SDF.vcproj
branches/3.2.x/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp
branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.cpp
branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.h
branches/3.2.x/Providers/SDF/Src/UnitTest/UnitTest.vcproj
branches/3.2.x/Providers/SDF/Src/Utils/DataValue.h
branches/3.2.x/Providers/SDF/Src/Utils/FDOUtils.vcproj
branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.cpp
branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.h
branches/3.2.x/Providers/SDF/Src/Utils/Makefile.am
branches/3.2.x/Providers/SDF/Src/Utils/NullValue.cpp
Log:
Ticket#32: SDF: Add filter support for the Fdo Upper, Lower, Ceil, and Floor functions
Modified: branches/3.2.x/Providers/SDF/Src/Makefile.am
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Makefile.am 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Makefile.am 2007-03-08 20:28:04 UTC (rev 231)
@@ -35,7 +35,6 @@
./Utils/libSDFUtils.la \
./Provider/libSDFProviderSrc.la \
$(FDO)/Unmanaged/Src/libFDO.la \
- $(FDO)/Unmanaged/Src/Spatial/libFDOSpatial.la \
$(FDOUTILITIES)/SQLiteInterface/libSQLiteInterface.la \
$(FDOTHIRDPARTY)/Sqlite3.1.5/linux/lib/sqlite3.a \
$(FDOUTILITIES)/Common/libProvidersCommon.la \
Modified: branches/3.2.x/Providers/SDF/Src/Provider/SDF.vcproj
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Provider/SDF.vcproj 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Provider/SDF.vcproj 2007-03-08 20:28:04 UTC (rev 231)
@@ -53,7 +53,7 @@
ProgramDataBaseFileName="$(IntDir)/SDFProvider.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
+ DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -69,7 +69,7 @@
Name="VCLinkerTool"
AdditionalDependencies="FDOUtils.lib FDO.lib FDOCommon.lib FDOGeometry.lib FDONLS.lib ProvidersCommon.lib FDOSpatial.lib SQLiteInterface.lib Sqlite3.lib Advapi32.lib"
OutputFile="$(OutDir)/SDFProvider.dll"
- LinkIncremental="2"
+ LinkIncremental="1"
AdditionalLibraryDirectories="$(FDO)\Unmanaged\Lib\Win32\Debug\;$(FDOUTILITIES)\Common\Lib\Win32\Debug;..\..\Lib\Win32\Debug;$(FDOTHIRDPARTY)\Sqlite3.1.5\Debug;$(FDOUTILITIES)\SQLiteInterface\Lib\Win32\Debug"
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="true"
Modified: branches/3.2.x/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Provider/SdfImpExtendedSelect.cpp 2007-03-08 20:28:04 UTC (rev 231)
@@ -244,7 +244,7 @@
realpath(cpath, cfullpath);
mbstowcs(fullpath, cfullpath, 1024);
- FILE *fp = fopen((const char*)FdoString(fullpath), "r");
+ FILE *fp = fopen((const char*)FdoStringP(fullpath), "r");
if( fp )
{
fclose(fp);
Modified: branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.cpp
===================================================================
--- branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.cpp 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.cpp 2007-03-08 20:28:04 UTC (rev 231)
@@ -1270,3 +1270,73 @@
TestCommonFail( ex );
}
}
+void MasterTest::selectFunctionTest()
+{
+ try
+ {
+ FdoPtr<FdoIConnection> conn = CreateConnection();
+
+ openConnection(conn, SHP_PATH, true);
+
+ FdoPtr<FdoISelect> select = (FdoISelect*)(conn->CreateCommand(FdoCommandType_Select));
+
+ select->SetFeatureClassName(L"World_Countries");
+
+ select->SetFilter(L"Upper(NAME) LIKE '%TU%'");
+ FdoPtr<FdoIReader> rdr = select->Execute();
+ int count = 0;
+ while (rdr->ReadNext())
+ {
+ //printf("%ls\n", rdr->GetString(L"NAME"));
+ count++;
+ }
+ rdr->Close();
+
+ //printf("Upper count: %d\n", count);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number of records returned by a Upper filter", count==14);
+
+ select->SetFilter(L"Lower(NAME) LIKE '%tu%'");
+ rdr = select->Execute();
+ count = 0;
+ while (rdr->ReadNext())
+ {
+ //printf("%ls\n", rdr->GetString(L"NAME"));
+ count++;
+ }
+ rdr->Close();
+ //printf("Upper count: %d\n", count);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number of records returned by a Lower filter", count==14);
+
+ select->SetFilter(L"Ceil(Autogenerated_ID) < 10");
+ rdr = select->Execute();
+ count = 0;
+ while (rdr->ReadNext())
+ {
+ //printf("%ls\n", rdr->GetString(L"NAME"));
+ count++;
+ }
+ rdr->Close();
+ //printf("Ceil count: %d\n", count);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number of records returned by a Lower filter", count==9);
+
+ select->SetFilter(L"Floor(Autogenerated_ID) < 10");
+ rdr = select->Execute();
+ count = 0;
+ while (rdr->ReadNext())
+ {
+ //printf("%ls\n", rdr->GetString(L"NAME"));
+ count++;
+ }
+ rdr->Close();
+ //printf("Floor count: %d\n", count);
+ CPPUNIT_ASSERT_MESSAGE("Unexpected number of records returned by a Floor filter", count==9);
+
+ conn->Close();
+ }
+ catch(FdoException *exp )
+ {
+ printf("Function test failed: %ls\n", exp->GetExceptionMessage() );
+ exp->Release();
+ CPPUNIT_FAIL("Function test failed");
+ }
+}
\ No newline at end of file
Modified: branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.h
===================================================================
--- branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.h 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/UnitTest/MasterTest.h 2007-03-08 20:28:04 UTC (rev 231)
@@ -96,6 +96,7 @@
CPPUNIT_TEST(concurencyTest);
CPPUNIT_TEST(descReadOnly);
CPPUNIT_TEST(test_aggregates_datetime_string);
+ CPPUNIT_TEST(selectFunctionTest);
CPPUNIT_TEST_SUITE_END();
// You may define any private variables that are used in your test
@@ -131,6 +132,7 @@
void selectSpatialExtentsTest();
void descReadOnly();
void test_aggregates_datetime_string();
+ void selectFunctionTest();
};
#endif
Modified: branches/3.2.x/Providers/SDF/Src/UnitTest/UnitTest.vcproj
===================================================================
--- branches/3.2.x/Providers/SDF/Src/UnitTest/UnitTest.vcproj 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/UnitTest/UnitTest.vcproj 2007-03-08 20:28:04 UTC (rev 231)
@@ -52,7 +52,7 @@
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
+ DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -67,7 +67,7 @@
Name="VCLinkerTool"
AdditionalDependencies="cppunitd.lib FDO.lib FDOCommon.lib FDOGeometry.lib FDOSpatial.lib ProvidersCommon.lib"
OutputFile="$(OutDir)/UnitTest.exe"
- LinkIncremental="2"
+ LinkIncremental="1"
AdditionalLibraryDirectories=""$(FDOTHIRDPARTY)\CppUnit\lib\";"$(FDO)\Unmanaged\Lib\Win32\Debug";"$(FDOUTILITIES)\TestCommon\Lib\Win32\Debug";"$(FDOUTILITIES)\Common\Lib\Win32\Debug""
IgnoreDefaultLibraryNames="libcmtd.lib"
GenerateDebugInformation="true"
Modified: branches/3.2.x/Providers/SDF/Src/Utils/DataValue.h
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/DataValue.h 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/DataValue.h 2007-03-08 20:28:04 UTC (rev 231)
@@ -18,16 +18,15 @@
#define MAX_STRING_LENGTH 256
-enum DataValueType
-{
- Dvt_Int64,
- Dvt_Double,
- Dvt_String,
- Dvt_Boolean,
- Dvt_DateTime,
- Dvt_Null
-};
+#define DataValueType FdoDataType
+#define Dvt_Boolean FdoDataType_Boolean
+#define Dvt_Int64 FdoDataType_Int64
+#define Dvt_Double FdoDataType_Double
+#define Dvt_String FdoDataType_String
+#define Dvt_DateTime FdoDataType_DateTime
+#define Dvt_Null (-1) // A null value indicator
+
//forward declare
class DataValuePool;
Modified: branches/3.2.x/Providers/SDF/Src/Utils/FDOUtils.vcproj
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/FDOUtils.vcproj 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/FDOUtils.vcproj 2007-03-08 20:28:04 UTC (rev 231)
@@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
- AdditionalIncludeDirectories="$(FDO)\Unmanaged\Inc;$(FDO)\Unmanaged\Src\NLS"
+ AdditionalIncludeDirectories=""$(FDO)\Unmanaged\Inc";"$(FDO)\Unmanaged\Src\NLS";"$(FDOUTILITIES)\Common\inc""
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FDOUTILS_EXPORTS;GISSPATIAL_STATIC;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@@ -53,7 +53,7 @@
ProgramDataBaseFileName="$(IntDir)/FDOUtils.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
- DebugInformationFormat="4"
+ DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
@@ -114,7 +114,7 @@
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
OmitFramePointers="true"
- AdditionalIncludeDirectories="$(FDO)\Unmanaged\Inc;$(FDO)\Unmanaged\Src\NLS"
+ AdditionalIncludeDirectories=""$(FDO)\Unmanaged\Inc";"$(FDO)\Unmanaged\Src\NLS";"$(FDOUTILITIES)\Common\inc""
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;FDOUTILS_EXPORTS;GISSPATIAL_STATIC;_CRT_SECURE_NO_DEPRECATE"
RuntimeLibrary="2"
TreatWChar_tAsBuiltInType="true"
Modified: branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.cpp
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.cpp 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.cpp 2007-03-08 20:28:04 UTC (rev 231)
@@ -26,8 +26,11 @@
#include "DateTimeValue.h"
#include "NullValue.h"
#include <FdoSpatial.h>
+#include "FdoCommonMiscUtil.h"
+#include <wctype.h>
+#include <malloc.h>
+#include <math.h>
-
FilterExecutor::FilterExecutor(FdoIFeatureReader* featureReader, PropertyIndex* propIndex, FdoIdentifierCollection* compIdents, FdoClassDefinition* classDef)
{
//don't think we need an addref since the FeatureReader owns us.
@@ -437,11 +440,129 @@
{
return ExecuteARGB(expr);
}
+ else if (wcscmp (name, FDO_FUNCTION_CEIL) == 0 || wcscmp (name, FDO_FUNCTION_FLOOR) == 0)
+ {
+ FdoPtr<FdoExpressionCollection> args = expr.GetArguments ();
+
+ if (args->GetCount () != 1)
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_75_INVALID_NUM_ARGUMENTS), expr.GetName(), 1, args->GetCount()));
+
+ FdoPtr<FdoExpression> left = args->GetItem (0);
+ left->Process (this);
+
+ DataValue* argLeft = m_retvals.pop ();
+
+ ProcessFunctionCeilFloor( name, argLeft );
+
+ m_pPool->RelinquishDataValue(argLeft);
+ }
+ else if (wcscmp (name, FDO_FUNCTION_LOWER) == 0)
+ {
+ FdoPtr<FdoExpressionCollection> args = expr.GetArguments ();
+
+ if (args->GetCount () != 1)
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_75_INVALID_NUM_ARGUMENTS), expr.GetName(), 1, args->GetCount()));
+
+ FdoPtr<FdoExpression> left = args->GetItem (0);
+ left->Process (this);
+
+ DataValue* argLeft = m_retvals.pop ();
+
+ if (FdoDataType_String != argLeft->GetType ())
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_88_INVALID_FUNCTION_ARG_TYPE), 1, name, FdoCommonMiscUtil::FdoDataTypeToString(argLeft->GetType()), FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_String)));
+
+ if ( argLeft->GetType() == Dvt_Null )
+ m_retvals.push ( m_pPool->ObtainNullValue() );
+ else
+ {
+ FdoString* arg = argLeft->GetAsString();
+ size_t len = wcslen (arg) + 1;
+ wchar_t* res = new wchar_t[len];
+ wcscpy (res, arg);
+ for (size_t i = 0; i < len; i++)
+ res[i] = towlower (res[i]);
+ m_retvals.push (m_pPool->ObtainStringValue (res,true) );
+ }
+ m_pPool->RelinquishDataValue(argLeft);
+ }
+ else if (wcscmp (name, FDO_FUNCTION_UPPER) == 0)
+ {
+ FdoPtr<FdoExpressionCollection> args = expr.GetArguments ();
+
+ if (args->GetCount () != 1)
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_75_INVALID_NUM_ARGUMENTS), expr.GetName(), 1, args->GetCount()));
+
+ FdoPtr<FdoExpression> left = args->GetItem (0);
+ left->Process (this);
+
+ DataValue* argLeft = m_retvals.pop ();
+
+ if (FdoDataType_String != argLeft->GetType ())
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_88_INVALID_FUNCTION_ARG_TYPE), 1, name, FdoCommonMiscUtil::FdoDataTypeToString(argLeft->GetType()), FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_String)));
+
+ if ( argLeft->GetType() == Dvt_Null )
+ m_retvals.push ( m_pPool->ObtainNullValue() );
+ else
+ {
+ FdoString* arg = argLeft->GetAsString();
+ size_t len = wcslen (arg) + 1;
+ wchar_t* res = new wchar_t[len];
+ wcscpy (res, arg);
+ for (size_t i = 0; i < len; i++)
+ res[i] = towupper (res[i]);
+ m_retvals.push (m_pPool->ObtainStringValue ( res, true ));
+ }
+ m_pPool->RelinquishDataValue(argLeft);
+ }
else
{
- throw FdoException::Create(L"Function not supported");
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_89_UNSUPPORTED_FUNCTION), name));
}
}
+
+void FilterExecutor::ProcessFunctionCeilFloor( FdoString *name, DataValue* argLeft )
+{
+ FdoDataType type = argLeft->GetType ();
+
+ // TODO: Int16 and Int32 are handled by Int64Value. Therefore for those types the retuned type will be always FdoDataType_Int64
+ // We need to define a specific Value classes for these types.
+ if ((FdoDataType_Double != type) && (FdoDataType_Single != type) && (FdoDataType_Decimal != type) && (FdoDataType_Int64 != type) &&
+ (FdoDataType_Int32 != type) && (FdoDataType_Int16 != type) )
+ {
+ FdoStringP allowedTypes = FdoStringP(FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_Double)) + L" / " +
+ FdoStringP(FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_Single)) + L" / " +
+ FdoStringP(FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_Decimal)) + L" / " +
+ FdoStringP(FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_Int32)) + L" / " +
+ FdoStringP(FdoCommonMiscUtil::FdoDataTypeToString(FdoDataType_Int16));
+
+ throw FdoException::Create (FdoException::NLSGetMessage(FDO_NLSID(FDO_88_INVALID_FUNCTION_ARG_TYPE), 1, name,
+ FdoCommonMiscUtil::FdoDataTypeToString(type),
+ (FdoString *)allowedTypes));
+ }
+ else
+ {
+ if ( argLeft->GetType() == Dvt_Null )
+ m_retvals.push ( m_pPool->ObtainNullValue() );
+ else
+ {
+ double d = 0.0;
+
+ if (FdoDataType_Double == type || FdoDataType_Decimal == type)
+ d = argLeft->GetAsDouble();
+ else if ( FdoDataType_Single == type )
+ d = argLeft->GetAsDouble();
+ else if ( FdoDataType_Int32 == type || FdoDataType_Int64 == type )
+ d = argLeft->GetAsInt64();
+ else if ( FdoDataType_Int16 == type )
+ d = argLeft->GetAsInt64();
+
+ d = ( wcscmp (name, FDO_FUNCTION_CEIL) == 0) ? ceil (d) : floor (d);
+
+ m_retvals.push (m_pPool->ObtainDoubleValue (d));
+ }
+ }
+}
+
FdoPropertyDefinition* GetProperty(FdoClassDefinition* cls, FdoString* propName )
{
FdoPropertyDefinition* prop = FdoPtr<FdoPropertyDefinitionCollection>(cls->GetProperties())->FindItem( propName );
@@ -679,7 +800,7 @@
void FilterExecutor::ProcessGeometryValue(FdoGeometryValue& expr)
{
- //m_tokens.push_back(new GeometryVal());
+ //m_tokens.push(new GeometryVal());
printf("geometry value\n");
}
Modified: branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.h
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.h 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/FilterExecutor.h 2007-03-08 20:28:04 UTC (rev 231)
@@ -151,6 +151,8 @@
void PushIdentifierValue(FdoIFeatureReader* reader, FdoString* name, FdoDataType type );
+ void ProcessFunctionCeilFloor( FdoString *name, DataValue* argLeft );
+
void ExecuteARGB(FdoFunction& function);
//pattern matching
Modified: branches/3.2.x/Providers/SDF/Src/Utils/Makefile.am
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/Makefile.am 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/Makefile.am 2007-03-08 20:28:04 UTC (rev 231)
@@ -55,6 +55,7 @@
-I../../Inc \
-I$(FDO)/Unmanaged/Inc \
-I$(FDO)/Unmanaged/Src/Nls \
+ -I$(FDOUTILITIES)/Common/Inc \
-I/usr/include
CXXFLAGS = @CXXFLAGS_SDF@ -DSQLITE
Modified: branches/3.2.x/Providers/SDF/Src/Utils/NullValue.cpp
===================================================================
--- branches/3.2.x/Providers/SDF/Src/Utils/NullValue.cpp 2007-03-07 16:58:55 UTC (rev 230)
+++ branches/3.2.x/Providers/SDF/Src/Utils/NullValue.cpp 2007-03-08 20:28:04 UTC (rev 231)
@@ -34,7 +34,7 @@
DataValueType NullValue::GetType()
{
- return Dvt_Null;
+ return (DataValueType)Dvt_Null;
}
DataValue* NullValue::Negate(DataValuePool* pPool)
More information about the fdo-commits
mailing list