KirbyBase 2.6 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/README +65 -67
  2. data/bin/kbserver.rb +18 -18
  3. data/changes.txt +144 -137
  4. data/examples/aaa_try_this_first/kbtest.rb +237 -237
  5. data/examples/add_column_test/add_column_test.rb +27 -27
  6. data/examples/calculated_field_test/calculated_field_test.rb +51 -51
  7. data/examples/change_column_type_test/change_column_type_test.rb +25 -25
  8. data/examples/column_required_test/column_required_test.rb +44 -44
  9. data/examples/crosstab_test/crosstab_test.rb +100 -100
  10. data/examples/csv_import_test/csv_import_test.rb +31 -31
  11. data/examples/csv_import_test/plane.csv +11 -11
  12. data/examples/default_value_test/default_value_test.rb +54 -54
  13. data/examples/drop_column_test/drop_column_test.rb +24 -24
  14. data/examples/indexes_test/add_index_test.rb +46 -46
  15. data/examples/indexes_test/drop_index_test.rb +65 -65
  16. data/examples/indexes_test/index_test.rb +94 -94
  17. data/examples/kbserver_as_win32_service/kbserver_daemon.rb +47 -47
  18. data/examples/kbserver_as_win32_service/kbserverctl.rb +75 -75
  19. data/examples/link_many_test/link_many_test.rb +70 -70
  20. data/examples/lookup_field_test/lookup_field_test.rb +55 -55
  21. data/examples/lookup_field_test/lookup_field_test_2.rb +62 -62
  22. data/examples/lookup_field_test/the_hal_fulton_feature_test.rb +69 -69
  23. data/examples/many_to_many_test/many_to_many_test.rb +65 -65
  24. data/examples/memo_test/memo_test.rb +74 -74
  25. data/examples/record_class_test/record_class_test.rb +77 -77
  26. data/examples/record_class_test/record_class_test2.rb +31 -31
  27. data/examples/rename_column_test/rename_column_test.rb +45 -45
  28. data/examples/rename_table_test/rename_table_test.rb +38 -38
  29. data/examples/yaml_field_test/yaml_field_test.rb +47 -47
  30. data/kirbybaserubymanual.html +2324 -2324
  31. data/lib/kirbybase.rb +3907 -3880
  32. data/test/tc_local_table.rb +108 -108
  33. metadata +56 -54
@@ -1,74 +1,74 @@
1
- # This script is an example of how you can use KirbyBase's new Memo field
2
- # type.
3
-
4
- require 'kirbybase'
5
-
6
- db = KirbyBase.new { |d| d.memo_blob_path = './memos' }
7
-
8
- #db = KirbyBase.new(:client, 'localhost', 44444)
9
-
10
-
11
- # If table exists, delete it.
12
- db.drop_table(:plane) if db.table_exists?(:plane)
13
-
14
- # Create a table.
15
- plane_tbl = db.create_table(:plane, :name, :String, :country, :String,
16
- :speed, :Integer, :range, :Integer, :descr, :Memo)
17
-
18
- # Create a long string field with embedded newlines for the memo contents.
19
- memo_string = <<END_OF_STRING
20
- The P-51 Mustang was the premier Allied fighter aircraft of World War II.
21
- It's performance and long range allowed it to escort Allied strategic
22
- bombers on raids deep inside Germany.
23
- END_OF_STRING
24
-
25
- # Create an instance of KBMemo for the memo field.
26
- memo = KBMemo.new(db, 'P-51.txt', memo_string)
27
-
28
- # Insert the new record, including the memo field.
29
- plane_tbl.insert('P-51', 'USA', 403, 1201, memo)
30
-
31
- # Insert another record.
32
- memo_string = <<END_OF_STRING
33
- The FW-190 was a World War II German fighter. It was used primarily as an
34
- interceptor against Allied strategic bombers.
35
- END_OF_STRING
36
-
37
- memo = KBMemo.new(db, 'FW-190.txt', memo_string)
38
- plane_tbl.insert('FW-190', 'Germany', 399, 499, memo)
39
-
40
- # Select all records, print name, country, speed and range on first line.
41
- # Then, print contents of memo field below.
42
- plane_tbl.select.each { |r|
43
- puts "Name: %s Country: %s Speed: %d Range: %d\n\n" % [r.name,
44
- r.country, r.speed, r.range]
45
- puts r.descr.contents
46
- puts "\n" + "-" * 75 + "\n\n"
47
- }
48
-
49
-
50
- puts "\n\nNow we will change the memo for the P-51:\n\n"
51
-
52
- # Grab the P-51's record.
53
- rec = plane_tbl.select { |r| r.name == 'P-51' }.first
54
-
55
- # Grab the contents of the memo field and add a line to it.
56
- memo = rec.descr
57
- memo.contents += "This last line should show up if the memo was changed.\n"
58
-
59
- # Now, update the record with the changed contents of the memo field.
60
- plane_tbl.update {|r| r.name == 'P-51'}.set(:descr => memo)
61
-
62
- # Do another select to show that the memo field indeed changed.
63
- puts plane_tbl.select { |r| r.name == 'P-51' }.first.descr.contents
64
-
65
-
66
- puts "\n\nNow we will change every record's memo field:\n\n"
67
-
68
- plane_tbl.update_all { |r|
69
- r.descr.contents += "I have added a line to the %s memo.\n\n" % r.name
70
- }
71
-
72
- # Do another select to show that the memo field for each record has
73
- # indeed changed.
74
- plane_tbl.select.each { |r| puts r.descr.contents }
1
+ # This script is an example of how you can use KirbyBase's new Memo field
2
+ # type.
3
+
4
+ require 'kirbybase'
5
+
6
+ db = KirbyBase.new { |d| d.memo_blob_path = './memos' }
7
+
8
+ #db = KirbyBase.new(:client, 'localhost', 44444)
9
+
10
+
11
+ # If table exists, delete it.
12
+ db.drop_table(:plane) if db.table_exists?(:plane)
13
+
14
+ # Create a table.
15
+ plane_tbl = db.create_table(:plane, :name, :String, :country, :String,
16
+ :speed, :Integer, :range, :Integer, :descr, :Memo)
17
+
18
+ # Create a long string field with embedded newlines for the memo contents.
19
+ memo_string = <<END_OF_STRING
20
+ The P-51 Mustang was the premier Allied fighter aircraft of World War II.
21
+ It's performance and long range allowed it to escort Allied strategic
22
+ bombers on raids deep inside Germany.
23
+ END_OF_STRING
24
+
25
+ # Create an instance of KBMemo for the memo field.
26
+ memo = KBMemo.new(db, 'P-51.txt', memo_string)
27
+
28
+ # Insert the new record, including the memo field.
29
+ plane_tbl.insert('P-51', 'USA', 403, 1201, memo)
30
+
31
+ # Insert another record.
32
+ memo_string = <<END_OF_STRING
33
+ The FW-190 was a World War II German fighter. It was used primarily as an
34
+ interceptor against Allied strategic bombers.
35
+ END_OF_STRING
36
+
37
+ memo = KBMemo.new(db, 'FW-190.txt', memo_string)
38
+ plane_tbl.insert('FW-190', 'Germany', 399, 499, memo)
39
+
40
+ # Select all records, print name, country, speed and range on first line.
41
+ # Then, print contents of memo field below.
42
+ plane_tbl.select.each { |r|
43
+ puts "Name: %s Country: %s Speed: %d Range: %d\n\n" % [r.name,
44
+ r.country, r.speed, r.range]
45
+ puts r.descr.contents
46
+ puts "\n" + "-" * 75 + "\n\n"
47
+ }
48
+
49
+
50
+ puts "\n\nNow we will change the memo for the P-51:\n\n"
51
+
52
+ # Grab the P-51's record.
53
+ rec = plane_tbl.select { |r| r.name == 'P-51' }.first
54
+
55
+ # Grab the contents of the memo field and add a line to it.
56
+ memo = rec.descr
57
+ memo.contents += "This last line should show up if the memo was changed.\n"
58
+
59
+ # Now, update the record with the changed contents of the memo field.
60
+ plane_tbl.update {|r| r.name == 'P-51'}.set(:descr => memo)
61
+
62
+ # Do another select to show that the memo field indeed changed.
63
+ puts plane_tbl.select { |r| r.name == 'P-51' }.first.descr.contents
64
+
65
+
66
+ puts "\n\nNow we will change every record's memo field:\n\n"
67
+
68
+ plane_tbl.update_all { |r|
69
+ r.descr.contents += "I have added a line to the %s memo.\n\n" % r.name
70
+ }
71
+
72
+ # Do another select to show that the memo field for each record has
73
+ # indeed changed.
74
+ plane_tbl.select.each { |r| puts r.descr.contents }
@@ -1,77 +1,77 @@
1
- #Test of returning result set composed of instances of user class.
2
-
3
- require 'kirbybase'
4
-
5
- class Foobar
6
- attr_accessor(:recno, :name, :country, :role, :speed, :range,
7
- :began_service, :still_flying, :alpha, :beta)
8
-
9
- def Foobar.kb_create(recno, name, country, role, speed, range,
10
- began_service, still_flying)
11
- name ||= 'No Name!'
12
- speed ||= 0
13
- began_service ||= Date.today
14
- Foobar.new do |x|
15
- x.recno = recno
16
- x.name = name
17
- x.country = country
18
- x.role = role
19
- x.speed = speed
20
- x.range = range
21
- x.began_service = began_service
22
- x.still_flying = still_flying
23
- end
24
- end
25
-
26
- def initialize(&block)
27
- instance_eval(&block)
28
- end
29
- end
30
-
31
- # To run local, single-user, uncomment next line.
32
- db = KirbyBase.new
33
-
34
- # If table exists, delete it.
35
- db.drop_table(:plane) if db.table_exists?(:plane)
36
-
37
- # Create a table. Notice how you set record_class equal to your class.
38
- plane_tbl = db.create_table do |t|
39
- t.name = :plane
40
- t.field_defs = [:name, :String, :country, :String, :role, :String,
41
- :speed, :Integer, :range, :Integer, :began_service, :Date,
42
- :still_flying, :Boolean]
43
- t.encrypt = false
44
- t.record_class = Foobar
45
- end
46
-
47
- plane_tbl = db.get_table(:plane)
48
-
49
- # Insert a record using an instance of Foobar.
50
- foo = Foobar.new do |x|
51
- x.name = 'Spitfire'
52
- x.country = 'Great Britain'
53
- x.role = 'Fighter'
54
- x.speed = 333
55
- x.range = 454
56
- x.began_service = Date.new(1936, 1, 1)
57
- x.still_flying = true
58
- x.alpha = "This variable won't be stored in KirbyBase."
59
- x.beta = 'Neither will this one.'
60
- end
61
- plane_tbl.insert(foo)
62
-
63
- # Notice how select returns instances of Foobar, since it was defined as the
64
- # record class.
65
- recs = plane_tbl.select
66
- puts "Example using #kb_create"
67
- puts recs[0].class
68
-
69
- # Now we are going to change a couple of fields of the Spitfire's Foobar
70
- # object and update the Spitfire record in the Plane table with the updated
71
- # Foobar object.
72
- recs[0].speed = 344
73
- recs[0].range = 555
74
- plane_tbl.update(recs[0]) {|r| r.name == 'Spitfire'}
75
-
76
- # Here's proof that the table was updated.
77
- p plane_tbl.select {|r| r.name == 'Spitfire'}
1
+ #Test of returning result set composed of instances of user class.
2
+
3
+ require 'kirbybase'
4
+
5
+ class Foobar
6
+ attr_accessor(:recno, :name, :country, :role, :speed, :range,
7
+ :began_service, :still_flying, :alpha, :beta)
8
+
9
+ def Foobar.kb_create(recno, name, country, role, speed, range,
10
+ began_service, still_flying)
11
+ name ||= 'No Name!'
12
+ speed ||= 0
13
+ began_service ||= Date.today
14
+ Foobar.new do |x|
15
+ x.recno = recno
16
+ x.name = name
17
+ x.country = country
18
+ x.role = role
19
+ x.speed = speed
20
+ x.range = range
21
+ x.began_service = began_service
22
+ x.still_flying = still_flying
23
+ end
24
+ end
25
+
26
+ def initialize(&block)
27
+ instance_eval(&block)
28
+ end
29
+ end
30
+
31
+ # To run local, single-user, uncomment next line.
32
+ db = KirbyBase.new
33
+
34
+ # If table exists, delete it.
35
+ db.drop_table(:plane) if db.table_exists?(:plane)
36
+
37
+ # Create a table. Notice how you set record_class equal to your class.
38
+ plane_tbl = db.create_table do |t|
39
+ t.name = :plane
40
+ t.field_defs = [:name, :String, :country, :String, :role, :String,
41
+ :speed, :Integer, :range, :Integer, :began_service, :Date,
42
+ :still_flying, :Boolean]
43
+ t.encrypt = false
44
+ t.record_class = Foobar
45
+ end
46
+
47
+ plane_tbl = db.get_table(:plane)
48
+
49
+ # Insert a record using an instance of Foobar.
50
+ foo = Foobar.new do |x|
51
+ x.name = 'Spitfire'
52
+ x.country = 'Great Britain'
53
+ x.role = 'Fighter'
54
+ x.speed = 333
55
+ x.range = 454
56
+ x.began_service = Date.new(1936, 1, 1)
57
+ x.still_flying = true
58
+ x.alpha = "This variable won't be stored in KirbyBase."
59
+ x.beta = 'Neither will this one.'
60
+ end
61
+ plane_tbl.insert(foo)
62
+
63
+ # Notice how select returns instances of Foobar, since it was defined as the
64
+ # record class.
65
+ recs = plane_tbl.select
66
+ puts "Example using #kb_create"
67
+ puts recs[0].class
68
+
69
+ # Now we are going to change a couple of fields of the Spitfire's Foobar
70
+ # object and update the Spitfire record in the Plane table with the updated
71
+ # Foobar object.
72
+ recs[0].speed = 344
73
+ recs[0].range = 555
74
+ plane_tbl.update(recs[0]) {|r| r.name == 'Spitfire'}
75
+
76
+ # Here's proof that the table was updated.
77
+ p plane_tbl.select {|r| r.name == 'Spitfire'}
@@ -1,38 +1,38 @@
1
1
  #Test of returning result set composed of instances of user class. This
2
2
  #example differs from the first in that there is no kb_create method, so
3
3
  #KirbyBase will default to create a new instance of the record's custom
4
- #class and setting each instance attribute to each field's value.
5
-
6
- require 'kirbybase'
7
-
8
- class Foobar
9
- attr_accessor(:recno, :name, :country, :role, :speed, :range,
10
- :began_service, :still_flying)
11
- end
12
-
13
- # To run local, single-user, uncomment next line.
14
- db = KirbyBase.new
15
-
16
- # If table exists, delete it.
17
- db.drop_table(:plane) if db.table_exists?(:plane)
18
-
19
- # Create a table. Notice how you set record_class equal to your class.
20
- plane_tbl = db.create_table do |t|
21
- t.name = :plane
22
- t.field_defs = [:name, :String, :country, :String, :role, :String,
23
- :speed, :Integer, :range, :Integer, :began_service, :Date,
24
- :still_flying, :Boolean]
25
- t.encrypt = false
26
- t.record_class = Foobar
27
- end
28
-
29
- plane_tbl = db.get_table(:plane)
30
-
4
+ #class and setting each instance attribute to each field's value.
5
+
6
+ require 'kirbybase'
7
+
8
+ class Foobar
9
+ attr_accessor(:recno, :name, :country, :role, :speed, :range,
10
+ :began_service, :still_flying)
11
+ end
12
+
13
+ # To run local, single-user, uncomment next line.
14
+ db = KirbyBase.new
15
+
16
+ # If table exists, delete it.
17
+ db.drop_table(:plane) if db.table_exists?(:plane)
18
+
19
+ # Create a table. Notice how you set record_class equal to your class.
20
+ plane_tbl = db.create_table do |t|
21
+ t.name = :plane
22
+ t.field_defs = [:name, :String, :country, :String, :role, :String,
23
+ :speed, :Integer, :range, :Integer, :began_service, :Date,
24
+ :still_flying, :Boolean]
25
+ t.encrypt = false
26
+ t.record_class = Foobar
27
+ end
28
+
29
+ plane_tbl = db.get_table(:plane)
30
+
31
31
  # Insert a record.
32
32
  plane_tbl.insert('Spitfire','Great Britain','Fighter',333,454,
33
- Date.new(1936, 1, 1),true)
34
-
33
+ Date.new(1936, 1, 1),true)
34
+
35
35
  # Notice how select returns instances of Foobar, even there is no
36
- # kb_create method.
37
- recs = plane_tbl.select
36
+ # kb_create method.
37
+ recs = plane_tbl.select
38
38
  p recs.first
@@ -1,46 +1,46 @@
1
- # This script is an example of how to rename a column.
2
- #
3
- require 'kirbybase'
4
-
5
- db = KirbyBase.new
6
-
7
- # If table exists, delete it.
8
- db.drop_table(:address_book) if db.table_exists?(:address_book)
9
-
10
- address_book_tbl = db.create_table(:address_book,
11
- :firstname, :String, :lastname, :String, :street_address, :String,
12
- :city, :String, :phone, :String, :category, :String
13
- )
14
-
15
- # Insert some contact info records.
16
- address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
17
- '111-111-1111', 'Super Hero')
18
- address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
19
- '222-222-2222', 'Cartoon Character')
20
- address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
21
- 'Washington', '333-333-3333', 'President')
22
- address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
23
- 'Any City', '444-444-4444', 'Super Hero')
24
-
25
- address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
26
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
27
- }
28
- puts;puts
29
-
30
- address_book_tbl.rename_column(:phone, :phone_no)
31
-
32
- begin
33
- address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
34
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
35
- }
36
- rescue StandardError => e
37
- puts e
38
- puts;puts
39
- end
40
-
41
- address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
42
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone_no]
43
- }
44
- puts;puts
45
-
1
+ # This script is an example of how to rename a column.
2
+ #
3
+ require 'kirbybase'
4
+
5
+ db = KirbyBase.new
6
+
7
+ # If table exists, delete it.
8
+ db.drop_table(:address_book) if db.table_exists?(:address_book)
9
+
10
+ address_book_tbl = db.create_table(:address_book,
11
+ :firstname, :String, :lastname, :String, :street_address, :String,
12
+ :city, :String, :phone, :String, :category, :String
13
+ )
14
+
15
+ # Insert some contact info records.
16
+ address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
17
+ '111-111-1111', 'Super Hero')
18
+ address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
19
+ '222-222-2222', 'Cartoon Character')
20
+ address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
21
+ 'Washington', '333-333-3333', 'President')
22
+ address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
23
+ 'Any City', '444-444-4444', 'Super Hero')
24
+
25
+ address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
26
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
27
+ }
28
+ puts;puts
29
+
30
+ address_book_tbl.rename_column(:phone, :phone_no)
31
+
32
+ begin
33
+ address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
34
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
35
+ }
36
+ rescue StandardError => e
37
+ puts e
38
+ puts;puts
39
+ end
40
+
41
+ address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
42
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone_no]
43
+ }
44
+ puts;puts
45
+
46
46
  p address_book_tbl.field_names