Author: Dennis Lee Bieber
Posted: 2012-05-02 at 13:43:17
On Wed, 02 May 2012 09:13:35 -0500, Bill House
<wch-tech@house-grp.net> declaimed the
following in gmane.comp.python.dabo.user:
> Given a dbase table called
>
> files
>
> with a structure of
>
> md5sum char 30
> path char 450
> file_name char 220
>
> and indexed (or sorted) in the order of
>
> md5sum + path + file_name
>
> run the following script
>
> <CODE>
> ********************** mark_del.prg **********************
> *mark all records with identical md5sums as deleted
> *except for last one
You apparently have no primary key or other means of identifying
order... Otherwise I'd suggest ordering IN REVERSE so the first
appearance of an md5sum value is the one to keep, and any subsequent
identical records are to be deleted. Oh well... Hypothetical is that the
one to keep is the one whose path/name sorts last...
#pseudo code including raw database operations
csr = con.cursor() #get a cursor for the database connection
csr.execute("""select md5sum, path, file_name
from files
order by md5sum desc,
path desc,
file_name desc""")
lastMD5 = None
for rec in csr.fetchall(): #I'm not sure if you can issue a new
#command on the cursor before
#reading all the data
if rec[0] == lastMD5:
#substitute the appropriate placeholder;
#MySQLdb uses %s, SQLite3 uses ?
csr.execute("""delete from files where
md5sum = %s and
path = %s and
file_name = %s""",
(rec[0], rec[1], rec[2]))
else:
lastMD5 = rec[0]
csr.close()
con.commit() #all the deletes now happen
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/jnrv83$a9$1@dough.gmane.org