[sqlalchemy] Re: how to unit test with SQ

2007-12-18 Thread Paulino

Hello!

I have a similar error with SA 4.1.0 and turbogears.

session.query(Extrato).filter_by(bank='IF5',
data=datetime.datetime.strptime('2007/07/27','%Y/%m/%d'))
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.1-py2.5.egg/
sqlalchemy/orm/session.py, line 654, in query
q = self._query_cls(_class_mapper(mapper_or_class,
entity_name=entity_name), self, **kwargs)
  File /usr/lib/python2.5/site-packages/SQLAlchemy-0.4.1-py2.5.egg/
sqlalchemy/orm/mapper.py, line 1649, in class_mapper
raise exceptions.InvalidRequestError(Class '%s' entity name '%s'
has no mapper associated with it % (class_.__name__, entity_name))
InvalidRequestError: Class 'Extrato' entity name 'None' has no mapper
associated with it


But if I run the query outside the turbogears framework, it works
fine, no errors!

My model definition is:

from sqlalchemy import Table, Column, String, Integer, DateTime,
MetaData, create_engine
from sqlalchemy.orm import relation, mapper, create_session

mssql = create_engine('mssql://paulino:[EMAIL PROTECTED]/db')
metadata = MetaData()
metadata.bind = mssql
session = create_session(bind=mssql)

extratoTab = Table('ttfcmf201100', metadata,
   Column('t_bank', String(), primary_key=True),
   Column('t_nseq', Integer(), primary_key=True,
autoincrement=False),
   Column('t_dtmv', DateTime(), primary_key=True),
   Column('t_dtvl', DateTime(), primary_key=True),
   autoload=True)

class Extrato(object):
pass

mapper(Extrato, extratoTab)

what is going on?

thank you
Paulino
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Can't insert records into a MS SQL database

2007-10-06 Thread Paulino

Hello!

I'm using sqlalchemy v0.3.10 and connecting to an existing table in
MSSQL with pymssql from a windows box.

I'm able to update existing records, but I can't insert new ones. The
error message says: The current user is not the database or object
owner of table 'ttfvbs061100'. Cannot perform SET operation.

I can insert records with this user account from python with pymssql
in any database table, so it is not a permissions issue.

Thank you for any help!

Paulino


PS: Here is the script, the commands i sent from IDLE and the complete
traceback:


from sqlalchemy import *

db = create_engine('mssql://user:[EMAIL PROTECTED]/db')

metadata = BoundMetaData(db)

ppi = Table('ttfvbs061100', metadata,
Column('t_year', Integer, primary_key=True),
Column('t_dimx', String(), primary_key=True),
Column('t_ceco', String(), primary_key=True),
autoload = True)

class PPI(object):
def __repr__(self):
return %s%s%s %(self.t_dimx, self.t_ceco, self.t_desc)

ppimapper = mapper(PPI, ppi)
session = create_session()

 p = PPI()
 p.t_year = 2008
(...)
 session.save(p)
 session.flush()
Traceback (most recent call last):
  File pyshell#11, line 1, in module
session.flush()
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\session.py, line 319, in flush
self.uow.flush(self, objects)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\unitofwork.py, line 210, in flush
flush_context.execute()
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\unitofwork.py, line 400, in execute
UOWExecutor().execute(self, head)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\unitofwork.py, line 1018, in execute
self.execute_save_steps(trans, task)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\unitofwork.py, line 1032, in execute_save_steps
self.save_objects(trans, task)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\unitofwork.py, line 1023, in save_objects
task.mapper.save_obj(task.polymorphic_tosave_objects, trans)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\orm\mapper.py, line 1210, in save_obj
c = connection.execute(statement, params)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\engine\base.py, line 517, in execute
return Connection.executors[c](self, object, *multiparams,
**params)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\engine\base.py, line 557, in execute_clauseelement
return self.execute_compiled(elem.compile(dialect=self.dialect,
parameters=param), *multiparams, **params)
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\engine\base.py, line 567, in execute_compiled
context.pre_exec()
  File c:\python25\lib\site-packages\sqlalchemy-0.3.10-py2.5.egg
\sqlalchemy\databases\mssql.py, line 254, in pre_exec
self.cursor.execute(SET IDENTITY_INSERT %s ON %
self.dialect.preparer().format_table(self.compiled.statement.table))
  File C:\Python25\Lib\site-packages\pymssql.py, line 126, in
execute
self.executemany(operation, (params,))
  File C:\Python25\Lib\site-packages\pymssql.py, line 152, in
executemany
raise DatabaseError, internal error: %s % self.__source.errmsg()
DatabaseError: internal error: SQL Server message 8104, severity 16,
state 1, line 1:
The current user is not the database or object owner of table
'ttfvbs061100'. Cannot perform SET operation.
DB-Lib error message 10007, severity 5:
General SQL Server error: Check messages from the SQL Server.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Can't insert records into a MS SQL database

2007-10-06 Thread Paulino



 session.flush()
2007-10-06 21:56:08,953 INFO sqlalchemy.engine.base.Engine.0x..f0
BEGIN
2007-10-06 21:56:09,171 INFO sqlalchemy.engine.base.Engine.0x..f0
ROLLBACK
Traceback (most recent call last):
(...)


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---