Exemple #1
0
def es_tabla_util(nombre):
    global cursor_cuenta
    if conexion and not cursor_cuenta:
        cursor_cuenta = conexion.cursor()
    for ban in BAN_TABLAS:
        if isinstance(ban,  basestring):
            if nombre.lower() == ban.lower():
                return False
        else:
            match = ban.search(nombre)
            
            if match != None:
                print "Match en", nombre
                return False
            
    if not nombre in cache_counts:
        cursor_cuenta.execute('select count(*) from %s' % nombre)
        cant = cursor_cuenta.fetchone()[0]
        cant = int(cant)
        cache_counts[nombre] = cant
    else:
        cant = cache_counts[nombre] 
    
    if not cant:
        return False
                     
    return True
Exemple #2
0
def main(argv = sys.argv):
    if not conexion:
        return
    cursor = conexion.cursor()
    cursor.execute(SQL)
    datos = cursor.fetchall()
    
    tablas = {}
    #tablas.setdefault([])
    for tabla, columna, tipo, longitud, default, null in datos:
        if not es_tabla_util(tabla):
            continue
        null = null.lower() == 'yes'
        item = dict(nombre = columna, tipo=tipo, longitud=longitud, 
                    default = default, null = null)
        if not tabla in tablas:
            tablas[tabla] = [item, ]
        else:
            tablas[tabla].append(item)
    
    TABLAS = tablas
    pickle.dump(TABLAS, open('tablas.pickle', 'w'))
    pprint(tablas)
    print(len(tablas))
    for tabla, cant in cache_counts.iteritems():
        if cant == 0:
            print tabla