def get_db():
"""Opens a new database connection if there is none yet for the
current application context.
"""
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
python类sqlite_db()的实例源码
def close_db(error):
"""Closes the database again at the end of the request."""
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
def get_db():
"""
Opens a new database connection if there is none yet for the
current application context.
"""
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
def get_db():
'''Opens a new database connection if there is none yet for the
current application context.'''
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
debug('Database connection created.')
return g.sqlite_db
def close_db(error):
'''Closes the database again at the end of the request.'''
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
debug('Database connection destroyed.')
def get_db():
# g is a general purpose variable associated with the current application context
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
# initialise the db
def close_db(error):
"""Closes the database again at the end of the request."""
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
def db_open():
"""Opens a new database connection if there is none yet for the
current application context.
"""
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = db_connect()
return g.sqlite_db
def close_db(error):
"""Closes the database again at the end of the request."""
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()
################################################################################
# Intersections
################################################################################
def get_db():
if not hasattr(g, 'sqlite_db'):
g.sqlite_db = connect_db()
return g.sqlite_db
def close_db(error):
if hasattr(g, 'sqlite_db'):
g.sqlite_db.close()