|
@@ -15,6 +15,8 @@
|
|
|
# See the License for the specific language governing permissions and
|
|
# See the License for the specific language governing permissions and
|
|
|
# limitations under the License.
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
|
|
+from builtins import range
|
|
|
|
|
+from builtins import object
|
|
|
import logging
|
|
import logging
|
|
|
import os
|
|
import os
|
|
|
import sys
|
|
import sys
|
|
@@ -28,7 +30,7 @@ LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
from py4j.java_gateway import JavaGateway, JavaObject
|
|
from py4j.java_gateway import JavaGateway, JavaObject
|
|
|
-except ImportError, e:
|
|
|
|
|
|
|
+except ImportError as e:
|
|
|
LOG.exception('Failed to import py4j')
|
|
LOG.exception('Failed to import py4j')
|
|
|
|
|
|
|
|
|
|
|
|
@@ -45,7 +47,7 @@ def query_and_fetch(db, statement, n=None):
|
|
|
return data, meta
|
|
return data, meta
|
|
|
finally:
|
|
finally:
|
|
|
curs.close()
|
|
curs.close()
|
|
|
- except Exception, e:
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
message = force_unicode(smart_str(e))
|
|
message = force_unicode(smart_str(e))
|
|
|
if 'Access denied' in message:
|
|
if 'Access denied' in message:
|
|
|
raise AuthenticationRequired()
|
|
raise AuthenticationRequired()
|
|
@@ -54,7 +56,7 @@ def query_and_fetch(db, statement, n=None):
|
|
|
db.close()
|
|
db.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
-class Jdbc():
|
|
|
|
|
|
|
+class Jdbc(object):
|
|
|
|
|
|
|
|
def __init__(self, driver_name, url, username, password, impersonation_property=None, impersonation_user=None):
|
|
def __init__(self, driver_name, url, username, password, impersonation_property=None, impersonation_user=None):
|
|
|
if 'py4j' not in sys.modules:
|
|
if 'py4j' not in sys.modules:
|
|
@@ -81,7 +83,7 @@ class Jdbc():
|
|
|
try:
|
|
try:
|
|
|
self.connect()
|
|
self.connect()
|
|
|
return True
|
|
return True
|
|
|
- except Exception, e:
|
|
|
|
|
|
|
+ except Exception as e:
|
|
|
message = force_unicode(smart_str(e))
|
|
message = force_unicode(smart_str(e))
|
|
|
if throw_exception:
|
|
if throw_exception:
|
|
|
if 'Access denied' in message:
|
|
if 'Access denied' in message:
|
|
@@ -106,7 +108,7 @@ class Jdbc():
|
|
|
self.conn = None
|
|
self.conn = None
|
|
|
|
|
|
|
|
|
|
|
|
|
-class Cursor():
|
|
|
|
|
|
|
+class Cursor(object):
|
|
|
"""Similar to DB-API 2.0 Cursor interface"""
|
|
"""Similar to DB-API 2.0 Cursor interface"""
|
|
|
|
|
|
|
|
def __init__(self, conn):
|
|
def __init__(self, conn):
|
|
@@ -130,9 +132,9 @@ class Cursor():
|
|
|
def fetchmany(self, n=None):
|
|
def fetchmany(self, n=None):
|
|
|
res = []
|
|
res = []
|
|
|
|
|
|
|
|
- while self.rs.next() and (n is None or n > 0):
|
|
|
|
|
|
|
+ while next(self.rs) and (n is None or n > 0):
|
|
|
row = []
|
|
row = []
|
|
|
- for c in xrange(self._meta.getColumnCount()):
|
|
|
|
|
|
|
+ for c in range(self._meta.getColumnCount()):
|
|
|
cell = self.rs.getObject(c + 1)
|
|
cell = self.rs.getObject(c + 1)
|
|
|
|
|
|
|
|
if isinstance(cell, JavaObject):
|
|
if isinstance(cell, JavaObject):
|
|
@@ -161,7 +163,7 @@ class Cursor():
|
|
|
self._meta.getPrecision(i),
|
|
self._meta.getPrecision(i),
|
|
|
self._meta.getScale(i),
|
|
self._meta.getScale(i),
|
|
|
self._meta.isNullable(i),
|
|
self._meta.isNullable(i),
|
|
|
- ] for i in xrange(1, self._meta.getColumnCount() + 1)]
|
|
|
|
|
|
|
+ ] for i in range(1, self._meta.getColumnCount() + 1)]
|
|
|
|
|
|
|
|
def close(self):
|
|
def close(self):
|
|
|
self._meta = None
|
|
self._meta = None
|