def _connection_factory(self): """Create a MySQLdb DBI connection based on the DSN""" conn_info = parseDSN(self.dsn) # patch to present ALL connection parameters conn_all = {} conn_all['db'] = conn_info['dbname'] conn_all['host'] = conn_info['host'] conn_all['user'] = conn_info['username'] conn_all['passwd'] = conn_info['password'] conn_all['port'] = int(conn_info['port'] or '3306') for k in conn_info['parameters'].keys(): conn_all[str(k)] = str(conn_info['parameters'][k]) connection = MySQLdb.Connect(**conn_all) #connection = MySQLdb.Connect(db=conn_info['dbname'], # host=conn_info['host'], # user=conn_info['username'], # passwd=conn_info['password'], # port=int(conn_info['port'] or '3306')) if self.__stringConverter.encoding != self.getEncoding(): #avoid resetting this everytime, otherwise the adapter #gets modified on each connection and that causes ZODB conflicts self.__stringConverter = MySQLStringConverter(self.getEncoding()) return connection
def _connection_factory(self): """Create a Gadfly DBI connection based on the DSN. Only local (filesystem-based) Gadfly connections are supported at this moment.""" conn_info = parseDSN(self.dsn) if conn_info['host'] != '' or conn_info['username'] != '' or \ conn_info['port'] != '' or conn_info['password'] != '': raise DatabaseAdapterError( "DSN for GadflyDA must be of the form " "dbi://dbname or dbi://dbname;dir=directory." ) connection = conn_info['dbname'] dir = os.path.join(getGadflyRoot(), conn_info['parameters'].get('dir', connection)) if not os.path.isdir(dir): raise DatabaseAdapterError('Not a directory ' + dir) if not os.path.exists(os.path.join(dir, connection + ".gfd")): db = gadfly.gadfly() db.startup(connection, dir) else: db = gadfly.gadfly(connection, dir) return db
def testAllOptionsAndParams(self): dsn = 'dbi://*****:*****@bohr:5432/test;param1=value1;param2=value2' result = {'parameters': {'param1': 'value1', 'param2': 'value2'}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': 'bohr', 'port': '5432'} self.assertEqual(result, parseDSN(dsn))
def testAllOptions(self): dsn = 'dbi://*****:*****@bohr:5432/test' result = {'parameters': {}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': 'bohr', 'port': '5432'} self.assertEqual(result, parseDSN(dsn))
def testUserPasswordAndHostWithoutPort(self): dsn = 'dbi://*****:*****@bohr/test' result = {'parameters': {}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': 'bohr', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testParamsWithSpecialCharacters(self): dsn = 'dbi://test;param%40=value%21;param%23=value%24' result = {'parameters': {'param@': 'value!', 'param#': 'value$'}, 'dbname': 'test', 'username': '', 'password': '', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testUserPasswordAndParams(self): dsn = 'dbi://mike:muster/test;param1=value1;param2=value2' result = {'parameters': {'param1': 'value1', 'param2': 'value2'}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testPasswordWithColon(self): dsn = 'dbi://mike:before:after/test' result = {'parameters': {}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testUserPasswordWithSpecialCharacters(self): dsn = 'dbi://m+i+k+e:m%7Bu%7Dster/test' result = {'parameters': {}, 'dbname': 'test', 'username': '******', 'password': '******', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testUser(self): dsn = 'dbi://mike/test' result = {'parameters': {}, 'dbname': 'test', 'username': '******', 'password': '', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))
def testDBNameWithSpecialCharacters(self): dsn = 'dbi://test%2Fmore+' result = {'parameters': {}, 'dbname': 'test/more ', 'username': '', 'password': '', 'host': '', 'port': ''} self.assertEqual(result, parseDSN(dsn))