Yeah, I am using cocoa bindings. I installed 1.3.6. Your answer makes sense, but I can't get it to work...

Hint me some more :-)


def OrderList(self):
    return Order.select()

ValueError: NSInvalidArgumentException - <sqlobject.main.SelectResults object at 0x1057c30> does not recognize -isKindOfClass

def OrderList(self):
    return list(Order.select())

2005-05-22 00:47:53.154 Diko[1785] *** Ignoring *** addObserver:forKeyPath:options:context: for 'name' (of <NSTableBinder: 0x1196b40>{object: <NSTableView: 0x1156d40>, bindings: content=arrangedObjects, selectionIndexes=selectionIndexes, sortDescriptors=sortDescriptors} with 0 in 0x0).

KeyError: u'Key name does not exist'

def OrderList(self):
    return dict(Order.select())

TypeError: cannot convert dictionary update sequence element #0 to a sequence



On 21-mei-2005, at 2:23, Bob Ippolito wrote:


On May 20, 2005, at 6:54 PM, Koen Bok wrote:


Sorry for the noob questions, but hey, you gotta start somewhere...

I am building an application in PyObjC. If I create a result object I want to convert it into a list wit dictionary's. Currently I do it like this:

results = Product.select()

for result in results:
    products.append({'code':result.code, 'name':result.name, 'price':result.price, 'brand':result.brand})

This is quite a performance hit. Is there a way to do this directly from sqlobject or at least more optimized?


First of all, make sure you're using PyObjC 1.3.6.  It includes a lot of bug fixes that are relevant to Cocoa Bindings and Key-Value Coding (it looks like you're using Cocoa Bindings from this example).

I haven't used SQLObject in a while, and I don't have it installed, so I can't really say whether or not this would work.. but you might be able to just return "results".  In PyObjC, regular Python objects should be suitable for most things, since they fully support Key-Value Coding and such.  So, you shouldn't really need to convert your result objects to dictionaries.  If SQLObject returns really weird custom types, then it might not work; you may have to return list(results), since only list and tuple subclasses are bridged to NSArray.

Also, if this is an accessor method, then you should be caching the result somehow so that you don't have to run a query whenever the UI wants to update itself.

If SQLObject does use weird types for things, it's possible to write custom proxy classes and add them to the depythonify table, but that's really kind of an implementation detail of PyObjC that is not exposed as a "public API" at this time and is certainly beyond the scope of what should be discussed on this list.

-bob



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss