Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow non select sql #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/jet_bridge_base/jet_bridge_base/serializers/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class SqlSerializer(Serializer):
params = SqlParamsSerializers(required=False)

def validate_query(self, value):
forbidden = ['insert', 'update', 'delete', 'grant', 'show']
for i in range(len(forbidden)):
forbidden.append('({}'.format(forbidden[i]))
if any(map(lambda x: ' {} '.format(value.lower()).find(' {} '.format(x)) != -1, forbidden)):
raise ValidationError('forbidden query')
# TODO allow any sql operations, maybe other serializer class for non select?
# forbidden = ['insert', 'update', 'delete', 'grant', 'show']
# for i in range(len(forbidden)):
# forbidden.append('({}'.format(forbidden[i]))
# if any(map(lambda x: ' {} '.format(value.lower()).find(' {} '.format(x)) != -1, forbidden)):
# raise ValidationError('forbidden query')

i = 0
while value.find('%s') != -1:
Expand Down Expand Up @@ -48,12 +49,10 @@ def execute(self, data):
params
)

rows = list(map(lambda x: list(x.itervalues()), result))
if not result.returns_rows:
return {'data': [], 'columns': []}

def map_column(x):
if x == '?column?':
return
return x
rows = result.fetchall()

def map_row_column(x):
if isinstance(x, bytes):
Expand All @@ -67,13 +66,14 @@ def map_row_column(x):
def map_row(x):
return list(map(map_row_column, x))

return {'data': list(map(map_row, rows)), 'columns': list(map(map_column, result.keys()))}
return {'data': list(map(map_row, rows)), 'columns': list(result.keys())}
except SQLAlchemyError as e:
session.rollback()
raise SqlError(e)
except TypeError as e:
raise SqlError(e)
finally:
session.commit()
session.close()


Expand Down