Sha256: a4d7204907084f69d149481aa15f5c82f34c7a63b370e6a2e0213585e5b389d9

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# This script is an example of how to rename a column.
#
require 'kirbybase'

db = KirbyBase.new

# If table exists, delete it.
db.drop_table(:address_book) if db.table_exists?(:address_book)

address_book_tbl = db.create_table(:address_book,
 :firstname, :String, :lastname, :String, :street_address, :String,
 :city, :String, :phone, :String, :category, :String
)

# Insert some contact info records.
address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave', 'Gotham City',
 '111-111-1111', 'Super Hero')
address_book_tbl.insert('Bugs', 'Bunny', '1234 Rabbit Hole', 'The Forest',
 '222-222-2222', 'Cartoon Character')
address_book_tbl.insert('George', 'Bush', '1600 Pennsylvania Ave',
 'Washington', '333-333-3333', 'President')
address_book_tbl.insert('Silver', 'Surfer', '1234 Galaxy Way',
 'Any City', '444-444-4444', 'Super Hero')

address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
    puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
}
puts;puts

address_book_tbl.rename_column(:phone, :phone_no)

begin
    address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
        puts '%s %s %s' % [r.firstname, r.lastname, r.phone]
    }
rescue StandardError => e
    puts e
    puts;puts
end

address_book_tbl.select { |r| r.category == 'Super Hero' }.each { |r|
    puts '%s %s %s' % [r.firstname, r.lastname, r.phone_no]
}
puts;puts

p address_book_tbl.field_names

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
KirbyBase-2.6 examples/rename_column_test/rename_column_test.rb
KirbyBase-2.5 examples/rename_column_test/rename_column_test.rb
KirbyBase-2.5.1 examples/rename_column_test/rename_column_test.rb
KirbyBase-2.5.2 examples/rename_column_test/rename_column_test.rb