From: Andy T. <an...@ha...> - 2006-01-19 11:04:30
|
Martinez, Miguel (Amermex) wrote: > Martinez, Miguel (Amermex) wrote: >> I'm trying to show a db cursor in a wxgrid and I don't know how, I > tried >> to set a cursor.fetchall() and I get this error. >> >> >> >> SetTable >> >> return _grid.Grid_SetTable(*args, **kwargs) >> >> TypeError: argument number 2: a 'wxGridTableBase *' is expected, >> 'list([('column one, row one', 'column two, row one'), ('column one, > row >> two', 'column two, row two')] >> >> )' is received. >> >> >> >> How can I show a list, tuple, cursor or resultset in a grid? >> > > First, it's more useful if you post a small sample of your code that > triggers the error message, that way people on this list can be a little > > more helpful and responsive. > > Secondly, if you want to display the contents of a database table in a > grid look at the dbBrowser2 sample application (in the samples/dbBrowser > > folder of your PythonCard installation). This does pretty much what you > have described. > > Regards, > Andy I know that this is late even by my lax standards, but I've been testing dbBrowser prior to the next release of PythonCard and thought I'd revisit this issue. In essence, there are two ways to populate a grid, you can loop through your rows and columns populating them as you go - as you've done in your sample code above - or you can pass a sequence of sequences to an object of type wxGridTableBase (or one that inherits from it) and assign that to your grid. The second option is generally a lot faster than the first and doesn't require much more code. So I've attached a sample PythonCard application that connects to a database (in this case MySQL but it will work just as well with Oracle as per your example). When you run it just type the name of one of your database tables into the field and then press the button labelled 'Get Rows'. It will then fetch the data from your database table, build a GridBaseTable from it and display it in the grid in the bottom part of the window. Hopefully this will be simpler to follow than the rather abstract code in dbBrowser2 for anyone wanting to use wx grids in their PythonCard application. The application class is quite simple and handles connecting to the database and then dropping and recreating the grid component when the button is pressed. The DBTable class is the one that deals with extracting the data from the database and then using it to populate a GridTableBase which is then attached to the grid. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ |