Onderstaande code werkt. Echter ik ben gedwongen om na elke delete statement een commit te maken. Aangezien deze database op een NAS staat wil ik liever 1 commit uit voeren na alle queries. Als ik dat doe dan wordt er echter niks verwijderd. Ik krijg geen documenten tevoorschijn die precies laten zien wat het effect van cursors en transacties is in python. Ook met een cursor krijg ik deze queries niet allemaal in 1x gecommit. Heeft iemand hier ervaring mee?
Python:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| today = date.today() oldYear=today.year-2 oldMonth=today.month-3 if(oldMonth < 1): oldMonth=today.month-3+12 oldYear=oldYear-1 oldDate=date(oldYear, oldMonth, 1) oldDateString=oldDate.strftime("%Y-%m-%d")+" 23:59:59" #query="delete from PRORATEFACTOR where validto < " + oldDateString query = "SELECT origincitycode,destinationcitycode,count(validto) as freq from proratefactor where validto>=? group by origincitycode,destinationcitycode having count(validto)>=1" print query, oldDateString con = sqlite3.connect(gNewSqlite) aCursor = con.cursor() aCursor.execute(query,(oldDateString,)) #print con.total_changes, 'row(s) deleted in ProrateFactor table' pfArray = aCursor.fetchall() pfSize = len(pfArray); aCursor.close() print "Will now delete old prorate factor rows, this can take up to 10 minutes depending on NAS etc.." i=0; for row in pfArray: i = i + 1 if i % 4000 == 0: print (100 * i)/pfSize, "%" con.execute ("Delete from proratefactor where origincitycode=? and destinationcitycode=? and validto<?",(row[0],row[1],oldDateString)) con.commit() con.close() |