def open(self): # Open connection / Create database try: connection = hashdb_sql.connect(self._filename) except OSError, ex: log.error('error: Unable to open primary database (%s): %s' % (self._filename, ex)) return False
def build_selects(self, sources=[None], columns=[], filters=[]): for source in sources: if source == None: found = self.build_selects_primary(columns, filters) elif isinstance(source, list): found = self.build_selects(source, columns, filters) elif isinstance(source, HashDatabase2.AttachLocal): found = self.build_selects_local(source, columns, filters) elif isinstance(source, HashDatabase2.AttachRemote): found = self.build_selects_remote(source, columns, filters) elif isinstance(source, basestring): source = truepath(source) local = self.get_local_by_path(source) if local != None: found = self.build_selects_local(local, columns, filters) else: remote = self.get_remote_by_path(source) if remote != None: found = self.build_selects_remote(remote, columns, filters) else: log.error('error: unknown database %r' % source) continue else: raise ValueError, 'invalid source specified in sources list' for result in found: yield result
def open(self): # Open primary database try: conn = sql.connect(self._filename) conn.row_factory = sql.Row conn.text_factory = str conn.create_function('count_components', 1, count_components) self._create_schema(conn) except OSError, ex: log.error('error: Unable to open primary database (%s): %s' % (self._filename, ex)) return False
); CREATE INDEX IF NOT EXISTS hashtab_by_size_time ON hashtab ( size, time ); CREATE INDEX IF NOT EXISTS hashtab_by_hash_size_time ON hashtab ( hash, size, time ); CREATE INDEX IF NOT EXISTS hashtab_by_mark ON hashtab ( mark ); """) except sql.Error, ex: log.error('error: Unable to create schema: %s' % ex) return False # Attach local databases for local in self.locals: try: with connection: connection.execute('ATTACH ? AS %s' % local.name, (local.database,)) except OSError, ex: log.error('error: Unable to attach local database (%r): %s' % (local.database, ex)) return False except sql.Error, ex: log.error('error: Unable to attach local database (%r): %s' % (local.database, ex)) return False # Attach local databases