Manage DB disconnection
This commit is contained in:
parent
d61c64112a
commit
0bdae5c0f4
1 changed files with 82 additions and 65 deletions
|
@ -25,8 +25,17 @@ class DB(object):
|
|||
except Exception, e:
|
||||
log.fatal('Error connecting to database : %s' % e)
|
||||
return
|
||||
else:
|
||||
try:
|
||||
self.con.ping(True)
|
||||
except Exception, e:
|
||||
self.con = 0
|
||||
return self.connect()
|
||||
return True
|
||||
|
||||
|
||||
def do_sql(self,sql):
|
||||
if self.connect():
|
||||
try:
|
||||
c=self.con.cursor()
|
||||
c.execute(sql)
|
||||
|
@ -37,12 +46,14 @@ class DB(object):
|
|||
return False
|
||||
|
||||
def select(self,sql):
|
||||
if self.connect():
|
||||
ret=self.do_sql(sql)
|
||||
if ret!=False:
|
||||
return ret.fetchall()
|
||||
return ret
|
||||
|
||||
def login(self,email,password):
|
||||
if self.connect():
|
||||
ret=self.select("SELECT email,name,password FROM users WHERE email='%s' AND password='%s'" % (email,password))
|
||||
log.debug(ret)
|
||||
if ret:
|
||||
|
@ -58,6 +69,7 @@ class DB(object):
|
|||
return { 'loginerror': 'Erreur inconnu' }
|
||||
|
||||
def subscribe(self,email,name,password):
|
||||
if self.connect():
|
||||
ret=self.select("SELECT count(*) as count FROM users WHERE email='%s'" % (email))
|
||||
log.debug(ret)
|
||||
if ret[0][0]!=0:
|
||||
|
@ -72,6 +84,7 @@ class DB(object):
|
|||
return {'subscribeerror': u'Une erreur est survenue durant votre inscription :('}
|
||||
|
||||
def sync_group(self,email,groups):
|
||||
if self.connect():
|
||||
db_groups=self.get_group(email)
|
||||
if db_groups!=False:
|
||||
db_grouplist=group.GroupList()
|
||||
|
@ -85,8 +98,11 @@ class DB(object):
|
|||
else:
|
||||
return {'syncerror': 'Erreur en modifiant les informations de la base de donnees'}
|
||||
return {'syncerror': 'Erreur inconnu'}
|
||||
else:
|
||||
return {'syncerror': u"Erreur de connexion à la base de données"}
|
||||
|
||||
def get_group(self,email):
|
||||
if self.connect():
|
||||
ret=self.select("SELECT groups FROM groups WHERE email='%s'" % email)
|
||||
if ret!=False:
|
||||
if len(ret)==1:
|
||||
|
@ -97,6 +113,7 @@ class DB(object):
|
|||
return False
|
||||
|
||||
def set_group(self,email,groups):
|
||||
if self.connect():
|
||||
ret=self.select("SELECT groups FROM groups WHERE email='%s'" % email)
|
||||
if ret!=False:
|
||||
json_groups=json.dumps(groups)
|
||||
|
|
Loading…
Reference in a new issue