from datetime import datetime

from axipy import provider_manager, data_manager
time_start=datetime.now()
name_tab=r"E:\Support\AxiomaTesting\DubleRecord\Вода_итоговая_21.tab"
table = provider_manager.openfile(name_tab)
sql="Select RowNum() as id___num,* from "+table.name
query = data_manager.query(sql)
list_name_by_group=['obj']
name_by_group=','.join(list_name_by_group)
sql_2="Select *,Count(*) as cnt From "+query.name+" group by "+name_by_group+" HAVING cnt>1 "
query_2=data_manager.query(sql_2)
#sql_3="Select * from "+query_2.name+" where cnt>1 order by id___num"
#query_3=data_manager.query(sql_3)
()
for i,item in enumerate(query_2.items()):
    print(i)
    cur_id=item['id___num']
    sql_temp_query="Select * from "+query_2.name+" where id___num="+str(cur_id)
    #temp_query=data_manager.query(sql_temp_query)
    sql_temp_query="("+sql_temp_query+")"
    #cur_sql="select "+query_2.name+".* from "+query_2.name+","+temp_query.name +" where "+query_2.name+".id___num<>"+str(cur_id)+" and "+query_2.name+".obj="+temp_query.name+".obj"
    cur_sql = "select " + query.name + ".* from " + query.name + "," + sql_temp_query+" as Query_z " + " where " + query.name + ".id___num<>" + str(
        cur_id) + " and " + query.name + ".obj=" + "Query_z.obj"
    ()
    query_cur=data_manager.query_hidden(cur_sql)
    list_ft_update=[]
    for item_del in query_cur.items():
        item_del['idparent']=cur_id
        list_ft_update.append(item_del)
    if len(list_ft_update)>0:
        query_cur.update(list_ft_update)
    query_cur.close()
    #break
print("End End")