From 1cb12ea6590de0afa77f41f0da69b89081e7f2dd Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Wed, 22 Jun 2011 13:31:07 +0000 Subject: [PATCH] replaced third-party library python-mysql with python pymysql, http://code.google.com/p/pymysql/ (MIT license) --- doc/README.sgml | 2 +- lib/core/common.py | 2 +- lib/core/settings.py | 2 +- lib/utils/deps.py | 2 +- plugins/dbms/mysql/connector.py | 22 +++++++++++----------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/README.sgml b/doc/README.sgml index 9edc77ba4..e7553e0bd 100644 --- a/doc/README.sgml +++ b/doc/README.sgml @@ -57,7 +57,7 @@ for the database management system that you are going to attack: Firebird: . Microsoft Access: . Microsoft SQL Server: . -MySQL: . +MySQL: . Oracle: . PostgreSQL: . SQLite: . diff --git a/lib/core/common.py b/lib/core/common.py index d5ddb6046..e3c31ecf0 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1036,7 +1036,7 @@ def parseTargetDirect(): raise sqlmapMissingDependence, errMsg elif dbmsName == DBMS.MYSQL: - import MySQLdb + import pymysql elif dbmsName == DBMS.PGSQL: import psycopg2 elif dbmsName == DBMS.ORACLE: diff --git a/lib/core/settings.py b/lib/core/settings.py index 3064d91ec..a17fb996a 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -159,7 +159,7 @@ SUPPORTED_DBMS = MSSQL_ALIASES + MYSQL_ALIASES + PGSQL_ALIASES + ORACLE_ALIASES SUPPORTED_OS = ( "linux", "windows" ) DBMS_DICT = { DBMS.MSSQL: [MSSQL_ALIASES, "python-pymssql", "http://pymssql.sourceforge.net/"], - DBMS.MYSQL: [MYSQL_ALIASES, "python-mysqldb", "http://mysql-python.sourceforge.net/"], + DBMS.MYSQL: [MYSQL_ALIASES, "python pymysql", "http://code.google.com/p/pymysql/"], DBMS.PGSQL: [PGSQL_ALIASES, "python-psycopg2", "http://initd.org/psycopg/"], DBMS.ORACLE: [ORACLE_ALIASES, "python cx_Oracle", "http://cx-oracle.sourceforge.net/"], DBMS.SQLITE: [SQLITE_ALIASES, "python-pysqlite2", "http://pysqlite.googlecode.com/"], diff --git a/lib/utils/deps.py b/lib/utils/deps.py index 8862a3228..e577f3d35 100644 --- a/lib/utils/deps.py +++ b/lib/utils/deps.py @@ -32,7 +32,7 @@ def checkDependencies(): warnMsg += "Download from %s" % data[2] logger.warn(warnMsg) elif dbmsName == DBMS.MYSQL: - import MySQLdb + import pymysql elif dbmsName == DBMS.PGSQL: import psycopg2 elif dbmsName == DBMS.ORACLE: diff --git a/plugins/dbms/mysql/connector.py b/plugins/dbms/mysql/connector.py index b4e853503..80f35d2de 100644 --- a/plugins/dbms/mysql/connector.py +++ b/plugins/dbms/mysql/connector.py @@ -8,7 +8,7 @@ See the file 'doc/COPYING' for copying permission """ try: - import MySQLdb + import pymysql except ImportError, _: pass @@ -20,11 +20,11 @@ from plugins.generic.connector import Connector as GenericConnector class Connector(GenericConnector): """ - Homepage: http://mysql-python.sourceforge.net/ - User guide: http://mysql-python.sourceforge.net/MySQLdb.html - API: http://mysql-python.sourceforge.net/MySQLdb-1.2.2/ - Debian package: python-mysqldb - License: GPL + Homepage: http://code.google.com/p/pymysql/ + User guide: http://code.google.com/p/pymysql/ + API: http://code.google.com/p/pymysql/ + Debian package: + License: MIT Possible connectors: http://wiki.python.org/moin/MySQL """ @@ -36,8 +36,8 @@ class Connector(GenericConnector): self.initConnection() try: - self.connector = MySQLdb.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True) - except MySQLdb.OperationalError, msg: + self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True) + except pymysql.OperationalError, msg: raise sqlmapConnectionException, msg[1] self.setCursor() @@ -46,16 +46,16 @@ class Connector(GenericConnector): def fetchall(self): try: return self.cursor.fetchall() - except MySQLdb.ProgrammingError, msg: + except pymysql.ProgrammingError, msg: logger.warn(msg[1]) return None def execute(self, query): try: self.cursor.execute(query) - except (MySQLdb.OperationalError, MySQLdb.ProgrammingError), msg: + except (pymysql.OperationalError, pymysql.ProgrammingError), msg: logger.warn(msg[1]) - except MySQLdb.InternalError, msg: + except pymysql.InternalError, msg: raise sqlmapConnectionException, msg[1] self.connector.commit()