use_deleted

85 views
Skip to first unread message

aklaver

unread,
Feb 8, 2013, 1:46:43 PM2/8/13
to Python dBase
I just noticed that use_deleted = False does not seem to have any
effect in the latest version:

In [7]: dbf.version
Out[7]: (0, 94, 5)

On an older version:

In [2]: dbf.version
Out[2]: (0, 90, 0)

it does work.

aklaver

unread,
Feb 8, 2013, 4:52:08 PM2/8/13
to Python dBase
Did some digging:

1) use_deleted is not in the 0.94 code. Not sure why an exception is
not raised when you use it.

2) A distant memory bubbled up that I had this conversation before and
it turns I did:

https://groups.google.com/group/python-dbase/browse_thread/thread/a175dc53d8bc3ccd#

So what was your final decision on this?

Ethan Furman

unread,
Feb 8, 2013, 5:22:56 PM2/8/13
to python...@googlegroups.com
I'm glad you remembered that conversation, 'cause I had completely
forgotten it; I stumbled over it myself about a week and a half ago,
but didn't have time to chase down why the change had occurred.

I went with a modified option 1: get rid of .use_deleted and go to the
record anyway. The deleted flag is just that: a flag. The record is
still present and still available. If you don't want to use it, either
check if the record has been deleted (dbf.is_deleted(record)) or create
an index that doesn't include the deleted records... or pack the table
and actually remove the records for good.

Thanks for your feedback then, and your recollection now! :)

~Ethan~

Adrian Klaver

unread,
Feb 8, 2013, 5:28:09 PM2/8/13
to python...@googlegroups.com, Ethan Furman
In the interim I went the dbf.is_deleted(record) route. I am unclear as
to how to make the index method work, in particular where I create the
index and on what?

>
> ~Ethan~
>


--
Adrian Klaver
adrian...@gmail.com

Ethan Furman

unread,
Feb 8, 2013, 5:39:40 PM2/8/13
to python...@googlegroups.com
On 02/08/2013 02:28 PM, Adrian Klaver wrote:
> In the interim I went the dbf.is_deleted(record) route. I am unclear as
> to how to make the index method work, in particular where I create the
> index and on what?

table = dbf.Table('some_table')
table.open()

active_records = table.create_index(lambda rec:
dbf.recno(rec) if not dbf.is_deleted(rec) else dbf.DoNotIndex
)

for record in active_records:
# do something with your definitely not deleted record :)


The `dbf.recno(rec)` portion can be substituted with whatever sorting
criteria you desire; and, of course, it's clearer if you use a `def`
function instead of a `lambda`:

def active_employees(rec):
"sorts employees by department, last_name; ignores deleted records"
if dbf.is_deleted(rec):
return dbf.DoNotIndex
return rec.department, rec.last_name

active_employee_index = table.create_index(active_employees)


Hope this helps.

~Ethan~1

Adrian Klaver

unread,
Feb 8, 2013, 5:43:25 PM2/8/13
to python...@googlegroups.com, Ethan Furman
Yes, now I understand.
>
> ~Ethan~1
>

Thanks,
--
Adrian Klaver
adrian...@gmail.com
Reply all
Reply to author
Forward
0 new messages