Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Zope: Dev

External method pulling data from an SQL method?

 

 

Zope dev RSS feed   Index | Next | Previous | View Threaded


julian at zereau

Mar 5, 1999, 7:30 AM

Post #1 of 3 (429 views)
Permalink
External method pulling data from an SQL method?

I am using PostgreSQL's array system for a "categories" field in a database, it
return records in a format like:
'{"foo"}'
'{"foo","bar"}'
'{"foo"}'

I am trying to extract the list of unique categories - in this example:
["foo","bar"]

This would be a complete nuisance to do in DTML. I have decided to read the SQL
method's results into an external method and edit them there - but first I need
to know how to call a SQL method without the "in" DTML tag.

Or maybe there is a simpler solution to all this, for any PostgreSQL gurus out
there??

---
Julian Morrison
Programmer (Zereau Ltd)


michel at digicool

Mar 5, 1999, 8:01 AM

Post #2 of 3 (422 views)
Permalink
RE: External method pulling data from an SQL method? [In reply to]

> -----Original Message-----
> From: julian [at] zereau [mailto:julian [at] zereau]
> Sent: Friday, March 05, 1999 9:31 AM
> To: zope-dev [at] zope
> Subject: [Zope-dev] External method pulling data from an SQL method?
>
>
> I am using PostgreSQL's array system for a "categories" field
> in a database, it
> return records in a format like:
> '{"foo"}'
> '{"foo","bar"}'
> '{"foo"}'
>
> I am trying to extract the list of unique categories - in
> this example:
> ["foo","bar"]
>
> This would be a complete nuisance to do in DTML. I have
> decided to read the SQL
> method's results into an external method and edit them there
> - but first I need
> to know how to call a SQL method without the "in" DTML tag.
>

An SQL method is like any other method. If you want to call it from an
external method, you could try this:

<untested>

<!--#var "myExternalMethod(this())"-->

...

def myExternalMethod(self):
self.mySQLMethod()

</untested>

This is just a sketch, but I hope you get the idea. You don't need the
#in tag to call an SQL method, you can even call it with a #var tag, if
you don't mind the output.

-Michel

> Or maybe there is a simpler solution to all this, for any
> PostgreSQL gurus out
> there??
>
> ---
> Julian Morrison
> Programmer (Zereau Ltd)
>
> _______________________________________________
> Zope-Dev maillist - Zope-Dev [at] zope
> http://www.zope.org/mailman/listinfo/zope-dev
>


jbauer at rubic

Mar 5, 1999, 8:04 AM

Post #3 of 3 (419 views)
Permalink
Re: External method pulling data from an SQL method? [In reply to]

[. Julian discusses using PostgreSQL arrays. My post will *not*
answer his question about how to use external methods. ;-) ]

I do something similar with large text fields. Rather than
use PostgreSQL's unique (non-portable) array system, I store
collections of primitives as strings and use eval() when reading
the fields.

>>> aList = [1, 'a', 2.5]
>>> field_value = repr(aList)
... perform some database insert operation
... read the field back in
>>> aList = eval(field_value)

This works well for lists and dictionaries that contain other
lists, dictionaries, and primitive data types. It provides a
possible alternative to storing object data when you're
required to use a relational database system.

Portability is constrained to Python applications, but the
technique is not restricted to any particular database. I'd
be interested in learning if other people are using this
technique (uh, er ... hack) in their Python/rdbms applications.

Best regards,

Jeff Bauer
Rubicon, Inc.


> I am using PostgreSQL's array system for a "categories" field
> in a database, it return records in a format like:
> '{"foo"}'
> '{"foo","bar"}'
> '{"foo"}'
>
> I am trying to extract the list of unique categories - in
> this example: ["foo","bar"]
>
> This would be a complete nuisance to do in DTML. I have decided
> to read the SQL method's results into an external method and edit
> them there - but first I need to know how to call a SQL method
> without the "in" DTML tag.

Zope dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.