(self)
| 63 | self.address = re.sub(r"\A.+://", "%s://" % self.dialect, self.address) |
| 64 | |
| 65 | def connect(self): |
| 66 | if _sqlalchemy: |
| 67 | self.initConnection() |
| 68 | |
| 69 | try: |
| 70 | if not self.port and self.db: |
| 71 | if not os.path.exists(self.db): |
| 72 | raise SqlmapFilePathException("the provided database file '%s' does not exist" % self.db) |
| 73 | |
| 74 | _ = self.address.split("//", 1) |
| 75 | self.address = "%s////%s" % (_[0], os.path.abspath(self.db)) |
| 76 | |
| 77 | if self.dialect == "sqlite": |
| 78 | engine = _sqlalchemy.create_engine(self.address, connect_args={"check_same_thread": False}) |
| 79 | elif self.dialect == "oracle": |
| 80 | engine = _sqlalchemy.create_engine(self.address) |
| 81 | else: |
| 82 | engine = _sqlalchemy.create_engine(self.address, connect_args={}) |
| 83 | |
| 84 | self.connector = engine.connect() |
| 85 | except (TypeError, ValueError): |
| 86 | if "_get_server_version_info" in traceback.format_exc(): |
| 87 | try: |
| 88 | import pymssql |
| 89 | if int(pymssql.__version__[0]) < 2: |
| 90 | raise SqlmapConnectionException("SQLAlchemy connection issue (obsolete version of pymssql ('%s') is causing problems)" % pymssql.__version__) |
| 91 | except ImportError: |
| 92 | pass |
| 93 | elif "invalid literal for int() with base 10: '0b" in traceback.format_exc(): |
| 94 | raise SqlmapConnectionException("SQLAlchemy connection issue ('https://bitbucket.org/zzzeek/sqlalchemy/issues/3975')") |
| 95 | else: |
| 96 | pass |
| 97 | except SqlmapFilePathException: |
| 98 | raise |
| 99 | except Exception as ex: |
| 100 | raise SqlmapConnectionException("SQLAlchemy connection issue ('%s')" % getSafeExString(ex)) |
| 101 | |
| 102 | self.printConnected() |
| 103 | else: |
| 104 | raise SqlmapMissingDependence("SQLAlchemy not available (e.g. 'pip%s install SQLAlchemy')" % ('3' if six.PY3 else "")) |
| 105 | |
| 106 | def fetchall(self): |
| 107 | try: |
no test coverage detected