Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48537 > unrolled thread
| Started by | Simpleton <support@superhost.gr> |
|---|---|
| First post | 2013-06-17 19:39 +0300 |
| Last post | 2013-06-18 03:22 +0300 |
| Articles | 9 on this page of 29 — 8 participants |
Back to article view | Back to comp.lang.python
Updating a filename's counter value failed each time Simpleton <support@superhost.gr> - 2013-06-17 19:39 +0300
Re: Updating a filename's counter value failed each time MRAB <python@mrabarnett.plus.com> - 2013-06-17 18:40 +0100
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-17 20:51 +0300
Re: Updating a filename's counter value failed each time John Gordon <gordon@panix.com> - 2013-06-17 17:40 +0000
Re: Updating a filename's counter value failed each time jt@toerring.de (Jens Thoms Toerring) - 2013-06-17 17:54 +0000
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-17 21:06 +0300
Re: Updating a filename's counter value failed each time jt@toerring.de (Jens Thoms Toerring) - 2013-06-17 18:32 +0000
Re: Updating a filename's counter value failed each time MRAB <python@mrabarnett.plus.com> - 2013-06-17 19:47 +0100
Re: Updating a filename's counter value failed each time jt@toerring.de (Jens Thoms Toerring) - 2013-06-17 19:16 +0000
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 20:33 +0000
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 19:05 +0000
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-17 22:30 +0300
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 20:26 +0000
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 20:43 +0000
Re: Updating a filename's counter value failed each time Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-17 19:30 -0400
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-18 03:25 +0300
Re: Updating a filename's counter value failed each time John Gordon <gordon@panix.com> - 2013-06-17 19:19 +0000
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-17 22:28 +0300
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 20:39 +0000
Re: Updating a filename's counter value failed each time John Gordon <gordon@panix.com> - 2013-06-17 20:44 +0000
Re: Updating a filename's counter value failed each time Alister <alister.ware@ntlworld.com> - 2013-06-17 20:49 +0000
Re: Updating a filename's counter value failed each time MRAB <python@mrabarnett.plus.com> - 2013-06-17 23:22 +0100
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-18 02:11 +0300
Re: Updating a filename's counter value failed each time Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-17 21:42 -0400
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-18 08:49 +0300
Re: Updating a filename's counter value failed each time Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-18 19:56 -0400
Re: Updating a filename's counter value failed each time Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-17 22:01 -0400
Re: Updating a filename's counter value failed each time Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-17 23:18 +0000
Re: Updating a filename's counter value failed each time Νίκος <support@superhost.gr> - 2013-06-18 03:22 +0300
Page 2 of 2 — ← Prev page 1 [2]
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2013-06-17 20:49 +0000 |
| Message-ID | <UDKvt.47402$ja6.28777@fx18.am4> |
| In reply to | #48563 |
On Mon, 17 Jun 2013 20:44:03 +0000, John Gordon wrote:
> In <MtKvt.47400$ja6.35986@fx18.am4> Alister <alister.ware@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.
My bad, Sorry if I confused Nicos further .
--
It's better to be wanted for murder that not to be wanted at all.
-- Marty Winch
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-06-17 23:22 +0100 |
| Message-ID | <mailman.3496.1371507741.3114.python-list@python.org> |
| In reply to | #48563 |
On 17/06/2013 21:44, John Gordon wrote:
> In <MtKvt.47400$ja6.35986@fx18.am4> Alister <alister.ware@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)
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <support@superhost.gr> |
|---|---|
| Date | 2013-06-18 02:11 +0300 |
| Message-ID | <kpo53s$sa6$1@news.grnet.gr> |
| In reply to | #48568 |
Στις 18/6/2013 1:22 πμ, ο/η MRAB έγραψε:
> On 17/06/2013 21:44, John Gordon wrote:
>> In <MtKvt.47400$ja6.35986@fx18.am4> Alister
>> <alister.ware@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!
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-06-17 21:42 -0400 |
| Message-ID | <mailman.3503.1371519731.3114.python-list@python.org> |
| In reply to | #48574 |
On Tue, 18 Jun 2013 02:11:55 +0300, ????? <support@superhost.gr> declaimed
the following:
>???? 18/6/2013 1:22 ??, ?/? MRAB ??????:
>> On 17/06/2013 21:44, John Gordon wrote:
>>> In <MtKvt.47400$ja6.35986@fx18.am4> Alister
>>> <alister.ware@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!
Just out of curiosity...
Do you ever COMMIT the changes.
cur.execute("update anything set something = whatever where that =
this")
without doing a con.commit() is just going to rollback the changes.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <support@superhost.gr> |
|---|---|
| Date | 2013-06-18 08:49 +0300 |
| Message-ID | <kposcm$jhs$1@news.grnet.gr> |
| In reply to | #48586 |
Στις 18/6/2013 4:42 πμ, ο/η Dennis Lee Bieber έγραψε:
>
> Do you ever COMMIT the changes.
>
> cur.execute("update anything set something = whatever where that =
> this")
>
> without doing a con.commit() is just going to rollback the changes.
committing the changes inst necessary neither is disconnecting from the
database, this are done automatically.
--
What is now proved was at first only imagined!
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-06-18 19:56 -0400 |
| Message-ID | <mailman.3563.1371599814.3114.python-list@python.org> |
| In reply to | #48596 |
On Tue, 18 Jun 2013 08:49:09 +0300, ????? <support@superhost.gr> declaimed
the following:
>???? 18/6/2013 4:42 ??, ?/? Dennis Lee Bieber ??????:
>
>committing the changes inst necessary neither is disconnecting from the
>database, this are done automatically.
>
NOT if the database adapter follows the db-api PEP/specification. PHP
and other clients may be operating in auto-commit, but any conforming
Python database adapter is supposed to turn auto-commit OFF when connecting
to the server.
>From PEP-249:
"""
.commit()
Commit any pending transaction to the database. Note that
if the database supports an auto-commit feature, this must
be initially off. An interface method may be provided to
turn it back on.
Database modules that do not support transactions should
implement this method with void functionality.
"""
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-06-17 22:01 -0400 |
| Message-ID | <mailman.3504.1371520901.3114.python-list@python.org> |
| In reply to | #48574 |
On Mon, 17 Jun 2013 21:42:00 -0400, Dennis Lee Bieber
<wlfraed@ix.netcom.com> declaimed the following:
I'm not going to inflict the group with the whole quote again, but...
What does the documentation for your db-api adapter (hmmm... have I even
installed one on my new computer <G>) indicate may happen if you get an
exception when adding a record? Hopefully it leaves the choice of rollback
vs commit up to you.
In pseudo-code:
con = db.connect(...)
cur = con.cursor()
for f in data:
if f not in somelist:
cur.execute("delete from table where field = %s",
f)
con.commit() #make deletes permanent in database
for f in otherdata:
cur.execute("select * from table where field = %s", f)
#while a try/except:pass might have the same result,
#if you don't check for details it could hide OTHER errors
if not cur.fetchall():
#record not found in database, go ahead and add it
cur.execute("insert into table (x, y, z) values (%s, %s, %s)",
(a, b, c) )
con.commit()
If you don't commit, and just exit the program, the database will throw
away all your changes.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-06-17 23:18 +0000 |
| Message-ID | <51bf994a$0$29872$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #48537 |
On Mon, 17 Jun 2013 19:39:16 +0300, Simpleton wrote: > Hello again, something simple this time: Have you read these links yet? http://sscce.org/ http://www.catb.org/esr/faqs/smart-questions.html Especially the first one. Until you read it, and follow it's advice, I will not answer your question. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <support@superhost.gr> |
|---|---|
| Date | 2013-06-18 03:22 +0300 |
| Message-ID | <kpo992$sa6$3@news.grnet.gr> |
| In reply to | #48537 |
Finally i made it!! Here it is:
#
=================================================================================================================
# Have 1:1 mapping of files <-> database records, delete spurious
#
=================================================================================================================
filenames = []
# Turn files from bytestrings => strings and trim them from their paths
for utf8_filename in utf8_filenames:
filenames.append( utf8_filename.decode('utf-8').replace(
'/home/nikos/public_html/data/apps/', '' ) )
# Create a database entry for each file
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.IntegrityError as e:
# Insertion failed, so, file already exist into database, skip this,
go to next
pass
# Delete those database records that do not correspond to files
cur.execute('''SELECT url FROM files''')
data = cur.fetchall()
for rec in data:
if rec[0] not in filenames:
cur.execute('''DELETE FROM files WHERE url = %s''', rec[0] )
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web