Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix DSN construction for remote server connections
  • Loading branch information
fdcastel committed Apr 18, 2026
commit 7a8fc18c476297bc9edd401cf946a43bf08cb165
35 changes: 28 additions & 7 deletions src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2164,9 +2164,31 @@ def _connect_helper(dsn: str, host: str, port: str, database: str, protocol: Net
if protocol is not None:
dsn = f'{protocol.name.lower()}://'
if host and port:
dsn += f'{host}:{port}/'
dsn += f'{host}:{port}'
elif host:
dsn += f'{host}/'
dsn += host
# Add database path
# When there's a host, URLs need proper path formatting:
# - Unix absolute paths (start with '/') - need double slash to preserve the leading /
# because Firebird URL parsing strips one /
# - Windows absolute paths (contain ':') - concatenate directly without separator
# - Aliases/relative paths - need '/' separator
# When there's no host (loopback), the path is used as-is
if host:
# For URLs with host
if database.startswith('/'):
# Unix absolute path - use double slash so Firebird keeps the leading /
dsn += f'/{database}' # Results in inet://host//absolute/path
elif ':' in database: # Windows path (e.g., C:\...)
dsn += database # Concatenate directly without separator
else: # Relative/alias
dsn += f'/{database}'
else:
# Loopback - path is used as-is after ://
if database.startswith('/') or ':' in database:
dsn += database
else:
dsn += f'/{database}'
else:
dsn = ''
if host and host.startswith('\\\\'): # Windows Named Pipes
Expand All @@ -2178,7 +2200,7 @@ def _connect_helper(dsn: str, host: str, port: str, database: str, protocol: Net
dsn += f'{host}/{port}:'
elif host:
dsn += f'{host}:'
dsn += database
dsn += database
return dsn

def _is_dsn(value: str) -> bool:
Expand Down Expand Up @@ -2401,10 +2423,9 @@ def create_database(database: str | Path, *, user: str | None=None, password: st
if db_config is None:
db_config = driver_config.db_defaults
srv_config = driver_config.server_defaults
if _is_dsn(database):
dsn = database
database = None
srv_config.host.clear()
dsn = database
database = None
srv_config.host.clear()
else:
database = db_config.database.value
dsn = db_config.dsn.value
Expand Down