I cant reproduce your problem, although i dont have access to MSSQL
here and there may be some issue on that end. Attached is your script
using an in-memory sqlite database, with the update inside of a while
loop, and it updates regularly. A few things to try on the MSSQL
side, if the issue is due to some typing issue, try not using
autoload=True, try using generic types instead of the MSSQL specific
ones, etc., in an effort to narrow down what might be the problem.
also ive added "MSSQL/pyodbc" to the subject line here in case any of
the MSSQL crew wants to try out your script with pyodbc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---
import sqlalchemy as sa
import datetime, time
from sqlalchemy.orm import sessionmaker
from sqlalchemy import *
sa_engine=sa.create_engine("sqlite://",echo=True)
metadata = sa.MetaData(sa_engine)
Session = sessionmaker(bind=sa_engine, autoflush=True,transactional=True)
sa_session = Session()
jobs = sa.Table('jobs', metadata,
sa.Column('identifier', Integer,
primary_key=True),
sa.Column('section', Integer),
sa.Column("start",DateTime,
primary_key=True),
sa.Column("stop",DateTime),
sa.Column("station", sa.VARCHAR(20)))
metadata.create_all()
class Job(object):
def __init__(self, identifier, start):
self.identifier, self.start=identifier, start
sa.orm.mapper(Job, jobs)
j = Job("TEST1", datetime.datetime.now())
sa_session.save(j)
sa_session.commit()
# The following part is here just to simluate my problem... if I keep using j instead of getting j1 from query
# the record is updated as well....
while True:
sa_session.clear()
time.sleep(1)
j1=sa_session.query(Job).all()[0]
j1.stop=datetime.datetime.now()
sa_session.save_or_update(j1)
sa_session.commit()
On Dec 9, 2007, at 5:26 PM, Smoke wrote:
>
> On 9 Dic, 21:37, Michael Bayer <[EMAIL PROTECTED]> wrote:
>> theyre entirely supported. try to provide a fully working example
>> illustrating the problem youre having.
>
>
>
> Here's a small example just to simulate the problem.. The last part of
> this code is there just to simulate the problem... normally i would
> just keep using j and update it... and this updates the record into
> the db. But if I get an instance of the Job class from a query on the
> db and try to update ( or save_or_update)it the record is not updated
> into the db as well..
>
> Here the sample code:
>
>
> import sqlalchemy as sa
> import datetime, time
> from sqlalchemy.orm import sessionmaker
>
> sa_engine=sa.create_engine("mssql://user:[EMAIL PROTECTED]/myDB",
> echo=True)
> metadata = sa.MetaData(sa_engine)
> Session = sessionmaker(bind=sa_engine, autoflush=True,
> transactional=True)
> sa_session = Session()
>
>
> jobs = sa.Table('jobs', metadata,
> sa.Column('identifier',
> sa.databases.mssql.MSUniqueIdentifier,
> primary_key=True),
> sa.Column('section',
> sa.databases.mssql.MSUniqueIdentifier),
>
> sa.Column("start",sa.databases.mssql.MSDateTime_pyodbc,
> primary_key=True),
>
> sa.Column("stop",sa.databases.mssql.MSDateTime_pyodbc),
> sa.Column("station",
> sa.VARCHAR(20)),
> autoload=True)
>
> class Job(object):
> def __init__(self, identifier, start):
> self.identifier, self.start=identifier, start
>
> sa.orm.mapper(Job, jobs)
>
> j = Job("TEST1", datetime.datetime.now())
> sa_session.save(j)
> sa_session.commit()
> # The following part is here just to simluate my problem... if I keep
> using j instead of getting j1 from query
> # the record is updated as well....
> sa_session.clear()
> time.sleep(1)
> j1=sa_session.query(Job).all()[0]
> j1.stop=datetime.datetime.now()
> sa_session.save_or_update(j1)
> sa_session.commit()
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To post to this group, send email to [email protected]
> 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
> -~----------~----~----~----~------~----~------~--~---
>