[sqlalchemy] needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

Trying to find out if I hit a bug or it is me doing something wrong.
Using version 0.4.6

when creating an object and then calling session.save() I get:
Instance 'res...@-0x486e4074' is already persistent

It works save_or_update() with, but I don't see why I should use that.

I did read that using session.mapper can cause this but I use
orm.mapper.

Here is the mapping code:


metadata = sa.MetaData()
sm = orm.sessionmaker(autoflush=True, transactional=True,
bind=engine)

Model.session = orm.scoped_session(sm)

person_table = sa.Table('person', metadata, autoload = True,
autoload_with=engine)
person_relative_table = sa.Table('person_relative', metadata,
autoload = True, autoload_with=engine)
resume_table = sa.Table('resume', metadata, autoload = True,
autoload_with=engine)
workplace_table = sa.Table('workplace', metadata, autoload =
True, autoload_with=engine)
resume_workplace_table = sa.Table('resume_workplace',
metadata, autoload = True, autoload_with=engine)

orm.mapper(self.Person, person_table, properties = {
'relatives' : orm.relation(self.Person,
secondary=person_relative_table,
 
primaryjoin=person_table.c.id==person_relative_table.c.person_id,
 
secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
 backref='followers'),
'resumes' : orm.relation(self.Resume, backref='person')
}
   )
orm.mapper(self.Resume, resume_table, properties = {
'workplaces' : orm.relation(self.Workplace,
secondary=resume_workplace_table, backref='resumes')
}
   )
orm.mapper(self.Workplace, workplace_table)



--~--~-~--~~~---~--~~
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: deletes using association_proxy

2009-06-03 Thread Michael Bayer

hollister wrote:


 # mappers
 mapper(Keyphrase, keyphrase_table)
 mapper(Action, action_table)

 mapper(KeyphraseAction, keyphrase_action_table, properties={
 'keyphrase': relation(Keyphrase,
 backref = 'keyphrase_action'),
 'action': relation(Action),
 })

 # test
 for i, action in enumerate(kp.actions):
 print action.action_name
 kp.actions.remove(action)   # this fails!

 s.commit()

you need to configure cascade so that SQLA knows to delete a
KeyphraseAction when it is deassociated from a Keyphrase.  See the mapping
docs for information on delete cascade.


--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

Moshe C. wrote:

 Trying to find out if I hit a bug or it is me doing something wrong.
 Using version 0.4.6

 when creating an object and then calling session.save() I get:
 Instance 'res...@-0x486e4074' is already persistent

 It works save_or_update() with, but I don't see why I should use that.

 I did read that using session.mapper can cause this but I use
 orm.mapper.


session.save() is only used to persist transient instances.   It is
deprecated (as is update() and save_or_update())  and not present in
version 0.5.   Upgrade to at least 0.4.8 if not 0.5 and use session.add()
(equivalent to save_or_update()), which eliminates the need for the user
to distinguish between transient and detached instances.  For a
description of what the heck im talking about when i say transient and
detached see
http://www.sqlalchemy.org/docs/05/session.html#quickie-intro-to-object-states
.




 Here is the mapping code:


 metadata = sa.MetaData()
 sm = orm.sessionmaker(autoflush=True, transactional=True,
 bind=engine)

 Model.session = orm.scoped_session(sm)

 person_table = sa.Table('person', metadata, autoload = True,
 autoload_with=engine)
 person_relative_table = sa.Table('person_relative', metadata,
 autoload = True, autoload_with=engine)
 resume_table = sa.Table('resume', metadata, autoload = True,
 autoload_with=engine)
 workplace_table = sa.Table('workplace', metadata, autoload =
 True, autoload_with=engine)
 resume_workplace_table = sa.Table('resume_workplace',
 metadata, autoload = True, autoload_with=engine)

 orm.mapper(self.Person, person_table, properties = {
 'relatives' : orm.relation(self.Person,
 secondary=person_relative_table,

 primaryjoin=person_table.c.id==person_relative_table.c.person_id,

 secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
  backref='followers'),
 'resumes' : orm.relation(self.Resume, backref='person')
 }
)
 orm.mapper(self.Resume, resume_table, properties = {
 'workplaces' : orm.relation(self.Workplace,
 secondary=resume_workplace_table, backref='resumes')
 }
)
 orm.mapper(self.Workplace, workplace_table)



 



--~--~-~--~~~---~--~~
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: deletes using association_proxy

2009-06-03 Thread Hollister

Mike, thanks for the quick reply.
I suspected it was a cascade issue, and have been through the docs and
tried various configs. At the risk of appearing stupid, can you point
me in the right direction? Do the cascades only need to be on the
association table, or also on the left  right parent tables? If a
parent (Keyphrase or Action) is deleted, then I want the delete to
cascade to the association (KeyphraseAction), but not vice versa.

On Jun 3, 10:26 am, Michael Bayer mike...@zzzcomputing.com wrote:
 hollister wrote:

  # mappers
  mapper(Keyphrase, keyphrase_table)
  mapper(Action, action_table)

  mapper(KeyphraseAction, keyphrase_action_table, properties={
          'keyphrase': relation(Keyphrase,
              backref = 'keyphrase_action'),
          'action': relation(Action),
      })

  # test
  for i, action in enumerate(kp.actions):
      print action.action_name
      kp.actions.remove(action)   # this fails!

  s.commit()

 you need to configure cascade so that SQLA knows to delete a
 KeyphraseAction when it is deassociated from a Keyphrase.  See the mapping
 docs for information on delete cascade.
--~--~-~--~~~---~--~~
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: deletes using association_proxy

2009-06-03 Thread Michael Bayer

cascades work from the parent that is being deleted or is having a child
removed to the child that is dependent on being attached to its parent.

so in this case Keyphrase-KeyphraseAction and Action-KeyPhraseAction
both in theory need delete, delete-orphan cascade.

In addition you can specify cascades in the database too in your foreign
keys by adding ON UPDATE DELETE to your ForeignKey entries (assuming you
are creating the schema with your table definitions).



Hollister wrote:

 Mike, thanks for the quick reply.
 I suspected it was a cascade issue, and have been through the docs and
 tried various configs. At the risk of appearing stupid, can you point
 me in the right direction? Do the cascades only need to be on the
 association table, or also on the left  right parent tables? If a
 parent (Keyphrase or Action) is deleted, then I want the delete to
 cascade to the association (KeyphraseAction), but not vice versa.

 On Jun 3, 10:26 am, Michael Bayer mike...@zzzcomputing.com wrote:
 hollister wrote:

  # mappers
  mapper(Keyphrase, keyphrase_table)
  mapper(Action, action_table)

  mapper(KeyphraseAction, keyphrase_action_table, properties={
          'keyphrase': relation(Keyphrase,
              backref = 'keyphrase_action'),
          'action': relation(Action),
      })

  # test
  for i, action in enumerate(kp.actions):
      print action.action_name
      kp.actions.remove(action)   # this fails!

  s.commit()

 you need to configure cascade so that SQLA knows to delete a
 KeyphraseAction when it is deassociated from a Keyphrase.  See the
 mapping
 docs for information on delete cascade.
 



--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

Thanks.
Given that I am not going to upgrade very soon, is it right to
conclude that there was a bug in 0.4.6, or is my usage wrong?


On Jun 3, 5:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Trying to find out if I hit a bug or it is me doing something wrong.
  Using version 0.4.6

  when creating an object and then calling session.save() I get:
  Instance 'res...@-0x486e4074' is already persistent

  It works save_or_update() with, but I don't see why I should use that.

  I did read that using session.mapper can cause this but I use
  orm.mapper.

 session.save() is only used to persist transient instances.   It is
 deprecated (as is update() and save_or_update())  and not present in
 version 0.5.   Upgrade to at least 0.4.8 if not 0.5 and use session.add()
 (equivalent to save_or_update()), which eliminates the need for the user
 to distinguish between transient and detached instances.  For a
 description of what the heck im talking about when i say transient and
 detached 
 seehttp://www.sqlalchemy.org/docs/05/session.html#quickie-intro-to-objec...
 .



  Here is the mapping code:

          metadata = sa.MetaData()
          sm = orm.sessionmaker(autoflush=True, transactional=True,
  bind=engine)

          Model.session = orm.scoped_session(sm)

          person_table = sa.Table('person', metadata, autoload = True,
  autoload_with=engine)
          person_relative_table = sa.Table('person_relative', metadata,
  autoload = True, autoload_with=engine)
          resume_table = sa.Table('resume', metadata, autoload = True,
  autoload_with=engine)
          workplace_table = sa.Table('workplace', metadata, autoload =
  True, autoload_with=engine)
          resume_workplace_table = sa.Table('resume_workplace',
  metadata, autoload = True, autoload_with=engine)

          orm.mapper(self.Person, person_table, properties = {
              'relatives' : orm.relation(self.Person,
  secondary=person_relative_table,

  primaryjoin=person_table.c.id==person_relative_table.c.person_id,

  secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
                                       backref='followers'),
              'resumes' : orm.relation(self.Resume, backref='person')
              }
                     )
          orm.mapper(self.Resume, resume_table, properties = {
              'workplaces' : orm.relation(self.Workplace,
  secondary=resume_workplace_table, backref='resumes')
              }
                     )
          orm.mapper(self.Workplace, workplace_table)
--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

Moshe C. wrote:

 Thanks.
 Given that I am not going to upgrade very soon, is it right to
 conclude that there was a bug in 0.4.6, or is my usage wrong?

it is not a bug.   save() is used only for transient instances.




 On Jun 3, 5:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Trying to find out if I hit a bug or it is me doing something wrong.
  Using version 0.4.6

  when creating an object and then calling session.save() I get:
  Instance 'res...@-0x486e4074' is already persistent

  It works save_or_update() with, but I don't see why I should use that.

  I did read that using session.mapper can cause this but I use
  orm.mapper.

 session.save() is only used to persist transient instances.   It is
 deprecated (as is update() and save_or_update())  and not present in
 version 0.5.   Upgrade to at least 0.4.8 if not 0.5 and use
 session.add()
 (equivalent to save_or_update()), which eliminates the need for the user
 to distinguish between transient and detached instances.  For a
 description of what the heck im talking about when i say transient and
 detached
 seehttp://www.sqlalchemy.org/docs/05/session.html#quickie-intro-to-objec...
 .



  Here is the mapping code:

          metadata = sa.MetaData()
          sm = orm.sessionmaker(autoflush=True, transactional=True,
  bind=engine)

          Model.session = orm.scoped_session(sm)

          person_table = sa.Table('person', metadata, autoload = True,
  autoload_with=engine)
          person_relative_table = sa.Table('person_relative', metadata,
  autoload = True, autoload_with=engine)
          resume_table = sa.Table('resume', metadata, autoload = True,
  autoload_with=engine)
          workplace_table = sa.Table('workplace', metadata, autoload =
  True, autoload_with=engine)
          resume_workplace_table = sa.Table('resume_workplace',
  metadata, autoload = True, autoload_with=engine)

          orm.mapper(self.Person, person_table, properties = {
              'relatives' : orm.relation(self.Person,
  secondary=person_relative_table,

  primaryjoin=person_table.c.id==person_relative_table.c.person_id,

  secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
                                       backref='followers'),
              'resumes' : orm.relation(self.Resume, backref='person')
              }
                     )
          orm.mapper(self.Resume, resume_table, properties = {
              'workplaces' : orm.relation(self.Workplace,
  secondary=resume_workplace_table, backref='resumes')
              }
                     )
          orm.mapper(self.Workplace, workplace_table)
 



--~--~-~--~~~---~--~~
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] SqlAlchemy reflection error in TurboGears 2

2009-06-03 Thread Mike

Hi,

I am working on a TurboGears 2 application that uses SqlAlchemy 0.5.1.
I am using reflection and am having a lot of trouble with it. Anyway,
here's the error I am getting:


Traceback (most recent call last):
  File V:\PythonPackages\Development\pyRetention\Scripts\paster-
script.py, line 8, in module
load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')
()
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\command.py, line 84, in run
invoke(command, command_name, options, args[1:])
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\command.py, line 123, in invoke
exit_code = runner.run(args)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\appinstall.py, line 68, in run
return super(AbstractInstallCommand, self).run(new_args)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\command.py, line 218, in run
result = self.command()
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\appinstall.py, line 456, in command
self, config_file, section, self.sysconfig_install_vars
(installer))
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\appinstall.py, line 598, in setup_config
mod.setup_app, command, filename, section, vars)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\pastescript-1.7.3-py2.5.egg\past
e\script\appinstall.py, line 612, in _call_setup_app
func(command, conf, vars)
  File D:\pyRetention\pyRetention\pyretention\websetup.py, line 18,
in setup_app
load_environment(conf.global_conf, conf.local_conf)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\turbogears2-2.0-py2.5.egg\tg\con
figuration.py, line 438, in load_environment
self.setup_sqlalchemy()
  File v:\pythonpackages\development\pyretention\lib\site-packages
\turbogears2-2.0-py2.5.egg\tg\con
figuration.py, line 393, in setup_sqlalchemy
self.package.model.init_model(engine)
  File D:\pyRetention\pyRetention\pyretention\model\__init__.py,
line 64, in init_model
autoload_with=engine)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\sqlalchemy-0.5.1-py2.5.egg\sqlal
chemy\schema.py, line 113, in __call__
return type.__call__(self, name, metadata, *args, **kwargs)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\sqlalchemy-0.5.1-py2.5.egg\sqlal
chemy\schema.py, line 239, in __init__
autoload_with.reflecttable(self, include_columns=include_columns)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\sqlalchemy-0.5.1-py2.5.egg\sqlal
chemy\engine\base.py, line 1265, in reflecttable
self.dialect.reflecttable(conn, table, include_columns)
  File v:\pythonpackages\development\pyretention\lib\site-packages
\sqlalchemy-0.5.1-py2.5.egg\sqlal
chemy\databases\mssql.py, line 1157, in reflecttable
coltype = coltype(*args, **kwargs)
TypeError: __init__() takes at most 2 arguments (3 given)


I'm not sure what it is talking about. Here are my sample tables
though:


tbl_checks = Table(tableOne, metadata, autoload=True,
   autoload_with=engine)
mapper(Checks, tbl_checks)

tbl_test = Table(tableTwo, metadata, autoload=True,
 autoload_with=engine,
 schema=DBName.dbo)
mapper(Test, tbl_test)


My databases were provided by a vendor and are on Microsoft SQL Server
2000. By analyzing my code in WingWare's debugger, it looks like the
first table is getting reflected correctly in the line
self.dialect.reflecttable(conn, table, include_columns) at least.

Any pointers would be great. I am using Python 2.5 if that matters.

Thanks!

Mike
--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

Well, I thought it was transient.

If you refer to the code in the first post:
If I create a new Resume object and save() it , it works.
If before the save(), I fetch a Workplace object from the DB, then save
() fails and I need to use save_and_update().

So the fact that I queried the DB for a related object, makes the
Resume object not transient anymore?


On Jun 3, 8:56 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Thanks.
  Given that I am not going to upgrade very soon, is it right to
  conclude that there was a bug in 0.4.6, or is my usage wrong?

 it is not a bug.   save() is used only for transient instances.



  On Jun 3, 5:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  Moshe C. wrote:

   Trying to find out if I hit a bug or it is me doing something wrong.
   Using version 0.4.6

   when creating an object and then calling session.save() I get:
   Instance 'res...@-0x486e4074' is already persistent

   It works save_or_update() with, but I don't see why I should use that.

   I did read that using session.mapper can cause this but I use
   orm.mapper.

  session.save() is only used to persist transient instances.   It is
  deprecated (as is update() and save_or_update())  and not present in
  version 0.5.   Upgrade to at least 0.4.8 if not 0.5 and use
  session.add()
  (equivalent to save_or_update()), which eliminates the need for the user
  to distinguish between transient and detached instances.  For a
  description of what the heck im talking about when i say transient and
  detached
  seehttp://www.sqlalchemy.org/docs/05/session.html#quickie-intro-to-objec...
  .

   Here is the mapping code:

           metadata = sa.MetaData()
           sm = orm.sessionmaker(autoflush=True, transactional=True,
   bind=engine)

           Model.session = orm.scoped_session(sm)

           person_table = sa.Table('person', metadata, autoload = True,
   autoload_with=engine)
           person_relative_table = sa.Table('person_relative', metadata,
   autoload = True, autoload_with=engine)
           resume_table = sa.Table('resume', metadata, autoload = True,
   autoload_with=engine)
           workplace_table = sa.Table('workplace', metadata, autoload =
   True, autoload_with=engine)
           resume_workplace_table = sa.Table('resume_workplace',
   metadata, autoload = True, autoload_with=engine)

           orm.mapper(self.Person, person_table, properties = {
               'relatives' : orm.relation(self.Person,
   secondary=person_relative_table,

   primaryjoin=person_table.c.id==person_relative_table.c.person_id,

   secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
                                        backref='followers'),
               'resumes' : orm.relation(self.Resume, backref='person')
               }
                      )
           orm.mapper(self.Resume, resume_table, properties = {
               'workplaces' : orm.relation(self.Workplace,
   secondary=resume_workplace_table, backref='resumes')
               }
                      )
           orm.mapper(self.Workplace, workplace_table)
