Browse Source

[notebook] Set SQL as the default type of highlighting

The generic JDBC and HS2 API favorize more SQL languages than
brand new ones.

Also make sure we don't leak any JDBC connection.
Romain Rigaux 10 years ago
parent
commit
145bcf2

+ 12 - 7
desktop/libs/notebook/src/notebook/connectors/jdbc.py

@@ -48,16 +48,21 @@ class JdbcApi(Api):
   def execute(self, notebook, snippet):
 
     db = Jdbc(self.options['driver'], self.options['url'], self.options['user'], self.options['password'])
-    db.connect()
 
-    curs = db.cursor()
-    curs.execute(snippet['statement'])
+    try:
+      db.connect()
+
+      curs = db.cursor()
 
-    data = curs.fetchmany(100)
-    description = curs.description
+      try:
+        curs.execute(snippet['statement'])
 
-    curs.close()
-    db.close()
+        data = curs.fetchmany(100)
+        description = curs.description
+      finally:
+        curs.close()
+    finally:
+      db.close()
 
     return {
       'sync': True,

+ 5 - 10
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -925,6 +925,11 @@ from desktop.views import _ko
 
   var SNIPPET_VIEW_SETTINGS = {
     default: {
+      placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
+      aceMode: 'ace/mode/sql',
+      snippetIcon: 'fa-database'
+    },
+    code: {
       placeHolder: '${ _("Example: 1 + 1, or press CTRL + space") }',
       snippetIcon: 'fa-code'
     },
@@ -941,16 +946,6 @@ from desktop.views import _ko
     jar : {
       snippetIcon: 'fa-file-archive-o '
     },
-    mysql: {
-      placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
-      aceMode: 'ace/mode/sql',
-      snippetIcon: 'fa-database'
-    },
-    mysqljdbc: {
-      placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
-      aceMode: 'ace/mode/sql',
-      snippetIcon: 'fa-database'
-    },
     pig: {
       placeHolder: '${ _("Example: 1 + 1, or press CTRL + space") }',
       aceMode: 'ace/mode/pig',