[sqlalchemy] association obj/proxy

2007-04-05 Thread svilen

seems this is the month of the many2many relations ;-)

why is a the whole assoc.proxy + _AssocList needed?

Can't one do just with overloading/replaceing the InstrumentedList's 
append() ? or something of sorts. i know it might be messier, but 
with proper hooks it will be shorter/faster/easier/...

in my case, i want any kwargs passed to append() to trigger creating 
proper assoc_obj off them, and using that one.

btw there is error in _AssociationList __setitem__(), item should 
be value there... or what?. This the only other place of creating 
assoc.object is __setitem__, but there's syntacticaly no way to pass 
**kwargs there - unless called explicitly as xxx.__setitem__(...).

ciao
svilen

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: simple many-to-many select

2007-04-05 Thread Ram Yalamanchili

was filter_by added recently? I have a assign_mapped class User from
TG, and doing a session.query(User).filter_by doesn't work (no such
method).

On 4/4/07, Michael Bayer [EMAIL PROTECTED] wrote:

 My preference with assign_mapper at this point is to say:

 Client.query.filter_by(sites=siteobj)

 i.e. i dont think constantly adding methods to assignmapper is going
 to scale, as the chances of conflicts with existing user classes
 grows.  im into hierarchies of names rather  than huge straight down
 lists.


 On Apr 4, 2007, at 5:40 AM, Alexandre CONRAD wrote:

 
  Glauco wrote:
 
  Alexandre CONRAD ha scritto:
 
  Okay, thanks. Any idea if .filter_by() and other new generative
  method
  will be available in an assign_mapper object?
 
  Yes..it's available, the final object has identical property as  a
  mapper
 
  Well, model.Client.filter_by(sites=siteobj) doesn't work for me...
 
 AttributeError: type object 'Client' has no attribute 'filter_by'
 
  Or am I misunderstanding how to use it ?
 
  Regards,
  --
  Alexandre CONRAD
 
 
  


 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: association obj/proxy

2007-04-05 Thread svilen

here's what i did and it seems to work:

class _Empty: pass
class Base4Association(..):#the base for assoc_objects
 ...
class MyCollection( list):
factory = None
def append( me, obj =_Empty, **kwargs):
if obj is _Empty:#marker for notset; else just use it
obj = me.factory( **kwargs) #create it from kwargs
list.append( me, obj)
return obj

@classmethod
def myCollectionFactory( klas):
m = Base4Association.MyCollection()
m.factory = klas
return m


...

def append( self, *args, **kwargs):
item = self._data_appender( *args,**kwargs)
#private __setrecord; was before _data_appender 
self._InstrumentedList__setrecord( item)
sqlalchemy.orm.attributes.InstrumentedList.append = append

...
   themapper.add_property( name, 
  sqlalchemy.relation(
   actual_assoc_klas, 
   lazy= False, cascade= all, delete-orphan,
   uselist= True,
   collection_class= actual_assoc_klas.myCollectionFactory
   ) )

 seems this is the month of the many2many relations ;-)

 why is a the whole assoc.proxy + _AssocList needed?

 Can't one do just with overloading/replaceing the
 InstrumentedList's append() ? or something of sorts. i know it
 might be messier, but with proper hooks it will be
 shorter/faster/easier/...

 in my case, i want any kwargs passed to append() to trigger
 creating proper assoc_obj off them, and using that one.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: simple many-to-many select

2007-04-05 Thread Glauco

Ram Yalamanchili ha scritto:
 was filter_by added recently? I have a assign_mapped class User from
 TG, and doing a session.query(User).filter_by doesn't work (no such
 method).
   


yes, it's in the latest 0.3.6 version...

this sometime it's hopeful :-)




