Module: MiqSqlite3DB

Defined in:
lib/db/MiqSqlite/MiqSqlite3.rb,
lib/db/MiqSqlite/MiqSqlite3Cell.rb,
lib/db/MiqSqlite/MiqSqlite3Page.rb,
lib/db/MiqSqlite/MiqSqlite3Util.rb,
lib/db/MiqSqlite/MiqSqlite3Table.rb

Defined Under Namespace

Classes: MiqSqlite3, MiqSqlite3Cell, MiqSqlite3Page, MiqSqlite3Table

Constant Summary collapse

DBHEADER =

Database Header (all numbers in Big-Endian format)

BinaryStruct.new([             #    OFFSET   SIZE    DESCRIPTION
  'a16',  'magic',                     #       0      16     Header string: "SQLite format 3\000"
  'n',    'page_size',                 #      16       2     Page size in bytes.
  'C',    'write_version',             #      18       1     File format write version
  'C',    'read_version',              #      19       1     File format read version
  'C',    'unused_space',              #      20       1     Bytes of unused space at the end of each page
  'C',    'max_payload_node_fraction', #      21       1     Max embedded payload fraction
  'C',    'min_payload_node_fraction', #      22       1     Min embedded payload fraction
  'C',    'min_payload_leaf_fraction', #      23       1     Min leaf payload fraction
  'N',    'file_change_counter',       #      24       4     File change counter
  'a4',   'reserved',                  #      28       4     Reserved for future use
  'N',    'first_freelist_page',       #      32       4     First freelist page
  'N',    'number_freelist_pages',     #      36       4     Number of freelist pages in the file
  'N15',  'meta_values',               #      40      60     15 4-byte meta values passed to higher layers
])
SIZEOF_DBHEADER =
DBHEADER.size
SQLITE_MAX_PAGE_SIZE =
32768

Class Method Summary collapse

Class Method Details

.dumpHex(buf) ⇒ Object



27
28
29
30
31
# File 'lib/db/MiqSqlite/MiqSqlite3Util.rb', line 27

def self.dumpHex(buf)
  out = ""
  buf.each_byte { |b| out += sprintf("%02x ", b) }
  out
end

.hiBit?(f) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/db/MiqSqlite/MiqSqlite3Util.rb', line 2

def self.hiBit?(f)
  f & 0x80 == 0x80
end

.variableInteger(buf) ⇒ Object

convert a var to an integer



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/db/MiqSqlite/MiqSqlite3Util.rb', line 7

def self.variableInteger(buf)
  raise "Empty Buffer" if buf.nil? || buf.size == 0
  bytes = []
  loop do
    byte = buf[bytes.size].ord
    bytes << byte
    break if !hiBit?(byte) || bytes.size == 9
  end

  value = 0
  bcnt  = 0
  bytes.each do |byte|
    bcnt += 1
    value <<= 7
    byte &= 0x7F  if bcnt < 9
    value |= byte
  end
  return value, bytes.size
end