RE: [sqlalchemy] How do I change enum values after previously creating a table?

2012-02-09 Thread Jackson, Cameron
Mike, may I suggest this as an enhancement: If SQLA is creating a table with an Enum column, and if there's already an Enum with the specified name, it should spit out an error if the list of values for the existing and requested Enums don't match? Maybe, though would that same logic extend to

RE: [sqlalchemy] How do I change enum values after previously creating a table?

2012-02-08 Thread Jackson, Cameron
(Mike: my problem is solved, but please read my final sentence for an enhancement request) >>> I'm guessing the old User_Roles type still exists in the database. You can >>> drop it with "DROP TYPE User_Roles". Yes, this is what I figured was happening, I wasn't sure how to get rid of it thoug

[sqlalchemy] How do I change enum values after previously creating a table?

2012-02-08 Thread Jackson, Cameron
One of my tables used to have something like: role = Column(Enum('user', 'admin', name = User_Roles)) Now I want to change it to: role = Column(Enum('user', 'superuser', name = User_Roles)) But I can't figure out how to change the enum values in the database. I've tried dropping the tabl

RE: [sqlalchemy] When creating many-to-many relationship I get: NoReferencedTableError

2012-02-08 Thread Jackson, Cameron
Have you tried changing the order so that Card is defined before collection_cards? Obviously you're passing 'cards.id' as a string so that the order doesn't matter, but have you tried it anyway? -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On

RE: [sqlalchemy] Re: String matching

2012-02-08 Thread Jackson, Cameron
I haven't been entirely following along with what you and Mike have been talking about, but one final suggestion: If your problem is something to with LIKE only working in one direction, you could always do the first filter in the query, and then filter those results in the other direction in Py

RE: [sqlalchemy] String matching

2012-02-07 Thread Jackson, Cameron
Ah, I missed a closing ) in my code sample there. There should be a ) before the ], to close the if statement. -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Cameron Sent: Wednesday, 8 February 2012 10:01 AM To: sqlalchemy

RE: [sqlalchemy] String matching

2012-02-07 Thread Jackson, Cameron
I'm not sure how to do exactly what you're asking, but I have an alternative suggestion: You could just query everything and do the filter at the application level (i.e. in Python), rather than in the query. Because Python is awesome, this is now easy to write: custom_string = 'foobar'

RE: [sqlalchemy] Anticipating an IntegrityError before it happens (or noticing it immediately after)

2012-01-23 Thread Jackson, Cameron
Wichert Akkerman Sent: Monday, 23 January 2012 6:44 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Anticipating an IntegrityError before it happens (or noticing it immediately after) On 2012-1-23 03:23, Jackson, Cameron wrote: > Anyway, it kind of looks to me like any attempt to

RE: [sqlalchemy] Anticipating an IntegrityError before it happens (or noticing it immediately after)

2012-01-22 Thread Jackson, Cameron
.au<http://www.thalesgroup.com.au> From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Monday, 23 January 2012 12:41 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Anticipating an IntegrityError before it happens (or noticing it

[sqlalchemy] RE: Anticipating an IntegrityError before it happens (or noticing it immediately after)

2012-01-22 Thread Jackson, Cameron
4591 cameron.jack...@thalesgroup.com.au<mailto:cameron.jack...@thalesgroup.com.au> | www.thalesgroup.com.au<http://www.thalesgroup.com.au> From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Cameron Sent: Monday, 23 January 2012 11:51 AM To: sqlalchemy@go

[sqlalchemy] Anticipating an IntegrityError before it happens (or noticing it immediately after)

2012-01-22 Thread Jackson, Cameron
I have a certain ORM model that is being referenced from several other models. I don't want the user to be able to delete rows from that table that are still being referenced elsewhere. Ideally I would like something like: refs = get_references(row) if refs: print "Can't delete r

RE: [sqlalchemy]Close database connection in SQLAlchemy

2012-01-22 Thread Jackson, Cameron
* http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session.close * Not too sure if there is a pre-written or easy way to do caching, or if you'd have to write it yourself. -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegro

RE: [sqlalchemy] Re: Initialize model by its primary key.

2012-01-15 Thread Jackson, Cameron
I just re-read that, and I think I came across as a bit frustrated or impatient, which certainly wasn't my intention. Apologies if it read that way to anyone else :) -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Ca

RE: [sqlalchemy] Re: Initialize model by its primary key.

2012-01-15 Thread Jackson, Cameron
l(id) model2.instance.title='text2' model2.commit() On Jan 15, 8:49 pm, "Jackson, Cameron" wrote: > In the MVC architecture, the application class I mentioned is your > controller, and the session is part of it. > > > > > > > > -Original Message-

RE: [sqlalchemy] Re: Initialize model by its primary key.

2012-01-15 Thread Jackson, Cameron
In the MVC architecture, the application class I mentioned is your controller, and the session is part of it. -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Cameron Sent: Monday, 16 January 2012 12:45 PM To: sqlalchemy

