Sha256: 890067f14c5267f5854f99a9a46308e5d7f6223a867533d2c93341e1170d7a5c

Contents?: true

Size: 1.71 KB

Versions: 130

Compression:

Stored size: 1.71 KB

Contents

require 'rubygems'
require 'sequel'
require 'logger'
require 'fastercsv'
require File.dirname(__FILE__) +'/../sequel/pervasive'

Sequel::Model.plugin(:schema)
DB = Sequel.connect("odbc:/#{ARGV[0]}")#, :loggers => [ Logger.new( $stdout ) ] )
DB.extend(Sequel::Pervasive::DatabaseMethods)

class XFILE < Sequel::Model( :'x$file' )
  #~ xf$name, xf$loc, xf$flags, xf$reserved
  set_primary_key :'xf$id'
  one_to_many :fields, :class => :XFIELD, :key => :'xe$file'
  one_to_many :indices, :class => :XINDEX, :key => :'xi$file'
end

class XFIELD < Sequel::Model( :'x$field' )
  #~ xe$file xe$name xe$datatype xe$offset xe$size xe$dec xe$flags
  set_primary_key :'xe$id'
  many_to_one :file, :class => :XFILE, :key => :'xe$file', :primary_key => :'xf$id'
  def <=>( other )
    self[:'xe$name'] <=> other[:'xe$name']
  end
end

class XINDEX < Sequel::Model( :'x$index' )
  #~ xi$file xi$field xi$number xi$part xi$flags
  set_primary_key [:'xi$file', :'xi$field', :'xi$part']
  many_to_one :field, :class => :XFIELD, :key => :'xi$field', :primary_key => :'xe$id'
  def <=>( other )
    val = self[:'xi$number'] <=> other[:'xi$number']
    val = self[:'xi$part'] <=> other[:'xi$part'] if val == 0
    val
  end
end

FasterCSV.open("FOS_SCHEMA_#{ARGV[1]}.csv", 'w') do |csv|
  csv << 'table_name,table_flags,column_name,column_datatype,column_size,column_dec,column_flags'.split(',')
  tables = XFILE.filter(~:'xf$flags' => 16).and(:'xf$loc'.like('%.btr')).or(:'xf$loc'.like('%.BTR')).order(:'xf$name').all
  tables.each do |table|
    fields = table.fields.sort
    fields.each do |field|
      csv << [ table[:'xf$name'],table[:'xf$flags'],field[:'xe$name'],field[:'xe$datatype'],field[:'xe$size'],field[:'xe$dec'],field[:'xe$flags'] ]
    end
  end
end

Version data entries

130 entries across 130 versions & 1 rubygems

Version Path
fossil-0.5.30 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.29 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.28 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.27 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.26 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.25 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.24 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.23 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.22 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.21 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.20 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.19 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.18 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.17 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.16 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.15 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.14 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.13 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.12 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.11 lib/fos_schema/fos_schema_snapshot.rb