Skip to content

Commit d43d84d

Browse files
committed
Merge pull request #118 from tvincentNuoDB/master
Updated driver to set clientHost and clientProcessId
2 parents eb2c7ec + e1f7110 commit d43d84d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

pynuodb/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from .encodedsession import EncodedSession
1414
from .crypt import ClientPassword, RC4Cipher
1515
from .util import getCloudEntry
16+
from os import getpid
1617

18+
import platform
1719
import time
1820

1921
apilevel = "2.0"
@@ -96,6 +98,9 @@ def __init__(self, dbName, broker, username, password, options):
9698
if 'cipher' in options and options['cipher'] == 'None':
9799
self.__session.set_encryption(False)
98100

101+
parameters['clientProcessId'] = str(getpid())
102+
parameters['clientHost'] = platform.node()
103+
99104
version, serverKey, salt = self.__session.open_database(dbName, parameters, cp)
100105

101106
sessionKey = cp.computeSessionKey(username.upper(), password, salt, serverKey)

pynuodb/encodedsession.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ def open_database(self, db_name, parameters, cp):
157157
self._putMessageId(protocol.OPENDATABASE).putInt(protocol.CURRENT_PROTOCOL_VERSION).putString(db_name).putInt(len(parameters))
158158
for (k, v) in parameters.items():
159159
self.putString(k).putString(v)
160-
161160
self.putNull().putString(cp.genClientKey())
162161

163162
self._exchangeMessages()

tests/nuodb_basic_test.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import unittest
1111
import decimal
12+
import platform
1213
import time
1314
import os
1415
import sys
@@ -17,7 +18,7 @@
1718
from .nuodb_base import NuoBase
1819
from .mock_tzs import EscapingTimestamp
1920
from .mock_tzs import Local
20-
from pynuodb.exception import DataError
21+
from pynuodb.exception import DataError, ProgrammingError
2122

2223

2324
class NuoDBBasicTest(NuoBase):
@@ -457,6 +458,36 @@ def test_long_string_types(self):
457458
finally:
458459
con.close()
459460

461+
def test_connection_properties(self):
462+
#Get NuoDB release
463+
con = self._connect()
464+
cursor = con.cursor()
465+
try:
466+
cursor.execute("select getReleaseversion() from dual")
467+
except ProgrammingError as pe:
468+
return #2.0 or earlier, skip test
469+
470+
version = cursor.fetchone()[0]
471+
majorVersion = version[0]
472+
minorVersion = version[2]
473+
if(majorVersion is '2'):
474+
if(minorVersion is not '3'):
475+
return
476+
477+
clientInfo = "NuoDB Python driver"
478+
tmp_args = self.connect_kw_args.copy()
479+
tmp_args['options'] = {'schema': 'test', 'clientInfo': clientInfo}
480+
con = pynuodb.connect(**tmp_args)#self._connect({'clientInfo':'Hello World'})
481+
cursor = con.cursor()
482+
cursor.execute("select * from SYSTEM.CONNECTIONS")
483+
result = cursor.fetchone()
484+
485+
#Make sure our clientHost, clientProcessId and clientInfo remain the same in the SYSTEM.CONNECTIONS table
486+
self.assertEqual(platform.node(), result[17]) #ClientHost
487+
self.assertEqual(str(os.getpid()), result[18]) #clientProcessId
488+
self.assertEqual(clientInfo, result[19]) #clientInfo
489+
490+
460491
def test_utf8_string_types(self):
461492
con = self._connect()
462493
cursor = con.cursor()

0 commit comments

Comments
 (0)