[sqlalchemy] Cascading deletes to children

2008-12-05 Thread James Brady
] COMMIT Any help would be much appreciated! James --~--~-~--~~~---~--~~ 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

[sqlalchemy] Re: Cascading deletes to children

2008-12-05 Thread James
.  These   are described athttp://www.sqlalchemy.org/docs/05/sqlalchemy_orm.html#docstrings_sqla...  . On Dec 5, 2008, at 11:42 AM, James Brady wrote: Hi all, I'm trying to get deletes and updates cascaded down from a parent   object to the child objects (connected by ForeignKey). It all seems

[sqlalchemy] Re: Cascading deletes to children

2008-12-05 Thread James
Yep, the same behaviour in 0.5rc4 On Dec 5, 12:44 pm, James [EMAIL PROTECTED] wrote: Ah, I should say I'm using SA 0.4.3 - I going to try the same test on 0.5 On Dec 5, 11:36 am, Michael Bayer [EMAIL PROTECTED] wrote: actually, use passive_deletes=True, not 'all'.   It will issue DELETEs

[sqlalchemy] Re: Cascading deletes to children

2008-12-05 Thread James
Ah! I see - I had the cascade and passive_delete arguments in the wrong place. This works as expected in 0.4.3 and 0.5 now. Thanks for the help James On Dec 5, 12:47 pm, Michael Bayer [EMAIL PROTECTED] wrote: Assuming user_id is a surrogate primary key, I dont see any need for   onupdate

[sqlalchemy] Re: How are connections managed?

2008-10-20 Thread Heston James
Hi Michael, Thanks for your response on this. the engine is using a connection pool which by default will keep five connections opened persistently.  It also has an overflow of 10 additional connections which are opened on an as-needed basis and closed after usage.  At the point of 15

[sqlalchemy] Re: How are connections managed?

2008-10-20 Thread Heston James
Hello Again Michael, This makes perfect sense to me, I've been looking at my application log data this morning and can see the connections being created, pooled and checked out exactly as I would expect which is a very good sign. I can however see that my application can potentialy see a

[sqlalchemy] How are connections managed?

2008-10-16 Thread Heston James - Cold Beans
Afternoon Guys, I have a suspicion that I'm leaving MySQL database connections open when I shouldn't be and I'm trying to understand how they are managed by SQLAlchemy. I currently create an engine instance and bind my session maker too it like this: # Create the engine to

[sqlalchemy] Error writing file

2008-10-15 Thread Heston James - Cold Beans
Guys, Got an unusual error this morning when running a query, I keep getting: Error writing file '/tmp/MYHo980S' (Errcode: 28) Thrown at me, any ideas what this is all about? What is it trying to write to the FS? Cheers, Heston

[sqlalchemy] Is this a transaction?

2008-10-15 Thread Heston James - Cold Beans
Quick question I hope guys. If I have an object which contains a bunch of children and cascade is set on the relationships. When I add the parent object to the session and commit it, are the children saved as part of a transaction by default? Or do I have to do something special? If I

[sqlalchemy] Re: object_session(remote_device_object) returns noneType

2008-10-13 Thread Heston James - Cold Beans
PROTECTED] On Behalf Of Michael Bayer Sent: 10 October 2008 15:25 To: sqlalchemy@googlegroups.com Subject: [sqlalchemy] Re: object_session(remote_device_object) returns noneType On Oct 10, 2008, at 8:03 AM, Heston James - Cold Beans wrote: Morning guys, When calling object_session

[sqlalchemy] Can't connect to local MySQL server

2008-10-09 Thread Heston James - Cold Beans
Hello Guys, I'm receiving errors in my application on a fairly regular basis now and I'm not sure how to begin solving it. Please find attached a backtrace for the error. It seems that its struggling to connect to the MySQL server, however I get this after the application has been running

[sqlalchemy] Limit to 500 records after particular date.

2008-09-24 Thread Heston James - Cold Beans
Morning Guys, I hope this'll be a fairly simple question. I have a query which looks something like this: the_objects = session.query(myobject.myobject).filter(myobject.created :lastrecord).params(lastrecord=time.strftime(%Y-%m-%d %H:%M:%S, from_date)).all() This grabs all the records

