dbf 4.1.3 → 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +63 -52
- data/LICENSE +1 -1
- data/README.md +109 -16
- data/docs/CNAME +1 -0
- data/docs/DBF.html +200 -0
- data/docs/DBF/Column.html +947 -0
- data/docs/DBF/Column/LengthError.html +124 -0
- data/docs/DBF/Column/NameError.html +124 -0
- data/docs/DBF/ColumnType.html +115 -0
- data/docs/DBF/ColumnType/Base.html +389 -0
- data/docs/DBF/ColumnType/Boolean.html +238 -0
- data/docs/DBF/ColumnType/Currency.html +238 -0
- data/docs/DBF/ColumnType/Date.html +242 -0
- data/docs/DBF/ColumnType/DateTime.html +246 -0
- data/docs/DBF/ColumnType/Double.html +238 -0
- data/docs/DBF/ColumnType/Float.html +238 -0
- data/docs/DBF/ColumnType/General.html +238 -0
- data/docs/DBF/ColumnType/Memo.html +246 -0
- data/docs/DBF/ColumnType/Nil.html +238 -0
- data/docs/DBF/ColumnType/Number.html +242 -0
- data/docs/DBF/ColumnType/SignedLong.html +238 -0
- data/docs/DBF/ColumnType/String.html +240 -0
- data/docs/DBF/Database.html +126 -0
- data/docs/DBF/Database/Foxpro.html +653 -0
- data/docs/DBF/Database/Table.html +346 -0
- data/docs/DBF/FileNotFoundError.html +124 -0
- data/docs/DBF/Header.html +723 -0
- data/docs/DBF/Memo.html +117 -0
- data/docs/DBF/Memo/Base.html +485 -0
- data/docs/DBF/Memo/Dbase3.html +242 -0
- data/docs/DBF/Memo/Dbase4.html +230 -0
- data/docs/DBF/Memo/Foxpro.html +268 -0
- data/docs/DBF/NoColumnsDefined.html +124 -0
- data/docs/DBF/Record.html +773 -0
- data/docs/DBF/Schema.html +980 -0
- data/docs/DBF/Table.html +1571 -0
- data/docs/_index.html +415 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +497 -0
- data/docs/file.README.html +359 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +359 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +675 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/dbf/column.rb +5 -4
- data/lib/dbf/column_type.rb +26 -0
- data/lib/dbf/database/foxpro.rb +7 -2
- data/lib/dbf/header.rb +11 -3
- data/lib/dbf/record.rb +5 -5
- data/lib/dbf/schema.rb +4 -3
- data/lib/dbf/table.rb +25 -11
- data/lib/dbf/version.rb +1 -1
- data/spec/dbf/file_formats_spec.rb +18 -0
- data/spec/fixtures/dbase_02.dbf +0 -0
- metadata +52 -6
- data/docs/supported_encodings.csv +0 -60
- data/docs/supported_types.markdown +0 -38
@@ -0,0 +1,359 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.26
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'>
|
61
|
+
<h1 id="label-DBF">DBF</h1>
|
62
|
+
|
63
|
+
<p><a href="https://rubygems.org/gems/dbf"><img src="https://img.shields.io/gem/v/dbf.svg?style=flat"></a> <a href="https://travis-ci.com/infused/dbf"><img src="https://img.shields.io/travis/infused/dbf/master.svg?style=flat"></a> <a href="https://codeclimate.com/github/infused/dbf"><img src="https://img.shields.io/codeclimate/maintainability/infused/dbf.svg?style=flat"></a> <a href="https://codeclimate.com/github/infused/dbf"><img src="https://img.shields.io/codeclimate/c/infused/dbf.svg?style=flat"></a> <a href="https://rubygems.org/gems/dbf/"><img src="https://img.shields.io/gem/dt/dbf.svg"></a> <a href="https://github.com/infused/dbf"><img src="https://img.shields.io/github/license/infused/dbf.svg"></a></p>
|
64
|
+
|
65
|
+
<p>DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files</p>
|
66
|
+
<ul><li>
|
67
|
+
<p>Project page: <a href="https://github.com/infused/dbf">github.com/infused/dbf</a></p>
|
68
|
+
</li><li>
|
69
|
+
<p>API Documentation: <a href="https://dbf.infused.org">dbf.infused.org</a></p>
|
70
|
+
</li><li>
|
71
|
+
<p>Report bugs: <a href="https://github.com/infused/dbf/issues">github.com/infused/dbf/issues</a></p>
|
72
|
+
</li><li>
|
73
|
+
<p>Questions: Email <a href="mailto:keithm@infused.org">keithm@infused.org</a> and put DBF somewhere in the subject line</p>
|
74
|
+
</li><li>
|
75
|
+
<p>Change log: <a href="https://github.com/infused/dbf/blob/master/CHANGELOG.md">github.com/infused/dbf/blob/master/CHANGELOG.md</a></p>
|
76
|
+
</li></ul>
|
77
|
+
|
78
|
+
<p>NOTE: 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, please use 3.0.x (<a href="https://github.com/infused.org/dbf/tree/3_stable">github.com/infused.org/dbf/tree/3_stable</a>)</p>
|
79
|
+
|
80
|
+
<p>NOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies, please use 2.0.x (<a href="https://github.com/infused/dbf/tree/2_stable">github.com/infused/dbf/tree/2_stable</a>)</p>
|
81
|
+
|
82
|
+
<h2 id="label-Compatibility">Compatibility</h2>
|
83
|
+
|
84
|
+
<p>DBF is tested to work with the following versions of Ruby:</p>
|
85
|
+
<ul><li>
|
86
|
+
<p>Ruby 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, TruffleRuby</p>
|
87
|
+
</li></ul>
|
88
|
+
|
89
|
+
<h2 id="label-Installation">Installation</h2>
|
90
|
+
|
91
|
+
<p>Install the gem manually:</p>
|
92
|
+
|
93
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_dbf'>dbf</span>
|
94
|
+
</code></pre>
|
95
|
+
|
96
|
+
<p>Or add to your Gemfile:</p>
|
97
|
+
|
98
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
99
|
+
</code></pre>
|
100
|
+
|
101
|
+
<h2 id="label-Basic+Usage">Basic Usage</h2>
|
102
|
+
|
103
|
+
<p>Open a DBF file using a path:</p>
|
104
|
+
|
105
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
106
|
+
<span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>widgets.dbf</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
107
|
+
</code></pre>
|
108
|
+
|
109
|
+
<p>Open a DBF file using an IO object:</p>
|
110
|
+
|
111
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>widgets.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
112
|
+
<span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
|
113
|
+
</code></pre>
|
114
|
+
|
115
|
+
<p>Open a DBF by passing in raw data (wrap the raw data with StringIO):</p>
|
116
|
+
|
117
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='const'>StringIO</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>raw binary data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
118
|
+
</code></pre>
|
119
|
+
|
120
|
+
<p>Enumerate all records</p>
|
121
|
+
|
122
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
123
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
124
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_email'>email</span>
|
125
|
+
<span class='kw'>end</span>
|
126
|
+
</code></pre>
|
127
|
+
|
128
|
+
<p>Find a single record</p>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span> <span class='op'>=</span> <span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>6</span><span class='rparen'>)</span>
|
131
|
+
</code></pre>
|
132
|
+
|
133
|
+
<p>Note that find() will return nil if the requested record has been deleted and not yet pruned from the database.</p>
|
134
|
+
|
135
|
+
<p>The value for an attribute can be accessed via element reference in several ways.</p>
|
136
|
+
|
137
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_slot_number'>slot_number</span> <span class='comment'># underscored field name as method
|
138
|
+
</span>
|
139
|
+
<span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>SlotNumber</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='comment'># original field name in dbf file
|
140
|
+
</span><span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>slot_number</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='comment'># underscored field name string
|
141
|
+
</span><span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='symbol'>:slot_number</span><span class='rbracket'>]</span> <span class='comment'># underscored field name symbol
|
142
|
+
</span></code></pre>
|
143
|
+
|
144
|
+
<p>Get a hash of all attributes. The keys are the original column names.</p>
|
145
|
+
|
146
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_attributes'>attributes</span>
|
147
|
+
<span class='comment'># => {"Name" => "Thing1 | SlotNumber" => 1}
|
148
|
+
</span></code></pre>
|
149
|
+
|
150
|
+
<p>Search for records using a simple hash format. Multiple search criteria are ANDed. Use the block form if the resulting recordset could be large, otherwise all records will be loaded into memory.</p>
|
151
|
+
|
152
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># find all records with slot_number equal to s42
|
153
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:all</span><span class='comma'>,</span> <span class='label'>slot_number:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>s42</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_widget'>widget</span><span class='op'>|</span>
|
154
|
+
<span class='comment'># the record will be nil if deleted, but not yet pruned from the database
|
155
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_widget'>widget</span>
|
156
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_serial_number'>serial_number</span>
|
157
|
+
<span class='kw'>end</span>
|
158
|
+
<span class='kw'>end</span>
|
159
|
+
|
160
|
+
<span class='comment'># find the first record with slot_number equal to s42
|
161
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span> <span class='symbol'>:first</span><span class='comma'>,</span> <span class='label'>slot_number:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>s42</span><span class='tstring_end'>'</span></span>
|
162
|
+
|
163
|
+
<span class='comment'># find record number 10
|
164
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>10</span><span class='rparen'>)</span>
|
165
|
+
</code></pre>
|
166
|
+
|
167
|
+
<h2 id="label-Enumeration">Enumeration</h2>
|
168
|
+
|
169
|
+
<p>DBF::Table is a Ruby Enumerable. This means you can use any Enumerable method. This means that you get a bunch of traversal, searching and sorting methods for free. For example, let's get only records created before January 1st, 2015:</p>
|
170
|
+
|
171
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_w'>w</span><span class='op'>|</span> <span class='id identifier rubyid_w'>w</span><span class='period'>.</span><span class='id identifier rubyid_created_date'>created_date</span> <span class='op'><</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>2015</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
172
|
+
</code></pre>
|
173
|
+
|
174
|
+
<p>Or custom sorting:</p>
|
175
|
+
|
176
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_w'>w</span><span class='op'>|</span> <span class='id identifier rubyid_w'>w</span><span class='period'>.</span><span class='id identifier rubyid_created_date'>created_date</span> <span class='rbrace'>}</span>
|
177
|
+
</code></pre>
|
178
|
+
|
179
|
+
<h2 id="label-Encodings+-28Code+Pages-29">Encodings (Code Pages)</h2>
|
180
|
+
|
181
|
+
<p>dBase supports encoding non-english characters in different formats. Unfortunately, the format used is not always set, so you may have to specify it manually. For example, you have a DBF file from Russia and you are getting bad data. Try using the 'Russion OEM' encoding:</p>
|
182
|
+
|
183
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cp866</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
184
|
+
</code></pre>
|
185
|
+
|
186
|
+
<p>| Code Page | Encoding | Description | | ——— | ——– | ———– | | 01 | cp437 | U.S. MS–DOS | | 02 | cp850 | International MS–DOS | | 03 | cp1252 | Windows ANSI | | 08 | cp865 | Danish OEM | | 09 | cp437 | Dutch OEM | | 0a | cp850 | Dutch OEM* | | 0b | cp437 | Finnish OEM | | 0d | cp437 | French OEM | | 0e | cp850 | French OEM* | | 0f | cp437 | German OEM | | 10 | cp850 | German OEM* | | 11 | cp437 | Italian OEM | | 12 | cp850 | Italian OEM* | | 13 | cp932 | Japanese Shift-JIS | | 14 | cp850 | Spanish OEM* | | 15 | cp437 | Swedish OEM | | 16 | cp850 | Swedish OEM* | | 17 | cp865 | Norwegian OEM | | 18 | cp437 | Spanish OEM | | 19 | cp437 | English OEM (Britain) | | 1a | cp850 | English OEM (Britain)* | | 1b | cp437 | English OEM (U.S.) | | 1c | cp863 | French OEM (Canada) | | 1d | cp850 | French OEM* | | 1f | cp852 | Czech OEM | | 22 | cp852 | Hungarian OEM | | 23 | cp852 | Polish OEM | | 24 | cp860 | Portuguese OEM | | 25 | cp850 | Portuguese OEM* | | 26 | cp866 | Russian OEM | | 37 | cp850 | English OEM (U.S.)* | | 40 | cp852 | Romanian OEM | | 4d | cp936 | Chinese GBK (PRC) | | 4e | cp949 | Korean (ANSI/OEM) | | 4f | cp950 | Chinese Big5 (Taiwan) | | 50 | cp874 | Thai (ANSI/OEM) | | 57 | cp1252 | ANSI | | 58 | cp1252 | Western European ANSI | | 59 | cp1252 | Spanish ANSI | | 64 | cp852 | Eastern European MS–DOS | | 65 | cp866 | Russian MS–DOS | | 66 | cp865 | Nordic MS–DOS | | 67 | cp861 | Icelandic MS–DOS | | 6a | cp737 | Greek MS–DOS (437G) | | 6b | cp857 | Turkish MS–DOS | | 6c | cp863 | French–Canadian MS–DOS | | 78 | cp950 | Taiwan Big 5 | | 79 | cp949 | Hangul (Wansung) | | 7a | cp936 | PRC GBK | | 7b | cp932 | Japanese Shift-JIS | | 7c | cp874 | Thai Windows/MS–DOS | | 86 | cp737 | Greek OEM | | 87 | cp852 | Slovenian OEM | | 88 | cp857 | Turkish OEM | | c8 | cp1250 | Eastern European Windows | | c9 | cp1251 | Russian Windows | | ca | cp1254 | Turkish Windows | | cb | cp1253 | Greek Windows | | cc | cp1257 | Baltic Windows |</p>
|
187
|
+
|
188
|
+
<h2 id="label-Migrating+to+ActiveRecord">Migrating to ActiveRecord</h2>
|
189
|
+
|
190
|
+
<p>An example of migrating a DBF book table to ActiveRecord using a migration:</p>
|
191
|
+
|
192
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
193
|
+
|
194
|
+
<span class='kw'>class</span> <span class='const'>Book</span> <span class='op'><</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Base</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
195
|
+
|
196
|
+
<span class='kw'>class</span> <span class='const'>CreateBooks</span> <span class='op'><</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Migration</span>
|
197
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_up'>up</span>
|
198
|
+
<span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db/dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
199
|
+
<span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
200
|
+
|
201
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_reset_column_information'>reset_column_information</span>
|
202
|
+
<span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
203
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>title:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span><span class='comma'>,</span> <span class='label'>author:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='rparen'>)</span>
|
204
|
+
<span class='kw'>end</span>
|
205
|
+
<span class='kw'>end</span>
|
206
|
+
|
207
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_down'>down</span>
|
208
|
+
<span class='id identifier rubyid_drop_table'>drop_table</span> <span class='symbol'>:books</span>
|
209
|
+
<span class='kw'>end</span>
|
210
|
+
<span class='kw'>end</span>
|
211
|
+
</code></pre>
|
212
|
+
|
213
|
+
<p>If you have initalized the DBF::Table with raw data, you will need to set the exported table name manually:</p>
|
214
|
+
|
215
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_table_name</span><span class='tstring_end'>'</span></span>
|
216
|
+
</code></pre>
|
217
|
+
|
218
|
+
<h2 id="label-Migrating+to+Sequel">Migrating to Sequel</h2>
|
219
|
+
|
220
|
+
<p>An example of migrating a DBF book table to Sequel using a migration:</p>
|
221
|
+
|
222
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
223
|
+
|
224
|
+
<span class='kw'>class</span> <span class='const'>Book</span> <span class='op'><</span> <span class='const'>Sequel</span><span class='op'>::</span><span class='const'>Model</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
225
|
+
|
226
|
+
<span class='const'>Sequel</span><span class='period'>.</span><span class='id identifier rubyid_migration'>migration</span> <span class='kw'>do</span>
|
227
|
+
<span class='id identifier rubyid_up'>up</span> <span class='kw'>do</span>
|
228
|
+
<span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db/dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
229
|
+
<span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_schema'>schema</span><span class='lparen'>(</span><span class='symbol'>:sequel</span><span class='comma'>,</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># passing true to limit output to create_table() only
|
230
|
+
</span>
|
231
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_reset_column_information'>reset_column_information</span>
|
232
|
+
<span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
233
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>title:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span><span class='comma'>,</span> <span class='label'>author:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='rparen'>)</span>
|
234
|
+
<span class='kw'>end</span>
|
235
|
+
<span class='kw'>end</span>
|
236
|
+
|
237
|
+
<span class='id identifier rubyid_down'>down</span> <span class='kw'>do</span>
|
238
|
+
<span class='id identifier rubyid_drop_table'>drop_table</span><span class='lparen'>(</span><span class='symbol'>:books</span><span class='rparen'>)</span>
|
239
|
+
<span class='kw'>end</span>
|
240
|
+
<span class='kw'>end</span>
|
241
|
+
</code></pre>
|
242
|
+
|
243
|
+
<p>If you have initialized the DBF::Table with raw data, you will need to set the exported table name manually:</p>
|
244
|
+
|
245
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_table_name</span><span class='tstring_end'>'</span></span>
|
246
|
+
</code></pre>
|
247
|
+
|
248
|
+
<h2 id="label-Command-line+utility">Command-line utility</h2>
|
249
|
+
|
250
|
+
<p>A small command-line utility called dbf is installed along with the gem.</p>
|
251
|
+
|
252
|
+
<pre class="code ruby"><code class="ruby">$ dbf -h
|
253
|
+
usage: dbf [-h|-s|-a] filename
|
254
|
+
-h = print this message
|
255
|
+
-v = print the version number
|
256
|
+
-s = print summary information
|
257
|
+
-a = create an ActiveRecord::Schema
|
258
|
+
-r = create a Sequel Migration
|
259
|
+
-c = export as CSV
|
260
|
+
</code></pre>
|
261
|
+
|
262
|
+
<p>Create an executable ActiveRecord schema:</p>
|
263
|
+
|
264
|
+
<pre class="code ruby"><code class="ruby">dbf -a books.dbf > books_schema.rb
|
265
|
+
</code></pre>
|
266
|
+
|
267
|
+
<p>Create an executable Sequel schema:</p>
|
268
|
+
|
269
|
+
<pre class="code ruby"><code class="ruby">dbf -r books.dbf > migrate/001_create_books.rb
|
270
|
+
</code></pre>
|
271
|
+
|
272
|
+
<p>Dump all records to a CSV file:</p>
|
273
|
+
|
274
|
+
<pre class="code ruby"><code class="ruby">dbf -c books.dbf > books.csv
|
275
|
+
</code></pre>
|
276
|
+
|
277
|
+
<h2 id="label-Reading+a+Visual+Foxpro+database+-28v8-2C+v9-29">Reading a Visual Foxpro database (v8, v9)</h2>
|
278
|
+
|
279
|
+
<p>A special Database::Foxpro class is available to read Visual Foxpro container files (file with .dbc extension). When using this class long field names are supported and tables can be referenced without using names.</p>
|
280
|
+
|
281
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
282
|
+
|
283
|
+
<span class='id identifier rubyid_contacts'>contacts</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Database.html" title="DBF::Database (module)">Database</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Database/Foxpro.html" title="DBF::Database::Foxpro (class)">Foxpro</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Database/Foxpro.html#initialize-instance_method" title="DBF::Database::Foxpro#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>contact_database.dbc</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_contacts'>contacts</span>
|
284
|
+
<span class='id identifier rubyid_my_contact'>my_contact</span> <span class='op'>=</span> <span class='id identifier rubyid_contacts'>contacts</span><span class='period'>.</span><span class='id identifier rubyid_record'>record</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_spouses_interests'>spouses_interests</span>
|
285
|
+
</code></pre>
|
286
|
+
|
287
|
+
<h2 id="label-dBase+version+compatibility">dBase version compatibility</h2>
|
288
|
+
|
289
|
+
<p>The basic dBase data types are generally supported well. Support for the advanced data types in dbase V and FoxPro are still experimental or not supported. If you have insight into how any of the unsupported data types are implemented, please give me a shout. FoxBase/dBase II files are not supported at this time.</p>
|
290
|
+
|
291
|
+
<h3 id="label-Supported+data+types+by+dBase+version">Supported data types by dBase version</h3>
|
292
|
+
|
293
|
+
<p>| Version | Description | C | N | L | D | M | F | B | G | P | Y | T | I | V | X | @ | O | + | |———|———————————–|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—| | 02 | FoxBase | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 03 | dBase III without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 04 | dBase IV without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 05 | dBase V without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 07 | Visual Objects 1.x | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 30 | Visual FoxPro | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | 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 | | 7b | dBase IV with memo file | Y | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | | 83 | dBase III with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | | 87 | Visual Objects 1.x with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | | 8b | dBase IV with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - | | 8e | dBase IV with SQL table | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - | | f5 | FoxPro with memo file | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | 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 |</p>
|
294
|
+
|
295
|
+
<p>Data type descriptions</p>
|
296
|
+
<ul><li>
|
297
|
+
<p>C = Character</p>
|
298
|
+
</li><li>
|
299
|
+
<p>N = Number</p>
|
300
|
+
</li><li>
|
301
|
+
<p>L = Logical</p>
|
302
|
+
</li><li>
|
303
|
+
<p>D = Date</p>
|
304
|
+
</li><li>
|
305
|
+
<p>M = Memo</p>
|
306
|
+
</li><li>
|
307
|
+
<p>F = Float</p>
|
308
|
+
</li><li>
|
309
|
+
<p>B = Binary</p>
|
310
|
+
</li><li>
|
311
|
+
<p>G = General</p>
|
312
|
+
</li><li>
|
313
|
+
<p>P = Picture</p>
|
314
|
+
</li><li>
|
315
|
+
<p>Y = Currency</p>
|
316
|
+
</li><li>
|
317
|
+
<p>T = DateTime</p>
|
318
|
+
</li><li>
|
319
|
+
<p>I = Integer</p>
|
320
|
+
</li><li>
|
321
|
+
<p>V = VariField</p>
|
322
|
+
</li><li>
|
323
|
+
<p>X = SQL compat</p>
|
324
|
+
</li><li>
|
325
|
+
<p>@ = Timestamp</p>
|
326
|
+
</li><li>
|
327
|
+
<p>O = Double</p>
|
328
|
+
</li><li><ul><li>
|
329
|
+
<p>= Autoincrement</p>
|
330
|
+
</li></ul>
|
331
|
+
</li></ul>
|
332
|
+
|
333
|
+
<h2 id="label-Limitations">Limitations</h2>
|
334
|
+
<ul><li>
|
335
|
+
<p>DBF is read-only</p>
|
336
|
+
</li><li>
|
337
|
+
<p>Index files are not utilized</p>
|
338
|
+
</li></ul>
|
339
|
+
|
340
|
+
<h2 id="label-License">License</h2>
|
341
|
+
|
342
|
+
<p>Copyright © 2006-2021 Keith Morrison <<a href="mailto:keithm@infused.org">keithm@infused.org</a>></p>
|
343
|
+
|
344
|
+
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
|
345
|
+
|
346
|
+
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
|
347
|
+
|
348
|
+
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
|
349
|
+
</div></div>
|
350
|
+
|
351
|
+
<div id="footer">
|
352
|
+
Generated on Sun Aug 8 16:19:07 2021 by
|
353
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
354
|
+
0.9.26 (ruby-3.0.1).
|
355
|
+
</div>
|
356
|
+
|
357
|
+
</div>
|
358
|
+
</body>
|
359
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.26</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,359 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.26
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'>
|
61
|
+
<h1 id="label-DBF">DBF</h1>
|
62
|
+
|
63
|
+
<p><a href="https://rubygems.org/gems/dbf"><img src="https://img.shields.io/gem/v/dbf.svg?style=flat"></a> <a href="https://travis-ci.com/infused/dbf"><img src="https://img.shields.io/travis/infused/dbf/master.svg?style=flat"></a> <a href="https://codeclimate.com/github/infused/dbf"><img src="https://img.shields.io/codeclimate/maintainability/infused/dbf.svg?style=flat"></a> <a href="https://codeclimate.com/github/infused/dbf"><img src="https://img.shields.io/codeclimate/c/infused/dbf.svg?style=flat"></a> <a href="https://rubygems.org/gems/dbf/"><img src="https://img.shields.io/gem/dt/dbf.svg"></a> <a href="https://github.com/infused/dbf"><img src="https://img.shields.io/github/license/infused/dbf.svg"></a></p>
|
64
|
+
|
65
|
+
<p>DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files</p>
|
66
|
+
<ul><li>
|
67
|
+
<p>Project page: <a href="https://github.com/infused/dbf">github.com/infused/dbf</a></p>
|
68
|
+
</li><li>
|
69
|
+
<p>API Documentation: <a href="https://dbf.infused.org">dbf.infused.org</a></p>
|
70
|
+
</li><li>
|
71
|
+
<p>Report bugs: <a href="https://github.com/infused/dbf/issues">github.com/infused/dbf/issues</a></p>
|
72
|
+
</li><li>
|
73
|
+
<p>Questions: Email <a href="mailto:keithm@infused.org">keithm@infused.org</a> and put DBF somewhere in the subject line</p>
|
74
|
+
</li><li>
|
75
|
+
<p>Change log: <a href="https://github.com/infused/dbf/blob/master/CHANGELOG.md">github.com/infused/dbf/blob/master/CHANGELOG.md</a></p>
|
76
|
+
</li></ul>
|
77
|
+
|
78
|
+
<p>NOTE: 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, please use 3.0.x (<a href="https://github.com/infused.org/dbf/tree/3_stable">github.com/infused.org/dbf/tree/3_stable</a>)</p>
|
79
|
+
|
80
|
+
<p>NOTE: Beginning with version 3 we have dropped support for Ruby 1.8 and 1.9. If you need support for older Rubies, please use 2.0.x (<a href="https://github.com/infused/dbf/tree/2_stable">github.com/infused/dbf/tree/2_stable</a>)</p>
|
81
|
+
|
82
|
+
<h2 id="label-Compatibility">Compatibility</h2>
|
83
|
+
|
84
|
+
<p>DBF is tested to work with the following versions of Ruby:</p>
|
85
|
+
<ul><li>
|
86
|
+
<p>Ruby 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, TruffleRuby</p>
|
87
|
+
</li></ul>
|
88
|
+
|
89
|
+
<h2 id="label-Installation">Installation</h2>
|
90
|
+
|
91
|
+
<p>Install the gem manually:</p>
|
92
|
+
|
93
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_dbf'>dbf</span>
|
94
|
+
</code></pre>
|
95
|
+
|
96
|
+
<p>Or add to your Gemfile:</p>
|
97
|
+
|
98
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
99
|
+
</code></pre>
|
100
|
+
|
101
|
+
<h2 id="label-Basic+Usage">Basic Usage</h2>
|
102
|
+
|
103
|
+
<p>Open a DBF file using a path:</p>
|
104
|
+
|
105
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
106
|
+
<span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>widgets.dbf</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
107
|
+
</code></pre>
|
108
|
+
|
109
|
+
<p>Open a DBF file using an IO object:</p>
|
110
|
+
|
111
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_data'>data</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>widgets.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
112
|
+
<span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span>
|
113
|
+
</code></pre>
|
114
|
+
|
115
|
+
<p>Open a DBF by passing in raw data (wrap the raw data with StringIO):</p>
|
116
|
+
|
117
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='const'>StringIO</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>raw binary data</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='rparen'>)</span>
|
118
|
+
</code></pre>
|
119
|
+
|
120
|
+
<p>Enumerate all records</p>
|
121
|
+
|
122
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
123
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
124
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_email'>email</span>
|
125
|
+
<span class='kw'>end</span>
|
126
|
+
</code></pre>
|
127
|
+
|
128
|
+
<p>Find a single record</p>
|
129
|
+
|
130
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span> <span class='op'>=</span> <span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>6</span><span class='rparen'>)</span>
|
131
|
+
</code></pre>
|
132
|
+
|
133
|
+
<p>Note that find() will return nil if the requested record has been deleted and not yet pruned from the database.</p>
|
134
|
+
|
135
|
+
<p>The value for an attribute can be accessed via element reference in several ways.</p>
|
136
|
+
|
137
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_slot_number'>slot_number</span> <span class='comment'># underscored field name as method
|
138
|
+
</span>
|
139
|
+
<span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>SlotNumber</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span> <span class='comment'># original field name in dbf file
|
140
|
+
</span><span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>slot_number</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='comment'># underscored field name string
|
141
|
+
</span><span class='id identifier rubyid_widget'>widget</span><span class='lbracket'>[</span><span class='symbol'>:slot_number</span><span class='rbracket'>]</span> <span class='comment'># underscored field name symbol
|
142
|
+
</span></code></pre>
|
143
|
+
|
144
|
+
<p>Get a hash of all attributes. The keys are the original column names.</p>
|
145
|
+
|
146
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_attributes'>attributes</span>
|
147
|
+
<span class='comment'># => {"Name" => "Thing1 | SlotNumber" => 1}
|
148
|
+
</span></code></pre>
|
149
|
+
|
150
|
+
<p>Search for records using a simple hash format. Multiple search criteria are ANDed. Use the block form if the resulting recordset could be large, otherwise all records will be loaded into memory.</p>
|
151
|
+
|
152
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># find all records with slot_number equal to s42
|
153
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='symbol'>:all</span><span class='comma'>,</span> <span class='label'>slot_number:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>s42</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_widget'>widget</span><span class='op'>|</span>
|
154
|
+
<span class='comment'># the record will be nil if deleted, but not yet pruned from the database
|
155
|
+
</span> <span class='kw'>if</span> <span class='id identifier rubyid_widget'>widget</span>
|
156
|
+
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_widget'>widget</span><span class='period'>.</span><span class='id identifier rubyid_serial_number'>serial_number</span>
|
157
|
+
<span class='kw'>end</span>
|
158
|
+
<span class='kw'>end</span>
|
159
|
+
|
160
|
+
<span class='comment'># find the first record with slot_number equal to s42
|
161
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span> <span class='symbol'>:first</span><span class='comma'>,</span> <span class='label'>slot_number:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>s42</span><span class='tstring_end'>'</span></span>
|
162
|
+
|
163
|
+
<span class='comment'># find record number 10
|
164
|
+
</span><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>10</span><span class='rparen'>)</span>
|
165
|
+
</code></pre>
|
166
|
+
|
167
|
+
<h2 id="label-Enumeration">Enumeration</h2>
|
168
|
+
|
169
|
+
<p>DBF::Table is a Ruby Enumerable. This means you can use any Enumerable method. This means that you get a bunch of traversal, searching and sorting methods for free. For example, let's get only records created before January 1st, 2015:</p>
|
170
|
+
|
171
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_select'>select</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_w'>w</span><span class='op'>|</span> <span class='id identifier rubyid_w'>w</span><span class='period'>.</span><span class='id identifier rubyid_created_date'>created_date</span> <span class='op'><</span> <span class='const'>Date</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>2015</span><span class='comma'>,</span> <span class='int'>1</span><span class='comma'>,</span> <span class='int'>1</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
172
|
+
</code></pre>
|
173
|
+
|
174
|
+
<p>Or custom sorting:</p>
|
175
|
+
|
176
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_widgets'>widgets</span><span class='period'>.</span><span class='id identifier rubyid_sort_by'>sort_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_w'>w</span><span class='op'>|</span> <span class='id identifier rubyid_w'>w</span><span class='period'>.</span><span class='id identifier rubyid_created_date'>created_date</span> <span class='rbrace'>}</span>
|
177
|
+
</code></pre>
|
178
|
+
|
179
|
+
<h2 id="label-Encodings+-28Code+Pages-29">Encodings (Code Pages)</h2>
|
180
|
+
|
181
|
+
<p>dBase supports encoding non-english characters in different formats. Unfortunately, the format used is not always set, so you may have to specify it manually. For example, you have a DBF file from Russia and you are getting bad data. Try using the 'Russion OEM' encoding:</p>
|
182
|
+
|
183
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cp866</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
184
|
+
</code></pre>
|
185
|
+
|
186
|
+
<p>| Code Page | Encoding | Description | | ——— | ——– | ———– | | 01 | cp437 | U.S. MS–DOS | | 02 | cp850 | International MS–DOS | | 03 | cp1252 | Windows ANSI | | 08 | cp865 | Danish OEM | | 09 | cp437 | Dutch OEM | | 0a | cp850 | Dutch OEM* | | 0b | cp437 | Finnish OEM | | 0d | cp437 | French OEM | | 0e | cp850 | French OEM* | | 0f | cp437 | German OEM | | 10 | cp850 | German OEM* | | 11 | cp437 | Italian OEM | | 12 | cp850 | Italian OEM* | | 13 | cp932 | Japanese Shift-JIS | | 14 | cp850 | Spanish OEM* | | 15 | cp437 | Swedish OEM | | 16 | cp850 | Swedish OEM* | | 17 | cp865 | Norwegian OEM | | 18 | cp437 | Spanish OEM | | 19 | cp437 | English OEM (Britain) | | 1a | cp850 | English OEM (Britain)* | | 1b | cp437 | English OEM (U.S.) | | 1c | cp863 | French OEM (Canada) | | 1d | cp850 | French OEM* | | 1f | cp852 | Czech OEM | | 22 | cp852 | Hungarian OEM | | 23 | cp852 | Polish OEM | | 24 | cp860 | Portuguese OEM | | 25 | cp850 | Portuguese OEM* | | 26 | cp866 | Russian OEM | | 37 | cp850 | English OEM (U.S.)* | | 40 | cp852 | Romanian OEM | | 4d | cp936 | Chinese GBK (PRC) | | 4e | cp949 | Korean (ANSI/OEM) | | 4f | cp950 | Chinese Big5 (Taiwan) | | 50 | cp874 | Thai (ANSI/OEM) | | 57 | cp1252 | ANSI | | 58 | cp1252 | Western European ANSI | | 59 | cp1252 | Spanish ANSI | | 64 | cp852 | Eastern European MS–DOS | | 65 | cp866 | Russian MS–DOS | | 66 | cp865 | Nordic MS–DOS | | 67 | cp861 | Icelandic MS–DOS | | 6a | cp737 | Greek MS–DOS (437G) | | 6b | cp857 | Turkish MS–DOS | | 6c | cp863 | French–Canadian MS–DOS | | 78 | cp950 | Taiwan Big 5 | | 79 | cp949 | Hangul (Wansung) | | 7a | cp936 | PRC GBK | | 7b | cp932 | Japanese Shift-JIS | | 7c | cp874 | Thai Windows/MS–DOS | | 86 | cp737 | Greek OEM | | 87 | cp852 | Slovenian OEM | | 88 | cp857 | Turkish OEM | | c8 | cp1250 | Eastern European Windows | | c9 | cp1251 | Russian Windows | | ca | cp1254 | Turkish Windows | | cb | cp1253 | Greek Windows | | cc | cp1257 | Baltic Windows |</p>
|
187
|
+
|
188
|
+
<h2 id="label-Migrating+to+ActiveRecord">Migrating to ActiveRecord</h2>
|
189
|
+
|
190
|
+
<p>An example of migrating a DBF book table to ActiveRecord using a migration:</p>
|
191
|
+
|
192
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
193
|
+
|
194
|
+
<span class='kw'>class</span> <span class='const'>Book</span> <span class='op'><</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Base</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
195
|
+
|
196
|
+
<span class='kw'>class</span> <span class='const'>CreateBooks</span> <span class='op'><</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>Migration</span>
|
197
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_up'>up</span>
|
198
|
+
<span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db/dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
199
|
+
<span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_schema'>schema</span><span class='rparen'>)</span>
|
200
|
+
|
201
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_reset_column_information'>reset_column_information</span>
|
202
|
+
<span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
203
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>title:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span><span class='comma'>,</span> <span class='label'>author:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='rparen'>)</span>
|
204
|
+
<span class='kw'>end</span>
|
205
|
+
<span class='kw'>end</span>
|
206
|
+
|
207
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_down'>down</span>
|
208
|
+
<span class='id identifier rubyid_drop_table'>drop_table</span> <span class='symbol'>:books</span>
|
209
|
+
<span class='kw'>end</span>
|
210
|
+
<span class='kw'>end</span>
|
211
|
+
</code></pre>
|
212
|
+
|
213
|
+
<p>If you have initalized the DBF::Table with raw data, you will need to set the exported table name manually:</p>
|
214
|
+
|
215
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_table_name</span><span class='tstring_end'>'</span></span>
|
216
|
+
</code></pre>
|
217
|
+
|
218
|
+
<h2 id="label-Migrating+to+Sequel">Migrating to Sequel</h2>
|
219
|
+
|
220
|
+
<p>An example of migrating a DBF book table to Sequel using a migration:</p>
|
221
|
+
|
222
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
223
|
+
|
224
|
+
<span class='kw'>class</span> <span class='const'>Book</span> <span class='op'><</span> <span class='const'>Sequel</span><span class='op'>::</span><span class='const'>Model</span><span class='semicolon'>;</span> <span class='kw'>end</span>
|
225
|
+
|
226
|
+
<span class='const'>Sequel</span><span class='period'>.</span><span class='id identifier rubyid_migration'>migration</span> <span class='kw'>do</span>
|
227
|
+
<span class='id identifier rubyid_up'>up</span> <span class='kw'>do</span>
|
228
|
+
<span class='id identifier rubyid_table'>table</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Table.html" title="DBF::Table (class)">Table</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Table.html#initialize-instance_method" title="DBF::Table#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db/dbf/books.dbf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
229
|
+
<span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_schema'>schema</span><span class='lparen'>(</span><span class='symbol'>:sequel</span><span class='comma'>,</span> <span class='kw'>true</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># passing true to limit output to create_table() only
|
230
|
+
</span>
|
231
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_reset_column_information'>reset_column_information</span>
|
232
|
+
<span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_record'>record</span><span class='op'>|</span>
|
233
|
+
<span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_create'>create</span><span class='lparen'>(</span><span class='label'>title:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span><span class='comma'>,</span> <span class='label'>author:</span> <span class='id identifier rubyid_record'>record</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='rparen'>)</span>
|
234
|
+
<span class='kw'>end</span>
|
235
|
+
<span class='kw'>end</span>
|
236
|
+
|
237
|
+
<span class='id identifier rubyid_down'>down</span> <span class='kw'>do</span>
|
238
|
+
<span class='id identifier rubyid_drop_table'>drop_table</span><span class='lparen'>(</span><span class='symbol'>:books</span><span class='rparen'>)</span>
|
239
|
+
<span class='kw'>end</span>
|
240
|
+
<span class='kw'>end</span>
|
241
|
+
</code></pre>
|
242
|
+
|
243
|
+
<p>If you have initialized the DBF::Table with raw data, you will need to set the exported table name manually:</p>
|
244
|
+
|
245
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_table'>table</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_table_name</span><span class='tstring_end'>'</span></span>
|
246
|
+
</code></pre>
|
247
|
+
|
248
|
+
<h2 id="label-Command-line+utility">Command-line utility</h2>
|
249
|
+
|
250
|
+
<p>A small command-line utility called dbf is installed along with the gem.</p>
|
251
|
+
|
252
|
+
<pre class="code ruby"><code class="ruby">$ dbf -h
|
253
|
+
usage: dbf [-h|-s|-a] filename
|
254
|
+
-h = print this message
|
255
|
+
-v = print the version number
|
256
|
+
-s = print summary information
|
257
|
+
-a = create an ActiveRecord::Schema
|
258
|
+
-r = create a Sequel Migration
|
259
|
+
-c = export as CSV
|
260
|
+
</code></pre>
|
261
|
+
|
262
|
+
<p>Create an executable ActiveRecord schema:</p>
|
263
|
+
|
264
|
+
<pre class="code ruby"><code class="ruby">dbf -a books.dbf > books_schema.rb
|
265
|
+
</code></pre>
|
266
|
+
|
267
|
+
<p>Create an executable Sequel schema:</p>
|
268
|
+
|
269
|
+
<pre class="code ruby"><code class="ruby">dbf -r books.dbf > migrate/001_create_books.rb
|
270
|
+
</code></pre>
|
271
|
+
|
272
|
+
<p>Dump all records to a CSV file:</p>
|
273
|
+
|
274
|
+
<pre class="code ruby"><code class="ruby">dbf -c books.dbf > books.csv
|
275
|
+
</code></pre>
|
276
|
+
|
277
|
+
<h2 id="label-Reading+a+Visual+Foxpro+database+-28v8-2C+v9-29">Reading a Visual Foxpro database (v8, v9)</h2>
|
278
|
+
|
279
|
+
<p>A special Database::Foxpro class is available to read Visual Foxpro container files (file with .dbc extension). When using this class long field names are supported and tables can be referenced without using names.</p>
|
280
|
+
|
281
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>dbf</span><span class='tstring_end'>'</span></span>
|
282
|
+
|
283
|
+
<span class='id identifier rubyid_contacts'>contacts</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="DBF.html" title="DBF (module)">DBF</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Database.html" title="DBF::Database (module)">Database</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="DBF/Database/Foxpro.html" title="DBF::Database::Foxpro (class)">Foxpro</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="DBF/Database/Foxpro.html#initialize-instance_method" title="DBF::Database::Foxpro#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>contact_database.dbc</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_contacts'>contacts</span>
|
284
|
+
<span class='id identifier rubyid_my_contact'>my_contact</span> <span class='op'>=</span> <span class='id identifier rubyid_contacts'>contacts</span><span class='period'>.</span><span class='id identifier rubyid_record'>record</span><span class='lparen'>(</span><span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_spouses_interests'>spouses_interests</span>
|
285
|
+
</code></pre>
|
286
|
+
|
287
|
+
<h2 id="label-dBase+version+compatibility">dBase version compatibility</h2>
|
288
|
+
|
289
|
+
<p>The basic dBase data types are generally supported well. Support for the advanced data types in dbase V and FoxPro are still experimental or not supported. If you have insight into how any of the unsupported data types are implemented, please give me a shout. FoxBase/dBase II files are not supported at this time.</p>
|
290
|
+
|
291
|
+
<h3 id="label-Supported+data+types+by+dBase+version">Supported data types by dBase version</h3>
|
292
|
+
|
293
|
+
<p>| Version | Description | C | N | L | D | M | F | B | G | P | Y | T | I | V | X | @ | O | + | |———|———————————–|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—|—| | 02 | FoxBase | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 03 | dBase III without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 04 | dBase IV without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 05 | dBase V without memo file | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 07 | Visual Objects 1.x | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | - | | 30 | Visual FoxPro | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | 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 | | 7b | dBase IV with memo file | Y | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | | 83 | dBase III with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | | 87 | Visual Objects 1.x with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | - | - | - | - | | 8b | dBase IV with memo file | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - | | 8e | dBase IV with SQL table | Y | Y | Y | Y | Y | - | - | - | - | - | - | - | - | N | - | - | - | | f5 | FoxPro with memo file | Y | Y | Y | Y | Y | Y | Y | Y | N | Y | N | Y | 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 |</p>
|
294
|
+
|
295
|
+
<p>Data type descriptions</p>
|
296
|
+
<ul><li>
|
297
|
+
<p>C = Character</p>
|
298
|
+
</li><li>
|
299
|
+
<p>N = Number</p>
|
300
|
+
</li><li>
|
301
|
+
<p>L = Logical</p>
|
302
|
+
</li><li>
|
303
|
+
<p>D = Date</p>
|
304
|
+
</li><li>
|
305
|
+
<p>M = Memo</p>
|
306
|
+
</li><li>
|
307
|
+
<p>F = Float</p>
|
308
|
+
</li><li>
|
309
|
+
<p>B = Binary</p>
|
310
|
+
</li><li>
|
311
|
+
<p>G = General</p>
|
312
|
+
</li><li>
|
313
|
+
<p>P = Picture</p>
|
314
|
+
</li><li>
|
315
|
+
<p>Y = Currency</p>
|
316
|
+
</li><li>
|
317
|
+
<p>T = DateTime</p>
|
318
|
+
</li><li>
|
319
|
+
<p>I = Integer</p>
|
320
|
+
</li><li>
|
321
|
+
<p>V = VariField</p>
|
322
|
+
</li><li>
|
323
|
+
<p>X = SQL compat</p>
|
324
|
+
</li><li>
|
325
|
+
<p>@ = Timestamp</p>
|
326
|
+
</li><li>
|
327
|
+
<p>O = Double</p>
|
328
|
+
</li><li><ul><li>
|
329
|
+
<p>= Autoincrement</p>
|
330
|
+
</li></ul>
|
331
|
+
</li></ul>
|
332
|
+
|
333
|
+
<h2 id="label-Limitations">Limitations</h2>
|
334
|
+
<ul><li>
|
335
|
+
<p>DBF is read-only</p>
|
336
|
+
</li><li>
|
337
|
+
<p>Index files are not utilized</p>
|
338
|
+
</li></ul>
|
339
|
+
|
340
|
+
<h2 id="label-License">License</h2>
|
341
|
+
|
342
|
+
<p>Copyright © 2006-2021 Keith Morrison <<a href="mailto:keithm@infused.org">keithm@infused.org</a>></p>
|
343
|
+
|
344
|
+
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
|
345
|
+
|
346
|
+
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
|
347
|
+
|
348
|
+
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
|
349
|
+
</div></div>
|
350
|
+
|
351
|
+
<div id="footer">
|
352
|
+
Generated on Sun Aug 8 16:19:06 2021 by
|
353
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
354
|
+
0.9.26 (ruby-3.0.1).
|
355
|
+
</div>
|
356
|
+
|
357
|
+
</div>
|
358
|
+
</body>
|
359
|
+
</html>
|