[Tutor] Tuple ordering: What is going on here?

Kent Johnson kent_johnson at skillsoft.com
Sat Oct 23 02:53:01 CEST 2004


Are you sure the two databases were created the same way?

Anyway it is bad practice to rely on the results of select *. Code that 
relies on this will break when the database is changed. You should list the 
specific fields you want to read, then you won't have this problem.

Kent

At 11:47 PM 10/20/2004 -0500, Douglas N. Shawhan wrote:
>Hi, I am writing a simple little blog script using gadfly. (I know, it's 
>overkill! I'm playing here!)
>
>My problem is, when I run it on one machine, the inserts go in in one 
>order, on the other it is reversed.
>
>To wit:
>
>--------------------------------------------------
>import time, gadfly ,kjbuckets, os, time
>
>if not os.path.isfile('blogDB/blog.gfd'):
>    connection= gadfly.gadfly()
>    connection.startup('blog','blogDB')
>    c=connection.cursor()
>    c.execute("create table default (entryTime varchar, entry varchar)")
>    connection.commit()
>
>connection= gadfly.gadfly('blog','blogDB')
>c=connection.cursor()
>
>t=(time.time(), 'Happy Happy')
>
>c.execute("insert into default(entryTime, entry) values('%s','%s')"%t)
>c.execute("select * from default order by entryTime desc")
>
>for each in c.fetchall():
>    print each[0]
>    print each[1]
>connection.commit()
>-----------------------------
>
>Machine 1 output:
>1098333356.12
>Happy Happy
>1098333355.03
>Happy Happy
>1098333354.01
>Happy Happy
>1098333275.99
>Happy Happy
>1098333275.06
>Happy Happy
>1098333273.85
>Happy Happy
>1098333272.3
>Happy Happy
>
>Machine 2 output:
>
>Happy Happy
>1098333442.39
>Happy Happy
>1098333356.12
>Happy Happy
>1098333355.03
>Happy Happy
>1098333354.01
>Happy Happy
>1098333275.99
>Happy Happy
>1098333275.06
>Happy Happy
>1098333273.85
>Happy Happy
>1098333272.3
>
>-------------
>
>My question: is the reversal occouring in the tuple or in gadfly's output?
>
>Both machines are OpenBSD.
>
>machine1= OpenBSD 3.5 GENERIC#34 i386
>machine 2 = OpenBSD 3.3 MERCURY#5 i386
>
>Weird, man.
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list