--~--~-~--~~~---~--~~
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: SqlAlchemy reflection error in TurboGears 2

2009-06-03 Thread Michael Bayer

the MSSQL has had a lot of fixes over the course of 0.5 so definitely get
on the latest 0.5 first.


Mike wrote:

 Hi,

 I am working on a TurboGears 2 application that uses SqlAlchemy 0.5.1.
 I am using reflection and am having a lot of trouble with it. Anyway,
 here's the error I am getting:


 Traceback (most recent call last):
   File V:\PythonPackages\Development\pyRetention\Scripts\paster-
 script.py, line 8, in module
 load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')
 ()
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\command.py, line 84, in run
 invoke(command, command_name, options, args[1:])
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\command.py, line 123, in invoke
 exit_code = runner.run(args)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\appinstall.py, line 68, in run
 return super(AbstractInstallCommand, self).run(new_args)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\command.py, line 218, in run
 result = self.command()
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\appinstall.py, line 456, in command
 self, config_file, section, self.sysconfig_install_vars
 (installer))
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\appinstall.py, line 598, in setup_config
 mod.setup_app, command, filename, section, vars)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \pastescript-1.7.3-py2.5.egg\past
 e\script\appinstall.py, line 612, in _call_setup_app
 func(command, conf, vars)
   File D:\pyRetention\pyRetention\pyretention\websetup.py, line 18,
 in setup_app
 load_environment(conf.global_conf, conf.local_conf)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \turbogears2-2.0-py2.5.egg\tg\con
 figuration.py, line 438, in load_environment
 self.setup_sqlalchemy()
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \turbogears2-2.0-py2.5.egg\tg\con
 figuration.py, line 393, in setup_sqlalchemy
 self.package.model.init_model(engine)
   File D:\pyRetention\pyRetention\pyretention\model\__init__.py,
 line 64, in init_model
 autoload_with=engine)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \sqlalchemy-0.5.1-py2.5.egg\sqlal
 chemy\schema.py, line 113, in __call__
 return type.__call__(self, name, metadata, *args, **kwargs)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \sqlalchemy-0.5.1-py2.5.egg\sqlal
 chemy\schema.py, line 239, in __init__
 autoload_with.reflecttable(self, include_columns=include_columns)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \sqlalchemy-0.5.1-py2.5.egg\sqlal
 chemy\engine\base.py, line 1265, in reflecttable
 self.dialect.reflecttable(conn, table, include_columns)
   File v:\pythonpackages\development\pyretention\lib\site-packages
 \sqlalchemy-0.5.1-py2.5.egg\sqlal
 chemy\databases\mssql.py, line 1157, in reflecttable
 coltype = coltype(*args, **kwargs)
 TypeError: __init__() takes at most 2 arguments (3 given)


 I'm not sure what it is talking about. Here are my sample tables
 though:


 tbl_checks = Table(tableOne, metadata, autoload=True,
autoload_with=engine)
 mapper(Checks, tbl_checks)

 tbl_test = Table(tableTwo, metadata, autoload=True,
  autoload_with=engine,
  schema=DBName.dbo)
 mapper(Test, tbl_test)


 My databases were provided by a vendor and are on Microsoft SQL Server
 2000. By analyzing my code in WingWare's debugger, it looks like the
 first table is getting reflected correctly in the line
 self.dialect.reflecttable(conn, table, include_columns) at least.

 Any pointers would be great. I am using Python 2.5 if that matters.

 Thanks!

 Mike
 



--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

Moshe C. wrote:

 Well, I thought it was transient.

 If you refer to the code in the first post:

your first post has a mapping only.  There is no illustration of how
you're querying, or using save() or load.



--~--~-~--~~~---~--~~
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] Creating a Dialect for Amazon SimpleDB

2009-06-03 Thread enj

Hello all,

I am new to sqlalchemy and was introduced to it by a project (cjklib)
that uses it. I want to migrate this project to Amazon SimpleDB and
since it makes extensive use of sqlalchemy I thought the best course
of action might be to make a SimpleDB dialect in sqlalchemy which
could possibly benefit other projects trying to move to AWS.

The purpose of my post is to see if there is any such effort out there
or any other interest in this. Also I was wondering if there is any
good docs/tutorials on implementing a Dialect.
From my current understanding I plan to implement engine.default
http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchemy/engine/default.py
which will use the boto library to interface with simpledb
http://code.google.com/p/boto/

Any thoughts?

--
Ian Johnson

--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

In code:

t = Model.Resume()
t.id = something

