Guest User

Untitled

a guest
Nov 30th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os, errno, re, psycopg2
  4.  
  5. # конфигурация
  6. dsn = 'dbname=stiebel user=postgres password=111 port=5434'
  7. table = 'menu_router'
  8. fields = ['load_functions', 'to_arg_functions', 'access_arguments', 'page_arguments', ]
  9. pk = 'path'
  10. file = '/web/data.sql'
  11. buffer = ''
  12.  
  13. # код
  14. conn = psycopg2.connect(dsn)
  15. cur = conn.cursor()
  16. cur.execute("SELECT " + pk + ", " + (','.join(fields)) + " FROM " + table)
  17. result = cur.fetchall()
  18.  
  19. for fieldrow in result:
  20. fieldrow = list(fieldrow)
  21. key = str(fieldrow.pop(0))
  22. fset = []
  23. i = 0
  24. for value in fieldrow:
  25. fset.append( fields[i] + ' = \'' + str(value) + '\'' )
  26. i = i + 1
  27. fset = ', '.join(fset)
  28. buffer += 'UPDATE ' + table + ' SET ' + fset + ' WHERE ' + pk + ' = "' + key + '" LIMIT 1;\n'
  29.  
  30. if(file):
  31. file = open(file, 'w')
  32. file.write(buffer)
  33. file.close()
  34. cur.close()
  35. conn.close()
Add Comment
Please, Sign In to add comment