[sqlalchemy] Re: Limit to 500 records after particular date.

2008-09-24 Thread Heston James
PROTECTED] wrote: first u get your query sorted in proper order (by timestamp or even dbid, or hierarchicaly via subselect + groupby + order, whatever) then yourquery[:1000] On Wednesday 24 September 2008 14:11:24 Heston James - Cold Beans wrote: Morning Guys, I hope this'll be a fairly

[sqlalchemy] Re: Limit to 500 records after particular date.

2008-09-24 Thread Heston James
:27 pm, Werner F. Bruhin [EMAIL PROTECTED] wrote: Heston, Heston James wrote: Hi, Thanks for the response, that gave me a good foot in the door to this. I've now appened my existing query with. .order_by('myobject.created')[:1000] Just tried this on a simple example: query

[sqlalchemy] Storing UTC Dates

2008-08-28 Thread Heston James - Cold Beans
Hello Guys, This might seem like a bit of a naive question but I'm looking for your advice. Being from the UK we operate on Daylight Savings Time which gives us a one hour offset on times for a few months of the year. I currently have a DateTime column which is declared like so:

[sqlalchemy] Re: Storing UTC Dates

2008-08-28 Thread Heston James - Cold Beans
Hi Werner, IIUC func.now is a database function. Ah, ok, that makes fair sense. You should be able to use datetime instead i.e.: created = Column(DateTime, default=datetime.datetime.utcnow) modified = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)

[sqlalchemy] DateTime Column as Python time tuple.

2008-08-19 Thread Heston James - Cold Beans
Hello Guys, I'm looking to send an object from SQLAlchemy across a ZSI web service as a complex type. To do this ZSI requires that datetime's in the objects be in Python Time Tuples as documented in the 'time' module. It looks as if by default SQLAlchemy uses datetime.datetime objects for

[sqlalchemy] Re: Mapper extensions in declerative.

2008-07-25 Thread Heston James - Cold Beans
Hi Kyle, Thanks for the really thorough response, it seems you know what you're on about :-) I agree with you that it would likely be a foolish decision to rely on undocumented behaviour, this will likely come back to bite me at some point in the future. I'm going to take all these ideas away

[sqlalchemy] Run basic query

2008-07-24 Thread Heston James - Cold Beans
Guys, I want to run a query which doesn't return any objects, just simply modifies all records in the table, like so: UPDATE foo SET bar = 0 How can I do this using SQLAlchemy? Is it possible and 'proper' for me to just pass this query as a string

[sqlalchemy] Re: Save file to FS along with object database commit.

2008-07-22 Thread Heston James - Cold Beans
Afternoon All, Hello Guys, I have an object which I save to the database using SQLAlchemy, the class is defined using declarative and has a whole bunch of properties. This object has one property though which isn't saved to the database, but to the file system. It is basically a binary

[sqlalchemy] Save file to FS along with object database commit.

2008-07-21 Thread Heston James - Cold Beans
Hello Guys, I have an object which I save to the database using SQLAlchemy, the class is defined using declarative and has a whole bunch of properties. This object has one property though which isn't saved to the database, but to the file system. It is basically a binary string of a files

[sqlalchemy] Boolean, Declerative, MySQL 5.2

2008-07-19 Thread Heston James - Cold Beans
Hello Guys, I'm looking to store a Boolean value in a MySQL 5.2 database. I'm then going to describe a class for the table using declarative and have a couple of questions on this: What Datatype should my table column be set to in MySQL? And likewise, when declaring the column using

[sqlalchemy] Re: Boolean, Declerative, MySQL 5.2

2008-07-19 Thread Heston James - Cold Beans
I am using Column(Boolean) with declarative and MySQL and it is working fine. In MySQL itself the type is 'tinyint(1)' but they provide 'bool' and 'boolean' as synonyms if you prefer. Bobby, Thank you for this, I went with the tinyint(1) and it seems to be working great! Thanks, Heston

[sqlalchemy] Re: Injecting business objects into constructor

