sdobrev | 1 Feb 02:19 2007

Re: any particular reason for creating unused lists?


> > another things i noted:
> >  - using  "value.lower() == value" instead of value.islower()
> >
> >  - ansisql.py:
> >  in _requires_quotes():
> > this
> > " bool(len([x for x in str(value)
> >            if x not in self._legal_characters()])) "
> > should be same as
> >   bool( s.translate( 256*' ', self._legal_characters() ) )
> > and that table(256) can be a static/global.
>
> oh no those are great, and should be fixed.  the only ones i dont
> want to use are map() and reduce() since guido has said that list
> comprehensions should be used instead.  i tend to not memorize all
> the little tweaky functions like these (note that I am frequently
> coming out against "humane" interfaces since i am more of a thinker
> and less of a memorizer).  one reason you wont see too much
> performance gain with those in particuilar is because the quoting
> system caches all the decisions it makes about identifiers.

hmmm.
i run 300 times a query, and it gets something like 
#calls
47026    __generic_obj_format
called from: 
            ansisql.py:929(format_label)(10530)
            ansisql.py:935(format_table)(20273)
            ansisql.py:942(format_column)(16223)
(Continue reading)

Michael Bayer | 1 Feb 05:11 2007

Re: custom sql.


use func.abs(q.address.lat) for the ABS function.

On Jan 31, 2007, at 4:24 PM, Brent Pedersen wrote:

>
> hi, i've got it this far now. but it doesnt like the q.address.lat/lon
> since it makes an alias in the join. how to i get at that alias?
>
>
>         sajoin = q.join_to('address')
>         sorder = "ABS(" + str(q.address.lat) +" - %f) + ABS(" +
> str(q.address.lon) +"  - %f)"
>         sorder %= (lat,lon)
>         return q.select(
>             sajoin
>             ,order_by=asc(sorder)
>             ,limit=800
>         )
>
>
> On 1/31/07, Brent Pedersen <bpederse <at> gmail.com> wrote:
>> hi, how can put custom sql in a query? specifically in this code? the
>> problem is with the order_by. i want to pass it some custom sql:
>>
>>         q = session.query(Student)
>>         sajoin = q.join_to('address')
>>
>>         return q.select(
>>             sajoin,
(Continue reading)

Brent Pedersen | 1 Feb 05:30 2007
Picon

Re: custom sql.


ah. that makes sense.
here's my working query. returns results in order of distance to a
point (lat,lon):

        q = session.query(Student)
        j = q.join_to('address')
        return q.select(
            j,order_by=asc(func.abs(address.c.lat -lat) +
func.abs(address.c.lon-lon))
            ,limit=500
        )

thanks for the response.
...and sqlalchemy.

-brent

On 1/31/07, Michael Bayer <mike_mp <at> zzzcomputing.com> wrote:
>
> use func.abs(q.address.lat) for the ABS function.
>
> On Jan 31, 2007, at 4:24 PM, Brent Pedersen wrote:
>
> >
> > hi, i've got it this far now. but it doesnt like the q.address.lat/lon
> > since it makes an alias in the join. how to i get at that alias?
> >
> >
> >         sajoin = q.join_to('address')
(Continue reading)

jose | 1 Feb 07:53 2007

Re: date format


Guy Hulbert wrote:

>On Wed, 2007-31-01 at 12:17 -0500, Guy Hulbert wrote:
>  
>
>>>I would like to display my dates with format '%d/%m/%Y'  instead of
>>>      
>>>
>>ISO 
>>    
>>
>>>format.
>>>
>>>qry = session.query(Nazione).select(Nazione.c.codice=='201')
>>>qry[0].data_inizio
>>>print qry[0].data_inizio
>>>2006-01-14
>>>
>>>
>>>      
>>>
Thank you Guy to answer my question.
I know I can use the strftime property of datetime to format my dates as:

qry.data_inizio.strftime('%d/%m/%Y')  

but what I'm looking for, is a way to setting date style in SA or 
psycopg2 whithout need to apply functions
to change the default format.
(Continue reading)

Guy Hulbert | 1 Feb 11:14 2007
Picon

Re: date format


On Thu, 2007-01-02 at 07:53 +0100, jose wrote:
> Thank you Guy to answer my question.
> I know I can use the strftime property of datetime to format my dates
> as:
> 
> qry.data_inizio.strftime('%d/%m/%Y')  
> 
> but what I'm looking for, is a way to setting date style in SA or 
> psycopg2 whithout need to apply functions
> to change the default format.
> Is it possible?

You can change the date format returned by Postgres.
http://www.postgresql.org/docs/8.0/interactive/functions-formatting.html

So I expect it would be awkward to put this into SA or psychopg2, which
is why I suggested python.

--

-- 
--gh

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

(Continue reading)

Christopher Arndt | 1 Feb 11:56 2007
Picon

Re: date format


jose schrieb:
> I know I can use the strftime property of datetime to format my dates as:
> 
> qry.data_inizio.strftime('%d/%m/%Y')  
> 
> but what I'm looking for, is a way to setting date style in SA or 
> psycopg2 whithout need to apply functions
> to change the default format.
> Is it possible?

Yes, use properties on your SA data mapper objects:

http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_overriding

HTH, Chris

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

Paul Johnston | 1 Feb 12:21 2007
Picon

Re: Tool to check whether DB matches model

Hi,

Well, I see a model as a set of tables. In this particular case, a model is the set of tables created with a particular MetaData object. I guess model is a term from the MVC world, so perhaps there's a better term for SA users.

Paul


On 1/30/07, Michael Bayer <mike_mp <at> zzzcomputing.com> wrote:

what i cant see here is exactly what a "model" is.  if its a TG
thing, then this app would belong with Turbogears.


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

svilen | 1 Feb 12:57 2007

r2285 breaks some lazy loading

Here last version of the all*AB testcase.
2284 is ok. 
2285 - no.

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

Attachment (testABall.tbz): application/x-tbz, 13 KiB
Manlio Perillo | 1 Feb 13:24 2007
Picon

about cascade rule


Hi.

I still do not fully understand cascade rules, however I want to be sure 
the behaviour below is a feature and not a bug.

Here is the code:

from sqlalchemy import *

db = create_engine('postgres://manlio:manlio <at> localhost/test', echo=False)

metadata = BoundMetaData(db)
a = Table(
     'a', metadata,
     Column('id', Integer, primary_key=True),
     Column('x', String)
     )

b = Table(
     'b', metadata,
     Column('uid', String, primary_key=True),
     Column('id', Integer, ForeignKey(a.c.id)),
     Column('y', String)
     )

class A(object):
     def __init__(self,  x):
         self.x = x

class B(object):
     def __init__(self, id, y):
         self.id = id
         self.y = y

aMapper = mapper(A, a)

bMapper = mapper(
     B, b,
     properties={
         'a': relation(
             A, lazy=False, cascade='all, delete-orphan'
             )
         }
     )

try:
     metadata.create_all()

     conn = db.connect()
     trans = conn.begin()
     sess = create_session(bind_to=conn)

     obj = A('x')
     sess.save(obj)

     sess.flush()
     sess.close()
     trans.commit()
     conn.close()
finally:
     metadata.drop_all()

When executing this script I obtain:

Traceback (most recent call last):
   File "cascade.py", line 52, in ?
     sess.flush()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", 
line 220, in flush
     self.uow.flush(self, objects)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", 
line 175, in flush
     if object_mapper(obj)._is_orphan(obj):
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py", 
line 232, in _is_orphan
     raise exceptions.FlushError("instance %s is an unsaved, pending 
instance and is an orphan (is not attached to %s)" %
sqlalchemy.exceptions.FlushError: instance <__main__.A object at 
0xb79d946c> is an unsaved, pending instance and is an orphan (is not 
attached to any parent 'B' instance via that classes' 'a' attribute)
manlio <at> synapsis:~/projects/bugs/sqlalchemy$ python cascade.py
Traceback (most recent call last):
   File "cascade.py", line 52, in ?
     sess.flush()
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", 
line 220, in flush
     self.uow.flush(self, objects)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", 
line 175, in flush
     if object_mapper(obj)._is_orphan(obj):
   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py", 
line 232, in _is_orphan
     raise exceptions.FlushError("instance %s is an unsaved, pending 
instance and is an orphan (is not attached to %s)" %
sqlalchemy.exceptions.FlushError: instance <__main__.A object at 
0xb79a146c> is an unsaved, pending instance and is an orphan (is not 
attached to any parent 'B' instance via that classes' 'a' attribute)

Thanks and regards  Manlio Perillo

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

King Simon-NFHD78 | 1 Feb 17:21 2007

Deferred column loading and inheritance

Hi again,

I have a situation where I'd like to be able to load entities from a
single table, but that have attributes defined in other tables,
depending on their type (basically the same as the multiple table
inheritance example in the docs), and I'd like all of the attributes
that are defined in other tables to be lazily loaded, so my initial
selection only queries the first table - no polymorphic unions or
anthing.

I've attached my initial attempt, which works for the simple case.
However, I think the only reason it works is because the primary key
columns on each table are named the same. If you rename
engineers.person_id to engineers.engineer_id, for example, it fails when
populating the instance because it can't find a value to populate the
engineer_id property with. Even if the column is called person_id, the
load fails if it is part of a bigger query (eg. an eager load from
another object), because column aliases also break it.

I played around with making the primary_key deferred as well, but that
stops the deferred loading from working completely (probably not
surprising really)

I suppose a different way of doing this would be to map the attributes
to a completely separate class, and then proxy them somehow on the main
class, but I thought I would ask the question first, to see if anyone
has any ideas.

Thanks a lot,

Simon

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

Attachment (deferred_test.py): application/octet-stream, 4689 bytes

Gmane