Thanks all!

- If I do query.all(), everything is pulled up once and stored in memory.
But I dont want to get a huge list into memory, though the same list will be
passed around.
- Because of above, I want to return a Query instance which can be iterated
upon, and which goes to the disk and fetches data as needed (issues one sql
query per iteration).
- I was looking for some way to override/hook on to some methods in query
class, so that I can modify it to return with :
    a. Return multiple columns stringized with some delimiters.
    b. In case of a single column query, return it as a list, instead of a
[(column, )]  <tuple>

Is there any way to do this?

Regards,
Harish
Sent from Bangalore, KA, India

On Wed, Jun 10, 2009 at 1:36 AM, Mike Conley <mconl...@gmail.com> wrote:

> 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