[sqlalchemy] Re: extra where on orm updates with error checking

2009-11-29 Thread kindly
Perfect.   I really thought I had read all the documentation.  Thanks
again.

On 28 Nov, 18:45, Michael Bayer mike...@zzzcomputing.com wrote:
 On Nov 28, 2009, at 10:25 AM, kindly wrote:



  Is there a way of, with every orm update to add extra conditions to
  the where clause and to check (and rollback if fail) that the row that
  was supposed to be updated actually was.  i.e

  user = session.query(User).get(4)  ## id of 4
  user.name = fred  ## a change to user name
  session.add(user)
  session.flush()

  I would want the sql that is issued at this point to be changed, so
  instead of just issuing just

  update user set name = fred where id = 4

  I would like to add another condition like

  update user set name = fred where id = 4  and current_version = 2

 this is provided through the version_id_col option on mapper().  see the 
 highlight at:

 http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html?highligh...

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




[sqlalchemy] [sqlamp] released version 0.5.1

2009-11-29 Thread Anton Gritsay
Hi all,

The sqlamp project gets a new release -- 0.5.1. The most important
highlight is that it now supports polymorphic inheritance of nodes. It
means that your trees can now contain objects of different types,
provided that they all have one base class.

sqlamp is an implementation of materialized path for SQLAlchemy. It is
licensed under BSD and have no external dependencies except of
SQLAlchemy.

docs and examples: http://sqlamp.angri.ru/
direct download of source dist: http://sqlamp.angri.ru/sqlamp-0.5.1.tar.gz

--
angri

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




[sqlalchemy] Re: pass any field as a keyword param to the constructor?

2009-11-29 Thread Lukasz Szybalski
I guess the proper solution is to setup your python class mapper like
this, and use the update method of the __dict__ instead of setattr.

class Recall(object):
def __init__(self, **kw):
self.__dict__.update(kw)
pass


Lucas

On Thu, Nov 26, 2009 at 3:24 PM, Lukasz Szybalski szybal...@gmail.com wrote:
 Any idea how should I be set the None Type argument to str.?

 x=Recall()
 type(x.MAKETXT) is type 'NoneType'

 set in OrmObject when it does the setattr it probably fails because
 you cannot setattr on NoneType objects?

 setattr(x.MAKETXT,'somevalue')
 Traceback (most recent call last):
  File stdin, line 1, in module
 TypeError: attribute name must be string, not 'NoneType'


 What is the proper way to do this?
 Thanks,
 Lucas

 On Wed, Nov 25, 2009 at 10:36 PM, Lukasz Szybalski szybal...@gmail.com 
 wrote:
 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GenericOrmBaseClass

 class Recall(OrmObject):pass

 mapper(Recall,recall_table)

 record=Recall(RECORD_ID=RECORD_ID,CAMPNO=CAMPNO,MAKETXT=MAKETXT)
 session.add(record)
 session.flush()

 This is not working if using the example set in the url. Is setattr
 still working.? What is the proper way to do this.for SA
 0.5.6?

 SQLAlchemy 0.5 Implementation:

 class OrmObject(object):

    def __init__(self, **kw):
        for key in kw:
            if not key.startswith('_') and key in self.__dict__:
                setattr(self, key, kw[key])

    def __repr__(self):
        attrs = []
        for key in self.__dict__:
            if not key.startswith('_'):
                attrs.append((key, getattr(self, key)))
        return self.__class__.__name__ + '(' + ', '.join(x[0] + '=' +
                                            repr(x[1]) for x in attrs) + ')'

 Thanks,
 Lucas




 --
 Setup CalendarServer for your company.
 http://lucasmanual.com/mywiki/CalendarServer
 Automotive Recall Database - See if you vehicle has a recall
 http://lucasmanual.com/recall




-- 
Setup CalendarServer for your company.
http://lucasmanual.com/mywiki/CalendarServer
Automotive Recall Database - See if you vehicle has a recall
http://lucasmanual.com/recall

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




[sqlalchemy] Re: SQLAlchemy 0.5.5 MySQL Issue

