コード例 #1
0
def update_snapshots(snapshots):
    connection = db_util.get_db_connection()
    cursor = connection.cursor()

    for snapshot in snapshots:
        db_util.update_snapshot(snapshot, cursor)

    connection.commit()
    connection.close()
コード例 #2
0
    def test_delete_search_query(self):
        fake_cursor = TestDBCursor()
        fake_connection = TestDBConnection(fake_cursor)

        self.mox.StubOutWithMock(db_util, 'get_db_connection')
        db_util.get_db_connection().AndReturn(fake_connection)
        self.mox.ReplayAll()

        filters = [
            models.Filter('study', 'eq', 'study1,study2')
        ]
        filter_util.run_delete_query(filters, 'test', True)

        query = fake_cursor.queries[0]
        query_str ='UPDATE test SET deleted=0 WHERE (study == ? OR study == ?)'
        self.assertEqual(query, query_str)

        operands = fake_cursor.operands[0]
        self.assertEqual(len(operands), 2)
        self.assertEqual(operands[0], 'study1')
        self.assertEqual(operands[1], 'study2')
コード例 #3
0
def parse_csv(contents, mcdi_type, languages, hard_of_hearing,
    act_as_file=False):

    mcdi_model = db_util.load_mcdi_model(mcdi_type)
    percentile_names = mcdi_model.details['percentiles']
    
    male_percentiles_name = percentile_names['male']
    female_percentiles_name = percentile_names['female']
    other_percentiles_name = percentile_names['other']

    male_percentiles = db_util.load_percentile_model(male_percentiles_name)
    female_percentiles = db_util.load_percentile_model(female_percentiles_name)
    other_percentiles = db_util.load_percentile_model(other_percentiles_name)
    
    percentile_tables = {
        constants.MALE: male_percentiles,
        constants.FEMALE: female_percentiles,
        constants.OTHER_GENDER: other_percentiles
    }

    connection = db_util.get_db_connection()
    cursor = connection.cursor()

    parse_info = parse_csv_prototypes(contents, percentile_tables, act_as_file)
    if parse_info['error']:
        connection.commit()
        connection.close()
        return {'error': parse_info['error']}

    prototypes = parse_info['prototypes']
    ids = map(lambda x: x['child_id'], prototypes)

    for prototype in prototypes:
        build_snapshot(prototype, mcdi_type, languages, hard_of_hearing, cursor)

    connection.commit()
    connection.close()
    return {'error': None, 'ids': ids}