2

I'm very new to ArcObjects and working on an ArcMap addin. I'm having some trouble with understanding the results I'm receiving from my queryFilter. It seems doing a ITable.Search(queryFilter, true) [recycling set to false nets the same results] hits the default table version but returns a cursor that iterates over the current version (active in ArcMap) of the table.

In ArcMap when I create a new version of my geodatabase and run my addin tool I get correct results. However, if I make an edit in the centerline_sequence table in ArcMap and then run the tool again. It appears to run the query against the default or parent version as it returns rows that should have been excluded by my edit. When the cursor cycles through the results I get the edited rows which should have been excluded from the results due to the query select statement. The real oddity to me is the cursor rows include the record edits which would have excluded that record from the results.

I have referenced the table originally like this:

IWorkspace workspace = ((IDataset)map.Layer[0]).Workspace;
featureWorkspace = (IFeatureWorkspace)workspace;
centerlineSequenceTable = featureWorkspace.OpenTable(tableName);

Then thinking I wasn't getting the current version I got the table this way:

IFeatureWorkspace cws = (IFeatureWorkspace)this.childVersion;
centerlineSequenceTable = cws.OpenTable(tableName);

However both showed they were the same active version in ArcMap.

In my queryFilter.WhereClause I pass a statement that looks for a records which include a specific field value. I have tested this clause in SQL Developer and believe it is returning correct results.

I search the centerlineSequenceTable like:

IQueryFilter2 queryFilter = new QueryFilterClass();
queryFilter.WhereClause = whereString;
queryFilter.SubFields = objectIdField + "," + routeIdField + "," + roadwayIdGuidField + "," + dominanceValueField;
IQueryFilterDefinition queryFilterDefinition = (IQueryFilterDefinition)queryFilter;
queryFilterDefinition.PostfixClause = "ORDER BY " + roadwayIdGuidField + ", " + routeIdField;
ICursor cursor = centerlineSequenceTable.Search(queryFilter, true);

Gather my results like so:

IRow row = cursor.NextRow();
while (row != null)
{
…
row = cursor.NextRow();
}

I'm not much of an ArcGIS user so quite possibly I'm just expecting something that isn't going to happen in my workflow without reconciling the current version or I'm missing something in how I reference and/or search the table.

3

Yes, sort of. The problem here is you're accessing directly from the database which may or may not be aware of any edits; edit reside in a different database in your TEMP directory (Scratch Workspace) and don't make it to the real database until you save your edits (commit). You really should be searching from the table object derived from the map thusly:

ILayer firstLayer = ArcMap.Document.FocusMap.Layer[0]; // if you're sure it's the top layer
if (firstLayer is IFeatureLayer)// make sure it's really a feature layer
{ 
    IFeatureLayer firstFeatureLayer = (IFeatureLayer)firstLayer; // not used after this

    // get all the tables in the map
    IStandaloneTableCollection mapTables = (IStandaloneTableCollection)ArcMap.Document.FocusMap;
    IStandaloneTable thisTable;
    ITable centerlineSequenceTable = null;
    // look at each table and see if it has the right name
    for (int tableIndex = 0; tableIndex < mapTables.StandaloneTableCount; tableIndex++)
    {
        thisTable = mapTables.get_StandaloneTable(tableIndex);
        if (thisTable.Name == TableName)
        {
            // this is the right one, now get the table
            // and break the loop
            centerlineSequenceTable = thisTable.Table;
            break;
        }                   
    }

    // the table looks identical to getting it from the workspace
    // but now it will respect edits as they are made
    if (centerlineSequenceTable != null)
    {
        IQueryFilter queryFilter = new QueryFilterClass(); 
        queryFilter.WhereClause = whereString;
        queryFilter.SubFields = objectIdField + "," + routeIdField + "," + roadwayIdGuidField + "," + dominanceValueField;
        IQueryFilterDefinition queryFilterDefinition = (IQueryFilterDefinition)queryFilter;
        queryFilterDefinition.PostfixClause = "ORDER BY " + roadwayIdGuidField + ", " + routeIdField;
        ICursor cursor = centerlineSequenceTable.Search(queryFilter, true);
    }
}

So the table is in the map as a Standalone Table and you get it from there... it would only be if you can't find it in the map that you would open it from where it lives. Of course if you're editing it in a different ArcMap session then of course the edits aren't visible - they never are until you save your edits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.