mysql solution

Ferrous Cranus nikos.gr33k at gmail.com
Thu Jan 24 07:01:40 EST 2013


Τη Πέμπτη, 24 Ιανουαρίου 2013 1:25:20 μ.μ. UTC+2, ο χρήστης Lele Gaifax έγραψε:
> Ferrous Cranus <nikos.gr33k at gmail.com> writes:
> 
> 
> 
> > I;am now convinced the hash solution isn't reversible and also isn't
> 
> > unique.
> 
> 
> 
> Great!
> 
> 
> 
> > how is the mysql statement is going to find the 'pin' to update the
> 
> > specific record.
> 
> 
> 
> The simplest way is to execute a SELECT just after the insertion, doing
> 
> a
> 
> 
> 
>   SELECT pin FROM counters WHERE page = %s
> 
> 
> 
> I don't use MySQL, so I can't say if it supports "INSERT ... RETURNING ..."
> 
> SQL syntax: should it, then you could insert the data and fetch
> 
> the pin in one shot, with something like
> 
> 
> 
>   INSERT INTO counters (page, hits) VALUES (%s, %s) RETURNING (pin)
> 
> 
> 
> ciao, lele.
> 
> --
> 
> nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
> 
> real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
> 
> lele at metapensiero.it  |                 -- Fortunato Depero, 1929.

I just tried this statement:

==========================================
cursor.execute( '''INSERT INTO counters(page, hits) VALUES(%s, %s) RETURNING (pin) 
								ON DUPLICATE KEY UPDATE hits = hits + 1''', (htmlpage, 1) )
	except MySQLdb.Error, e:
		print ( "Query Error: ", sys.exc_info()[1].excepinfo()[2] )
==========================================

and the error python tells me is:

<type 'exceptions.AttributeError'>: 'ProgrammingError' object has no attribute 'excepinfo' 
      args = ("'ProgrammingError' object has no attribute 'excepinfo'",) 
      message = "'ProgrammingError' object has no attribute 'excepinfo'"



More information about the Python-list mailing list