[fdo-users] ISelectAggregates: how use it to COUNT?

Dan Stoica dan.stoica at autodesk.com
Sun Dec 27 15:41:29 EST 2009


What error are you getting? By looking at the code I didn't see anything obviously wrong.

-----Original Message-----
From: fdo-users-bounces at lists.osgeo.org [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Matteo
Sent: Sunday, December 27, 2009 1:39 PM
To: fdo-users at lists.osgeo.org
Subject: RE: [fdo-users] ISelectAggregates: how use it to COUNT?


Hi Dan,
   I've write this function to calcolate the Count of row in a  SHP file but
I get an error when I execute the IselectAggrecates object
Can you help me?
Regards 
Matteo

Function INTCalcolaKey(ByVal objConn As Connections.IConnection, ByVal
strClassName As String) As Integer
        Try

        
            Dim objCmdSA As Commands.Feature.ISelectAggregates =
objConn.CreateCommand(Commands.CommandType.CommandType_SelectAggregates)
            objCmdSA.SetFeatureClassName(strClassName)
            objCmdSA.Distinct = False
            Dim intCount As Int64
            Dim objSelectIds As OSGeo.FDO.Commands.IdentifierCollection =
objCmdSA.PropertyNames

            objSelectIds.Clear()
            Dim objExp As OSGeo.FDO.Expression.Expression =
OSGeo.FDO.Expression.Expression.Parse("Count('FEATID')")



            Dim objCount As OSGeo.FDO.Expression.ComputedIdentifier = New
OSGeo.FDO.Expression.ComputedIdentifier("CONT", objExp)
            objSelectIds.Add(objCount)
            Dim objFR As OSGeo.FDO.Commands.Feature.IDataReader =
objCmdSA.Execute()
            While objFR.ReadNext
                intCount = objFR.GetInt64("CONT")
            End While
            objFR.Close()
            objCmdSA.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function


Dan Stoica wrote:
> 
> Hi Matteo,
> 
> In general you can check the unit tests (basically any provider) for
> virtually any snippet you need.
> 
> For Count(), I've copied this from the SHP unit tests:
> 
>         FdoPtr<FdoISelectAggregates> select =
> (FdoISelectAggregates*)mConnection->CreateCommand
> (FdoCommandType_SelectAggregates);
>         select->SetFeatureClassName (className);
>         select->SetDistinct(false);
>         FdoPtr<FdoIdentifierCollection> selectedIds =
> select->GetPropertyNames();
>         selectedIds->Clear();
>        
> selectedIds->Add(FdoPtr<FdoComputedIdentifier>(FdoComputedIdentifier::Create(L"Total",
> FdoPtr<FdoExpression>(FdoExpression::Parse(L"Count(\"Date\")")))));
>         FdoPtr<FdoIDataReader> datareader = select->Execute ();
>         long count = 0;
>         while (datareader->ReadNext ())
>         {
>             FdoInt64 total = datareader->GetInt64(L"Total");
>             CPPUNIT_ASSERT_MESSAGE("Count wrong", 4L == total);
>             count++;
>         }
> 
>  Dan.
> 
> -----Original Message-----
> From: fdo-users-bounces at lists.osgeo.org
> [mailto:fdo-users-bounces at lists.osgeo.org] On Behalf Of Matteo
> Sent: Tuesday, December 22, 2009 3:50 PM
> To: fdo-users at lists.osgeo.org
> Subject: [fdo-users] ISelectAggregates: how use it to COUNT?
> 
> 
> Hi all,
>   I need to know how I can use the ISelectAggregates command? (Ex. how I
> can
> do to get the count the object? or to get the MAX of a property?
> Regards
> Matteo
> -- 
> View this message in context:
> http://n2.nabble.com/ISelectAggregates-how-use-it-to-COUNT-tp4205687p4205687.html
> Sent from the FDO Users mailing list archive at Nabble.com.
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> _______________________________________________
> fdo-users mailing list
> fdo-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fdo-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/ISelectAggregates-how-use-it-to-COUNT-tp4205687p4221192.html
Sent from the FDO Users mailing list archive at Nabble.com.
_______________________________________________
fdo-users mailing list
fdo-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/fdo-users


More information about the fdo-users mailing list