How to retrieve data from SQLite faster in python -


i have following info in database (example):

longitude (real): 70.74 userid (int): 12 

this how fetch it:

import sqlite3 lite con = lite.connect(dbpath)     con:     cur = con.cursor()     cur.execute('select latitude, userid message')     con.commit()     print "executed"     while true:         tmp = cur.fetchone()         if tmp != none:             info.append([tmp[0],tmp[1]])         else:             break 

to same info on form [70.74, 12] else can speed process? @ 10,000,000 rows takes approx 50 seconds, i'm aiming 200,000,000 rows - never through this, possible memory leak or that?

from sqlite3 documentation:

a row instance serves highly optimized row_factory connection objects. tries mimic tuple in of features.

since row closely mimics tuple, depending on needs may not need unpack results.

however, since numerical types stored strings, need processing. @jon clements pointed out, cursor iterable, can use comprehension, obtaining float , ints @ same time.

import sqlite3 lite  lite.connect(dbpath) conn:   cur = conn.execute('select latitude, userid message')    items = [[float(x[0]), int(x[1])] x in cur] 

edit: we're not making changes, don't need call commit.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -