3

I'm working with a visual fox pro database (.dbf file) and I'm using the dbf python module. Heres an example:

myDb = VfpTable('table.dbf');

Now I can exclude deleted items with this by doing the following:

myDb._use_deleted = None; 

My question(s) is/are is there an easier way to do this? Maybe a function? I hate accessing "private" variables. Also, without setting this property, how can I determine if a row has been deleted? They are still technically in the database so is there a flag? A hidden column? Maybe someone with more knowledge of this python module or Visual Fox Pro has some ideas.

Class Skeleton
  • 2,913
  • 6
  • 31
  • 51
Dalton Conley
  • 1,599
  • 2
  • 28
  • 36
  • 1
    On the VFP side, Deleted() will return true or false for the current record in the current table. The trouble is the notions of 'current' record' and 'current table' are really an xBase thing and don't necessarily translate into a record set approach. – Alan B Mar 25 '11 at 09:28

2 Answers2

4

Using the dbf module referenced above what you want is:

myDB.use_deleted = False

and for individual records:

for record in myDB:
    if record.has_been_deleted:
        print "record %d is marked for deletion!" % record.record_number

To physically remove the records from the table:

myDB.pack()

disclosure: I am the author.

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • 1
    Ahh I thank you for your input. I feel as if I've mastered this module, but now that I'm talking to the real pro, I might have some questions for you in the future. – Dalton Conley Jul 20 '11 at 15:25
0

Stop me if you've heard this one before: """I have a DBF reading module (pydbfrw) which I've been meaning to release "one of these days"."""

It was easier to add the functionality that you want than to puzzle through the source code of the dbf module:

>>> import pydbfrw
>>> d = pydbfrw.DBFreader('/devel/dbf/all_files/del.dbf')
>>> list(d)
[['fred', 1], ['harriet', 4]]
>>> d.get_field_names()
['NAME', 'AMT']
>>> d = pydbfrw.DBFreader('/devel/dbf/all_files/del.dbf', include_deleted=True)
>>> list(d)
[[False, 'fred', 1], [True, 'tom', 2], [True, 'dick', 3], [False, 'harriet', 4]]
>>> d.get_field_names()
['deleted__', 'NAME', 'AMT']
>>> for rowdict in d.get_dicts():
...     print rowdict
...
{'deleted__': False, 'name': 'fred', 'amt': 1}
{'deleted__': True, 'name': 'tom', 'amt': 2}
{'deleted__': True, 'name': 'dick', 'amt': 3}
{'deleted__': False, 'name': 'harriet', 'amt': 4}
>>> for rowtup in d.get_namedtuples():
...     print rowtup
...
Row(deleted__=False, name='fred', amt=1)
Row(deleted__=True, name='tom', amt=2)
Row(deleted__=True, name='dick', amt=3)
Row(deleted__=False, name='harriet', amt=4)
>>>
John Machin
  • 81,303
  • 11
  • 141
  • 189
  • My apologies. Im weary on using your module simply because I don't know enough about it. Although, you could be really amazing at documenting. – Dalton Conley Mar 29 '11 at 15:53