dump_tables.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import re
  2. import codecs
  3. def find_table_names(_data):
  4. s = []
  5. bi = []
  6. def find(p, offset=1):
  7. results = re.findall(p, _data, re.IGNORECASE)
  8. for l in results:
  9. # print('l', l)
  10. text = l
  11. if type(l) is tuple:
  12. if l[0] == 'lawe':
  13. text = l[1]
  14. elif len(l[1]) == 1 or l[1] == 'thd' or l[1] == 'AIiKi' or l[1] == 'XVuSA':
  15. text = l[0]
  16. else:
  17. text = l[1]
  18. # print('>', text)
  19. if not text.startswith('bi_') and not text.startswith('v_bi_') and text != 'lawe' and text != 'icm' and text != 'icm_bpm':
  20. s.append(text)
  21. if text.startswith('bi_'):
  22. bi.append(text)
  23. find(r'CREATE TABLE `(\w+)`')
  24. find(r'from lawe\.(\w+)')
  25. find(r'from `(\w+)`.`(\w+)`', 2)
  26. find(r'from\r\n `(\w+)`.`(\w+)`', 2)
  27. find(r'from (\w+)')
  28. find(r'LEFT JOIN (\w+)')
  29. find(r'LEFT JOIN (\w+).(\w+)', 2)
  30. find(r'from (\w+)\.(\w+)')
  31. find(r'from\r\n\t(\w+)')
  32. find(r'inner join (\w+).(\w+)', 2)
  33. bi = list(set(bi))
  34. print(bi)
  35. r = list(set(s))
  36. print(r)
  37. # print(len(r))
  38. pass
  39. file_name = 'all.sql'
  40. text_file = codecs.open(file_name, "r")
  41. # read whole file to a string
  42. data = text_file.read()
  43. splitter = '-- ('
  44. parts = data.split(splitter)
  45. print('parts', len(parts))
  46. for part in parts:
  47. print(part.partition('\n')[0])
  48. find_table_names(part)
  49. # close file
  50. text_file.close()