w = Model.session.query(Model.Workplace).filter_by(id=idd).first()

# model.save(t)
model.save_or_update(t)


Without the query line, save() would have worked, but the query is on
another object. There is a relation between the objects, but it is not
clear how querying on another object makes the Resume object non-
transient.




On Jun 3, 10:55 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Well, I thought it was transient.

  If you refer to the code in the first post:

 your first post has a mapping only.  There is no illustration of how
 you're querying, or using save() or load.
--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

Moshe C. wrote:

 In code:

 t = Model.Resume()
 t.id = something

   w = Model.session.query(Model.Workplace).filter_by(id=idd).first()

 # model.save(t)
 model.save_or_update(t)


 Without the query line, save() would have worked, but the query is on
 another object. There is a relation between the objects, but it is not
 clear how querying on another object makes the Resume object non-
 transient.

if you're using ScopedSession.mapper, which I really, really, really think
you should not, then when you say Model.Resume(), it gets added to the
session immediately - the query() would then autoflush it.








 On Jun 3, 10:55 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Well, I thought it was transient.

  If you refer to the code in the first post:

 your first post has a mapping only.  There is no illustration of how
 you're querying, or using save() or load.
 



--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

Weird, the first assertion already fails, but I am not using
ScopedSession.mapper. See the code in the first post.

On Jun 3, 11:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 easy way to ensure things are working as expected:

 Moshe C. wrote:

  In code:

          t = Model.Resume()
          t.id = something

           assert t not in Model.session



     w = Model.session.query(Model.Workplace).filter_by(id=idd).first()

           assert t not in Model.session

          # model.save(t)
          model.save_or_update(t)
--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

Moshe C. wrote:

 Weird, the first assertion already fails, but I am not using
 ScopedSession.mapper. See the code in the first post.

 On Jun 3, 11:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 easy way to ensure things are working as expected:

 Moshe C. wrote:

  In code:

          t = Model.Resume()
          t.id = something

           assert t not in Model.session

its not a full example.  no imports are illustrated including what
orm.mapper() might be doing.   There is obviously code which is setting up
Session.mapper() or otherwise code within Resume().__init__() doing
something similar.











     w = Model.session.query(Model.Workplace).filter_by(id=idd).first()

           assert t not in Model.session

          # model.save(t)
          model.save_or_update(t)
 



--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Moshe C.

full code:

import sqlalchemy as sa
from sqlalchemy import orm

class Model:
session = None

class Person(object):
@staticmethod
def query():
return Model.session.query(Model.Person)

class PersonRelative(object):
@staticmethod
def query():
return Model.session.query(Model.PersonRelative)

class Resume(object):
@staticmethod
def query():
return Model.session.query(Model.Resume)

class Workplace(object):
@staticmethod
def query():
return Model.session.query(Model.Workplace)

class ResumeWorkplace(object):
@staticmethod
def query():
return Model.session.query(Model.ResumeWorkplace)


def __init__(self, engine):
Call me before using any of the tables or classes in the
model.

metadata = sa.MetaData()
sm = orm.sessionmaker(autoflush=True, transactional=True,
bind=engine)

Model.session = orm.scoped_session(sm)

person_table = sa.Table('person', metadata, autoload = True,
autoload_with=engine)
person_relative_table = sa.Table('person_relative', metadata,
autoload = True, autoload_with=engine)
resume_table = sa.Table('resume', metadata, autoload = True,
autoload_with=engine)
workplace_table = sa.Table('workplace', metadata, autoload =
True, autoload_with=engine)
resume_workplace_table = sa.Table('resume_workplace',
metadata, autoload = True, autoload_with=engine)

orm.mapper(self.Person, person_table, properties = {
'relatives' : orm.relation(self.Person,
secondary=person_relative_table,
 
primaryjoin=person_table.c.id==person_relative_table.c.person_id,
 
secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
 backref='followers'),
'resumes' : orm.relation(self.Resume, backref='person')
}
   )
orm.mapper(self.Resume, resume_table, properties = {
'workplaces' : orm.relation(self.Workplace,
secondary=resume_workplace_table, backref='resumes')
}
   )
orm.mapper(self.Workplace, workplace_table)



def commit(self):
Model.session.commit()

def save(self, obj):
Model.session.save(obj)

def save_or_update(self, obj):
Model.session.save_or_update(obj)

def flush(self):
Model.session.flush()

def delete(self, obj):
Model.session.delete(obj)

def clear(self):
Model.session.clear()


On Jun 3, 11:47 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Weird, the first assertion already fails, but I am not using
  ScopedSession.mapper. See the code in the first post.

  On Jun 3, 11:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  easy way to ensure things are working as expected:

  Moshe C. wrote:

   In code:

           t = Model.Resume()
           t.id = something

            assert t not in Model.session

 its not a full example.  no imports are illustrated including what
 orm.mapper() might be doing.   There is obviously code which is setting up
 Session.mapper() or otherwise code within Resume().__init__() doing
 something similar.



      w = Model.session.query(Model.Workplace).filter_by(id=idd).first()

            assert t not in Model.session

           # model.save(t)
           model.save_or_update(t)
--~--~-~--~~~---~--~~
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: SqlAlchemy reflection error in TurboGears 2

2009-06-03 Thread Mike Driscoll

Hi,

Actually, that was just a placeholder name since I'm not sure that my
employer would like me sticking my tables online. Anyway, the
tablename in Microsoft's Enterprise Manager shows it as being all
lowercase although when I run queries against it in MS Query Analyzer,
it uses all uppercase.

