You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by le...@apache.org on 2005/07/07 19:42:45 UTC
svn commit: r209622 - /gump/branches/Gump3/pygump/python/gump/util/mysql.py
Author: leosimons
Date: Thu Jul 7 10:42:45 2005
New Revision: 209622
URL: http://svn.apache.org/viewcvs?rev=209622&view=rev
Log:
Make db a lot less verbose in the case of a failing connection
Modified:
gump/branches/Gump3/pygump/python/gump/util/mysql.py
Modified: gump/branches/Gump3/pygump/python/gump/util/mysql.py
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/util/mysql.py?rev=209622&r1=209621&r2=209622&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/util/mysql.py (original)
+++ gump/branches/Gump3/pygump/python/gump/util/mysql.py Thu Jul 7 10:42:45 2005
@@ -37,6 +37,7 @@
self.password = password
self.db = db
self._conn = None
+ self.connect_failed = False
def __del__(self):
self.close()
@@ -77,6 +78,10 @@
rows affected and the result set as a tuple of tuples, if there was a
result set, or None otherwise.
"""
+ if self.connect_failed:
+ self.log.error(" No connection, canned execute SQL statement:\n %s%s...%s" % (ansicolor.Blue, statement[0:20], ansicolor.Black))
+ return (0, None)
+
cursor = None
affected = 0
try:
@@ -101,20 +106,24 @@
if not self._conn:
import MySQLdb
import MySQLdb.cursors
- if self.password:
- self._conn = MySQLdb.Connect(
- host=self.host,
- user=self.user,
- passwd=self.password,
- db=self.db,
- compress=1,
- cursorclass=MySQLdb.cursors.DictCursor)
- else:
- self._conn = MySQLdb.Connect(
- host=self.host,
- user=self.user,
- db=self.db,
- compress=1,
- cursorclass=MySQLdb.cursors.DictCursor)
+ try:
+ if self.password:
+ self._conn = MySQLdb.Connect(
+ host=self.host,
+ user=self.user,
+ passwd=self.password,
+ db=self.db,
+ compress=1,
+ cursorclass=MySQLdb.cursors.DictCursor)
+ else:
+ self._conn = MySQLdb.Connect(
+ host=self.host,
+ user=self.user,
+ db=self.db,
+ compress=1,
+ cursorclass=MySQLdb.cursors.DictCursor)
+ except:
+ self.connect_failed = True
+ self.log.exception("Unable to get a connection to the database!")
return self._conn