Re: [sqlalchemy] Problem with Association Object mapping

2012-07-10 Thread Jules Stevenson
Seems I got the append wrong, the below works fine, thanks again for your
help.

due_con.due_user = c.user
contact.due_dates.append(due_con)


On Tue, Jul 10, 2012 at 8:46 AM, Jules Stevenson
droolz...@googlemail.comwrote:

 Hi Michael,

 Yes, I am doing this:

 due_con = model.ArkContactDueDate()
 due_con.modded =
 arkUtils.process_date(field_dataList['duecontact'])
 due_con.contact = contact

 #todo: cannot append since it gives a duff default error message.
 #have triple checked against docs and DB looks sound, so not sure..
 c.user.due_contacts.append(due_con)

 ...but still get the error - is there anything else I can look into? Thank
 you for getting back to me, the level of support you give is outstanding.

 Jules

 On Mon, Jul 9, 2012 at 11:40 PM, Michael Bayer 
 mike...@zzzcomputing.comwrote:


 On Jul 9, 2012, at 6:08 PM, Jules Stevenson wrote:

 Hi All,

 I'm trying to put together an Association Object mapping within a pylons
 app, but am getting the following error:

 OperationalError: (OperationalError) (1364, Field 'user_id' doesn't have
 a default value) 'INSERT INTO contact_duedate_user_association
 (contact_id, modded) VALUES (%s, %s)' (209L, datetime.date(2012, 7, 18))

 As far as I can tell I've followed the recomendations in the association
 object help and am somehwta stumped as to what is causing the error. The
 classes are non-declarative, and are as follows (and if the formatting
 holds up the relevant bits should be in bold). Any help enormously
 appreciated.


 mapping looks fine, you'd need to ensure every ArkContactDueDate you add
 to the Session is associated with a User also in that session.
  single_parent=True should not be needed here.





 contacts_table = sa.Table('contacts', meta.metadata,
 sa.Column('id', sa.types.Integer, primary_key=True),
 sa.Column('project_id', sa.types.Integer, sa.ForeignKey('projects.id
 ')),
 sa.Column('client_id', sa.types.Integer, sa.ForeignKey('clients.id
 ')),
 sa.Column('firstname',sa.types.String(length=255)),
 sa.Column('lastname', sa.types.String(length=255)),
 sa.Column('email1', sa.types.String(length=255)),
 sa.Column('email2', sa.types.String(length=255)),
 sa.Column('workphone', sa.types.String(length=255)),
 sa.Column('mobile', sa.types.String(length=255)),
 sa.Column('company', sa.types.String(length=255)),
 sa.Column('category', sa.types.String(length=255)),
 sa.Column('job_role', sa.types.String(length=255)),
 sa.Column('mailer', sa.types.Boolean),
 sa.Column('type', sa.types.Integer), # 0: contact, 1: press
 sa.Column('modified', sa.types.DateTime),
 )

 class ArkContact(object):
 def __init__(self):
 self.category = 0
 self.type = 0
 self.modified = datetime.datetime.now()

 *#due_contact_association
 contact_due_contact = sa.Table('contact_duedate_user_association',
 meta.metadata,
 sa.Column('contact_id', sa.types.Integer, sa.ForeignKey('contacts.id'),
 primary_key = True),
 sa.Column('user_id', sa.types.Integer, sa.ForeignKey('users.id'),
  primary_key = True),
 sa.Column('modded', sa.types.Date)
 )

 class ArkContactDueDate(object):
 def __init__(self):
 pass*


 *# ArkContactDueDate
 orm.mapper(ArkContactDueDate, contact_due_contact, properties={
 'contact': orm.relation(ArkContact, backref = 'due_dates')
 })*

 # ArkUser - users module
 orm.mapper(ArkUser, users_table, properties={
 'notes': orm.relation(ArkNote,
 secondary=user_notes_table,
 single_parent=True,
 backref='user',
 order_by=notes_table.c.date,
 cascade=all, delete, delete-orphan),
 'software': orm.relation(ArkSoftware,
 secondary=user_software_table,
 backref='users'),
 'ratings': orm.relation(ArkUserSoftwareRating,
 cascade=all, delete,
 backref='user'),
 'job': orm.relation(ArkJob,
 backref='user'),
 *'due_contacts': orm.relation(ArkContactDueDate,
  backref = 'due_user',
  single_parent=True)*
 })

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


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




-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy

[sqlalchemy] Problem with Association Object mapping

2012-07-09 Thread Jules Stevenson
Hi All,

I'm trying to put together an Association Object mapping within a pylons
app, but am getting the following error:

OperationalError: (OperationalError) (1364, Field 'user_id' doesn't have a
default value) 'INSERT INTO contact_duedate_user_association (contact_id,
modded) VALUES (%s, %s)' (209L, datetime.date(2012, 7, 18))

As far as I can tell I've followed the recomendations in the association
object help and am somehwta stumped as to what is causing the error. The
classes are non-declarative, and are as follows (and if the formatting
holds up the relevant bits should be in bold). Any help enormously
appreciated.

contacts_table = sa.Table('contacts', meta.metadata,
sa.Column('id', sa.types.Integer, primary_key=True),
sa.Column('project_id', sa.types.Integer, sa.ForeignKey('projects.id')),
sa.Column('client_id', sa.types.Integer, sa.ForeignKey('clients.id')),
sa.Column('firstname',sa.types.String(length=255)),
sa.Column('lastname', sa.types.String(length=255)),
sa.Column('email1', sa.types.String(length=255)),
sa.Column('email2', sa.types.String(length=255)),
sa.Column('workphone', sa.types.String(length=255)),
sa.Column('mobile', sa.types.String(length=255)),
sa.Column('company', sa.types.String(length=255)),
sa.Column('category', sa.types.String(length=255)),
sa.Column('job_role', sa.types.String(length=255)),
sa.Column('mailer', sa.types.Boolean),
sa.Column('type', sa.types.Integer), # 0: contact, 1: press
sa.Column('modified', sa.types.DateTime),
)

class ArkContact(object):
def __init__(self):
self.category = 0
self.type = 0
self.modified = datetime.datetime.now()

*#due_contact_association
contact_due_contact = sa.Table('contact_duedate_user_association',
meta.metadata,
sa.Column('contact_id', sa.types.Integer, sa.ForeignKey('contacts.id'),
primary_key = True),
sa.Column('user_id', sa.types.Integer, sa.ForeignKey('users.id'),
 primary_key = True),
sa.Column('modded', sa.types.Date)
)

class ArkContactDueDate(object):
def __init__(self):
pass*


*# ArkContactDueDate
orm.mapper(ArkContactDueDate, contact_due_contact, properties={
'contact': orm.relation(ArkContact, backref = 'due_dates')
})*

# ArkUser - users module
orm.mapper(ArkUser, users_table, properties={
'notes': orm.relation(ArkNote,
secondary=user_notes_table,
single_parent=True,
backref='user',
order_by=notes_table.c.date,
cascade=all, delete, delete-orphan),
'software': orm.relation(ArkSoftware,
secondary=user_software_table,
backref='users'),
'ratings': orm.relation(ArkUserSoftwareRating,
cascade=all, delete,
backref='user'),
'job': orm.relation(ArkJob,
backref='user'),
*'due_contacts': orm.relation(ArkContactDueDate,
 backref = 'due_user',
 single_parent=True)*
})

-- 
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] Querying multiple classes and ordering the results

2011-10-25 Thread Jules Stevenson
Hi All,

I'm trying to query more than one class at the same time, and order
the result by date (both classes have a .date property), using the
following query:

c.items = meta.Session.query(model.ArkEmail, model.ArkNote).\
filter(model.ArkEmail.is_thread_parent == True).\
filter(model.ArkEmail.project == c.project).\
filter(model.ArkEmail.is_duplicate == False).\
filter(model.ArkNote.project.contains(c.project)).\
order_by(sa.desc(model.ArkEmail.date),
sa.desc(model.ArkNote.date)).\
all()

There's not really any mapping between these two classes, I jsut want
a list ordered by date of the two class instances that match the
filter criteria.

I'm hitting some wierdness with this in so much as on some queries the
results return nothing (when they should do according to what's in the
database), I'm also fairly certain the ordering is not working.

It's also returning the result inside a tuple:

 c.items
[(ark.model.clientprojectshot.ArkEmail object at 0x073FF208,
ark.model.utilities.ArkNote object at 0x073FF278)]

So generally, I think I'm doing quite a lot wrong. Any pointers as to
the correct way of doing this?

Many thanks,

Jules

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



Re: [sqlalchemy] mapping a class linked with two other classes (AttributeError: 'str' object has no attribute '_sa_instance_state')

2011-06-16 Thread Jules Stevenson
Hi Simon, thank you very much for your help (again!), and yes, that's
how I'm using the mapping :).

I'm now getting an SQL error, I think because the user is not being
pulled automatically through when trying to add the
ArkUserContactGUID:

OperationalError: (OperationalError) (1364, Field 'user_id' doesn't
have a default value) 'INSERT INTO `user_contact_UID_table`
(contact_id, uid) VALUES (%s, %s)' (2L,
'http://www.google.com/m8/feeds/contacts/jules%40kettlestudio.co.uk/base/7c5456c108b2111b')

File 'C:\\ark\\ark\\controllers\\contacts.py', line 368 in initial_sync
  contact_sync.initial_sync()
File 'C:\\ark\\ark\\arkTools\\arkGoogle.py', line 121 in initial_sync
  self.add_contact_to_google(contact)
File 'C:\\ark\\ark\\arkTools\\arkGoogle.py', line 263 in add_contact_to_google
  meta.Session.commit()
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\scoping.py',
line 113 in do
  return getattr(self.registry(), name)(*args, **kwargs)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\session.py',
line 617 in commit
  self.transaction.commit()
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\session.py',
line 293 in commit
  self._prepare_impl()
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\session.py',
line 277 in _prepare_impl
  self.session.flush()
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\session.py',
line 1473 in flush
  self._flush(objects)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\session.py',
line 1542 in _flush
  flush_context.execute()
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\unitofwork.py',
line 327 in execute
  rec.execute(self)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\unitofwork.py',
line 471 in execute
  uow
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\orm\\mapper.py',
line 2163 in _save_obj
  execute(statement, params)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\engine\\base.py',
line 1358 in execute
  params)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\engine\\base.py',
