2014-09-02 57 views
1

我想在python中創建一個dbf到mysql連接器。到目前爲止,我已經把它連接到mysql服務器並讀取dbf文件,但是當我運行該程序時,它顯示沒有數據在sql中複製。python dbf到mysql

繼承人我的代碼到目前爲止。

from dbfpy import dbf 
import MySQLdb 

source = dbf.Dbf("foxpro.Dbf") 

db = MySQLdb.connect(host = "localhost", user = "root", passwd = "", db = "mydb") 
cur = db.cursor() 

for r in source: 
    query = """INSERT mytb SET column1 = %s, column2 = %s, column3 = %s""" 
    values = (r["column1"], r["column2"], r["column3"]) 
    print r["column1"], r["column2"], r["column3"] 

回答

2

您已經寫入查詢來插入,但您還沒有​​d it。

# since your `values` is already a tuple 
cur.execute(query, values) 

# otherwise can be written as... 
cur.execute(query, (r["column1"], r["column2"], r["column3"]))