473,382 Members | 1,583 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
1 1378
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Jacobs | last post by:
I attempt to back up a database on one server and restore it on my local machine. This is what the query text looks like: restore database model from Disk='c:\JQJ\mydump\model.bak' with...
6
by: Jay King | last post by:
Well so far I've been directed to Access (when I asked for a free solution), I'be also been directed to firebird. I then asked how with firebird do I create the initial database, and setup the...
8
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well....
1
by: combs5703 | last post by:
We've set up our DB2 database on a separate server than our application server (both UNIX). Now when I issue the connect statement, I also need to pass the user id and the password. All our...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.