line 1491 in _execute_clauseelement
  compiled_sql, distilled_params
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\engine\\base.py',
line 1599 in _execute_context
  context)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\engine\\base.py',
line 1592 in _execute_context
  context)
File 
'C:\\ark\\env_x64\\lib\\site-packages\\sqlalchemy-0.7.1-py2.6.egg\\sqlalchemy\\engine\\default.py',
line 325 in do_execute
  cursor.execute(statement, parameters)
File 'C:\\ark\\env_x64\\lib\\site-packages\\MySQLdb\\cursors.py', line
173 in execute
  self.errorhandler(self, exc, value)
File 'C:\\ark\\env_x64\\lib\\site-packages\\MySQLdb\\connections.py',
line 36 in defaulterrorhandler
  raise errorclass, errorvalue
OperationalError: (OperationalError) (1364, Field 'user_id' doesn't
have a default value) 'INSERT INTO `user_contact_UID_table`
(contact_id, uid) VALUES (%s, %s)' (2L,
'http://www.google.com/m8/feeds/contacts/jules%40kettlestudio.co.uk/base/7c5456c108b2111b')

I think this is because the contacts object uses a many to many
relationship (a contact can belong to any or all users), code as
follows:

# ArkContact - clientprojectshot module
orm.mapper(ArkContact, contacts_table, properties={
'notes': orm.relation(ArkNote,
secondary=contact_notes_table,
backref='contacts',
single_parent=True,
cascade=all, delete, delete-orphan),
'users': orm.relation(ArkUser,
secondary=user_contact_table,
backref='contacts'),
'google_UID': orm.relation(ArkUserContactGUID,
cascade=all, delete,
uselist=False,
backref='user')
})


