Пример #1
0
    def __init__(self,
                 cookie,
                 pathname=None,
                 seed=None,
                 version=None,
                 compatible=None):
        if cookie != bayesdb_open_cookie:
            raise ValueError('Do not construct BayesDB objects directly!')
        if pathname is None:
            pathname = ":memory:"
        self._sqlite3 = apsw.Connection(pathname)
        self.txn_depth = 0
        self.metamodels = {}
        self.tracer = None
        self.sql_tracer = None
        self.cache = None
        self.temptable = 0
        self.qid = 0
        if seed is None:
            seed = struct.pack('<QQQQ', 0, 0, 0, 0)
        self._prng = weakprng.weakprng(seed)
        pyrseed = self._prng.weakrandom32()
        self._py_prng = random.Random(pyrseed)
        nprseed = [self._prng.weakrandom32() for _ in range(4)]
        self._np_prng = numpy.random.RandomState(nprseed)
        schema.bayesdb_install_schema(self._sqlite3,
                                      version=version,
                                      compatible=compatible)
        bqlfn.bayesdb_install_bql(self._sqlite3, self)

        # Cache an empty cursor for convenience.
        empty_cursor = self._sqlite3.cursor()
        empty_cursor.execute('')
        self._empty_cursor = bql.BayesDBCursor(self, empty_cursor)
Пример #2
0
    def __init__(self,
                 cookie,
                 pathname=None,
                 seed=None,
                 version=None,
                 compatible=None):
        if cookie != bayesdb_open_cookie:
            raise ValueError('Do not construct BayesDB objects directly!')
        if pathname is None:
            pathname = ":memory:"
        self.pathname = pathname
        self._sqlite3 = apsw.Connection(pathname)
        self._txn_depth = 0  # managed in txn.py
        self._cache = None  # managed in txn.py
        self.metamodels = {}
        self.tracer = None
        self.sql_tracer = None
        self.temptable = 0
        self.qid = 0
        if seed is None:
            seed = struct.pack('<QQQQ', 0, 0, 0, 0)
        self._prng = weakprng.weakprng(seed)
        pyrseed = self._prng.weakrandom32()
        self._py_prng = random.Random(pyrseed)
        nprseed = [self._prng.weakrandom32() for _ in range(4)]
        self._np_prng = numpy.random.RandomState(nprseed)

        # Set up or check the permanent schema on disk.
        schema.bayesdb_install_schema(self,
                                      version=version,
                                      compatible=compatible)

        # Set up the in-memory BQL functions and virtual tables that
        # need not have storage on disk.
        bqlfn.bayesdb_install_bql(self._sqlite3, self)
        self._sqlite3.createmodule('bql_mutinf', bqlvtab.MutinfModule(self))
        self._sqlite3.cursor().execute(
            'create virtual table temp.bql_mutinf using bql_mutinf')

        # Cache an empty cursor for convenience.
        empty_cursor = self._sqlite3.cursor()
        empty_cursor.execute('')
        self._empty_cursor = bql.BayesDBCursor(self, empty_cursor)
Пример #3
0
 def _do_sql_execute(self, string, bindings):
     cursor = self._sqlite3.cursor()
     cursor.execute(string, bindings)
     return bql.BayesDBCursor(self, cursor)