Michael Bayer wrote:
>
> im guessing you are using some implicit executions...you should take a
> look at http://www.sqlalchemy.org/docs/dbengine.myt#dbengine_implicit to
> understand their behavior.
>
I'm only using the ORM and a session, using classed mapped to Tables
using DynamicMetaData.
I explicitly do an engine.connect()
I then create several queries for my data classes ready to use later in
the program.
I then use a query to retrieve a single object, modify one or more
properties of the object and perhaps add/modfiy some related objects and
flush the session.
Below is a snippet of the program. The telephones routine is called to
process data from a file, many other similar routines are called to
process other types of data on other objects during a single run of the
program. Any clue here as to how more than one connection is created/used?
db = create_engine('mssql://sa:[EMAIL PROTECTED]/she9832')
connection = db.connect()
metadata.connect(db)
session = create_session(bind_to=db)
cq = session.query(Client)
def telephones(data,field_map):
"process telephones"
log.info("processing client telephones")
for record in data:
# need a manual transaction here as creating new
features/extras may require an intermediate flush()
transaction = session.create_transaction()
try:
# get the "key" from the mapping
sdict = {field_map['key'][1]:record[field_map['key'][0]]}
cl = cq.get_by(**sdict)
if (cl == None):
log.error("Client with %s of %s does not
exist",field_map['key'][0],record[field_map['key'][0]])
else:
log.info("Updating telephone info for client %s
%s",cl.fname, cl.sname)
if record['primary_contact_indicator'] == 'Y':
cl.location.tel1 = record['telephone_number']
else:
cl.location.tel2 = record['telephone_number']
session.flush()
transaction.commit()
except:
transaction.rollback()
raise
...
connection.close()
....
db.dispose()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---