本文整理匯總了Python中sqlite3.dbapi2方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.dbapi2方法的具體用法?Python sqlite3.dbapi2怎麽用?Python sqlite3.dbapi2使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.dbapi2方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __enter__
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import dbapi2 [as 別名]
def __enter__(self):
if self.engine == None:
absolute_path = os.path.abspath(self.db_path)
parent_dir = os.path.dirname(absolute_path)
if not os.path.exists(parent_dir):
raise Exception("Unable to find a parent directory for DB %s, did you install properly?" % (absolute_path))
if not os.access(parent_dir, os.W_OK):
raise Exception("Unable to write to directory for DB file %s, do you need to run as root?" % (absolute_path))
if os.path.exists(absolute_path) and not os.access(absolute_path, os.W_OK):
raise Exception("Unable to write to DB file %s, do you need to run as root?" % (absolute_path))
self.engine = sqlalchemy.create_engine('sqlite:///%s' % (self.db_path),module=sqlite)
Base.metadata.create_all(self.engine)
Session = sessionmaker(bind=self.engine)
self.session = Session()
return self.session
示例2: create_connect_args
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import dbapi2 [as 別名]
def create_connect_args(self, url):
if url.username or url.password or url.host or url.port:
raise exc.ArgumentError(
"Invalid SQLite URL: %s\n"
"Valid SQLite URL forms are:\n"
" sqlite:///:memory: (or, sqlite://)\n"
" sqlite:///relative/path/to/file.db\n"
" sqlite:////absolute/path/to/file.db" % (url,))
filename = url.database or ':memory:'
if filename != ':memory:':
filename = os.path.abspath(filename)
opts = url.query.copy()
util.coerce_kw_type(opts, 'timeout', float)
util.coerce_kw_type(opts, 'isolation_level', str)
util.coerce_kw_type(opts, 'detect_types', int)
util.coerce_kw_type(opts, 'check_same_thread', bool)
util.coerce_kw_type(opts, 'cached_statements', int)
return ([filename], opts)
示例3: __init__
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import dbapi2 [as 別名]
def __init__(self):
engine_str = stmt.auth()
if engine_str.find('sqlite') == 0:
self.sql_type = 'sqlite'
self.eng = create_engine(engine_str, module=sqlite)
else:
self.sql_type = 'mysql'
self.eng = create_engine(engine_str)
self.conn = self.eng.connect()
self.meta = MetaData(self.eng)
self.tbl = self.load_tables()
示例4: test_check_sqlite_version
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import dbapi2 [as 別名]
def test_check_sqlite_version(self):
msg = 'SQLite 3.8.3 or later is required (found 3.8.2).'
with mock.patch.object(dbapi2, 'sqlite_version_info', (3, 8, 2)), \
mock.patch.object(dbapi2, 'sqlite_version', '3.8.2'), \
self.assertRaisesMessage(ImproperlyConfigured, msg):
check_sqlite_version()
示例5: dbapi
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import dbapi2 [as 別名]
def dbapi(cls):
try:
from pysqlite2 import dbapi2 as sqlite
except ImportError as e:
try:
from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name.
except ImportError:
raise e
return sqlite