Daniel Miller пишет:
> 
> Basil Shubin wrote:
>> Michael Bayer пишет:
>>> this example is confusing the Table object with a mapped class.
>>>
>>> selecting off a table with the FOR UPDATE clause added looks like:
>>>
>>> result = table.select(localTowns.c.id==itemid, for_update=True)
>>>
>>> "lockmode" is an ORM-level concept when youre dealing with mapped
>>> classes.
>> Thanks, now I realise how to use it. But here is another problem, how I 
>> can check if the appropriate row was selected for update? It's needed 
>> because I want show error message box in a case where row is in update 
>> status. As I see if I try access already selected row it just hang up 
>> until the row was released, alas, no exception was raised. So my 
>> question is how I can prevent user from selecting the row that was 
>> selected by other, how I can do this by programming?
>>
> 
> I have to agree with Michael here, you probably shouldn't be using 
> pessimistic locking. I'm a PostgreSQL user, so I'll tell you how I would do 
> it with that. You'll have to translate this to use it with MySQL (I think 
> that's what you said you're using). Also, this approach will only work if you 
> control all access to the table (i.e. only if no external applications will 
> be updating the table--otherwise you'll need to use pessimistic locking). 
> Also, this solution will only work for tables with with an integer primary 
> key, although it could be adapted to work with any table by creating 
> additional lock tables for each primary key type.
> 
> Create a table in your database to hold locks. It should be something like 
> this:
> 
> CREATE TABLE locks (
>   table_name varchar,
>   locked_row_id int,
>   PRIMARY KEY (table_name, locked_row_id)
> );

Is it possible to create table like above via SQLAlchemy? For 
construction like this:

self.locks = Table('locks', self.metadata,
                    Column('table_name', Unicode(15)),
                    Column('locked_row_id', Integer),
                    Column('table_name', 'locked_row_id',
                           primary_key=True))

I got ab error:

  File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
284, in create
     self.metadata.create_all(connectable=connectable, 
checkfirst=checkfirst, tables=[self])
   File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
862, in create_all
     connectable.create(self, checkfirst=checkfirst, tables=tables)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 413, in create
     self._run_visitor(self.dialect.schemagenerator, entity, 
connection=connection, **kwargs)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 437, in _run_visitor
     element.accept_schema_visitor(visitorcallable(self, conn.proxy, 
connection=conn, **kwargs), traverse=False)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
882, in accept_schema_visitor
     visitor.visit_metadata(self)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 
637, in visit_metadata
     table.accept_schema_visitor(self, traverse=False)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
268, in accept_schema_visitor
     return visitor.visit_table(self)
   File "/usr/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 
658, in visit_table
     self.append("\t" + self.get_column_specification(column, 
first_pk=column.primary_key and not first_pk))
   File 
"/usr/lib/python2.4/site-packages/sqlalchemy/databases/mysql.py", line 
435, in get_column_specification
     t = column.type.engine_impl(self.engine)
AttributeError: 'str' object has no attribute 'engine_impl'
OnInit returned false, exiting...

-- 
Basil Shubin
Freelance Software Developer


--~--~---------~--~----~------------~-------~--~----~
 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to