0

I wrote an ArcPy script which uses cursors and it works fine with shapefiles. However, it does not work if I execute the same thing in a personal geodatabase. Should I use different format for a personal geodatabase such as regular parenthesis, single quote etc.

Here is the code:

import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\P2P\DMP_GeoDB_EXP.mdb\Featuredataset'
workspace = arcpy.env.workspace

with arcpy.da.UpdateCursor('featureclass', ["PermitNo", "AppType", "FeatCLS", 
  "Contact", "National_ID", "Source","Type_Flag", "Calc"]) as cursor:
    for row in cursor:
        cursor.deleteRow()

then error I am getting:

for row in cursor:
RuntimeError: Too few parameters. Expected 3.

I am using ArcMap 10.6

1

In ArcGIS a feature_class name MUST be unique within a GDB. ie: if Dataset_AA contains Feature_Class_AA then Feature_Class_AA cannot exist anywhere else in the same GDB regardless of whether it is in a Dataset or not.

take this schema for example:

update_cursor_testing_schema.png

in this map: enter image description here and this script:

import arcpy
arcpy.env.overwriteOutput = True
feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\thisdoesntexist\Boundaries'

with arcpy.da.UpdateCursor(feature_class, ["PermitNo", "AppType", "FeatCLS",
  "Contact", "National_ID", "Source","Type_Flag", "Calc"]) as cursor:
    for row in cursor:
        cursor.deleteRow()

One would expect this not to run for a feature class in the root of the GDB (as Boundaries is), and they'd be right due to the invalid Dataset specified. The same is true even for a featue class that IS in a dataset (as Boundaries_AA is). Changing feature_class to:

feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\thisdoesntexist\Boundaries_AA'

Fails to execute as well.

If the argument to UpdateCursor has Either an Invalid Dataset Or Invalid FeatureClass, the script will fail.

Here's where things get weird:

If BOTH the Dataset and FeatureClass exist, arcpy will successfully delete the features from the feature class EVEN if the feature class is NOT in the Dataset!

If we change feature_class to:

feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\Dataset_AA\Boundaries_BB'

Notice that Boundaries_BB is NOT in Dataset_AA. The results are painfull: enter image description here As you can see, Boundaries_BB(the feature class) was deleted even though it was NOT in Dataset_AA.

consider these scenarios for feature_class:

feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\Dataset_AA\Boundaries'
feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\Boundaries_AA'

and a more troubling result: enter image description here

Not once did we pass UpdateCursor a fully qualified path name to our feature_classes ... and yet, all of our data is deleted.

If you're brave enough, I uploaded the Map, Scripts, & DB to dropbox.

These results may be unique to Personal GeoDatabases. File Geodatabases may not exhibit this exact behavior.

| improve this answer | |
  • Thank you @Robbie Symborski ! This situation is weirder than I thought. I figured it is easier to export the Feature class as shapefile do all processes on it then import back that to as feature class. I will convert the database to file geodatabase in future as we migrate to ArcGIS PRO anyway. I hope it will be easier by then. – Amadeus Sep 30 '19 at 13:42
  • 1
    On the contrary ... it most cases, File GDB's have more robust api support, more efficient storage mechanism and less headaches than shapefiles. Don't get me wrong, I still do a lot of work in shapefiles ... but i'm quickly being swayed as I try to grasp all the tricks that python brings to the table. – Robbie Symborski Oct 1 '19 at 18:22
0

Try using a feature class in the database as your "in_table" parameter, which is currently set to 'ffff'. I assume you want to update the 'Boundaries' feature class, and you do not need to set the env.workspace. Code should look something like this if you want to remove rows from the Boundaries feature class in your DMP_GeoDB_EXP.mdb database:

import arcpy
arcpy.env.overwriteOutput = True
feature_class = r'C:\P2P\DMP_GeoDB_EXP.mdb\Boundaries'

with arcpy.da.UpdateCursor(feature_class, ["PermitNo", "AppType", "FeatCLS", 
  "Contact", "National_ID", "Source","Type_Flag", "Calc"]) as cursor:
    for row in cursor:
        cursor.deleteRow()
| improve this answer | |
  • 1
    An unbounded DA Cursor to just delete rows is fiendishly expensive, compared to TruncateTable. See gis.stackexchange.com/questions/24969 – Vince Sep 27 '19 at 23:08
  • 1
    arcpy.da.UpdateCursor has always given me problems with personal GDB's ... moving the data to a File GeoDatabase has often solved the problem for me. Your mileage may vary. – Robbie Symborski Sep 29 '19 at 18:50
0

I just want to clarify for other people. I was using the wrong field names that was causing the error (RuntimeError: Too few parameters. Expected 3). 3 of field names were slightly different than what was in the geodatabase. I know it is a silly mistake but it happens.

| improve this answer | |

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.