[wxPython-users] [Always OT] - wx.TreeCtrl and SQLAlchemy

Werner F. Bruhin werner.bruhin at free.fr
Wed Mar 7 01:04:24 PST 2007


Hi Andrea,

Andrea Gavana wrote:
> Hi All,
>
>    it seems like I am going further and further off topic, but I
> promise it won't happen anymore. I have already abused of your
> patience.
> I have been fighting against this problem for 2 days, searching back
> and forth on the net. I have also written a couple of post in the
> SQLAlchemy mailing list, but got no answer.
> So I thought to ask few questions here, as I know that some of you
> work with databases and few also with SQLAlchemy. But the database
> itself is not that important, as the issue I am fighting with is
> mainly related to the fact that there are very few examples of
> tree-structured like databases in Python out there.
> So, for those who know SQLAlchemy, I tried the sample called
> "byroot_tree.py" in the examples/adjacencytree directory.
Can you send this file to me off-line?  Also I don't use SQLAlchemy (SA) 
but maybe I give you some hints.
> Well, it
> looks like SQLAlchemy can retrieve all the items in the tree based on
> the item id, but it's impossible to do it using the item *names*, in
> which I am much more interested. In other words, the statement:
>
> session.query(TreeNode).select(TreeNode.c.name=="MyCustomName")
I don't know with SA, but with SQL a "select" is only preparing the data 
it normally does not return anything.

One normally has to issue some kind of "fetch", maybe something like this:

session.query(TreeNode).select(TreeNode.c.name=="MyCustomName") 
.fetchall()  (or fetchone())
I would have to do something along these lines.

Have seen their tutorial on select 
(http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html), there they put 
the it into "run":

|def run(stmt):
    rs = stmt.execute()
    for row in rs:
        print row|


you would probably also do something like this:

|def run(stmt):
    rs = stmt.execute()
    list = rs.fetchall()
    return list

|

>
> Returns always an empty list except when the name is the root item
> name. So it seems impossible to query data by name, by size, by
> whatever else I will put in the database, except the id.
I think that when you use id they probably use a different type of 
select (I think it is called a singleton), i.e. it will always return 
one row or an error, where when you start to select on things like name 
etc the db can not know if there is one or more matches, you therefor 
have to use fetchone() or fetchall().  The above "for row in rs" is 
iterating and basically does a fetchone() on each iteration (at least 
that is my guess).
>
> I know it is a too much specific question, so I may come up with a
> simpler (?) one: does anyone have an example of a way to populate a
> wx.TreeCtrl using a tree-structured database? I have received a lot of
> help from Werner, but I am afraid my knowledge of Python is way too
> scarce to understand what he has done.
It is not your Python know how, it is more likely my crappy coding style.

Werner




More information about the wxpython-users mailing list