467,087 Members | 1,283 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,087 developers. It's quick & easy.

Database objects? Persistence? Sql Server woes


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-objec...html#a11866779
Sent from the Python - python-list mailing list archive at Nabble.com.

Jul 30 '07 #1
  • viewed: 1167
Share:
1 Reply
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/Coo.../Recipe/302088

Store a connection per thread.

Diez
Jul 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jon Jacobs | last post: by
6 posts views Thread by Jay King | last post: by
8 posts views Thread by morleyc@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.