class DRbSQLite

Public Class Methods

new(raw_dbfile=nil, host: nil, port: '57000', debug: false) click to toggle source
# File lib/drb_sqlite.rb, line 15
def initialize(raw_dbfile=nil, host: nil, port: '57000', debug: false)
  
    
  @host, @port, @debug = host, port, debug
  
  puts 'inside DRbSQLite'.info if @debug
  
  DRb.start_service
  
  if raw_dbfile then
    load_db(raw_dbfile)
  else
    @server = DRbObject.new nil, "druby://#{host}:#{port}"
  end    
      
end

Public Instance Methods

execute(*args, &blk) click to toggle source
# File lib/drb_sqlite.rb, line 32
def execute(*args, &blk)
  
  r = @server.execute @dbfile, *args, &blk
  
  if r.is_a? String and r =~ /^SQLiteServerError:/ then
    raise SQLiteServerError, r[/(?<=^SQLiteServerError: )(.*)/]
  end
  
  r
end
exists?(dbfile) click to toggle source
# File lib/drb_sqlite.rb, line 43
def exists?(dbfile)
  @server.exists? dbfile
end
fields(table) click to toggle source
# File lib/drb_sqlite.rb, line 47
def fields(table)
  @server.fields @dbfile, table
end
load_db(raw_dbfile) click to toggle source
# File lib/drb_sqlite.rb, line 51
def load_db(raw_dbfile)
  
  puts 'DRbSQLite | inside load_db'.info if @debug
  
  if raw_dbfile =~ /^sqlite:\/\// then
    host, @dbfile = raw_dbfile\
        .match(/(?<=^sqlite:\/\/)([^\/]+)\/(.*)/).captures
    
    if @debug then
      puts ('host: ' + host.inspect).debug
      puts ('@dbfile: ' + @dbfile.inspect).debug
    end
    
    @server = DRbObject.new nil, "druby://#{host}:#{@port}"
  else
    @dbfile = raw_dbfile
    @server = DRbObject.new nil, "druby://#{@host}:#{@port}"
  end

  @server.load_db(@dbfile)
end
query(*args, &blk) click to toggle source
# File lib/drb_sqlite.rb, line 90
def query(*args, &blk)
  
  r = @server.query @dbfile, *args, &blk
  
  if r.is_a? String and r =~ /^SQLiteServerError:/ then
    raise SQLiteServerError, r[/(?<=^SQLiteServerError: )(.*)/]
  end
  
  r    
end
results_as_hash() click to toggle source
# File lib/drb_sqlite.rb, line 73
def results_as_hash()
  @server.results_as_hash @dbfile
end
results_as_hash=(val) click to toggle source
# File lib/drb_sqlite.rb, line 77
def results_as_hash=(val)
  puts 'inside results_as_hash=()'.info if @debug
  @server.results_as_hash = [@dbfile, val]
end
table_info(s) click to toggle source
# File lib/drb_sqlite.rb, line 82
def table_info(s)
  @server.table_info @dbfile, s
end
tables() click to toggle source
# File lib/drb_sqlite.rb, line 86
def tables()
  @server.tables @dbfile
end