All the column names in the table are in uppercase and there are no
foreign keys. The vendor also didn't bother setting a primary key.

So, I decided to try accessing the table without autoload. Since there
are quite a few columns, I thought I'd also try grabbing only the
columns I wanted. For a simple test, I did this:

test_tbl = Table(tablename, metadata,
 Column('id', Integer, primary_key=True),
 Column(CYCLE_CODE, String))

Unfortunately, MSSQL is reporting that my fake primary key column is
invalid. Is there a workaround? Do I need to recreate all the Columns
in a Table object and also in my class definition?

Sorry for all the trouble.

Mike



On Jun 3, 3:48 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 tableTwo is a case sensitive name so must be spelled out with that exact
 case.   in particular if your database is returning foreign key names
 without proper case sensitivity then issues will occur with this.  turn
 echo='debug' to see all SQL emitted and result sets returned.

 Mike Driscoll wrote:

  Hi,

  That fixed that issue. However, now I'm getting an error that my 2nd
  table doesn't exist:

  sqlalchemy.exc.NoSuchTableError: tableTwo

  This is weird since it's been around since 2007 and has lots of data
  in it. I tried changing the name to all lowercase and all uppercase,
  but the error remains the same. I also tried removing the schema line
  to no avail.

  Here's the complete traceback:

  File D:\pyRetention\Scripts\paster, line 5, in module
    pkg_resources.run_script('pastescript==1.7.3', 'paster')
  File c:\Python25\Lib\site-packages\pkg_resources.py, line 448, in
  run_script
    self.require(requires)[0].run_script(script_name, ns)
  File c:\Python25\Lib\site-packages\pkg_resources.py, line 1166, in
  run_script
    execfile(script_filename, namespace, namespace)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\EGG-
  INFO\scripts\paster, line 18, in module
    command.run()
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 84, in run
    invoke(command, command_name, options, args[1:])
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 123, in invoke
    exit_code = runner.run(args)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 218, in run
    result = self.command()
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\serve.py, line 276, in command
    relative_to=base, global_conf=vars)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\serve.py, line 313, in loadapp
    **kw)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 204, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 225, in loadobj
    return context.create()
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 625, in create
    return self.object_type.invoke(self)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 110, in invoke
    return fix_call(context.object, context.global_conf,
  **context.local_conf)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\util\fixtypeerror.py, line 57, in fix_call
    val = callable(*args, **kw)
  File D:\pyRetention\pyRetention\pyretention\config\middleware.py,
  line 35, in make_app
    app = make_base_app(global_conf, full_stack=True, **app_conf)
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 588, in make_base_app
    load_environment(global_conf, app_conf)
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 438, in load_environment
    self.setup_sqlalchemy()
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 393, in setup_sqlalchemy
    self.package.model.init_model(engine)
  File d:\pyRetention\pyRetention\pyretention\model\__init__.py, line
  70, in init_model
    autoload=True, autoload_with=engine)
  File c:\Python25\Lib\site-packages\sqlalchemy-0.5.4p2-py2.5.egg
  \sqlalchemy\schema.py, line 113, in __call__
    return type.__call__(self, name, metadata, *args, **kwargs)
  File c:\Python25\Lib\site-packages\sqlalchemy-0.5.4p2-py2.5.egg
  \sqlalchemy\schema.py, line 239, in __init__
    autoload_with.reflecttable(self, include_columns=include_columns)
  File c:\Python25\Lib\site-packages\sqlalchemy-0.5.4p2-py2.5.egg
 

[sqlalchemy] Re: Creating a Dialect for Amazon SimpleDB

2009-06-03 Thread Laurence Rowe

It would be interesting to see if this could be made to work. The
SimpleDB model is rather different from the relational model, so it
would only be useful if your application does not use any advanced
features - no joins etc, each 'domain' might map to one big (albeit
sparse) table.

Laurence

On Jun 3, 8:38 pm, enj enjah...@gmail.com wrote:
 Hello all,

 I am new to sqlalchemy and was introduced to it by a project (cjklib)
 that uses it. I want to migrate this project to Amazon SimpleDB and
 since it makes extensive use of sqlalchemy I thought the best course
 of action might be to make a SimpleDB dialect in sqlalchemy which
 could possibly benefit other projects trying to move to AWS.

 The purpose of my post is to see if there is any such effort out there
 or any other interest in this. Also I was wondering if there is any
 good docs/tutorials on implementing a Dialect.
 From my current understanding I plan to implement 
 engine.defaulthttp://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchem...
 which will use the boto library to interface with 
 simpledbhttp://code.google.com/p/boto/

 Any thoughts?

 --
 Ian Johnson
--~--~-~--~~~---~--~~
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: needed save_or_update(), save() didn't work

2009-06-03 Thread Michael Bayer

that code is fine as far as I can see.   if you are still having problems,
produce a test script that can be run by others (this does not qualify
since it uses autoload and does not illustrate the session usage nor the
creation of Model).


Moshe C. wrote:

 full code:

 import sqlalchemy as sa
 from sqlalchemy import orm

 class Model:
 session = None

 class Person(object):
 @staticmethod
 def query():
 return Model.session.query(Model.Person)

 class PersonRelative(object):
 @staticmethod
 def query():
 return Model.session.query(Model.PersonRelative)

 class Resume(object):
 @staticmethod
 def query():
 return Model.session.query(Model.Resume)

 class Workplace(object):
 @staticmethod
 def query():
 return Model.session.query(Model.Workplace)

 class ResumeWorkplace(object):
 @staticmethod
 def query():
 return Model.session.query(Model.ResumeWorkplace)


 def __init__(self, engine):
 Call me before using any of the tables or classes in the
 model.

 metadata = sa.MetaData()
 sm = orm.sessionmaker(autoflush=True, transactional=True,
 bind=engine)

 Model.session = orm.scoped_session(sm)

 person_table = sa.Table('person', metadata, autoload = True,
 autoload_with=engine)
 person_relative_table = sa.Table('person_relative', metadata,
 autoload = True, autoload_with=engine)
 resume_table = sa.Table('resume', metadata, autoload = True,
 autoload_with=engine)
 workplace_table = sa.Table('workplace', metadata, autoload =
 True, autoload_with=engine)
 resume_workplace_table = sa.Table('resume_workplace',
 metadata, autoload = True, autoload_with=engine)

 orm.mapper(self.Person, person_table, properties = {
 'relatives' : orm.relation(self.Person,
 secondary=person_relative_table,

 primaryjoin=person_table.c.id==person_relative_table.c.person_id,

 secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
  backref='followers'),
 'resumes' : orm.relation(self.Resume, backref='person')
 }
)
 orm.mapper(self.Resume, resume_table, properties = {
 'workplaces' : orm.relation(self.Workplace,
 secondary=resume_workplace_table, backref='resumes')
 }
)
 orm.mapper(self.Workplace, workplace_table)



 def commit(self):
 Model.session.commit()

 def save(self, obj):
 Model.session.save(obj)

 def save_or_update(self, obj):
 Model.session.save_or_update(obj)

 def flush(self):
 Model.session.flush()

 def delete(self, obj):
 Model.session.delete(obj)

 def clear(self):
 Model.session.clear()


 On Jun 3, 11:47 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 Moshe C. wrote:

  Weird, the first assertion already fails, but I am not using
  ScopedSession.mapper. See the code in the first post.

  On Jun 3, 11:28 pm, Michael Bayer mike...@zzzcomputing.com wrote:
  easy way to ensure things are working as expected:

  Moshe C. wrote:

   In code:

           t = Model.Resume()
           t.id = something

            assert t not in Model.session

 its not a full example.  no imports are illustrated including what
 orm.mapper() might be doing.   There is obviously code which is setting
 up
 Session.mapper() or otherwise code within Resume().__init__() doing
 something similar.



      w =
 Model.session.query(Model.Workplace).filter_by(id=idd).first()

            assert t not in Model.session

           # model.save(t)
           model.save_or_update(t)
 



--~--~-~--~~~---~--~~
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: SqlAlchemy reflection error in TurboGears 2

2009-06-03 Thread Michael Bayer


i don't see what the purpose of a fake id column serves here.  you can
make a Table object and place within it as many actual columns as you
want, including primary key columns.   if the table name is truly all
uppercase, then you need to name it that way in the Table object.


Mike Driscoll wrote:

 Hi,

 Actually, that was just a placeholder name since I'm not sure that my
 employer would like me sticking my tables online. Anyway, the
 tablename in Microsoft's Enterprise Manager shows it as being all
 lowercase although when I run queries against it in MS Query Analyzer,
 it uses all uppercase.

 All the column names in the table are in uppercase and there are no
 foreign keys. The vendor also didn't bother setting a primary key.

 So, I decided to try accessing the table without autoload. Since there
 are quite a few columns, I thought I'd also try grabbing only the
 columns I wanted. For a simple test, I did this:

 test_tbl = Table(tablename, metadata,
  Column('id', Integer, primary_key=True),
  Column(CYCLE_CODE, String))

 Unfortunately, MSSQL is reporting that my fake primary key column is
 invalid. Is there a workaround? Do I need to recreate all the Columns
 in a Table object and also in my class definition?

 Sorry for all the trouble.

 Mike



 On Jun 3, 3:48 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 tableTwo is a case sensitive name so must be spelled out with that exact
 case.   in particular if your database is returning foreign key names
 without proper case sensitivity then issues will occur with this.  turn
 echo='debug' to see all SQL emitted and result sets returned.

 Mike Driscoll wrote:

  Hi,

  That fixed that issue. However, now I'm getting an error that my 2nd
  table doesn't exist:

  sqlalchemy.exc.NoSuchTableError: tableTwo

  This is weird since it's been around since 2007 and has lots of data
  in it. I tried changing the name to all lowercase and all uppercase,
  but the error remains the same. I also tried removing the schema line
  to no avail.

  Here's the complete traceback:

  File D:\pyRetention\Scripts\paster, line 5, in module
    pkg_resources.run_script('pastescript==1.7.3', 'paster')
  File c:\Python25\Lib\site-packages\pkg_resources.py, line 448, in
  run_script
    self.require(requires)[0].run_script(script_name, ns)
  File c:\Python25\Lib\site-packages\pkg_resources.py, line 1166, in
  run_script
    execfile(script_filename, namespace, namespace)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\EGG-
  INFO\scripts\paster, line 18, in module
    command.run()
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 84, in run
    invoke(command, command_name, options, args[1:])
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 123, in invoke
    exit_code = runner.run(args)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\command.py, line 218, in run
    result = self.command()
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\serve.py, line 276, in command
    relative_to=base, global_conf=vars)
  File c:\Python25\Lib\site-packages\pastescript-1.7.3-py2.5.egg\paste
  \script\serve.py, line 313, in loadapp
    **kw)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 204, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 225, in loadobj
    return context.create()
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 625, in create
    return self.object_type.invoke(self)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\loadwsgi.py, line 110, in invoke
    return fix_call(context.object, context.global_conf,
  **context.local_conf)
  File c:\Python25\Lib\site-packages\pastedeploy-1.3.3-py2.5.egg\paste
  \deploy\util\fixtypeerror.py, line 57, in fix_call
    val = callable(*args, **kw)
  File D:\pyRetention\pyRetention\pyretention\config\middleware.py,
  line 35, in make_app
    app = make_base_app(global_conf, full_stack=True, **app_conf)
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 588, in make_base_app
    load_environment(global_conf, app_conf)
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 438, in load_environment
    self.setup_sqlalchemy()
  File c:\Python25\Lib\site-packages\turbogears2-2.0-py2.5.egg\tg
  \configuration.py, line 393, in setup_sqlalchemy
    self.package.model.init_model(engine)
  File d:\pyRetention\pyRetention\pyretention\model\__init__.py, line
  70, in init_model
    autoload=True, autoload_with=engine)
  File c:\Python25\Lib\site-packages\sqlalchemy-0.5.4p2-py2.5.egg
  \sqlalchemy\schema.py, line 113, in 

