Skip to content

Commit

Permalink
Raw engine execute support (#134)
Browse files Browse the repository at this point in the history
Raw engine execute support
  • Loading branch information
FishermanZzhang committed Jul 26, 2021
1 parent 71564b5 commit 14958fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions clickhouse_sqlalchemy/drivers/http/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 7 additions & 3 deletions tests/drivers/http/test_cursor.py
Original file line number Diff line number Diff line change
@@ -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)])
6 changes: 4 additions & 2 deletions tests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
7 changes: 6 additions & 1 deletion tests/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 """
Expand Down

0 comments on commit 14958fb

Please sign in to comment.