Grid vs GridTableBase| + Sequel + SQLite3

Hey all,
Wondering if i could get an example of working code that ties Sequel (or
any other database layer) into a GridTableBase and then into a Grid.
I am just now trying it and i cant seem to get it to work - no errors
(well - sometimes) but it is also not displaying anything.
Code follows:
class TimeFrame < Wx::Frame
def initialize()


@time_grid = Wx::Grid.new(self, -1)
@time_grid_table = TimeTableBase.new()**

end

def on_go_button_pressed(evt)

… # define a recordset that can contain 0 or more rows (0 rows
will not make it nil)
if recordset != nil
column_no = 1
p recordset.columns
@time_grid_table.append_cols(recordset.columns.length)
recordset.columns.each {|column|
@time_grid_table.set_col_label_value(column_no, column.to_s)
column_no = column_no +1
}
@time_grid_table.insert_rows(2)
@time_grid.set_table(@time_grid_table)
end
end
##################
**
class TimeTableBase < Wx::GridTableBase
def initialize
super()
end
def get_attr row, col, attr_kind
##
end

def get_number_rows
super.get_number_rows()
end

def get_number_cols
super.get_number_cols()
end

def get_col_label_value col
super.get_col_label_value(col)
end

def is_empty_cell row, col
super.is_empty_cell(row, col)
end

def get_value row, col
super.get_value(row, col)
end
end

EchoB wrote:

Hey all,
Wondering if i could get an example of working code that ties Sequel (or
any other database layer) into a GridTableBase and then into a Grid.

It depends what your’e trying to do with the database. I couldn’t work
out what your sample code was meant to do.

There’s nothing that says if you’re working with a SQL db, you must use
GridTableBase. If you simply want to display results from a SQL query as
rows in a Grid, it might well be easier to populate the Grid with
create_table and set_cell_value, and not mess around with GridTable.

GridTable is probably useful if:

  1. You have a huge dataset, and want to avoid loading it all at once.
    GridTable will only load cell values as they are visible.
  2. There is a tight connection between a cell’s value and a stored
    value; then you can overload set_value in your GridTable class and write
    any changes straight back to the database.

I am just now trying it and i cant seem to get it to work - no errors
(well - sometimes) but it is also not displaying anything.
A couple of things stick out:

  • you should call Grid#set_table, once, immediately after initialising
    the grid, not in an event handler.
  • you must return valid values (not call super) for the methods listed
    in the GridTableBase documentation (get_number_cols, is_empty_cell etc)

alex

Alex F. wrote:

It depends what your’e trying to do with the database. I couldn’t work
out what your sample code was meant to do.
I get that a lot :smiley:

There’s nothing that says if you’re working with a SQL db, you must use
GridTableBase. If you simply want to display results from a SQL query as
rows in a Grid, it might well be easier to populate the Grid with
create_table and set_cell_value, and not mess around with GridTable.
I thought about it, and thats what I was initially trying to do, but
GridTable sounds nicer. I want to do things like sorting, and
grouping, and other stuff on the fly.

Are there any working examples of how to use GridTableBase?
From http://wxruby.rubyforge.org/doc/gridtablebase.html I get that in
order to use the class I have to at least override:

  • get_attr-
    “May be overridden to handle attributes directly in the table.”

  • get_number_cols-
    “Should return the total number of columns in the grid. You must
    override this functions in a derived table class.”

  • get_number_rows-
    “Should return the total number of rows in the grid. You must override
    these functions in a derived table class.”

  • get_value-
    “Should return the content of the specified cell as a Ruby string. You
    must override this function in a derived table class.”

  • is_empty_cell-
    “Should return true if a cell is empty. You must override this
    function in a derived table class.”

To me this seems to say that the gridtablebase is depending on the grid
(which is depending on the gridtablebase for information) for
information. (That made my head hurt)

Perhaps an updated version of bigdemo.rb? :smiley:
Anyways, thanks for bearing with me!
:EchoBinary