TestSchemaLock

Synthèse

Tests if a schema lock can be acquired for a feature class, table, or feature dataset. Tools that alter schema will require a schema lock to be placed on the input data. The Add Field tool is an example of such a tool. If the tool requires a schema lock and is unable to acquire one when the tool is run, an appropriate error message is returned. Scripts that use such tools should test if a schema lock can be acquired on the input data. The TestSchemaLock function will not actually apply a schema lock on the input data, but will return a Boolean.

Syntaxe

TestSchemaLock (dataset)
ParamètreExplicationType de données
dataset

The input data to be tested if a schema lock can be applied.

String
Valeur renvoyée
Type de donnéesExplication
Boolean

Returns a Boolean indicating if a schema lock can be applied to the input dataset.

  • TrueA schema lock can be applied to the dataset.
  • FalseA schema lock cannot be obtained on the dataset.

Exemple de code

TestSchemaLock example

Returns a Boolean True if exclusive lock can be applied to dataset.

import arcpy

data = arcpy.GetParameterAsText(0)

# Test if a schema lock can be applied, and if so, add a new field
#
if arcpy.TestSchemaLock(data):
    arcpy.AddField_management(data, "Flag", "LONG")
else:
    print("Unable to acquire the necessary schema lock to add the new field")

Dans cette rubrique