- orm:
- the full featureset of the SelectResults extension has been merged
  into a new set of methods available off of Query.  These methods
  all provide generative behavior, whereby the Query is copied
  and a new one returned with additional criterion added.  
  The new methods include:

  filter() - applies select criterion to the query
  filter_by() - applies by-style criterion to the query
  avg() - return the avg() function on the given column
  join() - join to a property (or across a list of properties)
  outerjoin() - like join() but uses LEFT OUTER JOIN
  limit()/offset() - apply LIMIT/OFFSET
  range-based access which applies limit/offset:  
 session.query(Foo)[3:5]
  distinct() - apply DISTINCT
  list() - evaluate the criterion and return results
  
  no incompatible changes have been made to Query's API and no methods
  have been deprecated.  Existing methods like select(), select_by(),
  get(), get_by() all execute the query at once and return results
  like they always did.  join_to()/join_via() are still there although
  the generative join()/outerjoin() methods are easier to use.



-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: How would you build a mapper with a calculated field based on a join from two tables

2007-04-05 Thread Glauco

vinjvinj ha scritto:
 Say I have a python class defined:

 def class User(object):
 get_calculated_field(self):
 return self.a_column_in_user_table_1  +
 self.a_column_in_additional_info

 user_table = Table('user_table', metadata, autoload=True)
 additional_info = Table('additional_info', metadata, autoload=True)

 Now I need to do the following:

 1. Add an additional read only attribute to the User object which is
 calculated from columns on the user_table and additional_info table

 2. Be able to generate a join between a user_table and additional_info
 table and then for each row that is returned by the db, have the User
 object add calculated_field as a read only attribute (by calling the
 function get_calculated_field)
   
Why  additional_info isn't a property of  user_table  ?

properties = { 'additional_info'  : relation(additional_info),
  })

so you have:

a = user_table()
a.a_column_in_user_table_1  + a.additional_info.your_column



Glauco

-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: simple many-to-many select

2007-04-05 Thread Glauco
Glauco ha scritto:
 Ram Yalamanchili ha scritto:
   
 was filter_by added recently? I have a assign_mapped class User from
 TG, and doing a session.query(User).filter_by doesn't work (no such
 method).
   
 


 yes, it's in the latest 0.3.6 version...

 this sometime it's hopeful :-)
   
ps... i forgot link:   http://www.sqlalchemy.org/CHANGES



 - orm:
 - the full featureset of the SelectResults extension has been merged
   into a new set of methods available off of Query.  These methods
   all provide generative behavior, whereby the Query is copied
   and a new one returned with additional criterion added.  
   The new methods include:

   filter() - applies select criterion to the query
   filter_by() - applies by-style criterion to the query
   avg() - return the avg() function on the given column
   join() - join to a property (or across a list of properties)
   outerjoin() - like join() but uses LEFT OUTER JOIN
   limit()/offset() - apply LIMIT/OFFSET
   range-based access which applies limit/offset:  
  session.query(Foo)[3:5]
   distinct() - apply DISTINCT
   list() - evaluate the criterion and return results
   
   no incompatible changes have been made to Query's API and no methods
   have been deprecated.  Existing methods like select(), select_by(),
   get(), get_by() all execute the query at once and return results
   like they always did.  join_to()/join_via() are still there although
   the generative join()/outerjoin() methods are easier to use.



   


-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software®  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: 0.3.6 problem, was working with 0.3.4

2007-04-05 Thread fw

Thanks Rick,

I updated to the latest SVN rev  and things do work now.

Cheers,
 François

On Apr 4, 10:08 pm, Rick Morrison [EMAIL PROTECTED] wrote:
 Hi fw,

 The explicit zero for the
 float column was a bug that should be fixed in rev #2491.

 MSSQL can store low-resolution datetimes in DATE columns, and the format for
 MSSQL Date columns was expanded to allow storing those (note the missing
 seconds in the format).

 That date change should not affect your queries -- does it?

 On 4/4/07, fw [EMAIL PROTECTED] wrote:



  Hi list,

  I am using a mssql database.

  A mapper that was working in 0.3.4, no longer works in 0.3.6,

  The query built is apparently the same, but the values used as
  parameters are not the same.

  Under 0.3.4 it was
