Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import os, errno, re, psycopg2
- # конфигурация
- dsn = 'dbname=stiebel user=postgres password=111 port=5434'
- table = 'menu_router'
- fields = ['load_functions', 'to_arg_functions', 'access_arguments', 'page_arguments', ]
- pk = 'path'
- file = '/web/data.sql'
- buffer = ''
- # код
- conn = psycopg2.connect(dsn)
- cur = conn.cursor()
- cur.execute("SELECT " + pk + ", " + (','.join(fields)) + " FROM " + table)
- result = cur.fetchall()
- for fieldrow in result:
- fieldrow = list(fieldrow)
- key = str(fieldrow.pop(0))
- fset = []
- i = 0
- for value in fieldrow:
- fset.append( fields[i] + ' = \'' + str(value) + '\'' )
- i = i + 1
- fset = ', '.join(fset)
- buffer += 'UPDATE ' + table + ' SET ' + fset + ' WHERE ' + pk + ' = "' + key + '" LIMIT 1;\n'
- if(file):
- file = open(file, 'w')
- file.write(buffer)
- file.close()
- cur.close()
- conn.close()
Add Comment
Please, Sign In to add comment