I am sorry Michael,

Maybe the problem is not in the column_prefix,
The thing that I don't understand in this query is why sa tries to change the 
primary key of this row.


I changed in my form only the value of id_operator,
thus I expected a query like:

UPDATE anagrafica SET id_operatore=1695
WHERE  id = 141092

instead of:

UPDATE anagrafica SET id=NULL,
telefono=NULL,
ts_ultima_modifica=NULL,
id_operatore=1695,
tipo=NULL
WHERE anagrafica.id = 141092


Michael Bayer wrote:
If you could send code examples in a readable format, that would be helpful.

Here is column_prefix working as documented:

from sqlalchemy import *
from sqlalchemy.orm import *

engine = create_engine('sqlite://', echo=True)
metadata = MetaData()

t = Table('foo', metadata,
    Column('id', Integer, primary_key=True),
    Column('data', String),
)

class Foo(object):
    pass

mapper(Foo, t, column_prefix="bar_")

metadata.create_all(engine)

sess = sessionmaker(engine)()

f1 = Foo()
f1.bar_id = 1
f1.bar_data = "some data"

sess.add(f1)
sess.commit()

assert engine.execute("select * from foo").fetchall() == [(1, 'some data')]

sess.expunge_all()

f1 = sess.query(Foo).first()
assert f1.bar_id == 1
assert f1.bar_data == "some data"


z-eeks-Computer-3:sqlalchemy classic$ python test.py
2010-04-15 11:15:16,472 INFO sqlalchemy.engine.base.Engine.0x...b990 PRAGMA 
table_info("foo")
2010-04-15 11:15:16,472 INFO sqlalchemy.engine.base.Engine.0x...b990 ()
2010-04-15 11:15:16,472 INFO sqlalchemy.engine.base.Engine.0x...b990 CREATE TABLE foo ( id INTEGER NOT NULL, data VARCHAR, PRIMARY KEY (id)
)


2010-04-15 11:15:16,473 INFO sqlalchemy.engine.base.Engine.0x...b990 ()
2010-04-15 11:15:16,473 INFO sqlalchemy.engine.base.Engine.0x...b990 COMMIT
2010-04-15 11:15:16,474 INFO sqlalchemy.engine.base.Engine.0x...b990 BEGIN
2010-04-15 11:15:16,475 INFO sqlalchemy.engine.base.Engine.0x...b990 INSERT 
INTO foo (id, data) VALUES (?, ?)
2010-04-15 11:15:16,475 INFO sqlalchemy.engine.base.Engine.0x...b990 (1, 'some 
data')
2010-04-15 11:15:16,475 INFO sqlalchemy.engine.base.Engine.0x...b990 COMMIT
2010-04-15 11:15:16,476 INFO sqlalchemy.engine.base.Engine.0x...b990 select * 
from foo
2010-04-15 11:15:16,476 INFO sqlalchemy.engine.base.Engine.0x...b990 ()
2010-04-15 11:15:16,477 INFO sqlalchemy.engine.base.Engine.0x...b990 BEGIN
2010-04-15 11:15:16,478 INFO sqlalchemy.engine.base.Engine.0x...b990 SELECT foo.id AS foo_id, foo.data AS foo_data FROM foo LIMIT 1 OFFSET 0
2010-04-15 11:15:16,478 INFO sqlalchemy.engine.base.Engine.0x...b990 ()


On Apr 15, 2010, at 11:00 AM, jo wrote:

Hi all,

....
Module sqlalchemy.engine.base:*1180* in |__execute_context
||context*.*parameters*[**0**]**,* context*=*context*)*|
Module sqlalchemy.engine.base:*1249* in |_cursor_execute||
self*.*_handle_dbapi_exception*(*e*,* statement*,* parameters*,* cursor*,* 
context*)*|
Module sqlalchemy.engine.base:*1247* in |_cursor_execute|
|self*.*dialect*.*do_execute*(*cursor*,* statement*,* parameters*,* 
context*=*context*)*|
Module sqlalchemy.engine.default:*266* in |do_execute| 
<http://tg11.sferacarta.com:8000/operatore/save#>
|cursor*.*execute*(*statement*,* parameters*)*|
*IntegrityError: ('(IntegrityError) null value in column "id" violates not-null constraint\n', 
<bound method Controller.save of <sicer.BASE.controller.authentication.operatore.Controller object at 
0x4e178d0>>) 'UPDATE anagrafica SET id=%(id)s, telefono=%(telefono)s, 
ts_ultima_modifica=%(ts_ultima_modifica)s, id_operatore=%(id_operatore)s, tipo=%(tipo)s WHERE anagrafica.id = 
%(anagrafica_id)s' {'ts_ultima_modifica': None, 'tipo': None, 'anagrafica_id': 141092, 'telefono': None, 'id': 
None, 'id_operatore': 1695}* |<<  <http://tg11.sferacarta.com:8000/operatore/save#>                   
         context*.*cursor*,*
                              context*.*statement*,*
                              context*.*parameters*[**0**]**,* 
context*=*context*)*
            *if* context*.*compiled*:*| |<<  
<http://tg11.sferacarta.com:8000/operatore/save#>            
self.dialect.do_execute(cursor, statement, parameters, context=context)
          except Exception, e:
              self._handle_dbapi_exception(e, statement, parameters, cursor, 
context)
              raise
  | |<<  <http://tg11.sferacarta.com:8000/operatore/save#>            
self.engine.logger.info("%r", parameters)
          try:
              self.dialect.do_execute(cursor, statement, parameters, 
context=context)
          except Exception, e:
              self._handle_dbapi_exception(e, statement, parameters, cursor, context)| 
|<<  <http://tg11.sferacarta.com:8000/operatore/save#>
      *def* *do_execute**(**self**,* *cursor**,* *statement**,* *parameters**,* 
*context**=*None*)**:*
          cursor*.*execute*(*statement*,* parameters*)*
        *def* *is_disconnect**(**self**,* *e**)**:*|

-----------------------------------------------------------------------

I'm using column_prefix, but seems sa compiles this query without prefix, 
furthermore it try to update the primary key with a NULL value.

*'UPDATE anagrafica SET id=%(id)s,
  telefono=%(telefono)s,    ts_ultima_modifica=%(ts_ultima_modifica)s,
id_operatore=%(id_operatore)s, tipo=%(tipo)s WHERE anagrafica.id = %(anagrafica_id)s'
*|   <http://tg11.sferacarta.com:8000/operatore/save#>     *def* 
*do_execute**(**self**,* *cursor**,* *statement**,* *parameters**,* 
*context**=*None*)**:*

          cursor*.*execute*(*statement*,* parameters*)*

*def* *is_disconnect**(**self**,* *e**)**:*|
class Anagrafica():
    pass
mapper(Anagrafica,
     tbl['anagrafica'],
     column_prefix = 'anagrafica_',
     extension=History(),
  )

The migration from 0.3 to 0.6 is too hard. :-( j







--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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 sqlalch...@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.

Reply via email to