tsv con python y bases de datos

时间:2019-12-26 19:51:52

标签: python mysql

Tengo el siguiente错误消息和未归档的TSV数据库。

Mi codigo es el siguiente:

import MySQLdb
from datetime import datetime
now = datetime.now()
fech = now.strftime('%d/%m/%Y')
print (fech)


#Abrimos el archivo CSV
f=open("C:/.tsv/fnd_gfm_43139914.tsv") 
#Omitimos la linea de encabezado
next(f, None)
reader = csv.reader(f, delimiter='\t')

db = MySQLdb.connect(host="localhost",    # tu host, usualmente localhost
                     user="root",         # tu usuario
                     passwd="",  # tu password
                     db="prueba")
cur = db.cursor()




#Llenamos la BD con los datos del CSV
for row in reader:
   cur.execute("INSERT INTO frame(Order,ItemDes,ShipToC,CPON,ShipToLoc,ShipToA,IItem,Qty,UOM,Status,QtyF,ListPrice,Desc1,RDate,Wh,ShiMe,FT,PT,AR,IRule,TParI,PriI,ReturnR,Desc2,Fechadeingreso) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",row)
   #cur.execute("INSERT INTO prueba(Numero,ItemDescription,ShipToCustomer) VALUES (%s,%s,%s)",row)
   #cur.execute("INSERT INTO frame(Fechadeingreso)VALUES(%s)",fech) 
   print(row)


#Muestro las filas guardadas en la tabla
cur.execute("SELECT * FROM prueba")
for row in cur:
    print(row)

#Cerramos el archivo y la conexion a la bd
f.close()
db.commit()
db.close()

错误,错误:

MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Order,ItemDes,ShipToC,CPON,ShipToLoc,ShipToA,IItem,Qty,UOM,Status,QtyF,ListPrice' at line 1")

Alguien Sabra que puede ser?

0 个答案:

没有答案