[sqlalchemy] Re: Creating a Dialect for Amazon SimpleDB

2009-06-03 Thread enj

The way Simpledb works you don't want to make each domain a table, you
want to put all related tables in one domain. This way you can do
relational queries on the set of objects. One thing that might help
conceptualize it would be to set a table attribute for each item
that contains what the table name would be called. That way you could
quickly get a resultset of all the objects that should be in that
table. One can do any kind of relational operation on the set of
objects in the domain, so sqlalchemy functionality can be mapped to
it. Since transactions aren't supported that functionality wont be
supported, but one can still make useful applications.

Ian

On Jun 3, 6:00 pm, Laurence Rowe laurencer...@gmail.com wrote:
 It would be interesting to see if this could be made to work. The
 SimpleDB model is rather different from the relational model, so it
 would only be useful if your application does not use any advanced
 features - no joins etc, each 'domain' might map to one big (albeit
 sparse) table.

 Laurence

 On Jun 3, 8:38 pm, enj enjah...@gmail.com wrote:

  Hello all,

  I am new to sqlalchemy and was introduced to it by a project (cjklib)
  that uses it. I want to migrate this project to Amazon SimpleDB and
  since it makes extensive use of sqlalchemy I thought the best course
  of action might be to make a SimpleDB dialect in sqlalchemy which
  could possibly benefit other projects trying to move to AWS.

  The purpose of my post is to see if there is any such effort out there
  or any other interest in this. Also I was wondering if there is any
  good docs/tutorials on implementing a Dialect.
  From my current understanding I plan to implement 
  engine.defaulthttp://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/lib/sqlalchem...
  which will use the boto library to interface with 
  simpledbhttp://code.google.com/p/boto/

  Any thoughts?

  --
  Ian Johnson
--~--~-~--~~~---~--~~
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] Filtering by count of child object

2009-06-03 Thread Moshe C.

Let's say I have a many to many relationship as for example in:

orm.mapper(self.Person, person_table, properties = {
'relatives' : orm.relation(self.Person,
secondary=person_relative_table,
 
primaryjoin=person_table.c.id==person_relative_table.c.person_id,
 
secondaryjoin=person_relative_table.c.relative_id==person_table.c.id,
 backref='followers'),
}

Is there an elegant ORM-only expresssion to retrieve all the Persons
that have more than 2 Relatives?

Creating the non-ORM count-join-group by-having expression on the
person_relative_table is easy, but you end up with person ids that you
still have to convert to Person objects.

TIA

Moshe

--~--~-~--~~~---~--~~
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] Query - column names

2009-06-03 Thread George Sakkis

Is there a (public) API for getting the column names of a given Query
instance and other similar introspection needs  ? I didn't find
anything related in the docs but after digging in the code I came up
with
col_names = [e._result_label for e in q._entities]
but I'm not sure how stable and robust this is.

George
--~--~-~--~~~---~--~~
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: Query - column names

2009-06-03 Thread Michael Bayer

each row has a keys() attribute if that helps...


On Jun 3, 2009, at 8:49 PM, George Sakkis wrote:


 Is there a (public) API for getting the column names of a given Query
 instance and other similar introspection needs  ? I didn't find
 anything related in the docs but after digging in the code I came up
 with
col_names = [e._result_label for e in q._entities]
 but I'm not sure how stable and robust this is.

 George
 


--~--~-~--~~~---~--~~
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] Can I coerce strings into Unicode?

2009-06-03 Thread AF

Hello,

I'm using sqlite and convert_unicode = True on the engine.

How can I force coerce string based object attributes in to unicode?
(I had thought convert_unicode = True would do this)

Here is what I am seeing...

Setup code:
engine = create_engine('sqlite:///:memory:', echo=True,
convert_unicode=True)
Session = sessionmaker(bind=engine)
session = Session()
metadata = MetaData()
m1 = message(u'message body 1')

Now, in ipython:

In [1]: session.add(m1)

In [2]: m1.body
Out[2]: u'message body 1'

In [3]: m1.body = u'new - unicode'

In [4]: m1.body
Out[4]: u'new - unicode'

In [5]: m1.body = 'new - NOT unicode'

In [6]: m1.body
Out[6]: 'new - NOT unicode'

In [7]: unicode(m1.body)
Out[7]: u'new - NOT unicode'


Output line 6 is the problem.

Ideally, I'd like to see output lines 6  7 be the same.

Am I doing something wrong?

Thank you,
Allen
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---