#!/usr/bin/env python

import MySQLdb
import sys
import fileinput

devdb_host = "10.10.1.1"
prdb_host = "10.10.2.2"

prdb = MySQLdb.connect(prdb_host, "angcoup", "impasswd", "mydb")
devdb = MySQLdb.connect(devdb_host, "angcoup", "impasswd", "mydb")
prdb_cursor = prdb.cursor()
devdb_cursor = devdb.cursor()


columnsSql = "col1, col2, col3"

selectSql = "SELECT " + columnsSql + " from angcoup.angcoups WHERE angcoup_srl={0}"

insertSql = "replace into angcoup.angcoups ( " + columnsSql + " ) values ('{0}', '{1}', '{2}')

for angcoupSrl in fileinput.input():

    selectSqlBinded = selectSql.format(angcoupSrl)
    print selectSqlBinded
    prdb_cursor.execute(selectSqlBinded)
    r = prdb_cursor.fetchone();

    insertSqlBinded = insertSql.format(r[0], r[1], r[2])
    print insertSqlBinded

    devdb_cursor.execute(insertSqlBinded)
    #devdb_cursor.execute("select last_insert_id()");

    devdb.commit()
    sys.stdout.write("inserted");

print "Done."

devdb.close()
prdb.close()


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2015-10-23 13:57:27
Processing time 0.0041 sec