问题描述
我正在尝试将旧版应用程序(将数据存储在VisualFoxpro dbfs中)同步到MySql或SqlServer2005.这将使我们能够在线查看某些信息.我每天至少需要两次同步.
I'm trying to sync a legacy application (wich stores data in VisualFoxpro dbfs) to MySql or SqlServer 2005. This will allow us to see certain information online. I need this sync at least twice a day.
有人知道该怎么做吗?
提前谢谢.
推荐答案
我不知道有任何现成的软件可以解决这个问题,但是使用 python ,我的dbf模块和一个 MySQL 软件包中.
I am not aware of any off-the-shelf software to handle this, but it would not be difficult using python, my dbf module, and one of the MySQL packages.
编写脚本后,将其添加到系统调度程序中以根据需要运行.
Once you have the script written, add it to the system scheduler to run as often as you need.
一个非常粗糙的例子:
import dbf
import MySQLdb
legacy_table = dbf.Table(r'\some\path\to\table.dbf')
connection = MySQLdb.connect(host='some_server', user='some_body', passwd='complexicate me!', db='the_db')
cursor = connection.cursor()
cusor.execute('command to recreate table') # yes, my SQL is weak :(
# other option is to use REPLACE below, and skip this step
for record in legacy_table:
cursor.execute(
'insert into table_name values (%s, %s, %s)',
args=(record.name, record.age, record.comment)
)
# for performance, executemany is better -- I _think_ this will work
cursor.executemany(
'insert into table_name values (%s, %s, %s)',
args = [(record.name, record.age, record.comment) for record in legacy_table])
希望这可以帮助您入门.随时问更多问题.
This will hopefully get you started. Feel free to ask more questions.
这篇关于如何使用MySql同步Visual Foxpro dbfs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!