I'm thinking I should join between the user and ArkUserContactGUID
somehow, but don't know how...

Many thanks,

Jules

On Thu, Jun 16, 2011 at 2:04 PM, King Simon-NFHD78
simon.k...@motorolasolutions.com wrote:
 -Original Message-
 From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com]
 On Behalf Of Jules Stevenson
 Sent: 16 June 2011 08:44
 To: sqlalchemy@googlegroups.com
 Subject: [sqlalchemy] mapping a class linked with two other classes
 (AttributeError: 'str' object has no attribute '_sa_instance_state')

 Hi List,

 I have a user class, a contact class, and a googleID class.

 the contact class has can have a googleID per user in the system. I'm
 trying to map it out as follows:

 # ArkContact - clientprojectshot module
 orm.mapper(ArkContact, contacts_table, properties={
     'notes': orm.relation(ArkNote,
             secondary

Re: [sqlalchemy] mapping a class linked with two other classes (AttributeError: 'str' object has no attribute '_sa_instance_state')

2011-06-16 Thread Jules Stevenson
Ack, ignore :). There was no direct relationship to the user at all,
doh. So I'm passing that into the ArkUserContactGUID construction, and
all works well.

Thanks again for the help, much appreciated.

Jules

-- 
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: Trying to query a relationship of a relationship

2011-06-09 Thread Jules Stevenson
I don't think the info I sent last night was particularly clear,
apologies it was late. The code for the classes is below:

# ArkClient - clientprojectshot module
orm.mapper(ArkClient, clients_table, properties={
   'contacts':orm.relation(ArkContact,
           backref='client'),
   'projects':orm.relation(ArkProject,
           backref='client',
           cascade=all, delete, delete-orphan)
})

# ArkProject - clientprojectshot module
orm.mapper(ArkProject, projects_table, properties={
   'contacts': orm.relation(ArkContact,
           secondary=project_contact_table,
           backref='projects'),
   'invoices':orm.relation(ArkInvoice,
           backref='project',
           cascade=all, delete),
   'shots':orm.relation(ArkShot,
           backref='project',
           cascade=all, delete, delete-orphan),
   'users':orm.relation(ArkUser,
           backref='projects',
           secondary=user_projects_primary_table)
})

# ArkInvoice - invoices module
orm.mapper(ArkInvoice, invoices_table, properties={
'entries': orm.relation(ArkInvoiceEntry,
secondary=invoice_entries_primary_table,
backref='invoice',
cascade=all, delete),
'user': orm.relation(ArkUser, backref='invoice'),
'child_invoices':orm.relation(ArkInvoice,
backref=backref('parent_invoice',
remote_side=[invoices_table.c.id]),
cascade=all,
lazy=False,
join_depth=3)
})

What I am trying to do is query the client of an invoice, and to do
this I need to build a query something along the lines of:

invoice  project  client, and filter by client, or at least I thnk I
need to do this.

So the current query code I have looks something like this:

  invoices = query(ArkInvoice).\
join(ArkInvoice.project).\
join(ArkProject.client).\

options(sa.orm.contains_eager(model.ArkInvoice.project.client)).\
filter(model.ArkInvoice.project.client.id == id)

But this doesn't work, and I've tried many variations around this
theme with no joy. I'm clearly missing something fundamental, but I'm
not sure what. Any pointers gratefully received.

Many thanks,

Jules


On Wed, Jun 8, 2011 at 9:56 PM, Jules Stevenson
droolz...@googlemail.com wrote:
 sorry, hit the send button a little too soon.

 Any help on the above much appreciated,

 Jules


-- 
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: Trying to query a relationship of a relationship

2011-06-09 Thread Jules Stevenson
Sorry, for the spamming, code typo (was trying to simplify it), should read:

  invoices = query(ArkInvoice).\
join(ArkInvoice.project).\
join(ArkProject.client).\
options(sa.orm.contains_eager(ArkInvoice.project.client)).\
filter(ArkInvoice.project.client.id == id)

On Thu, Jun 9, 2011 at 8:50 AM, Jules Stevenson
droolz...@googlemail.com wrote:
 I don't think the info I sent last night was particularly clear,
 apologies it was late. The code for the classes is below:

 # ArkClient - clientprojectshot module
 orm.mapper(ArkClient, clients_table, properties={
    'contacts':orm.relation(ArkContact,
            backref='client'),
    'projects':orm.relation(ArkProject,
            backref='client',
            cascade=all, delete, delete-orphan)
 })

 # ArkProject - clientprojectshot module
 orm.mapper(ArkProject, projects_table, properties={
    'contacts': orm.relation(ArkContact,
            secondary=project_contact_table,
            backref='projects'),
    'invoices':orm.relation(ArkInvoice,
            backref='project',
            cascade=all, delete),
    'shots':orm.relation(ArkShot,
            backref='project',
            cascade=all, delete, delete-orphan),
    'users':orm.relation(ArkUser,
            backref='projects',
            secondary=user_projects_primary_table)
 })

 # ArkInvoice - invoices module
 orm.mapper(ArkInvoice, invoices_table, properties={
    'entries': orm.relation(ArkInvoiceEntry,
            secondary=invoice_entries_primary_table,
            backref='invoice',
            cascade=all, delete),
    'user': orm.relation(ArkUser, backref='invoice'),
    'child_invoices':orm.relation(ArkInvoice,
            backref=backref('parent_invoice',
 remote_side=[invoices_table.c.id]),
            cascade=all,
            lazy=False,
            join_depth=3)
 })

 What I am trying to do is query the client of an invoice, and to do
 this I need to build a query something along the lines of:

 invoice  project  client, and filter by client, or at least I thnk I
 need to do this.

 So the current query code I have looks something like this:

      invoices = query(ArkInvoice).\
                join(ArkInvoice.project).\
                join(ArkProject.client).\

 options(sa.orm.contains_eager(model.ArkInvoice.project.client)).\
                filter(model.ArkInvoice.project.client.id == id)

 But this doesn't work, and I've tried many variations around this
 theme with no joy. I'm clearly missing something fundamental, but I'm
 not sure what. Any pointers gratefully received.

 Many thanks,

 Jules


 On Wed, Jun 8, 2011 at 9:56 PM, Jules Stevenson
 droolz...@googlemail.com wrote:
 sorry, hit the send button a little too soon.

 Any help on the above much appreciated,

 Jules



-- 
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] Trying to query a relationship of a relationship

2011-06-08 Thread Jules Stevenson
Hi List,

I'm inexperienced with DBs so please bear with me.

I would like to return a list of all invoices that are assigned to a
specific client. However the relationships are built so that an
invoice has a foreign key to a project, which in turn has a foreign
key to a client:

Invoice.project  project.client  client

or in reverse

client.projects  project.invoices  invoice[s]

I've really been struggling as how to implement this, from what I've
been reading I want to join these relationships so that I can actually
filter the results, but Im having no luck at implementing this, my
nasty code is below:

   invoices = query(ArkInvoice).\
 join(ArkInvoice.project).\
 join(ArkProject.client).\

options(sa.orm.contains_eager(model.ArkInvoice.project.client)).\
 filter(model.ArkInvoice.project.client.id == id)

Which fails on the instrumented list of 'client' on the contains_eager.

-- 
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: Trying to query a relationship of a relationship

2011-06-08 Thread Jules Stevenson
sorry, hit the send button a little too soon.

Any help on the above much appreciated,

Jules

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



Re: [sqlalchemy] Problem with Joined Table inheritance

2010-07-13 Thread Jules Stevenson
Thankyou all, makes sense. foolishly I was looking at the 5.8.0 docs
which don;t include the example classes, but should have worked it out
regardless.

Thanks again, Jules

On Tue, Jul 13, 2010 at 3:18 PM, Stefano Bartaletti
stefano.bartale...@gmail.com wrote:
 class ArkWebVideoWidget(object):

 should be

 class ArkWebVideoWidget(ArkWebWidget):

 --
 Beauty is a pair of shoes that makes you wanna die

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



[sqlalchemy] Threading and session

2010-01-12 Thread Jules Stevenson
Hi List,

I've been trying to work out exactly how I can safely use the session
object in a threaded application. I've read the session docs, and
posts such as this one:

http://mail.google.com/mail/#search/label%3Asqlalchemy+session+threading/1259f8c18a4d2578

But I am struggling a little, but I think it may have more to do with
the 'design' of the app. The app looks at a db table for 'events' to
process. A threadpool periodically takes these mapped db objects and
puts them into a list, and then threads pick up these tasks. Each
thread has it's own session object.

This is giving me all the usual MySQL threading type issues that
others encounter. I have a hunch as to what the problem is (and is
just a hunch, so apologies if totally wrong): because the 'queued'
tasks are mapped dbobjects, they we're created in another session?
Therefore they don't play well with the thread's local session?

I have got it to work by using threading.lock() and a single session,
but this goes against everything that I read about using sessions.

Any help would be much appreciated, and please let me know if  you
need more information.

Jules
-- 
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.




Re: [sqlalchemy] Threading and session

2010-01-12 Thread Jules Stevenson
 most likely.  when a thread in your queue gets a hold of a new object, 
 merge() it into the local session, using the returned object.   or when you 
 put objects on the queue, expunge() them from their source session first.  
 that way you dont use state which is still associated with the originating 
 session.

Thanks Michael, I've got expunge working and this gets rid of the
errors, but from what I understand of the docs this means that the
expunged object will not return any deeper db info as it's now
detached - is there a way of adding it back into the worker threads
session? I think this what merge does, but I'm unsure of its usage -
do I call merge from the threadpool session on the object and put that
in the list, then add the object to the threads session? Any quick
examples or links would be much appreciated.

Jules
-- 
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.




Re: [sqlalchemy] Threading and session

2010-01-12 Thread Jules Stevenson
Worked it out, sorry for the noise.

self.task = self.Session.merge(self.task)
-- 
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.




Re: [sqlalchemy] foreign key to *any* other class?

2010-01-11 Thread Jules Stevenson
Thanks Michael, very useful.
-- 
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.




[sqlalchemy] foreign key to *any* other class?

2010-01-10 Thread Jules Stevenson
Sorry for the bad subject, and probably incorrect terminology but is
it possible to set up a table that would allow a foreign key link (or
any other technique) that would enable it to bind against *any* other
mapped class?

The context for this is there is a DB table that stores tasks to be
executed. These tasks could relate to lots and lots of other mapped
classes, and essentially I'd just like to be able to call:

sentinelTask.dbObject

where dbObject could be a user, project, client or any other allready
mapped class.

Is this possible? What should the DB structure be to set this sort of
relationship up.

Sorry if this is just plain stupid, any pointers much appreciated.

Jules
-- 
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.




[sqlalchemy] Re: Adjacency list problem

2009-08-13 Thread Jules Stevenson

 the mapping seems perfect to me.  parent_invoice would only be None for
 the actual parent.  perhaps there's some issue with your usage.   check
 your SQL echoing to make sure things are as expected.

My bad, was using 5.0, not 5.5 - just upgraded and it works fine.

--~--~-~--~~~---~--~~
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] Newbie: Adding a column after database table has been created, declarative

