From: James Laska <jal233@gm...> - 2006-04-21 15:06:15
I'm looking into building a tree structure using SQLObject. Prior to
using SQLObject, I was using a modified preorder tree structure. I'd
like to continue this approach, and have found several posts from
others on this list who took that path as well. One approach appears
to be wrapped into the Alinea project
Another approach was proposed by Ben Bangert
I'm trying to compare the two approaches (in an attempt to not
reinvent the wheel). However, pastebin seems to have long since
dropped any references to 372150 and I can't find it cached anywhere.
Does anyone have a pointer to that sample code?
> On Sep 23, 2005, at 11:14 AM, Philippe Normand wrote:
> > I also read the link you gave above (sitepoint), and cooked up a class
> > to implement a Modified Preorder tree structure, see:
> > http://svn.pythonfr.org/public/alinea/Alinea/AlineaLib/AlineaNode.py
> > Actually the code is not (that) specific to Alinea and could be reused
> > by others ...
> > Please close your eyes and don't read the code of "moveTo" method,
> > it's
> > really ugly ;( In fact moving nodes in such a tree structure is not
> > trivial, if you have a smart solution let me see :)
> I'm still putting together unit tests to ensure it works, but I do
> have a appendChild (move) function that does significantly less
> queries than your version to move a node that contains children to
> have a new parent node. I have no idea how long pastebin.com history
> lasts, so better look sooner than later:
> Thats my code to deal with the Modified Preorder tree. In my limited
> interactive testing, it is moving and closing gaps properly in the
> few dozen cases I've manually tested.
> As there's no quick way to reliably remove the cache for all objects
> in the class (is there?), the table inheriting from it should have
> cacheValues set to False. Enhancements to that code are very
> appreciated. :)
From: Gabe Rudy <rudy@go...> - 2006-04-21 17:35:13
SQLBuilder is working great for my optimized queries and table displays, one
thing I think would be cool is if it could also provide some simple string
operators for queries.
I think that concatenation would be particularly usefull, but it may not be
standardized in the SQL specs, at least it appears to be implemented
differently in different databases, but that's what SQLBuilder is for eh? I
know at least postgres and sqlite use || for the operator.
I would like to generate a query such as
"select last_name || ', ' || first_name from contact"
(I actually care about doing more complex queries involving data from multiple
tables, but for simplicity this is the idea)
One possible syntax could be:
from sqlobject.sqlbuilder import *
Select( StrCat(Contact.q.lastName, ",", Contact.q.firstName) ) )
Does this sound like a reasonable feature request? I'd help with the coding if
it was cleared. A reasonable concern would be if the majority of suppored
databases have some syntax to deal with this and what would happen if they
didn't (exception raised? do it in python?).
On Fri, Apr 21, 2006 at 11:34:57AM -0600, Gabe Rudy wrote:
> from sqlobject.sqlbuilder import *
> Select( StrCat(Contact.q.lastName, ",", Contact.q.firstName) ) )
> Does this sound like a reasonable feature request?
It does. The name could be CONCAT() or CONCATENATION(). Please don't
forget about tests and documentation.
> A reasonable concern would be if the majority of suppored
> databases have some syntax to deal with this
Postgres and SQLite have || operator, MySQL has CONCAT() function (||
operator in MySQL means boolean OR).
> what would happen if they
> didn't (exception raised? do it in python?).
A backend reports an error, DB PAI driver rasies an exception, and you
can ignore this for now.
Oleg Broytmann http://phd.pp.ru/ phd@...
Programmers don't die, they just GOSUB without RETURN.