Class: BtrieveSchema
- Inherits:
-
Object
- Object
- BtrieveSchema
- Includes:
- Btrieve
- Defined in:
- lib/btrieve/btrieve_schema.rb
Overview
Represents the btrieve schema (DDF files) of a particular BTR database.
Constant Summary collapse
- CHAR =
Datatypes used to transact with the BTR engine.
{ :name=>'CHAR', :unpacker=>'a', :size=>1 }
- TINYINT =
{ :name=>'TINYINT', :unpacker=>'c', :size=>1 }
- SMALLINT =
{ :name=>'SMALLINT', :unpacker=>'s', :size=>1 }
- INTEGER =
{ :name=>'INTEGER', :unpacker=>'i', :size=>1 }
- REAL =
{ :name=>'REAL', :unpacker=>'f', :size=>1 }
- DOUBLE =
{ :name=>'DOUBLE', :unpacker=>'d', :size=>1 }
- DATE =
day month year
{ :name=>'DATE', :unpacker=>'ccs', :size=>4 }
- TIME =
100th sec min hour
{ :name=>'TIME', :unpacker=>'cccc', :size=>4 }
- BIT =
{ :name=>'BIT', :unpacker=>'c', :size=>1 }
- VARCHAR =
{ :name=>'VARCHAR', :unpacker=>'A', :size=>1 }
- LONGVARCHAR =
{ :name=>'LONGVARCHAR', :unpacker=>'A', :size=>1 }
- UTINYINT =
{ :name=>'UTINYINT', :unpacker=>'C', :size=>1, :size=>1 }
- USMALLINT =
{ :name=>'USMALLINT', :unpacker=>'S', :size=>1 }
- UINTEGER =
{ :name=>'UINTEGER', :unpacker=>'I', :size=>1 }
- UBIGINT =
{ :name=>'UBIGINT', :unpacker=>'Q', :size=>1 }
- SIZEOF =
Array of all datatypes supported by the BTR engine.
{'a'=>1, 'c'=>1, 's'=>1, 'i'=>1, 'f'=>1, 'd'=>1, 'ccs'=>4, 'cccc'=>4, 'A'=>1, 'C'=>1, 'S'=>1, 'I'=>1, 'Q'=>1}
Constants included from BtrCodes
BtrCodes::ABORT_TRANSACTION, BtrCodes::ACCELERATED_MODE, BtrCodes::BEGIN_TRANSACTION, BtrCodes::CLOSE, BtrCodes::DELETE, BtrCodes::END_TRANSACTION, BtrCodes::EOF, BtrCodes::EXCEPTION_MESSAGES, BtrCodes::EXCLUSIVE_MODE, BtrCodes::GET_DIRECT, BtrCodes::GET_EQUAL, BtrCodes::GET_EQUAL_KEY, BtrCodes::GET_FIRST, BtrCodes::GET_GREATER_THAN_OR_EQUAL, BtrCodes::GET_LESS_THAN_OR_EQUAL, BtrCodes::GET_NEXT, BtrCodes::GET_NEXT_EXTENDED, BtrCodes::GET_NEXT_KEY, BtrCodes::GET_POSITION, BtrCodes::GET_PREVIOUS, BtrCodes::INSERT, BtrCodes::KEY_NOT_FOUND, BtrCodes::LOCAL_ACCELERATED_MODE, BtrCodes::LOCAL_EXCLUSIVE_MODE, BtrCodes::LOCAL_NORMAL_MODE, BtrCodes::LOCAL_READ_ONLY_MODE, BtrCodes::MAX_DATATYPE, BtrCodes::NORMAL_MODE, BtrCodes::NO_CURRENCY_CHANGE, BtrCodes::NO_LOGICAL_CURRENCY_KEY, BtrCodes::NULL_BUFFER, BtrCodes::NULL_KEY, BtrCodes::OK, BtrCodes::OPEN, BtrCodes::POS_BLOCK_SIZE, BtrCodes::READ_ONLY_MODE, BtrCodes::RECORD_POSITION_SIZE, BtrCodes::REMOTE_ACCELERATED_MODE, BtrCodes::REMOTE_EXCLUSIVE_MODE, BtrCodes::REMOTE_NORMAL_MODE, BtrCodes::REMOTE_READ_ONLY_MODE, BtrCodes::RESET, BtrCodes::STEP_NEXT, BtrCodes::STEP_NEXT_EXTENDED, BtrCodes::STOP, BtrCodes::SYSTEM_LOG_KEY, BtrCodes::UPDATE, BtrCodes::VERIFY_MODE
Instance Attribute Summary collapse
-
#xfield_records ⇒ Object
readonly
Returns the value of attribute xfield_records.
-
#xfile_records ⇒ Object
readonly
Returns the value of attribute xfile_records.
Class Method Summary collapse
Instance Method Summary collapse
-
#get_table_schema(tablename) ⇒ Object
Loads the schema of a particular btrieve table.
-
#initialize ⇒ BtrieveSchema
constructor
Creates a new instance of btrieve schema for a given session.
Methods included from Btrieve
Constructor Details
#initialize ⇒ BtrieveSchema
Creates a new instance of btrieve schema for a given session.
27 28 29 30 31 32 33 34 35 |
# File 'lib/btrieve/btrieve_schema.rb', line 27 def initialize() session=BtrieveSession.get_session if(!session.cache[:schemas_loaded]) cache_system_table(:'x$file') cache_system_table(:'x$field') cache_system_table(:'x$index') session.cache[:schemas_loaded] = true end end |
Instance Attribute Details
#xfield_records ⇒ Object (readonly)
Returns the value of attribute xfield_records.
4 5 6 |
# File 'lib/btrieve/btrieve_schema.rb', line 4 def xfield_records @xfield_records end |
#xfile_records ⇒ Object (readonly)
Returns the value of attribute xfile_records.
4 5 6 |
# File 'lib/btrieve/btrieve_schema.rb', line 4 def xfile_records @xfile_records end |
Class Method Details
.readable_type(column) ⇒ Object
76 77 78 79 80 |
# File 'lib/btrieve/btrieve_schema.rb', line 76 def self.readable_type(column) c=column.to_a[0] btrtype = lookup(c[1][:datatype],c[1][:size]) [:name=>c[0], :datatype=>btrtype[:name], :size=>c[1][:size]] end |
Instance Method Details
#get_table_schema(tablename) ⇒ Object
Loads the schema of a particular btrieve table.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/btrieve/btrieve_schema.rb', line 38 def get_table_schema(tablename) session=BtrieveSession.get_session schema = nil xfile_index = nil session.cache[:'x$file'].each do |xfile| next unless xfile[:'xf$name'].downcase.strip.to_sym == tablename schema = {:filename=>xfile[:'xf$loc'].downcase.strip, :record_size=>0, :columns=>{}} xfile_index = xfile[:'xf$id'] break end xfield_index = [] session.cache[:'x$field'].each do |xfield| next unless xfile_index == xfield[:'xe$file'] next unless xfield[:'xe$datatype'] < MAX_DATATYPE id = xfield[:'xe$id'] name = xfield[:'xe$name'].strip.downcase offset = xfield[:'xe$offset'] size = xfield[:'xe$size'] datatype = xfield[:'xe$datatype'] datatype = (name == 'kid - mult') ? 14 : datatype # Absolute BS line of code... Needed for CTA-FOS unpacker = BtrieveSchema.unpacker(offset, datatype, size) schema[:columns][name.to_sym] = {:unpacker=>unpacker, :id=>id, :offset=>offset, :datatype=>datatype, :size=>size} xfield_index[id] = name.to_sym end session.cache[:'x$index'].each do |xindex| next unless xfile_index == xindex[:'xi$file'] indices = schema[:indices] ||= [] index = indices[xindex[:'xi$number']] ||= [] index[xindex[:'xi$part']] = xfield_index[xindex[:'xi$field']] flags = schema[:index_flags] ||= [] flags[xindex[:'xi$number']] = flags[xindex[:'xi$number']].to_i | xindex[:'xi$flags'].to_i end last_field=schema[:columns].values.sort{|a,b| a[:offset] <=> b[:offset]}.last schema[:record_size] = last_field[:offset]+last_field[:size] raise Exception.new("Unknown table '#{tablename}'.") if schema.nil? schema end |