Created
August 10, 2012 14:41
-
-
Save xfenix/3314714 to your computer and use it in GitHub Desktop.
Drupal pg2mysql migration helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment