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,31 +1,31 @@
1
- #Test of CSV file import.
2
-
3
- require 'kirbybase'
4
- require 'date'
5
-
6
- db = KirbyBase.new
7
-
8
- # To run as a client in a multi-user environment, uncomment next line.
9
- # Also, make sure kbserver.rb is running.
10
- #db = KirbyBase.new do |d|
11
- # d.connect_type = :client
12
- # d.host = 'localhost'
13
- # d.port = 44444
14
- #end
15
-
16
- # If table exists, delete it.
17
- db.drop_table(:plane) if db.table_exists?(:plane)
18
-
19
- # Create a table.
20
- plane_tbl = db.create_table(:plane, :name, :String, :country, :String,
21
- :role, :String, :speed, :Integer, :range, :Integer, :began_service, :Date,
22
- :still_flying, :Boolean)
23
-
24
- # Import csv file.
25
- puts 'Records imported: %d' % plane_tbl.import_csv('plane.csv')
26
-
27
- puts
28
-
29
- # Now, lets show that the csv file did, in fact, get imported.
30
- puts plane_tbl.select(:name, :country, :role, :speed, :range).sort(:name
31
- ).to_report
1
+ #Test of CSV file import.
2
+
3
+ require 'kirbybase'
4
+ require 'date'
5
+
6
+ db = KirbyBase.new
7
+
8
+ # To run as a client in a multi-user environment, uncomment next line.
9
+ # Also, make sure kbserver.rb is running.
10
+ #db = KirbyBase.new do |d|
11
+ # d.connect_type = :client
12
+ # d.host = 'localhost'
13
+ # d.port = 44444
14
+ #end
15
+
16
+ # If table exists, delete it.
17
+ db.drop_table(:plane) if db.table_exists?(:plane)
18
+
19
+ # Create a table.
20
+ plane_tbl = db.create_table(:plane, :name, :String, :country, :String,
21
+ :role, :String, :speed, :Integer, :range, :Integer, :began_service, :Date,
22
+ :still_flying, :Boolean)
23
+
24
+ # Import csv file.
25
+ puts 'Records imported: %d' % plane_tbl.import_csv('plane.csv')
26
+
27
+ puts
28
+
29
+ # Now, lets show that the csv file did, in fact, get imported.
30
+ puts plane_tbl.select(:name, :country, :role, :speed, :range).sort(:name
31
+ ).to_report
@@ -1,11 +1,11 @@
1
- FW-190,Germany,Fighter,399,499,1942-12-01,false
2
- P-51,USA,Fighter,405,1210,1943-06-24,true
3
- P-47,USA,Fighter,365,888,1943-03-12,false
4
- B-17,USA,Bomber,315,1400,1937-05-01,true
5
- Typhoon,Great Britain,Fighter-Bomber,389,690,1944-11-20,false
6
- Spitfire,Great Britain,Fighter,345,540,1939-02-18,true
7
- Oscar,Japan,Fighter,361,777,1943-12-31,false
8
- ME-109,Germany,Fighter,366,514,1936-07-07,true
9
- JU-88,Germany,Bomber,289,999,1937-01-19,false
10
- P-39,USA,Fighter,,,,false
11
- Zero,Japan,Fighter,377,912,1937-05-15,true
1
+ FW-190,Germany,Fighter,399,499,1942-12-01,false
2
+ P-51,USA,Fighter,405,1210,1943-06-24,true
3
+ P-47,USA,Fighter,365,888,1943-03-12,false
4
+ B-17,USA,Bomber,315,1400,1937-05-01,true
5
+ Typhoon,Great Britain,Fighter-Bomber,389,690,1944-11-20,false
6
+ Spitfire,Great Britain,Fighter,345,540,1939-02-18,true
7
+ Oscar,Japan,Fighter,361,777,1943-12-31,false
8
+ ME-109,Germany,Fighter,366,514,1936-07-07,true
9
+ JU-88,Germany,Bomber,289,999,1937-01-19,false
10
+ P-39,USA,Fighter,,,,false
11
+ Zero,Japan,Fighter,377,912,1937-05-15,true
@@ -1,54 +1,54 @@
1
- # This script is an example of how to specify a default value for 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
- # Create a table. Notice how we specify a default value for :category.
11
- address_book_tbl = db.create_table(:address_book,
12
- :firstname, :String, :lastname, :String, :street_address, :String,
13
- :city, :String, :phone, :String,
14
- :category, {:DataType=>:String, :Default=>'Super Hero'})
15
-
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')
21
-
22
- # Insert another record. Here we supply the value for :category, so
23
- # KirbyBase will use it instead of the default.
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)
34
-
35
- # Now lets change the default value for :category to 'President'.
36
- address_book_tbl.change_column_default_value(:category, 'President')
37
-
38
- # And let's add another record without supplying a value for :category.
39
- address_book_tbl.insert(:firstname=>'George', :lastname=>'Bush',
40
- :street_address=>'1600 Pennsylvania Ave', :city=>'Washington',
41
- :phone=>'333-333-3333')
42
-
43
- # Now, let's remove the default value for :category
44
- address_book_tbl.change_column_default_value(:category, nil)
45
-
46
- # And add another record. We won't specify a value for :category and,
47
- # KirbyBase will not use a default value, because we removed it.
48
- address_book_tbl.insert(:firstname=>'Silver', :lastname=>'Surfer',
49
- :street_address=>'1234 Galaxy Way', :city=>'Any City',
50
- :phone=>'444-444-4444')
51
-
52
- # Now lets print the table out and you will see how all of the defaults
53
- # worked.
54
- puts address_book_tbl.select.to_report
1
+ # This script is an example of how to specify a default value for 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
+ # Create a table. Notice how we specify a default value for :category.
11
+ address_book_tbl = db.create_table(:address_book,
12
+ :firstname, :String, :lastname, :String, :street_address, :String,
13
+ :city, :String, :phone, :String,
14
+ :category, {:DataType=>:String, :Default=>'Super Hero'})
15
+
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')
21
+
22
+ # Insert another record. Here we supply the value for :category, so
23
+ # KirbyBase will use it instead of the default.
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)
34
+
35
+ # Now lets change the default value for :category to 'President'.
36
+ address_book_tbl.change_column_default_value(:category, 'President')
37
+
38
+ # And let's add another record without supplying a value for :category.
39
+ address_book_tbl.insert(:firstname=>'George', :lastname=>'Bush',
40
+ :street_address=>'1600 Pennsylvania Ave', :city=>'Washington',
41
+ :phone=>'333-333-3333')
42
+
43
+ # Now, let's remove the default value for :category
44
+ address_book_tbl.change_column_default_value(:category, nil)
45
+
46
+ # And add another record. We won't specify a value for :category and,
47
+ # KirbyBase will not use a default value, because we removed it.
48
+ address_book_tbl.insert(:firstname=>'Silver', :lastname=>'Surfer',
49
+ :street_address=>'1234 Galaxy Way', :city=>'Any City',
50
+ :phone=>'444-444-4444')
51
+
52
+ # Now lets print the table out and you will see how all of the defaults
53
+ # worked.
54
+ puts address_book_tbl.select.to_report
@@ -1,24 +1,24 @@
1
- #Test of drop_column method.
2
-
3
- require 'kirbybase'
4
-
5
- db = KirbyBase.new
6
-
7
- # If table exists, delete it.
8
- db.drop_table(:plane) if db.table_exists?(:plane)
9
-
10
- # Create a table.
11
- plane_tbl = db.create_table(:plane, :name, :String, :speed, :Integer,
12
- :service_date, :Date, :still_flying, :Boolean)
13
-
14
- # Insert a bunch more records so we can have some "select" fun below.
15
- plane_tbl.insert('Spitfire', 345, Date.new(1939,2,18), true)
16
- plane_tbl.insert('Oscar', 361, Date.new(1943,12,31), false)
17
- plane_tbl.insert('ME-109', 366, Date.new(1936,7,7),true)
18
- plane_tbl.insert('JU-88', 289, Date.new(1937,1,19), false)
19
- plane_tbl.insert('P-39', nil, nil, false)
20
- plane_tbl.insert('Zero', 377, Date.new(1937,5,15), true)
21
-
22
- plane_tbl.drop_column(:speed)
23
-
24
- puts plane_tbl.select.to_report
1
+ #Test of drop_column method.
2
+
3
+ require 'kirbybase'
4
+
5
+ db = KirbyBase.new
6
+
7
+ # If table exists, delete it.
8
+ db.drop_table(:plane) if db.table_exists?(:plane)
9
+
10
+ # Create a table.
11
+ plane_tbl = db.create_table(:plane, :name, :String, :speed, :Integer,
12
+ :service_date, :Date, :still_flying, :Boolean)
13
+
14
+ # Insert a bunch more records so we can have some "select" fun below.
15
+ plane_tbl.insert('Spitfire', 345, Date.new(1939,2,18), true)
16
+ plane_tbl.insert('Oscar', 361, Date.new(1943,12,31), false)
17
+ plane_tbl.insert('ME-109', 366, Date.new(1936,7,7),true)
18
+ plane_tbl.insert('JU-88', 289, Date.new(1937,1,19), false)
19
+ plane_tbl.insert('P-39', nil, nil, false)
20
+ plane_tbl.insert('Zero', 377, Date.new(1937,5,15), true)
21
+
22
+ plane_tbl.drop_column(:speed)
23
+
24
+ puts plane_tbl.select.to_report
@@ -1,46 +1,46 @@
1
- # This script is an example of how to add an index to an existing table.
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
- # Insert some contact info records.
15
- address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
16
- '111-111-1111', 'Super Hero')
17
- address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
18
- '222-222-2222', 'Cartoon Character')
19
- address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
20
- 'Washington', '333-333-3333', 'President')
21
- address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
22
- 'Any City', '444-444-4444', 'Super Hero')
23
-
24
- # Select all super heros without using the index.
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.add_index(:category)
31
-
32
- # Now, do the same query, but use the category index. These
33
- # select_by_index methods are automatically created by KirbyBase when you
34
- # specify that a column be indexed.
35
- address_book_tbl.select_by_category_index { |r|
36
- r.category == 'Super Hero' }.each { |r|
37
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
38
- }
39
- puts;puts
40
-
41
- address_book_tbl.add_index(:firstname, :lastname)
42
-
43
- # Select Bugs Bunny using the firstname+lastname index.
44
- address_book_tbl.select_by_firstname_lastname_index { |r|
45
- r.firstname == 'Bugs' and r.lastname == 'Bunny'
46
- }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
1
+ # This script is an example of how to add an index to an existing table.
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
+ # Insert some contact info records.
15
+ address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
16
+ '111-111-1111', 'Super Hero')
17
+ address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
18
+ '222-222-2222', 'Cartoon Character')
19
+ address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
20
+ 'Washington', '333-333-3333', 'President')
21
+ address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
22
+ 'Any City', '444-444-4444', 'Super Hero')
23
+
24
+ # Select all super heros without using the index.
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.add_index(:category)
31
+
32
+ # Now, do the same query, but use the category index. These
33
+ # select_by_index methods are automatically created by KirbyBase when you
34
+ # specify that a column be indexed.
35
+ address_book_tbl.select_by_category_index { |r|
36
+ r.category == 'Super Hero' }.each { |r|
37
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
38
+ }
39
+ puts;puts
40
+
41
+ address_book_tbl.add_index(:firstname, :lastname)
42
+
43
+ # Select Bugs Bunny using the firstname+lastname index.
44
+ address_book_tbl.select_by_firstname_lastname_index { |r|
45
+ r.firstname == 'Bugs' and r.lastname == 'Bunny'
46
+ }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
@@ -1,66 +1,66 @@
1
- # This script is an example of how to drop an index from an existing table.
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, {:DataType=>:String, :Index=>1},
12
- :lastname, {:DataType=>:String, :Index=>1},
13
- :street_address, :String,
14
- :city, :String,
15
- :phone, :String,
16
- :category, {:DataType=>:String, :Index=>2}
17
- )
18
-
19
- # Insert some contact info records.
20
- address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
21
- '111-111-1111', 'Super Hero')
22
- address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
23
- '222-222-2222', 'Cartoon Character')
24
- address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
25
- 'Washington', '333-333-3333', 'President')
26
- address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
27
- 'Any City', '444-444-4444', 'Super Hero')
28
-
29
- p address_book_tbl.field_indexes
30
- puts;puts
31
-
32
- address_book_tbl.select_by_category_index { |r|
33
- r.category == 'Super Hero' }.each { |r|
34
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
35
- }
36
- puts;puts
37
-
38
- address_book_tbl.drop_index(:category)
39
-
40
- begin
41
- address_book_tbl.select_by_category_index { |r|
42
- r.category == 'Super Hero' }.each { |r|
43
- puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
44
- }
45
- rescue StandardError => e
46
- puts e
47
- puts;puts
48
- end
49
-
50
- # Select Bugs Bunny using the firstname+lastname index.
51
- address_book_tbl.select_by_firstname_lastname_index { |r|
52
- r.firstname == 'Bugs' and r.lastname == 'Bunny'
53
- }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
54
-
55
- address_book_tbl.drop_index(:firstname, :lastname)
56
-
57
- begin
58
- address_book_tbl.select_by_firstname_lastname_index { |r|
59
- r.firstname == 'Bugs' and r.lastname == 'Bunny'
60
- }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
61
- rescue StandardError => e
62
- puts e
63
- puts;puts
64
- end
65
-
1
+ # This script is an example of how to drop an index from an existing table.
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, {:DataType=>:String, :Index=>1},
12
+ :lastname, {:DataType=>:String, :Index=>1},
13
+ :street_address, :String,
14
+ :city, :String,
15
+ :phone, :String,
16
+ :category, {:DataType=>:String, :Index=>2}
17
+ )
18
+
19
+ # Insert some contact info records.
20
+ address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
21
+ '111-111-1111', 'Super Hero')
22
+ address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
23
+ '222-222-2222', 'Cartoon Character')
24
+ address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
25
+ 'Washington', '333-333-3333', 'President')
26
+ address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
27
+ 'Any City', '444-444-4444', 'Super Hero')
28
+
29
+ p address_book_tbl.field_indexes
30
+ puts;puts
31
+
32
+ address_book_tbl.select_by_category_index { |r|
33
+ r.category == 'Super Hero' }.each { |r|
34
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
35
+ }
36
+ puts;puts
37
+
38
+ address_book_tbl.drop_index(:category)
39
+
40
+ begin
41
+ address_book_tbl.select_by_category_index { |r|
42
+ r.category == 'Super Hero' }.each { |r|
43
+ puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
44
+ }
45
+ rescue StandardError => e
46
+ puts e
47
+ puts;puts
48
+ end
49
+
50
+ # Select Bugs Bunny using the firstname+lastname index.
51
+ address_book_tbl.select_by_firstname_lastname_index { |r|
52
+ r.firstname == 'Bugs' and r.lastname == 'Bunny'
53
+ }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
54
+
55
+ address_book_tbl.drop_index(:firstname, :lastname)
56
+
57
+ begin
58
+ address_book_tbl.select_by_firstname_lastname_index { |r|
59
+ r.firstname == 'Bugs' and r.lastname == 'Bunny'
60
+ }.each { |r| puts '%s %s %s' % [r.firstname, r.lastname, r.phone] }
61
+ rescue StandardError => e
62
+ puts e
63
+ puts;puts
64
+ end
65
+
66
66
  p address_book_tbl.field_indexes