Merge "Change logging of sql to single line"

changes/14/589314/2
Zuul 5 years ago committed by Gerrit Code Review
commit 0341954f00

@ -109,7 +109,7 @@ class DbAccess:
executes the supplied query and returns the array of dictionaries of
the row results
"""
LOG.debug('Query: %s', query)
LOG.debug('Query: %s', _query_single_line(query))
result_dict_list = []
if query is not None:
with self.get_engine().connect() as connection:
@ -142,7 +142,15 @@ class DbAccess:
"""
Performs an update/insert/delete
"""
LOG.debug('Query: %s', query)
LOG.debug('Query: %s', _query_single_line(query))
if query is not None:
with self.get_engine().connect() as connection:
return connection.execute(query, **kwargs)
def _query_single_line(query):
"""Reformats a query string to remove newlines and extra spaces
:param query: The query string to log
"""
return " ".join(query.split())

@ -0,0 +1,53 @@
# Copyright 2018 AT&T Intellectual Property. All other rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from shipyard_airflow.db import common_db
M_QUERY = """
SELECT
junk_id,
junk_name
FROM
junk_table
WHERE
junk_name = "Junk"
"""
M_RES = 'SELECT junk_id, junk_name FROM junk_table WHERE junk_name = "Junk"'
M2_QUERY = """
SELECT
things
FROM
tables
"""
M2_RES = 'SELECT things FROM tables'
S_QUERY = "SELECT 1 FROM dual"
class TestCommonDb():
def test_single_line_query(self):
assert M_RES == common_db._query_single_line(M_QUERY)
assert M2_RES == common_db._query_single_line(M2_QUERY)
assert S_QUERY == common_db._query_single_line(S_QUERY)
Loading…
Cancel
Save