471,620 Members | 1,281 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

A weird problem (adodb + mysql)

Hi to all,

I'm using adodb for accessing mysql and postgres. My problem relies on
the mysql access.

Sometimes, when I try to execute a query (using ExecTrans method
below), I get this error:

'NoneType' object has no attribute 'cursor'

Maybe this error ocurrs not in my code, but in the mysql module. Does
anyone had had this problem?

Thanks.

The following is my DB connection class.

class DB:
def __init__(self, host=None, user=None, password=None,
database=None):
self.host =
[host,variables.IP_DB][isinstance(host,(types.NoneType))]
self.user =
[user,variables.USER][isinstance(user,(types.NoneType))]
self.password =
[password,variables.PASSWORD][isinstance(password,(types.NoneType))]
self.database =
[database,variables.DATABASE][isinstance(database,(types.NoneType))]

self.bActive = True
self.bConnected = False

def OpenDB(self):

success = False
if self.bActive:
try:
self.conn = adodb.NewADOConnection('mysql')
if not self.conn:
Log.log("Can't connecto to DB-Mysql")
success = False
else :
#Create the connection
ret = self.conn.Connect(self.host, self.user,
self.password, self.database)
if ret:
Log.log("DB-Mysql connection stablished")
success = True
except:
success = False
pass
else:
print "DB connection disabled"
self.bConnected = success
return success

def Exec(self,query,simple=False):
resultado = list()

#Open a DB connection
if self.OpenDB():
Log.log("Executing Query: " + str(query))
cursor = self.conn.Execute(query)
if cursor:
while not cursor.EOF:
if not simple:
resultado.append(cursor.GetRowAssoc())
cursor.MoveNext()
else :
resultado.append(cursor.FetchRow())
#Close Cursor
cursor.Close()
else:
resultado = None
self.CloseDB()
else:
resultado = None
return resultado

def ExecTrans(self, lQueries):

success = False
if self.OpenDB():
print "Executing Querys: " + str(lQueries)

#Begin Transaction
self.conn.BeginTrans()

#Execute each query in lQueries
for query in lQueries:
self.conn.Execute(query)
if self.conn._errno != 0 :
success = False
break;
else:
success = True

#End of transaction
if success:
self.conn.CommitTrans()
else:
self.conn.RollbackTrans()

#Closing DB
self.CloseDB()
return success

def TestConnection(self):
if self.OpenDB():
self.CloseDB()
return True
return False

def CloseDB(self):
if self.conn.IsConnected() :
self.conn.Close()
return

Jan 5 '06 #1
0 1474

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Ian.H | last post: by
1 post views Thread by skeeterbug | last post: by
5 posts views Thread by Bill | last post: by
reply views Thread by CountDraculla | last post: by
3 posts views Thread by Tom | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.