Στις 18/6/2013 1:22 πμ, ο/η MRAB έγραψε:
On 17/06/2013 21:44, John Gordon wrote:
In <MtKvt.47400$ja6.35986@fx18.am4> Alister
<alister.w...@ntlworld.com> writes:
> #update file's counter if cookie does not exist cur.execute('''UPDATE
> files SET hits = hits + 1, host = %s, lastvisit =
> %s WHERE url = %s''', (host, lastvisit, filename) )
>
> if cur.rowcount:
> print( " database has been affected" )
>
> indeed every time i select afilename the message gets printed bu then
> again noticing the database via phpmyadmin the filename counter is
> always remaining 0, and not added by +1
replase
if cur.rowcount:
print( " database has been affected" )
with print cur.rowcount()
rowcount isn't a method call; it's just an attribute. You don't need
the parentheses.
Well, you do need parentheses, it's just that you need them around the
'print':
if cur.rowcount:
print(cur.rowcount)
Okey print( cur.rowcount ) shows each time a select a fialenme from the
html table for downlaod that update affected 1 row.
Checking the database records instantly shown that in fact the counter
was increased by +1
Runing files.py turn all counter values to 0.
So, update works, its the reload of files.py the deleets the values.
# Delete those database records that do not exist as filenames inside
the path
for rec in data:
if rec not in filenames:
cur.execute('''DELETE FROM files WHERE url = %s''', rec )
# Load'em
for filename in filenames:
try:
# try to insert the file into the database
cur.execute('''INSERT INTO files (url, host, lastvisit) VALUES (%s,
%s, %s)''', (filename, host, lastvisit) )
except pymysql.ProgrammingError as e:
# Insertion failed, file already into database, skip this, go to next
filename
pass
These lines i dont how but they "manage" not to maintain the counter's value
--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list