|
@@ -17,10 +17,11 @@
|
|
|
|
|
|
|
|
import logging
|
|
import logging
|
|
|
import re
|
|
import re
|
|
|
-import sys
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
from desktop.lib.exceptions_renderable import PopupException
|
|
from desktop.lib.exceptions_renderable import PopupException
|
|
|
from desktop.lib.i18n import force_unicode
|
|
from desktop.lib.i18n import force_unicode
|
|
|
|
|
+from librdbms.jdbc import Jdbc
|
|
|
from django.utils.translation import ugettext as _
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
from notebook.connectors.base import Api, QueryError
|
|
from notebook.connectors.base import Api, QueryError
|
|
@@ -28,11 +29,6 @@ from notebook.connectors.base import Api, QueryError
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
-try:
|
|
|
|
|
- import jaydebeapi
|
|
|
|
|
-except ImportError, e:
|
|
|
|
|
- LOG.exception('Failed to import jaydebeapi')
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
def query_error_handler(func):
|
|
def query_error_handler(func):
|
|
|
def decorator(*args, **kwargs):
|
|
def decorator(*args, **kwargs):
|
|
@@ -54,45 +50,35 @@ class JDBCApi(Api):
|
|
|
# impersonation / prompting for username/password
|
|
# impersonation / prompting for username/password
|
|
|
@query_error_handler
|
|
@query_error_handler
|
|
|
def execute(self, notebook, snippet):
|
|
def execute(self, notebook, snippet):
|
|
|
- if 'jaydebeapi' not in sys.modules:
|
|
|
|
|
- raise Exception('Required jaydebeapi module is not imported.')
|
|
|
|
|
-
|
|
|
|
|
user = 'root'
|
|
user = 'root'
|
|
|
password = 'root'
|
|
password = 'root'
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
host = 'localhost'
|
|
host = 'localhost'
|
|
|
port = 3306
|
|
port = 3306
|
|
|
database = 'test'
|
|
database = 'test'
|
|
|
-
|
|
|
|
|
- autocommit = True
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
jclassname = "com.mysql.jdbc.Driver"
|
|
jclassname = "com.mysql.jdbc.Driver"
|
|
|
url = "jdbc:mysql://{host}:{port}/{database}".format(host=host, port=port, database=database)
|
|
url = "jdbc:mysql://{host}:{port}/{database}".format(host=host, port=port, database=database)
|
|
|
- driver_args = [url, user, password]
|
|
|
|
|
- jars = None
|
|
|
|
|
- libs = None
|
|
|
|
|
-
|
|
|
|
|
- db = jaydebeapi.connect(jclassname, driver_args, jars=jars, libs=libs)
|
|
|
|
|
- db.jconn.setAutoCommit(autocommit)
|
|
|
|
|
-
|
|
|
|
|
- curs = db.cursor()
|
|
|
|
|
- curs.execute(snippet['statement'])
|
|
|
|
|
-
|
|
|
|
|
- data = curs.fetchmany(100)
|
|
|
|
|
- description = curs.description
|
|
|
|
|
-
|
|
|
|
|
- curs.close()
|
|
|
|
|
- db.close()
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ db = Jdbc(jclassname, url, user, password)
|
|
|
|
|
+ db.connect()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ data, meta = db.execute(snippet['statement'])
|
|
|
|
|
+
|
|
|
|
|
+ db.disconnect()
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
'sync': True,
|
|
'sync': True,
|
|
|
'result': {
|
|
'result': {
|
|
|
'has_more': False,
|
|
'has_more': False,
|
|
|
'data': list(data),
|
|
'data': list(data),
|
|
|
'meta': [{
|
|
'meta': [{
|
|
|
- 'name': column[0],
|
|
|
|
|
- 'type': 'TODO',
|
|
|
|
|
|
|
+ 'name': column['name'],
|
|
|
|
|
+ 'type': column['type'],
|
|
|
'comment': ''
|
|
'comment': ''
|
|
|
- } for column in description],
|
|
|
|
|
|
|
+ } for column in meta],
|
|
|
'type': 'table'
|
|
'type': 'table'
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|