Skip to content

Commit

Permalink
fix #58
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Romeu committed Jul 4, 2017
1 parent 8454cc0 commit ea0eb50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion carto/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, auth_client, api_version='v2'):
self.username = getattr(self.auth_client, 'username', None)
self.base_url = self.auth_client.base_url

def send(self, sql, parse_json=True, do_post=True, format=None):
def send(self, sql, parse_json=True, do_post=True, format=None, **request_args):
"""
Executes SQL query in a CARTO server
Expand All @@ -50,10 +50,12 @@ def send(self, sql, parse_json=True, do_post=True, format=None):
:param do_post: Set it to True to force post request
:param format: Any of the data export formats allowed by CARTO's
SQL API
:param request_args: Additional parameters to send with the request
:type sql: str
:type parse_json: boolean
:type do_post: boolean
:type format: str
:type request_args: dictionary
:return: response data, either as json or as a regular
response.content object
Expand All @@ -68,6 +70,10 @@ def send(self, sql, parse_json=True, do_post=True, format=None):
if format not in ['json', 'geojson']:
parse_json = False

if request_args is not None:
for attr in request_args:
params[attr] = request_args[attr]

if len(sql) < MAX_GET_QUERY_LEN and do_post is False:
resp = self.auth_client.send(self.api_url,
'GET',
Expand Down
21 changes: 21 additions & 0 deletions tests/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,24 @@ def test_sql_unverified_fails_with_auth_client(wrong_onprem_auth_client):
sql = SQLClient(wrong_onprem_auth_client)
with pytest.raises(CartoException):
data = sql.send('select version()')


def test_sql_additional_params(api_key_auth_client_usr):
sql = SQLClient(api_key_auth_client_usr)
request_args = {
"skipfields": "the_geom_webmercator"
}
data = sql.send('select * from ' + EXISTING_POINT_DATASET,
do_post=True, **request_args)

assert data is not None
assert 'rows' in data
assert 'total_rows' in data
assert 'time' in data
assert len(data['rows']) > 0
assert "the_geom_webmercator" not in data['rows'][0]

data = sql.send('select * from ' + EXISTING_POINT_DATASET,
do_post=True)

assert "the_geom_webmercator" not in data['rows'][0]

0 comments on commit ea0eb50

Please sign in to comment.