def verify_ids(): session = DBSession() for condition in id_verify_conditions: print '--------------------' print condition['main']['csv']['file'] print '--------------------' print '\n' for csv_row in data[condition['main']['csv']['file']]['records']: csv_id, entity_name = csv_row[condition['main']['csv']['id']],\ csv_row[condition['main']['csv']['name']] db_entities = session.query(condition['main']['db']['table'])\ .filter(eq(condition['main']['db']['name'], entity_name))\ .all() if len(db_entities) != 1: raise Exception() db_entity_id = db_entities[0].id print '\n' print entity_name for dependency in condition['dependency']: csv_dependency_records = data[dependency['csv']['id'][0]]['records'] count_dependency_records = 0 db_dependency_entities = session.query(dependency['db']['table']) if 'alias' in dependency['db']: alias = dependency['db']['alias'] db_dependency_entities = db_dependency_entities.outerjoin(alias, dependency['db']['joined'] == alias.id) db_dependency_entities = db_dependency_entities.filter(eq(dependency['db']['alias'].id, db_entity_id)) else: db_dependency_entities = db_dependency_entities.filter(eq(dependency['db']['id'], db_entity_id)) db_dependency_entities = db_dependency_entities.all() for csv_dep_record in csv_dependency_records: if csv_dep_record[dependency['csv']['id'][1]] == csv_id: count_dependency_records += 1 # if len(db_dependency_entities) == count_dependency_records: # print '' print condition['main']['csv']['file'] + ' -> ' + dependency['csv']['id'][0] print 'db: ' + str(len(db_dependency_entities)) print 'csv: ' + str(count_dependency_records)
def sql_equal(a, b): if FilterToQuery.is_field(a): if FilterToQuery.is_field(b): r = ((a == b) | (sql_operators.is_(a, None) & sql_operators.is_(b, None))) else: if b is not None: r = ((a == b) | sql_operators.eq(a, None)) else: r = sql_operators.eq(a, None) else: if FilterToQuery.is_field(b): if a is not None: r = ((a == b) | sql_operators.eq(b, None)) else: sql_operators.eq(b, None) else: r = (a == b) return r
def tuple_operator_in(model_pk, ids): """The tuple_ Operator only works on certain engines like MySQL or Postgresql. It does not work with sqlite. The function returns an or_ - operator, that containes and_ - operators for every single tuple in ids. Example:: model_pk = [ColumnA, ColumnB] ids = ((1,2), (1,3)) tuple_operator(model_pk, ids) -> or_( and_( ColumnA == 1, ColumnB == 2), and_( ColumnA == 1, ColumnB == 3) ) The returning operator can be used within a filter(), as it is just an or_ operator """ ands = [] for id in ids: k = [] for i in range(len(model_pk)): k.append(eq(model_pk[i], id[i])) ands.append(and_(*k)) if len(ands) >= 1: return or_(*ands) else: return None
def tuple_operator_in(model_pk, ids): """The tuple_ Operator only works on certain engines like MySQL or Postgresql. It does not work with sqlite. The function returns an or_ - operator, that containes and_ - operators for every single tuple in ids. Example:: model_pk = [ColumnA, ColumnB] ids = ((1,2), (1,3)) tuple_operator(model_pk, ids) -> or_( and_( ColumnA == 1, ColumnB == 2), and_( ColumnA == 1, ColumnB == 3) ) The returning operator can be used within a filter(), as it is just an or_ operator """ l = [] for id in ids: k = [] for i in range(len(model_pk)): k.append(eq(model_pk[i],id[i])) l.append(and_(*k)) if len(l)>=1: return or_(*l) else: return None
def search_operator_is(cls, model_column: Column, value): return eq(model_column, value)
def sql_differ(a, b): r = ((a != b) | (sql_operators.eq(a, None) & sql_operators.ne(b, None))) | ( sql_operators.ne(a, None) & sql_operators.eq(b, None)) return r