本文整理汇总了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