How To Improve Sqlite Database Request And Speed
I found put that I open the database at every request.Is there a way to simplify and improve this code to increase the sqlite speed? name3 = ' '.join(name2) import
Solution 1:
- Do not use
import
in the middle of your program. - Open the database once at the start of your program.
- Select only the records you actually need.
- Select only the columns you actually need.
- Do not use
fetchall
; read only the records you actually need. - Do not fetch into a temporary variable if you can use the cursor directly.
import sqlite3
# at startup
conn = sqlite3.connect("keywords.db")
def search_location(name2):
name3 = ' '.join(name2)
c = conn.cursor()
c.execute('SELECT location FROM kmedicals WHERE id = ?', (name3,))
for (location,) in c:
print name3.capitalize(),':' '\n',location
break
else:
pass # not found
Post a Comment for "How To Improve Sqlite Database Request And Speed"