[sqlalchemy] Re: How to disable Foreign Keys to clear database

2012-08-17 Thread GHZ
There is a recipe for dropping FK constraints: http://www.sqlalchemy.org/trac/wiki/UsageRecipes did you find that? In addition, if you wanted to keep the FKs enabled, there is an example here using Metadata.sorted_tables, to get the table list in dependency order.

[sqlalchemy] Re: Retrive datetime attributes

2012-06-21 Thread GHZ
Here is code that works for me: from datetime import datetime from sqlalchemy import Column, DateTime, Integer, create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite://', echo=True) Base =

[sqlalchemy] Re: The Minimalists' strategy for SQLAlchemy.

2011-04-30 Thread GHZ
You can reflect once, then cache the metadata (e.g. pickle it) then I think you can use autoload with usexisting On Apr 30, 12:13 am, Kuze kuze.to...@gmail.com wrote: I'm aware SQLAlchemy provides a comprehensive package for creating database objects (tables, indexes, etc.) with a simple

[sqlalchemy] Re: Side by side versions on one machine.

2011-04-26 Thread GHZ
Try virtualenv http://pypi.python.org/pypi/virtualenv On Apr 26, 2:31 pm, Mathieu Tozer math...@madebysofa.com wrote: Is it possible to have multiple installation versions on the one machine? I don't want to screw with my dev environment too much but want to try migrating up. -- You

[sqlalchemy] Re: Create a one-to-many relationship using association object with two foreign key primary keys

2011-04-14 Thread GHZ
Looks like you need to specify a composite ForeignKey http://www.sqlalchemy.org/docs/core/schema.html?highlight=foreign_keys#sqlalchemy.schema.ForeignKeyConstraint comment_table = Table('comment',metadata, Column('id',Integer,primary_key=True), Column('package_id', Integer),

[sqlalchemy] Re: Setting column value that changes everyday

2011-03-01 Thread GHZ
Hi, Do you need to store expiry_code? seeing as it is a function of last_con and the current date. class PhNumber(Base): __tablename__ = 'ph_numbers' ph_no = Column(Integer, nullable=False) last_con = Column(DateTime, nullable=False) @property def expiry_code(self): msg = 'Expired

[sqlalchemy] Re: The right way to clear database of content?

2011-02-15 Thread GHZ
GHZ, it did work! Wondering about one thing though; the recipe in the documentation iterates over the tables in reverse sorted order, like so: for table in reversed(meta.sorted_tables) Do you know what this would be good for (since your code does not care about the table order)? Arve

[sqlalchemy] Re: The right way to clear database of content?

2011-02-14 Thread GHZ
maybe it needs to be in a transaction: con = engine.connect() trans = con.begin() for name, table in meta.tables.items(): print table.delete() con.execute(table.delete()) trans.commit() On Feb 14, 1:29 pm, Arve Knudsen arve.knud...@gmail.com wrote: Hi What's the right way to

[sqlalchemy] prevent extra selects to get default values

2010-06-21 Thread GHZ
Hi, If I create a table with a default. create table T (id number primary key, data number default NULL) Then reflect this table. then using the ORM I trigger an insert, but only into the id column and flush() then I try to access the 'data' attribute this causes a select, to get the actual

[sqlalchemy] Re: prevent extra selects to get default values

2010-06-21 Thread GHZ
AS t_data FROM t WHERE t.id = :param_1 2010-06-21 11:41:46,215 INFO sqlalchemy.engine.base.Engine.0x...84ec {'param_1': 1} On 21 Jun, 11:40, GHZ geraint.willi...@gmail.com wrote: Hi, If I create a table with a default. create table T (id number primary key, data number default NULL

[sqlalchemy] Re: help please

2010-06-10 Thread GHZ
you should access column names via lower case i.e. columns = 'projectid', 'program', 'progmanger'] On 10 Jun, 03:39, Aref arefnamm...@gmail.com wrote: Hello All, I just began learning sqlalchemy and am not quite used to it yet so please excuse my ignorance and which might be a trivial