2009-11-29 Thread gizli
Thank you. That was exactly the problem. MyISAM engine was selected as
default, changed to InnoDB and now the autoflush behavior is as
expected.

On Nov 28, 4:36 am, Alexandre Conrad alexandre.con...@gmail.com
wrote:
 You may be using MyISAM storage engine which doesn't support transactions
 and may make all flushes persistent. The other storage engine widely used is
 InnoDB which does support transactions. Find out in the MySQL docs how to
 figure out which storage engine you're using.

 Sent from my fantastic HTC Hero

 On Nov 28, 2009 7:27 AM, gizli mehm...@gmail.com wrote:

 I am not sure about the storage engine but here goes:

 mysql status
 --
 mysql  Ver 14.12 Distrib 5.0.75, for debian-linux-gnu (i486) using
 readline 5.2

 the mysql-python version is MySQL_python-1.2.3c1

 On Nov 26, 11:47 pm, Alexandre Conrad alexandre.con...@gmail.com
 wrote:

  2009/11/27 gizli mehm...@gmail.com:
With mysql however, the insert done by the query() actually does a  

 commit.. i turned on ec...

 -- You received this message because you are subscribed to the Google Groups
 sqlalchemy group. To...

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




Re: [sqlalchemy] SQL IF in sqlalchemy?

2009-11-29 Thread Diego Woitasen
2009/11/28 Michael Bayer mike...@zzzcomputing.com:
 we support CASE via case() which will get you there just as well.


 On Nov 28, 2009, at 1:54 PM, Diego Woitasen wrote:

 Does sqlalchemy support SQL IF? For example:

 select date, if(proxy_user_id  1, count(distinct address_id), 0)
 from table group by date;

 I've solved this using literal SQL in Query() parameters but may be I
 can do it using ORM.


 --
 Diego Woitasen
 XTECH

 --

 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.



 --

 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.





I discovered that func.if_() works.

count_ip = func.if_(MiniAccess.proxy_user_id == dash_id,

func.count(MiniAccess.address_id.distinct()), 0)

I looks like func.foo() are translated to SQL FOO(), with the same arguments.



-- 
Diego Woitasen
XTECH

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




Re: [sqlalchemy] Re: pass any field as a keyword param to the constructor?

2009-11-29 Thread Michael Bayer

On Nov 29, 2009, at 2:17 PM, Lukasz Szybalski wrote:

 I guess the proper solution is to setup your python class mapper like
 this, and use the update method of the __dict__ instead of setattr.
 
 class Recall(object):
def __init__(self, **kw):
self.__dict__.update(kw)
pass

if Recall is ORM-mapped, the above won't work.  use setattr(), not __dict__ 
access.

 
 
 Lucas
 
 On Thu, Nov 26, 2009 at 3:24 PM, Lukasz Szybalski szybal...@gmail.com wrote:
 Any idea how should I be set the None Type argument to str.?
 
 x=Recall()
 type(x.MAKETXT) is type 'NoneType'
 
 set in OrmObject when it does the setattr it probably fails because
 you cannot setattr on NoneType objects?
 
 setattr(x.MAKETXT,'somevalue')

don't you mean setattr(x, 'MAKETXT', 'somevalue') here?





 Traceback (most recent call last):
  File stdin, line 1, in module
 TypeError: attribute name must be string, not 'NoneType'
 
 
 What is the proper way to do this?
 Thanks,
 Lucas
 
 On Wed, Nov 25, 2009 at 10:36 PM, Lukasz Szybalski szybal...@gmail.com 
 wrote:
 http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GenericOrmBaseClass
 
 class Recall(OrmObject):pass
 
 mapper(Recall,recall_table)
 
 record=Recall(RECORD_ID=RECORD_ID,CAMPNO=CAMPNO,MAKETXT=MAKETXT)
 session.add(record)
 session.flush()
 
 This is not working if using the example set in the url. Is setattr
 still working.? What is the proper way to do this.for SA
 0.5.6?
 
 SQLAlchemy 0.5 Implementation:
 
 class OrmObject(object):
 
