sqlalchemy

sqlalchemy Oracle REF CURSOR

Hi I am using sqlalchemy for connection pooling only (need to call existing procs) and want to return a REF CURSOR which is an out parameter. There seems to be no cursor in sqlalchemy to do this. Any advice greatly appreciated. ...

How do I Handle Database changes and port my data?

Example, for web applications using Turbogears and SQLAlchemy. Every time I update my data model, I need to delete my database and recreate it. Is there an easy way to update the production database? Do I have to write a custom script that transfers all the production data into a new database model? Or is there an easier way to upgra...

SQLAlchemy, self-referential secondary table association

I'm trying to create a "Product" object in SQLAlchemy and so far I have gotten everything working accept the Product's "accessories". What I have is a Product with a list of field/value pairs (ie. Capacity : 12 L etc.), and integer ID and a catalog number. I would like to be able to associate certain "accessories" with a given product wh...

SQLAlchemy - ObjectDeletedError: Instance '<Class at...>' has been deleted. Help.

I'm having some issues with deleting rows from a database and then adding new ones. Here's the code: for positionid in form_result['responsibilities']: inputdata = form_result['responsibilities'][positionid] self.__deleterow(dbmyaccount.Responsibilities, session['authed']['userid']) for resp in (i.strip() for i in inputdata...

How to get specified columns with result as array of table class objects?

Hello. I have simple problem. In my table have columns ID, NAME, CONTENT, TIMESTAMP. If i use session.query(table).all() result is array of table class objects. So i have no problem with modify one or more objects and update, or use this objects in associations. But i need only columns ID and NAME. If use session.query(table.id, table.n...

sqlalchemy - double polymorphic inheritance problem

Hi, I've got a class mapping with two polymorphic inheritance : #test classes class AbstractA(Base): __tablename__ = "abstract_a" id = Column(Integer, primary_key=True) class_name = Column('class_name', String(50)) __mapper_args__ = { 'polymorphic_on': class_name, } #some stuff here class AbstractB(Abs...

SqlAlchemy: create object if does not exist already?

I'm new to SQLAlchemy. I currently have: ev = model.EnumerationValue(key=key_level_2, code=level_2) ev.keyvalues[key_parent] = level_1 model.Session.add(ev) How can I change this so it only adds the object if it doesn't already exist? This would be nice... model.Session.create_if_does_not_exist(ev) Thanks! ...

How to filter columns in two tables with many-to-many relation?

Hello, I have this table: channel_items = Table( "channel_items", metadata, Column("channel_id", Integer, ForeignKey("channels.id")), Column("media_item_id", Integer, ForeignKey("media_items.id")) ) class Channel(rdb.Model): """Set up channels table in the database""" rdb.metadata(metadata) ...

pivot tables in database with sqlalchemy

I need a database that support pivots to get pivot columns with sqlalchemy, something like that: # find all possible values of the pivot pivot_values = map( operator.itemgetter(0), select([pivot_on], from_obj=[report]).distinct().execute() ) # build the new pivot columns new_columns = [ pivot_func(case([(pivot_on == value, ...

SQLAlchemy ProgrammingError - how to debug?

I'm using SQLAlchemy 0.5.8, and seeing this error: ProgrammingError: (ProgrammingError) can't adapt 'INSERT INTO enumeration_value (id, key_id, code, name, notes) VALUES (%(id)s, %(key_id)s, %(code)s, %(name)s, %(notes)s)' {'key_id': 'aac6fc29-4ccd-4fe4-9118-cfbbd04449fe', 'notes': '', 'code': (u'Barnet',), 'id': 'd0540c97-882e-4a5b-b...

Controlling the instantiation of python object

My question does not really have much to do with sqlalchemy but rather with pure python. I'd like to control the instantiation of sqlalchemy Model instances. This is a snippet from my code: class Tag(db.Model): __tablename__ = 'tags' query_class = TagQuery id = db.Column(db.Integer, primary_key=True) name = db.Column(d...

Inserting Encrypted Data in Postgres via SQLALchemy

Hi, I want to encrypt a string using RSA algorithm and then store that string into postgres database using SQLAlchemy in python. Then Retrieve the encrypted string and decrypt it using the same key. My problem is that the value gets stored in the database is not same as the actual encrypted string. The datatype of column which is storin...

How to get read-only objects from database?

Hello, I'd like to query the database and get read-only objects with session object. I need to save the objects in my server and use them through the user session. If I use a object outside of the function that calls the database, I get this error: "DetachedInstanceError: Parent instance is not bound to a Session; lazy load operation o...

Avoiding socket timeouts in SQLAlchemy

I'm new to SQLAlchemy, but I'm trying to use it to create and fill a database for a personal project. I've set pool_timeout to 43200 (twelve hours), but I'm still getting socket timeouts. engine = sqlalchemy.create_engine( 'postgresql+pg8000://gdwatson:pass@localhost/dbname', pool_timeout=43200) db.tables.meta.d...

How do I set the transaction isolation level in SQLAlchemy for PostgreSQL?

We're using SQLAlchemy declarative base and I have a method that I want isolate the transaction level for. To explain, there are two processes concurrently writing to the database and I must have them execute their logic in a transaction. The default transaction isolation level is READ COMMITTED, but I need to be able to execute a piece ...

How to deploy a Python/SQLAlchemy application?

Dear all: SQLAlchemy allowed me to create a powerful database utility. Now I don't know how to deploy it. Let me explain how is it built with an example: # objects.py class Item(object): def __init__(self, name): self.name = name # schema.py from sqlalchemy import * from objects import Item engine=create_engine('sqlite:///mydb.db')...

Unique constraint using data in multiple tables (SQL / SQLAlchemy)

A top class called Parametric is used to create objects which can have parameters associated with them: class Parametric(object): def __init__(self, name): self.name = name self.pars = [] class Foo(Parametric): def __init__(self, name, prop): self.prop = prop Parametric.__init__(self, name) class Bar(Parametric): def __init...

SQLAlchemy duplicate table, rename table?

All, This is a snippet from internet repersent the database table will be used: >>> from sqlalchemy import Table,Column,Integer,String,MetaData,ForeignKey >>> metadata=MetaData() >>> users_table=Table('users',metadata, Column('id',Integer,primary_key=True), Column('name',String), Column('fullname',String),...

Look for an example application of "pylons + sqlalchemy"

I'm new to python, and starting to learn website development with pylons and sqlalchemy. I've read the document of sqlalchemy and pylons, but still have a lot of problems. I've tried 2 days, but a simple website with basic CRUD operations can't work yet. I met some big problems(for me), that the circular imports problem, and relationsh...

How to declared one-to-many if there are 2 fields for a same foreign key

I'm new to python(sqlalchemy), and I'm learning to build web site with pylons and sqlalchemy. I have a problem when I declare the relationship between models. I've tried it several hours, but failed. But I think it should be a basic question. I have two classes: User and Article, user can create articles, and modified the other people...