This project extracts the database schema from .DBF files in a specified folder and generates corresponding SQL CREATE TABLE statements. The extracted schemas are written to a text file (dbf_schemas.txt) for further use or reference.
- Parses
.DBFfiles to read field names, types, and lengths. - Maps DBF field types to SQLite-compatible data types.
- Generates SQL
CREATE TABLEstatements for all.DBFfiles in the specified folder.
- Python: Version 3.12
- DBFread: Version 2.0.7
- Install Python 3.12 from the official Python website: https://www.python.org/downloads/.
- Install the
DBFreadlibrary:pip install dbfread==2.0.7
- Clone or download the project to your local machine.
- Update the
dbf_foldervariable in the script with the path to the folder containing your.DBFfiles. - Run the script:
python extract_dbf_schemas.py
- The output file,
dbf_schemas.txt, will be generated in the same directory as the script.
The script:
- Reads all
.DBFfiles in the specified folder. - Converts each file's schema to an SQL
CREATE TABLEstatement using the field mapping function. - Writes the SQL statements to a text file.
Mapping DBF to SQLite Types
The map_field_type function handles the mapping of DBF field types to SQLite-compatible data types:
C:TEXT(length)N:INTEGER(for lengths ≤ 10) orREALF:REALD:DATEL:BOOLEANM:TEXT- Others: Default to
TEXT
For a .DBF file named example.DBF with the following fields:
ID(Numeric, Length: 5)Name(Character, Length: 50)Birthdate(Date)
The generated schema will look like:
CREATE TABLE example (
ID INTEGER,
Name TEXT(50),
Birthdate DATE
);Feel free to fork the repository and submit pull requests for enhancements or bug fixes.
This project is licensed under the MIT License.
For issues or questions, please open an issue in the repository or contact at devaanshpathak08@gmail.com