[fxruby-users] Accessing SQLite database in FXRuby application

Nataraj S Narayan natarajsn at gmail.com
Sat Feb 27 05:39:22 EST 2010


Hi

Should'nt it be like this?


class TestApp < FXApp
  def initialize
     super('Test', 'Test')


  end

  def db
    @db = SQLite3::Database.new('test.db3')
 @db || raise("can't connect to database")
  end
end

regards

Nataraj


On Sat, Feb 27, 2010 at 7:09 AM, Will Parsons <wbparsons at cshore.com> wrote:
> I'm trying to develop an application that accesses an SQLite database and
> am running into problems related to using getApp (probably because of some
> simple misunderstanding of how FXRuby works on my part).  The following is
> a stripped-down version of my (non-functioning) program:
>
> ========================================================================
> #!/usr/bin/env ruby
>
> require 'fox16'
> require 'sqlite3'
>
> include Fox
>
> class TestApp < FXApp
>   def initialize
>      super('Test', 'Test')
>      @db = SQLite3::Database.new('test.db3')
>      @db || raise("can't connect to database")
>   end
>
>   def db
>      @db
>   end
> end
>
> class TestTable < FXTable
>   def initialize(p)
>      super(p, :opts => LAYOUT_FILL|PACK_UNIFORM_WIDTH|TABLE_COL_SIZABLE)
>
>      db = getApp.db
>      db || raise("can't access DB")      # <---- this condition is raised
>
>      setTableSize(3, 3)
>      # fill table with data from database...
>   end
> end
>
> class TopLevelWindow < FXMainWindow
>   def initialize(app)
>      super(app, 'Test', :width => 400, :height => 100)
>      TestTable.new(self)
>   end
>
>   def create
>      super
>      show(PLACEMENT_SCREEN)
>   end
> end
>
> TestApp.new do |app|
>   TopLevelWindow.new(app)
>   app.create
>   app.run
> end
>
> ========================================================================
>
> When run, the condition "can't access DB" is raised.  This is probably simple,
> but I can't seem to figure out what I'm doing wrong.
>
> --
> Will
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
>


More information about the fxruby-users mailing list