def find(self, record_filter = None, columns=None): if not columns: columns = "*" else: columns = ",".join(columns) sql = "SELECT %s FROM %s WHERE True " % (columns, self.tablename) if isinstance(record_filter, (list, tuple, set)): ints = filter(lambda x: isinstance(x, (int, long)), record_filter) strs = filter(lambda x: isinstance(x, StringTypes), record_filter) record_filter = Filter(SfaRecord.all_fields, {'record_id': ints, 'hrn': strs}) sql += "AND (%s) %s " % record_filter.sql("OR") elif isinstance(record_filter, dict): record_filter = Filter(SfaRecord.all_fields, record_filter) sql += " AND (%s) %s" % record_filter.sql("AND") elif isinstance(record_filter, StringTypes): record_filter = Filter(SfaRecord.all_fields, {'hrn':[record_filter]}) sql += " AND (%s) %s" % record_filter.sql("AND") elif isinstance(record_filter, int): record_filter = Filter(SfaRecord.all_fields, {'record_id':[record_filter]}) sql += " AND (%s) %s" % record_filter.sql("AND") results = self.db.selectall(sql) if isinstance(results, dict): results = [results] return results
def exists(self): sql = "SELECT * from pg_tables" tables = self.db.selectall(sql) tables = filter(lambda row: row['tablename'].startswith(self.SFA_TABLE_PREFIX), tables) if tables: return True return False