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.50 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.49 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.48 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.47 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.46 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.45 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.44 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.43 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.42 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.41 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.40 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.39 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.38 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.37 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.36 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.35 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.34 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.33 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.32 lib/fos_schema/fos_schema_snapshot.rb
fossil-0.5.31 lib/fos_schema/fos_schema_snapshot.rb