There are probably multiple ways to do what you are looking for.

I would consider simply constructing the query without the .all() and
returning the query instance. Callers then simply iterate over the query
themselves. No need to parse a string to get the individual columns; they
could do something as simple as:

for row in call_your_code(whatever parameters are required,...):
      use row.firstname, row.lastname, etc. in their code

If you do execute the query with .all(); callers can iterate on the result
in the same way.

Another thing to remember is that even if you do generate a list and return
it; only a pointer to the list is being returned. The list is not copied to
another memory location unless the caller does that themselves, and they
should be working with and understand the same memory constraints you are
dealing with.


-- 
Mike Conley



On Mon, Jun 8, 2009 at 11:34 PM, Harish Vishwanath <harish.shas...@gmail.com
> wrote:

> Thanks for your thoughts!
>
> I was looking for some query apis to get the job done. Query itself is an
> iterator and I want to construct and pass around the query object itself to
> my callers. I work on an embedded system, and I dont want to do a
> query.all(), post process it with required delimiters and send a list in
> memory coz of memory constraints.
>
>
> Regards,
> Harish
> Sent from Bangalore, KA, India
>
> On Tue, Jun 9, 2009 at 1:09 AM, phrrn...@googlemail.com <
> phrrn...@googlemail.com> wrote:
>
>>
>> I have something like this to serialize a result-set to delimited file-
>> format. It is not very pretty and probably not at all pythonic but I
>> find it handy.
>>
>> pjjH
>>
>>
>> def as_delimited(q, *args):
>>    csvdata = StringIO()
>>    w = writer(csvdata, delimiter='|')
>>    for i in q.values(*args):
>>        w.writerow(i)
>>        yield csvdata.getvalue()
>>        csvdata.truncate(0)
>>
>> q = session.query(User)
>> for i in as_delimited(q,
>> User.firstname,User.lastname,User.age,User.password):
>>  print i,
>>
>> On Jun 8, 10:18 am, Glauco <gla...@sferacarta.com> wrote:
>> > Harish Vishwanath ha scritto:> <cut>
>> >
>> > > How can I modify this query to return something like :
>> > > [(fname~lname~22~pwd)...] with '~' being preferred delimiter.
>> >
>> > SA return a list or record, what exactly you are searching for? a
>> > string  or something else
>> >
>> >
>> >
>> > > I would like to know if I can return something like above directly
>> > > from the query itself.
>> >
>> > something like ?
>> >
>> > [ '~'.join(x) for x in qry.fetchall() ]
>> >
>> > Glauco
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to