Class: KirbyBase::KBTable

Class | KirbyBase::KBTable
In: | lib/kirbybase.rb
Parent: | Object

### Methods

[] []= add_column add_index change_column_default_value change_column_required change_column_type clear create_called_from_database_instance delete drop_column drop_index encrypted? field_defaults field_extras field_indexes field_names field_requireds field_types import_csv insert new pack rename_column select select_by_recno_index set total_recs update update_all valid_data_type? valid_default_type? valid_field_type? valid_index_type?

### Included Modules

DRb::DRbUndumped KBTypeConversionsMixin

### Classes and Modules

Class KirbyBase::KBTable::KBBlob
Class KirbyBase::KBTable::KBIndex
Class KirbyBase::KBTable::KBMemo
Class KirbyBase::KBTable::KBRecnoIndex
Class KirbyBase::KBTable::KBResultSet
Class KirbyBase::KBTable::KBTableRec

### Constants

VALID_FIELD_TYPES | = | [:String, :Integer, :Float, :Boolean, :Date, :Time, :DateTime, :Memo, :Blob, :ResultSet, :YAML] |  | Make constructor private. KBTable instances should only be created from KirbyBase#get_table.
VALID_DEFAULT_TYPES | = | [:String, :Integer, :Float, :Boolean, :Date, :Time, :DateTime, :YAML]
VALID_INDEX_TYPES | = | [:String, :Integer, :Float, :Boolean, :Date, :Time, :DateTime]

### External Aliases

clear | -> | delete_all
| Alias delete_all to clear method.

### Attributes

db | [R] |
filename | [R] |
lookup_key | [R] |
name | [R] |
table_class | [R] |

### Public Class methods

create_called_from_database_instance(db, name, filename)

Return a new instance of KBTable. Should never be called directly by your application. Should only be called from KirbyBase#get_table.

new(db, name, filename)

This has been declared private so user‘s cannot create new instances of KBTable from their application. A user gets a handle to a KBTable instance by calling KirbyBase#get_table for an existing table or KirbyBase.create_table for a new table.

valid_data_type?(data_type, value)

Return true if data is correct type, false otherwise.

data_type: | Symbol specifying data type.
value: | Value to convert to String.

valid_default_type?(field_type)

Return true if valid default type.

field_type: | Symbol specifying field type.

valid_field_type?(field_type)

Return true if valid field type.

field_type: | Symbol specifying field type.

valid_index_type?(field_type)

Return true if valid index type.

field_type: | Symbol specifying field type.

### Public Instance methods

[](*index)

Return the record(s) whose recno field is included in index.

index: | Array of Integer(s) specifying recno(s) you wish to select.

[]=(index, updates)

Update record whose recno field equals index.

index: | Integer specifying recno you wish to select.
updates: | Hash, Struct, or Array containing updates.

add_column(col_name, col_type, after=nil)

Add a column to table.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_name: | Symbol of column name to add.
col_type: | Symbol (or Hash if includes field extras) of column type to add.
after: | Symbol of column name that you want to add this column after.

add_index(*col_names)

Add an index to a column.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_names: | Array containing column name(s) of new index.

change_column_default_value(col_name, value)

Change a column‘s default value.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_name: | Symbol of column name.
value: | New default value for column.

change_column_required(col_name, required)

Change whether a column is required.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_name: | Symbol of column name.
required: | true or false.

change_column_type(col_name, col_type)

Change a column‘s type.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_name: | Symbol of column name.
col_type: | Symbol of new column type.

clear(reset_recno_ctr=true)

Delete all records from table. You can also use delete_all.

reset_recno_ctr: | true/false specifying whether recno counter should be reset to 0.

delete(&select_cond)

Delete records from table and return # deleted.

select_cond: | Proc containing code to select records.

drop_column(col_name)

Drop a column from table.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_name: | Symbol of column name to add.

drop_index(*col_names)

Drop an index on a column(s).

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

col_names: | Array containing column name(s) of new index.

encrypted?()

Returns true if table is encrypted.

field_defaults()

Return array containing table field defaults.

field_extras()

Return array containing table field extras.

field_indexes()

Return array containing table field indexes.

field_names()

Return array containing table field names.

field_requireds()

Return array containing table field requireds.

field_types()

Return array containing table field types.

import_csv(csv_filename)

Import csv file into table.

csv_filename: | filename of csv file to import.

insert(*data, &insert_proc)

Insert a new record into a table, return unique record number.

data: | Array, Hash, Struct instance containing field values of new record.
insert_proc: | Proc instance containing insert code. This and the data parameter are mutually exclusive.

pack()

Remove blank records from table, return total removed.

rename_column(old_col_name, new_col_name)

Rename a column.

Make sure you are executing this method while in single-user mode (i.e. not running in client/server mode).

old_col_name: | Symbol of old column name.
new_col_name: | Symbol of new column name.

select(*filter, &select_cond)

Return array of records (Structs) matching select conditions.

filter: | List of field names (Symbols) to include in result set.
select_cond: | Proc containing select code.

select_by_recno_index(*filter, &select_cond)

Return array of records (Structs) matching select conditions. Select condition block should not contain references to any table column except :recno. If you need to select by other table columns than just :recno, use select instead.

filter: | List of field names (Symbols) to include in result set.
select_cond: | Proc containing select code.

set(recs, data)

Set fields of records to updated values. Returns number of records updated.

recs: | Array of records (Structs) that will be updated.
data: | Hash, Struct, Proc containing updates.

total_recs()

Return total number of undeleted (blank) records in table.

update(*updates, &select_cond)

Return array of records (Structs) to be updated based on select cond.

updates: | Hash or Struct containing updates.
select_cond: | Proc containing code to select records to update.

update_all(*updates, &update_proc)

Return array of records (Structs) to be updated, in this case all records.

updates: | Hash or Struct containing updates.

[Validate]