Welcome to ESRI Blogs

Developer Tips - Qualified field names in ArcSDE

This post was provided by geodatabase Product Engineer James MacKay.

There are fourteen field names that cause fields to behave slightly different in ArcSDE. They are:

AREA

POINTS

FID

EMINX

EMINY

EMINZ

MIN_MEASURE

LEN

NUMOFPTS

ENTITY

EMAXX

EMAXY

EMAXZ

MAX_MEASURE

These field names conflict with internal ArcSDE properties used for storing geometries. Fields that use these names can be created like any other fields, but when they’re retrieved – or when using FindField to find their indexes in a fields collection – they will be qualified with the username and table name (and database name, if applicable).

 This means a field named “Len” could appear as “wgretzky.Highways.Len” if the DBMS is Oracle, or as “sde.mlemieux.Highways.Len” if the DBMS is SQL Server.

The best plan is to avoid using these field names, but when that isn’t possible, a few code changes can be made to handle these cases. The most noticeable effect is that calls to FindField with the unqualified field name will return a value of -1 (indicating that the field could not be found).

It’s the developer’s responsibility to either qualify the field name with the username and table name (and database name, if applicable), or to find the field’s index with IFields2.FindFieldIgnoreQualification (this will find both qualified and unqualified field names).

The code below shows how to retrieve a field with the FindFieldIgnoreQualification method:

private IField GetFieldByName(IWorkspace workspace,IObjectClass objectClass, String fieldName)

{

      // Cast the workspace to the ISQLSyntax interface.

      ISQLSyntax sqlSyntax =(ISQLSyntax)workspace;

                      

      // Get the field's index from the fields collection.

      IFields2 fields2 = (IFields2)objectClass.Fields;

      int fieldndex = -1;

      fields2.FindFieldIgnoreQualification(sqlSyntax, fieldName, out fieldIndex);

 

      // If the field was found, return it.

      if (fieldIndex >= 0)

      {

        return fields2.get_Field(fieldIndex);

      }

       else

      (

        return null ;

      }

}

Published Wednesday, April 30, 2008 12:13 PM by JonMurphy

Comments

No Comments
Anonymous comments are disabled