Posted By

arifwidi on 02/02/11


Tagged

mysql import dump export SQLite


Versions (?)

MySQL Dump to SQLite Import


 / Published in: Python
 

  1. import re, fileinput
  2.  
  3. def main():
  4. for line in fileinput.input():
  5. process = False
  6. for nope in ('BEGIN TRANSACTION','COMMIT',
  7. 'sqlite_sequence','CREATE UNIQUE INDEX'):
  8. if nope in line: break
  9. else:
  10. process = True
  11. if not process: continue
  12. m = re.search('CREATE TABLE "([a-z_]*)"(.*)', line)
  13. if m:
  14. name, sub = m.groups()
  15. line = '''DROP TABLE IF EXISTS %(name)s;
  16. CREATE TABLE IF NOT EXISTS %(name)s%(sub)s
  17. '''
  18. line = line % dict(name=name, sub=sub)
  19. else:
  20. m = re.search('INSERT INTO "([a-z_]*)"(.*)', line)
  21. if m:
  22. line = 'INSERT INTO %s%s\n' % m.groups()
  23. line = line.replace('"', r'\"')
  24. line = line.replace('"', "'")
  25. line = re.sub(r"([^'])'t'(.)", "\1THIS_IS_TRUE\2", line)
  26. line = line.replace('THIS_IS_TRUE', '1')
  27. line = re.sub(r"([^'])'f'(.)", "\1THIS_IS_FALSE\2", line)
  28. line = line.replace('THIS_IS_FALSE', '0')
  29. print line,
  30.  
  31. main()

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: JhonConstantine01 on November 2, 2018

If you were facing issue with the windows 10 operating system then from our website you will learn that how to fix connections to bluetooth audio devices and wireless displays in windows 10 operating system with the help of our tutorial which you will do it online in simple steps.

You need to login to post a comment.