{"id":13878155,"url":"https://github.com/infused/dbf","last_synced_at":"2025-07-16T14:31:31.407Z","repository":{"id":395947,"uuid":"13966","full_name":"infused/dbf","owner":"infused","description":"DBF is a small, fast Ruby library for reading dBase, xBase, Clipper, and FoxPro database files.","archived":false,"fork":false,"pushed_at":"2024-11-04T02:21:49.000Z","size":1069,"stargazers_count":262,"open_issues_count":1,"forks_count":88,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-11-17T14:07:43.830Z","etag":null,"topics":["database","dbase","dbf","foxpro","ruby","xbase"],"latest_commit_sha":null,"homepage":"http://rdoc.info/projects/infused/dbf","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infused.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"infused","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2008-05-02T06:44:06.000Z","updated_at":"2024-11-04T02:21:53.000Z","dependencies_parsed_at":"2023-07-05T14:46:54.228Z","dependency_job_id":"101bdcde-1962-44c2-b188-a754b4cf4cd5","html_url":"https://github.com/infused/dbf","commit_stats":{"total_commits":844,"total_committers":35,"mean_commits":"24.114285714285714","dds":0.2109004739336493,"last_synced_commit":"31f7113526b35808d7ed20538e128c2be9faa1a5"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infused%2Fdbf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infused%2Fdbf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infused%2Fdbf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infused%2Fdbf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infused","download_url":"https://codeload.github.com/infused/dbf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","dbase","dbf","foxpro","ruby","xbase"],"created_at":"2024-08-06T08:01:41.245Z","updated_at":"2024-11-24T07:30:48.562Z","avatar_url":"https://github.com/infused.png","language":"Ruby","readme":"# DBF\n\n[![Version](https://img.shields.io/gem/v/dbf.svg?style=flat)](https://rubygems.org/gems/dbf)\n[![Build Status](https://github.com/infused/dbf/actions/workflows/build.yml/badge.svg)](https://github.com/infused/dbf/actions/workflows/build.yml)\n[![Code Quality](https://img.shields.io/codeclimate/maintainability/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)\n[![Code Coverage](https://img.shields.io/codeclimate/c/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)\n[![Total Downloads](https://img.shields.io/gem/dt/dbf.svg)](https://rubygems.org/gems/dbf/)\n[![License](https://img.shields.io/github/license/infused/dbf.svg)](https://github.com/infused/dbf)\n\nDBF is a small, fast Ruby library for reading dBase, xBase, Clipper, and FoxPro database files.\n\n* Project page: \u003chttps://github.com/infused/dbf\u003e\n* API Documentation: \u003chttps://rubydoc.info/github/infused/dbf\u003e\n* Report bugs: \u003chttps://github.com/infused/dbf/issues\u003e\n* Questions: Email \u003cmailto:keithm@infused.org\u003e and put DBF somewhere in the\n  subject line\n* Change log: \u003chttps://github.com/infused/dbf/blob/master/CHANGELOG.md\u003e\n\nNOTE: Beginning with version 4.3 we have dropped support for Ruby 3.0 and earlier.\n\nNOTE: Beginning with version 4 we have dropped support for Ruby 2.0, 2.1, 2.2, and 2.3. If you need support for these older Rubies,\nplease use 3.0.x (\u003chttps://github.com/infused.org/dbf/tree/3_stable\u003e)\n\nNOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies,\nplease use 2.0.x (\u003chttps://github.com/infused/dbf/tree/2_stable\u003e)\n\n## Compatibility\n\nDBF is tested to work with the following versions of Ruby:\n\n* Ruby 3.1.x, 3.2.x, 3.3.x\n\n## Installation\n\nInstall the gem manually:\n\n```ruby\ngem install dbf\n```\n\nOr add to your Gemfile:\n\n```ruby\ngem 'dbf'\n```\n\n## Basic Usage\n\nOpen a DBF file using a path:\n\n```ruby\nrequire 'dbf'\nwidgets = DBF::Table.new(\"widgets.dbf\")\n```\n\nOpen a DBF file using an IO object:\n\n```ruby\ndata = File.open('widgets.dbf')\nwidgets = DBF::Table.new(data)\n```\n\nOpen a DBF by passing in raw data (wrap the raw data with StringIO):\n\n```ruby\nwidgets = DBF::Table.new(StringIO.new('raw binary data'))\n```\n\nEnumerate all records\n\n```ruby\nwidgets.each do |record|\n  puts record.name\n  puts record.email\nend\n```\n\nFind a single record\n\n```ruby\nwidget = widgets.find(6)\n```\n\nNote that find() will return nil if the requested record has been deleted\nand not yet pruned from the database.\n\nThe value for an attribute can be accessed via element reference in several\nways.\n\n```ruby\nwidget.slot_number     # underscored field name as method\n\nwidget[\"SlotNumber\"]   # original field name in dbf file\nwidget['slot_number']  # underscored field name string\nwidget[:slot_number]   # underscored field name symbol\n```\n\nGet a hash of all attributes. The keys are the original column names.\n\n```ruby\nwidget.attributes\n# =\u003e {\"Name\" =\u003e \"Thing1 | SlotNumber\" =\u003e 1}\n```\n\nSearch for records using a simple hash format. Multiple search criteria are\nANDed. Use the block form if the resulting record set is too big. Otherwise, all records are loaded into memory.\n\n```ruby\n# find all records with slot_number equal to s42\nwidgets.find(:all, slot_number: 's42') do |widget|\n  # the record will be nil if deleted, but not yet pruned from the database\n  if widget\n    puts widget.serial_number\n  end\nend\n\n# find the first record with slot_number equal to s42\nwidgets.find :first, slot_number: 's42'\n\n# find record number 10\nwidgets.find(10)\n```\n\n## Enumeration\n\nDBF::Table is a Ruby Enumerable, so you get several traversal, search, and sort methods\nfor free. For example, let's get only records created before January 1st, 2015:\n\n```ruby\nwidgets.select { |w| w.created_date \u003c Date.new(2015, 1, 1) }\n```\n\nOr custom sorting:\n\n```ruby\nwidgets.sort_by { |w| w.created_date }\n```\n\n## Encodings (Code Pages)\n\ndBase supports encoding non-english characters with different character sets. Unfortunately, the character set used may not be set explicitly. In that case, you will have to specify it manually. For example, if you know the dbf file is encoded with 'Russian OEM':\n\n```ruby\ntable = DBF::Table.new('dbf/books.dbf', nil, 'cp866')\n```\n\n| Code Page | Encoding | Description |\n| --------- | -------- | ----------- |\n| 01 | cp437 | U.S. MS–DOS |\n| 02 | cp850 | International MS–DOS |\n| 03 | cp1252 | Windows ANSI |\n| 08 | cp865 | Danish OEM |\n| 09 | cp437 | Dutch OEM |\n| 0a | cp850 | Dutch OEM* |\n| 0b | cp437 | Finnish OEM |\n| 0d | cp437 | French OEM |\n| 0e | cp850 | French OEM* |\n| 0f | cp437 | German OEM |\n| 10 | cp850 | German OEM* |\n| 11 | cp437 | Italian OEM |\n| 12 | cp850 | Italian OEM* |\n| 13 | cp932 | Japanese Shift-JIS |\n| 14 | cp850 | Spanish OEM* |\n| 15 | cp437 | Swedish OEM |\n| 16 | cp850 | Swedish OEM* |\n| 17 | cp865 | Norwegian OEM |\n| 18 | cp437 | Spanish OEM |\n| 19 | cp437 | English OEM (Britain) |\n| 1a | cp850 | English OEM (Britain)* |\n| 1b | cp437 | English OEM (U.S.) |\n| 1c | cp863 | French OEM (Canada) |\n| 1d | cp850 | French OEM* |\n| 1f | cp852 | Czech OEM |\n| 22 | cp852 | Hungarian OEM |\n| 23 | cp852 | Polish OEM |\n| 24 | cp860 | Portuguese OEM |\n| 25 | cp850 | Portuguese OEM* |\n| 26 | cp866 | Russian OEM |\n| 37 | cp850 | English OEM (U.S.)* |\n| 40 | cp852 | Romanian OEM |\n| 4d | cp936 | Chinese GBK (PRC) |\n| 4e | cp949 | Korean (ANSI/OEM) |\n| 4f | cp950 | Chinese Big5 (Taiwan) |\n| 50 | cp874 | Thai (ANSI/OEM) |\n| 57 | cp1252 | ANSI |\n| 58 | cp1252 | Western European ANSI |\n| 59 | cp1252 | Spanish ANSI |\n| 64 | cp852 | Eastern European MS–DOS |\n| 65 | cp866 | Russian MS–DOS |\n| 66 | cp865 | Nordic MS–DOS |\n| 67 | cp861 | Icelandic MS–DOS |\n| 6a | cp737 | Greek MS–DOS (437G) |\n| 6b | cp857 | Turkish MS–DOS |\n| 6c | cp863 | French–Canadian MS–DOS |\n| 78 | cp950 | Taiwan Big 5 |\n| 79 | cp949 | Hangul (Wansung) |\n| 7a | cp936 | PRC GBK |\n| 7b | cp932 | Japanese Shift-JIS |\n| 7c | cp874 | Thai Windows/MS–DOS |\n| 86 | cp737 | Greek OEM |\n| 87 | cp852 | Slovenian OEM |\n| 88 | cp857 | Turkish OEM |\n| c8 | cp1250 | Eastern European Windows |\n| c9 | cp1251 | Russian Windows |\n| ca | cp1254 | Turkish Windows |\n| cb | cp1253 | Greek Windows |\n| cc | cp1257 | Baltic Windows |\n\n## Migrating to ActiveRecord\n\nAn example of migrating a DBF book table to ActiveRecord using a migration:\n\n```ruby\nrequire 'dbf'\n\nclass Book \u003c ActiveRecord::Base; end\n\nclass CreateBooks \u003c ActiveRecord::Migration\n  def self.up\n    table = DBF::Table.new('db/dbf/books.dbf')\n    eval(table.schema)\n\n    Book.reset_column_information\n    table.each do |record|\n      Book.create(title: record.title, author: record.author)\n    end\n  end\n\n  def self.down\n    drop_table :books\n  end\nend\n```\n\nIf you have initialized the DBF::Table with raw data, you will need to set the\nexported table name manually:\n\n```ruby\ntable.name = 'my_table_name'\n```\n\n## Migrating to Sequel\n\nAn example of migrating a DBF book table to Sequel using a migration:\n\n```ruby\nrequire 'dbf'\n\nclass Book \u003c Sequel::Model; end\n\nSequel.migration do\n  up do\n    table = DBF::Table.new('db/dbf/books.dbf')\n    eval(table.schema(:sequel, true)) # passing true to limit output to create_table() only\n\n    Book.reset_column_information\n    table.each do |record|\n      Book.create(title: record.title, author: record.author)\n    end\n  end\n\n  down do\n    drop_table(:books)\n  end\nend\n```\n\nIf you have initialized the DBF::Table with raw data, you will need to set the\nexported table name manually:\n\n```ruby\ntable.name = 'my_table_name'\n```\n\n## Command-line utility\n\nA small command-line utility called dbf is installed with the gem.\n\n    $ dbf -h\n    usage: dbf [-h|-s|-a] filename\n      -h = print this message\n      -v = print the version number\n      -s = print summary information\n      -a = create an ActiveRecord::Schema\n      -r = create a Sequel Migration\n      -c = export as CSV\n\nCreate an executable ActiveRecord schema:\n\n    dbf -a books.dbf \u003e books_schema.rb\n\nCreate an executable Sequel schema:\n\n    dbf -r books.dbf \u003e migrate/001_create_books.rb\n\nDump all records to a CSV file:\n\n    dbf -c books.dbf \u003e books.csv\n\n## Reading a Visual Foxpro database (v8, v9)\n\nA special Database::Foxpro class is available to read Visual Foxpro container\nfiles (file with .dbc extension). When using this class, long field names are supported, and tables can be referenced without using names.\n\n```ruby\nrequire 'dbf'\n\ncontacts = DBF::Database::Foxpro.new('contact_database.dbc').contacts\nmy_contact = contacts.record(1).spouses_interests\n```\n\n## dBase version compatibility\n\nThe basic dBase data types are generally supported well. Support for the\nadvanced data types in dBase V and FoxPro are still experimental or not\nsupported. If you have insight into how any of the unsupported data types are\nimplemented, please open an issue on Github. FoxBase/dBase II files are not supported\nat this time.\n\n### Supported data types by dBase version\n\n| Version | Description                                         | C | N | L | D | M | F | B | G | P | Y | T | I | V | X | @ | O | + |\n|---------|-----------------------------------------------------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|\n| 02      | FoxBase                                             | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - |\n| 03      | dBase III without memo file                         | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - |\n| 04      | dBase IV without memo file                          | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - |\n| 05      | dBase V without memo file                           | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - |\n| 07      | Visual Objects 1.x                                  | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - |\n| 30      | Visual FoxPro                                       | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | N | N | N | N | - |\n| 31      | Visual FoxPro with AutoIncrement                    | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | N | N | N | N | N |\n| 32      | Visual FoxPro with field type Varchar or Varbinary  | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | N | N | N | N | N |\n| 7b      | dBase IV with memo file                             | Y | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - |\n| 83      | dBase III with memo file                            | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - |\n| 87      | Visual Objects 1.x with memo file                   | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - |\n| 8b      | dBase IV with memo file                             | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - |\n| 8e      | dBase IV with SQL table                             | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - |\n| f5      | FoxPro with memo file                               | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | N | N | N | N | N |\n| fb      | FoxPro without memo file                            | Y | Y | Y | Y | - | Y | Y | Y | N | Y | N | Y | N | N | N | N | N |\n\nData type descriptions\n\n* C = Character\n* N = Number\n* L = Logical\n* D = Date\n* M = Memo\n* F = Float\n* B = Binary\n* G = General\n* P = Picture\n* Y = Currency\n* T = DateTime\n* I = Integer\n* V = VariField\n* X = SQL compat\n* @ = Timestamp\n* O = Double\n* + = Autoincrement\n\n## Limitations\n\n* DBF is read-only\n* Index files are not utilized\n\n## License\n\nCopyright (c) 2006-2024 Keith Morrison \u003c\u003ckeithm@infused.org\u003e\u003e\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","funding_links":["https://github.com/sponsors/infused"],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfused%2Fdbf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfused%2Fdbf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfused%2Fdbf/lists"}