RE: [sqlalchemy] Re: Initialize model by its primary key.

2012-01-15 Thread Jackson, Cameron
. I will post my example when I get it working. ~Grant On Jan 15, 6:42 pm, "Jackson, Cameron" wrote: > Putting a session inside a model seems like an odd thing to want to do. > Changes in session A won't show up in session B until you commit() A and > rollback() B (whi

RE: [sqlalchemy] Initialize model by its primary key.

2012-01-15 Thread Jackson, Cameron
Putting a session inside a model seems like an odd thing to want to do. Changes in session A won't show up in session B until you commit() A and rollback() B (which of course will destroy changes you may have made in B). I think your Test0 constructor should just be: def __init__(self, titl

RE: [sqlalchemy] insert or update on duplicate key

2012-01-11 Thread Jackson, Cameron
Bah! Mike beat me to it again! :P -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Michael Bayer Sent: Thursday, 12 January 2012 12:07 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] insert or update on duplicate key On

RE: [sqlalchemy] insert or update on duplicate key

2012-01-11 Thread Jackson, Cameron
That looks like an OK way to do things to me, but I'm by no means an expert. Depending on memory limitations, and how big the table is going to get, you might be able to do something like: * Store all index objects at application startup: self.indices = self.session.query(Index).all() * Che

RE: [sqlalchemy] sql hashed tables

2012-01-09 Thread Jackson, Cameron
Woah, 100 tables of users? That doesn't seem right. How come you don't just have 1 table, 'users', with an id column, and then each user is a row in the table? Likewise for your events. Is there a reason you don't have a single 'events' table, with date as a column, and then each row in the tab

RE: [sqlalchemy] Strange session.commit behavior

2012-01-09 Thread Jackson, Cameron
I agree with Mike, I don't think vars(obj).update(kwargs) is the best way to do it. Python trusts the programmer enough to let you bypass the middle layers of abstraction like this, but it's not always a good idea. Besides, it only takes 2 lines to do it with setattr() instead: for key, val

[sqlalchemy] RE: Is there a way to accrue all references to a declarative mapped object?

2012-01-03 Thread Jackson, Cameron
, Australia Tel: +61 3 8630 4591 cameron.jack...@thalesgroup.com.au<mailto:cameron.jack...@thalesgroup.com.au> | www.thalesgroup.com.au<http://www.thalesgroup.com.au> From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Cameron Sent: Wednesday, 4 Januar

[sqlalchemy] Is there a way to accrue all references to a declarative mapped object?

2012-01-03 Thread Jackson, Cameron
I have a relatively complex structure to my data. In essence it's something like: * A Foo is a small object containing some data. * A Bar has a fixed number of (say, 3) references to Foos * A Baz has a single Bar, plus one additional Foo * A Qux has a single Foo

RE: [sqlalchemy] SqlAlchemy dynamic query generation

2011-12-21 Thread Jackson, Cameron
You might get more help if you provide more details. What error are you getting? -Original Message- From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Sana Sent: Thursday, 22 December 2011 2:50 AM To: sqlalchemy Subject: [sqlalchemy] SqlAlchemy dynamic que

RE: [sqlalchemy] How can I have duplicate entries in a many-to-many relationship.

2011-12-19 Thread Jackson, Cameron
s.com Subject: Re: [sqlalchemy] How can I have duplicate entries in a many-to-many relationship. On Dec 19, 2011, at 8:13 PM, Jackson, Cameron wrote: A have a Machines table and a Parts table. A machine is made up of many parts, and each part could be in many machines, so clearly this is a M:M re

[sqlalchemy] How can I have duplicate entries in a many-to-many relationship.

2011-12-19 Thread Jackson, Cameron
A have a Machines table and a Parts table. A machine is made up of many parts, and each part could be in many machines, so clearly this is a M:M relationship. I've implemented this with a secondary table, which has two columns: machine_id and part_id. There is no primary key or unique constraint

RE: [sqlalchemy] Multiple sessions and data conflicts.

2011-12-19 Thread Jackson, Cameron
Of Michael Bayer Sent: Tuesday, 20 December 2011 2:07 AM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Multiple sessions and data conflicts. On Dec 19, 2011, at 1:04 AM, Jackson, Cameron wrote: OK, I think I understand. Just to make sure, how about this example: from SomeModule im

RE: [sqlalchemy] Multiple sessions and data conflicts.

2011-12-18 Thread Jackson, Cameron
hemy] Multiple sessions and data conflicts. On Dec 18, 2011, at 8:25 PM, Jackson, Cameron wrote: Here is a simplified version of my scenario: My application has two session objects. One is being used for editing certain data, and the other is reading this data, doing some calculations, and displ

[sqlalchemy] Multiple sessions and data conflicts.

2011-12-18 Thread Jackson, Cameron
Here is a simplified version of my scenario: My application has two session objects. One is being used for editing certain data, and the other is reading this data, doing some calculations, and displaying the results. I've set up a callback kind of system so that whenever the first session does

