dbf 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +19 -0
- data/Rakefile +3 -3
- data/lib/dbf/reader.rb +19 -6
- metadata +2 -2
data/README.txt
CHANGED
@@ -46,6 +46,25 @@ Copyright (c) 2006-2007 Keith Morrison <keithm@infused.org, www.infused.org>
|
|
46
46
|
reader.find :first, :first_name => 'Keith'
|
47
47
|
reader.find(10)
|
48
48
|
|
49
|
+
== Dealing with deleted records
|
50
|
+
xBase database systems do not physically delete records, but merely mark the
|
51
|
+
records for deletion. The file must be compacted using a special utility to
|
52
|
+
remove the deleted records.
|
53
|
+
|
54
|
+
DBF returns nil for any record that has been marked for deletion, so if the
|
55
|
+
database file has deleted records, you need to be careful when looping. For
|
56
|
+
example, the following will fail if it encounters a nil record:
|
57
|
+
|
58
|
+
reader.records.each do |record| puts record['name'] end
|
59
|
+
|
60
|
+
Therefore, it's a good idea to compact the records array to remove any nil
|
61
|
+
records before iterating over it:
|
62
|
+
|
63
|
+
reader.records.compact.each do |record|
|
64
|
+
puts record['name']
|
65
|
+
puts record['email']
|
66
|
+
end
|
67
|
+
|
49
68
|
== Limitations and known bugs
|
50
69
|
|
51
70
|
* DBF is read-only at the moment
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
|
|
2
2
|
require 'spec/rake/spectask'
|
3
3
|
|
4
4
|
PKG_NAME = "dbf"
|
5
|
-
PKG_VERSION = "0.5.
|
5
|
+
PKG_VERSION = "0.5.2"
|
6
6
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
7
7
|
|
8
8
|
Hoe.new PKG_NAME, PKG_VERSION do |p|
|
@@ -17,7 +17,7 @@ Hoe.new PKG_NAME, PKG_VERSION do |p|
|
|
17
17
|
end
|
18
18
|
|
19
19
|
desc 'Run tests'
|
20
|
-
task :default => :test
|
20
|
+
task :default => [:spec, :test]
|
21
21
|
|
22
22
|
desc 'Run tests'
|
23
23
|
Rake::TestTask.new :test do |t|
|
@@ -28,6 +28,6 @@ end
|
|
28
28
|
|
29
29
|
desc "Run specs"
|
30
30
|
Spec::Rake::SpecTask.new :spec do |t|
|
31
|
-
t.spec_opts = ["-f specdoc"]
|
31
|
+
# t.spec_opts = ["-f specdoc"]
|
32
32
|
t.spec_files = FileList['spec/**/*spec.rb']
|
33
33
|
end
|
data/lib/dbf/reader.rb
CHANGED
@@ -2,16 +2,22 @@ module DBF
|
|
2
2
|
class Reader
|
3
3
|
# The total number of fields (columns)
|
4
4
|
attr_reader :field_count
|
5
|
+
|
5
6
|
# An array of DBF::Field records
|
6
7
|
attr_reader :fields
|
7
|
-
|
8
|
+
|
9
|
+
# The total number of records. This number includes records marked as deleted.
|
8
10
|
attr_reader :record_count
|
11
|
+
|
9
12
|
# Internal dBase version number
|
10
13
|
attr_reader :version
|
14
|
+
|
11
15
|
# Last updated datetime
|
12
16
|
attr_reader :last_updated
|
17
|
+
|
13
18
|
# Either :fpt or :dpt
|
14
19
|
attr_reader :memo_file_format
|
20
|
+
|
15
21
|
# The block size for memo records
|
16
22
|
attr_reader :memo_block_size
|
17
23
|
|
@@ -55,7 +61,8 @@ module DBF
|
|
55
61
|
@fields.detect {|f| f.name == field_name.to_s}
|
56
62
|
end
|
57
63
|
|
58
|
-
# An array of all the records contained in the database file
|
64
|
+
# An array of all the records contained in the database file. Each record is an instance
|
65
|
+
# of DBF::Record (or nil if the record is marked for deletion).
|
59
66
|
def records
|
60
67
|
if in_memory?
|
61
68
|
@records ||= get_all_records_from_file
|
@@ -66,7 +73,7 @@ module DBF
|
|
66
73
|
|
67
74
|
alias_method :rows, :records
|
68
75
|
|
69
|
-
# Returns the record at <tt>index</tt>.
|
76
|
+
# Returns a DBF::Record (or nil if the record has been marked for deletion) for the record at <tt>index</tt>.
|
70
77
|
def record(index)
|
71
78
|
if in_memory?
|
72
79
|
records[index]
|
@@ -237,10 +244,16 @@ module DBF
|
|
237
244
|
end
|
238
245
|
|
239
246
|
def get_all_records_from_file
|
240
|
-
|
241
|
-
|
242
|
-
|
247
|
+
all_records = []
|
248
|
+
0.upto(@record_count - 1) do |n|
|
249
|
+
seek_to_record(n)
|
250
|
+
if active_record?
|
251
|
+
all_records << DBF::Record.new(self, @data_file, @memo_file)
|
252
|
+
else
|
253
|
+
all_records << nil
|
254
|
+
end
|
243
255
|
end
|
256
|
+
all_records
|
244
257
|
end
|
245
258
|
|
246
259
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: dbf
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2007-06-
|
6
|
+
version: 0.5.2
|
7
|
+
date: 2007-06-12 00:00:00 -07:00
|
8
8
|
summary: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
|
9
9
|
require_paths:
|
10
10
|
- lib
|