|
@@ -15,6 +15,7 @@
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
+import datetime
|
|
|
import json
|
|
import json
|
|
|
import logging
|
|
import logging
|
|
|
import uuid
|
|
import uuid
|
|
@@ -63,7 +64,7 @@ class SqlAlchemyApi(Api):
|
|
|
'result': result,
|
|
'result': result,
|
|
|
'meta': [{
|
|
'meta': [{
|
|
|
'name': col[0] if type(col) is dict or type(col) is tuple else col,
|
|
'name': col[0] if type(col) is dict or type(col) is tuple else col,
|
|
|
- 'type': 'String', #TODO: resolve
|
|
|
|
|
|
|
+ 'type': 'STRING_TYPE',
|
|
|
'comment': ''
|
|
'comment': ''
|
|
|
} for col in result.cursor.description]
|
|
} for col in result.cursor.description]
|
|
|
}
|
|
}
|
|
@@ -98,17 +99,33 @@ class SqlAlchemyApi(Api):
|
|
|
if cache:
|
|
if cache:
|
|
|
data = cache['result'].fetchmany(rows)
|
|
data = cache['result'].fetchmany(rows)
|
|
|
meta = cache['meta']
|
|
meta = cache['meta']
|
|
|
|
|
+ self._assign_types(data, meta)
|
|
|
else:
|
|
else:
|
|
|
data = []
|
|
data = []
|
|
|
meta = []
|
|
meta = []
|
|
|
- has_result_set = data is not None
|
|
|
|
|
return {
|
|
return {
|
|
|
- 'has_more': has_result_set and len(data) >= rows,
|
|
|
|
|
- 'data': data if has_result_set else [],
|
|
|
|
|
- 'meta': meta,
|
|
|
|
|
|
|
+ 'has_more': data and len(data) >= rows,
|
|
|
|
|
+ 'data': data if data else [],
|
|
|
|
|
+ 'meta': meta if meta else [],
|
|
|
'type': 'table'
|
|
'type': 'table'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ def _assign_types(self, results, meta):
|
|
|
|
|
+ result = results[0]
|
|
|
|
|
+ if result:
|
|
|
|
|
+ for index, col in enumerate(result):
|
|
|
|
|
+ if isinstance(col, int):
|
|
|
|
|
+ meta[index]['type'] = 'INT_TYPE'
|
|
|
|
|
+ elif isinstance(col, float):
|
|
|
|
|
+ meta[index]['type'] = 'FLOAT_TYPE'
|
|
|
|
|
+ elif isinstance(col, long):
|
|
|
|
|
+ meta[index]['type'] = 'BIGINT_TYPE'
|
|
|
|
|
+ elif isinstance(col, bool):
|
|
|
|
|
+ meta[index]['type'] = 'BOOLEAN_TYPE'
|
|
|
|
|
+ elif isinstance(col, datetime.date):
|
|
|
|
|
+ meta[index]['type'] = 'TIMESTAMP_TYPE'
|
|
|
|
|
+ else:
|
|
|
|
|
+ meta[index]['type'] = 'STRING_TYPE'
|
|
|
|
|
|
|
|
@query_error_handler
|
|
@query_error_handler
|
|
|
def fetch_result_metadata(self):
|
|
def fetch_result_metadata(self):
|
|
@@ -216,11 +233,20 @@ class SqlAlchemyApi(Api):
|
|
|
if sample_data:
|
|
if sample_data:
|
|
|
response['status'] = 0
|
|
response['status'] = 0
|
|
|
response['rows'] = escape_rows(sample_data)
|
|
response['rows'] = escape_rows(sample_data)
|
|
|
|
|
+
|
|
|
|
|
+ if table:
|
|
|
|
|
+ columns = assist.get_columns(database, table)
|
|
|
response['full_headers'] = [{
|
|
response['full_headers'] = [{
|
|
|
- 'name': col[0] if type(col) is dict or type(col) is tuple else col,
|
|
|
|
|
- 'type': 'String', #TODO: resolve
|
|
|
|
|
- 'comment': ''
|
|
|
|
|
- } for col in metadata] if has_result_set else []
|
|
|
|
|
|
|
+ 'name': col.get('name'),
|
|
|
|
|
+ 'type': str(col.get('type')),
|
|
|
|
|
+ 'comment': ''
|
|
|
|
|
+ } for col in columns]
|
|
|
|
|
+ elif metadata:
|
|
|
|
|
+ response['full_headers'] = [{
|
|
|
|
|
+ 'name': col[0] if type(col) is dict or type(col) is tuple else col,
|
|
|
|
|
+ 'type': 'STRING_TYPE',
|
|
|
|
|
+ 'comment': ''
|
|
|
|
|
+ } for col in metadata]
|
|
|
|
|
|
|
|
return response
|
|
return response
|
|
|
|
|
|