RE: [sqlalchemy] Suggestion: Should relationship's order_by parameter default to id?

2011-12-15 Thread Jackson, Cameron
27;t necessarily know what that's talking about, also what is the "callable function"? in that case it just needs an example.What do i put in the python-evaluable string ? etc. On Dec 16, 2011, at 12:19 AM, Jackson, Cameron wrote: It's listed with all the oth

RE: [sqlalchemy] Suggestion: Should relationship's order_by parameter default to id?

2011-12-15 Thread Jackson, Cameron
think there was one not sure where it went.... On Dec 15, 2011, at 11:36 PM, Jackson, Cameron wrote: Yeah, when I said 'id', I guess I really meant the primary key. All of your arguments make perfect sense. Consider my mind change, it's better how it is now! In that case,

RE: [sqlalchemy] Suggestion: Should relationship's order_by parameter default to id?

2011-12-15 Thread Jackson, Cameron
alchemy] Suggestion: Should relationship's order_by parameter default to id? On Dec 15, 2011, at 10:15 PM, Jackson, Cameron wrote: I was just having a problem with a one-to-many relationship array coming out in the wrong order. Looking here<http://www.sqlalchemy.org/docs/orm/relationship

[sqlalchemy] Suggestion: Should relationship's order_by parameter default to id?

2011-12-15 Thread Jackson, Cameron
I was just having a problem with a one-to-many relationship array coming out in the wrong order. Looking here, It wasn't too hard to figure out that I needed to do: myFoos = relationship(Foo, order_by = Foo.id) I was

RE: [sqlalchemy] SQLAlchemy emitting INTEGER instead of SERIAL- postgres sequence isn't created

2011-12-06 Thread Jackson, Cameron
widget_id==Entry.widget_id, foreign_keys=Entry.widget_id) favorite_entry = relationship(Entry, primaryjoin= favorite_entry_id==Entry.entry_id, foreign_k

RE: [sqlalchemy] SQLAlchemy emitting INTEGER instead of SERIAL- postgres sequence isn't created

2011-12-06 Thread Jackson, Cameron
PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] SQLAlchemy emitting INTEGER instead of SERIAL- postgres sequence isn't created On Dec 6, 2011, at 8:02 PM, Jackson, Cameron wrote: For the background to the code I'm using, see this Stack Overflow question: http://stackove

[sqlalchemy] SQLAlchemy emitting INTEGER instead of SERIAL- postgres sequence isn't created

2011-12-06 Thread Jackson, Cameron
For the background to the code I'm using, see this Stack Overflow question: http://stackoverflow.com/questions/8394177/complex-foreign-key-constraint-in-sqlalchemy/8408659 My declarative code looks like this: from MyGlobals import Base from sqlalchemy import Column, Integer, String, Fore

RE: [sqlalchemy] Complex foreign key constraint

2011-12-06 Thread Jackson, Cameron
Re: [sqlalchemy] Complex foreign key constraint yes, I had an intuition that a composite FK could do it as I've seen that approach before, but I couldn't figure it out. we have test coverage for cases exactly like that as well and I think I may even add this to the docs. On Dec 6,

RE: [sqlalchemy] Complex foreign key constraint

2011-12-05 Thread Jackson, Cameron
p.com.au> | www.thalesgroup.com.au<http://www.thalesgroup.com.au> From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On Behalf Of Jackson, Cameron Sent: Tuesday, 6 December 2011 1:29 PM To: sqlalchemy@googlegroups.com Subject: RE: [sqlalchemy] Complex foreign key constr

RE: [sqlalchemy] Complex foreign key constraint

2011-12-05 Thread Jackson, Cameron
r 2011 1:13 PM To: sqlalchemy@googlegroups.com Subject: Re: [sqlalchemy] Complex foreign key constraint On Dec 5, 2011, at 7:40 PM, Jackson, Cameron wrote: I have two tables, SystemVariables and VariableOptions. SystemVariables is self-explanatory, and VariableOptions contains all of the possible value

[sqlalchemy] Complex foreign key constraint

2011-12-05 Thread Jackson, Cameron
I have two tables, SystemVariables and VariableOptions. SystemVariables is self-explanatory, and VariableOptions contains all of the possible values for all of the variables. VariableOptions has a foreign key, variable_id, which states which variable it is an option for. SystemVariables has a f

RE: [sqlalchemy] Passing additional arguments to event listeners ?

2011-12-01 Thread Jackson, Cameron
Not sure if this helps or not, but how about using a lambda that that calls your function with the arguments you want? This is the solution I've been using for passing arguments to wxPython event handlers. This tutorial might help: http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks

RE: [sqlalchemy] Trouble getting started with SQLAlchemy on Jython

2011-11-17 Thread Jackson, Cameron
Hmmm. I have a Windows machine on my desk, and the only linux boxes I have access to (through SSH) don't have internet access. So I browsed to the link you had in the hg clone command, and downloaded from the zip file at the left of the page. I then extracted and copied the contents onto a linu