Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cron_classes.py Message = ['DB connexion error!', 'Error SQL request: "'GestionBD' object has no attribute 'cursor'" : [INSERT INTO traitements (admin, date, timestamp, code_dept) VALUES (True, '2018-06-25', '2018-06-25 09:26', 84)]']
- $ python
- Python 2.7.9 (default, Jun 29 2016, 13:08:31)
- [GCC 4.9.2] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import psycopg2
- >>> conn = psycopg2.connect("host=localhost dbname=xxx password=xxx user=xxx")
- >>> cur=conn.cursor()
- >>> cur.execute("select * from departements")
- >>> cur.fetchall()
- .. some datas
- >>> cur.execute("INSERT INTO traitements (admin, date, timestamp, code_dept) VALUES (True, '2018-06-25', '2018-06-25 14:50', 84)")
- >>> conn.commit()
- >>> cur.execute("select * from traitements order by date desc limit 1")
- >>> cur.fetchall()
- [(1236, True, datetime.date(2018, 6, 25), datetime.datetime(2018, 6, 25, 14, 50), 84)]
- def recordTreatment(self):
- self.connectDB()
- now = datetime.now()
- # enregistrement de l'operation
- request = "INSERT INTO traitements (admin, date, timestamp, code_dept) VALUES (%s, '%s', '%s', %s)" % (self.config.MANAGER.get('admin'), self.demain.date(), now.strftime('%Y-%m-%d %H:%M'), self.config.MANAGER.get('code_dept'))
- logging.info("insertTreatment request = %s" % (request,))
- if not self.db.executeReq(request):
- self.exit('critical', self.db.messerr)
- class GestionBD(object):
- def __init__(self, dbname='massifs', user='postgres', passwd='postgres'):
- self.params = "dbname=%s user=%s password=%s" % (dbname, user, passwd)
- self.messerr = None
- try:
- self.conne = psycopg2.connect(self.params)
- except psycopg2.OperationalError as err:
- self.messerr = 'Erreur connexion: %s' % (err, )
- self.echec = 1
- else:
- self.cursor = self.conne.cursor()
- self.echec = 0
Add Comment
Please, Sign In to add comment