Diff.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #coding=utf-8
  2. import MSSQL
  3. db2010 = MSSQL.MSSQL(host=r"192.168.1.100",user="sa",pwd="`12345",db="Con2010_zjhw")
  4. db2016 = MSSQL.MSSQL(host=r"192.168.1.100\MSSQLSERVERR2",user="sa", \
  5. pwd="`12345",db="Con2016")
  6. def FindNotIn():
  7. sqlalltable=r"SELECT Name FROM SysObjects Where XType='U' ORDER BY Name"
  8. tablelist2010 = ToList(db2010.ExecQuery(sqlalltable))
  9. tablelist2016 = ToList(db2016.ExecQuery(sqlalltable))
  10. TnotIn=[]
  11. CnotIn={}
  12. for table in tablelist2010:
  13. if table not in tablelist2016:
  14. TnotIn.append(table)
  15. else:
  16. sqlallCol=r"SELECT Name FROM SysColumns WHERE id=Object_Id('%s')" %table
  17. col2010=ToList(db2010.ExecQuery(sqlallCol))
  18. col2016=ToList(db2016.ExecQuery(sqlallCol))
  19. collist=[]
  20. for col in col2010:
  21. if col not in col2016:
  22. collist.append(col)
  23. if len(collist)>0:
  24. CnotIn[table]=collist
  25. return TnotIn,CnotIn
  26. def FindNotIn_TR_P_FN(TR_P_FN):
  27. sql="SELECT * FROM Sysobjects WHERE xtype = '%s'" %TR_P_FN
  28. list2010 = ToList(db2010.ExecQuery(sql))
  29. list2016 = ToList(db2016.ExecQuery(sql))
  30. notin=[]
  31. notsame=[]
  32. for x in list2010:
  33. if x not in list2016:
  34. notin.append(x)
  35. else:
  36. sqltxt="EXEC sp_helptext '%s'" %x
  37. txt2010=ToStr(db2010.ExecQuery(sqltxt))
  38. txt2016=ToStr(db2016.ExecQuery(sqltxt))
  39. if txt2010!=txt2016:
  40. notsame.append(x)
  41. return notin,notsame
  42. def ToList(listresult):
  43. result=[]
  44. for x in listresult:
  45. result.append (x[0])
  46. return result
  47. def ToStr(listresult):
  48. result=""
  49. for x in listresult:
  50. result+=x[0].strip()
  51. return result
  52. if __name__ == '__main__':
  53. t10=ToStr(db2010.ExecQuery("EXEC sp_helptext 'sp_qcc010305'"))
  54. t16=ToStr(db2016.ExecQuery("EXEC sp_helptext 'sp_qcc010305'"))
  55. if t10==t16:
  56. print("ok")
  57. else:
  58. print("no")