Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jaydebeapiarrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def connect(jclassname, url, driver_args=None, jars=None, libs=None):
libs: Dll/so filenames or sequence of dlls/sos used as shared
library by the JDBC driver
"""
if not isinstance(url, str):
raise ProgrammingError(
"The 'url' parameter must be a JDBC connection string, "
"not %s. If you meant to pass connection credentials, "
"use the 'driver_args' parameter. "
"Usage: connect(jclassname, url, driver_args=None, jars=None, libs=None)"
% type(url).__name__
)
if isinstance(driver_args, str):
driver_args = [ driver_args ]
if not driver_args:
Expand Down
9 changes: 9 additions & 0 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,3 +2007,12 @@ def test_hsqldb_jar_path_with_spaces(self):
)
self.assertTrue(result.stdout.strip().startswith('OK'),
f'Connection failed: {result.stdout}\n{result.stderr}')

def test_connect_url_must_be_string(self):
"""Passing a list as url should raise ProgrammingError (issue #95)."""
with self.assertRaises(jaydebeapiarrow.ProgrammingError) as ctx:
jaydebeapiarrow.connect(
'org.hsqldb.jdbcDriver',
['jdbc:hsqldb:mem:.', 'SA', '']
)
self.assertIn('url', str(ctx.exception).lower())
22 changes: 22 additions & 0 deletions test/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,3 +1327,25 @@ def test_jar_path_with_special_chars(self):
shutil.copy2(mock_jar, dest)
stdout, stderr = self._run_connect_in_subprocess(dest)
self.assertEqual(stdout, 'OK', f'Connection failed: {stderr}')


class ConnectValidationTest(unittest.TestCase):
"""Tests for connect() argument validation (issue #95)."""

def test_url_must_be_string_not_list(self):
"""Passing a list as url should raise ProgrammingError."""
with self.assertRaises(jaydebeapiarrow.ProgrammingError) as ctx:
jaydebeapiarrow.connect(
'org.jaydebeapi.mockdriver.MockDriver',
['jdbc:jaydebeapi://dummyurl', 'user', 'pass']
)
self.assertIn('url', str(ctx.exception).lower())

def test_url_must_be_string_not_dict(self):
"""Passing a dict as url should raise ProgrammingError."""
with self.assertRaises(jaydebeapiarrow.ProgrammingError) as ctx:
jaydebeapiarrow.connect(
'org.jaydebeapi.mockdriver.MockDriver',
{'user': 'sa', 'password': ''}
)
self.assertIn('url', str(ctx.exception).lower())
Loading