INFO sqlalchemy.engine.base.Engine.0x..d0 {'lazy_fa2e': 'x',
  'MakerCost_MakerCost': '0', 'MakerCost_Effective_Date': '2007-04-04'}

  Under 03.6 it has become
 INFO sqlalchemy.engine.base.Engine.0x..d0
  {'MakerCost_MakerCost': None, 'lazy_e4bf': 'x',
  'MakerCost_Effective_Date': '2007-04-04 00:00'}

  As you can see MakerCost has become None instead of 0 (zero) and the
  Date has turned into a Datetime. Note that the 0 (zero) is explicitly
  specified in a query.

  What is going on? Any pointer appreciated.

  TIA
  François

  Here are the gruesome details

  The MakerCost  table associate the Maker and the Model tables. It also
  has a Cost and a Date fields.

  The mapped Cost property retrieves only the current cost. It is
  when using the Cost property  that the problem occurs (In the info
  above, the Cost property on a Maker object)

  tblMaker=Table(Maker,
  Column(MAKERCODE,StripString, primary_key = True),
  Column(NAME , CP874String,nullable=False),
  Column(ADDR0,String(40),nullable=True),
  Column(ADDR1,String(40),nullable=True),
  Column(ADDR2,String(40),nullable=True),
  Column(ADDR3,String(40),nullable=True),
  Column(TBCODE,String,nullable=False),
  Column(CONTACT,String,nullable=False),
  Column(COMMENTS,String),
  Column(DSTAMP,DateTime),
  Column(USERNAME,String(8)))

  tblModel=Table(Model,
  Column(ModelCode,CodeString(20), primary_key = True),
  Column(ModelGroup,String(12),nullable=False),
  Column(ModelThaiName,CP874String(50),nullable=False),
  Column(ModelEnglishName,StripString(50),nullable=False),
  Column(ModelWeight,Float),
  Column(UnitCode,String(5)),
  #Column(ProductGroupCode,ForeignKey(... TODO
  Column(ModelRemark,CP874String(50)),
  Column(EffectDate,Date),
  Column(LastDate,DateTime),
  Column(LastUser,String(8)))

  tblMakerCost=Table(MakerCost,
  Column(RowOrder,Integer, primary_key = True),
  Column(MakerCode , StripString(50),ForeignKey(Maker.MAKERCODE
  )),
  Column(ModelCode , CodeString,ForeignKey(Model.ModelCode)),
  Column(MakerCost,Float,nullable=False),
  Column(Remark,CP874String(100)),
  Column(Reference,CP874String()),
  Column(Effective_Date,Date),
  Column(LastUpdate,DateTime),
  Column(LastUser,String(8)))

  MakerCost.mapper[Primary]=mapper(MakerCost,tblMakerCost,
  properties={
  'Cost': tblMakerCost.c.MakerCost,
  'id':tblMakerCost.c.RowOrder,
  }
  )

  #Getting only the latest costs
  sCCSub=select([tblMakerCost.c.MakerCode, tblMakerCost.c.ModelCode,
  func.max(tblMakerCost.c.Effective_Date).label('Effective_Date')],
  tblMakerCost.c.Effective_Date=datetime.date.today(),group_by=[
  tblMakerCost.c.MakerCode,
  tblMakerCost.c.ModelCode]).alias('sCCSub')

  sCurrentCost=select([c for c in
  tblMakerCost.c],tblMakerCost.c.MakerCost
  0,from_obj=[join(tblMakerCost,sCCSub,and_(
  sCCSub.c.MakerCode==tblMakerCost.c.MakerCode,and_(
  sCCSub.c.ModelCode==tblMakerCost.c.ModelCode,
  sCCSub.c.Effective_Date==tblMakerCost.c.Effective_Date
  )))]).alias('sCurrentCost')

  Maker.mapper[Primary]=mapper(Maker, tblMaker, properties={
  'AllCosts':relation(MakerCost, backref='Maker',lazy=True,
  cascade=all, delete-orphan),
  'Costs': relation(mapper(MakerCost,sCurrentCost,
  non_primary=True),
  uselist=True, viewonly=True),
   #Models':
  relation(Model,secondary=tblMakerCost,secondaryjoin=
  tblModel.c.ModelCode==tblMakerCost.c.ModelCode,

  #primaryjoin=tblMaker.c.MAKERCODE==tblMakerCost.c.MakerCode,uselist=True,
  viewonly=True),
  'Name':tblMaker.c.NAME,
  'Code':tblMaker.c.MAKERCODE,
  'Contact': tblMaker.c.CONTACT,
  'Comment': tblMaker.c.COMMENTS,
  'LastUpdate':tblMaker.c.DSTAMP,
  'LastUser':tblMaker.c.USERNAME
  }
  )

  Model.mapper[Primary]=mapper(Model,tblModel, properties={
  'AllCosts':relation(MakerCost,backref='Model',lazy=True,
  cascade=all, delete-orphan),
  'Costs': 

[sqlalchemy]

2007-04-05 Thread meyyitfani

The Second Station of the Thirteenth
Word


In the Name of
God, the Merciful, the Compassionate.

[A conversation held
with some young people who, though surrounded by temptation, had not yet
lost their power of reason.]

Being assaulted by
the deceptive, seductive amusements of the present time, a group of young
people were asking: #8220;How can we save our lives in the
hereafter?#8221;, and they sought help from the Risale-i Nur. So I said
the following to them in the name of the Risale-i Nur:

The grave is there
and no one can deny it. Whether they want to or not, everyone must enter
it. And apart from the following three #8216;Ways#8217;, there is no
other way it can be approached:

First
Way: For
those who believe, the grave is the door to a world far better than this
world.

Second
Way: For
those who believe in the hereafter, but who approach it on the path of
dissipation and misguidance, it is the door to a prison of solitary
confinement, an eternal dungeon, where they will be separated from all
their loved ones.

Third
Way: For
the unbelievers and the misguided who do not believe in the hereafter, it
is the door to eternal extinction. That is to say, it is the gallows on
which both themselves and all those they love will be executed. Since they
think it is thus, that is exactly how they shall experience it: as
punishment.

These last two Ways
are self-evident, they do not require proof, they are plain for all to
see. Since the appointed hour is secret, and death may come any time and
cut off his head, and it does not differentiate between young and old,
perpetually having such an awesome and serious matter before him, unhappy
man will surely search for the means to deliver himself from that eternal
extinction, that infinite, endless solitary confinement; the means to
transform the door of the grave into a door opening on to an everlasting
world, eternal happiness, and a world of light. It will be a question for
him that looms as large as the world.

The certain fact of
death, then, can only be approached in these three ways, and one hundred
and twenty-four thousand veracious messengers #8212;the prophets, in
whose hands are miracles as signs of confirmation#8212; have announced
that the three ways are as described above. And, relying on their
illuminations and visions, one hundred and twenty-four million saints have
confirmed and set their signatures on the prophets#8217; tidings. And
innumerable exact scholars have proved it rationally with their
categorical proofs at the level of #8216;certainty at the degree of
knowledge.#8217;1 They have all unanimously declared it to be
a ninety-nine per cent certain probability, saying: #8220;The only way to
be saved from extinction and eternal imprisonment, and be directed towards
eternal happiness, is through belief in God and obedience to
Him.#8221;

If a person considers
but does not heed the word of a single messenger not to take a dangerous
road on which there is a one per cent danger of perishing, and takes it,
the anxiety at perishing he suffers will destroy even his appetite for
food. Thus hundreds of thousands of veracious and verified messengers
announced that there is a one hundred per cent probability that
misguidance and vice lead to the gallows of the grave, ever before the
eyes, and eternal solitary confinement, and that there is a one hundred
per cent probability that belief and worship remove those gallows, close
the solitary prison, and transform the ever-apparent grave into a door
opening onto an everlasting treasury and palace of felicity; and they have
pointed out signs and traces of these. Confronted as he is, then, with
this strange, awesome, terrifying matter, if wretched man
#8212;especially if he is a Muslim#8212; does not believe and worship,
is he able to banish the grievous pain arising from the anxiety he suffers
as he all the time awaits his turn to be summoned to those gallows,
ever-present before his eyes, even if he is given rule over the whole
world together with all its pleasures? I ask you.

Since old-age,
illness, disaster, and on all sides death open up the frightful pain and
are a reminder, even if the people of misguidance and vice enjoy a hundred
thousand pleasures and delights, they most certainly experience a sort of
hell in their hearts, but a profound stupor of heedlessness temporarily
makes them insensible to it.

Since for the people
of belief and worship the grave, ever before their eyes, is the door to an
everlasting treasury and eternal happiness, and since, by reason of the
#8216;belief coupon#8217;, a ticket from the pre-eternal lottery of
Divine Determining for millions upon millions of poundsworth of gold and
diamonds has come up for each of them, they all the time await the word,
#8220;Come and collect your ticket#8221; with a truly profound pleasure
and real spiritual delight. This pleasure is such that if it materialized
and the seed became a tree, it would be like a private paradise. However,
one 

[sqlalchemy] Re: 0.3.6 problem, was working with 0.3.4

2007-04-05 Thread fw

Hi Rick,

I am afraid I reported success a bit too fast.

The problem has changed though.

I am using rev 2492.

If I use the MakerCost mapper as it is defined in my previous email,
I get a strange behaviour:
If I query a MakerCost  directly (e.g.
session.query(MakerCost).select_by(..))  things work fine.

If I get the MakerCost objects  indirectly, first by getting a
Maker and then going through the Costs list, all the MakerCost
objects I get have a Cost attribute that is None.

If I change the mapper to
  MakerCost.mapper[Primary]=mapper(MakerCost,tblMakerCost)

 and use MakerCost instead of Cost as the attribute,   it
works fine

It seems to me that the renaming of attributes vs. column name has
some issue.

It is easy to work around it in any case.

Cheers,
  François

On Apr 4, 10:08 pm, Rick Morrison [EMAIL PROTECTED] wrote:
 Hi fw,

 The explicit zero for the
 float column was a bug that should be fixed in rev #2491.

 MSSQL can store low-resolution datetimes in DATE columns, and the format for
 MSSQL Date columns was expanded to allow storing those (note the missing
 seconds in the format).

 That date change should not affect your queries -- does it?

 On 4/4/07, fw [EMAIL PROTECTED] wrote:



  Hi list,

  I am using a mssql database.

  A mapper that was working in 0.3.4, no longer works in 0.3.6,

  The query built is apparently the same, but the values used as
  parameters are not the same.

  Under 0.3.4 it was
INFO sqlalchemy.engine.base.Engine.0x..d0 {'lazy_fa2e': 'x',
  'MakerCost_MakerCost': '0', 'MakerCost_Effective_Date': '2007-04-04'}

  Under 03.6 it has become
 INFO sqlalchemy.engine.base.Engine.0x..d0
  {'MakerCost_MakerCost': None, 'lazy_e4bf': 'x',
  'MakerCost_Effective_Date': '2007-04-04 00:00'}

  As you can see MakerCost has become None instead of 0 (zero) and the
  Date has turned into a Datetime. Note that the 0 (zero) is explicitly
  specified in a query.

  What is going on? Any pointer appreciated.

  TIA
  François

  Here are the gruesome details

  The MakerCost  table associate the Maker and the Model tables. It also
  has a Cost and a Date fields.

  The mapped Cost property retrieves only the current cost. It is
  when using the Cost property  that the problem occurs (In the info
  above, the Cost property on a Maker object)

  tblMaker=Table(Maker,
  Column(MAKERCODE,StripString, primary_key = True),
  Column(NAME , CP874String,nullable=False),
  Column(ADDR0,String(40),nullable=True),
  Column(ADDR1,String(40),nullable=True),
  Column(ADDR2,String(40),nullable=True),
  Column(ADDR3,String(40),nullable=True),
  Column(TBCODE,String,nullable=False),
  Column(CONTACT,String,nullable=False),
  Column(COMMENTS,String),
  Column(DSTAMP,DateTime),
  Column(USERNAME,String(8)))

  tblModel=Table(Model,
  Column(ModelCode,CodeString(20), primary_key = True),
  Column(ModelGroup,String(12),nullable=False),
  Column(ModelThaiName,CP874String(50),nullable=False),
  Column(ModelEnglishName,StripString(50),nullable=False),
  Column(ModelWeight,Float),
  Column(UnitCode,String(5)),
  #Column(ProductGroupCode,ForeignKey(... TODO
  Column(ModelRemark,CP874String(50)),
  Column(EffectDate,Date),
  Column(LastDate,DateTime),
  Column(LastUser,String(8)))

  tblMakerCost=Table(MakerCost,
  Column(RowOrder,Integer, primary_key = True),
  Column(MakerCode , StripString(50),ForeignKey(Maker.MAKERCODE
  )),
  Column(ModelCode , CodeString,ForeignKey(Model.ModelCode)),
  Column(MakerCost,Float,nullable=False),
  Column(Remark,CP874String(100)),
  Column(Reference,CP874String()),
  Column(Effective_Date,Date),
  Column(LastUpdate,DateTime),
  Column(LastUser,String(8)))

  MakerCost.mapper[Primary]=mapper(MakerCost,tblMakerCost,
  properties={
  'Cost': tblMakerCost.c.MakerCost,
  'id':tblMakerCost.c.RowOrder,
  }
  )

  #Getting only the latest costs
  sCCSub=select([tblMakerCost.c.MakerCode, tblMakerCost.c.ModelCode,
  func.max(tblMakerCost.c.Effective_Date).label('Effective_Date')],
  tblMakerCost.c.Effective_Date=datetime.date.today(),group_by=[
  tblMakerCost.c.MakerCode,
  tblMakerCost.c.ModelCode]).alias('sCCSub')

  sCurrentCost=select([c for c in
  tblMakerCost.c],tblMakerCost.c.MakerCost
  0,from_obj=[join(tblMakerCost,sCCSub,and_(
  sCCSub.c.MakerCode==tblMakerCost.c.MakerCode,and_(
  sCCSub.c.ModelCode==tblMakerCost.c.ModelCode,
  sCCSub.c.Effective_Date==tblMakerCost.c.Effective_Date
  )))]).alias('sCurrentCost')

  Maker.mapper[Primary]=mapper(Maker, tblMaker, properties={
  'AllCosts':relation(MakerCost, backref='Maker',lazy=True,
  cascade=all, delete-orphan),
  'Costs': relation(mapper(MakerCost,sCurrentCost,
  

[sqlalchemy] Re: [sqlalchemy]

2007-04-05 Thread Rick Morrison
trans = session.create_transaction()
messages.delete(messages.c.submitter_type == 'spammer').execute()
bozodetector.insert().execute({'[EMAIL PROTECTED]'})
trans.commit()



On 4/5/07, meyyitfani [EMAIL PROTECTED] wrote:

 *The Second Station of the Thirteenth Word*



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] query for a subset of the object's columns

2007-04-05 Thread Disrupt07

I hava a table called mytable (defined in the model as mytable_def)
with the following columns:
  name, surname, age, address, idcard, sex, mobilenumber

I want to query its name and surname columns only, so I am using a
query such as the following:

results=select([mytable_def.c.name,mytable_def.c.surname],
 
distinct=True,order_by=[desc(processlibrary_def.c.popularity)],
   offset=0).execute()

Can I use the SQLAlchemy instance of the mytable_def definition to
query on 2 (only 2, not all columns) of mytable's columns instead of
defining a query similar to the above?

Thanks.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Is ILIKE supported?

2007-04-05 Thread Paul Kippes

Michael, I certainly understand why this hasn't been added.  With some
databases like sqlite, a case sensitive search isn't even possible.
This is much more complicated that I would have imagined.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: How would you build a mapper with a calculated field based on a join from two tables

2007-04-05 Thread vinjvinj

 a = user_table()
 a.a_column_in_user_table_1  + a.additional_info.your_column


My logic is not as simple as (a.a_column_in_user_table_1  +
a.additional_info.your_column). It's about 20 lines of code. Also I'm
trying to understand how you would add additional attributes to a
python User object which is set up by the sqlalchemy mysql object.

Vineet


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Autoload and Foreign Keys

2007-04-05 Thread mike nelson

Could someone explain how I could do the following:

#None of these tables have foreign keys defined in the database
entity = Table('entity',meta,autoload=True)
user = Table('user',meta,autoload=True)

class Entity(object):
pass

class User(Entity):
pass

m_entity = mapper(Entity,entity)

#this raises an exception because there are no foreign keys defined
between entity and user
m_user = mapper(User,user,inherits=m_entity)

Is there a way I can still use autoload (these tables have a lot of
columns and they change somewhat frequently) and explicitly add a
foreign key relationship between the two and allow for inheritance?

Thanks in advance


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: simple many-to-many select

2007-04-05 Thread Alexandre CONRAD

Michael Bayer wrote:

 My preference with assign_mapper at this point is to say:
 
 Client.query.filter_by(sites=siteobj)

For the mailing list's archives correctness:

   Client.query().filter_by(sites=siteobj)

 i.e. i dont think constantly adding methods to assignmapper is going  
 to scale, as the chances of conflicts with existing user classes  
 grows.  im into hierarchies of names rather  than huge straight down  
 lists.

I understand. I also think that having it in the query() is a good 
practice. Then maybe the methods directly accessible from Client.x() 
should be set as deprecated ?

Regards,
-- 
Alexandre CONRAD


 On Apr 4, 2007, at 5:40 AM, Alexandre CONRAD wrote:
 
 
Glauco wrote:


Alexandre CONRAD ha scritto:


Okay, thanks. Any idea if .filter_by() and other new generative  
method
will be available in an assign_mapper object?

Yes..it's available, the final object has identical property as  a  
mapper

Well, model.Client.filter_by(sites=siteobj) doesn't work for me...

   AttributeError: type object 'Client' has no attribute 'filter_by'

Or am I misunderstanding how to use it ?

Regards,
-- 
Alexandre CONRAD



 
 
  
 
 
 ---
 Texte inséré par Platinum 2007:
 
  S'il s'agit d'un mail indésirable (SPAM), cliquez sur le lien suivant pour 
 le reclasser : http://127.0.0.1:6083/Panda?ID=pav_33314SPAM=true
 ---
 
 




--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: offset limit on query with relations

2007-04-05 Thread King Simon-NFHD78


Huy wrote:
 
 Hi,
 
 When using the generative limit() offset() or order_by calls 
 on mapper 
 query, the sql generated looks weird.
 
 I get something like
 
 select table1.* table2.*
 from (select table1a.id from table1a limit 20 offset 0 order by 
 table1.col) as table_row, table1 join table2 (on...)
 
 
 Notice how the limit and offset is in that subselect ? Is 
 this by design.
 The query results are not what I would expect either because the 
 subselect doesn't join to the main table (table1).
 
 Hope what Im describing makes sense.
 

If the outer query involved eager loading of many-to-many properties,
the number of rows returned would not necessarily be the same as the
number of entities being loaded. By doing the limit and offset in the
inner query, it guarantees that you will get exactly the expected number
of entities.

At least, that's my understanding. Hope that helps,

Simon

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: offset limit on query with relations

2007-04-05 Thread HD Mail

King Simon-NFHD78 wrote:
 Huy wrote:
   
 Hi,

 When using the generative limit() offset() or order_by calls 
 on mapper 
 query, the sql generated looks weird.

 I get something like

 select table1.* table2.*
 from (select table1a.id from table1a limit 20 offset 0 order by 
 table1.col) as table_row, table1 join table2 (on...)
 

 Notice how the limit and offset is in that subselect ? Is 
 this by design.
 The query results are not what I would expect either because the 
 subselect doesn't join to the main table (table1).

 Hope what Im describing makes sense.

 

 If the outer query involved eager loading of many-to-many properties,
 the number of rows returned would not necessarily be the same as the
 number of entities being loaded. By doing the limit and offset in the
 inner query, it guarantees that you will get exactly the expected number
 of entities.

 At least, that's my understanding. Hope that helps
Hi Simon,

That makes perfect sense, but why is the inner query joined not joined 
with the main table from the outer query ? because this is not done, I 
get a cartesian product between the inner result with the outer result.

Thanks

Huy

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Autoload and Foreign Keys

2007-04-05 Thread Michael Bayer

explicitly specify the columns:

entity = Table('entity', meta,
Column('somecol', ForeginKey('user.id'))
autoload=True
)

On Apr 5, 2007, at 10:46 AM, mike nelson wrote:


 Could someone explain how I could do the following:

 #None of these tables have foreign keys defined in the database
 entity = Table('entity',meta,autoload=True)
 user = Table('user',meta,autoload=True)

 class Entity(object):
 pass

 class User(Entity):
 pass

 m_entity = mapper(Entity,entity)

 #this raises an exception because there are no foreign keys defined
 between entity and user
 m_user = mapper(User,user,inherits=m_entity)

 Is there a way I can still use autoload (these tables have a lot of
 columns and they change somewhat frequently) and explicitly add a
 foreign key relationship between the two and allow for inheritance?

 Thanks in advance


 


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: offset limit on query with relations

2007-04-05 Thread Michael Bayer


On Apr 5, 2007, at 6:27 PM, HD Mail wrote:


 King Simon-NFHD78 wrote:
 Huy wrote:

 Hi,

 When using the generative limit() offset() or order_by calls
 on mapper
 query, the sql generated looks weird.

 I get something like

 select table1.* table2.*
 from (select table1a.id from table1a limit 20 offset 0 order by
 table1.col) as table_row, table1 join table2 (on...)
 

 Notice how the limit and offset is in that subselect ? Is
 this by design.
 The query results are not what I would expect either because the
 subselect doesn't join to the main table (table1).

 Hope what Im describing makes sense.



 If the outer query involved eager loading of many-to-many properties,
 the number of rows returned would not necessarily be the same as the
 number of entities being loaded. By doing the limit and offset in the
 inner query, it guarantees that you will get exactly the expected  
 number
 of entities.

 At least, that's my understanding. Hope that helps
 Hi Simon,

 That makes perfect sense, but why is the inner query joined not joined
 with the main table from the outer query ? because this is not done, I
 get a cartesian product between the inner result with the outer  
 result.


the query wrapping i see in your example should only occur for eager  
loaded properties, so that the actual result you want, represented by  
the full rowset of the inner query, gets joined to the eager loaded  
properties you want.  everything you specify with your Query should  
be in the inner query.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] FlushError (unsaved, pending instance and is an orphan)

2007-04-05 Thread George Sakkis

I'm using SA (with Elixir on top) and I have a parent Entity Ranker
that has many children Results; that is, for a Ranker instance rk,
rk.results gives its children and for a Result rs, rs.ranker gives its
parent. When I add new children by providing the parent to the
constructor of the child (rather than appending the child to
rk.results) and then try to flush, I get:

FlushError: instance Result at (...) is an unsaved, pending
instance and is an orphan
(is not attached to any parent 'Ranker' instance via that classes'
'results' attribute)

Here's a (very) stripped-down version of what I'm doing:

ranker = Ranker(...)
for score in scores:
Result(ranker=ranker, score=score, **kwds).save()
session.flush()

I expected that I can create a parent-child link either from parent to
child (by appending to ranker.results) or from child to parent (as
above), but apparently the latter doesn't seem to work. Is this the
case or something else is wrong ?

George


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---