Python dbfpy and FoxPro

Ok, I use the ancient database format here, dbf files. Don't ask why, just be aware that certain software decided to expand foxpro support because microsoft decided to expand foxpro support. Now I get the following error in a specific file. I have successfully uploaded another file, and I'm curious if there is anything wrong with this database. I'm sure you probably need to look at the database to determine this, but its the path to a huge message, so I will take what I can get.

Traceback (most recent call last): File "billsapi.py", line 250, in <module> x.getUsedGuns() File "billsapi.py", line 72, in getUsedGuns itemdb = dbf.Dbf('item.dbf', readOnly=True, ignoreErrors=True) File "C:\Python27\lib\site-packages\dbfpy\dbf.py", line 135, in __init__ self.header = self.HeaderClass.fromStream(self.stream) File "C:\Python27\lib\site-packages\dbfpy\header.py", line 127, in fromStream _fld = fields.lookupFor(_data[11]).fromString(_data, _pos) File "C:\Python27\lib\site-packages\dbfpy\fields.py", line 455, in lookupFor return _fieldsRegistry[typeCode] KeyError: '0' 

And here is my simple code that returns this error:

 def getUsedGuns(self): itemdb = dbf.Dbf('item.dbf', readOnly=True, ignoreErrors=True) 

As I said, I can upload other files with the problem, but maybe there is work for this particular error?

EDIT: I would also like to indicate that the file can be opened and viewed and modified in DBF View Plus.

EDIT: solution found. I actually used the python dBase module. I think my main problem was that I did not have memo files (no matter what they are, it has the extension .fpt). Here is what I am using at the moment:

 from dbf.tables import VfpTable itemdb = VfpTable('item.db') for rec in itemdb: print rec['MY_COLUM_NAME'] 

I would also like to point out that anyone who currently uses FoxPro needs to be burned.

+4
source share
3 answers

Your trace is a dbfpy way to tell you that your file has code like unsupported dbfpy code, 0 . This is Visual FoxPro ("VFP").

This is not related to memo files. Yes, if there are memo fields, they are stored in a .FPT file. foo.fpt must be present when accessing foo.dbf .

You say "" I actually finished using the python dBase module "" ... presumably you mean the Ethan Furman dbf module, which according to the PyPI entry does not support null fields.

I have a DBF reader module ( pydbfrw ) that I had in mind for the other day release. Here is an excerpt from his documents:

 Field Type Description DBF variety Python 2.x type 0 (digit zero) _NullFlags VFP N/A Notes: This field type is used only for the hidden _NullFlags field which is a bit mask saying which fields in the record should be interpreted as NULL. 

My module implements recognition and returns None for the field value where necessary. If you want a copy of the module, find my email address - for example. google ("john machin xlrd") - write me and I will send it to you.

+2
source

It may be that item.dbf uses the more advanced features of dbf that other dbf does not have. For example, integers with automatic additions were introduced very late and are not supported by most odbc drivers.

0
source

You should take a look at the Sybase Advantage Database Server . This product has excellent support for VFP DBF files. I have been using my ODBC drivers with Python through pyodbc for several years and have had excellent results using the recently released DB-API 2.0 compatible Python driver .

I was also placed in a position where I have to maintain DBF tables. Advantage Database Server was an absolute lifesaver.

0
source

Source: https://habr.com/ru/post/1343356/


All Articles