google-code-export / pymssql

Automatically exported from code.google.com/p/pymssql
GNU Lesser General Public License v2.1
0 stars 0 forks source link

How to do multiple inserts into MSSQL from select statements done in MySQL? #70

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
     GNU nano 2.2.6             File: SMARTins.py                        Modified  

#!/usr/bin/python

import pymssql as ms
import MySQLdb as mdb
import trans
import sys

#Connection to MSSQL
connMSSQL=ms.connect(host='192.168.1.214', user='sa', password='hacker2be', dat$

#Connection to MySQL
connMySQL=mdb.connect('localhost', 'root', 'smart123', 'smartlink');

#Cursor to MSSQL
curMSSQL=connMSSQL.cursor()

#Cursor to MySQL
curMySQL=connMySQL.cursor(mdb.cursors.DictCursor)
curMySQL.execute('SELECT * FROM clinics_mapping')

#Get Data from MySQL server
for rowMySQL in curMySQL:
#       print (rowMySQL['Clinic_name'],rowMySQL['Clinic_code'])
#       curMSSQL.executemany("INSERT INTO clinics values(%s,%s)", [(rowMySQL['C$
        names = rowMySQL['Clinic_name']
        codes = rowMySQL['Clinic_code']
        qryINS="INSERT INTO clinics(name,code)values('%s','%s')" %(str(names),s$
        curMSSQL.execute(qryINS)
        print (rowMySQL['Clinic_name'],rowMySQL['Clinic_code'])
        print qryINS

#Close MSSQL connection
connMSSQL.close()

#Close MySQL connection
connMySQL.close()

What is the expected output? What do you see instead?
 To finally get rows in MySQL get moved to MSSQL

What version of the product are you using? On what operating system?
 Version 2.7 on Ubuntu 11.04 desktop

Please provide any additional information below.
 1.MSSQL is on Windows
 2.My Python script runs from Linux Ubuntu 11.04
 3.MySQL database is on Linux

Original issue reported on code.google.com by muithimw...@gmail.com on 18 Oct 2011 at 8:23

GoogleCodeExporter commented 9 years ago
Please post such questions on the mailing list.  When you do so, make sure you 
include the version of pymssql you are using.  I recommend you try one of the 
eggs I uploaded last night.

Original comment by rsyr...@gmail.com on 19 Oct 2011 at 2:01