Esempio n. 1
0
 def test_sqlite_master_table_def(self):
     self.assertEquals(utils.table_names(self.db.cursor()),
                       set([u'bonds', u'stocks']))
     self.assertEquals(utils.sqlite_master_table_def(self.db.cursor(), "stocks"),
                       (u'table', u'stocks', u'stocks', 2, u'CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)'))
     self.assertEquals(utils.table_definition(self.db.cursor(), "stocks"),
                       ((u'table', u'stocks', u'stocks', 2, u'CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)'), [(u'index', u'idx_stock_symbol', u'stocks', 4, u'CREATE INDEX idx_stock_symbol ON stocks (symbol)')]))
Esempio n. 2
0
def table_header_diff(db1, db2, name):
    tbl1, ind1 = utils.table_definition(db1.cursor(), name)
    tbl2, ind2 = utils.table_definition(db2.cursor(), name)
    table_diff = False
    if (tbl1 != tbl2):
        table_diff = (tbl1, tbl2)
    index_diff = []
    #First compute diffs of indices held in common
    ind1_map = dict( [ (i[1], i) for i in ind1] )
    ind2_map = dict( [ (i[1], i) for i in ind2] )
    for nm in set(ind1_map.keys()).intersection(set(ind2_map.keys())):
        if ind1_map[nm] != ind2_map[nm]:
            index_diff.append( ( ind1_map[nm], ind2_map[nm]) )
    #Now compute indices held by one but not the other
    for nm in set(ind1_map.keys()) - set(ind2_map.keys()):
        index_diff.append( (ind1_map[nm], None) )
    for nm in set(ind2_map.keys()) - set(ind1_map.keys()):
        index_diff.append( (None, ind2_map[nm]) )

    if (not table_diff) and (len(index_diff) == 0):
        return False
    else:
        return (table_diff, index_diff)