def __init__(self, **kw):
for key in kw:
if not key.startswith('_') and key in self.__dict__:
setattr(self, key, kw[key])
 
def __repr__(self):
attrs = []
for key in self.__dict__:
if not key.startswith('_'):
attrs.append((key, getattr(self, key)))
return self.__class__.__name__ + '(' + ', '.join(x[0] + '=' +
repr(x[1]) for x in attrs) + ')'
 
 Thanks,
 Lucas
 
 
 
 
 --
 Setup CalendarServer for your company.
 http://lucasmanual.com/mywiki/CalendarServer
 Automotive Recall Database - See if you vehicle has a recall
 http://lucasmanual.com/recall
 
 
 
 
 -- 
 Setup CalendarServer for your company.
 http://lucasmanual.com/mywiki/CalendarServer
 Automotive Recall Database - See if you vehicle has a recall
 http://lucasmanual.com/recall
 
 --
 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 
 

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




Re: [sqlalchemy] Re: pass any field as a keyword param to the constructor?

2009-11-29 Thread Lukasz Szybalski
On Sun, Nov 29, 2009 at 3:58 PM, Michael Bayer mike...@zzzcomputing.com wrote:

 On Nov 29, 2009, at 2:17 PM, Lukasz Szybalski wrote:

 I guess the proper solution is to setup your python class mapper like
 this, and use the update method of the __dict__ instead of setattr.

 class Recall(object):
    def __init__(self, **kw):
        self.__dict__.update(kw)
    pass


mapper(Recall,recall_table)

then.

x=Recall(column1=column1.)
session.add(Recall)

 if Recall is ORM-mapped, the above won't work.  use setattr(), not __dict__ 
 access.

This seems to work in 0.5.6? Does that change in 0.6? or



Yes.



 Lucas

 On Thu, Nov 26, 2009 at 3:24 PM, Lukasz Szybalski szybal...@gmail.com 
 wrote:
 Any idea how should I be set the None Type argument to str.?

 x=Recall()
 type(x.MAKETXT) is type 'NoneType'

 set in OrmObject when it does the setattr it probably fails because
 you cannot setattr on NoneType objects?

 setattr(x.MAKETXT,'somevalue')

 don't you mean setattr(x, 'MAKETXT', 'somevalue') here?

yesthat was my mistake...

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.




Re: [sqlalchemy] Re: pass any field as a keyword param to the constructor?

2009-11-29 Thread Michael Bayer

On Nov 29, 2009, at 7:24 PM, Lukasz Szybalski wrote:

 On Sun, Nov 29, 2009 at 3:58 PM, Michael Bayer mike...@zzzcomputing.com 
 wrote:
 
 On Nov 29, 2009, at 2:17 PM, Lukasz Szybalski wrote:
 
 I guess the proper solution is to setup your python class mapper like
 this, and use the update method of the __dict__ instead of setattr.
 
 class Recall(object):
def __init__(self, **kw):
self.__dict__.update(kw)
pass
 
 
 mapper(Recall,recall_table)
 
 then.
 
 x=Recall(column1=column1.)
 session.add(Recall)
 
 if Recall is ORM-mapped, the above won't work.  use setattr(), not __dict__ 
 access.
 
 This seems to work in 0.5.6? Does that change in 0.6? or

its not been safe to modify __dict__ directly since at least 0.3.



 
 
 
 Yes.
 
 
 
 Lucas
 
 On Thu, Nov 26, 2009 at 3:24 PM, Lukasz Szybalski szybal...@gmail.com 
 wrote:
 Any idea how should I be set the None Type argument to str.?
 
 x=Recall()
 type(x.MAKETXT) is type 'NoneType'
 
 set in OrmObject when it does the setattr it probably fails because
 you cannot setattr on NoneType objects?
 
 setattr(x.MAKETXT,'somevalue')
 
 don't you mean setattr(x, 'MAKETXT', 'somevalue') here?
 
 yesthat was my mistake...
 
 --
 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@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.
 
 

--

You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@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.