2008-11-10 Thread Jules Stevenson

Hi,

Apologies for lowering the general IQ of the list, I'm very new to web apps
and databases.

I had a declarative table:

class ArkContact(Base):

table of all contacts

__tablename__ = 'contacts'

id = Column(Integer, primary_key=True)
project_id = Column(Integer, ForeignKey('projects.id'))
client_id = Column(Integer, ForeignKey('clients.id'))
firstname = Column(String)
lastname = Column(String)
email1 = Column(String)
email2 = Column(String)
workphone = Column(Integer)
mobile = Column(Integer)
project = relation(ArkProject, backref=backref('contacts',
order_by=func.lower(firstname)))
client = relation(ArkClient, backref=backref('contacts',
order_by=func.lower(firstname)))

All is good,

I added a new column in:

lastcontact = Column(DateTime)

Now I'm getting errors when I try to connect:

class 'sqlalchemy.exc.OperationalError': (OperationalError) no such
column: contacts.lastcontact u'SELECT contacts.id AS contacts_id,
contacts.project_id AS contacts_project_id, contacts.client_id AS
contacts_client_id, contacts.firstname AS contacts_firstname,
contacts.lastname AS contacts_lastname, contacts.email1 AS contacts_email1,
contacts.email2 AS contacts_email2, contacts.workphone AS
contacts_workphone, contacts.mobile AS contacts_mobile, contacts.lastcontact
AS contacts_lastcontact \nFROM contacts ORDER BY lower(contacts.firstname)'
[]  

Am I being extremely naive in thinking there would be some way of 'updating'
the table to show the new column?

Many thanks,

Jules


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