【问题标题】:How to sync Visual Foxpro dbfs with MySQL?如何将 Visual Foxpro dbfs 与 MySQL 同步?
【发布时间】:2011-05-13 16:36:06
【问题描述】:

我正在尝试将旧应用程序(将数据存储在 VisualFoxpro dbfs 中)同步到 MySQL 或 SqlServer 2005。这将使我们能够在线查看某些信息。我每天至少需要两次同步。

我该怎么做?

【问题讨论】:

  • 多少数据(记录估计),多少表?存储原始数据(.dbf、.cdx、.fpt)的驱动器上有多大?
  • 大约 300,000 条记录,大约 20MB。

标签: mysql synchronization dbf


【解决方案1】:

我不知道有任何现成的软件可以处理这个问题,但使用pythonmy dbf moduleMySQL 软件包之一并不难。

编写好脚本后,将其添加到系统调度程序中,以便根据需要随时运行。

非常粗略的例子:

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])

这有望帮助您入门。欢迎提出更多问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-29
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2015-01-12
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多