KirbyBase 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -3
- data/changes.txt +6 -0
- data/examples/aaa_try_this_first/kbtest.rb +1 -1
- data/examples/column_required_test/column_required_test.rb +11 -0
- data/examples/default_value_test/default_value_test.rb +21 -10
- data/kirbybaserubymanual.html +3 -3
- data/lib/kirbybase.rb +10 -4
- data/test/tc_local_db.rb +1 -1
- data/test/tc_local_table.rb +57 -3
- metadata +2 -2
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= KirbyBase 2.5.
|
1
|
+
= KirbyBase 2.5.2
|
2
2
|
|
3
3
|
A small, plain-text, dbms written in Ruby. It can be used either embedded
|
4
4
|
or client/server.
|
@@ -24,8 +24,8 @@ See the examples directory for examples of how to use KirbyBase.
|
|
24
24
|
* install.rb - install script
|
25
25
|
* changes.txt - history of changes.
|
26
26
|
* kirbybaserubymanual.html - documentation
|
27
|
-
* kirbybase.rb - dbms library
|
28
|
-
* kbserver.rb - multi-threaded database server script.
|
27
|
+
* lib/kirbybase.rb - dbms library
|
28
|
+
* bin/kbserver.rb - multi-threaded database server script.
|
29
29
|
* test directory - unit tests
|
30
30
|
* examples directory - many example scripts demonstrating features.
|
31
31
|
* images directory - images used in manual.
|
data/changes.txt
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2005-12-30:: Version 2.5.2
|
2
|
+
* Changed the behavior of KBTable#insert method. If user specifies nil
|
3
|
+
for a field value and there is a default value for that field, the
|
4
|
+
default value will no longer override the user specified nil value.
|
5
|
+
Thanks to Assaph Mehr for suggesting this.
|
6
|
+
|
1
7
|
2005-12-28:: Version 2.5.1
|
2
8
|
* Fixed a bug that had broken encrypted tables.
|
3
9
|
* Changed KBTable#pack method so that it raises an error if trying to
|
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
#-------------------- Initialize KirbyBase Instance ------------------------
|
13
13
|
# To run local, single-user, uncomment next line.
|
14
|
-
db = KirbyBase.new
|
14
|
+
db = KirbyBase.new
|
15
15
|
|
16
16
|
# To run as a client in a multi-user environment, uncomment next line.
|
17
17
|
# Also, make sure kbserver.rb is running.
|
@@ -24,6 +24,17 @@ rescue StandardError => e
|
|
24
24
|
puts;puts
|
25
25
|
end
|
26
26
|
|
27
|
+
begin
|
28
|
+
# Same thing should happen if I don't even specify a value for
|
29
|
+
# :category.
|
30
|
+
address_book_tbl.insert(:firstname=>'Bruce', :lastname=>'Wayne',
|
31
|
+
:street_addres=>'1234 Bat Cave', :city=>'Gotham City',
|
32
|
+
:phone=>'111-111-1111')
|
33
|
+
rescue StandardError => e
|
34
|
+
puts e
|
35
|
+
puts;puts
|
36
|
+
end
|
37
|
+
|
27
38
|
# Now, let's turn off the required flag for :category.
|
28
39
|
address_book_tbl.change_column_required(:category, false)
|
29
40
|
|
@@ -13,30 +13,41 @@ address_book_tbl = db.create_table(:address_book,
|
|
13
13
|
:city, :String, :phone, :String,
|
14
14
|
:category, {:DataType=>:String, :Default=>'Super Hero'})
|
15
15
|
|
16
|
-
# Insert a record. Notice that I am passing
|
17
|
-
# will insert the default value, 'Super Hero', in that field.
|
18
|
-
address_book_tbl.insert('Bruce', 'Wayne',
|
19
|
-
'
|
16
|
+
# Insert a record. Notice that I am not passing a value for :category.
|
17
|
+
# KirbyBase will insert the default value, 'Super Hero', in that field.
|
18
|
+
address_book_tbl.insert(:firstname=>'Bruce', :lastname=>'Wayne',
|
19
|
+
:street_address=>'1234 Bat Cave', :city=>'Gotham City',
|
20
|
+
:phone=>'111-111-1111')
|
20
21
|
|
21
22
|
# Insert another record. Here we supply the value for :category, so
|
22
23
|
# KirbyBase will use it instead of the default.
|
23
|
-
address_book_tbl.insert('Bugs', 'Bunny',
|
24
|
-
'
|
24
|
+
address_book_tbl.insert(:firstname=>'Bugs', :lastname=>'Bunny',
|
25
|
+
:street_address=>'1234 Rabbit Hole', :city=>'The Forest',
|
26
|
+
:phone=>'222-222-2222', :category=>'Cartoon Character')
|
27
|
+
|
28
|
+
# Insert another record. Here we explicitly supply nil as the value for
|
29
|
+
# category. KirbyBase will not override this with the default value
|
30
|
+
# because we explicitly specified nil as the value.
|
31
|
+
address_book_tbl.insert(:firstname=>'Super', :lastname=>'Man',
|
32
|
+
:street_address=>'1234 Fortress of Solitude', :city=>'Metropolis',
|
33
|
+
:phone=>'333-333-3333', :category=>nil)
|
25
34
|
|
26
35
|
# Now lets change the default value for :category to 'President'.
|
27
36
|
address_book_tbl.change_column_default_value(:category, 'President')
|
28
37
|
|
29
38
|
# And let's add another record without supplying a value for :category.
|
30
|
-
address_book_tbl.insert(firstname
|
31
|
-
street_address
|
39
|
+
address_book_tbl.insert(:firstname=>'George', :lastname=>'Bush',
|
40
|
+
:street_address=>'1600 Pennsylvania Ave', :city=>'Washington',
|
41
|
+
:phone=>'333-333-3333')
|
32
42
|
|
33
43
|
# Now, let's remove the default value for :category
|
34
44
|
address_book_tbl.change_column_default_value(:category, nil)
|
35
45
|
|
36
46
|
# And add another record. We won't specify a value for :category and,
|
37
47
|
# KirbyBase will not use a default value, because we removed it.
|
38
|
-
address_book_tbl.insert('Silver', 'Surfer',
|
39
|
-
'
|
48
|
+
address_book_tbl.insert(:firstname=>'Silver', :lastname=>'Surfer',
|
49
|
+
:street_address=>'1234 Galaxy Way', :city=>'Any City',
|
50
|
+
:phone=>'444-444-4444')
|
40
51
|
|
41
52
|
# Now lets print the table out and you will see how all of the defaults
|
42
53
|
# worked.
|
data/kirbybaserubymanual.html
CHANGED
@@ -262,7 +262,7 @@ div.exampleblock-content {
|
|
262
262
|
<h1>KirbyBase Manual (Ruby Version)</h1>
|
263
263
|
<span id="author">Jamey Cribbs</span><br />
|
264
264
|
<span id="email"><tt><<a href="mailto:jcribbs@twmi.rr.com">jcribbs@twmi.rr.com</a>></tt></span><br />
|
265
|
-
v2.5.
|
265
|
+
v2.5.2 December 2005
|
266
266
|
</div>
|
267
267
|
<div id="preamble">
|
268
268
|
<div class="sectionbody">
|
@@ -753,7 +753,7 @@ memo/blob files, you need to pass the location as an argument, like so:</p>
|
|
753
753
|
<pre><tt>db = KirbyBase.new(:local, nil, './', '.tbl', './memos')</tt></pre>
|
754
754
|
</div></div>
|
755
755
|
<p>If you don't want KirbyBase to spend time initially creating all of the
|
756
|
-
indexes for the tables in the database, you can pass
|
756
|
+
indexes for the tables in the database, you can pass true as the
|
757
757
|
delay_index_creation argument:</p>
|
758
758
|
<div class="listingblock">
|
759
759
|
<div class="content">
|
@@ -2266,7 +2266,7 @@ an Array like all of the regular indexes. So selects are even faster.</p>
|
|
2266
2266
|
</div>
|
2267
2267
|
<div id="footer">
|
2268
2268
|
<div id="footer-text">
|
2269
|
-
Last updated
|
2269
|
+
Last updated 30-Dec-2005 10:16:41 Eastern Daylight Time
|
2270
2270
|
</div>
|
2271
2271
|
</div>
|
2272
2272
|
</body>
|
data/lib/kirbybase.rb
CHANGED
@@ -146,6 +146,12 @@ require 'yaml'
|
|
146
146
|
# * Moved #build_header_string from KBEngine class to KirbyBase class.
|
147
147
|
# * Added KirbyBase::VERSION constant.
|
148
148
|
#
|
149
|
+
# 2005-12-30:: Version 2.5.2
|
150
|
+
# * Changed the behavior of KBTable#insert method. If user explicitly
|
151
|
+
# specifies nil for a field value and there is a default value for that
|
152
|
+
# field, the default value will no longer override the user specified nil
|
153
|
+
# value. Thanks to Assaph Mehr for suggesting this.
|
154
|
+
#
|
149
155
|
#
|
150
156
|
#---------------------------------------------------------------------------
|
151
157
|
# KBTypeConversionsMixin
|
@@ -336,7 +342,7 @@ class KirbyBase
|
|
336
342
|
include DRb::DRbUndumped
|
337
343
|
include KBTypeConversionsMixin
|
338
344
|
|
339
|
-
VERSION = "2.5.
|
345
|
+
VERSION = "2.5.2"
|
340
346
|
|
341
347
|
attr_reader :engine
|
342
348
|
|
@@ -2102,10 +2108,10 @@ class KBTable
|
|
2102
2108
|
|
2103
2109
|
input_rec = Struct.new(*field_names).new(*field_names.zip(
|
2104
2110
|
@field_defaults).collect do |fn, fd|
|
2105
|
-
if input_rec
|
2106
|
-
fd
|
2107
|
-
else
|
2111
|
+
if input_rec.has_key?(fn)
|
2108
2112
|
input_rec[fn]
|
2113
|
+
else
|
2114
|
+
fd
|
2109
2115
|
end
|
2110
2116
|
end)
|
2111
2117
|
|
data/test/tc_local_db.rb
CHANGED
data/test/tc_local_table.rb
CHANGED
@@ -123,7 +123,7 @@ class TestTableLocal < Test::Unit::TestCase
|
|
123
123
|
t.encrypt = @encrypted }
|
124
124
|
tbl.insert('Spitfire', nil)
|
125
125
|
|
126
|
-
assert_equal([1, 'Spitfire',
|
126
|
+
assert_equal([1, 'Spitfire', nil], tbl[1].to_a)
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_insert_007
|
@@ -219,7 +219,7 @@ class TestTableLocal < Test::Unit::TestCase
|
|
219
219
|
tbl = @db.create_table(:plane, :name, :String,
|
220
220
|
:speed, {:DataType=>:Integer, :Default=>300, :Required=>true}
|
221
221
|
) { |t| t.encrypt = @encrypted }
|
222
|
-
tbl.insert(:name => 'Spitfire'
|
222
|
+
tbl.insert(:name => 'Spitfire')
|
223
223
|
|
224
224
|
assert_raise(ArgumentError) { tbl.update(:speed => nil) { |r|
|
225
225
|
r.recno == 1 } }
|
@@ -459,6 +459,34 @@ class TestTableLocal < Test::Unit::TestCase
|
|
459
459
|
assert_equal([1, 'one', 'bob'], tbl[1].to_a)
|
460
460
|
end
|
461
461
|
|
462
|
+
def test_column_required_005
|
463
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
464
|
+
{:DataType => :String, :Required => true}) { |t|
|
465
|
+
t.encrypt = @encrypted }
|
466
|
+
tbl.insert('one', 'two')
|
467
|
+
|
468
|
+
assert_raise(ArgumentError) {
|
469
|
+
tbl.update('one', nil) { |r| r.recno == 1 } }
|
470
|
+
end
|
471
|
+
|
472
|
+
def test_column_required_006
|
473
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
474
|
+
{:DataType => :String, :Required => true}) { |t|
|
475
|
+
t.encrypt = @encrypted }
|
476
|
+
tbl.insert('one', 'two')
|
477
|
+
|
478
|
+
assert_raise(ArgumentError) {
|
479
|
+
tbl.update(:two => nil) { |r| r.recno == 1 } }
|
480
|
+
end
|
481
|
+
|
482
|
+
def test_column_required_007
|
483
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
484
|
+
{:DataType => :String, :Required => true, :Default => 'three'}
|
485
|
+
) { |t| t.encrypt = @encrypted }
|
486
|
+
|
487
|
+
assert_raise(ArgumentError) { tbl.insert('one', nil) }
|
488
|
+
end
|
489
|
+
|
462
490
|
def test_change_column_required_001
|
463
491
|
tbl = @db.create_table(:empty, :one, :String, :two, :String
|
464
492
|
) { |t| t.encrypt = @encrypted }
|
@@ -481,7 +509,7 @@ class TestTableLocal < Test::Unit::TestCase
|
|
481
509
|
{:DataType => :String, :Default => 'two'}) { |t|
|
482
510
|
t.encrypt = @encrypted }
|
483
511
|
tbl.insert('one', nil)
|
484
|
-
assert_equal([1, 'one',
|
512
|
+
assert_equal([1, 'one', nil], tbl[1].to_a)
|
485
513
|
end
|
486
514
|
|
487
515
|
def test_column_default_002
|
@@ -493,6 +521,32 @@ class TestTableLocal < Test::Unit::TestCase
|
|
493
521
|
assert_equal([1, 'one', 'not two'], tbl[1].to_a)
|
494
522
|
end
|
495
523
|
|
524
|
+
def test_column_default_003
|
525
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
526
|
+
{:DataType => :String, :Default => 'two'}) { |t|
|
527
|
+
t.encrypt = @encrypted }
|
528
|
+
tbl.insert(:one => 'one')
|
529
|
+
|
530
|
+
assert_equal([1, 'one', 'two'], tbl[1].to_a)
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_column_default_004
|
534
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
535
|
+
{:DataType => :String, :Default => 'two'}) { |t|
|
536
|
+
t.encrypt = @encrypted }
|
537
|
+
tbl.insert(Struct.new(:one, :two).new('one'))
|
538
|
+
|
539
|
+
assert_equal([1, 'one', nil], tbl[1].to_a)
|
540
|
+
end
|
541
|
+
|
542
|
+
def test_column_default_005
|
543
|
+
tbl = @db.create_table(:empty, :one, :String, :two,
|
544
|
+
{:DataType => :String, :Default => 'two', :Required => true}) { |t|
|
545
|
+
t.encrypt = @encrypted }
|
546
|
+
|
547
|
+
assert_raise(ArgumentError) { tbl.insert('one', nil) }
|
548
|
+
end
|
549
|
+
|
496
550
|
def test_change_column_default_value_001
|
497
551
|
tbl = @db.create_table(:empty, :one, :String, :two, :String
|
498
552
|
) { |t| t.encrypt = @encrypted }
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: KirbyBase
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.5.
|
7
|
-
date:
|
6
|
+
version: 2.5.2
|
7
|
+
date: 2006-01-03
|
8
8
|
summary: "KirbyBase is a simple, pure-Ruby, plain-text, flat-file database management
|
9
9
|
system."
|
10
10
|
require_paths:
|