Select to view content in your preferred language

dbf file and SearchCursor

4442
4
09-08-2010 09:05 PM
MicheleH_DNReply
Deactivated User
Hi all,

I have a process that compares a feature class in SDE to records in a database and if there are any records in the database that do not appear in the feature class these are written out to a dbf file.

I then check if there are any rows in the dbf file and if there are create points for these and append them to the feature class in SDE.

I use a search cursor in a python script to check if there are any rows in the dbf file.  This worked fine with ArcGIS 9.3.1 but now with 10.0 it's acting like it doesn't know the dbf is there.  If I export it to a feature dataset it works as well but I really don't want to have to do that.

Does anyone know why this is happening or if there is a better way to do this?



This is my code at the moment:

GEOINVENT_dbf = "\\\\whk2k3sql02\\SDE_DataAdmin\\Transfer\\Import\\Table\\GEOTHERM.dbf"
try:
  print '==== Checking for empty DBF'
  rows = arcpy.SearchCursor(GEOINVENT_dbf)
  row = rows.next()
  if row:
    AppendAll()
  else:
    print "No rows in DBF"
except:
  arcpy.getmessages()


print '*****ALL DONE'




I've also tried the new fangled way of doing it and it doesn't work either - but not sure if I have it right:

GEOINVENT_dbf = "\\\\whk2k3sql02\\SDE_DataAdmin\\Transfer\\Import\\Table\\GEOTHERM.dbf"
try:
  print '==== Checking for empty DBF'
  for row in arcpy.SearchCursor(GEOINVENT_dbf):
    if row:
      AppendAll()
  else:
    print "No rows in DBF"
except:
  arcpy.getmessages()
 
print '*****ALL DONE'


Thanks for your help,
Michele.
0 Kudos
4 Replies
GünterDörffel
Frequent Contributor
Hi Michele,

I think it is just the
if row
that is not working as expected
I'd suggest you try:
GEOINVENT_dbf = "\\\\whk2k3sql02\\SDE_DataAdmin\\Transfer\\Import\\Table\\GEOTHERM.dbf"
rows,row = None,None
try:
  print '==== Checking for empty DBF'
  rows = arcpy.SearchCursor(GEOINVENT_dbf)
  row = rows.next()
  if row <> None:
    AppendAll()
  else:
    print "No rows in DBF"
except:
  arcpy.getmessages()

del rows,row
print '*****ALL DONE'
0 Kudos
MicheleH_DNReply
Deactivated User
Thanks for that - I gave it a try but it's definately the SearchCursor row that is throwing the error. When I step through the code it doesn't even get past this line.

I get the following error in Wing after that line:


RuntimeError: ERROR 999999: Error executing function.
The Field type is invalid or unsupported for the operation.
The Field type is invalid or unsupported for the operation.
File "k:\PythonScripts\PythonScripts92\AppendGeoInventSDE92.py", line 66, in <module>
  rows = arcpy.SearchCursor(GEOINVENT_dbf)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 804, in SearchCursor
  return gp.searchCursor(*args)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 357, in searchCursor
  self._gp.SearchCursor(*gp_fixargs(args)))


Do you have any other ideas?  I might just transfer my table to a geodatabase - might be the easiest fix but I'd like to find out what is going on here.  It's really pretty annoying!
0 Kudos
GünterDörffel
Frequent Contributor
Hi Michele,

I had tried with "any" dbf file ... and it worked ... so the only thing I can assume is that your GEOTHERM dbf has some "issue" - so yes, loading it into a Geodatabase (just for a try) might be worth the effort
0 Kudos
MicheleH_DNReply
Deactivated User
Yip - I believe you are right - a problem with my dbf file.  Thanks for your help.
0 Kudos