-->

寻找一个SQL脚本语言来操纵DBF文件(Looking for an SQL scripting l

2019-09-22 23:39发布

我收集了大量的DBF文件(其中约1100),我需要分析一个客户端。 每个文件都包含一个单一的表。 我需要在每个表执行查询,复制结果到一个大的结果表(将举行由所有文件的结果),然后移动到下一个DBF文件。 最后我需要的结果表保存在我以后可以操作的格式。 有谁知道一个脚本语言,它可以使这个容易,我呢?

有几个注意事项:1)我需要的东西,在Vista(工作在DOS上运行的东西,Python或GNU Octave是好的太)。 2)我不是一个数据库管理员,但我有相当好的编程技能。 3)我只有SQL的基本知识。 我可以写的查询,我的问题是打开DBF文件并保存结果。 4)其实我已经完成了这个使用的MS Access,但它是一个混乱的解决方案。 所以我在寻找的东西,不使用访问。

我一直在阅读了各种脚本语言的SQL。 大多数我见过的网站进入有关服务器的事情,建立关系,安全和所有这些事情。 这些问题已远远超出我的理解和是不是我关心的。 我只是想查询这些文件,得到结果,并且全身而退。 有什么在那里,是初学者容易接近,但显著厉害?

任何帮助将非常感激。

Answer 1:

我将与SSIS做到这一点。 循环和数据转换是SSIS相当容易。



Answer 2:

我的第一个选择是Visual FoxPro中 。 它处理的.dbf文件本身,有一个互动的环境,并提供SQL SELECT能力。 SELECT语句具有发送查询结果到另一个表INTO子句。 有些种类的MSDN订阅包括FoxPro的DVD上,并使其可以从MSDN下载。

的dBASE可用了。

如果有必要,.dbf文件结构很容易用代码操作。 在过去,我不得不写代码修改的.dbf文件在C和德尔福。 这是从来没有比下午的工作更多。 一个谷歌代码搜索可能会产生的.dbf相关的代码,任何重大的编程语言。 .dbf文件格式和相关的文件格式都记录在MSDN 。



Answer 3:

我已经写了蟒蛇DBF模块具有非常基本的SQL支持。 然而,即使SQL是不是到你的需求,这是很容易地查询使用Python语法的DBF文件。

一些例子:

import dbf

要创建一个结果表和记录添加到它:

results = dbf.Table('results_table', 'name C(50); amount N(10, 4)')
record = results.append()
with record:
    record.name = 'something'
    record.amount = 99.928

# to open an existing table
table = dbf.Table('some_dbf_table').open()

# find all sales >= $10,000
records = table.pql("select * where sales >= 10000")

# find all transactions for customer names that start with Bob
records = table.pql("select * where customer.startswith('Bob')")

# nevermind thin sql veneer, just use python commands
records = table.find("sales >= 10000 and customer.startswith('Bob')")

# sum sales by customer
customer_sales = default_dict(int)  # if customer not already seen, will default to 0
for record in table:
    customer_sales[record.customer] += record.sales

# now add to results table and print them out
for name, total in sorted(customer_sales.items()):
    result_record = results.append()
    with result_record:
        result_record.name = name
        result_record.amount = total
    print "%s: %s" % (name, total)


文章来源: Looking for an SQL scripting language to manipulate DBF files
标签: sql dbf