栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Reading DBF files with pyodbc

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Reading DBF files with pyodbc

I DID IT!!!!

There where several problems with what I was doing so, here I come with what I
did to solve it (after implementing it the first time with Ethan Furman’s
solution)

The first thing was a driver problem, it turns out that the Windows’ DBF
drivers are 32 bits programs and runs on a 64 bits operating system, so, I had
installed Python-amd64 and that was the first problem, so I installed a 32bit
Python.

The second issue was a library/file issue, according to
this,
dbf files in VFP > 7 are diferent, so my pyodbc library won’t read them
correctly, so I tried some OLE-DB libraries with no success and I decided to
to it from scratch.

Googling for a while took me to
this
post which finally gave me a light on this

Basically, what I did was the following:

import win32com.clientconn = win32com.client.Dispatch('ADODB.Connection')db = 'C:\Profit\profit_a\ARMM'dsn = 'Provider=VFPOLEDB.1;Data Source=%s' % dbconn.Open(dsn)cmd = win32com.client.Dispatch('ADODB.Command')cmd.ActiveConnection = conncmd.CommandText = "Select * from factura, reng_fac where factura.fact_num = reng_fac.fact_num AND factura.fact_num = 6099;"rs, total = cmd.Execute() # This returns a tuple: (<RecordSet>, number_of_records)while total:    for x in xrange(rs.Fields.Count):        print '%s --> %s' % (rs.Fields.item(x).Name, rs.Fields.item(x).Value)    rs.MoveNext()        #<- Extra indent    total = total - 1

And it gave me 20 records which I checked with DBFCommander and were OK

First, you need to install pywin32
extensions (32bits)
and the Visual FoxPro OLE-DB Provider (only available for 32bits), in my case for
VFP 9.0

Also, it’s good to read de ADO
documentation at the w3c website

This worked for me. Thank you very much to those who replied



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371378.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号