Database Query Contains Old Data

giraffeboy at gmail.com giraffeboy at gmail.com
Wed May 21 09:22:02 EDT 2008


On May 21, 1:49 pm, "Jerry Hill" <malaclyp... at gmail.com> wrote:

> Did you remember to commit your changes before re-running the report?
> Python's DB API requires that any auto-commit feature of the
> underlying database be turned off by default, so you are required to
> commit changes yourself.  If you're used to having auto-commit turned
> on, this can be confusing.

I did and I confirmed this by modifying the data, selecting it from
the mysql command line client to verify the changes, then running the
report again. If I exit the application and then start it again,
everything works as expected until the second instance of the report
is run. I have a feeling it has something to do with there already
being an instance of the report class, but I can't work out how to
destroy it and aren't really sure how to remove the references to it
either. I added a print statement to the code and it displays a row
that doesn't exist any more. Code, output of print statement and
result from the mysql client shown below.

Andrew


Code:
#Get all the mileages and add them together for the month:
curs.execute('SELECT date, mileage, name FROM mileage, agents WHERE
mileage.agent = agent.rowid AND date >= CAST(%s AS DATE) AND date <
CAST(%s AS DATE) AND mileage.agent=%s ORDER BY date', (fromdate,
todate, agentid))
for row in curs:
   month = str(row[0])[:7]
   print row[1], month

Output:
100.0 2008-03

MySQL Output just prior to running the report:
mysql> select * from mileage;
+-------+------------+---------+---------+-------+
| rowid | date       | mileage | vehicle | agent |
+-------+------------+---------+---------+-------+
|     1 | 2008-04-28 |  875.63 |       3 | 3     |
|     2 | 2008-04-28 | 1188.13 |       6 | 6     |
|     3 | 2008-04-28 |  676.88 |       4 | 4     |
|     4 | 2008-04-21 | 1111.25 |       6 | 6     |
|     5 | 2008-04-21 | 1126.88 |       3 | 3     |
|     6 | 2008-04-28 | 1029.38 |       7 | 8     |
|     7 | 2008-04-21 |  953.13 |       7 | 8     |
|     8 | 2008-04-21 |  675.63 |       4 | 4     |
|     9 | 2008-04-14 |  891.88 |       3 | 3     |
+-------+------------+---------+---------+-------+
9 rows in set (0.00 sec)

As you can see there's no row with a mileage of 100 with the correct
month.



More information about the Python-list mailing list