Python SQLITE3 Inserting Backwards
Question: I have a small piece of code which inserts some data into a database. However,
the data is being inserting in a reverse order.  
If i "commit" after the for loop has run through, it inserts backwards, if i
"commit" as part of the for loop, it inserts in the correct order, however it
is much slower.  
How can i commit after the for loop but still retain the correct order?

    
    
    import subprocess, sqlite3
    output4 = subprocess.Popen(['laZagne.exe', 'all'], stdout=subprocess.PIPE).communicate()[0]
    lines4 = output4.splitlines()
    
    conn = sqlite3.connect('DBNAME')
    cur = conn.cursor()
    
    
    for j in lines4:
        print j
        cur.execute('insert into Passwords (PassString) VALUES (?)',(j,))
    conn.commit()
    conn.close()
    


Answer: You can't rely on _any_ ordering in SQL database tables. Insertion takes place
in an implementation-dependent manner, and where rows end up depends entirely
on the storage implementation used and the data that is already there.

As such, no reversing takes place; if you are selecting data from the table
again and these rows come back in a reverse order, then that's a coincidence
and not a choice the database made.

If rows must come back in a specific order, use `ORDER BY` when selecting. You
could order by `ROWID` for example, which _may_ be increasing monotonically
for new rows and thus give you an approximation for insertion order. See
[_ROWIDs and the INTEGER PRIMARY
KEY_](http://sqlite.org/lang_createtable.html#rowid).

