[sqlalchemy] Re: Declaring compound primary key on reflective model

2011-06-13 Thread Cody Django
Thanks!

On Jun 10, 1:06 pm, A.M. age...@themactionfaction.com wrote:
 On Jun 10, 2011, at 2:25 PM, Cody Django wrote:

  Hi all -- I'm new on pylons, coming from a django background.  I'm
  working on a mapfish project.

  I'd like to autoload a model based on a db table, but in doing so I
  get the error could not assemble any primary key columns for mapped
  table.

  The table itself is a postgres view with no declared primary key
  column, so it makes sense that no primary key columns are detected.

  I figure it is possible to define which columns to use as the primary
  key in the __table_args__ dict, but I have yet to figure out exactly
  how.

  Tips, please!

 I do the same thing:

   newtable = Table(name,
                          meta,
                          *props,
                          autoload=True
                          )

 where props = ColumnCollection(Column('id',Integer,primary_key=True))

 SQLAlchemy overwrites the autoloaded info with the passed-in column info.

 Cheers,
 M

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-13 Thread Moshe C.
Hi,
I am using Sqlalchemy 0.6.5 .

How do I generate the following statement usin Sqlalchemy expressions
(not ORM).

DELETE FROM table ORDER BY timestamp LIMIT 10;

TIA

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-13 Thread Michael Bayer
That's a MySQL specific syntax you might be better off not using, perhaps you 
could say delete from table where id in (select id from table order by 
timestamp limit 10).

To get the exact statement, it's probably easiest just to emit the string SQL.  
If you wanted the sqlalchemy.sql.delete() construct to do it you'd need to 
subclass Delete, add order_by() and limit() to it, and augment its compilation 
as described in http://www.sqlalchemy.org/docs/core/compiler.html


On Jun 13, 2011, at 10:10 AM, Moshe C. wrote:

 Hi,
 I am using Sqlalchemy 0.6.5 .
 
 How do I generate the following statement usin Sqlalchemy expressions
 (not ORM).
 
 DELETE FROM table ORDER BY timestamp LIMIT 10;
 
 TIA
 
 -- 
 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 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 sqlalchemy@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: Odd behaviour of echo flag

2011-06-13 Thread Vinay Sajip
Forgot to mention - this happens with SQLAlchemy versions 0.6.7 and
0.6.8.

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Odd behaviour of echo flag

2011-06-13 Thread Vinay Sajip
Thanks for the detailed explanation, Mike. It makes complete sense - I
missed the fact that a new Connection was being created under the hood
at different times in the two different scenarios.

Regards,

Vinay Sajip

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Deferred loader for attribute for Table having large number of columns.

2011-06-13 Thread pavi ena
Hello,

I am using SQLAlchemy-0.7.1 and i am facing Deferred loader for attribute
Error while trying to access the table columns in my code.

I have table with huge number of columns around 200 fields and i have
defined the schema and entity with hybrid declarative_base approach as
below.
I have some sample testcases to assert newly inserted values in db with
normal python assert statements. When i run my sample test cases i am
getting
following error:

   KeyError: Deferred loader for attribute 'is_updated' failed to populate
correctly

Below is my code example due to large number of columns i have not defined
entire db Table definition here.

test_table = Table(test_table, metadata,
Column('test_table_idn', Integer, primary_key=True),
Column('test_parent_table_idn', Float, ForeignKey('parent_table_idn')),
Column('name', String(10)),
Column('is_exported', Integer),
.
.
. #Other columns go here.
. #Other columns go here.
. #Other columns go here.
.
.
.
Column('is_updated', Integer)
)

class TestTable(Base):


___table___ =  test_table

def set_all_other_attribs(self, **kwargs):
#Common method to set other column attributes.
for key, value in kwargs:
self.key = value


class TestTableInserts(TestCase):
def setUp():


self.session = will get session object

def test_run(self):
tbl_obj = TestTable()
dict_to_set(name='test',is_exported=1,.is_updated=1)
tbl_obj.set_all_other_attribs(dict_to_set)
self.session.add(tbl_obj)
self.session.commit()

#Now trying to assert the records in test_table
result = self.session.query(TestTable).filter(name ==
'test').first()

assert result.name == 'test'
assert result. http://result.name/user_access == 1
assert result. http://result.name/web_addr == 'www.myweb.org'
assert result.is_updated == 1
#When i tryied to assert the above is_updated column i am getting
#KeyError: Deferred loader for attribute 'is_updated' failed to
populate correctly

def tearDown(self):
self.session.execute('delete from test_table')
self.session.close()


 File /var/dev/SA/SampleTest/test_sample/test_insert.py, line 79, in
test_run
  assert result.is_updated == 1
 File
/var/dev/SA/SampleTest/eggs/SQLAlchemy-0.7.1-py2.6-linux-i686.egg/sqlalchemy/orm/attributes.py,
line 170, in __get__
   return self.impl.get(instance_state(instance),dict_)
 File
/var/dev/SA/SampleTest/eggs/SQLAlchemy-0.7.1-py2.6-linux-i686.egg/sqlalchemy/orm/attributes.py,
line 439, in get
correctly % key)
KeyError: Deferred loader for attribute 'is_updated' failed to populate
correctly

Please suggest to me fix this error.

Just a thought is this error is raised for following reasons.

1. If table column name length is more than 30 chars.
2. If table has large number of columns defined.

Thanks,

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Deferred loader for attribute for Table having large number of columns.

2011-06-13 Thread Michael Bayer

On Jun 13, 2011, at 10:28 AM, pavi ena wrote:

 Hello,
 
 I am using SQLAlchemy-0.7.1 and i am facing Deferred loader for attribute 
 Error while trying to access the table columns in my code.
 
 I have table with huge number of columns around 200 fields and i have defined 
 the schema and entity with hybrid declarative_base approach as below.
 I have some sample testcases to assert newly inserted values in db with 
 normal python assert statements. When i run my sample test cases i am getting
 following error:

KeyError: Deferred loader for attribute 'is_updated' failed to populate 
 correctly

 Below is my code example due to large number of columns i have not defined 
 entire db Table definition here.
 
 Please suggest to me fix this error.

would need a reproducing test case, it suggests something to do with the 
mechanics of the table but its not clear nor is it an issue seen before.

 
 Just a thought is this error is raised for following reasons.
 
 1. If table column name length is more than 30 chars.

is_updated doesn't appear to be more than 30 characters to me.  Did you 
create a test that sees if this is the case ?

 2. If table has large number of columns defined.

Did you create a test with a fewer number of columns in a table to see if this 
is the case ?


-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: What is the Sqlalchemy syntax for having ORDER BY and LIMIT on DELETE

2011-06-13 Thread Moshe C.
What is the syntax for the where id in (select ... )  ?

On Jun 13, 5:17 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 That's a MySQL specific syntax you might be better off not using, perhaps you 
 could say delete from table where id in (select id from table order by 
 timestamp limit 10).

 To get the exact statement, it's probably easiest just to emit the string 
 SQL.  If you wanted the sqlalchemy.sql.delete() construct to do it you'd need 
 to subclass Delete, add order_by() and limit() to it, and augment its 
 compilation as described inhttp://www.sqlalchemy.org/docs/core/compiler.html

 On Jun 13, 2011, at 10:10 AM, Moshe C. wrote:







  Hi,
  I am using Sqlalchemy 0.6.5 .

  How do I generate the following statement usin Sqlalchemy expressions
  (not ORM).

  DELETE FROM table ORDER BY timestamp LIMIT 10;

  TIA

  --
  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 email to 
  sqlalchemy+unsubscr...@googlegroups.com.
  For more options, visit this group 
  athttp://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 sqlalchemy@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] how to get model class from CachingQuery

2011-06-13 Thread virhilo
Hello
There is a way to get model class from CachingQuery instance?
Thanks for help

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Conditional insert in one transaction

2011-06-13 Thread Moch Ramis
Hello.

I am trying to create a transaction that should insert a value
depending of the result of a select. This should be done at once by
the database in order to avoid some conflicts or duplicates.
An equivalent sql version of the transaction would be :

IF EXISTS (SELECT * FROM Table1 WHERE Column1='SomeValue')
INSERT INTO Table1 VALUES (...)

Is there a way to do that using sqlalchemy ?
Having the if done by python is easy but not safe and i can't find
out how to do this using some begin/commit statements.

Thanks to help !

-- 
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 email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.