123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- """MySQL Database implementation."""
- from __future__ import print_function
- from pwman.data.database import Database
- import MySQLdb as mysql
- import pwman.util.config as config
- class MySQLDatabase(Database):
- @classmethod
- def check_db_version(cls, dburi):
- port = 3306
- credentials, host = dburi.netloc.split('@')
- user, passwd = credentials.split(':')
- if ':' in host:
- host, port = host.split(':')
- port = int(port)
- try:
- con = mysql.connect(host=host, port=port, user=user, passwd=passwd,
- db=dburi.path.lstrip('/'))
- cur = con.cursor()
- cur.execute("SELECT VERSION FROM DBVERSION")
- version = cur.fetchone()
- cur.close()
- con.close()
- return version[-1]
- except mysql.ProgrammingError:
- con.rollback()
|