[sqlalchemy] Re: Starting with SQLAlchemy and Oracle: Reflection question

2010-05-25 Thread GHZ
you can check for primary key constraints using: select table_name, constraint_name from user_constraints where constraint_type = 'P' the orm will need to know the primary keys, but if they do not exist in the schema, you can set them when you reflect the table t = Table('t1', meta,

[sqlalchemy] Re: adding a Sequence link to a reflected table

2010-05-17 Thread GHZ
suggest seeing what happens if you take an existing table and just say table.c.id.default = Sequence(some_sequence), which should do the job but im not 100% sure. On May 12, 2010, at 5:47 AM, GHZ wrote: Hi, Can I make the second form (metadata.reflect, then Table with useexising=True

[sqlalchemy] adding a Sequence link to a reflected table

2010-05-12 Thread GHZ
Hi, Can I make the second form (metadata.reflect, then Table with useexising=True), result in the same insert statement as the first form (Table with autoload=True)? Thanks. from sqlalchemy import create_engine, Table, Column, Sequence, MetaData, Integer engine =

[sqlalchemy] mixing metaclass with redefining the primary key of an autoloaded table

2010-05-10 Thread GHZ
Hi, Using plain Declarative, I am able to redefine a primary key column that has been autoloaded, so that I can link it to an oracle sequence and give it a new name: Id = Column('id', Integer, Sequence('table_sq'), primary_key=True) However, if I then try to add some methods to the class using

[sqlalchemy] Re: TypeError: synonym() got an unexpected keyword argument

2010-04-14 Thread GHZ
Hi, http://www.sqlalchemy.org/changelog/CHANGES_0_6beta3 * 'proxy' argument on synonym() is removed. This flag did nothing throughout 0.5, as the proxy generation behavior is now automatic. On 14 apr, 13:16, jose soares jose.soa...@sferacarta.com wrote: Hi all, seems

[sqlalchemy] Specifying Alternate Join Conditions to relation()

2009-07-15 Thread GHZ
using 5.5 from sqlalchemy import create_engine, Table, Column, ForeignKeyConstraint, MetaData, and_, String, Integer, ForeignKey from sqlalchemy.orm import relation, sessionmaker, synonym, join from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite:///:memory:')

[sqlalchemy] globaly convert existing types

2009-07-10 Thread GHZ
I'm reflecting an existing schema with autoload=True All strings are stored as fixed length, which I need to strip() Is there a way of converting all attributes of an existing type? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the

[sqlalchemy] Re: insert and joined mappers

2009-05-05 Thread GHZ
try : m = mapper(MyJoin, a_table.join(b_table), properties={ 'a_id' : [Table_a.__table__.c.id, Table_b.__table__.c.a_id] }) from: http://www.sqlalchemy.org/docs/05/mappers.html#mapping-a-class-against-multiple-tables On May 5, 11:46 am, Alessandro Dentella san...@e-den.it wrote: Hi,

[sqlalchemy] association_proxy with association object - declarative

2009-04-25 Thread GHZ
I tried to use the example from: http://www.sqlalchemy.org/docs/05/reference/ext/associationproxy.html#simplifying-association-object-relations But with declarative syntax. Any idea why this is going wrong? from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, Sequence,

[sqlalchemy] association_proxy question

2009-02-06 Thread GHZ
I am trying to use the association_proxy for attributes that link to tables containing mostly static data e.g. my static data is: COUNTRY COUNTRY.CODE COUNTRY.NAME and the data I am changing is: USER USER.COUNTRY_CODE I use the association_proxy as I want to be able to say: user = User()

[sqlalchemy] Re: Need SqlAlchemy Model Advice for a table with many foreign keys.

2009-02-04 Thread GHZ
Don't know if this will work in your case.. but to handle joins to so many static tables. Note.. I didn't need to update these tables, nor query from them back to the data tables. (i.e. no need to call Gender.member_profiles()) I did something like the following: class MemberProfile(Base):

[sqlalchemy] Re: joining to child, and using child in relation

2009-01-29 Thread GHZ
to a join and just modify your Subscriber class to break up the addresses collection amongst a proxy of the MAIN element and a list of the remaining elements.  an attribute_mapped_collection could help to accomplish this nicely. On Jan 28, 2009, at 7:22 PM, GHZ wrote: I have

[sqlalchemy] joining to child, and using child in relation

2009-01-28 Thread GHZ
I have a subscriber and address table. a subscriber will have one and only one 'MAIN' address. I want the subscriber and MAIN address to be represented by one class 'Subscriber'. However, I want that class to have a collection 'addresses' which contains other addresses (e.g. old addresses) -

[sqlalchemy] find only loaded objects in relation collections

2009-01-27 Thread GHZ
Hi, I have a Subscriber and an Address table. Subscriber can have many Addresses mapper(Subscriber, subscriber_table, properties={ 'addresses' : relation(Address, collection_class=Addresses, backref='customer')}) From the a Subscriber object, I want to inspect all loaded objects in any

[sqlalchemy] expunge_all and statement caching - Oracle

2008-11-12 Thread GHZ
Hi, I am using SQLA for reading from a database. I modify the objects to use in my code, but don't want to write anything back to the database. therefore I call: session.expunge_all() , before reading the next set of data. This works, but it results in the select statements being re-parsed by

[sqlalchemy] Re: setting table and mapper arguments with Declarative

2008-09-23 Thread GHZ
On Sep 18, 2:59 pm, Michael Bayer [EMAIL PROTECTED] wrote: Well, I would think __table_args__ is the only argument you'd really   want to propigate in that way, and this is an inconvenience I've also   had so perhaps we'll do something about it...I would propose a   default_table_args keyword

[sqlalchemy] Re: grandparent id relation

2008-09-19 Thread GHZ
On Sep 18, 2:54 pm, Michael Bayer [EMAIL PROTECTED] wrote: 2. more involved: catch change events and populate a Child.grandparent   relation().   0.5 has made the AttributeExtension API public which   would be a good place to catch this event.  The advantage to this is   that your Child has a

[sqlalchemy] RETURNING clause on Insert (Oracle sequences)

2008-09-18 Thread GHZ
Hi, Is there a reason why this is not used to return the id column value? Would cut down on the number of roundtrips for insert statements e.g. insert into bob (id) values (bob_sq.nextval) returning id into :id rather than what seems to be happening at the moment: select bob_sq.nextval from

[sqlalchemy] setting table and mapper arguments with Declarative

2008-09-18 Thread GHZ
I want to set table, mapper arguments automatically. The following is the only way I have found to do this. Is this supported? Am I wasting my time with Declarative and should rather use the non declarative if I want this control? class MyMeta(DeclarativeMeta): def __new__(meta, classname,

[sqlalchemy] Re: RETURNING clause on Insert (Oracle sequences)

2008-09-18 Thread GHZ
Thank you Michael, I found the changeset adding this to Postgresql. Will look into a similar change for Oracle. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to

[sqlalchemy] simple Extract, Transform pattern needed

2008-09-10 Thread GHZ
I am thinking about moving from home grown data access classes, to sqlalchemy for a simple ETL tool for moving from legacy databases - at least for the Extract and simplest of Transformations. Example of what I'm trying to achieve.. if I have a customer table in the legacy database, and a

[sqlalchemy] Re: simple Extract, Transform pattern needed

2008-09-10 Thread GHZ
Figured it out. slight issue with documentation confused me http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative 'instruments' should read 'descriptor'? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google

[sqlalchemy] Re: simple Extract, Transform pattern needed

2008-09-10 Thread GHZ
now I have a real question based on example 1 above. i.e. wanting an object with the following attributes: customer.o_cutype customer.id customer.type (converted from cutype through mapping function) from create table old_customer (cunr number, cutype char(1)); The following works: PREFIX