So basically I'm working on this python script that reads data from an sqlite file and synchronizes it with a MySQL server (uploads the data). The script seems to be fine since I get no errors, still whenever I look in phpMyAdmin for the changes nothing happens.
Here's my complete code:
#!/usr/bin/python2.7
__author__ = ''
import sys
import sqlite3 as lite
import MySQLdb as mysql
c=0
liteDB = ''
for arg in sys.argv:
c=c+1
if c==2:
liteDB = arg
SQLServer = '*********'
SQLUser = '***********'
SQLPass = '***********'
SQLDB = '*************'
try:
conMSQL = mysql.connect(SQLServer, SQLUser, SQLPass, SQLDB)
curMSQL = conMSQL.cursor()
try:
conLite = lite.connect(liteDB)
curLite = conLite.cursor()
curLite.execute('SELECT * FROM Ventas')
while True:
row=curLite.fetchone()
if row == None:
break
texto = 'INSERT INTO Ventas VALUES (' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ',' + str(row[4]) + ',' + str(row[3]) + ',' + str(row[5]) + ',' + str(row[6]) + ',' + str(row[8]) + ',' + str(row[7]) + ',' + str(row[9]) + ',' + str(row[10]) + """,'""" + row[11] + """')"""
print texto
curMSQL.execute('INSERT INTO Ventas VALUES (' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ',' + str(row[4]) + ',' + str(row[3]) + ',' + str(row[5]) + ',' + str(row[6]) + ',' + str(row[8]) + ',' + str(row[7]) + ',' + str(row[9]) + ',' + str(row[10]) + """,'""" + row[11] + """');""")
conLite.commit()
except lite.Error, e:
if conLite:
conLite.rollback()
print "Error %s:" % e.args[0]
finally:
if conLite:
conLite.close()
except mysql.Error, e:
print "Error MySQL %s:" % e.args[0]
sys.exit(1)
finally:
if conMSQL:
conMSQL.close()
and here is the specific part where I grab the sqlite data and Insert it into the MySQL server
while True:
row=curLite.fetchone()
if row == None:
break
texto = 'INSERT INTO Ventas VALUES (' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ',' + str(row[4]) + ',' + str(row[3]) + ',' + str(row[5]) + ',' + str(row[6]) + ',' + str(row[8]) + ',' + str(row[7]) + ',' + str(row[9]) + ',' + str(row[10]) + """,'""" + row[11] + """')"""
print texto
curMSQL.execute('INSERT INTO Ventas VALUES (' + str(row[0]) + ',' + str(row[1]) + ',' + str(row[2]) + ',' + str(row[4]) + ',' + str(row[3]) + ',' + str(row[5]) + ',' + str(row[6]) + ',' + str(row[8]) + ',' + str(row[7]) + ',' + str(row[9]) + ',' + str(row[10]) + """,'""" + row[11] + """');""")
conLite.commit()
I'm new to python so any help is appreciated, thanks in advance!