vendredi 20 mars 2015

How to retrieve data from SQLite faster in python

I have the following info in my database (example):



longitude (str): 70.74
userid (str): 12


This is how i fetch it:



import sqlite3 as lite
con = lite.connect(dbpath)
with con:
cur = con.cursor()
cur.execute('SELECT latitude, userid FROM message')
con.commit()
print "executed"
while True:
tmp = cur.fetchone()
if tmp != None:
info.append([float(tmp[0]),int(tmp[1])])
else:
break


To get the same info on the form [70.74, 12] I'm aware that I should save the latitude and userid as real (to conserve any leading zeros), not string - but what else can I do to speed up this process, as the number of values that are being read is quite high?


Aucun commentaire:

Enregistrer un commentaire