Python sqlite3.dbapi2() Examples

The following are 5 code examples of sqlite3.dbapi2(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sqlite3 , or try the search function .
Example #1
Source File: db_session_fetcher.py    From centos-package-cron with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 
Example #2
Source File: pysqlite.py    From moviegrabber with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: clss.py    From bitQuant with MIT License 5 votes vote down vote up
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() 
Example #4
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
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() 
Example #5
Source File: pysqlite.py    From moviegrabber with GNU General Public License v3.0 5 votes vote down vote up
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