2008-07-16 Thread Heston James - Cold Beans
Hi Rick, I'm not sure where this is going with the 0.5 version, but I believe that MappedClass.__int__ is still not called when objects are loaded from the DB. If that's the case, and there isn't some alternate that SA provides like MappedClass.__onload__, You can look into Mapper

[sqlalchemy] Ensure Get() always returns a result.

2008-07-16 Thread Heston James - Cold Beans
Morning Guys, I'm looking to build a uniform method for getting/creating instance of my objects from the database. At the moment I've been using query(SomeObject).get(object_id) to return the objects from the DB, however, it would be really great if there were a method which always returned a

[sqlalchemy] Joined Query

2008-07-16 Thread Heston James - Cold Beans
Afternoon Chaps, I've got a query here which I've been looking to reconstruct from the standard SQL into a SQLAlchemy statement which will return a list of objects but I'm really struggling to make any headway on it, I'm hoping you'll be able to offer me some help. I have two objects in my

[sqlalchemy] Re: Injecting business objects into constructor

2008-07-16 Thread Heston James - Cold Beans
Hi Michael, theres some experiments in IoC for Python if you google around for dependency injection python, but the Python way is usually focused around not really needing thick layers of abstraction like that. Thanks for that. I did do some googling around a while back when first

[sqlalchemy] Re: M2M relationship

2008-07-15 Thread Heston James - Cold Beans
Hi Michael, create a file called something like globals.py, and in all other modules that use SQLAlchemy, say import globals. A primer on modules, packages and such is at http://www.python.org/doc/tut/node8.html Excellent! This seems to have done the job, I am now successfully

[sqlalchemy] Filter by optional attributes.

