sqlite3 db update extremely slow
Steve Holden
steve at holdenweb.com
Mon Jul 16 21:32:24 EDT 2007
coldpizza wrote:
> Thanks a lot, Roel, adding a single commit() at the end did solve the
> speed problem.
>
> Another question is do I have to explicitly close the DB connection,
> or is it automatically garbage collected? Is it Ok to no have any
> cleanup code?
>
It's generally OK, but you can register a function with atexit() if you
are paranoid about cleanup. Here's a sample with an ugly global variable.
from atexit import register
def close():
global conn
if conn:
conn.close()
print "Database closed"
conn = None
#
# We try to ensure the database is always closed by registering
# the nodule's close() function to be called on program exit
#
register(close)
import psycopg2 as db
conn = db.connect(database="billing", user="steve", password="tadaa!")
curs = conn.cursor()
print "Database opened"
> Another question would be how to define the encoding for newly added
> records?
> And how do set the encoding for the retrieved records? Is it always
> utf-8 by default?
>
Generally speaking each database instance will have an associated
encoding. Trying to establish some other encoding would then be pissing
into the wind.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list