Database objects? Persistence? Sql Server woes

Discussion in 'Python' started by Mike Howarth, Jul 30, 2007.

  1. Mike Howarth

    Mike Howarth Guest

    I've been having a few problems with connecting to SQL Server, initially I
    was using dblib however found some problems with returning text fields
    whereby all text fields were ignored and it bawked at multiline sql
    statements.

    Having found these major stumbling blocks I've started using pymssql which
    seems less flaky. One problem I've stumbled across is that I seem to reach
    my max connections on the database fairly easily (given how my script was
    written) and therefore have used the singleton pattern on my database
    object.

    Great problem solved, or so I thought.

    Using the following code I'm finding that the Set is now also being enforced
    as a singleton as well.

    class Set(Database,Product):

    def __init__(self, *args, **kw):

    Database.__init__(self)
    Product.__init__(self)

    def dosomething(self):
    cu = self.c.cursor()

    Having sat back and thought about it, its easy to understand why this is
    occurring given I'm indicating that Set belongs to Database and therefore
    this is a singleton as well.

    Being relatively new to Python I'm unsure on how to then go about using a
    database object between each class. Can anyone advise me on how they
    approach this, and whether there is a common approach to this?

    --
    View this message in context: http://www.nabble.com/Database-objects--Persistence--Sql-Server-woes-tf4171199.html#a11866779
    Sent from the Python - python-list mailing list archive at Nabble.com.
     
    Mike Howarth, Jul 30, 2007
    #1
    1. Advertising

  2. Mike Howarth schrieb:
    > I've been having a few problems with connecting to SQL Server, initially I
    > was using dblib however found some problems with returning text fields
    > whereby all text fields were ignored and it bawked at multiline sql
    > statements.
    >
    > Having found these major stumbling blocks I've started using pymssql which
    > seems less flaky. One problem I've stumbled across is that I seem to reach
    > my max connections on the database fairly easily (given how my script was
    > written) and therefore have used the singleton pattern on my database
    > object.
    >
    > Great problem solved, or so I thought.
    >
    > Using the following code I'm finding that the Set is now also being enforced
    > as a singleton as well.
    >
    > class Set(Database,Product):
    >
    > def __init__(self, *args, **kw):
    >
    > Database.__init__(self)
    > Product.__init__(self)
    >
    > def dosomething(self):
    > cu = self.c.cursor()
    >
    > Having sat back and thought about it, its easy to understand why this is
    > occurring given I'm indicating that Set belongs to Database and therefore
    > this is a singleton as well.
    >
    > Being relatively new to Python I'm unsure on how to then go about using a
    > database object between each class. Can anyone advise me on how they
    > approach this, and whether there is a common approach to this?


    You might consider using a ORM mapper, like SQLObject or SQLAlchemy. If
    they support your backend, that is.

    Apart from that, this might help:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302088

    Store a connection per thread.

    Diez
     
    Diez B. Roggisch, Jul 30, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rico
    Replies:
    2
    Views:
    435
  2. Andy Grove
    Replies:
    0
    Views:
    453
    Andy Grove
    Nov 4, 2003
  3. javaguy44
    Replies:
    10
    Views:
    1,011
    Michael Berg
    May 18, 2004
  4. dohertywa
    Replies:
    2
    Views:
    287
    dohertywa
    Sep 17, 2007
  5. Kenneth P. Turvey

    Java Persistence API and persistence.xml

    Kenneth P. Turvey, Mar 15, 2008, in forum: Java
    Replies:
    2
    Views:
    17,514
    Kenneth P. Turvey
    Mar 16, 2008
Loading...

Share This Page