Sha256: b9f8d5e91c6536cb337623f586bf611e66c35dde085d313eaa4d30f6da16c079

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# This script is an example of how to specify that a value is required for a
# column.
#
require 'kirbybase'

db = KirbyBase.new

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

# Create a table.  Notice how we specify a default value for :category.
address_book_tbl = db.create_table(:address_book,
 :firstname, :String, :lastname, :String, :street_address, :String,
 :city, :String, :phone, :String, 
 :category, {:DataType=>:String, :Required=>true})

begin
    # Insert a record.  Notice that I am passing nil for :category.  This
    # will cause KirbyBase to raise an exception.
    address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave',
     'Gotham City', '111-111-1111', nil)
rescue StandardError => e
    puts e
    puts;puts
end

# Now, let's turn off the required flag for :category.
address_book_tbl.change_column_required(:category, false)

# And we will attempt to add the record again.
address_book_tbl.insert('Bruce', 'Wayne', '1234 Bat Cave',
 'Gotham City', '111-111-1111', nil)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
KirbyBase-2.5.1 examples/column_required_test/column_required_test.rb
KirbyBase-2.5 examples/column_required_test/column_required_test.rb