Browse files

in connect() dsn can set port number. ex) dsn='example.com/3050:foo.fdb'

  • Loading branch information...
1 parent cae4574 commit 3c073310fbe40458172e1c4970885482e1ebe5f1 @nakagami committed Apr 28, 2011
Showing with 15 additions and 10 deletions.
  1. +9 −2 firebirdsql/fbcore.py
  2. +6 −8 firebirdsql/tests.py
View
11 firebirdsql/fbcore.py
@@ -1166,15 +1166,22 @@ def __init__(self, dsn=None, user=None, password=None, host=None,
self.hostname = host
self.filename = dsn
else:
- self.hostname = dsn[:i]
+ hostport = dsn[:i]
self.filename = dsn[i+1:]
+ i = hostport.find('/')
+ if i < 0:
+ self.hostname = hostport
+ self.port = port
+ else:
+ self.hostname = hostport[:i]
+ self.port = int(hostport[i+1:])
else:
self.hostname = host
self.filename = database
+ self.port = port
self.user = user
self.password = password
self.charset = charset
- self.port = port
self.cursor_set = set()
self.isolation_level = ISOLATION_LEVEL_READ_COMMITED
View
14 firebirdsql/tests.py
@@ -21,15 +21,15 @@ def debug_print(msg):
import tempfile
fbase = tempfile.mktemp()
TEST_HOST = 'localhost'
+ TEST_PORT = 3050
TEST_DATABASE = fbase + '.fdb'
- TEST_DSN = TEST_HOST + ':' + TEST_DATABASE
+ TEST_DSN = TEST_HOST + '/' + str(TEST_PORT) + ':' + TEST_DATABASE
TEST_BACKUP_FILE = fbase + '.fbk'
TEST_RESTORE_DSN = 'localhost:' + fbase + '_restore.fdb'
print('dsn=', TEST_DSN)
TEST_USER = 'sysdba'
TEST_PASS = 'masterkey'
- conn = firebirdsql.create_database(dsn=TEST_DSN, user=TEST_USER,
- password=TEST_PASS, port=3050)
+ conn = firebirdsql.create_database(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
print(conn.info_database(['isc_info_ods_version',
'isc_info_ods_minor_version',
'isc_info_user_names']))
@@ -80,7 +80,7 @@ def debug_print(msg):
conn.close()
conn = firebirdsql.connect(host=TEST_HOST, database=TEST_DATABASE,
- user=TEST_USER, password=TEST_PASS)
+ port=TEST_PORT, user=TEST_USER, password=TEST_PASS)
conn.set_isolation_level(firebirdsql.ISOLATION_LEVEL_SERIALIZABLE)
cur = conn.cursor()
cur.execute("select * from foo")
@@ -90,12 +90,10 @@ def debug_print(msg):
conn.close()
print('backup database')
- svc = firebirdsql.service_mgr(dsn=TEST_DSN, user=TEST_USER,
- password=TEST_PASS, port=3050)
+ svc = firebirdsql.service_mgr(dsn=TEST_DSN, user=TEST_USER, password=TEST_PASS)
svc.backup_database(TEST_BACKUP_FILE, callback=debug_print)
svc.close()
print('restore database')
- svc = firebirdsql.service_mgr(dsn=TEST_RESTORE_DSN, user=TEST_USER,
- password=TEST_PASS, port=3050)
+ svc = firebirdsql.service_mgr(dsn=TEST_RESTORE_DSN, user=TEST_USER, password=TEST_PASS)
svc.restore_database(TEST_BACKUP_FILE, callback=debug_print)
svc.close()

0 comments on commit 3c07331

Please sign in to comment.