當前位置: 首頁>>代碼示例>>Python>>正文


Python sqlite3.dbapi2方法代碼示例

本文整理匯總了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 
開發者ID:wied03,項目名稱:centos-package-cron,代碼行數:21,代碼來源:db_session_fetcher.py

示例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) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:22,代碼來源:pysqlite.py

示例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() 
開發者ID:rosspalmer,項目名稱:bitQuant,代碼行數:13,代碼來源:clss.py

示例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() 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:tests.py

示例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 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:11,代碼來源:pysqlite.py


注:本文中的sqlite3.dbapi2方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。