Welcome to ESRI Blogs

Developer Tips - Using the Field Checker

This post was written by geodatabase Product Engineer James MacKay. James works on the geodatabase development team and is responsible for a lot of the geodatabase SDK that is generated.

The IFieldChecker interface provides a way to validate fields for a specific workspace before they’re created. Reserved keywords, special characters and maximum field name lengths are properties that vary between different types of workspaces and DBMSs; the field checker will not only detect fields that violate these rules, but it will generate a “fixed” fields collection with a similar (but valid) name. There are three common cases where field checkers are useful:

A field checker should always be used whenever an application allows users to manually enter field names, but it’s a good defensive programming pattern to use them all of the time. The following code shows how to validate fields prior to a CreateTable or CreateFeatureClass call.

Geoprocessing users: The geoprocessor also exposes field checking capability. See this article for more information.

public IFields ValidateFields(IWorkspace workspace, IFields fields)

{

      // Create and initialize a field checker.

      IFieldChecker fieldChecker = new FieldCheckerClass();

      fieldChecker.ValidateWorkspace = workspace;

                 

      // Generate a validated fields collection.

      IFields validatedFields = null;

      IEnumFieldError enumFieldError = null;

      fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

 

      // You can either notify the user of any errors or just skip this step.

      IFieldError fieldError = null;

      while ((fieldError = enumFieldError.Next()) != null)

      {

            Console.WriteLine("Error in field {0}: {1}", fieldError.FieldIndex, fieldError.FieldError);

      }

 

      // Return the validated fields.

      return validatedFields;

}

Published Friday, April 11, 2008 1:40 PM by brentardenpierce

Comments

# re: Developer Tips - Using the Field Checker

It doesn't seem like the ValidateTableName method checks for too long table names. It seems like feature class names in a personal gdb in ArcGIS 9.2 can be only 52 chars long (and table names a few chars longer), but such invalid names are passes the method.

Sunday, April 13, 2008 2:29 PM by mahj

# re: Developer Tips - Using the Field Checker

Hi mahj,

Thanks for the comment. Not detecting table names that are invalid on account of length is a current limitation of the field checker. To view the status of this issue, go to support.esri.com and search for "NIM034235" (you'll have to be logged in to get the result).

In most cases, checking the individual DBMS documentation is the best bet, but Personal Geodatabases are an exception, because of the way supporting tables are stored. I believe that the maximum length of a name you should give a PGDB dataset is 46 characters. Using more may result in errors while editing.

Cheers,

James

Friday, April 18, 2008 11:20 AM by mackayj80

# re: Developer Tips - Using the Field Checker

Hi James,

thanks for answering. Hope this get fixed, because it has caused problems in several ArcGIS-based applications. It is really nice to have the field checker that can detect these limitations, it makes the code database agnostic.

Regards,

Markus Hjärne

Friday, April 18, 2008 1:46 PM by mahj

# re: Developer Tips - Using the Field Checker

As a follow-up on this post, I'd like to note that the Geoprocessor class can also be used to validate individual field names and table names. More information, along with code examples, can be found here:

http://edndoc.esri.com/arcobjects/9.2/NET/1e84b146-18af-4e07-9cc2-41542f2ae91b.htm

Note that the limitation pointed out above (regarding long table names) also applies to the geoprocessor.

James

Sunday, June 15, 2008 11:54 AM by mackayj80
Anonymous comments are disabled