2008-07-15 Thread Heston James - Cold Beans
Good morning guys, I'm looking for a way in which I can query my database for records which meet multiple, optional arguments. I'm looking to encapsulate access to this using a service layer, I want to create a method like this: def get_foos(self, foo_id=, foo_firstname=,

[sqlalchemy] Re: Filter by optional attributes.

2008-07-15 Thread Heston James - Cold Beans
Hi Svil: use keywordargs as dictionary, i.e. ...query.filter( **kwargs) where the kwargs are a dict made by u containing only the required fields. e.g. kwargs={} if foo_id: kwargs['fooid']=fooid That sounds like a fair enough solution to me, seems safer than the more generic version.

[sqlalchemy] Re: Filter by optional attributes.

2008-07-15 Thread Heston James - Cold Beans
Hello Again Svil: That sounds like a fair enough solution to me, seems safer than the more generic version. Thanks for the tip mate, sounds really great. I'll play around with that concept. Heston I've tested this little concept and it works really nicely :-D thanks. One quick question

[sqlalchemy] Re: Filter by optional attributes.

2008-07-15 Thread Heston James - Cold Beans
Hi, pass an echo=True to the create_engine() (or whereever else u could pass that) and u'll see the sql. Ok, I see! Perfect! I've just configured logging on this so I can keep track, looks excellent. Heston --~--~-~--~~~---~--~~ You received this message

[sqlalchemy] Injecting business objects into constructor

2008-07-15 Thread Heston James - Cold Beans
Afternoon Guys, In my classic non-orm based applications I would usually inject other business object instances into my classes for such things as logging, emailing and all manner of other things. For instance: class foo: def __init__(self, logger, email_service, foo_id=,

[sqlalchemy] Re: M2M relationship

2008-07-14 Thread Heston James - Cold Beans
Hi Michael, what I see immediately is that you're declaring mutliple declarative_bases and multiple MetaData objects. All of the Table objects which relate to one another need to share the same underlying MetaData object, and the declarative_base() function also uses a MetaData

[sqlalchemy] Re: M2M relationship

2008-07-14 Thread Heston James - Cold Beans
Hello Michael, what I see immediately is that you're declaring mutliple declarative_bases and multiple MetaData objects. All of the Table objects which relate to one another need to share the same underlying MetaData object, and the declarative_base() function also uses a MetaData

[sqlalchemy] Re: M2M relationship

2008-07-13 Thread Heston James - Cold Beans
Hi Michael, declarative places a convenience __init__ that installs keywords as attributes, but you're free to override this constructor with anything you'd like. Thank you for confirming this for me, I'd hoped I'd be able to override the class constructor, I often use it for

[sqlalchemy] Re: M2M relationship

2008-07-13 Thread Heston James - Cold Beans
i'm sorry for my misleading reply;( i was kind of too sleepy last night;P No problem my man. Heston. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] Re: Connecting to MySQL

2008-07-11 Thread Heston James - Cold Beans
Column('created', DateTime, default=func.now()), Column('updated', DateTime, onupdate=func.now())) You can set both default= and onupdate= on the same Column if you want 'updated' to be non-NULL on insert. That sounds like a nice clean way of doing this Jason, I'm more than

[sqlalchemy] Re: Connecting to MySQL

2008-07-11 Thread Heston James - Cold Beans
Hello Rick, These mapper extensions look very good, I've used a similar concept in other ORM's in the past for all manner of things and have a couple of decent ways to utilize them in this current application. Cheers, Heston From: sqlalchemy@googlegroups.com [mailto:[EMAIL

[sqlalchemy] M2M relationship

2008-07-11 Thread Heston James - Cold Beans
Good morning all, So, this morning's challenge has been learning many-to-many relationships, after reading through the tutorial I understand most of the core concepts of how it should work but I'm struggling to actually make it do so, I thought I would come and rely on you good people to help

[sqlalchemy] Re: M2M relationship

2008-07-11 Thread Heston James - Cold Beans
NameError's are thrown usualy by import'ing or similar mechanisms. have a look on your code. eventualy post the whole traceback? Hello Mate, I think you're right, but the problem is that I don't know what I 'should' be importing into the class. See, I have two files; Post.py and

[sqlalchemy] Re: M2M relationship

2008-07-11 Thread Heston James - Cold Beans
the association table is an instance of Table, and does not need its own class. It's easiest to declare the association table in the same module as that which it is used, in this case post.py. Ok this sounds fine, I've done this now, declaring the table in the post.py module. When you

[sqlalchemy] Re: M2M relationship

2008-07-11 Thread Heston James - Cold Beans
if u look up the stacktrace/traceback, u'll see which statement in your own code triggered the error. is it in the mapping-part or is still in table-declaration part? do all 3 tables use same metadata? Thank you for your comments so far, I appreciate you helping me out on this. The entire

[sqlalchemy] Re: Connecting to MySQL

2008-07-10 Thread Heston James - Cold Beans
Session.add is a version 0.5 method, you're maybe running 0.4.6? In the 0.4.x series, it's going to be: Session.save() for objects that are to be newly added to the session Session.update() for objects that are already in the session, or Session.save_or_update() to have the library figure

[sqlalchemy] column name must be lowercase for CheckConstraint.

2008-05-05 Thread James Su
If you define a column with column name contains capital letter, and define CheckConstraint for this column, then DDL issued by SA will be wrong. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To

[sqlalchemy] Re: TurboGears: best practices for SELECTing

2007-10-16 Thread James Brady
Hi Florent, On Oct 11, 1:01 pm, Florent Aide [EMAIL PROTECTED] wrote: On 10/11/07, James Brady [EMAIL PROTECTED] wrote: Did you call assign_mapper on Ownership? [...] However, I'm using the identity framework (part of TurboGears) which unfortunately doesn't play nicely

[sqlalchemy] Re: TurboGears: best practices for SELECTing

2007-10-11 Thread James Brady
, which currently has a lot more on SQLObject... So it seems from that tutorial that session.query... is the way to go for these selects, and I need to learn how to manage the sessions properly! Thanks, James --~--~-~--~~~---~--~~ You received this message because

[sqlalchemy] Re: TurboGears: best practices for SELECTing

2007-10-11 Thread James Brady
On Oct 10, 2:12 pm, Marco Mariani [EMAIL PROTECTED] wrote: James Brady ha scritto: The problem I'm hitting at the moment is how to properly select simple objects... There seems to be two main approaches, for example: session.query(Ownership).select() or ownership_table.select

[sqlalchemy] TurboGears: best practices for SELECTing

2007-10-10 Thread James Brady
these specific questions or point me in the direction of some further documentation? Thanks, James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy

[sqlalchemy] Re: ondelete cascade with turbogears/SA

2007-08-16 Thread James
just to make sure I'm understanding this: even though mysql is configured to cascade deletes for this relationship, SA needs to be told about it so that it doesn't prevent it from cascading by first nulling the foreign key? I tried this: class Account(ActiveMapper): class mapping:

[sqlalchemy] Re: ondelete cascade with turbogears/SA

2007-08-16 Thread James
='delete' and passive_deletes=True items belong? thanks, James --~--~-~--~~~---~--~~ 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

[sqlalchemy] ondelete cascade with SA.

2007-08-15 Thread James
column (below) based on example here: http://www.sqlalchemy.org/docs/03/adv_datamapping.html This did not work. Child rows not deleted. Any help much appreciated! James INFO: I have accounts with one-to-many users in model.py: class User(ActiveMapper): Reasonably basic User definition

[sqlalchemy] ondelete cascade with turbogears/SA

2007-08-15 Thread James
call in the account column (below) based on example here: http://www.sqlalchemy.org/docs/03/adv_datamapping.html This did not work. Child rows not deleted. Any help much appreciated! James INFO: I have accounts with one-to-many users in model.py: class User(ActiveMapper): Reasonably

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
which python reference (url?) are you speaking of? how does 'import_fullname' work? how would it be applied? On Jul 21, 11:35 am, [EMAIL PROTECTED] wrote: In other words, should I first attempt to __import__('vor.'+modname) in runJob() ? see the python reference about how to use __import__

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
aaah, u are _that_ new... - use it instead of the __import__() func - original python library reference of the version u use; e.g.http://docs.python.org/lib/built-in-funcs.html wow there's a level parameter now... somethin to try I'm not using 2.5 (2.4 still). I tried the 'my_import'

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
Ok, I just tried something that actually worked. WOO HOO! First, I appended the sys.path var like this (relative, was absolute before): sys.path.append( 'vor') combined with this: ... module = my_import('vor.'+modname) ... I realize that this is not ideal. But

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
-3: 2.5 or 2.4 all the same (Except abs/rel imports which still dont work in 2.5 anyway). -2: u need my_import (or similar) because __import__( 'vor.model') will not give u want u want. -1: u need to give _same_ full absolute paths to __import__ (or substitute) or else u'll get duplicated

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
On Jul 23, 10:33 am, svilen [EMAIL PROTECTED] wrote: First, I appended the sys.path var like this (relative, was absolute before): sys.path.append( 'vor') IMO u should not touch sys.path unless u really really have no other chance. Although this above is another wholesale

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-23 Thread Jesse James
On Jul 23, 10:33 am, svilen [EMAIL PROTECTED] wrote: First, I appended the sys.path var like this (relative, was absolute before): sys.path.append( 'vor') IMO u should not touch sys.path unless u really really have no other chance. Although this above is another wholesale

[sqlalchemy] Re: Issue when loading module in scheduler utility

2007-07-21 Thread Jesse James
On Jul 20, 10:42 pm, [EMAIL PROTECTED] wrote: this ain't SA issue, but if u want a solution, u have to provide more data, and do some prints here-there. When a scheduled job is run, its specified module is loaded using __import__ . This works fine unless the loaded module has an

[sqlalchemy] Issue when loading module in scheduler utility

2007-07-20 Thread Jesse James
I am creating a persistent job scheduler utility in my TG application and have run into a minor issue regarding SqlAlchemy. When a scheduled job is run, its specified module is loaded using __import__ . This works fine unless the loaded module has an 'import model' in it. If so, I get this:

[sqlalchemy] Order by lost in subselect?

2006-11-29 Thread James Taylor
I want to use order by and limit in a sub select, but it doesn't seem to work: Code import pkg_resources pkg_resources.require( sqlalchemy ) pkg_resources.require( pysqlite ) from sqlalchemy import * metadata = BoundMetaData( 'sqlite:tmp/test.db' ) metadata.engine.echo = True

<    1   2