diff --git a/clickhouse_sqlalchemy/drivers/http/connector.py b/clickhouse_sqlalchemy/drivers/http/connector.py index 17dbef7c..d3c89237 100644 --- a/clickhouse_sqlalchemy/drivers/http/connector.py +++ b/clickhouse_sqlalchemy/drivers/http/connector.py @@ -107,6 +107,10 @@ def execute(self, operation, parameters=None, context=None): if parameters is not None: raw_sql = raw_sql % self._params_escaper.escape(parameters) + raw_sql_big = raw_sql.upper() + if 'FORMAT' not in raw_sql_big and 'INSERT' not in raw_sql_big: + raw_sql += ' FORMAT TabSeparatedWithNamesAndTypes' + self._reset_state() self._begin_query() diff --git a/tests/drivers/http/test_cursor.py b/tests/drivers/http/test_cursor.py index 8d0858b4..5e99bf6f 100644 --- a/tests/drivers/http/test_cursor.py +++ b/tests/drivers/http/test_cursor.py @@ -1,7 +1,11 @@ -from tests.testcase import HttpSessionTestCase +from tests.testcase import HttpSessionTestCase, HttpEngineTestCase -class CursorTestCase(HttpSessionTestCase): - def test_check_iter_cursor(self): +class CursorTestCase(HttpSessionTestCase, HttpEngineTestCase): + def test_check_iter_cursor_by_session(self): rv = self.session.execute('SELECT number FROM system.numbers LIMIT 5') self.assertListEqual(list(rv), [(x,) for x in range(5)]) + + def test_check_iter_cursor_by_engine(self): + rv = self.engine.execute('SELECT number FROM system.numbers LIMIT 5') + self.assertListEqual(list(rv), [(x,) for x in range(5)]) diff --git a/tests/session.py b/tests/session.py index e1e48a04..655e0cbd 100644 --- a/tests/session.py +++ b/tests/session.py @@ -5,9 +5,11 @@ from clickhouse_sqlalchemy import make_session from tests.config import http_uri, native_uri, system_native_uri -http_session = make_session(create_engine(http_uri)) +http_engine = create_engine(http_uri) +http_session = make_session(http_engine) http_stream_session = make_session(create_engine(http_uri + '?stream=1')) -native_session = make_session(create_engine(native_uri)) +native_engine = create_engine(native_uri) +native_session = make_session(native_engine) system_native_session = make_session(create_engine(system_native_uri)) diff --git a/tests/testcase.py b/tests/testcase.py index c1dd85c5..72df937f 100644 --- a/tests/testcase.py +++ b/tests/testcase.py @@ -6,7 +6,7 @@ from sqlalchemy.orm import Query from tests.config import database, host, port, http_port, user, password -from tests.session import http_session, native_session, system_native_session +from tests.session import http_session, native_session, system_native_session, http_engine, native_engine from tests.util import skip_by_server_version @@ -96,6 +96,11 @@ class HttpSessionTestCase(BaseTestCase): port = http_port session = http_session +class HttpEngineTestCase(BaseTestCase): + """ Explicitly HTTP-based session Test Case """ + + port = http_port + engine = http_engine class NativeSessionTestCase(BaseTestCase): """ Explicitly Native-protocol-based session Test Case """